/* System Action History — dark, Obsidian-adjacent. */

:root {
  --bg: #131519;
  --bg-2: #181b21;
  --panel: #1c2027;
  --panel-2: #222731;
  --border: #2b313b;
  --border-soft: #232830;
  --text: #e6e9ee;
  --muted: #8d96a5;
  --faint: #646d7c;
  --accent: #7c9cf5;
  --accent-soft: #7c9cf522;

  --person: #83b0ff;
  --part: #f2c078;
  --test: #6fd48a;
  --problem: #ff8f8a;
  --system: #c3a6ff;

  --radius: 10px;
  --radius-sm: 7px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.55 var(--sans);
  -webkit-font-smoothing: antialiased;
}

button, input, textarea, select { font: inherit; color: inherit; }
a { color: inherit; text-decoration: none; }

::selection { background: var(--accent-soft); }

mark {
  background: color-mix(in srgb, var(--accent) 30%, transparent);
  color: inherit; border-radius: 3px; padding: 0 1px;
}

/* ------------------------------------------------------------------ layout */

.app { display: grid; grid-template-columns: 256px 1fr; height: 100vh; }

.sidebar {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px 12px;
  background: var(--bg-2);
  border-right: 1px solid var(--border-soft);
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 9px; padding: 2px 6px 6px; }
.brand-mark {
  display: grid; place-items: center;
  width: 28px; height: 28px; flex: none;
  border-radius: 8px;
  background: linear-gradient(140deg, var(--accent), var(--system));
  color: #12141a; font-size: 11px; font-weight: 800; letter-spacing: .02em;
}
.brand-name { font-size: 13px; font-weight: 600; letter-spacing: -.01em; }

.search-trigger {
  display: flex; align-items: center; gap: 8px; width: 100%;
  padding: 8px 10px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--muted);
  cursor: pointer; text-align: left;
}
.search-trigger:hover { background: var(--panel-2); color: var(--text); }
.search-trigger span { flex: 1; font-size: 13px; }

.kbd-hint, kbd {
  font: 11px/1 var(--mono);
  padding: 3px 5px; border-radius: 5px;
  background: #0e1014; border: 1px solid var(--border);
  color: var(--faint);
}

.nav { display: flex; flex-direction: column; gap: 1px; }
.nav-section {
  padding: 12px 10px 5px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .08em; text-transform: uppercase; color: var(--faint);
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  color: var(--muted); cursor: pointer; font-size: 13.5px;
}
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active { background: var(--panel-2); color: var(--text); font-weight: 500; }
.nav-item .sigil { width: 14px; text-align: center; font: 700 13px var(--mono); }
.nav-item .count { margin-left: auto; font: 11px var(--mono); color: var(--faint); }

.sidebar-foot { margin-top: auto; padding-top: 10px; border-top: 1px solid var(--border-soft); }
.sync {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 10px; border-radius: var(--radius-sm);
  font-size: 12px; color: var(--muted); cursor: pointer;
}
.sync:hover { background: var(--panel); }
.sync .dot { width: 7px; height: 7px; border-radius: 50%; background: var(--test); flex: none; }
.sync.dirty .dot { background: var(--part); }
.sync.error .dot { background: var(--problem); }

.main { overflow-y: auto; padding: 28px 34px 80px; outline: none; }
.wrap { max-width: 940px; margin: 0 auto; }
.wrap.wide { max-width: 1180px; }

/* ------------------------------------------------------------------ header */

.page-head { display: flex; align-items: flex-start; gap: 16px; margin-bottom: 22px; }
.page-head .grow { flex: 1; min-width: 0; }
.page-title {
  margin: 0; font-size: 24px; font-weight: 650; letter-spacing: -.02em;
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
}
.page-sub { margin: 5px 0 0; color: var(--muted); font-size: 13.5px; }
.crumb { color: var(--faint); font-size: 12.5px; margin-bottom: 6px; }
.crumb a:hover { color: var(--text); }

/* ------------------------------------------------------------------ pieces */

.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: var(--radius-sm);
  background: var(--panel); border: 1px solid var(--border);
  color: var(--text); cursor: pointer; font-size: 13px; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); border-color: #39414e; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #101319; font-weight: 600; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--muted); }
.btn.ghost:hover { background: var(--panel); color: var(--text); }
.btn.danger:hover { border-color: var(--problem); color: var(--problem); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.sm { padding: 4px 8px; font-size: 12px; }

.input, .textarea, select.input {
  width: 100%; padding: 8px 11px;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius-sm); color: var(--text); outline: none;
}
.input:focus, .textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.textarea { resize: vertical; min-height: 88px; line-height: 1.6; font-family: var(--sans); }
.field { margin-bottom: 14px; }
.field label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 5px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }
.row.tight { gap: 8px; }
.row.auto > * { flex: none; }

.card {
  background: var(--panel); border: 1px solid var(--border-soft);
  border-radius: var(--radius); padding: 16px;
}
.card + .card { margin-top: 12px; }
.grid > .card + .card, .grid > * > .card:first-child { margin-top: 0; }
.card-title {
  font-size: 12px; font-weight: 700; letter-spacing: .06em;
  text-transform: uppercase; color: var(--faint); margin: 0 0 12px;
}

.grid { display: grid; gap: 12px; }
.grid.two { grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); }
.grid.three { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
.grid.stats { grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); }

.stat { background: var(--panel); border: 1px solid var(--border-soft); border-radius: var(--radius); padding: 14px 16px; }
.stat .n { font-size: 26px; font-weight: 650; letter-spacing: -.02em; line-height: 1.1; }
.stat .l { font-size: 12px; color: var(--muted); margin-top: 3px; }

.empty { padding: 44px 20px; text-align: center; color: var(--faint); }
.empty h3 { margin: 0 0 6px; color: var(--muted); font-size: 15px; font-weight: 550; }
.empty p { margin: 0 0 14px; font-size: 13px; }

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.spacer { flex: 1; }

.icon { width: 15px; height: 15px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ------------------------------------------------------------- ref chips */

.ref {
  display: inline-flex; align-items: baseline; gap: 1px;
  padding: 1px 6px 1px 4px; margin: 0 1px;
  border-radius: 5px; font-size: .93em; line-height: 1.35;
  border: 1px solid transparent; cursor: pointer; white-space: nowrap;
}
.ref .sig { font-family: var(--mono); font-weight: 700; opacity: .75; }
.ref:hover { filter: brightness(1.18); border-color: currentColor; }
.ref.person  { color: var(--person);  background: color-mix(in srgb, var(--person) 13%, transparent); }
.ref.part    { color: var(--part);    background: color-mix(in srgb, var(--part) 13%, transparent); }
.ref.test    { color: var(--test);    background: color-mix(in srgb, var(--test) 13%, transparent); }
.ref.problem { color: var(--problem); background: color-mix(in srgb, var(--problem) 13%, transparent); }
.ref.unknown { opacity: .72; border-style: dashed; border-color: currentColor; }

.s-person { color: var(--person); } .s-part { color: var(--part); }
.s-test { color: var(--test); } .s-problem { color: var(--problem); }
.s-system { color: var(--system); }

.pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px; font-size: 11.5px;
  background: var(--panel-2); border: 1px solid var(--border); color: var(--muted);
}
.pill.open { color: var(--part); border-color: color-mix(in srgb, var(--part) 40%, transparent); }
.pill.closed, .pill.done { color: var(--test); border-color: color-mix(in srgb, var(--test) 40%, transparent); }

/* --------------------------------------------------------------- listing */

.list { display: flex; flex-direction: column; gap: 1px; }
.list-item {
  display: flex; align-items: center; gap: 12px;
  padding: 11px 13px; border-radius: var(--radius-sm);
  border: 1px solid transparent; cursor: pointer;
}
.list-item:hover { background: var(--panel); border-color: var(--border-soft); }
.list-item .li-main { flex: 1; min-width: 0; }
.list-item .li-title { font-weight: 550; letter-spacing: -.01em; }
.list-item .li-sub {
  font-size: 12.5px; color: var(--muted); margin-top: 2px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.list-item .li-meta { font: 11.5px var(--mono); color: var(--faint); text-align: right; flex: none; }

.entity-card {
  display: flex; flex-direction: column; gap: 4px;
  padding: 13px 14px; border-radius: var(--radius);
  background: var(--panel); border: 1px solid var(--border-soft); cursor: pointer;
}
.entity-card:hover { border-color: var(--border); background: var(--panel-2); }
.entity-card .ec-name { font-weight: 550; display: flex; align-items: center; gap: 6px; }
.entity-card .ec-meta { font-size: 12px; color: var(--faint); display: flex; gap: 10px; }
.entity-card .ec-notes {
  font-size: 12.5px; color: var(--muted); margin-top: 3px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}

/* -------------------------------------------------------------- timeline */

.timeline { position: relative; padding-left: 22px; }
.timeline::before {
  content: ""; position: absolute; left: 5px; top: 6px; bottom: 6px;
  width: 1px; background: var(--border);
}
.tl-day { position: relative; margin-bottom: 20px; }
.tl-day::before {
  content: ""; position: absolute; left: -21px; top: 6px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--accent);
}
.tl-date {
  font: 12px var(--mono); color: var(--muted);
  display: flex; align-items: baseline; gap: 8px; margin-bottom: 7px;
}
.tl-date .ago { color: var(--faint); font-size: 11px; }

.action {
  position: relative; padding: 11px 13px; border-radius: var(--radius-sm);
  background: var(--panel); border: 1px solid var(--border-soft);
}
.action + .action { margin-top: 7px; }
.action:hover { border-color: var(--border); }
.action-text { white-space: pre-wrap; word-break: break-word; }
.action-tools {
  position: absolute; top: 7px; right: 7px; display: flex; gap: 3px;
  opacity: 0; transition: opacity .12s;
}
.action:hover .action-tools, .action:focus-within .action-tools { opacity: 1; }
.action-sys { font: 11.5px var(--mono); color: var(--system); margin-bottom: 4px; }

/* -------------------------------------------------------------- composer */

.composer { position: relative; }
.composer .textarea { padding-right: 12px; }
.composer-bar {
  display: flex; align-items: center; gap: 8px; margin-top: 9px; flex-wrap: wrap;
}
.composer-hint { font-size: 12px; color: var(--faint); }
.composer-hint b { font-family: var(--mono); font-weight: 700; }

.typeahead {
  position: absolute; z-index: 60; min-width: 250px; max-width: 380px;
  max-height: 268px; overflow-y: auto;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: 0 14px 40px #0009;
  padding: 5px;
}
.ta-item {
  display: flex; align-items: center; gap: 8px;
  padding: 7px 9px; border-radius: var(--radius-sm); cursor: pointer; font-size: 13px;
}
.ta-item .ta-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ta-item .ta-count { font: 11px var(--mono); color: var(--faint); }
.ta-item.active { background: var(--panel-2); }
.ta-item .sig { font: 700 12px var(--mono); }
.ta-new { color: var(--muted); font-style: italic; }
.ta-empty { padding: 10px; color: var(--faint); font-size: 12.5px; }

/* --------------------------------------------------------------- palette */

.palette-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: #0009; backdrop-filter: blur(3px);
  display: flex; justify-content: center; padding-top: 12vh;
}
.palette-backdrop[hidden] { display: none; }
.palette {
  width: min(680px, 92vw); align-self: flex-start; max-height: 70vh;
  display: flex; flex-direction: column;
  background: var(--panel); border: 1px solid var(--border);
  border-radius: 13px; box-shadow: 0 24px 70px #000b; overflow: hidden;
}
.palette-input-row {
  display: flex; align-items: center; gap: 10px;
  padding: 13px 15px; border-bottom: 1px solid var(--border-soft); color: var(--muted);
}
.palette-input-row input {
  flex: 1; background: none; border: none; outline: none; font-size: 15px; color: var(--text);
}
.palette-results { overflow-y: auto; padding: 6px; flex: 1; }
.palette-group {
  padding: 9px 10px 4px; font-size: 10.5px; font-weight: 700;
  letter-spacing: .07em; text-transform: uppercase; color: var(--faint);
}
.p-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius-sm); cursor: pointer;
}
.p-item.active { background: var(--panel-2); }
.p-item .p-main { flex: 1; min-width: 0; }
.p-item .p-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.p-item .p-sub {
  font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.p-item .p-kind { font: 11px var(--mono); color: var(--faint); flex: none; }

.palette-foot {
  display: flex; gap: 16px; padding: 8px 14px;
  border-top: 1px solid var(--border-soft);
  font-size: 11.5px; color: var(--faint); flex-wrap: wrap;
}
.palette-foot b { font-family: var(--mono); }

/* ---------------------------------------------------------------- toasts */

.toasts { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.toast {
  padding: 10px 14px; border-radius: var(--radius);
  background: var(--panel-2); border: 1px solid var(--border);
  box-shadow: 0 10px 30px #0008; font-size: 13px; max-width: 380px;
  animation: rise .18s ease-out;
}
.toast.error { border-color: var(--problem); color: var(--problem); }
.toast.ok { border-color: color-mix(in srgb, var(--test) 45%, transparent); }
@keyframes rise { from { opacity: 0; transform: translateY(7px); } }

/* --------------------------------------------------------------- tables */

.kv { display: grid; grid-template-columns: minmax(90px, auto) 1fr; gap: 7px 14px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }

.tabs { display: flex; gap: 3px; border-bottom: 1px solid var(--border-soft); margin-bottom: 16px; }
.tab {
  padding: 8px 13px; border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  color: var(--muted); cursor: pointer; font-size: 13.5px;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--text); border-bottom-color: var(--accent); }
.tab .count { font: 11px var(--mono); color: var(--faint); margin-left: 5px; }

@media (max-width: 820px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { display: none; }
  .main { padding: 18px 16px 70px; }
}
