:root {
  --ink: #15221d;
  --ink-2: #3b4a43;
  --muted: #66736c;
  --forest: #0f2e26;
  --forest-2: #143c32;
  --green: #1e5c49;
  --green-2: #2e7a62;
  --mint: #dcebe3;
  --mint-2: #eef5f1;
  --brass: #b8892b;
  --brass-2: #d9b35e;
  --cream: #f6f3ec;
  --cream-2: #eee9dd;
  --paper: #ffffff;
  --line: #e3ded2;
  --line-dark: rgba(246, 243, 236, 0.14);
  --red: #a63d2f;
  --red-bg: #fbeae6;
  --amber: #9a6b12;
  --amber-bg: #fdf3dc;
  --font-display: "Fraunces", "Iowan Old Style", Georgia, serif;
  --font-body: "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 12px 34px rgba(15, 46, 38, 0.1);
  --shadow-sm: 0 4px 14px rgba(15, 46, 38, 0.06);
  --sidebar: 240px;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--cream);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--green); }
button { font-family: inherit; font-size: inherit; }
h1, h2, h3 { font-family: var(--font-display); font-weight: 600; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 28px; }
h2 { font-size: 20px; }
h3 { font-size: 16px; font-family: var(--font-body); font-weight: 600; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: var(--sidebar) 1fr; min-height: 100vh; }
.sidebar {
  background: var(--forest);
  color: var(--cream);
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 18px; }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--forest-2); display: grid; place-items: center; }
.brand .name { font-weight: 700; letter-spacing: 0.02em; font-size: 15px; }
.brand .sub { font-size: 11px; letter-spacing: 0.14em; text-transform: uppercase; opacity: 0.7; }
.nav a {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  color: rgba(246, 243, 236, 0.82); text-decoration: none; padding: 10px 12px; border-radius: 10px; font-weight: 500;
}
.nav a:hover { background: var(--forest-2); color: #fff; }
.nav a.active { background: var(--green); color: #fff; }
.nav .badge { background: var(--brass-2); color: var(--forest); border-radius: 999px; font-size: 11px; font-weight: 700; padding: 1px 8px; }
.sidebar .foot { margin-top: auto; font-size: 12px; opacity: 0.7; padding: 8px 12px; display: flex; flex-direction: column; gap: 8px; }
.sidebar .foot button { background: transparent; border: 1px solid var(--line-dark); color: var(--cream); padding: 7px 10px; border-radius: 8px; cursor: pointer; }
.main { padding: 28px 32px 60px; max-width: 1240px; width: 100%; }
.topbar { display: none; }

@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; transform: translateX(-100%); transition: transform 0.2s ease; z-index: 50; }
  .sidebar.open { transform: translateX(0); box-shadow: var(--shadow); }
  .topbar { display: flex; align-items: center; justify-content: space-between; padding: 12px 16px; background: var(--forest); color: var(--cream); position: sticky; top: 0; z-index: 40; }
  .topbar button { background: transparent; border: 1px solid var(--line-dark); color: var(--cream); border-radius: 8px; padding: 6px 10px; }
  .main { padding: 18px 16px 40px; }
  h1 { font-size: 24px; }
}

/* ---------- Common ---------- */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.card { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); padding: 18px 20px; }
.card + .card { margin-top: 16px; }
.card h2, .card h3 { margin-bottom: 10px; }
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(auto-fit, minmax(230px, 1fr)); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.tiny { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
.btn {
  display: inline-flex; align-items: center; gap: 8px; border: 1px solid transparent; background: var(--green); color: #fff;
  padding: 9px 14px; border-radius: 10px; font-weight: 600; cursor: pointer; text-decoration: none; line-height: 1.2;
}
.btn:hover { background: var(--green-2); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }
.btn.secondary { background: var(--paper); color: var(--ink); border-color: var(--line); }
.btn.secondary:hover { background: var(--cream); }
.btn.ghost { background: transparent; color: var(--green); }
.btn.danger { background: var(--red); }
.btn.small { padding: 6px 10px; font-size: 13px; border-radius: 8px; }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 2px 9px; border-radius: 999px; font-size: 12px; font-weight: 600; background: var(--cream-2); color: var(--ink-2); }
.pill.ok { background: var(--mint); color: var(--green); }
.pill.warn { background: var(--amber-bg); color: var(--amber); }
.pill.bad { background: var(--red-bg); color: var(--red); }
.pill.info { background: #e8eef7; color: #2f4f7f; }
.notice { padding: 12px 14px; border-radius: var(--radius-sm); background: var(--mint-2); border: 1px solid var(--mint); margin-bottom: 14px; }
.notice.warn { background: var(--amber-bg); border-color: #f1dca3; }
.notice.bad { background: var(--red-bg); border-color: #f0c7c0; }
.empty { color: var(--muted); padding: 22px; text-align: center; border: 1px dashed var(--line); border-radius: var(--radius-sm); }
.spinner { width: 16px; height: 16px; border: 2px solid var(--mint); border-top-color: var(--green); border-radius: 50%; animation: spin 0.8s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }
.toast { position: fixed; bottom: 20px; right: 20px; background: var(--forest); color: var(--cream); padding: 12px 16px; border-radius: 12px; box-shadow: var(--shadow); z-index: 100; max-width: 420px; }
.toast.bad { background: var(--red); }

/* forms */
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; font-weight: 500; color: var(--ink-2); }
input[type="text"], input[type="number"], input[type="password"], input[type="email"], textarea, select {
  font-family: inherit; font-size: 14px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 9px; background: #fff; color: var(--ink); width: 100%;
}
textarea { min-height: 72px; resize: vertical; }
input:focus, textarea:focus, select:focus { outline: 2px solid var(--mint); border-color: var(--green-2); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 12px; }
.switch { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.switch input { width: 18px; height: 18px; accent-color: var(--green); }

/* tables */
table.data { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.data th { text-align: left; font-size: 11.5px; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 9px 10px; border-bottom: 1px solid var(--cream-2); vertical-align: top; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
table.data tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

/* ---------- Login ---------- */
.login { min-height: 100vh; display: grid; place-items: center; padding: 24px; background: radial-gradient(1200px 500px at 20% -10%, var(--mint) 0, transparent 60%), var(--cream); }
.login .card { width: 100%; max-width: 400px; padding: 30px; }
.login h1 { margin-bottom: 6px; }

/* ---------- Dashboard ---------- */
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .v { font-family: var(--font-display); font-size: 24px; font-weight: 600; color: var(--forest); }
.stat .l { font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.account-card .head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; margin-bottom: 12px; }
.metric-row { display: grid; grid-template-columns: 90px repeat(4, 1fr); gap: 6px; font-size: 13px; padding: 6px 0; border-top: 1px solid var(--cream-2); font-variant-numeric: tabular-nums; }
.metric-row.head { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.06em; border-top: 0; }
.metric-row > span:not(:first-child) { text-align: right; }

/* ---------- Chat ---------- */
.chat-layout { display: grid; grid-template-columns: 250px 1fr; gap: 16px; height: calc(100vh - 150px); min-height: 520px; }
.chat-list { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px; overflow-y: auto; }
.chat-list .item { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 8px 10px; border-radius: 8px; cursor: pointer; font-size: 13.5px; }
.chat-list .item:hover { background: var(--cream); }
.chat-list .item.active { background: var(--mint); }
.chat-list .item .t { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-list .item .x { opacity: 0; border: 0; background: transparent; cursor: pointer; color: var(--muted); }
.chat-list .item:hover .x { opacity: 1; }
.chat-main { background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius); display: flex; flex-direction: column; overflow: hidden; }
.chat-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 12px 16px; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.chat-head select { width: auto; min-width: 220px; }
.messages { flex: 1; overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 16px; }
.msg { max-width: 860px; }
.msg.user { align-self: flex-end; background: var(--mint); border-radius: 14px 14px 4px 14px; padding: 10px 14px; white-space: pre-wrap; }
.msg.assistant { align-self: flex-start; }
.msg.assistant .body { background: var(--cream); border-radius: 14px 14px 14px 4px; padding: 12px 16px; }
.msg.assistant .body p:first-child { margin-top: 0; }
.msg.assistant .body p:last-child { margin-bottom: 0; }
.msg.assistant .body table { border-collapse: collapse; margin: 8px 0; font-size: 13px; display: block; overflow-x: auto; max-width: 100%; }
.msg.assistant .body th, .msg.assistant .body td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; white-space: nowrap; }
.msg.assistant .body th { background: var(--cream-2); }
.msg.assistant .body code { background: #fff; padding: 1px 4px; border-radius: 4px; }
.msg.assistant .body pre { background: #fff; padding: 10px; border-radius: 8px; overflow-x: auto; }
.msg .tools { display: flex; flex-direction: column; gap: 3px; margin-bottom: 6px; }
.msg .tools span { font-size: 12px; color: var(--muted); display: flex; gap: 6px; align-items: center; }
.msg .tools span::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--brass-2); }
.proposal-chip { display: inline-flex; gap: 8px; align-items: center; margin-top: 8px; background: #fff; border: 1px solid var(--line); padding: 8px 10px; border-radius: 10px; font-size: 13px; }
.composer { border-top: 1px solid var(--line); padding: 12px 16px; display: flex; gap: 10px; align-items: flex-end; }
.composer textarea { min-height: 48px; max-height: 180px; }
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; }
.suggestions button { background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 7px 12px; cursor: pointer; font-size: 13px; color: var(--ink-2); }
.suggestions button:hover { border-color: var(--green-2); color: var(--green); }
@media (max-width: 900px) {
  .chat-layout { grid-template-columns: 1fr; height: auto; }
  .chat-list { max-height: 160px; }
  .chat-main { min-height: 70vh; }
}

/* ---------- Approvals ---------- */
.tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.tabs button { background: #fff; border: 1px solid var(--line); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-size: 13px; }
.tabs button.active { background: var(--forest); color: #fff; border-color: var(--forest); }
.proposal { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px 16px; background: #fff; margin-bottom: 12px; }
.proposal .top { display: flex; justify-content: space-between; gap: 12px; align-items: flex-start; flex-wrap: wrap; }
.proposal .summary { font-weight: 600; font-size: 15px; }
.proposal .reason { white-space: pre-wrap; color: var(--ink-2); margin: 8px 0; font-size: 14px; }
.proposal details { margin-top: 6px; }
.proposal details summary { cursor: pointer; color: var(--green); font-size: 13px; }
.proposal pre { background: var(--cream); padding: 10px; border-radius: 8px; overflow-x: auto; font-size: 12px; max-height: 320px; }
.proposal .actions { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

/* ---------- Automations ---------- */
.rule { border-top: 1px solid var(--cream-2); padding: 12px 0; }
.rule:first-of-type { border-top: 0; }
.rule .head { display: flex; justify-content: space-between; align-items: center; gap: 10px; }
.rule .desc { font-size: 13px; color: var(--muted); margin: 2px 0 8px; }
.rule .inputs { display: flex; flex-wrap: wrap; gap: 10px; }
.rule .inputs label { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.rule .inputs input { width: 90px; }
.log { background: var(--forest); color: var(--cream); font-size: 12px; padding: 12px; border-radius: 8px; max-height: 300px; overflow: auto; white-space: pre-wrap; font-family: ui-monospace, Menlo, monospace; }

/* ---------- Activity ---------- */
.activity-item { display: grid; grid-template-columns: 150px 90px 1fr; gap: 12px; padding: 9px 0; border-bottom: 1px solid var(--cream-2); font-size: 13.5px; }
.activity-item:last-child { border-bottom: 0; }
@media (max-width: 700px) { .activity-item { grid-template-columns: 1fr; gap: 2px; } }

/* ---------- Settings ---------- */
.step { display: grid; grid-template-columns: 26px 1fr; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--cream-2); font-size: 14px; }
.step:last-child { border-bottom: 0; }
.step .i { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-size: 12px; font-weight: 700; }
.step .i.ok { background: var(--mint); color: var(--green); }
.step .i.bad { background: var(--red-bg); color: var(--red); }
.step .hint { color: var(--amber); font-size: 13px; margin-top: 2px; }
.account-edit { border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 14px; margin-bottom: 12px; background: #fff; }
.account-edit .head { display: flex; justify-content: space-between; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 10px; }
.kbd { font-family: ui-monospace, Menlo, monospace; background: var(--cream); padding: 1px 6px; border-radius: 5px; border: 1px solid var(--line); font-size: 12px; }
