:root {
  --bg: #ededed;
  --bg-strong: #e2e2e2;
  --surface: #f7f7f7;
  --panel: #ffffff;
  --panel-muted: #f2f2f2;
  --sidebar: #111111;
  --sidebar-surface: #1a1a1a;
  --line: #d4d4d4;
  --line-strong: #9f9f9f;
  --text: #111111;
  --muted: #666666;
  --inverse: #ffffff;
  --shadow: none;
  --radius-xl: 0;
  --radius-lg: 0;
  --radius-md: 0;
  --radius-sm: 0;
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: light;
}

body {
  margin: 0;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
}

body.has-modal {
  overflow: hidden;
}

a {
  color: inherit;
}

.shell-body,
.login-body {
  min-height: 100vh;
}

.page-noise,
.login-bg-shape {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background-image:
    linear-gradient(rgba(0, 0, 0, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(0, 0, 0, 0.03) 1px, transparent 1px);
  background-size: 28px 28px;
  opacity: 0.32;
}

.app-shell {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 20px;
  background: var(--sidebar);
  color: var(--inverse);
  border-right: 1px solid #000;
}

.brand-card,
.user-card,
.chat-list-panel,
.panel,
.material-card,
.login-card,
.login-hero {
  border: 1px solid var(--line);
  border-radius: 0;
  box-shadow: var(--shadow);
}

.brand-card {
  padding: 20px;
  background: var(--sidebar-surface);
  border-color: #2b2b2b;
}

.brand-card h1,
.login-hero h1,
.page-header h2,
.details-header h3,
.material-card h3 {
  margin: 10px 0 8px;
  font-size: clamp(28px, 3vw, 44px);
  line-height: 1;
  font-weight: 700;
  letter-spacing: -0.04em;
}

.material-card h3,
.details-header h3 {
  font-size: 24px;
}

.brand-card p,
.login-hero p,
.page-header p,
.user-role,
.empty-note,
.message-time {
  color: var(--muted);
}

.brand-kicker,
.page-kicker,
.section-title,
.message-label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
}

.brand-kicker,
.page-kicker {
  color: var(--muted);
}

.main-nav,
.tab-row,
.segmented,
.quick-prompts,
.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

.main-nav {
  flex-direction: column;
}

.main-nav a,
.segmented a,
.tab-row a,
.chat-list-item,
.user-list-item,
.quick-prompt,
.new-chat-link,
.primary-button,
.secondary-button,
.ghost-button {
  text-decoration: none;
  transition: transform 160ms ease, background-color 160ms ease, color 160ms ease, border-color 160ms ease, opacity 160ms ease;
}

.main-nav a,
.segmented a,
.tab-row a,
.chat-list-item,
.user-list-item,
.quick-prompt {
  border: 1px solid var(--line);
}

.main-nav a {
  padding: 12px 14px;
  background: transparent;
  color: #d7d7d7;
  border-color: #303030;
}

.main-nav a:hover,
.main-nav a.active {
  background: #ffffff;
  color: #111111;
  border-color: #ffffff;
}

.new-chat-link,
.primary-button,
.secondary-button,
.ghost-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 16px;
  min-height: 46px;
  border-radius: 0;
  cursor: pointer;
  font: inherit;
}

.new-chat-link,
.primary-button {
  background: #111111;
  color: #ffffff;
  border: 1px solid #111111;
}

.primary-button:hover,
.new-chat-link:hover {
  transform: translateY(-1px);
  opacity: 0.88;
}

.secondary-button,
.ghost-button {
  background: #ffffff;
  color: #111111;
  border: 1px solid var(--line-strong);
}

.ghost-button {
  background: transparent;
}

.secondary-button:hover,
.ghost-button:hover,
.segmented a:hover,
.tab-row a:hover,
.quick-prompt:hover,
.chat-list-item:hover,
.user-list-item:hover {
  transform: translateY(-1px);
  background: var(--surface);
}

.danger-text {
  color: #111111;
}

.chat-list-panel,
.user-card {
  background: var(--sidebar-surface);
  border-color: #2b2b2b;
}

.chat-list-panel {
  flex: 1;
  min-height: 240px;
  padding: 16px;
}

.section-title {
  margin-bottom: 12px;
  color: #8e8e8e;
}

.chat-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.chat-list-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  background: transparent;
  border-color: #303030;
  color: #efefef;
}

.chat-list-item.active {
  background: #ffffff;
  border-color: #ffffff;
  color: #111111;
}

.chat-date {
  font-size: 11px;
  color: inherit;
  opacity: 0.65;
}

.chat-label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sidebar .empty-note,
.user-card .user-role {
  color: #8e8e8e;
}

.user-card {
  padding: 16px;
  color: #ffffff;
}

.user-name {
  font-weight: 700;
}

.content-area {
  padding: 24px;
}

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.page-header h2 {
  font-size: clamp(28px, 4vw, 40px);
}

.page-header p {
  margin: 0;
}

.flash-stack {
  display: grid;
  gap: 10px;
  margin-bottom: 16px;
}

.flash {
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  background: #ffffff;
}

.flash-error {
  border-color: #111111;
}

.flash-info,
.flash-success {
  border-color: var(--line-strong);
}

.panel,
.material-card,
.login-card,
.login-hero,
.chat-panel,
.message-card,
.empty-chat,
.composer,
.modal-card {
  background: var(--panel);
}

.panel,
.material-card,
.chat-panel,
.login-card,
.login-hero {
  border: 1px solid var(--line);
}

.panel,
.chat-panel,
.material-card {
  padding: 18px;
}

.narrow-panel {
  max-width: 620px;
}

.empty-note {
  padding: 16px;
}

.users-toolbar {
  margin-bottom: 16px;
}

.segmented a,
.tab-row a,
.quick-prompt {
  padding: 10px 12px;
  background: #ffffff;
  color: var(--text);
}

.segmented a.active,
.tab-row a.active {
  background: #111111;
  color: #ffffff;
  border-color: #111111;
}

.users-layout {
  display: grid;
  grid-template-columns: minmax(220px, 300px) minmax(0, 1fr);
  gap: 16px;
}

.user-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  min-height: 360px;
}

.user-list-item {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 14px;
  background: #ffffff;
}

.user-list-item.active {
  border-color: #111111;
  background: var(--surface);
}

.user-list-item small {
  color: var(--muted);
}

.user-details {
  min-height: 360px;
}

.details-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.details-header p {
  margin: 0;
  color: var(--muted);
}

.token-badge,
.file-pill,
.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 12px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  font-size: 13px;
  color: var(--text);
}

.inline-form,
.stack-form,
.upload-form {
  display: grid;
  gap: 14px;
}

.quick-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
}

.wide-field {
  width: 100%;
}

.tab-row {
  margin: 18px 0;
}

.tab-content {
  display: grid;
  gap: 10px;
}

.data-row,
.list-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  background: #ffffff;
}

.data-row strong {
  min-width: 150px;
  font-size: 13px;
}

.list-row span,
.data-row span {
  word-break: break-word;
}

label {
  display: grid;
  gap: 8px;
}

label span {
  font-weight: 600;
}

input,
textarea,
select,
button {
  font: inherit;
}

input,
textarea,
select {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 0;
  background: #ffffff;
  color: var(--text);
  outline: none;
  transition: border-color 160ms ease, background-color 160ms ease;
}

input:focus,
textarea:focus,
select:focus {
  border-color: #111111;
  background: #ffffff;
}

textarea {
  resize: vertical;
  min-height: 120px;
}

.chat-layout {
  display: grid;
}

.chat-panel {
  display: grid;
  gap: 16px;
}

.message-stream {
  display: flex;
  flex-direction: column;
  gap: 16px;
  min-height: 420px;
  max-height: calc(100vh - 270px);
  overflow-y: auto;
  padding: 4px;
}

.message-card {
  max-width: min(78%, 820px);
  padding: 16px;
  border: 1px solid var(--line);
}

.message-card.user {
  align-self: flex-end;
  background: #f5f5f5;
  border-color: var(--line-strong);
}

.message-card.assistant {
  align-self: flex-start;
}

.message-label {
  margin-bottom: 8px;
  color: var(--muted);
}

.message-text {
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-word;
}

.message-time {
  margin-top: 10px;
  font-size: 12px;
}

.empty-chat {
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
}

.empty-chat h3 {
  margin: 0;
  font-size: 24px;
}

.empty-chat p {
  margin: 0;
  color: var(--muted);
}

.composer {
  display: grid;
  gap: 12px;
  padding: 18px;
  border: 1px solid var(--line);
}

.typing-indicator {
  display: inline-flex;
  gap: 8px;
  padding: 12px 0 0;
}

.typing-indicator span {
  width: 10px;
  height: 10px;
  border-radius: 999px;
  background: #111111;
  animation: bounce 1s infinite ease-in-out;
}

.typing-indicator span:nth-child(2) {
  animation-delay: 0.12s;
}

.typing-indicator span:nth-child(3) {
  animation-delay: 0.24s;
}

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.32; }
  40% { transform: translateY(-5px); opacity: 1; }
}

.upload-dropzone {
  display: grid;
  gap: 8px;
  padding: 18px;
  border: 1px dashed var(--line-strong);
  background: var(--surface);
}

.upload-dropzone small {
  color: var(--muted);
}

.material-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
  gap: 16px;
  margin-top: 16px;
}

.material-topline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.file-pill,
.status-pill {
  min-height: 32px;
  font-size: 12px;
}

.status-ready,
.status-processing,
.status-error {
  background: #ffffff;
}

.material-card p {
  margin: 6px 0;
  color: var(--muted);
}

.error-box {
  margin: 14px 0;
  padding: 12px;
  border: 1px solid var(--line-strong);
  background: var(--surface);
  white-space: pre-wrap;
  word-break: break-word;
}

.list-panel {
  margin-top: 16px;
}

.login-body {
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-shell {
  width: min(1100px, 100%);
  display: grid;
  grid-template-columns: minmax(0, 1.1fr) minmax(340px, 0.9fr);
  gap: 16px;
}

.login-hero,
.login-card {
  padding: 28px;
}

.login-hero {
  display: grid;
  align-content: end;
  min-height: 540px;
  background: #111111;
  color: #ffffff;
  border-color: #111111;
}

.login-hero .brand-kicker,
.login-hero p {
  color: #b5b5b5;
}

.login-card h2 {
  margin: 0 0 8px;
  font-size: 32px;
  line-height: 1;
}

.login-card p {
  margin: 0 0 18px;
  color: var(--muted);
}

.modal[hidden] {
  display: none !important;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(0, 0, 0, 0.38);
}

.modal.is-open {
  display: grid;
}

.modal-card {
  width: min(520px, 100%);
  padding: 20px;
  border: 1px solid var(--line-strong);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.modal-header h3 {
  margin: 0;
  font-size: 20px;
}

.modal-header .ghost-button {
  min-width: 42px;
  padding: 0 12px;
}

@media (max-width: 980px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid #000;
  }

  .users-layout,
  .login-shell {
    grid-template-columns: 1fr;
  }

  .message-stream {
    max-height: none;
  }
}

@media (max-width: 720px) {
  .content-area,
  .sidebar,
  .login-body {
    padding: 16px;
  }

  .page-header,
  .details-header,
  .material-topline,
  .data-row,
  .list-row {
    grid-template-columns: 1fr;
    display: grid;
  }

  .message-card {
    max-width: 100%;
  }

  .quick-form {
    grid-template-columns: 1fr;
  }
}
