/* ============================================================
   Ledger — Celestech admin redesign, line B design language.
   Ink on light. Swiss grid discipline. Color is meaning;
   ink is action. Type: IBM Plex Sans / IBM Plex Mono.
   ============================================================ */

:root {
  /* surfaces */
  --bg:      #f4f5f7;
  --surface: #ffffff;
  --wash:    #eef0f3;

  /* ink */
  --ink:   #171a21;
  --ink-2: #454a56;
  --ink-3: #7a8090;

  /* rules */
  --line:        #e4e7ec;
  --line-strong: #d2d7df;

  /* status — the only saturated hues allowed */
  --ok:       #217a46;  --ok-wash:     #e5f3ea;
  --info:     #2c63b8;  --info-wash:   #e7effa;
  --warn:     #9a6a10;  --warn-wash:   #f9efdb;
  --bad:      #b23a3a;  --bad-wash:    #fae9e9;
  --mut:      #7a8090;  --mut-wash:    #eef0f3;

  /* area identities — quiet, used only on marks + active states */
  --a-sell:    #ad4d28;
  --a-make:    #2e6e62;
  --a-ship:    #34618f;
  --a-money:   #2f7048;
  --a-catalog: #6f5a9e;
  --a-company: #55606e;

  /* type */
  --font-ui:   'IBM Plex Sans', 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  /* rhythm (4pt) */
  --s1: 4px;  --s2: 8px;  --s3: 12px; --s4: 16px;
  --s5: 24px; --s6: 32px; --s7: 48px; --s8: 64px;

  --r-sm: 5px; --r: 8px; --r-lg: 12px;
  --shadow-menu: 0 12px 32px rgba(20,24,33,.14), 0 2px 6px rgba(20,24,33,.08);
  --bar-h: 52px;

  --ease: cubic-bezier(.25,.6,.3,1);
}

* { box-sizing: border-box; margin: 0; }
html { height: 100%; }
body {
  min-height: 100%;
  background: var(--bg);
  color: var(--ink);
  font: 400 14px/1.5 var(--font-ui);
  -webkit-font-smoothing: antialiased;
  font-kerning: normal;
}
::selection { background: #d7e3f7; }
:focus-visible { outline: 2px solid var(--ink); outline-offset: 2px; border-radius: 3px; }
a { color: inherit; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }

/* ---------- primitives ---------- */

.cap {                       /* micro label — structure, not decoration */
  font-size: .6875rem; font-weight: 600;
  letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3);
}
.mono { font-family: var(--font-mono); }
.num  { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

kbd {
  font: 500 .6875rem/1 var(--font-mono);
  color: var(--ink-2);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  padding: 3px 5px;
}

.btn {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .8125rem; font-weight: 500;
  padding: 7px 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface);
  transition: border-color .13s var(--ease), background .13s var(--ease), color .13s var(--ease);
}
.btn:hover { border-color: var(--ink-3); }
.btn.primary { background: var(--ink); color: #fff; border-color: var(--ink); }
.btn.primary:hover { background: #2b303c; border-color: #2b303c; }
.btn.quiet  { border-color: transparent; color: var(--ink-2); }
.btn.quiet:hover { background: var(--wash); border-color: transparent; }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.sm { padding: 4px 9px; font-size: .75rem; }

/* status badge — dot + word; hue carries meaning only */
.badge {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .75rem; font-weight: 500; white-space: nowrap;
  color: var(--badge-c, var(--mut));
}
.badge::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%;
  background: var(--badge-c, var(--mut));
}
.badge[data-tone="ok"]   { --badge-c: var(--ok); }
.badge[data-tone="info"] { --badge-c: var(--info); }
.badge[data-tone="warn"] { --badge-c: var(--warn); }
.badge[data-tone="bad"]  { --badge-c: var(--bad); }
.badge[data-tone="mut"]  { --badge-c: var(--mut); }

/* entity chip — THE relation grammar: kind · id · state · fact */
.chip {
  position: relative;
  display: inline-flex; align-items: center; gap: 8px;
  max-width: 100%;
  padding: 4px 9px 4px 5px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-size: .75rem; line-height: 1.35;
  text-decoration: none;
  transition: border-color .13s var(--ease);
}
.chip:hover { border-color: var(--ink-3); }
.chip .ck {
  flex: none;
  font-family: var(--font-mono); font-size: .5625rem; font-weight: 600;
  letter-spacing: .06em;
  color: #fff; background: var(--chip-hue, var(--ink-3));
  border-radius: 3px; padding: 2px 4px;
}
.chip .cid { font-family: var(--font-mono); font-size: .75rem; font-weight: 500; white-space: nowrap; }
.chip .cdot { flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--cdot, var(--mut)); }
.chip .cfact { color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* peek card — hover without committing */
.peek {
  display: none; position: absolute; z-index: 70;
  left: 0; top: calc(100% + 7px); min-width: 250px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r); box-shadow: var(--shadow-menu);
  padding: 12px 14px; font-size: .75rem; color: var(--ink-2);
  text-align: left; cursor: default;
}
.peek b { display: block; color: var(--ink); font-size: .8125rem; margin-bottom: 5px; }
.peek .pf { display: flex; justify-content: space-between; gap: 16px; padding: 2px 0; }
.peek .pf span:first-child { color: var(--ink-3); }
.peek .pa { display: flex; gap: var(--s2); margin-top: 9px; padding-top: 9px; border-top: 1px solid var(--line); }
.chip:hover .peek, [data-peek]:hover .peek { display: block; }

/* panel */
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
}
.panel > header {
  display: flex; align-items: center; gap: var(--s3);
  padding: 13px var(--s4) 11px;
  border-bottom: 1px solid var(--line);
}
.panel > header h3 { font-size: .6875rem; font-weight: 600; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3); }
.panel > header .grow { flex: 1; }
.panel > footer {
  padding: 10px var(--s4);
  border-top: 1px solid var(--line);
  font-size: .75rem; color: var(--ink-3);
}

/* data table */
table.tbl { width: 100%; border-collapse: collapse; font-size: .8125rem; }
.tbl th {
  position: sticky; top: 0; z-index: 5;
  text-align: left;
  font-size: .6563rem; font-weight: 600; letter-spacing: .09em; text-transform: uppercase;
  color: var(--ink-3);
  background: var(--surface);
  padding: 9px 12px;
  border-bottom: 1px solid var(--line-strong);
  white-space: nowrap;
}
.tbl td { padding: 11px 12px; border-bottom: 1px solid var(--line); vertical-align: middle; }
body[data-density="compact"] .tbl td { padding: 6px 12px; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl tbody tr { transition: background .1s; }
.tbl tbody tr:hover { background: #f7f8fa; }
.tbl tr[data-nav] { cursor: pointer; }
.tbl .num, .tbl td.r { text-align: right; font-family: var(--font-mono); font-variant-numeric: tabular-nums; }
.tbl .id { font-family: var(--font-mono); font-size: .78rem; font-weight: 500; white-space: nowrap; }
.tbl .meta { color: var(--ink-3); font-size: .75rem; }
.tbl th.r { text-align: right; }

/* detail rows — label left, value right (house rule) */
table.dt { width: 100%; border-collapse: collapse; font-size: .8125rem; }
.dt th {
  text-align: left; font-weight: 500; color: var(--ink-3);
  width: 168px; padding: 8px 16px 8px 0; vertical-align: top; white-space: nowrap;
}
.dt td { padding: 8px 0; vertical-align: top; }
.dt tr + tr th, .dt tr + tr td { border-top: 1px solid var(--line); }

/* editable affordance — click-to-edit, pencil appears on hover */
.ed {
  cursor: text; border-bottom: 1px dashed transparent;
  border-radius: 2px; padding: 0 1px;
}
.ed:hover { border-bottom-color: var(--line-strong); background: var(--wash); }
.ed::after {
  content: '✎'; font-size: .6875rem; color: var(--ink-3);
  opacity: 0; margin-left: 5px; transition: opacity .13s var(--ease);
}
.ed:hover::after { opacity: .85; }

/* ---------- page scaffolding ---------- */

main { padding-top: var(--bar-h); }
#stage { max-width: 1480px; margin: 0 auto; padding: var(--s6) var(--s6) var(--s8); }

.page-head { display: flex; align-items: baseline; gap: var(--s4); flex-wrap: wrap; margin-bottom: var(--s2); }
.page-head h1 { font-size: 1.625rem; font-weight: 650; letter-spacing: -.015em; line-height: 1.2; }
.page-head .sub { color: var(--ink-3); font-size: .8125rem; }
.page-head .spacer { flex: 1; }
.page-head .actions { display: flex; gap: var(--s2); align-self: center; }

.statrow { display: flex; gap: var(--s5); margin: var(--s4) 0 var(--s5); flex-wrap: wrap; }
.stat .cap { display: block; margin-bottom: 2px; }
.stat b { font-family: var(--font-mono); font-size: 1.375rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.stat b.warn { color: var(--warn); }
.stat b.bad { color: var(--bad); }

/* views row — content-owned; never stacked on nav */
.views {
  display: flex; gap: 2px; align-items: center;
  border-bottom: 1px solid var(--line-strong);
  margin-bottom: var(--s5);
}
.views button {
  font-size: .8125rem; font-weight: 500; color: var(--ink-3);
  padding: 9px 14px; margin-bottom: -1px;
  border-bottom: 2px solid transparent;
  transition: color .13s var(--ease);
}
.views button:hover { color: var(--ink); }
.views button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--ink); }
.views .count {
  font-family: var(--font-mono); font-size: .6875rem; color: var(--ink-3);
  background: var(--wash); border-radius: 99px; padding: 1px 7px; margin-left: 6px;
}
.views button[aria-selected="true"] .count { background: #e8ebf0; color: var(--ink-2); }

/* filter bar */
.filterbar { display: flex; gap: var(--s2); align-items: center; margin-bottom: var(--s4); flex-wrap: wrap; }
.filterbar input[type=search] {
  font: inherit; font-size: .8125rem; color: var(--ink);
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--r-sm); padding: 7px 11px; width: 280px;
}
.filterbar input[type=search]::placeholder { color: var(--ink-3); }
.fchip {
  font-size: .75rem; font-weight: 500; color: var(--ink-2);
  border: 1px solid var(--line); border-radius: 99px;
  padding: 5px 12px; background: var(--surface);
  transition: all .13s var(--ease);
}
.fchip:hover { border-color: var(--line-strong); }
.fchip[aria-pressed="true"] { background: var(--ink); border-color: var(--ink); color: #fff; }

/* density control */
.seg {
  display: inline-flex; border: 1px solid var(--line-strong); border-radius: var(--r-sm); overflow: hidden;
}
.seg button { font-size: .6875rem; font-weight: 500; color: var(--ink-3); padding: 5px 10px; background: var(--surface); }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--wash); color: var(--ink); }

/* bulk bar */
.bulkbar {
  display: none; align-items: center; gap: var(--s3);
  margin-bottom: var(--s3); padding: 9px 14px;
  background: var(--ink); color: #fff;
  border-radius: var(--r); font-size: .8125rem;
}
.bulkbar.on { display: flex; }
.bulkbar b { font-family: var(--font-mono); }
.bulkbar .btn { background: transparent; color: #fff; border-color: #4a5060; }
.bulkbar .btn.primary { background: #fff; color: var(--ink); border-color: #fff; }

/* empty state */
.empty { text-align: center; padding: var(--s8) var(--s5); color: var(--ink-3); }
.empty .glyph { font-size: 1.75rem; margin-bottom: var(--s3); opacity: .5; }
.empty b { display: block; color: var(--ink-2); font-weight: 550; margin-bottom: 4px; }
.empty p { font-size: .8125rem; max-width: 44ch; margin: 0 auto; }

/* ---------- relations rail ---------- */
.rail { position: relative; padding-left: 22px; }
.rail::before {
  content: ''; position: absolute; left: 8px; top: 8px; bottom: 8px;
  width: 1px; background: var(--line-strong);
}
.rnode { position: relative; padding: var(--s3) 0; }
.rnode::before {
  content: ''; position: absolute; left: -18px; top: 19px;
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--cdot, var(--mut));
}
.rnode .rwhen { font-family: var(--font-mono); font-size: .6875rem; color: var(--ink-3); margin-left: 8px; }

/* activity feed */
.feed { list-style: none; }
.feed li {
  display: flex; gap: var(--s3); padding: 9px 0;
  border-bottom: 1px solid var(--line); font-size: .8125rem;
}
.feed li:last-child { border-bottom: 0; }
.feed time { flex: none; width: 118px; font-family: var(--font-mono); font-size: .6875rem; color: var(--ink-3); padding-top: 2px; }
.feed .who { font-weight: 550; }

/* ---------- the one bar ---------- */

#bar {
  position: fixed; inset: 0 0 auto 0; height: var(--bar-h); z-index: 50;
  display: flex; align-items: stretch; gap: var(--s1);
  background: var(--surface);
  border-bottom: 1px solid var(--line-strong);
  padding: 0 var(--s4) 0 var(--s4);
}
#mark {
  display: flex; align-items: center; padding: 0 var(--s2) 0 0;
  font-size: .8125rem; font-weight: 700; letter-spacing: .14em;
  text-decoration: none; color: var(--ink);
}
#mark i { font-style: normal; color: var(--a-sell); }

nav.areas { display: flex; align-items: stretch; }
.abtn {
  position: relative;
  display: flex; align-items: center;
  padding: 0 13px;
  font-size: .6875rem; font-weight: 600;
  letter-spacing: .11em; text-transform: uppercase;
  color: var(--ink-3);
  border-bottom: 2px solid transparent; border-top: 2px solid transparent;
  transition: color .13s var(--ease);
}
.abtn:hover { color: var(--ink); }
.abtn[data-on="1"] { color: var(--hue); border-bottom-color: var(--hue); }
.abtn.support { color: var(--ink-3); font-weight: 500; }
.abtn .dot { display: none; width: 8px; height: 8px; border-radius: 50%; background: var(--hue); }
.asep { align-self: center; width: 1px; height: 18px; background: var(--line-strong); margin: 0 var(--s3); }

/* path continues inside the bar after the active area */
#path { display: flex; align-items: stretch; min-width: 0; }
.pseg {
  position: relative; display: flex; align-items: center; gap: 6px;
  padding: 0 var(--s3); font-size: .8125rem; font-weight: 550; color: var(--ink);
  white-space: nowrap;
}
.pseg::before { content: '›'; color: var(--line-strong); font-weight: 400; margin-right: var(--s3); }
.pseg .car { color: var(--ink-3); font-size: .55rem; transform: translateY(1px); }
.pseg:hover { background: var(--wash); }
.pseg.ent { font-family: var(--font-mono); font-weight: 500; cursor: default; }
.pseg.ent:hover { background: none; }

#bar .tools { margin-left: auto; display: flex; align-items: center; gap: var(--s3); }
#palbtn {
  display: flex; align-items: center; gap: 9px;
  font-size: .8125rem; color: var(--ink-3);
  padding: 6px 11px; border: 1px solid var(--line); border-radius: var(--r-sm);
  transition: all .13s var(--ease);
}
#palbtn:hover { color: var(--ink); border-color: var(--line-strong); }
#user { display: flex; align-items: center; gap: 8px; font-size: .8125rem; font-weight: 550; color: var(--ink-2); }
#user .av {
  width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  font-size: .625rem; font-weight: 700; letter-spacing: .04em;
  background: var(--wash); color: var(--ink-2);
}

@media (max-width: 1180px) {
  .abtn:not([data-on="1"]) { padding: 0 10px; }
  .abtn:not([data-on="1"]) .lbl { display: none; }
  .abtn:not([data-on="1"]) .dot { display: block; }
}
@media (max-width: 860px) {
  #stage { padding: var(--s4) var(--s4) var(--s7); }
  #palbtn span { display: none; }
  #user span.uname { display: none; }
}

/* menus (area siblings + configure) */
.menu {
  position: fixed; z-index: 60; min-width: 216px;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r); box-shadow: var(--shadow-menu);
  padding: 5px; display: none;
}
.menu.open { display: block; animation: menuin .13s var(--ease); }
@keyframes menuin { from { opacity: 0; transform: translateY(-3px); } }
.menu a, .menu button.mitem {
  display: flex; width: 100%; align-items: center; gap: 8px;
  font-size: .8125rem; text-decoration: none; text-align: left;
  padding: 8px 10px; border-radius: var(--r-sm); color: var(--ink-2);
}
.menu a:hover, .menu button.mitem:hover { background: var(--wash); color: var(--ink); }
.menu .on { color: var(--ink); font-weight: 550; box-shadow: inset 2px 0 0 var(--mc, var(--ink)); }
.menu .sep { border-top: 1px solid var(--line); margin: 5px 4px; }
.menu .mcap {
  font-size: .625rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase;
  color: var(--ink-3); padding: 8px 10px 3px;
}

/* command palette */
.pal-overlay {
  position: fixed; inset: 0; z-index: 100; display: none;
  background: rgba(20,24,33,.32);
  padding-top: 13vh;
}
.pal-overlay.open { display: block; }
.pal {
  width: min(620px, 92vw); margin: 0 auto;
  background: var(--surface); border: 1px solid var(--line-strong);
  border-radius: var(--r-lg); box-shadow: var(--shadow-menu); overflow: hidden;
}
.pal input {
  width: 100%; font: inherit; font-size: 1rem; color: var(--ink);
  background: transparent; border: 0; outline: none;
  padding: 15px 18px; border-bottom: 1px solid var(--line);
}
.pal-list { max-height: 46vh; overflow-y: auto; padding: 6px; }
.pal-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  font-size: .8125rem; padding: 9px 12px; border-radius: var(--r-sm);
}
.pal-item .where { margin-left: auto; font-size: .625rem; color: var(--ink-3); letter-spacing: .07em; text-transform: uppercase; }
.pal-item.sel { background: var(--wash); }
.pal-item .pdot { flex: none; width: 8px; height: 8px; border-radius: 50%; }
.pal-empty { padding: 22px 16px; font-size: .8125rem; color: var(--ink-3); text-align: center; }

/* utility layout */
.cols { display: grid; gap: var(--s5); }
.cols-side { grid-template-columns: minmax(0, 1fr) 340px; }
@media (max-width: 1100px) { .cols-side { grid-template-columns: 1fr; } }
.stack { display: grid; gap: var(--s4); }
.row { display: flex; align-items: center; gap: var(--s3); }
.grow { flex: 1; }
.muted { color: var(--ink-3); }

/* sandbox chrome — not part of the design */
#sandboxnote {
  position: fixed; right: var(--s4); bottom: var(--s4); z-index: 90;
  font-size: .6875rem; color: var(--ink-3); max-width: 300px; text-align: right;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: 99px; padding: 6px 13px; box-shadow: var(--shadow-menu);
}
#sandboxnote a { color: var(--ink-2); font-weight: 550; }
