:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f1f3f6;
  --border: #e3e6eb;
  --text: #1b1f27;
  --muted: #667085;
  --accent: #e5484d;
  --accent-ink: #ffffff;
  --accent-soft: #fdecec;
  --ok: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --shadow: 0 1px 2px rgb(16 24 40 / 6%), 0 1px 3px rgb(16 24 40 / 8%);
  --shadow-lg: 0 12px 32px rgb(16 24 40 / 18%);
  --radius: 10px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2b303b;
    --text: #e7e9ee;
    --muted: #9aa3b2;
    --accent-soft: #3a1d1f;
    --shadow: 0 1px 2px rgb(0 0 0 / 40%);
    --shadow-lg: 0 12px 32px rgb(0 0 0 / 55%);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 var(--font); }
[hidden] { display: none !important; }
a { color: inherit; }
button { font: inherit; }

/* ---------- layout ---------- */
.app { display: grid; grid-template-columns: 200px 1fr; height: 100vh; }
.sidebar { background: var(--surface); border-right: 1px solid var(--border); display: flex; flex-direction: column; padding: 16px 12px; gap: 16px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; padding: 0 6px; }
.brand-lg { font-size: 20px; justify-content: center; margin-bottom: 8px; }
.brand-mark { width: 26px; height: 26px; border-radius: 7px; background: var(--accent); position: relative; flex: none; }
.brand-mark::after { content: ""; position: absolute; inset: 7px 8px 5px; border-radius: 50% 50% 45% 45%; background: #fff; opacity: .9; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; }
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.me { margin-top: auto; padding: 10px 6px 0; border-top: 1px solid var(--border); display: flex; flex-direction: column; gap: 6px; }
.me-name { font-weight: 600; }
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.toolbar { display: flex; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--border); background: var(--surface); flex-wrap: wrap; align-items: center; }
.toolbar .search { flex: 1 1 260px; }
.view { flex: 1; min-height: 0; overflow: auto; padding: 16px; }
.view.view-board { padding: 12px 12px 0; overflow: hidden; display: flex; flex-direction: column; }

/* ---------- controls ---------- */
.input { height: 34px; padding: 0 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface); color: var(--text); font: inherit; min-width: 0; }
textarea.input { height: auto; padding: 8px 10px; resize: vertical; min-height: 70px; }
.input:focus, .btn:focus-visible, .card:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.btn { height: 34px; padding: 0 14px; border-radius: 8px; border: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font-weight: 500; white-space: nowrap; display: inline-flex; align-items: center; gap: 6px; text-decoration: none; }
.btn:hover { background: var(--surface-2); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn-primary:hover { background: #d63c41; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-danger { color: var(--danger); }
.btn-sm { height: 28px; padding: 0 10px; font-size: 13px; }
.btn-block { width: 100%; justify-content: center; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); font-weight: 500; }
.field .input { color: var(--text); font-size: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.span-2 { grid-column: span 2; }
.form-error { color: var(--danger); min-height: 1.2em; margin: 4px 0; font-size: 13px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }

.pill { display: inline-flex; align-items: center; height: 20px; padding: 0 7px; border-radius: 999px; font-size: 11px; font-weight: 600; background: var(--surface-2); color: var(--muted); white-space: nowrap; }
.pill-alert { background: var(--danger); color: #fff; }
.src { color: #fff; }
.src-BAFE { background: #2563eb; }
.src-IFE { background: #7c3aed; }
.src-IFPO { background: #0d9488; }
.src-NFRAR { background: #ea580c; }
.src-Manual { background: #475569; }
.prio-high { background: #fee2e2; color: #b91c1c; }
.prio-low { background: var(--surface-2); color: var(--muted); }
.due-overdue { background: #fee2e2; color: #b91c1c; }
.due-today { background: #fef3c7; color: #92400e; }
.due-later { background: #e0f2fe; color: #075985; }
@media (prefers-color-scheme: dark) {
  .prio-high, .due-overdue { background: #4a1d1d; color: #fca5a5; }
  .due-today { background: #44351a; color: #fcd34d; }
  .due-later { background: #13324a; color: #7dd3fc; }
}

/* ---------- board ---------- */
.board-head { display: flex; align-items: center; gap: 10px; padding: 0 4px 10px; }
.board { display: flex; gap: 12px; overflow-x: auto; flex: 1; min-height: 0; padding-bottom: 12px; }
.column { flex: 0 0 280px; display: flex; flex-direction: column; background: var(--surface-2); border-radius: var(--radius); min-height: 0; border-top: 3px solid var(--stage, var(--muted)); }
.column-head { padding: 10px 12px 6px; display: flex; flex-direction: column; gap: 2px; }
.column-title { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.column-title .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--stage); }
.column-meta { font-size: 12px; color: var(--muted); }
.column-body { flex: 1; overflow-y: auto; padding: 4px 8px 8px; display: flex; flex-direction: column; gap: 8px; min-height: 60px; }
.column.drag-over { outline: 2px dashed var(--stage); outline-offset: -2px; }
.card { background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 9px 10px; box-shadow: var(--shadow); cursor: grab; display: flex; flex-direction: column; gap: 5px; user-select: none; }
.card:hover { border-color: var(--muted); }
.card.dragging { opacity: .4; }
.card-title { font-weight: 600; line-height: 1.25; overflow-wrap: anywhere; }
.card-sub { font-size: 12px; color: var(--muted); overflow-wrap: anywhere; }
.card-foot { display: flex; gap: 4px; flex-wrap: wrap; align-items: center; }
.card-foot .owner { margin-left: auto; font-size: 11px; color: var(--muted); }
.drop-marker { height: 4px; border-radius: 2px; background: var(--accent); flex: none; }
.load-more { margin: 2px 0 4px; }

/* ---------- table ---------- */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; color: var(--muted); font-weight: 600; background: var(--surface); position: sticky; top: 0; z-index: 1; white-space: nowrap; }
th.sortable { cursor: pointer; }
th.sorted::after { content: " ↑"; }
th.sorted.desc::after { content: " ↓"; }
tbody tr { cursor: pointer; }
tbody tr:hover { background: var(--surface-2); }
td .stage-chip { display: inline-flex; align-items: center; gap: 6px; }
td .stage-chip::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--stage); }
.bulkbar { display: flex; gap: 8px; align-items: center; padding: 8px 10px; background: var(--accent-soft); border-radius: var(--radius); margin-bottom: 10px; flex-wrap: wrap; }
.pager { display: flex; gap: 8px; align-items: center; justify-content: flex-end; padding: 10px 0; }

/* ---------- dashboard ---------- */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi, .panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px; }
.kpi-label { font-size: 12px; color: var(--muted); font-weight: 500; }
.kpi-value { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.panels { display: grid; grid-template-columns: 1.3fr 1fr; gap: 16px; }
.panel h3 { margin: 0 0 12px; font-size: 14px; }
.funnel-row { display: grid; grid-template-columns: 120px 1fr 60px; gap: 10px; align-items: center; padding: 4px 0; cursor: pointer; }
.funnel-bar { height: 14px; border-radius: 4px; background: var(--stage); min-width: 3px; width: var(--w); }
.funnel-n { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); }
.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.feed li { display: flex; gap: 8px; align-items: baseline; }
.feed a { cursor: pointer; text-decoration: underline; text-decoration-color: var(--border); }

/* ---------- agenda ---------- */
.agenda-group { margin-bottom: 18px; }
.agenda-group h3 { font-size: 13px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0 0 8px; }
.agenda-item { display: grid; grid-template-columns: 24px 110px 1fr auto; gap: 10px; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; margin-bottom: 6px; }
.agenda-item .when { font-variant-numeric: tabular-nums; font-size: 13px; }
.agenda-item .what { min-width: 0; }
.agenda-item .what a { cursor: pointer; font-weight: 600; }

/* ---------- drawer ---------- */
.drawer-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 25%); z-index: 20; }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(640px, 100vw); background: var(--surface); box-shadow: var(--shadow-lg); z-index: 21; transform: translateX(100%); transition: transform .18s ease; display: flex; flex-direction: column; }
.drawer.open { transform: none; }
.drawer-head { padding: 16px 18px 10px; border-bottom: 1px solid var(--border); display: flex; flex-direction: column; gap: 8px; }
.drawer-title { font-size: 18px; font-weight: 700; margin: 0; overflow-wrap: anywhere; }
.drawer-body { flex: 1; overflow-y: auto; padding: 14px 18px 24px; display: flex; flex-direction: column; gap: 14px; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.steps { display: flex; gap: 3px; flex-wrap: wrap; }
.step { flex: 1 1 0; min-width: 52px; height: 26px; border: 0; border-radius: 4px; background: var(--surface-2); color: var(--muted); font-size: 11px; cursor: pointer; padding: 0 4px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.step.done { background: color-mix(in srgb, var(--stage) 30%, var(--surface-2)); color: var(--text); }
.step.current { background: var(--stage); color: #fff; font-weight: 600; }
.guidance { background: var(--surface-2); border-left: 3px solid var(--stage); border-radius: 6px; padding: 8px 10px; font-size: 13px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab { border: 0; background: none; padding: 8px 12px; cursor: pointer; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 500; }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.composer { border: 1px solid var(--border); border-radius: var(--radius); padding: 10px; display: flex; flex-direction: column; gap: 8px; }
.type-switch { display: flex; gap: 4px; flex-wrap: wrap; }
.type-switch button { height: 28px; padding: 0 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); color: var(--muted); cursor: pointer; font-size: 13px; }
.type-switch button.active { background: var(--text); color: var(--surface); border-color: var(--text); }
.timeline { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.tl { display: grid; grid-template-columns: 28px 1fr; gap: 10px; }
.tl-icon { width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center; font-size: 13px; background: var(--surface-2); }
.tl-note .tl-icon { background: #e0e7ff; }
.tl-call .tl-icon { background: #dcfce7; }
.tl-email .tl-icon { background: #e0f2fe; }
.tl-meeting .tl-icon { background: #fef3c7; }
.tl-task .tl-icon { background: #fce7f3; }
@media (prefers-color-scheme: dark) { .tl-note .tl-icon, .tl-call .tl-icon, .tl-email .tl-icon, .tl-meeting .tl-icon, .tl-task .tl-icon { background: var(--surface-2); } }
.tl-card { background: var(--surface-2); border-radius: 8px; padding: 8px 10px; min-width: 0; }
.tl-stage .tl-card { background: none; padding: 4px 0; color: var(--muted); font-size: 12px; }
.tl-head { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.tl-title { font-weight: 600; }
.tl-body { white-space: pre-wrap; overflow-wrap: anywhere; margin-top: 4px; }
.tl-meta { font-size: 12px; color: var(--muted); }
.tl-actions { display: flex; gap: 4px; margin-top: 6px; }
.tl.is-done .tl-title { text-decoration: line-through; color: var(--muted); }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; overflow-wrap: anywhere; white-space: pre-wrap; }

/* ---------- modal / login / toast ---------- */
.modal-backdrop { position: fixed; inset: 0; background: rgb(0 0 0 / 35%); z-index: 30; display: grid; place-items: center; padding: 16px; }
.modal { background: var(--surface); border-radius: 12px; box-shadow: var(--shadow-lg); width: min(560px, 100%); max-height: 90vh; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 12px; }
.modal h2 { margin: 0; font-size: 17px; }
.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 28px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow); }
.toasts { position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 50; }
.toast { background: var(--text); color: var(--surface); padding: 9px 14px; border-radius: 8px; box-shadow: var(--shadow-lg); font-size: 13px; }
.toast.error { background: var(--danger); color: #fff; }
.empty { color: var(--muted); text-align: center; padding: 24px; }
.settings { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; align-items: start; }
.settings form { display: flex; flex-direction: column; gap: 10px; }

@media (max-width: 860px) {
  .app { grid-template-columns: 1fr; grid-template-rows: auto 1fr; }
  .sidebar { flex-direction: row; align-items: center; padding: 8px 12px; overflow-x: auto; }
  .nav { flex-direction: row; }
  .me { margin: 0 0 0 auto; border: 0; padding: 0; flex-direction: row; align-items: center; }
  .panels { grid-template-columns: 1fr; }
  .agenda-item { grid-template-columns: 24px 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}

.mfa { display: flex; flex-direction: column; gap: 8px; }
.mfa p { margin: 0; }
.mfa-qr { display: block; margin: 4px auto; width: 200px; height: 200px; background: #fff; border-radius: 8px; padding: 6px; box-sizing: border-box; }
.mfa-secret { margin-top: 4px; display: block; padding: 8px 10px; background: var(--surface-2); border-radius: 6px; font-size: 15px; letter-spacing: .08em; word-break: break-all; user-select: all; }
.mfa-uri { display: block; margin-top: 4px; word-break: break-all; user-select: all; }
.notice { background: var(--accent-soft); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; }
