:root {
  --bg: #f5f6fa; --panel: #ffffff; --ink: #1b1f2a; --muted: #667085; --line: #e3e6ee;
  --brand: #4f46e5; --brand-ink: #ffffff; --brand-soft: #eceafd; --good: #0f7a4a; --bad: #b42318; --warn: #a15c07;
  --radius: 10px; --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.08);
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0f1117; --panel: #171a23; --ink: #e8eaf1; --muted: #98a2b3; --line: #262b38; --brand: #7c78f5; --brand-ink: #0f1117; --brand-soft: #25234a; --good: #4cc38a; --bad: #f97066; --warn: #f5b04a; --shadow: none; }
}
* { box-sizing: border-box; }
body { margin: 0; font: 14px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--ink); }
h1 { font-size: 22px; margin: 0; } h2 { font-size: 16px; margin: 0 0 12px; } h3 { font-size: 14px; margin: 0 0 8px; }
button, input, select, textarea { font: inherit; color: inherit; }
input, select, textarea { width: 100%; padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--panel); }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--brand); outline-offset: 1px; }
textarea { resize: vertical; min-height: 70px; }
label { display: block; font-weight: 600; font-size: 12px; color: var(--muted); margin: 10px 0 4px; }
.btn { padding: 8px 14px; border-radius: 8px; border: 1px solid var(--line); background: var(--panel); cursor: pointer; font-weight: 600; }
.btn:hover { border-color: var(--brand); }
.btn.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
.btn.danger { color: var(--bad); }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.ghost { border-color: transparent; background: transparent; }
.muted { color: var(--muted); } .small { font-size: 12px; } .right { margin-left: auto; }
.row { display: flex; gap: 10px; align-items: center; } .row.wrap { flex-wrap: wrap; } .col { display: flex; flex-direction: column; gap: 10px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }

/* shell */
.shell { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 16px 12px; position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { display: flex; align-items: center; gap: 8px; font-weight: 800; font-size: 17px; padding: 4px 8px 14px; }
.brand i { width: 26px; height: 26px; border-radius: 7px; background: var(--brand); display: inline-block; }
.nav a { display: block; padding: 8px 10px; border-radius: 8px; color: var(--ink); text-decoration: none; font-weight: 600; }
.nav a:hover { background: var(--bg); } .nav a.active { background: var(--brand-soft); color: var(--brand); }
.nav .sep { height: 1px; background: var(--line); margin: 8px 0; }
.main { padding: 20px 28px 48px; min-width: 0; }
.top { display: flex; align-items: center; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.top select { width: auto; font-weight: 600; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat b { display: block; font-size: 24px; } .stat span { color: var(--muted); font-size: 12px; }

/* tables / lists */
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-size: 12px; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); }
td { padding: 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tr.click { cursor: pointer; } tr.click:hover td { background: var(--bg); }
.tag { display: inline-block; background: var(--brand-soft); color: var(--brand); border-radius: 99px; padding: 1px 9px; font-size: 12px; font-weight: 600; margin: 1px 3px 1px 0; }
.tag button { border: 0; background: none; cursor: pointer; color: inherit; padding: 0 0 0 4px; }
.pill { border-radius: 99px; padding: 1px 9px; font-size: 12px; font-weight: 600; background: var(--bg); }
.pill.good { color: var(--good); } .pill.bad { color: var(--bad); } .pill.warn { color: var(--warn); }
.empty { text-align: center; color: var(--muted); padding: 32px 12px; }

/* kanban */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 8px; align-items: flex-start; }
.lane { flex: 0 0 260px; background: var(--bg); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; min-height: 140px; }
.lane.over { outline: 2px dashed var(--brand); }
.lane h3 { display: flex; justify-content: space-between; }
.opp { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; cursor: grab; box-shadow: var(--shadow); }
.opp b { display: block; } .opp.dragging { opacity: .4; }

/* inbox */
.inbox { display: grid; grid-template-columns: 300px 1fr; gap: 12px; min-height: 480px; }
.convo { padding: 10px; border-bottom: 1px solid var(--line); cursor: pointer; } .convo:hover, .convo.active { background: var(--brand-soft); }
.thread { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; padding: 4px; }
.bubble { max-width: 75%; padding: 8px 12px; border-radius: 14px; background: var(--bg); white-space: pre-wrap; overflow-wrap: anywhere; }
.bubble.out { align-self: flex-end; background: var(--brand); color: var(--brand-ink); }
.bubble.internal { align-self: center; background: #fff6d6; color: #5c4600; font-style: italic; }
.bubble small { display: block; opacity: .7; margin-top: 2px; }

/* drawer + dialog */
.drawer { position: fixed; inset: 0 0 0 auto; width: min(520px, 100%); background: var(--panel); border-left: 1px solid var(--line); box-shadow: -8px 0 24px rgba(0,0,0,.15); padding: 20px; overflow-y: auto; z-index: 20; }
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.3); z-index: 10; }
dialog { border: 1px solid var(--line); border-radius: 14px; padding: 22px; width: min(560px, 94vw); background: var(--panel); color: var(--ink); }
dialog::backdrop { background: rgba(0,0,0,.4); }
.timeline li { list-style: none; border-left: 2px solid var(--line); padding: 0 0 10px 12px; margin-left: 4px; }
.timeline { padding: 0; margin: 0; }

/* workflow editor */
.step { border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin-bottom: 8px; background: var(--bg); }
.step .nested { margin: 8px 0 0 12px; padding-left: 10px; border-left: 3px solid var(--brand-soft); }
.token-hint { font-size: 12px; color: var(--muted); }

/* auth */
.auth { max-width: 380px; margin: 9vh auto; }
.auth .card { padding: 26px; }
#toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: var(--ink); color: var(--bg); padding: 10px 16px; border-radius: 8px; box-shadow: 0 4px 16px rgba(0,0,0,.25); }
.toast.err { background: var(--bad); color: #fff; }
code, pre { font: 12px ui-monospace, Consolas, monospace; background: var(--bg); border-radius: 6px; }
code { padding: 1px 5px; } pre { padding: 10px; overflow-x: auto; margin: 6px 0; }

@media (max-width: 800px) {
  .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); }
  .brand { padding: 4px 8px; } .nav { display: flex; flex-wrap: wrap; } .nav .sep { display: none; }
  .main { padding: 16px; } .inbox { grid-template-columns: 1fr; } .grid2 { grid-template-columns: 1fr; }
}

/* action cells inside tables must stay table cells */
td.row { display: table-cell; text-align: right; white-space: nowrap; }
td.row > * { margin-left: 6px; }
