:root {
  color-scheme: light;
  --bg: #f7f8f7;
  --surface: #ffffff;
  --surface-soft: #f4f6f5;
  --ink: #171b1f;
  --muted: #687178;
  --line: #dde3e0;
  --line-strong: #b9c4bf;
  --rail: #20262d;
  --rail-soft: #2b333c;
  --accent: #126b5f;
  --accent-dark: #0c5148;
  --accent-soft: #e8f3f0;
  --danger: #a33a3a;
  --warning: #8a5b12;
  --success: #236d4e;
  --radius: 8px;
  --shadow: 0 16px 38px rgba(25, 34, 43, 0.10);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-width: 320px;
  background: var(--bg);
}

body {
  min-height: 100vh;
  margin: 0;
  background: var(--bg);
  color: var(--ink);
}

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

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.55;
}

input,
select,
textarea {
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}

input,
select {
  height: 42px;
  padding: 0 12px;
}

textarea {
  min-height: 120px;
  padding: 12px;
  line-height: 1.6;
  resize: vertical;
}

pre {
  margin: 0;
  white-space: pre-wrap;
  word-break: break-word;
}

[hidden] {
  display: none !important;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
.upload-box:focus-within {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(13, 122, 114, 0.16);
}

.auth-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.auth-panel {
  display: grid;
  width: min(448px, 100%);
  gap: 20px;
  padding: 28px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.brand-line {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  color: inherit;
  text-decoration: none;
}

.brand-line strong,
.brand-line span {
  display: block;
}

.brand-line strong {
  overflow: hidden;
  font-size: 15px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-line span:not(.brand-mark) {
  color: var(--muted);
  font-size: 12px;
}

.brand-mark {
  display: grid;
  flex: 0 0 auto;
  width: 38px;
  height: 38px;
  place-items: center;
  border-radius: var(--radius);
  background: var(--rail);
  color: #fff;
  font-size: 13px;
  font-weight: 850;
}

.auth-title h1,
.auth-title p {
  margin: 0;
}

.auth-title h1 {
  font-size: 26px;
  line-height: 1.2;
}

.auth-title p {
  margin-top: 9px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.7;
}

.auth-form {
  display: grid;
  gap: 13px;
}

.auth-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 12px;
}

.app {
  display: grid;
  min-height: 100vh;
}

.side-rail {
  position: sticky;
  top: 0;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr) auto;
  height: 100vh;
  padding: 18px;
  background: var(--rail);
  color: #f6f8fa;
  overflow: hidden;
}

.side-rail .brand-mark {
  background: #f6f8fa;
  color: var(--rail);
}

.side-rail .brand-line span:not(.brand-mark) {
  color: rgba(246, 248, 250, 0.68);
}

.side-brand {
  margin-bottom: 16px;
}

.side-nav {
  display: grid;
  gap: 6px;
  padding: 6px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
}

.side-nav a {
  display: flex;
  align-items: center;
  min-height: 38px;
  padding: 8px 10px;
  border-radius: 6px;
  color: rgba(246, 248, 250, 0.74);
  font-size: 14px;
  font-weight: 760;
  text-decoration: none;
}

.side-nav a.is-active {
  background: #f6f8fa;
  color: var(--rail);
}

.rail-section {
  min-height: 0;
  margin-top: 18px;
}

.rail-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 13px;
  font-weight: 820;
}

.history-list {
  display: grid;
  gap: 8px;
  max-height: calc(100vh - 284px);
  overflow: auto;
}

.rail-account {
  align-self: end;
  display: grid;
  gap: 8px;
  padding: 12px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.05);
  color: rgba(246, 248, 250, 0.76);
  font-size: 12px;
}

.rail-account p {
  margin: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main-stage {
  min-width: 0;
  padding: 28px;
}

.view {
  min-width: 0;
}

.workbench {
  display: grid;
  grid-template-columns: minmax(0, 500px) minmax(0, 1fr);
  gap: 18px;
  width: min(1120px, 100%);
  min-height: calc(100vh - 56px);
  margin: 0 auto;
}

.chat-pane {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 12px;
  min-width: 0;
}

.workspace-header,
.composer,
.result-panel,
.context-panel,
.page-panel,
.record-detail,
.account-grid > section {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: none;
}

.workspace-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 16px;
  padding: 18px;
  border-color: transparent;
  background: transparent;
}

.workspace-header h1,
.workspace-header p,
.panel-head h1,
.panel-head h2,
.account-grid h2 {
  margin: 0;
}

.workspace-header h1 {
  font-size: 26px;
  line-height: 1.22;
}

.workspace-header p {
  margin-top: 7px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.6;
}

.quick-modes {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
}

.quick-modes button {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--ink);
  font-weight: 780;
}

.quick-modes button:hover,
.button.secondary:hover,
.button.ghost:hover,
.record-row:hover,
.upload-box:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.message-thread {
  display: grid;
  align-content: start;
  gap: 12px;
  min-height: 180px;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
  overflow: auto;
}

.message {
  width: min(760px, 92%);
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.message.user {
  justify-self: end;
  border-color: rgba(13, 122, 114, 0.35);
  background: var(--accent-soft);
}

.message span {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.message p {
  margin: 0;
  line-height: 1.65;
}

.composer {
  display: grid;
  gap: 14px;
  padding: 16px;
}

.composer-row {
  display: grid;
  grid-template-columns: 140px 180px;
  gap: 10px;
}

.field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.field span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.prompt-field textarea {
  min-height: 132px;
}

.upload-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.upload-box {
  position: relative;
  display: grid;
  gap: 6px;
  min-height: 96px;
  padding: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.upload-box input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.upload-box strong {
  color: var(--ink);
}

.upload-box span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

.tone-ready,
.tone-success {
  color: var(--success) !important;
}

.tone-danger {
  color: var(--danger) !important;
}

.tone-warning {
  color: var(--warning) !important;
}

.context-summary {
  display: none;
  flex-wrap: wrap;
  gap: 7px;
}

.context-summary span {
  display: inline-flex;
  max-width: 100%;
  padding: 5px 8px;
  border: 1px solid rgba(13, 122, 114, 0.25);
  border-radius: 999px;
  background: var(--accent-soft);
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 760;
  overflow-wrap: anywhere;
}

.composer-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.button,
.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 40px;
  border-radius: var(--radius);
  font-weight: 820;
  text-decoration: none;
  white-space: nowrap;
}

.button {
  padding: 0 14px;
  border: 1px solid transparent;
}

.button.primary {
  background: var(--accent);
  color: #fff;
}

.button.primary:hover {
  background: var(--accent-dark);
}

.button.secondary {
  border-color: rgba(13, 122, 114, 0.3);
  background: var(--accent-soft);
  color: var(--accent-dark);
}

.button.ghost,
.icon-button {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
}

.icon-button {
  width: 34px;
  min-height: 34px;
  padding: 0;
}

.result-pane {
  display: grid;
  align-content: start;
  gap: 14px;
  min-width: 0;
}

.result-panel,
.context-panel,
.page-panel,
.record-detail,
.account-grid > section {
  padding: 14px;
}

.result-panel {
  display: grid;
  gap: 12px;
  min-height: calc(100vh - 48px);
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 12px;
}

.panel-head.compact {
  align-items: center;
}

.eyebrow {
  display: inline-flex;
  color: var(--accent-dark);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0;
  text-transform: uppercase;
}

.result-actions,
.filter-row {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.result-surface {
  display: grid;
  align-content: start;
  gap: 12px;
  max-height: none;
  padding-right: 4px;
  overflow: auto;
}

.result-block {
  display: grid;
  gap: 9px;
  padding: 13px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.result-block h3 {
  margin: 0;
  font-size: 14px;
}

.result-block p,
.result-block li {
  margin: 0;
  line-height: 1.7;
}

.result-block ul {
  display: grid;
  gap: 7px;
  margin: 0;
  padding-left: 18px;
}

.context-list {
  display: grid;
  gap: 8px;
}

.context-item {
  display: grid;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface-soft);
}

.context-item strong {
  font-size: 13px;
}

.context-item span {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.55;
}

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

.records-layout {
  display: grid;
  grid-template-columns: minmax(280px, 420px) minmax(0, 1fr);
  gap: 14px;
}

.record-list {
  display: grid;
  gap: 8px;
}

.record-list.large {
  align-content: start;
}

.record-row {
  display: grid;
  gap: 4px;
  width: 100%;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--surface);
  color: inherit;
  text-align: left;
}

.side-rail .record-row {
  border-color: rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.05);
  color: #f6f8fa;
}

.record-row.active {
  border-color: rgba(13, 122, 114, 0.45);
  background: var(--accent-soft);
}

.record-row strong {
  overflow: hidden;
  font-size: 13px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.record-row span {
  color: var(--muted);
  font-size: 12px;
}

.side-rail .record-row span {
  color: rgba(246, 248, 250, 0.66);
}

.record-detail {
  display: grid;
  align-content: start;
  gap: 12px;
}

.account-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 14px;
}

.detail-list {
  display: grid;
  gap: 8px;
}

.detail-list p {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  margin: 0;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  font-size: 13px;
}

.detail-list strong {
  color: var(--ink);
}

.form-note {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.55;
}

.form-note.danger {
  color: var(--danger);
}

.form-note.success {
  color: var(--success);
}

.form-note.warning {
  color: var(--warning);
}

.pill {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  max-width: 100%;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 780;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.pill.muted {
  background: #eef1f4;
  color: #5d6875;
}

.pill.ready {
  background: #e4f3ec;
  color: var(--success);
}

.pill.warning {
  background: #fff3d8;
  color: var(--warning);
}

.pill.danger {
  background: #fde8e8;
  color: var(--danger);
}

.empty-state {
  display: grid;
  gap: 4px;
  padding: 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  background: var(--surface-soft);
  color: var(--muted);
}

.empty-state strong {
  color: var(--ink);
}

.empty-state span {
  font-size: 13px;
  line-height: 1.55;
}

@media (max-width: 1100px) {
  .app {
    display: block;
  }

  .workbench {
    grid-template-columns: 1fr;
  }

  .result-pane {
    grid-template-columns: minmax(0, 1fr);
  }

  .result-surface {
    max-height: none;
  }

  .result-panel {
    min-height: 420px;
  }
}

@media (max-width: 760px) {
  .app {
    display: block;
  }

  .side-rail {
    position: static;
    height: auto;
    grid-template-rows: auto auto auto;
  }

  .history-list,
  .rail-account {
    display: none;
  }

  .main-stage {
    padding: 12px;
  }

  .workspace-header,
  .composer-actions,
  .panel-head,
  .auth-foot {
    align-items: stretch;
    flex-direction: column;
  }

  .quick-modes,
  .upload-grid,
  .composer-row,
  .records-layout,
  .account-grid {
    grid-template-columns: 1fr;
  }

  .workspace-header h1 {
    font-size: 21px;
  }
}
