:root {
  --bg: #faf9f7;
  --surface: #ffffff;
  --surface-alt: #f2f0ec;
  --border: #e2ded7;
  --text: #1f1d1a;
  --text-soft: #6b655c;
  --accent: #1f5f4f;
  --accent-soft: #e6f0ec;
  --danger: #a33a2c;
  --radius: 10px;
  --font: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --font-ui: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --mono: "SF Mono", "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171614;
    --surface: #211f1d;
    --surface-alt: #2a2724;
    --border: #3a3733;
    --text: #ece9e4;
    --text-soft: #a29b91;
    --accent: #6fbfa5;
    --accent-soft: #23342e;
    --danger: #d9705f;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 15px;
  line-height: 1.55;
}

.hidden { display: none !important; }

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
  border: 1px solid transparent;
  padding: 8px 14px;
  transition: background 0.12s, border-color 0.12s;
}
button:disabled { opacity: 0.45; cursor: not-allowed; }

.primary { background: var(--accent); color: #fff; border-color: var(--accent); font-weight: 600; }
.primary:hover:not(:disabled) { filter: brightness(1.08); }
.ghost { background: transparent; color: var(--text); border-color: var(--border); }
.ghost:hover { background: var(--surface-alt); }
.ghost.danger { color: var(--danger); }
.link { background: none; border: none; color: var(--text-soft); text-decoration: underline; padding: 0; font-size: 13px; }
.small { padding: 6px 11px; font-size: 13px; }

/* ------------------------------------------------------------------- auth */

.auth-screen {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px;
}
.brand {
  font-family: var(--font);
  font-size: 30px;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}
.brand.small { font-size: 21px; margin: 0; }
.tagline { color: var(--text-soft); margin: 0 0 14px; font-size: 14px; }
.demo-note {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin: 0 0 20px;
  line-height: 1.45;
}

.tabs { display: flex; gap: 4px; margin-bottom: 18px; border-bottom: 1px solid var(--border); }
.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  border-radius: 0;
  padding: 8px 12px;
  color: var(--text-soft);
  font-size: 14px;
}
.tab.active { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }

form label { display: block; margin-bottom: 14px; }
form label span { display: block; font-size: 13px; color: var(--text-soft); margin-bottom: 5px; }
input, textarea {
  width: 100%;
  font: inherit;
  color: var(--text);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 11px;
}
input:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
form .primary { width: 100%; margin-top: 4px; }
.error { color: var(--danger); font-size: 13px; margin: 0 0 12px; }

/* -------------------------------------------------------------------- app */

.app { display: grid; grid-template-columns: 260px 1fr; height: 100vh; }

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.sidebar-head {
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.error.small { font-size: 12px; margin: 0; }
.doc-list { flex: 1; overflow-y: auto; padding: 8px; min-height: 0; }
.doc-item {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  border-radius: 8px;
  padding: 9px 11px;
  margin-bottom: 2px;
  color: var(--text);
}
.doc-item:hover { background: var(--surface-alt); }
.doc-item.active { background: var(--accent-soft); }
.doc-item strong { display: block; font-weight: 600; font-size: 14px; }
.doc-item span { font-size: 12px; color: var(--text-soft); }
.sidebar-foot { padding: 14px 16px; border-top: 1px solid var(--border); }
.user-row { display: flex; justify-content: space-between; align-items: center; margin-top: 8px; }
.user-name { font-size: 13px; color: var(--text-soft); overflow: hidden; text-overflow: ellipsis; }
.badge {
  display: inline-block;
  font-size: 11px;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--surface-alt);
  color: var(--text-soft);
}

.main { min-width: 0; display: flex; flex-direction: column; overflow: hidden; }

.empty-state { padding: 56px 40px; max-width: 640px; }
.empty-state h2 { font-family: var(--font); font-size: 27px; margin: 0 0 10px; }
.empty-state p { color: var(--text-soft); margin: 0 0 22px; }
.catalog { margin-top: 40px; }
.catalog h3 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--text-soft); }
.catalog ul { list-style: none; padding: 0; margin: 0; }
.catalog li { padding: 9px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.catalog li b { display: block; }
.catalog li span { color: var(--text-soft); font-size: 13px; }

/* -------------------------------------------------------------- workspace */

.workspace { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.workspace-head {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  background: var(--surface);
}
.workspace-head h2 { font-family: var(--font); font-size: 20px; margin: 0; }
.doc-status { margin: 2px 0 0; font-size: 13px; color: var(--text-soft); }
.workspace-actions { display: flex; gap: 8px; flex-shrink: 0; align-items: center; }
.workspace-actions select {
  font: inherit;
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 8px;
}

.workspace-body { flex: 1; display: grid; grid-template-columns: 1fr 340px; min-height: 0; }

.chat-pane { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); }
.messages { flex: 1; overflow-y: auto; padding: 24px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 72ch; }
.msg .who { font-size: 12px; color: var(--text-soft); margin-bottom: 4px; }
.msg .bubble {
  padding: 12px 15px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}
.msg.user { align-self: flex-end; }
.msg.user .bubble { background: var(--accent-soft); border-color: transparent; }
.msg .bubble strong { font-weight: 700; }
.msg .bubble em { color: var(--text-soft); font-style: italic; }

.chat-form { display: flex; gap: 8px; padding: 16px 24px; border-top: 1px solid var(--border); background: var(--surface); }
.chat-form textarea { resize: none; }
.chat-form button { align-self: flex-end; }

.side-panel { display: flex; flex-direction: column; min-height: 0; background: var(--surface); }
.panel-tabs { display: flex; border-bottom: 1px solid var(--border); padding: 0 8px; }
.panel-content { flex: 1; overflow-y: auto; padding: 16px; min-height: 0; }

.field-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.field-row .field-label { font-size: 13px; font-weight: 600; display: flex; justify-content: space-between; gap: 8px; }
.field-row .req { font-size: 11px; color: var(--danger); font-weight: 400; }
.field-row .opt { font-size: 11px; color: var(--text-soft); font-weight: 400; }
.field-row .field-value { font-size: 14px; margin-top: 3px; overflow-wrap: anywhere; }
.field-row .field-value.empty { color: var(--text-soft); font-style: italic; }

.doc-preview {
  font-family: var(--mono);
  font-size: 12px;
  line-height: 1.5;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  margin: 0;
}

@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .workspace-body { grid-template-columns: 1fr; }
  .side-panel { display: none; }
  .side-panel.mobile-open { display: flex; }
}
