:root {
  --ground: #f5f7fa;
  --surface: #ffffff;
  --card: #ffffff;
  --ink: #1a1f2b;
  --muted: #5b6472;
  --faint: #8a92a2;
  --border: #e4e8ef;
  --border-strong: #d3d9e3;
  --accent: #4f5bd5;
  --accent-soft: #eef0fc;
  --accent-ink: #3742b0;
  --good: #16a34a;
  --warn: #d97706;
  --high: #ea580c;
  --crit: #dc2626;
  --shadow: 0 1px 2px rgba(20,26,40,.06), 0 4px 12px rgba(20,26,40,.05);
  --shadow-lift: 0 6px 24px rgba(20,26,40,.14);
  --col-gap: 16px;
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ground: #0f1218; --surface: #161a22; --card: #1b212c;
    --ink: #e7eaf1; --muted: #99a2b2; --faint: #6b7484;
    --border: #262d39; --border-strong: #333c4b;
    --accent: #808bf2; --accent-soft: #20263c; --accent-ink: #aab2f7;
    --good: #34d17f; --warn: #e0a33a; --high: #f4813f; --crit: #f0616b;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.25);
    --shadow-lift: 0 8px 30px rgba(0,0,0,.5);
  }
}
:root[data-theme="light"] {
  --ground: #f5f7fa; --surface: #ffffff; --card: #ffffff;
  --ink: #1a1f2b; --muted: #5b6472; --faint: #8a92a2;
  --border: #e4e8ef; --border-strong: #d3d9e3;
  --accent: #4f5bd5; --accent-soft: #eef0fc; --accent-ink: #3742b0;
  --good: #16a34a; --warn: #d97706; --high: #ea580c; --crit: #dc2626;
  --shadow: 0 1px 2px rgba(20,26,40,.06), 0 4px 12px rgba(20,26,40,.05);
  --shadow-lift: 0 6px 24px rgba(20,26,40,.14);
}
:root[data-theme="dark"] {
  --ground: #0f1218; --surface: #161a22; --card: #1b212c;
  --ink: #e7eaf1; --muted: #99a2b2; --faint: #6b7484;
  --border: #262d39; --border-strong: #333c4b;
  --accent: #808bf2; --accent-soft: #20263c; --accent-ink: #aab2f7;
  --good: #34d17f; --warn: #e0a33a; --high: #f4813f; --crit: #f0616b;
  --shadow: 0 1px 2px rgba(0,0,0,.3), 0 4px 12px rgba(0,0,0,.25);
  --shadow-lift: 0 8px 30px rgba(0,0,0,.5);
}

* { box-sizing: border-box; }
body {
  margin: 0; background: var(--ground); color: var(--ink);
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased; font-size: 14px; line-height: 1.45;
}
.wrap { max-width: 1360px; margin: 0 auto; padding: 22px 20px 40px; }

/* ── Top bar ── */
.top { display: flex; align-items: baseline; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 16px; }
.brand { display: flex; align-items: baseline; gap: 10px; }
.brand h1 { font-size: 19px; font-weight: 650; letter-spacing: -0.01em; margin: 0; }
.brand .sub { color: var(--faint); font-size: 12.5px; }
.top-right { display: flex; align-items: center; gap: 12px; }
.whoami { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 8px; }
.whoami .av { width: 24px; height: 24px; border-radius: 7px; display: grid; place-items: center; font-size: 10px; font-weight: 650; color: #fff; }
.badge-l3 { font-size: 10.5px; font-weight: 700; letter-spacing: .04em; color: #fff; background: var(--crit); border-radius: 5px; padding: 1px 6px; }
.refreshed { font-size: 11.5px; color: var(--faint); font-variant-numeric: tabular-nums; }
.icon-btn, .text-btn {
  font: inherit; font-size: 12.5px; font-weight: 600; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 11px; cursor: pointer;
}
.icon-btn:hover, .text-btn:hover { color: var(--ink); border-color: var(--border-strong); }

/* ── L3 panel ── */
.l3 { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 15px 18px 16px; margin: 0 0 2px; box-shadow: var(--shadow); }
.l3-head { display: flex; align-items: center; gap: 9px; margin-bottom: 15px; }
.l3-head .sev { width: 8px; height: 8px; border-radius: 50%; background: var(--crit); flex: none; box-shadow: 0 0 0 3px color-mix(in srgb, var(--crit) 20%, transparent); }
.l3-head .t { font-size: 13.5px; font-weight: 650; }
.l3-head .lock { font-size: 11px; color: var(--faint); display: inline-flex; align-items: center; gap: 4px; }
.l3-head a { margin-left: auto; font-size: 12px; color: var(--accent-ink); text-decoration: none; font-weight: 600; }
.l3-head a:hover { text-decoration: underline; }
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 15px; }
.kpi { background: var(--ground); border: 1px solid var(--border); border-radius: 10px; padding: 11px 13px; display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.kpi .l { font-size: 10.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.kpi .row { display: flex; align-items: flex-end; gap: 8px; justify-content: space-between; }
.kpi .v { font-size: 25px; font-weight: 680; letter-spacing: -.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.kpi .d { font-size: 11px; font-weight: 600; color: var(--muted); }
.l3-sub { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); font-weight: 650; margin-bottom: 9px; }
.l3-errs { display: flex; flex-direction: column; gap: 9px; }
.err { display: flex; align-items: center; gap: 10px; }
.err .sd { width: 7px; height: 7px; border-radius: 50%; flex: none; }
.err .sd.error { background: var(--crit); } .err .sd.warn { background: var(--warn); }
.err .title { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 11.5px; color: var(--ink); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; min-width: 0; }
.err .proj { font-size: 10px; font-weight: 600; color: var(--muted); background: var(--surface); border: 1px solid var(--border); border-radius: 5px; padding: 1px 6px; flex: none; }
.err .cnt { font-size: 11.5px; color: var(--ink); font-weight: 600; font-variant-numeric: tabular-nums; flex: none; min-width: 34px; text-align: right; }
.err .seen { font-size: 11px; color: var(--faint); flex: none; white-space: nowrap; font-variant-numeric: tabular-nums; }
.l3-note { font-size: 12px; color: var(--muted); }
@media (max-width: 720px) { .kpis { grid-template-columns: repeat(2, 1fr); } }

/* ── Filters ── */
.filters { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin: 16px 0 18px; }
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 2px; }
.seg button {
  font: inherit; font-size: 12.5px; font-weight: 550; color: var(--muted);
  background: transparent; border: 0; padding: 5px 12px; border-radius: 7px; cursor: pointer;
  transition: background .12s, color .12s;
}
.seg button:hover { color: var(--ink); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; box-shadow: var(--shadow); }
.search {
  flex: 1 1 200px; max-width: 300px; display: flex; align-items: center; gap: 8px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 7px 12px;
}
.search input { border: 0; background: transparent; color: var(--ink); font: inherit; font-size: 13px; width: 100%; outline: none; }
.search input::placeholder { color: var(--faint); }
.search svg { flex: none; color: var(--faint); }
.filter-label { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--faint); font-weight: 600; margin-right: 2px; }

/* ── Board ── */
.board { display: grid; grid-template-columns: repeat(4, minmax(240px, 1fr)); gap: var(--col-gap); align-items: start; overflow-x: auto; padding-bottom: 8px; }
.col { background: transparent; min-width: 0; }
.col-head { display: flex; align-items: center; gap: 8px; padding: 2px 4px 12px; position: sticky; top: 0; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.col[data-status="new"] .dot { background: var(--accent); }
.col[data-status="in_progress"] .dot { background: var(--warn); }
.col[data-status="waiting"] .dot { background: var(--faint); }
.col[data-status="resolved"] .dot { background: var(--good); }
.col-head .name { font-size: 12.5px; font-weight: 650; letter-spacing: .01em; }
.col-head .count {
  font-size: 11.5px; font-weight: 600; color: var(--muted); background: var(--surface);
  border: 1px solid var(--border); border-radius: 999px; padding: 1px 8px; font-variant-numeric: tabular-nums;
}
.col-body { display: flex; flex-direction: column; gap: 10px; min-height: 60px; border-radius: var(--radius); padding: 2px; transition: background .12s, outline-color .12s; outline: 2px dashed transparent; outline-offset: -2px; }
.col-body.drop-target { background: var(--accent-soft); outline-color: var(--accent); }

/* ── Card ── */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 13px 11px; cursor: pointer; text-align: left; width: 100%; font: inherit; color: inherit;
  box-shadow: var(--shadow); transition: transform .12s, box-shadow .12s, border-color .12s, opacity .12s;
  display: flex; flex-direction: column; gap: 9px; position: relative;
}
.card:hover { transform: translateY(-2px); box-shadow: var(--shadow-lift); border-color: var(--border-strong); }
.card:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card.dragging { opacity: .45; cursor: grabbing; }
.card::before {
  content: ""; position: absolute; left: 0; top: 12px; bottom: 12px; width: 3px; border-radius: 3px;
}
.card[data-pri="urgent"]::before { background: var(--crit); }
.card[data-pri="high"]::before { background: var(--high); }
.card[data-pri="medium"]::before { background: var(--warn); }
.card[data-pri="low"]::before, .card:not([data-pri])::before { background: transparent; }

.card-top { display: flex; align-items: center; gap: 9px; }
.avatar { width: 26px; height: 26px; border-radius: 7px; flex: none; display: grid; place-items: center; font-size: 11px; font-weight: 650; color: #fff; letter-spacing: .01em; }
.cust { font-weight: 600; font-size: 13px; line-height: 1.25; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card-top .time { margin-left: auto; font-size: 11px; color: var(--faint); font-variant-numeric: tabular-nums; white-space: nowrap; }

.section-pill {
  align-self: flex-start; display: inline-flex; align-items: center; gap: 5px;
  background: var(--accent-soft); color: var(--accent-ink); border-radius: 6px;
  font-size: 11px; font-weight: 600; padding: 2px 8px; letter-spacing: .01em;
}
.section-pill::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: currentColor; opacity: .7; }

.msg { font-size: 12.5px; color: var(--muted); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

.meta { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chip { font-size: 10.5px; font-weight: 600; letter-spacing: .02em; border-radius: 5px; padding: 2px 7px; border: 1px solid var(--border); color: var(--muted); background: var(--surface); }
.chip.line { text-transform: uppercase; letter-spacing: .06em; }
.chip.pri { border: 0; color: #fff; }
.pri-urgent { background: var(--crit); } .pri-high { background: var(--high); } .pri-medium { background: var(--warn); }
.pri-low { background: var(--surface) !important; color: var(--muted) !important; border: 1px solid var(--border) !important; }
.chip.ai { color: var(--accent-ink); background: var(--accent-soft); border-color: transparent; display: inline-flex; align-items: center; gap: 4px; }
.chip.ai::before { content: ""; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.assignee { margin-left: auto; display: inline-flex; align-items: center; gap: 6px; font-size: 11px; color: var(--muted); }
.assignee .av { width: 20px; height: 20px; border-radius: 6px; font-size: 9.5px; }

.empty { color: var(--faint); font-size: 12px; text-align: center; padding: 18px 0; border: 1px dashed var(--border); border-radius: var(--radius); }

/* ── Drawer ── */
.scrim { position: fixed; inset: 0; background: rgba(12,15,22,.42); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 40; }
.scrim.open { opacity: 1; pointer-events: auto; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100%; width: min(430px, 94vw);
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lift);
  transform: translateX(100%); transition: transform .24s cubic-bezier(.32,.72,0,1); z-index: 41;
  display: flex; flex-direction: column;
}
.drawer.open { transform: none; }
.dr-head { padding: 18px 20px 14px; border-bottom: 1px solid var(--border); display: flex; gap: 12px; align-items: flex-start; }
.dr-head .avatar { width: 38px; height: 38px; border-radius: 9px; font-size: 14px; }
.dr-head h2 { margin: 0; font-size: 16px; font-weight: 650; }
.dr-head .who { font-size: 12px; color: var(--faint); margin-top: 2px; }
.dr-close { margin-left: auto; background: transparent; border: 1px solid var(--border); color: var(--muted); border-radius: 8px; width: 30px; height: 30px; cursor: pointer; font-size: 16px; line-height: 1; flex: none; }
.dr-close:hover { color: var(--ink); border-color: var(--border-strong); }
.dr-body { padding: 16px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.dr-meta { display: flex; flex-wrap: wrap; gap: 6px; }
.dr-sec-label { font-size: 10.5px; text-transform: uppercase; letter-spacing: .09em; color: var(--faint); font-weight: 650; margin-bottom: 7px; }
.thread { display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 82%; padding: 8px 12px; border-radius: 12px; font-size: 12.5px; line-height: 1.4; white-space: pre-wrap; word-wrap: break-word; }
.bubble.cx { align-self: flex-start; background: var(--ground); border: 1px solid var(--border); border-bottom-left-radius: 4px; }
.bubble.bot { align-self: flex-end; background: var(--accent); color: #fff; border-bottom-right-radius: 4px; }
.bubble.priv { align-self: flex-end; background: color-mix(in srgb, var(--warn) 16%, var(--surface)); color: var(--ink); border: 1px solid var(--warn); border-bottom-right-radius: 4px; }
.bubble .b-who { font-size: 10px; text-transform: uppercase; letter-spacing: .06em; opacity: .7; margin-bottom: 3px; }
.dr-foot { margin-top: auto; padding: 14px 20px; border-top: 1px solid var(--border); display: flex; gap: 10px; }
.btn { font: inherit; font-size: 13px; font-weight: 600; border-radius: 9px; padding: 9px 14px; cursor: pointer; border: 1px solid var(--border); background: var(--surface); color: var(--ink); }
.btn:hover { border-color: var(--border-strong); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 7px; text-decoration: none; }
.btn.primary:hover { filter: brightness(1.05); }

/* ── Login ── */
.login-scrim { position: fixed; inset: 0; background: var(--ground); display: grid; place-items: center; z-index: 60; padding: 20px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow-lift); padding: 28px 26px; width: min(360px, 100%); display: flex; flex-direction: column; gap: 14px; }
.login-card h1 { margin: 0; font-size: 18px; font-weight: 680; }
.login-card .sub { color: var(--muted); font-size: 13px; margin: -6px 0 4px; }
.login-card label { font-size: 12px; font-weight: 600; color: var(--muted); display: flex; flex-direction: column; gap: 5px; }
.login-card input { font: inherit; font-size: 14px; padding: 9px 12px; border-radius: 9px; border: 1px solid var(--border); background: var(--ground); color: var(--ink); outline: none; }
.login-card input:focus { border-color: var(--accent); }
.login-card .err-msg { color: var(--crit); font-size: 12.5px; min-height: 16px; }
.login-card .btn.primary { flex: none; padding: 10px; }

/* ── Toast ── */
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%) translateY(20px); background: var(--ink); color: var(--surface); font-size: 13px; font-weight: 550; padding: 10px 18px; border-radius: 10px; box-shadow: var(--shadow-lift); opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; z-index: 70; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.err { background: var(--crit); color: #fff; }

.hidden { display: none !important; }
@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }
@media (max-width: 720px) { .board { grid-template-columns: repeat(4, 260px); } }
