/* ── Plumbline design system ─────────────────────────────────────────── */
:root {
  --paper: #f7f6f3;          /* page plane, warm */
  --surface: #ffffff;
  --surface-2: #fcfcfb;
  --ink: #1c2126;
  --ink-2: #52514e;
  --ink-3: #898781;
  --line: #e5e3dc;
  --line-soft: #eeece6;
  --amber: #eda100;          /* accent: safety amber, always with ink text */
  --amber-hover: #d99400;
  --amber-soft: #fdf3dd;
  --blue: #2a78d6;           /* links / info */
  --blue-soft: #e8f1fb;
  --good: #0ca30c;  --good-soft: #e7f5e7;  --good-ink: #086308;
  --warn: #b97a00;  --warn-soft: #fdf3dd;
  --serious: #c65f33; --serious-soft: #fbeee8;
  --crit: #d03b3b;  --crit-soft: #fbe9e9;  --crit-ink: #a32c2c;
  --violet: #4a3aa7; --violet-soft: #edebf8;
  --slate-soft: #eef0f2;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow-1: 0 1px 2px rgba(28,33,38,.06), 0 0 0 1px rgba(28,33,38,.04);
  --shadow-2: 0 4px 16px rgba(28,33,38,.10), 0 0 0 1px rgba(28,33,38,.05);
  --shadow-3: 0 16px 48px rgba(28,33,38,.18);
  --sidebar-w: 216px;
  --topbar-h: 56px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.45;
  color: var(--ink); background: var(--paper);
  -webkit-font-smoothing: antialiased;
}
h1,h2,h3,h4 { margin: 0; text-wrap: balance; }
p { margin: 0; }
a { color: var(--blue); text-decoration: none; }
a:hover { text-decoration: underline; }
button { font: inherit; color: inherit; }
svg.icon { width: 18px; height: 18px; flex: 0 0 auto; display: block; }
:focus-visible { outline: 2px solid var(--blue); outline-offset: 2px; border-radius: 4px; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}

/* ── App frame ── */
#app { display: flex; min-height: 100vh; }
#sidebar {
  width: var(--sidebar-w); flex: 0 0 auto; background: var(--ink); color: #d9d7d0;
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; z-index: 40;
}
.sb-logo {
  display: flex; align-items: center; gap: 10px; padding: 16px 16px 14px;
  color: #fff; font-weight: 700; font-size: 15.5px; letter-spacing: .01em;
}
.sb-logo .mark {
  width: 30px; height: 30px; border-radius: 8px; background: var(--amber); color: var(--ink);
  display: grid; place-items: center; font-weight: 800; font-size: 15px;
}
.sb-logo small { display: block; font-size: 10.5px; font-weight: 500; color: #9a978f; letter-spacing: .02em; }
.sb-nav { flex: 1; overflow-y: auto; padding: 4px 10px 12px; }
.sb-section {
  font-size: 10px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase;
  color: #7d7b74; padding: 16px 8px 5px;
}
.sb-item {
  display: flex; align-items: center; gap: 10px; width: 100%; text-align: left;
  padding: 7.5px 10px; border: 0; background: none; border-radius: 8px; cursor: pointer;
  color: #c9c7c0; font-size: 13.5px; font-weight: 500; margin: 1px 0;
}
.sb-item:hover { background: rgba(255,255,255,.07); color: #fff; }
.sb-item.active { background: var(--amber); color: var(--ink); font-weight: 650; }
.sb-item .icon { width: 17px; height: 17px; opacity: .85; }
.sb-item.active .icon { opacity: 1; }
.sb-badge {
  margin-left: auto; background: rgba(255,255,255,.16); color: #fff; border-radius: 99px;
  font-size: 10.5px; font-weight: 700; padding: 1px 7px; min-width: 20px; text-align: center;
}
.sb-item.active .sb-badge { background: rgba(28,33,38,.18); color: var(--ink); }
.sb-foot { padding: 10px; border-top: 1px solid rgba(255,255,255,.09); display: grid; gap: 2px; }
.sb-foot .sb-item { font-size: 12.5px; color: #a5a39b; }

#main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
#topbar {
  height: var(--topbar-h); background: var(--surface); border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px; padding: 0 20px;
  position: sticky; top: 0; z-index: 30;
}
#view { flex: 1; padding: 22px 24px 80px; max-width: 1280px; width: 100%; margin: 0 auto; }

/* topbar search */
.tb-search { position: relative; flex: 0 1 380px; }
.tb-search input {
  width: 100%; padding: 7px 12px 7px 34px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--paper); font: inherit; font-size: 13.5px;
}
.tb-search > .icon { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--ink-3); width: 16px; height: 16px; }
.tb-results {
  position: absolute; top: calc(100% + 6px); left: 0; width: min(480px, 92vw); max-height: 60vh; overflow: auto;
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-3); z-index: 60; padding: 6px;
}
.tb-hit { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer; }
.tb-hit:hover, .tb-hit.sel { background: var(--paper); }
.tb-hit .icon { color: var(--ink-3); }
.tb-hit small { color: var(--ink-3); }
.tb-spacer { flex: 1; }
.tb-co { display: flex; align-items: center; gap: 9px; font-weight: 600; font-size: 13px; color: var(--ink-2); }

/* ── Buttons ── */
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 7.5px 14px;
  border-radius: 8px; border: 1px solid var(--line); background: var(--surface);
  font-size: 13.5px; font-weight: 600; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.btn:hover { background: var(--paper); }
.btn .icon { width: 15.5px; height: 15.5px; }
.btn.primary { background: var(--amber); border-color: var(--amber); color: var(--ink); }
.btn.primary:hover { background: var(--amber-hover); border-color: var(--amber-hover); }
.btn.dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn.dark:hover { background: #2c333a; }
.btn.danger { color: var(--crit-ink); border-color: #eccfcf; background: #fff; }
.btn.danger:hover { background: var(--crit-soft); }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--slate-soft); color: var(--ink); }
.btn.sm { padding: 4.5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn.icon-only { padding: 7px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

/* ── Pills / status ── */
.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 99px;
  font-size: 11.5px; font-weight: 650; white-space: nowrap; line-height: 1.7;
}
.pill .dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.pill.neutral { background: var(--slate-soft); color: var(--ink-2); }
.pill.blue    { background: var(--blue-soft); color: #1c5cab; }
.pill.green   { background: var(--good-soft); color: var(--good-ink); }
.pill.amber   { background: var(--amber-soft); color: #8a5f00; }
.pill.red     { background: var(--crit-soft); color: var(--crit-ink); }
.pill.violet  { background: var(--violet-soft); color: var(--violet); }
.pill.serious { background: var(--serious-soft); color: #9c4116; }
.pill.outline { background: none; box-shadow: inset 0 0 0 1px var(--line); color: var(--ink-2); }

/* ── Cards / page scaffolding ── */
.card { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-1); min-width: 0; }
.grid > *, .kpis > * { min-width: 0; }
.card.pad { padding: 16px; }
.card-title { font-size: 13px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.card-title .icon { width: 16px; height: 16px; color: var(--ink-3); }
.view-head { display: flex; align-items: flex-start; gap: 14px; flex-wrap: wrap; margin-bottom: 18px; }
.view-head h1 { font-size: 21px; font-weight: 750; letter-spacing: -.01em; }
.view-head .sub { color: var(--ink-3); font-size: 13px; margin-top: 3px; }
.view-head .actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.eyebrow {
  font-size: 10.5px; font-weight: 750; letter-spacing: .1em; text-transform: uppercase; color: var(--ink-3);
}
.grid { display: grid; gap: 14px; }
.num, .tabnum { font-variant-numeric: tabular-nums; }
.muted { color: var(--ink-3); }
.dim { color: var(--ink-2); }
.strong { font-weight: 650; }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: 8px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 10px; }

/* KPI tiles */
.kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(158px, 1fr)); gap: 12px; }
.kpi { background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-1); padding: 13px 15px; }
.kpi .k-label { font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase; color: var(--ink-3); }
.kpi .k-value { font-size: 23px; font-weight: 750; letter-spacing: -.01em; margin-top: 3px; }
.kpi .k-sub { font-size: 12px; color: var(--ink-3); margin-top: 2px; }
.kpi .k-sub.up { color: var(--good-ink); font-weight: 600; }
.kpi .k-sub.down { color: var(--crit-ink); font-weight: 600; }
.kpi.alert { box-shadow: var(--shadow-1), inset 3px 0 0 var(--crit); }

/* ── Tables ── */
.table-scroll { overflow-x: auto; border-radius: var(--radius); }
table.tbl { width: 100%; border-collapse: collapse; background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-1); overflow: hidden; }
.tbl th {
  text-align: left; font-size: 11px; font-weight: 700; letter-spacing: .07em; text-transform: uppercase;
  color: var(--ink-3); padding: 9px 12px; border-bottom: 1px solid var(--line); background: var(--surface-2);
  white-space: nowrap;
}
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.tbl tr:last-child td { border-bottom: 0; }
.tbl tbody tr.click { cursor: pointer; }
.tbl tbody tr.click:hover { background: var(--surface-2); }
.tbl td.right, .tbl th.right { text-align: right; }

/* ── Forms ── */
.field { display: grid; gap: 5px; margin-bottom: 12px; }
.field > label { font-size: 12px; font-weight: 650; color: var(--ink-2); }
.field > label .req { color: var(--crit); }
.field .hint { font-size: 11.5px; color: var(--ink-3); }
input.in, select.in, textarea.in {
  width: 100%; padding: 8px 11px; border: 1px solid var(--line); border-radius: 8px;
  font: inherit; font-size: 13.5px; background: var(--surface); color: var(--ink);
}
textarea.in { resize: vertical; min-height: 70px; }
input.in:focus, select.in:focus, textarea.in:focus { outline: 2px solid var(--blue); outline-offset: -1px; }
input.in.invalid, select.in.invalid, textarea.in.invalid { outline: 2px solid var(--crit); outline-offset: -1px; }
.form-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
@media (max-width: 640px) { .form-cols { grid-template-columns: 1fr; } }

/* ── Modal / drawer / toast ── */
.overlay {
  position: fixed; inset: 0; background: rgba(28,33,38,.45); z-index: 80;
  display: grid; place-items: center; padding: 20px; animation: fadeIn .15s ease;
}
@keyframes fadeIn { from { opacity: 0; } }
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-3);
  width: 560px; max-width: 100%; max-height: min(86vh, 900px); display: flex; flex-direction: column;
  animation: popIn .18s cubic-bezier(.2,.9,.3,1.2);
}
.modal.wide { width: 860px; }
@keyframes popIn { from { opacity: 0; transform: scale(.97) translateY(6px); } }
.modal-head { display: flex; align-items: center; gap: 10px; padding: 15px 18px; border-bottom: 1px solid var(--line-soft); }
.modal-head h3 { font-size: 15.5px; font-weight: 700; flex: 1; }
.modal-body { padding: 16px 18px; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 13px 18px; border-top: 1px solid var(--line-soft); }
.modal-foot .foot-left { margin-right: auto; }
.x-btn { border: 0; background: none; cursor: pointer; color: var(--ink-3); padding: 5px; border-radius: 6px; display: grid; place-items: center; }
.x-btn:hover { background: var(--slate-soft); color: var(--ink); }

.drawer-wrap { position: fixed; inset: 0; z-index: 70; }
.drawer-wrap .scrim { position: absolute; inset: 0; background: rgba(28,33,38,.35); animation: fadeIn .15s ease; }
.drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: 480px; max-width: 94vw;
  background: var(--surface); box-shadow: var(--shadow-3); display: flex; flex-direction: column;
  animation: slideIn .2s cubic-bezier(.2,.9,.3,1);
}
@keyframes slideIn { from { transform: translateX(40px); opacity: 0; } }
.drawer-head { display: flex; align-items: center; gap: 10px; padding: 15px 18px; border-bottom: 1px solid var(--line-soft); }
.drawer-head h3 { font-size: 15px; font-weight: 700; flex: 1; min-width: 0; }
.drawer-body { flex: 1; overflow-y: auto; padding: 16px 18px; }
.drawer-foot { display: flex; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--line-soft); flex-wrap: wrap; }

#toasts { position: fixed; bottom: 18px; left: 50%; transform: translateX(-50%); z-index: 100; display: grid; gap: 8px; justify-items: center; }
.toast {
  display: flex; align-items: center; gap: 9px; background: var(--ink); color: #fff;
  padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-3); font-size: 13.5px; font-weight: 550;
  animation: toastIn .22s cubic-bezier(.2,.9,.3,1.2);
}
.toast .icon { width: 16px; height: 16px; color: var(--amber); }
.toast.leaving { opacity: 0; transform: translateY(8px); transition: all .25s; }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } }

/* ── Tabs ── */
.tabs { display: flex; gap: 2px; border-bottom: 1px solid var(--line); margin-bottom: 16px; overflow-x: auto; }
.tab {
  border: 0; background: none; cursor: pointer; padding: 8px 13px; font-size: 13.5px; font-weight: 600;
  color: var(--ink-3); border-bottom: 2px solid transparent; margin-bottom: -1px; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 7px;
}
.tab:hover { color: var(--ink); }
.tab.active { color: var(--ink); border-bottom-color: var(--amber); }
.tab .count { background: var(--slate-soft); border-radius: 99px; padding: 0 7px; font-size: 11px; color: var(--ink-2); }

/* ── Avatars, misc ── */
.avatar {
  width: 32px; height: 32px; border-radius: 50%; display: inline-grid; place-items: center; flex: 0 0 auto;
  font-size: 12px; font-weight: 700; color: #fff; background: var(--ink-2); user-select: none;
}
.avatar.sm { width: 26px; height: 26px; font-size: 10.5px; }
.avatar.lg { width: 44px; height: 44px; font-size: 16px; }
.avatar.co { border-radius: 8px; }
.empty {
  display: grid; place-items: center; gap: 4px; text-align: center; padding: 44px 20px; color: var(--ink-3);
}
.empty > .icon { width: 30px; height: 30px; opacity: .5; }
.empty .e-title { font-weight: 650; color: var(--ink-2); font-size: 14px; }
.empty .e-hint { font-size: 12.5px; max-width: 320px; }
.activity-row { display: flex; gap: 11px; padding: 9px 2px; border-bottom: 1px solid var(--line-soft); cursor: pointer; border-radius: 6px; }
.activity-row:hover { background: var(--surface-2); }
.activity-row.no-link { cursor: default; }
.activity-row.no-link:hover { background: none; }
.activity-row:last-child { border-bottom: 0; }
.activity-row .a-ic {
  width: 28px; height: 28px; border-radius: 50%; background: var(--slate-soft); color: var(--ink-2);
  display: grid; place-items: center; flex: 0 0 auto; margin-top: 1px;
}
.activity-row .a-ic .icon { width: 14px; height: 14px; }
.activity-row.auto .a-ic { background: var(--amber-soft); color: #8a5f00; }
.activity-row.money .a-ic { background: var(--good-soft); color: var(--good-ink); }
.activity-row .a-tx { font-size: 13px; }
.activity-row .a-time { font-size: 11.5px; color: var(--ink-3); margin-top: 1px; }
.photo-ph { border-radius: 8px; display: block; }
.photo-cap { font-size: 11.5px; color: var(--ink-2); margin-top: 4px; display: flex; gap: 6px; align-items: center; }
.search-hl { background: var(--amber-soft); border-radius: 2px; }
.divider { border: 0; border-top: 1px solid var(--line-soft); margin: 14px 0; }
.qb-chip { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; font-weight: 650; color: var(--ink-3); }
.qb-chip .qb-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--good); }
.qb-chip.pending .qb-dot { background: var(--warn); }

/* detail meta list */
.meta-list { display: grid; gap: 0; }
.meta-list .meta { display: flex; gap: 10px; padding: 6.5px 0; border-bottom: 1px solid var(--line-soft); font-size: 13px; }
.meta-list .meta:last-child { border-bottom: 0; }
.meta-list .meta .m-label { flex: 0 0 118px; color: var(--ink-3); font-size: 12.5px; }
.meta-list .meta .m-value { min-width: 0; }

/* ── Mobile ── */
#mobilenav { display: none; }
@media (max-width: 900px) {
  #sidebar { display: none; }
  #view { padding: 16px 14px 96px; }
  #topbar { padding: 0 12px; }
  #mobilenav {
    display: flex; position: fixed; bottom: 0; left: 0; right: 0; z-index: 50;
    background: var(--ink); padding: 6px 6px calc(6px + env(safe-area-inset-bottom));
    justify-content: space-around;
  }
  .mn-item {
    display: grid; gap: 3px; justify-items: center; border: 0; background: none; cursor: pointer;
    color: #a5a39b; font-size: 10px; font-weight: 600; padding: 6px 10px; border-radius: 8px; position: relative;
  }
  .mn-item.active { color: var(--amber); }
  .mn-item .icon { width: 20px; height: 20px; }
  .mn-dot { position: absolute; top: 4px; right: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--crit); }
  .modal { width: 100%; max-height: 92vh; }
  .drawer { width: 100vw; max-width: 100vw; }
  .kpi .k-value { font-size: 19px; }
  #toasts { bottom: calc(74px + env(safe-area-inset-bottom)); }
}

