:root {
  --bg: #f4f6f5; --panel: #ffffff; --text: #17201c; --muted: #66736d; --line: #dfe5e2;
  --accent: #1f7a4d; --accent-soft: #e4f2ea; --warn: #b4540f; --warn-soft: #fcefe3;
  --bad: #b53a3a; --bad-soft: #fbe9e9; --radius: 10px; --shadow: 0 1px 2px rgb(0 0 0 / 6%);
  color-scheme: light;
  font-family: Inter, system-ui, -apple-system, "Segoe UI", sans-serif;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0e1412; --panel: #151d1a; --text: #e9efec; --muted: #93a19a; --line: #26312c;
    --accent: #4db27a; --accent-soft: #173226; --warn: #e39a57; --warn-soft: #33241a;
    --bad: #e07474; --bad-soft: #351d1d; --shadow: none; color-scheme: dark;
  }
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.5; }
button, input, textarea, select { font: inherit; color: inherit; }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 13px; }

/* layout */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; display: flex; flex-direction: column; gap: 4px; position: sticky; top: 0; height: 100vh; }
.brand { font-weight: 750; font-size: 17px; padding: 4px 10px 14px; }
.brand span { display: block; font-weight: 500; font-size: 12px; color: var(--muted); }
.nav { text-align: left; border: 0; background: none; padding: 9px 10px; border-radius: 8px; cursor: pointer; color: var(--muted); font-weight: 600; }
.nav:hover { background: var(--bg); color: var(--text); }
.nav.active { background: var(--accent-soft); color: var(--accent); }
.side .spacer { flex: 1; }
.main { padding: 22px 28px 40px; min-width: 0; }
.head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 16px; margin: 0 0 10px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); padding: 16px 18px; }
.grid { display: grid; gap: 14px; }
.stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 24px; font-weight: 750; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* controls */
.btn { border: 1px solid var(--line); background: var(--panel); border-radius: 8px; padding: 8px 13px; font-weight: 650; cursor: pointer; }
.btn:hover { border-color: var(--muted); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--bad); border-color: var(--bad); }
input[type=text], input[type=password], input[type=search], textarea {
  width: 100%; border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 9px 11px; outline: none;
}
input:focus, textarea:focus { border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 650; background: var(--bg); color: var(--muted); border: 1px solid var(--line); }
.pill.ok { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.pill.warn { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.pill.bad { background: var(--bad-soft); color: var(--bad); border-color: transparent; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: currentColor; }

/* chat */
.chat { display: grid; grid-template-rows: 1fr auto; height: calc(100vh - 110px); }
.messages { overflow-y: auto; padding-right: 4px; }
.msg { padding: 12px 14px; border-radius: var(--radius); margin: 8px 0; max-width: 820px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.user { background: var(--accent-soft); margin-left: auto; }
.msg.bot { background: var(--panel); border: 1px solid var(--line); }
.msg .meta { color: var(--muted); font-size: 12px; margin-top: 6px; }
.composer { border-top: 1px solid var(--line); padding-top: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 12px; background: var(--bg); border: 1px solid var(--line); border-radius: 999px; padding: 3px 8px; display: inline-flex; gap: 6px; }
.chip button { border: 0; background: none; cursor: pointer; color: var(--muted); padding: 0; }
.composer.drag textarea { border-color: var(--accent); }

/* tables & lists */
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { color: var(--muted); font-weight: 650; font-size: 12px; text-transform: uppercase; letter-spacing: .02em; }
td.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.conv { border-bottom: 1px solid var(--line); padding: 12px 0; }
.conv .q { font-weight: 650; }
.conv .a { white-space: pre-wrap; margin-top: 6px; color: var(--text); }
.conv details summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.edit { margin-top: 10px; display: grid; gap: 8px; }
.empty { color: var(--muted); padding: 30px 0; text-align: center; }

/* login */
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login .card { width: min(380px, 100%); display: grid; gap: 12px; padding: 24px; }
.error { color: var(--bad); font-size: 14px; min-height: 20px; }

@media (max-width: 760px) {
  .shell { grid-template-columns: 1fr; }
  .side { position: static; height: auto; flex-direction: row; flex-wrap: wrap; border-right: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; }
  .brand { width: 100%; padding-bottom: 6px; }
  .side .spacer { display: none; }
  .main { padding: 16px; }
  .chat { height: auto; min-height: 70vh; }
}
.spacer-flex { flex: 1; }
.grow { flex: 1; min-width: 200px; }
textarea.tall { min-height: 200px; font-family: inherit; }
select { border: 1px solid var(--line); background: var(--bg); border-radius: 8px; padding: 8px 10px; max-width: 260px; }
label { display: grid; gap: 4px; font-size: 13px; color: var(--muted); }
label input, label textarea { color: var(--text); font-size: 15px; }
