:root {
  --bg: #f6f7f9; --panel: #ffffff; --ink: #16181d; --muted: #646b78; --line: #e3e6eb; --soft: #f0f2f5;
  --accent: #2357d9; --accent-ink: #ffffff; --accent-soft: #e8eefc;
  --good: #137a3e; --good-soft: #e5f4ea; --warn: #9a5b00; --warn-soft: #fdf1dc; --bad: #b42318; --bad-soft: #fdeceb;
  --radius: 10px; --shadow: 0 1px 2px rgba(16, 24, 40, .06);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; color: var(--ink); background: var(--bg);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115; --panel: #171a20; --ink: #e7e9ee; --muted: #9aa1ad; --line: #2a2f38; --soft: #1e222a;
    --accent: #6d9bff; --accent-ink: #0b1020; --accent-soft: #1c2742;
    --good: #5fd08f; --good-soft: #15291e; --warn: #f1b45b; --warn-soft: #2d2313; --bad: #ff8a80; --bad-soft: #2e1716;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
body { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 20px; margin: 0 0 4px; letter-spacing: -.01em; }
h2 { font-size: 15px; margin: 0 0 10px; }
h3 { font-size: 13px; margin: 0 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; }
.hidden { display: none !important; }

/* layout */
.app { display: grid; grid-template-columns: 220px 1fr; min-height: 100vh; }
.side { background: var(--panel); border-right: 1px solid var(--line); padding: 18px 12px; position: sticky; top: 0;
        height: 100vh; display: flex; flex-direction: column; gap: 4px; }
.brand { font-weight: 700; font-size: 15px; padding: 4px 10px 16px; }
.brand span { color: var(--accent); }
.nav a { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; color: var(--ink); }
.nav a:hover { background: var(--soft); text-decoration: none; }
.nav a.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }
.nav .count { margin-left: auto; font-size: 11px; background: var(--soft); border-radius: 10px; padding: 1px 7px;
              color: var(--muted); }
.nav .count:empty { display: none; }
.side .who { margin-top: auto; padding: 10px; border-top: 1px solid var(--line); font-size: 12px; }
main { padding: 24px 28px 60px; max-width: 1400px; width: 100%; }
.head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 18px;
        flex-wrap: wrap; }

/* cards */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px;
        box-shadow: var(--shadow); }
.grid { display: grid; gap: 14px; align-items: start; }
.activity { max-height: 640px; overflow-y: auto; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: 2fr 1fr; }
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .v { font-size: 26px; font-weight: 700; letter-spacing: -.02em; }
.kpi .l { color: var(--muted); font-size: 12px; margin-top: 2px; }
@media (max-width: 900px) { .app { grid-template-columns: 1fr; } .side { position: static; height: auto; }
  .g2, .g3 { grid-template-columns: 1fr; } main { padding: 16px; } }

/* controls */
button, .btn { font: inherit; border: 1px solid var(--line); background: var(--panel); color: var(--ink);
               padding: 7px 12px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; }
button:hover { background: var(--soft); }
button.primary, .btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
button.primary:hover, .btn.primary:hover { filter: brightness(1.05); text-decoration: none; }
.btn:hover { text-decoration: none; background: var(--soft); }
button.danger { color: var(--bad); }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--ink); background: var(--panel); border: 1px solid var(--line);
                          border-radius: 8px; padding: 7px 10px; }
input:focus, select:focus, textarea:focus, button:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
textarea.code { width: 100%; min-height: 520px; font-family: ui-monospace, Consolas, monospace; font-size: 12.5px;
                line-height: 1.45; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); border-radius: 999px; padding: 4px 11px; font-size: 12.5px; cursor: pointer;
        background: var(--panel); }
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.chip .n { opacity: .75; margin-left: 4px; }
.badge { display: inline-block; font-size: 11.5px; padding: 1px 8px; border-radius: 999px; background: var(--soft);
         color: var(--muted); white-space: nowrap; }
.badge.good { background: var(--good-soft); color: var(--good); }
.badge.warn { background: var(--warn-soft); color: var(--warn); }
.badge.bad { background: var(--bad-soft); color: var(--bad); }
.badge.acc { background: var(--accent-soft); color: var(--accent); }

/* tables */
.tablewrap { overflow: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--panel); }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { font-size: 12px; color: var(--muted); font-weight: 600; position: sticky; top: 0; background: var(--panel);
     cursor: pointer; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--soft); }
td.num { text-align: right; font-variant-numeric: tabular-nums; }
.clip { max-width: 360px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.role { font-weight: 600; }

/* funnel */
.funnel { display: flex; flex-direction: column; gap: 6px; }
.fstage { display: grid; grid-template-columns: 260px 1fr 70px; gap: 12px; align-items: center; cursor: pointer;
          padding: 4px 6px; border-radius: 8px; }
.fstage:hover, .fstage.on { background: var(--soft); }
.fbar { height: 18px; background: var(--soft); border-radius: 5px; overflow: hidden; display: flex; }
.fbar .done { background: var(--accent); }
.fbar .proj { background: repeating-linear-gradient(45deg, var(--accent), var(--accent) 4px, transparent 4px,
              transparent 8px); opacity: .55; }
.fstage .n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.reasons { margin: 2px 0 8px 272px; display: flex; flex-wrap: wrap; gap: 6px; }

/* tooltip */
.tip { position: relative; display: inline-flex; width: 16px; height: 16px; border-radius: 50%;
       border: 1px solid var(--muted); color: var(--muted); font-size: 10.5px; font-weight: 700; align-items: center;
       justify-content: center; cursor: help; margin-left: 6px; flex: none; font-style: normal; }
.tip .bubble { display: none; position: absolute; left: 22px; top: -6px; z-index: 30; width: 320px;
               background: var(--ink); color: var(--panel); padding: 10px 12px; border-radius: 8px; font-weight: 400;
               font-size: 12.5px; line-height: 1.45; box-shadow: 0 6px 24px rgba(0, 0, 0, .2); }
.tip:hover .bubble, .tip:focus .bubble { display: block; }

/* settings */
.setting { display: grid; grid-template-columns: minmax(220px, 1fr) 260px 140px; gap: 12px; align-items: center;
           padding: 10px 0; border-bottom: 1px solid var(--line); }
.setting:last-child { border-bottom: 0; }
.setting .lab { display: flex; align-items: center; font-weight: 500; }
.setting input[type=text], .setting input[type=number], .setting input[type=password], .setting select { width: 100%; }
.setting.changed { background: linear-gradient(90deg, var(--accent-soft), transparent 70%); }
.savebar { position: sticky; bottom: 0; background: var(--panel); border-top: 1px solid var(--line); padding: 12px 16px;
           display: flex; justify-content: space-between; align-items: center; margin-top: 14px; border-radius: var(--radius); }

/* kanban */
.kanban { display: grid; grid-template-columns: repeat(7, minmax(220px, 1fr)); gap: 10px; overflow-x: auto; }
.col { background: var(--soft); border-radius: var(--radius); padding: 8px; min-height: 200px; }
.col h2 { font-size: 13px; display: flex; justify-content: space-between; padding: 4px 4px 8px; margin: 0; }
.col.drop { outline: 2px dashed var(--accent); }
.kcard { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; margin-bottom: 7px;
         cursor: grab; }
.kcard .c { font-size: 12px; color: var(--muted); }

/* drawer / modal */
.drawer { position: fixed; top: 0; right: 0; width: min(720px, 100%); height: 100vh; background: var(--panel);
          border-left: 1px solid var(--line); box-shadow: -8px 0 30px rgba(0, 0, 0, .12); z-index: 40;
          overflow-y: auto; padding: 22px; }
.scrim { position: fixed; inset: 0; background: rgba(10, 12, 16, .35); z-index: 35; }
.desc { white-space: pre-wrap; font-size: 13px; line-height: 1.5; background: var(--soft); padding: 12px;
        border-radius: 8px; max-height: 360px; overflow: auto; }
.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 12px; font-size: 13px; }
.kv div:nth-child(odd) { color: var(--muted); }

/* run log */
.log { background: #0d1117; color: #c9d1d9; font-family: ui-monospace, Consolas, monospace; font-size: 12px;
       padding: 10px 12px; border-radius: 8px; max-height: 260px; overflow: auto; white-space: pre-wrap; }

/* auth */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.auth .card { width: min(420px, 100%); padding: 26px; }
.auth label { display: block; font-size: 12.5px; color: var(--muted); margin: 12px 0 4px; }
.auth input { width: 100%; }
.error { color: var(--bad); font-size: 13px; margin-top: 10px; }
.toast { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); background: var(--ink); color: var(--panel);
         padding: 9px 16px; border-radius: 8px; z-index: 60; font-size: 13px; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
