:root {
  --bg: #14151a;
  --panel: #1b1d24;
  --panel-2: #212430;
  --line: #2c3040;
  --text: #e6e8ee;
  --muted: #9098ab;
  --accent: #f0b429;
  --accent-soft: #3a2f14;
  --good: #4ec9a5;
  --bad: #f2777a;
  --radius: 12px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font: 15px/1.55 ui-sans-serif, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  -webkit-text-size-adjust: 100%;
}

.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.error { color: var(--bad); min-height: 1.2em; margin: 4px 0; font-size: 13px; }

button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border-radius: 9px; border: 1px solid var(--line); background: var(--panel-2); padding: 8px 14px; }
button:hover { border-color: #3c4256; }
button.primary { background: var(--accent); color: #1b1400; border-color: var(--accent); font-weight: 600; }
button.primary:hover { filter: brightness(1.08); }
button.primary:disabled { opacity: .55; cursor: progress; }
button.ghost, a.ghost { background: transparent; border: 1px solid var(--line); color: var(--muted);
  padding: 7px 12px; border-radius: 9px; text-decoration: none; font-size: 13.5px; }
button.ghost:hover, a.ghost:hover { color: var(--text); }
button.danger:hover { color: var(--bad); border-color: var(--bad); }
button.icon { background: none; border: none; font-size: 18px; padding: 4px 8px; color: var(--muted); }
button.link { background: none; border: none; color: var(--muted); text-decoration: underline; padding: 0; font-size: 13px; }

input, textarea {
  width: 100%; background: var(--bg); border: 1px solid var(--line);
  border-radius: 9px; padding: 10px 12px;
}
input:focus, textarea:focus { outline: none; border-color: var(--accent); }
textarea { resize: vertical; }

/* ------------------------------------------------------------------ auth */
.auth { min-height: 100%; display: grid; place-items: center; padding: 24px; }
.auth-card { width: 100%; max-width: 380px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 16px; padding: 26px; }
.auth-card h1 { margin: 0 0 6px; font-size: 22px; }
.auth-card p { margin: 0 0 18px; font-size: 14px; }
.auth-card label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
.auth-card label input { margin-top: 5px; }
.auth-card .primary { width: 100%; }
.tabs { display: flex; gap: 6px; margin-bottom: 16px; }
.tab { flex: 1; background: transparent; border: 1px solid var(--line); color: var(--muted); padding: 7px; font-size: 13.5px; }
.tab.active { background: var(--panel-2); color: var(--text); border-color: #3c4256; }

/* ------------------------------------------------------------------- app */
.app { display: grid; grid-template-columns: 250px 1fr; height: 100%; }

#sidebar {
  background: var(--panel); border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-height: 0;
}
.side-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 14px 10px; }
.logo { font-weight: 600; font-size: 14px; letter-spacing: .2px; }
#closeSidebar { display: none; }
.project-list { flex: 1; overflow-y: auto; padding: 0 8px; }
.project-item { display: block; width: 100%; text-align: left; background: none; border: none;
  padding: 9px 10px; border-radius: 9px; margin-bottom: 2px; }
.project-item:hover { background: var(--panel-2); }
.project-item.active { background: var(--panel-2); box-shadow: inset 2px 0 0 var(--accent); }
.project-item .pname { display: block; font-size: 14px; }
.project-item .pmeta { display: block; font-size: 11.5px; color: var(--muted); }
.new-project { display: flex; gap: 6px; padding: 10px; border-top: 1px solid var(--line); }
.new-project input { font-size: 13px; padding: 7px 9px; }
.side-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 14px 14px; border-top: 1px solid var(--line); }
.side-foot span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

main { overflow-y: auto; min-height: 0; padding: 0 20px 60px; }
.topbar { position: sticky; top: 0; z-index: 5; background: var(--bg);
  display: flex; align-items: center; gap: 12px; padding: 16px 0 12px; border-bottom: 1px solid var(--line); }
#openSidebar { display: none; }
.topbar-title { flex: 1; min-width: 0; }
.topbar-title h2 { margin: 0; font-size: 18px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-title span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-actions { display: flex; gap: 8px; flex-shrink: 0; }

/* --------------------------------------------------------------- capture */
.capture { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; margin: 16px 0 20px; }
.capture textarea { background: var(--bg); }
.capture-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 10px; }
.notice { margin: 10px 0 0; padding: 9px 11px; border-radius: 9px; background: var(--accent-soft);
  border: 1px solid #4b3d1a; font-size: 13.5px; }
.notice.bad { background: #3a1f21; border-color: #5d2b2e; color: #ffc9ca; }

/* ------------------------------------------------------------- decisions */
.pane-title { font-size: 12px; letter-spacing: .8px; text-transform: uppercase; color: var(--muted);
  margin: 22px 0 10px; }
.decision { background: var(--panel); border: 1px solid #4b3d1a; border-left: 3px solid var(--accent);
  border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.decision .q { font-weight: 600; margin-bottom: 2px; }
.decision .for { font-size: 12px; color: var(--muted); margin-bottom: 10px; }
.options { display: flex; flex-wrap: wrap; gap: 8px; }
.option { display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 9px; padding: 8px 12px; text-align: left; }
.option.sel { border-color: var(--accent); background: var(--accent-soft); }
.option .ol { font-size: 14px; }
.option .on { font-size: 11.5px; color: var(--muted); }
.option .rec { color: var(--accent); font-size: 11px; }
.decision-actions { display: flex; gap: 8px; align-items: center; margin-top: 12px; }

/* ---------------------------------------------------------- requirements */
.cat { margin: 26px 0 10px; font-size: 13px; font-weight: 600; color: var(--accent); letter-spacing: .3px; }
.req { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 13px 15px; margin-bottom: 9px; }
.req.done { opacity: .6; }
.req-head { display: flex; align-items: flex-start; gap: 10px; }
.req-title { flex: 1; font-weight: 600; }
.req-detail { color: #c3c8d6; font-size: 14px; margin-top: 5px; white-space: pre-wrap; }
.ref { font: 600 11.5px/1 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .4px;
  border: 1px solid var(--line); border-radius: 5px; padding: 3px 6px; margin-right: 2px;
  vertical-align: 1px; color: var(--muted); }
.ref.fr { color: var(--accent); border-color: #6b4a1c; }
.ref.nfr { color: var(--good); border-color: #2b5d4d; }
.acceptance { margin-top: 9px; border-left: 2px solid var(--line); padding-left: 11px; }
.acc-title { font-size: 11px; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); margin-bottom: 3px; }
.acceptance ul { margin: 0; padding-left: 17px; }
.acceptance li { font-size: 13.5px; color: #b6bccb; margin-bottom: 2px; }
.req-actions { display: flex; gap: 6px; flex-shrink: 0; }
.req-actions button { padding: 3px 8px; font-size: 12px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 9px; }
.chip { font-size: 11.5px; padding: 2px 8px; border-radius: 999px; border: 1px solid var(--line); color: var(--muted); }
.chip.must { border-color: #6b4a1c; color: var(--accent); }
.chip.resolved { border-color: #2b5d4d; color: var(--good); }
.chip.open-q { border-color: #6b4a1c; color: var(--accent); }
.empty { color: var(--muted); text-align: center; padding: 40px 20px; font-size: 14px; }

/* --------------------------------------------------------------- diagram */
button.ghost.accent { color: var(--accent); border-color: #6b4a1c; }
button.ghost.accent:hover { background: var(--accent-soft); }

.overlay { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: flex; flex-direction: column; }
.dg-bar { display: flex; align-items: center; gap: 12px; padding: 10px 14px;
  border-bottom: 1px solid var(--line); background: var(--panel); }
.dg-heading { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.dg-heading strong { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dg-heading span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dg-tools { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
.dg-tools .ghost { padding: 6px 10px; font-size: 13px; }

.dg-stage { position: relative; flex: 1; min-height: 0; overflow: hidden; }
.dg-canvas { position: absolute; inset: 0; touch-action: none;
  background-image: radial-gradient(#23262f 1px, transparent 1px); background-size: 22px 22px; }
.dg-canvas svg { display: block; width: 100%; height: 100%; }

.dg-legend { position: absolute; left: 12px; bottom: 12px; display: flex; flex-wrap: wrap; gap: 10px;
  background: #1b1d24dd; border: 1px solid var(--line); border-radius: 10px; padding: 7px 10px; }
.dg-key { display: inline-flex; align-items: center; gap: 6px; font-size: 11.5px; color: var(--muted); }
.dg-key i { width: 9px; height: 9px; border-radius: 3px; display: inline-block; background: var(--muted); }
.dg-key.t-actor i { background: #7fb3ff; } .dg-key.t-feature i { background: #f0b429; }
.dg-key.t-process i { background: #4ec9a5; } .dg-key.t-data i { background: #9098ab; }
.dg-key.t-external i { background: #f2a6a8; }

.dg-panel { position: absolute; top: 12px; right: 12px; bottom: 12px; width: 330px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; }
.dg-panel h3 { margin: 6px 0 2px; font-size: 16px; }
.dgp-head { display: flex; align-items: center; justify-content: space-between; }
.dgp-type { font-size: 10px; letter-spacing: .7px; text-transform: uppercase; font-weight: 600; }
.dgp-type.t-actor { color: #7fb3ff; } .dgp-type.t-feature { color: #f0b429; }
.dgp-type.t-process { color: #4ec9a5; } .dgp-type.t-data { color: #9098ab; }
.dgp-type.t-external { color: #f2a6a8; }
.dgp-note { color: #c3c8d6; font-size: 13.5px; margin: 8px 0 0; }
.dg-panel .pane-title { margin: 16px 0 8px; }
.dgp-req { border: 1px solid var(--line); border-radius: 10px; padding: 10px; margin-bottom: 8px; }
.dgp-req-head { font-weight: 600; font-size: 13.5px; }
.dgp-req-body { font-size: 13px; color: #b6bccb; margin-top: 5px; }
.dgp-acc { margin: 6px 0 0; padding-left: 16px; }
.dgp-acc li { font-size: 12.5px; color: #a8aec0; }
.dg-panel .chip { display: inline-block; margin: 6px 4px 0 0; }

.dg-status { position: absolute; left: 50%; top: 16px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 9px 14px; font-size: 13.5px; max-width: 82vw; text-align: center; }
.dg-status:empty { display: none; }
.dg-status.bad { border-color: #5d2b2e; color: #ffc9ca; }

@media (max-width: 760px) {
  .dg-heading strong { font-size: 14px; }
  .dg-tools .ghost { padding: 5px 8px; font-size: 12px; }
  .dg-panel { top: auto; left: 10px; right: 10px; bottom: 10px; width: auto; max-height: 52%; }
  .dg-legend { left: 10px; bottom: auto; top: 10px; padding: 5px 8px; gap: 8px; }
}

/* ----------------------------------------------------------------- toast */
.toast { position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%);
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; font-size: 13.5px; z-index: 50; max-width: 90vw; }

/* ---------------------------------------------------------------- mobile */
#scrim { display: none; }
@media (max-width: 760px) {
  .app { grid-template-columns: 1fr; }
  #sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 20; transform: translateX(-100%);
    transition: transform .18s ease; }
  body.nav-open #sidebar { transform: none; }
  body.nav-open #scrim { display: block; position: fixed; inset: 0; background: #0009; z-index: 15; }
  #closeSidebar, #openSidebar { display: block; }
  main { padding: 0 14px 60px; }
  .topbar-actions a.ghost, .topbar-actions button.ghost { padding: 6px 9px; font-size: 12.5px; }
}
