/* ==========================================================================
   DIGITZ UI — classic frontend · base.css
   --------------------------------------------------------------------------
   Layout and components shared by every theme. Written only against semantic
   tokens; a theme's stylesheets (themes/<theme>/tokens.css, overrides.css) set
   their values and are loaded after this file. Never reference palette ramps
   (--teal-500 etc.) here. Token contract: digitz_ui/frontend/TECHNICAL.md
   ========================================================================== */

/* The hidden attribute always wins over component display rules (e.g. .field { display: flex }). */
[hidden] { display: none !important; }

/* ==========================================================================
   Base
   ========================================================================== */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: var(--font-ui);
  font-size: var(--fs-base);
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "cv11", "ss01";
}
h1, h2, h3, h4 { margin: 0; font-family: var(--font-display); font-stretch: var(--stretch-heading); color: var(--text); letter-spacing: 0; }
h1 { font-stretch: var(--stretch-display); }
p { margin: 0; }
a { color: var(--primary); text-decoration: none; }
a:hover { color: var(--primary-hover); text-decoration: underline; text-underline-offset: 2px; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round; }
svg.i-sm { width: 15px; height: 15px; }
.num, .tabular { font-variant-numeric: tabular-nums; }
.muted { color: var(--text-3); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
:focus-visible { outline: none; box-shadow: var(--focus); border-radius: var(--r-sm); }

/* ==========================================================================
   App shell: sidebar + topbar + content
   ========================================================================== */
.app { display: grid; grid-template-columns: var(--sidebar-w) minmax(0, 1fr); min-height: 100vh; }

.sidebar {
  position: sticky; top: 0; height: 100vh;
  display: flex; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--line);
}
.sidebar__brand {
  height: var(--topbar-h); display: flex; align-items: center; gap: 10px;
  padding: 0 22px; border-bottom: 1px solid var(--line-soft);
}
.sidebar__brand img { height: 17px; width: auto; display: block; }
.sidebar__brand .sidebar__mark { display: none; height: 28px; width: 28px; object-fit: contain; }
.sidebar__company {
  margin: 14px 14px 6px; padding: 10px 12px;
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-sunk);
  cursor: pointer;
}
.sidebar__company .mono {
  width: 30px; height: 30px; border-radius: var(--r-sm); flex: none;
  display: grid; place-items: center; font-weight: 700; font-size: 12px;
  background: var(--brand-ink); color: #fff; letter-spacing: .02em;
}
.sidebar__company b { display: block; font-size: var(--fs-sm); font-weight: 600; line-height: 1.25; }
.sidebar__company small { color: var(--text-3); font-size: var(--fs-xs); }
.sidebar__company svg { margin-left: auto; color: var(--text-3); }

.nav { flex: 1; overflow-y: auto; padding: 6px 12px 16px; }
.nav__label {
  margin: 18px 10px 6px; font-size: 10.5px; font-weight: 600;
  letter-spacing: .08em; text-transform: uppercase; color: var(--text-3);
}
.nav__item {
  position: relative; display: flex; align-items: center; gap: 11px;
  height: 36px; padding: 0 10px; margin: 1px 0; border-radius: var(--r-sm);
  color: var(--text-2); font-weight: 500;
}
.nav__item:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.nav__item.is-active { background: var(--primary-soft); color: var(--primary); font-weight: 600; }
.nav__item.is-active::before {
  /* The amber marker: the one place the accent appears in the shell. */
  content: ""; position: absolute; left: -12px; top: 8px; bottom: 8px; width: 3px;
  border-radius: 0 3px 3px 0; background: var(--accent);
}
.nav__item .count {
  margin-left: auto; min-width: 20px; height: 18px; padding: 0 6px;
  border-radius: 9px; background: var(--fill-muted); color: var(--text-2);
  font-size: 11px; font-weight: 600; display: grid; place-items: center;
}
.sidebar__foot {
  padding: 12px 14px; border-top: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 10px; font-size: var(--fs-sm); color: var(--text-3);
}

.main { min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h); display: flex; align-items: center; gap: 16px;
  padding: 0 28px; background: rgba(255, 255, 255, .92);
  backdrop-filter: saturate(160%) blur(8px);
  border-bottom: 1px solid var(--line);
}
.icon-btn.topbar__menu { flex: none; margin-left: -10px; }

/* The app in use (TECHNICAL.md → Current app in the top bar): tile + family eyebrow + name; with 2+ apps, the switcher. */
.appid {
  display: flex; align-items: center; gap: 10px; min-width: 0; flex: none;
  padding: 4px 8px 4px 4px; margin-left: -4px; border: 1px solid transparent; border-radius: var(--r-md);
  background: none; color: var(--text); font: inherit; text-align: left;
}
.appid__tile {
  width: 32px; height: 32px; flex: none; display: grid; place-items: center;
  border-radius: var(--r-sm); background: var(--primary); color: var(--text-inverse);
  font: 700 12.5px var(--font-display); letter-spacing: .03em;
  box-shadow: inset 0 -3px 0 var(--accent); /* the accent underline */
}
.appid__text { display: flex; flex-direction: column; min-width: 0; line-height: 1.1; }
.appid__text small {
  font-size: 10px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--text-3);
}
.appid__text b {
  font-family: var(--font-display); font-stretch: var(--stretch-heading); font-size: 17px; font-weight: 700;
  color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 260px;
}
.topbar__sep { width: 1px; height: 24px; flex: none; background: var(--line); }
.apps-menu a .appid__tile { width: 24px; height: 24px; font-size: 10.5px; box-shadow: inset 0 -2px 0 var(--accent); }
.apps-menu__name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.apps-menu a[aria-current="true"] > svg { color: var(--primary); }
.crumbs { display: flex; align-items: center; gap: 6px; color: var(--text-3); font-size: var(--fs-sm); white-space: nowrap; }
.crumbs a { color: var(--text-3); }
.crumbs b { color: var(--text); font-weight: 600; }
.search {
  margin-left: auto; width: min(420px, 38vw); height: 36px;
  display: flex; align-items: center; gap: 8px; padding: 0 10px 0 12px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--surface-sunk);
  color: var(--text-3);
}
.search input { flex: 1; min-width: 0; border: 0; background: none; font: inherit; color: var(--text); outline: none; }
.kbd {
  font: 600 10.5px var(--font-ui); color: var(--text-3);
  border: 1px solid var(--line); border-bottom-width: 2px; border-radius: 4px; padding: 1px 5px; background: var(--surface);
}
.topbar__actions { display: flex; align-items: center; gap: 4px; }
.icon-btn {
  position: relative; width: 36px; height: 36px; border-radius: var(--r-md);
  display: grid; place-items: center; color: var(--text-2);
  background: none; border: 0; cursor: pointer;
}
.icon-btn:hover { background: var(--surface-hover); color: var(--text); }
.icon-btn .dot { position: absolute; top: 8px; right: 9px; width: 7px; height: 7px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 2px var(--surface); }
.user { display: flex; align-items: center; gap: 10px; padding-left: 12px; margin-left: 6px; border-left: 1px solid var(--line); }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 600; font-size: 12.5px;
  background: var(--avatar-bg); color: var(--avatar-text);
}
.user__meta b { display: block; font-size: var(--fs-sm); line-height: 1.2; }
.user__meta small { color: var(--text-3); font-size: var(--fs-xs); }
.user { position: relative; }
.user__btn { display: flex; align-items: center; gap: 10px; padding: 0; border: 0; background: none; color: inherit; font: inherit; text-align: left; cursor: pointer; }
.user__menu {
  position: absolute; top: calc(100% + 8px); right: 0; z-index: 50; min-width: 180px; padding: 6px;
  background: var(--surface); color: var(--text); border: 1px solid var(--line); border-radius: var(--r-md); box-shadow: var(--shadow-md);
}
.user__menu a, .user__menu button {
  display: flex; align-items: center; gap: 8px; width: 100%; padding: 8px 10px; border: 0; border-radius: var(--r-sm);
  background: none; color: var(--text); font: 500 var(--fs-sm) var(--font-ui); text-align: left; cursor: pointer;
}
.user__menu a:hover, .user__menu button:hover { background: var(--surface-hover); color: var(--text); text-decoration: none; }
.user__menu [hidden] { display: none; }
.menu-wrap { position: relative; }
.settings-menu, .apps-menu { min-width: 240px; }
.apps-menu a[aria-current="true"] { font-weight: 600; color: var(--primary); }
.menu__label { padding: 6px 10px 2px; font: 600 var(--fs-xs) var(--font-ui); letter-spacing: .06em; text-transform: uppercase; color: var(--text-3); }
.menu__company { display: flex; align-items: center; gap: 8px; padding: 6px 10px 8px; color: var(--text); font-size: var(--fs-sm); }
.menu__company b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu__sep { height: 1px; margin: 6px 4px; background: var(--line-soft); }
a.sidebar__company { color: inherit; text-decoration: none; }

.content { width: 100%; max-width: var(--content-max); margin: 0 auto; padding: 28px 28px 48px; }

/* ==========================================================================
   Page header
   ========================================================================== */
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; margin-bottom: 24px; flex-wrap: wrap; }
.page-head h1 { font-size: var(--fs-2xl); font-weight: 700; line-height: 1.15; }
.btn, .tab, .nav__label, .eyebrow, .table th { font-stretch: semi-expanded; }
.page-head p { color: var(--text-2); margin-top: 6px; }
.page-head__actions { display: flex; gap: 8px; flex-wrap: wrap; }
.eyebrow { font-size: 11px; font-weight: 600; letter-spacing: .09em; text-transform: uppercase; color: var(--accent-text); margin-bottom: 8px; }

/* ==========================================================================
   Buttons
   ========================================================================== */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 36px; padding: 0 14px; border-radius: var(--r-md);
  font: 600 var(--fs-base) var(--font-ui); white-space: nowrap; cursor: pointer;
  border: 1px solid transparent; transition: background .12s, border-color .12s, box-shadow .12s;
}
.btn:hover { text-decoration: none; }
.btn-primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-xs), inset 0 1px 0 rgba(255,255,255,.12); }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-primary:active { background: var(--primary-press); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--line-strong); box-shadow: var(--shadow-xs); }
.btn-secondary:hover { background: var(--surface-hover); color: var(--text); }
.btn-ghost { background: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--surface-hover); color: var(--text); }
.btn-accent { background: var(--accent); color: var(--accent-ink); box-shadow: var(--shadow-xs); }
.btn-accent:hover { background: var(--accent-hover); color: var(--accent-ink); }
.btn-danger { background: var(--surface); color: var(--danger-600); border-color: var(--danger-200); }
.btn-danger:hover { background: var(--danger-50); color: var(--danger-600); }
.btn-sm { height: 30px; padding: 0 10px; font-size: var(--fs-sm); border-radius: var(--r-sm); }
.btn-lg { height: 44px; padding: 0 20px; font-size: var(--fs-md); }
.btn-block { width: 100%; }
.btn-group { display: inline-flex; }
.btn-group .btn { border-radius: 0; }
.btn-group .btn:first-child { border-radius: var(--r-md) 0 0 var(--r-md); }
.btn-group .btn:last-child { border-radius: 0 var(--r-md) var(--r-md) 0; margin-left: -1px; }

/* ==========================================================================
   Cards
   ========================================================================== */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-sm); }
.card__head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line-soft); }
.card__head h2, .card__head h3 { font-size: var(--fs-md); font-weight: 650; }
.card__head p { color: var(--text-3); font-size: var(--fs-sm); margin-top: 2px; }
.card__body { padding: 20px; }
.card__foot { padding: 12px 20px; border-top: 1px solid var(--line-soft); background: var(--surface-sunk); border-radius: 0 0 var(--r-lg) var(--r-lg); }

.grid { display: grid; gap: 20px; }

/* ==========================================================================
   Badges / status pills (always label + dot, never colour alone)
   ========================================================================== */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 22px; padding: 0 9px;
  border-radius: 11px; font-size: 11.5px; font-weight: 600; white-space: nowrap;
  border: 1px solid transparent;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-neutral { background: var(--fill-muted); color: var(--text-2); border-color: var(--line); }
.badge-info    { background: var(--info-50);    color: var(--info-600);    border-color: var(--info-200); }
.badge-success { background: var(--success-50); color: var(--success-600); border-color: var(--success-200); }
.badge-warning { background: var(--warning-50); color: var(--warning-700); border-color: var(--warning-200); }
.badge-danger  { background: var(--danger-50);  color: var(--danger-600);  border-color: var(--danger-200); }
.badge-plain::before { display: none; }

/* ==========================================================================
   Forms
   ========================================================================== */
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label, .label { font-size: var(--fs-sm); font-weight: 600; color: var(--text-2); }
.field .req { color: var(--danger-600); margin-left: 2px; }
.field .hint { font-size: var(--fs-xs); color: var(--text-3); }
.input, .select, .textarea {
  width: 100%; height: 38px; padding: 0 12px;
  font: var(--fs-base) var(--font-ui); color: var(--text);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: var(--r-md);
  transition: border-color .12s, box-shadow .12s;
}
.textarea { height: auto; min-height: 84px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.select {
  appearance: none; padding-right: 34px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%236B7489' stroke-width='1.75' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 10px center;
}
.input:hover, .select:hover, .textarea:hover { border-color: var(--line-hover); }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--focus-border); box-shadow: var(--focus); }
.input[readonly] { background: var(--surface-sunk); color: var(--text-2); }
.input-wrap { position: relative; display: flex; align-items: center; }
.input-wrap > svg { position: absolute; left: 11px; color: var(--text-3); pointer-events: none; }
.input-wrap > .input { padding-left: 36px; }
.input-wrap > .suffix { position: absolute; right: 10px; color: var(--text-3); font-size: var(--fs-sm); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; color: var(--text-2); }
.check input { width: 16px; height: 16px; accent-color: var(--primary); margin: 0; }

.form-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px 20px; }
.form-grid .span-2 { grid-column: span 2; }
.form-grid .span-3 { grid-column: 1 / -1; }
.section-title { display: flex; align-items: center; gap: 10px; font: var(--stretch-heading) 650 var(--fs-md) var(--font-display); margin: 0 0 16px; }
.section-title small { font: 500 var(--fs-sm) var(--font-ui); color: var(--text-3); }

/* ==========================================================================
   Tabs
   ========================================================================== */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); padding: 0 20px; overflow-x: auto; }
.tab {
  position: relative; padding: 13px 12px; background: none; border: 0; cursor: pointer;
  font: 600 var(--fs-base) var(--font-ui); color: var(--text-3); white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.is-active { color: var(--primary); }
.tab.is-active::after { content: ""; position: absolute; left: 10px; right: 10px; bottom: -1px; height: 2px; border-radius: 2px 2px 0 0; background: var(--primary); }
.tab .count { margin-left: 6px; font-size: 11px; color: var(--text-3); background: var(--fill-muted); padding: 1px 6px; border-radius: 8px; }
.tab-panel[hidden] { display: none; }

/* ==========================================================================
   Tables
   ========================================================================== */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: var(--fs-base); }
.table th {
  position: sticky; top: 0; text-align: left; white-space: nowrap;
  padding: 10px 16px; background: var(--surface-sunk);
  font-size: 11.5px; font-weight: 600; letter-spacing: .03em; text-transform: uppercase; color: var(--text-3);
  border-bottom: 1px solid var(--line);
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
.table tbody tr:hover td { background: var(--row-hover); }
.table tbody tr:last-child td { border-bottom: 0; }
.table .r { text-align: right; font-variant-numeric: tabular-nums; }
.table .doc { font-weight: 600; color: var(--primary); white-space: nowrap; }
.table.nowrap td { white-space: nowrap; }
.table .sub { display: block; color: var(--text-3); font-size: var(--fs-sm); }

/* Editable line-item grid used on transaction pages */
.grid-table td { padding: 6px 8px; }
.grid-table th { padding: 10px 8px; }
.grid-table th:first-child, .grid-table td:first-child { padding-left: 16px; }
.grid-table th:last-child, .grid-table td:last-child { padding-right: 12px; }
.grid-table .cell {
  width: 100%; height: 34px; padding: 0 9px; border: 1px solid transparent; border-radius: var(--r-sm);
  background: transparent; font: inherit; color: var(--text);
}
.grid-table .cell.r { text-align: right; }
.grid-table tr:hover .cell { border-color: var(--line); background: var(--surface); }
.grid-table .cell:focus { outline: none; border-color: var(--focus-border); background: var(--surface); box-shadow: var(--focus); }
.grid-table .idx { color: var(--text-3); width: 36px; font-variant-numeric: tabular-nums; }
.grid-table .row-x { opacity: 0; }
.grid-table tr:hover .row-x { opacity: 1; }

/* ==========================================================================
   KPI tiles
   ========================================================================== */
.kpis { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 20px; }
.kpi { padding: 18px 20px; display: flex; flex-direction: column; gap: 10px; }
.kpi__top { display: flex; align-items: center; justify-content: space-between; color: var(--text-2); font-weight: 500; }
.kpi__icon { width: 34px; height: 34px; border-radius: var(--r-md); display: grid; place-items: center; background: var(--primary-soft); color: var(--primary); }
.kpi__value { font: var(--stretch-display) 700 26px/1.1 var(--font-display); letter-spacing: 0; font-variant-numeric: tabular-nums; }
.kpi__value small { font: 600 13px var(--font-ui); color: var(--text-3); margin-right: 4px; letter-spacing: 0; }
.kpi__foot { display: flex; align-items: center; gap: 8px; font-size: var(--fs-sm); color: var(--text-3); }
.delta { display: inline-flex; align-items: center; gap: 3px; font-weight: 600; }
.delta.up { color: var(--success-600); }
.delta.down { color: var(--danger-600); }
.kpi--feature { background: var(--grad-feature); border-color: transparent; color: #fff; position: relative; overflow: hidden; }
.kpi--feature::after { content: ""; position: absolute; right: -40px; top: -40px; width: 140px; height: 140px; border-radius: 50%; border: 1px solid rgba(255,255,255,.08); box-shadow: 0 0 0 26px rgba(255,255,255,.03); }
.kpi--feature .kpi__top, .kpi--feature .kpi__foot { color: rgba(255,255,255,.72); }
.kpi--feature .kpi__value small { color: rgba(255,255,255,.6); }
.kpi--feature .kpi__icon { background: var(--accent); color: var(--accent-ink); }
.kpi--feature .delta.up { color: var(--feature-positive); }

/* ==========================================================================
   Misc
   ========================================================================== */
.divider { height: 1px; background: var(--line-soft); margin: 20px 0; border: 0; }
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 12px; padding: 12px 20px; border-bottom: 1px solid var(--line-soft); }
.list > li:last-child { border-bottom: 0; }
.chip-icon { width: 34px; height: 34px; border-radius: var(--r-md); display: grid; place-items: center; flex: none; background: var(--fill-muted); color: var(--text-2); }
.chip-icon.blue { /* "blue" = primary tone; kept so markup matches the other themes */ }
.chip-icon.blue { background: var(--primary-soft); color: var(--primary); }
.chip-icon.amber { background: var(--accent-tint); color: var(--accent-text); }
.chip-icon.green { background: var(--green); color: var(--accent-ink); }
.chip-icon.red { background: var(--danger-50); color: var(--danger-600); }
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--fill-muted); border-radius: var(--r-md); }
.seg button { height: 28px; padding: 0 11px; border: 0; background: none; border-radius: var(--r-sm); font: 600 var(--fs-sm) var(--font-ui); color: var(--text-2); cursor: pointer; }
.seg button.is-active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-xs); }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; font-size: var(--fs-base); }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; text-align: right; font-weight: 500; font-variant-numeric: tabular-nums; }
.progress { height: 6px; border-radius: 3px; background: var(--fill-muted); overflow: hidden; }
.progress > span { display: block; height: 100%; border-radius: 3px; background: var(--primary); }

/* Chart tooltip (shared by the dashboard charts) */
.tip {
  position: fixed; z-index: 50; pointer-events: none; min-width: 150px;
  padding: 10px 12px; border-radius: var(--r-md); background: var(--tooltip-bg); color: #fff;
  font-size: var(--fs-sm); box-shadow: var(--shadow-lg); opacity: 0; transition: opacity .1s;
}
.tip.show { opacity: 1; }
.tip b { display: block; margin-bottom: 6px; font-size: var(--fs-sm); }
.tip .row { display: flex; align-items: center; gap: 8px; justify-content: space-between; }
.tip .row span:first-child { display: inline-flex; align-items: center; gap: 6px; color: rgba(255,255,255,.75); }
.tip .sw { width: 8px; height: 8px; border-radius: 2px; }

/* ==========================================================================

   Pinned documents bar
   Sits under the top bar on every app page and sticks with it. Each tab is one
   pinned transaction: type icon (module tone), number, party and a status dot.
   ========================================================================== */
.pinbar {
  position: sticky; top: var(--topbar-h); z-index: 19;
  height: var(--pinbar-h); display: flex; align-items: center; gap: 12px;
  padding: 0 20px 0 28px; background: var(--tint); border-bottom: 1px solid var(--line);
}
.pinbar__label { display: inline-flex; align-items: center; gap: 6px; flex: none; color: var(--text-2); font-size: var(--fs-sm); font-weight: 600; font-stretch: semi-expanded; }
.pinbar__label svg { color: var(--accent-text); }
.pinbar__label .count { min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; display: grid; place-items: center; background: var(--surface); border: 1px solid var(--line); font-size: 11px; color: var(--text-2); }
.pinbar__tabs {
  flex: 1; min-width: 0; display: flex; align-items: center; gap: 6px; height: 100%;
  overflow-x: auto; scrollbar-width: none;
  mask-image: linear-gradient(90deg, #000 calc(100% - 32px), transparent);
}
.pinbar__tabs::-webkit-scrollbar { display: none; }
.pinbar__empty { display: inline-flex; align-items: center; gap: 6px; color: var(--text-3); font-size: var(--fs-sm); }
.pinbar__clear { flex: none; height: 28px; padding: 0 10px; border: 0; border-radius: var(--r-sm); background: none; color: var(--text-3); font: 600 var(--fs-sm) var(--font-ui); cursor: pointer; }
.pinbar__clear:hover { background: var(--surface); color: var(--danger-600); }

.pin {
  position: relative; flex: none; display: flex; align-items: center; height: 34px; max-width: 240px;
  background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-md);
  box-shadow: var(--shadow-xs); transition: border-color .12s, box-shadow .12s;
}
.pin:hover { border-color: var(--primary-line); box-shadow: var(--shadow-sm); }
.pin > a { display: flex; align-items: center; gap: 8px; min-width: 0; height: 100%; padding: 0 4px 0 10px; color: var(--text); }
.pin > a:hover { text-decoration: none; }
.pin[data-tone="primary"] > a > svg  { color: var(--tone-primary); }
.pin[data-tone="accent"] > a > svg   { color: var(--tone-accent); }
.pin[data-tone="positive"] > a > svg { color: var(--tone-positive); }
.pin__text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.pin__text b { font: 600 12px var(--font-mono); letter-spacing: -.01em; white-space: nowrap; }
.pin__text small { font-size: 11px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pin__dot { width: 7px; height: 7px; border-radius: 50%; flex: none; margin-left: 2px; }
.pin__dot--neutral { background: var(--line-hover); }
.pin__dot--info    { background: var(--info-600); }
.pin__dot--success { background: var(--success-600); }
.pin__dot--warning { background: var(--warning-dot); }
.pin__dot--danger  { background: var(--danger-600); }
.pin__x { width: 24px; height: 24px; margin-right: 4px; flex: none; border: 0; border-radius: var(--r-xs); background: none; color: var(--text-3); display: grid; place-items: center; cursor: pointer; opacity: .55; }
.pin:hover .pin__x, .pin.is-active .pin__x, .pin__x:focus-visible { opacity: 1; }
.pin__x:hover { background: var(--fill-muted); color: var(--text); }

/* The open document: teal outline with the amber underline used by active tabs. */
.pin.is-active { border-color: var(--primary); box-shadow: inset 0 -3px 0 var(--accent), 0 2px 8px -2px var(--pin-active-glow); }
.pin.is-active .pin__text b { color: var(--primary); }
.pin.is-dragging { opacity: .45; }
.pin.drop-before::before, .pin.drop-after::after { content: ""; position: absolute; top: 4px; bottom: 4px; width: 3px; border-radius: 2px; background: var(--primary); }
.pin.drop-before::before { left: -5px; }
.pin.drop-after::after { right: -5px; }

/* Pin toggle (document header, list rows) */
.pin-btn.is-pinned { background: var(--accent-soft); border-color: var(--accent-line); color: var(--accent-text); }
.pin-btn.is-pinned svg { fill: currentColor; }
.pin-btn.is-pinned:hover { background: var(--accent-soft-hover); color: var(--accent-text); }
.row-pin { width: 28px; height: 28px; border: 1px solid transparent; border-radius: var(--r-sm); background: none; color: var(--text-3); display: grid; place-items: center; cursor: pointer; opacity: 0; }
tr:hover .row-pin, .row-pin:focus-visible, .row-pin.is-pinned { opacity: 1; }
.row-pin:hover { background: var(--surface-hover); color: var(--text); }
.row-pin.is-pinned { color: var(--accent-text); }
.row-pin.is-pinned svg { fill: currentColor; }

/* ==========================================================================
   Module tones (icons): semantic, coloured by the theme
   ========================================================================== */
.nav__item[data-tone="primary"] svg  { color: var(--tone-primary); }
.nav__item[data-tone="accent"] svg   { color: var(--tone-accent); }
.nav__item[data-tone="positive"] svg { color: var(--tone-positive); }
.nav__item.is-active svg { color: var(--text-inverse); }

/* Collapsed sidebar: icon rail on wide windows only (frontend/TECHNICAL.md → Collapsing the sidebar) */
@media (min-width: 961px) {
  .app.nav-collapsed { grid-template-columns: 68px minmax(0, 1fr); }
  .nav-collapsed .sidebar { overflow: hidden; }
  .nav-collapsed .sidebar__brand { padding: 0; justify-content: center; }
  .nav-collapsed .sidebar__brand .sidebar__logo { display: none; }
  .nav-collapsed .sidebar__brand .sidebar__mark { display: block; }  /* the compact mark fits the 68px rail */
  .nav-collapsed .sidebar__company { margin: 14px 10px 6px; padding: 6px; justify-content: center; }
  .nav-collapsed .sidebar__company > span:not(.mono),
  .nav-collapsed .sidebar__company > svg { display: none; }
  .nav-collapsed .nav { padding: 6px 10px 16px; }
  .nav-collapsed .nav__label { height: 1px; margin: 12px 6px; font-size: 0; background: var(--line-soft); }
  .nav-collapsed .nav__item { justify-content: center; padding: 0; }
  .nav-collapsed .nav__item.is-active::before { left: -10px; }
  .nav-collapsed .nav__item > span,
  .nav-collapsed .nav__item .nav__launcher-chev {
    position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
  }
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 1180px) {
  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .user__meta { display: none; }
}
@media (max-width: 960px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: fixed; z-index: 40; left: 0; top: 0; width: var(--sidebar-w); transform: translateX(-100%); transition: transform .2s; box-shadow: var(--shadow-lg); }
  .app.nav-open .sidebar { transform: none; }
  .icon-btn.topbar__menu { margin-left: -6px; }
  .topbar { padding: 0 16px; }
  .content { padding: 20px 16px 40px; }
  .form-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .crumbs, .topbar__sep { display: none; }
  .search { margin-left: 0; flex: 1; width: auto; }
  .pinbar { padding: 0 12px 0 16px; }
  .pinbar__label { font-size: 0; gap: 4px; }
  .pinbar__label .count { font-size: 11px; }
  .pinbar__clear { display: none; }
}
@media (max-width: 600px) {
  .kpis { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: auto; }
  .page-head h1 { font-size: var(--fs-xl); }
  .search .kbd { display: none; }
  .appid__text small { display: none; }
  .appid__text b { font-size: 15px; max-width: 40vw; }
}

/* Launcher ("Modules" popup) and pins: frontend/TECHNICAL.md → Launcher */
.nav__launcher { width: 100%; border: 0; background: none; font: inherit; text-align: left; cursor: pointer; }
.nav__launcher .nav__launcher-chev { margin-left: auto; color: var(--text-3); }
.launcher { position: fixed; inset: 0; z-index: 60; display: grid; place-items: start center; padding: 72px 16px 16px; }
.launcher__backdrop { position: absolute; inset: 0; background: rgba(15, 23, 42, .35); }
.launcher__panel { position: relative; width: min(960px, 100%); max-height: calc(100vh - 96px); overflow: auto; background: var(--surface); border: 1px solid var(--line); border-radius: var(--r-lg); box-shadow: var(--shadow-md); padding: 20px; }
.launcher__head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.launcher__head h2 { margin: 0; font-size: 20px; }
.launcher__search { flex: 1; }
.launcher__grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 16px; }
.launcher__card { padding: 14px 16px; }
.launcher__group { margin: 0 0 8px; font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: .04em; color: var(--text-3); }
.launcher__items { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.launcher__items li { display: flex; align-items: center; gap: 4px; }
.launcher__item { flex: 1; display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: var(--r-sm); color: var(--text); }
.launcher__item:hover { background: var(--surface-hover); text-decoration: none; }
.launcher__pin { color: var(--text-3); }
.launcher__pin.is-on { color: var(--primary); }
.launcher__empty, .launcher__note { color: var(--text-3); font-size: var(--fs-sm); }
.launcher__note { margin: 16px 0 0; }
