/* ═══════════════════════════════════════════════════════════════════
   Newon Systems — receivables cockpit
   black chassis · orange signal · cyan circuits
   ═══════════════════════════════════════════════════════════════════ */

:root {
  --page: #06070a;
  --panel: #0d0f15;
  --panel-2: #12151d;
  --panel-3: #171b25;
  --line: rgba(180, 200, 230, 0.08);
  --line-strong: rgba(180, 200, 230, 0.18);
  --ink: #eef1f6;
  --ink-2: #99a2b3;
  --ink-3: #5d6675;
  --orange: #ff7a1a;
  --orange-2: #ffa41a;
  --orange-soft: rgba(255, 122, 26, 0.14);
  --cyan: #22d9e6;
  --cyan-soft: rgba(34, 217, 230, 0.12);
  --l1: #34d399;
  --l2: #fbbf24;
  --l3: #fb923c;
  --l4: #f43f5e;
  --radius: 14px;
  --radius-sm: 9px;
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: dark;
  font-size: 15px;
}

* { box-sizing: border-box; }

html, body { margin: 0; min-height: 100%; }

body {
  background:
    radial-gradient(1000px 480px at 8% -8%, rgba(255, 122, 26, 0.07), transparent 55%),
    radial-gradient(900px 520px at 100% 12%, rgba(34, 217, 230, 0.05), transparent 55%),
    var(--page);
  background-attachment: fixed;
  color: var(--ink);
  font-family: var(--font);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  overflow-x: hidden;
}

h1, h2, h3, p { margin-top: 0; }
h1 { font-size: 1.65rem; font-weight: 700; letter-spacing: -0.015em; }
h2 { font-size: 1.04rem; font-weight: 650; letter-spacing: -0.01em; margin-bottom: 0; }
a { color: inherit; text-decoration: none; }

/* ── motion primitives ─────────────────────────────────────────────── */

@keyframes rise {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fade {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes shimmer {
  from { background-position: -600px 0; }
  to   { background-position: 600px 0; }
}
@keyframes growX {
  from { transform: scaleX(0); }
  to   { transform: scaleX(1); }
}
@keyframes pulseGlow {
  0%, 100% { box-shadow: 0 0 6px -2px var(--bv); }
  50%      { box-shadow: 0 0 16px -2px var(--bv); }
}
@keyframes drift-a {
  0%, 100% { transform: translate(0, 0) scale(1); }
  50%      { transform: translate(70px, 40px) scale(1.15); }
}
@keyframes drift-b {
  0%, 100% { transform: translate(0, 0) scale(1.1); }
  50%      { transform: translate(-60px, -30px) scale(0.95); }
}
@keyframes sparkDraw {
  from { stroke-dashoffset: 240; }
  to   { stroke-dashoffset: 0; }
}

/* page sections cascade in (login backdrop must stay un-transformed for fixed positioning) */
.page > *:not(.login-wrap) { animation: rise 0.5s cubic-bezier(0.2, 0.7, 0.3, 1) both; }
.page > *:nth-child(1) { animation-delay: 0.02s; }
.page > *:nth-child(2) { animation-delay: 0.07s; }
.page > *:nth-child(3) { animation-delay: 0.12s; }
.page > *:nth-child(4) { animation-delay: 0.17s; }
.page > *:nth-child(5) { animation-delay: 0.22s; }
.page > *:nth-child(6) { animation-delay: 0.27s; }
.page > *:nth-child(7) { animation-delay: 0.32s; }
.page > *:nth-child(8) { animation-delay: 0.37s; }

/* ── topbar ────────────────────────────────────────────────────────── */

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 84px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 22px;
  padding: 10px 28px;
  background: rgba(4, 5, 8, 0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}

/* cyan circuit line under the bar, slowly shimmering */
.topbar::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: -1px;
  height: 1px;
  background: linear-gradient(90deg,
    transparent 0%, rgba(34, 217, 230, 0.0) 20%,
    rgba(34, 217, 230, 0.55) 50%,
    rgba(34, 217, 230, 0.0) 80%, transparent 100%);
  background-size: 1200px 1px;
  animation: shimmer 7s linear infinite;
  pointer-events: none;
}

.brand { display: inline-flex; align-items: center; min-width: 0; }

.logo-frame {
  display: block;
  background: transparent;
  border: none;
}
.logo-frame img {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.nav-logo { width: 300px; height: 70px; }
.nav-logo img { filter: drop-shadow(0 0 10px rgba(255, 122, 26, 0.35)); }

.top-actions { display: flex; align-items: center; gap: 10px; }

.chip {
  font-size: 0.74rem;
  color: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 12px;
  background: var(--panel);
  white-space: nowrap;
}
.domain-chip { color: var(--cyan); border-color: rgba(34, 217, 230, 0.3); }

/* ── page & tabs ───────────────────────────────────────────────────── */

.page {
  max-width: min(1720px, 96vw);
  margin: 0 auto;
  padding: 26px 28px 90px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.top-nav {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 999px;
  margin-right: auto;
}
.top-nav a {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink-2);
  padding: 7px 20px;
  border-radius: 999px;
  transition: color 0.15s, background 0.15s;
}
.top-nav a:hover { color: var(--ink); }
.top-nav a.active {
  color: #0a0602;
  background: linear-gradient(180deg, var(--orange-2), var(--orange));
  box-shadow: 0 2px 14px -4px rgba(255, 122, 26, 0.7);
}
.nav-count {
  font-size: 0.68rem;
  font-weight: 700;
  background: var(--cyan);
  color: #041012;
  border-radius: 999px;
  padding: 1px 7px;
  font-variant-numeric: tabular-nums;
}
.top-nav a.active .nav-count { background: #0a0602; color: var(--orange-2); }

.kicker {
  display: block;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--orange);
  margin-bottom: 5px;
}

.hint { color: var(--ink-3); font-size: 0.75rem; }
.hint-block { color: var(--ink-3); font-size: 0.78rem; margin: 12px 0 0; }

/* ── metrics ───────────────────────────────────────────────────────── */

.metrics {
  display: grid;
  grid-template-columns: 1.7fr repeat(4, 1fr);
  gap: 12px;
}

.metric {
  position: relative;
  background: linear-gradient(180deg, var(--panel-2), var(--panel));
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px 14px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
  transition: transform 0.18s, border-color 0.18s;
}
.metric:hover { transform: translateY(-2px); border-color: var(--line-strong); }

.metric > span {
  font-size: 0.7rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.metric strong {
  font-size: 1.7rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
  display: flex;
  align-items: baseline;
  gap: 1px;
}
.metric strong em { font-style: normal; font-size: 1rem; color: var(--ink-2); }
.metric small { color: var(--ink-3); font-size: 0.72rem; }

.hero-metric { border-color: rgba(255, 122, 26, 0.35); }
.hero-metric::before {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(320px 130px at 18% 0%, rgba(255, 122, 26, 0.14), transparent 70%);
  pointer-events: none;
}
.hero-metric strong {
  font-size: 2.3rem;
  background: linear-gradient(100deg, #fff 20%, var(--orange-2) 75%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.hero-metric strong .cur { color: var(--orange-2); font-size: 1.4rem; }

.metric.warn { border-color: rgba(244, 63, 94, 0.45); }
.metric.warn strong { color: var(--l4); }

/* ── urgency strip ─────────────────────────────────────────────────── */

.levels-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

.level-seg {
  --lv: var(--ink-3);
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px 16px 14px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform 0.18s;
}
.level-seg:hover { transform: translateY(-2px); }
.level-seg.l1 { --lv: var(--l1); }
.level-seg.l2 { --lv: var(--l2); }
.level-seg.l3 { --lv: var(--l3); }
.level-seg.l4 { --lv: var(--l4); }
.level-seg.active {
  border-color: color-mix(in srgb, var(--lv) 35%, transparent);
  box-shadow: inset 0 0 44px -30px var(--lv);
}

.seg-label { font-size: 0.68rem; letter-spacing: 0.12em; text-transform: uppercase; color: var(--ink-3); }
.level-seg strong { font-size: 1.55rem; font-variant-numeric: tabular-nums; color: var(--lv); }
.level-seg small { color: var(--ink-3); font-size: 0.72rem; }

.seg-bar {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 3px;
  background: rgba(255, 255, 255, 0.05);
}
.seg-bar::after {
  content: "";
  position: absolute;
  inset: 0;
  width: var(--share, 0%);
  background: var(--lv);
  transform-origin: left;
  animation: growX 0.9s 0.35s cubic-bezier(0.2, 0.7, 0.3, 1) both;
  box-shadow: 0 0 8px var(--lv);
}

/* ── cards ─────────────────────────────────────────────────────────── */

.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px 22px;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.03);
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 14px;
  margin-bottom: 16px;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  align-items: start;
}

/* ── upload ────────────────────────────────────────────────────────── */

.upload-form { display: flex; flex-direction: column; gap: 14px; }
.upload-form > .btn.primary { align-self: flex-end; padding: 10px 28px; }
.dropzones { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

.dropzone {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 20px 12px 15px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: center;
  transition: border-color 0.16s, background 0.16s, transform 0.16s;
}
.dropzone:hover { border-color: var(--cyan); background: var(--cyan-soft); }
.dropzone.dragover { border-color: var(--cyan); background: var(--cyan-soft); transform: scale(1.015); }
.dropzone.has-file { border-style: solid; border-color: rgba(52, 211, 153, 0.55); }
.dropzone input[type="file"] { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.dz-icon {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border-radius: 50%;
  background: var(--panel-3);
  border: 1px solid var(--line);
  color: var(--orange);
  font-weight: 700;
  transition: transform 0.16s;
}
.dropzone:hover .dz-icon { transform: translateY(-2px); }
.dz-title { font-size: 0.85rem; font-weight: 600; }
.file-name { font-size: 0.72rem; color: var(--l1); word-break: break-all; min-height: 1em; }

/* ── forms ─────────────────────────────────────────────────────────── */

.field { display: flex; flex-direction: column; gap: 5px; flex: 1; min-width: 0; }
.field > span {
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input:not([type]), select, textarea {
  background: #0a0c11;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  color: var(--ink);
  padding: 9px 12px;
  font: inherit;
  font-size: 0.9rem;
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--cyan);
  box-shadow: 0 0 0 3px var(--cyan-soft);
}
textarea {
  resize: vertical;
  line-height: 1.45;
  font-family: ui-monospace, "SF Mono", Menlo, monospace;
  font-size: 0.82rem;
}
select { appearance: none; }

.settings-row { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 12px; }

/* ── buttons ───────────────────────────────────────────────────────── */

.btn {
  position: relative;
  font: inherit;
  font-size: 0.86rem;
  font-weight: 650;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  padding: 9px 18px;
  cursor: pointer;
  overflow: hidden;
  white-space: nowrap;
  transition: filter 0.13s, border-color 0.13s, color 0.13s, transform 0.1s;
}
.btn:active { transform: scale(0.975); }
.btn.small { padding: 6px 13px; font-size: 0.78rem; }
.btn.tiny { padding: 3px 11px; font-size: 0.7rem; border-radius: 999px; }
.btn.wide { width: 100%; }

.btn.primary {
  background: linear-gradient(180deg, var(--orange-2), var(--orange));
  color: #140800;
  box-shadow: 0 4px 20px -6px rgba(255, 122, 26, 0.65);
}
.btn.primary::after {
  content: "";
  position: absolute;
  inset: 0;
  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.35) 50%, transparent 65%);
  transform: translateX(-110%);
  transition: transform 0.5s;
}
.btn.primary:hover::after { transform: translateX(110%); }
.btn.primary:hover { filter: brightness(1.06); }

.btn.ghost { background: transparent; color: var(--ink-2); border-color: var(--line-strong); }
.btn.ghost:hover { color: var(--cyan); border-color: var(--cyan); }

.btn.danger-ghost { background: transparent; color: var(--l4); border-color: rgba(244, 63, 94, 0.35); }
.btn.danger-ghost:hover { background: rgba(244, 63, 94, 0.1); }

.btn.danger { background: var(--l4); color: #fff; border-color: var(--l4); }
.btn.danger:hover { filter: brightness(1.08); }

.btn:disabled { opacity: 0.45; cursor: not-allowed; }

/* ── mail safety switch ────────────────────────────────────────────── */

.safety-banner {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 9px 16px;
  font-size: 0.85rem;
  color: #ffd7de;
  background: linear-gradient(90deg, rgba(244, 63, 94, 0.22), rgba(244, 63, 94, 0.14));
  border-bottom: 1px solid rgba(244, 63, 94, 0.4);
}
.safety-banner a { color: #fff; text-decoration: underline; }
.safety-dot {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--l4);
  box-shadow: 0 0 8px var(--l4);
  animation: safety-pulse 1.6s ease-in-out infinite;
}
@keyframes safety-pulse { 50% { opacity: 0.35; } }
@media (prefers-reduced-motion: reduce) { .safety-dot { animation: none; } }

.chip-danger { color: #ffd7de; border-color: rgba(244, 63, 94, 0.55); background: rgba(244, 63, 94, 0.14); }
.chip-ok { color: var(--l1); border-color: rgba(52, 211, 153, 0.4); background: rgba(52, 211, 153, 0.08); }
.safety-panel.armed { border-color: rgba(244, 63, 94, 0.45); }

/* ── timeline ──────────────────────────────────────────────────────── */

.timeline-scroll { overflow-x: auto; margin: 0 -6px; padding: 0 6px; }

.timeline-table { min-width: 720px; }
.timeline-table th:first-child, .timeline-table td:first-child {
  position: sticky;
  left: 0;
  background: var(--panel);
  z-index: 2;
}

.company-cell strong { display: block; font-size: 0.88rem; }
.company-cell span { display: block; font-size: 0.68rem; color: var(--ink-3); }

.trend-cell { min-width: 150px; }

.trend-chip {
  display: inline-block;
  font-size: 0.68rem;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 10px;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}
.trend-chip::before { margin-right: 4px; }
.trend-chip.increased { color: var(--l4); background: rgba(244, 63, 94, 0.12); }
.trend-chip.increased::before { content: "▲"; }
.trend-chip.aging { color: var(--l2); background: rgba(251, 191, 36, 0.12); }
.trend-chip.aging::before { content: "◆"; }
.trend-chip.reduced { color: var(--l1); background: rgba(52, 211, 153, 0.12); }
.trend-chip.reduced::before { content: "▼"; }
.trend-chip.resolved { color: #0a0e0a; background: var(--l1); }
.trend-chip.resolved::before { content: "✓"; }
.trend-chip.new { color: var(--cyan); background: var(--cyan-soft); }
.trend-chip.new::before { content: "●"; }
.trend-chip.steady { color: var(--ink-2); background: rgba(180, 200, 230, 0.1); }
.trend-chip.steady::before { content: "→"; }

.spark { display: block; width: 120px; height: 26px; }
.spark polyline {
  fill: none;
  stroke: var(--cyan);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-dasharray: 240;
  animation: sparkDraw 1.1s 0.3s cubic-bezier(0.3, 0.6, 0.3, 1) both;
}
.spark-dot { fill: var(--ink-2); }
.spark-dot.lvl1 { fill: var(--l1); }
.spark-dot.lvl2 { fill: var(--l2); }
.spark-dot.lvl3 { fill: var(--l3); }
.spark-dot.lvl4 { fill: var(--l4); }

.month-cell { min-width: 108px; border-radius: 6px; }
.month-cell strong { display: block; font-size: 0.84rem; font-variant-numeric: tabular-nums; }
.month-cell small { color: var(--ink-3); font-size: 0.68rem; }
.month-cell.l1 { background: rgba(52, 211, 153, 0.07); }
.month-cell.l2 { background: rgba(251, 191, 36, 0.07); }
.month-cell.l3 { background: rgba(251, 146, 60, 0.09); }
.month-cell.l4 { background: rgba(244, 63, 94, 0.1); }
.month-cell .dash { color: var(--ink-3); }

.latest-total { font-variant-numeric: tabular-nums; font-weight: 650; margin-left: 6px; }

/* ── exposure chart ────────────────────────────────────────────────── */

.chart-wrap { position: relative; width: 100%; }
#exposure-chart { display: block; width: 100%; overflow: visible; }

.grid-line { stroke: rgba(180, 200, 230, 0.07); stroke-width: 1; }
.axis-label { fill: var(--ink-3); font-size: 11px; font-family: var(--font); font-variant-numeric: tabular-nums; }

.series-line { fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; transition: opacity 0.15s; }
.series-dot { transition: opacity 0.15s, r 0.15s; }
.series-label { font-size: 11.5px; font-weight: 650; font-family: var(--font); transition: opacity 0.15s; }
/* value labels shown on a line while its legend chip is hovered — haloed for legibility over the plot */
.series-value {
  font-size: 10.5px; font-weight: 650; font-family: var(--font);
  font-variant-numeric: tabular-nums; fill: var(--ink);
  paint-order: stroke; stroke: var(--page); stroke-width: 3px; stroke-linejoin: round;
}
svg.focus .series.hot .series-value { opacity: 1; }

/* legend-hover focus: dim everything except the hot series */
svg.focus .series { opacity: 0.18; }
svg.focus .series.hot { opacity: 1; }
.series { transition: opacity 0.18s; }

.cursor-line { stroke: rgba(238, 241, 246, 0.25); stroke-width: 1; stroke-dasharray: 3 4; }

/* per-invoice line chart (company modal) */
.line-chart-wrap { width: 100%; margin: 4px 0 10px; }
.inv-line { display: block; width: 100%; height: auto; overflow: visible; }
.inv-line .paid-dot { fill: var(--panel); stroke-width: 2; }
.inv-line .series { transition: opacity 0.15s; }
.inv-line.focus .series:not(.hot) { opacity: 0.22; }

.chart-tip {
  position: fixed;
  z-index: 80;
  min-width: 190px;
  max-width: 280px;
  pointer-events: none;
  background: rgba(16, 19, 27, 0.94);
  backdrop-filter: blur(10px);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  font-size: 0.76rem;
  box-shadow: 0 14px 34px -14px rgba(0, 0, 0, 0.8);
}
.chart-tip strong { display: block; color: var(--ink-2); font-size: 0.7rem; letter-spacing: 0.08em; margin-bottom: 5px; }
.tip-row { display: flex; align-items: center; gap: 7px; padding: 2px 0; color: var(--ink); }
.tip-row i { width: 8px; height: 8px; border-radius: 50%; flex: none; }
.tip-row b { margin-left: auto; font-variant-numeric: tabular-nums; }
.tip-row em { font-style: normal; color: var(--ink-3); font-size: 0.68rem; }

.chart-legend { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
.legend-chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font: inherit;
  font-size: 0.74rem;
  font-weight: 600;
  color: var(--ink-2);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 13px;
  cursor: default;
  transition: color 0.14s, border-color 0.14s;
}
.legend-chip { cursor: pointer; user-select: none; }
.legend-chip:hover { color: var(--ink); border-color: var(--line-strong); }
.legend-chip i { width: 9px; height: 9px; border-radius: 50%; transition: opacity 0.14s; }
.legend-chip.off { color: var(--ink-3); border-style: dashed; }
.legend-chip.off i { opacity: 0.25; }
.legend-chip.off span, .legend-chip.off { text-decoration: line-through; text-decoration-color: var(--ink-3); }

.delta { font-variant-numeric: tabular-nums; font-weight: 650; }
.delta.up { color: var(--l4); }
.delta.down { color: var(--l1); }

/* ── queue / drafts ────────────────────────────────────────────────── */

.queue { display: flex; flex-direction: column; gap: 10px; }

.draft {
  --lv: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  overflow: hidden;
  transition: transform 0.16s, border-color 0.16s, box-shadow 0.16s;
}
.draft:hover {
  transform: translateY(-1px);
  border-color: color-mix(in srgb, var(--lv) 30%, var(--line));
  box-shadow: 0 6px 22px -14px var(--lv);
}
.draft.l1 { --lv: var(--l1); }
.draft.l2 { --lv: var(--l2); }
.draft.l3 { --lv: var(--l3); }
.draft.l4 { --lv: var(--l4); }

.draft summary {
  list-style: none;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 12px 16px;
  cursor: pointer;
  border-left: 3px solid var(--lv);
}
.draft summary::-webkit-details-marker { display: none; }
.draft[open] summary { border-bottom: 1px solid var(--line); }

.draft-body { padding: 16px; position: relative; animation: rise 0.28s cubic-bezier(0.2, 0.7, 0.3, 1) both; }

.badge {
  --bv: var(--lv);
  font-size: 0.72rem;
  font-weight: 700;
  color: #0a0e1a;
  background: var(--bv);
  border-radius: 6px;
  padding: 3px 8px;
  box-shadow: 0 0 12px -2px var(--bv);
  flex: none;
}
.badge.sm { font-size: 0.65rem; padding: 2px 6px; box-shadow: none; }
.badge.l1 { --bv: var(--l1); }
.badge.l2 { --bv: var(--l2); }
.badge.l3 { --bv: var(--l3); }
.badge.l4 { --bv: var(--l4); animation: pulseGlow 2.4s ease-in-out infinite; }

.draft-client {
  font-weight: 600;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.warn-tag {
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--l4);
  border: 1px solid rgba(244, 63, 94, 0.4);
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 8px;
  vertical-align: 1px;
}
.draft-lang { font-size: 0.7rem; color: var(--ink-3); letter-spacing: 0.08em; }
.draft-days { font-size: 0.8rem; color: var(--lv); font-variant-numeric: tabular-nums; white-space: nowrap; }
.draft-amount { font-weight: 650; font-variant-numeric: tabular-nums; white-space: nowrap; }

.chev {
  width: 8px; height: 8px;
  border-right: 2px solid var(--ink-3);
  border-bottom: 2px solid var(--ink-3);
  transform: rotate(45deg);
  transition: transform 0.18s;
  flex: none;
}
.draft[open] .chev { transform: rotate(-135deg); }

.draft-meta {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--ink-3);
  font-size: 0.8rem;
  margin-bottom: 14px;
}
.warn-text { color: var(--l4); }

.toggles { display: inline-flex; gap: 8px; align-items: center; flex: none; }

.lang-toggle {
  display: inline-flex;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  overflow: hidden;
}
.lang-toggle button {
  font: inherit;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  padding: 4px 13px;
  border: none;
  background: transparent;
  color: var(--ink-3);
  cursor: pointer;
  transition: color 0.13s, background 0.13s;
}
.lang-toggle button:hover { color: var(--ink); }
.lang-toggle button.on { background: var(--cyan); color: #041012; }
.level-toggle button.on.lv1 { background: var(--l1); color: #041008; }
.level-toggle button.on.lv2 { background: var(--l2); color: #140f02; }
.level-toggle button.on.lv3 { background: var(--l3); color: #140902; }
.level-toggle button.on.lv4 { background: var(--l4); color: #fff; }

.draft-form { display: flex; flex-direction: column; gap: 12px; }
.two-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.draft-actions { display: flex; justify-content: flex-end; }
.reject-form { position: absolute; bottom: 16px; left: 16px; }

/* ── tables ────────────────────────────────────────────────────────── */

/* wide tables scroll inside their card, never the page */
.table-scroll {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin: 0 -6px;
  padding: 0 6px;
  scrollbar-width: thin;
}
.table-scroll .data-table { min-width: 540px; }
.table-scroll .standing-table { min-width: 660px; }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.83rem; }
.data-table th {
  text-align: left;
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--ink-3);
  font-weight: 650;
  padding: 6px 10px;
  border-bottom: 1px solid var(--line);
}
.data-table td { padding: 9px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.data-table tbody tr { transition: background 0.13s; }
.data-table tbody tr:hover { background: rgba(180, 200, 230, 0.03); }
.data-table tr:last-child td { border-bottom: none; }
.data-table .num { font-variant-numeric: tabular-nums; text-align: right; white-space: nowrap; }
.data-table .dim { color: var(--ink-3); font-size: 0.76rem; white-space: nowrap; }
.row-note { display: block; font-size: 0.68rem; color: var(--ink-3); max-width: 260px; }

.status-chip {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 650;
  border-radius: 999px;
  padding: 2px 10px;
  text-transform: capitalize;
}
.status-chip.sent { color: var(--l1); background: rgba(52, 211, 153, 0.12); }
.status-chip.auto-sent { color: var(--cyan); background: var(--cyan-soft); }
.status-chip.rejected { color: var(--ink-2); background: rgba(180, 200, 230, 0.1); }
.status-chip.superseded { color: var(--ink-3); background: rgba(180, 200, 230, 0.06); }
.status-chip.held { color: var(--l2); background: rgba(251, 191, 36, 0.12); }
.status-chip.neutral { color: var(--cyan); background: var(--cyan-soft); }
.status-chip.paid { color: var(--l1); background: rgba(52, 211, 153, 0.14); }

/* ── company source-data modal ─────────────────────────────────────── */

.company-row { cursor: pointer; }
.company-row:hover td { background: rgba(34, 217, 230, 0.04); }
.company-row:focus-visible { outline: 2px solid var(--cyan); outline-offset: -2px; }

.modal-backdrop[hidden] { display: none; }
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(3, 4, 7, 0.72);
  animation: fade 0.18s ease both;
}
/* the blur lives on a layer *behind* the modal, so the modal's own text is
   never re-sampled through backdrop-filter (which blurs it in Chrome) */
.modal-backdrop::before {
  content: "";
  position: absolute;
  inset: 0;
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  z-index: 0;
}
.modal {
  position: relative;
  z-index: 1;
  width: min(960px, 96vw);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  background: var(--panel);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius);
  box-shadow: 0 40px 90px -30px rgba(0, 0, 0, 0.9);
  animation: rise 0.24s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 20px 22px 14px;
  border-bottom: 1px solid var(--line);
}
.modal-close {
  font: inherit;
  font-size: 1.5rem;
  line-height: 1;
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--ink-3);
  width: 34px;
  height: 34px;
  cursor: pointer;
  transition: color 0.14s, border-color 0.14s;
}
.modal-close:hover { color: var(--ink); border-color: var(--line-strong); }
.modal-body { overflow-y: auto; padding: 16px 22px 24px; }

.modal-section { margin-bottom: 20px; }
.modal-section h3 { font-size: 0.86rem; font-weight: 650; margin-bottom: 10px; }
.modal-section .mono { font-family: ui-monospace, Menlo, monospace; color: var(--cyan); font-size: 0.82em; }

.kv-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 18px; margin-bottom: 12px; }
.kv-grid span { font-size: 0.82rem; color: var(--ink); }
.kv-grid b {
  display: block;
  font-size: 0.64rem;
  font-weight: 650;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}

.src-label {
  font-size: 0.68rem;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-3);
  margin: 10px 0 6px;
}
.raw-row { display: flex; flex-wrap: wrap; gap: 6px; }
.raw-chip {
  font-size: 0.72rem;
  font-family: ui-monospace, Menlo, monospace;
  color: var(--ink-2);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 3px 8px;
  max-width: 100%;
  overflow-wrap: anywhere;
}
.raw-chip b {
  color: var(--ink-3);
  font-weight: 600;
  margin-right: 6px;
}
.raw-chip.hot {
  border-color: rgba(255, 122, 26, 0.55);
  background: rgba(255, 122, 26, 0.09);
  color: var(--orange-2);
}
.raw-chip.hot b { color: rgba(255, 164, 26, 0.7); }

/* ── company contacts / merge (modal) ─────────────────────────────── */

.emails-form { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 8px; flex-wrap: wrap; }
.emails-form .field.grow { flex: 1; min-width: 220px; }
.emails-status { font-size: 0.8rem; align-self: center; }

.merge-form { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 8px; }
.field-select {
  flex: 1;
  min-width: 220px;
  background: var(--panel-2);
  color: var(--ink);
  border: 1px solid var(--line-strong);
  border-radius: 10px;
  padding: 9px 12px;
  font: inherit;
  font-size: 0.86rem;
}

.alias-chip {
  font-size: 0.74rem;
  color: var(--cyan);
  background: rgba(34, 217, 230, 0.08);
  border: 1px solid rgba(34, 217, 230, 0.3);
  border-radius: 999px;
  padding: 3px 10px;
}
.alias-note {
  font-size: 0.7rem;
  color: var(--cyan);
  border: 1px solid rgba(34, 217, 230, 0.3);
  border-radius: 999px;
  padding: 1px 8px;
  margin-left: 8px;
  white-space: nowrap;
}

.modal-invoice {
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 10px;
  background: var(--panel-2);
}
.snap-group { margin-bottom: 14px; }
.snap-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; font-size: 0.84rem; }
.snap-head .mono { font-family: ui-monospace, Menlo, monospace; color: var(--cyan); }
.inv-table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
.inv-table th {
  text-align: left; font-weight: 600; color: var(--ink-3);
  padding: 4px 8px; border-bottom: 1px solid var(--line);
  font-size: 0.7rem; text-transform: uppercase; letter-spacing: 0.05em;
}
.inv-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: baseline; }
.inv-table tbody tr:last-child td { border-bottom: none; }
.inv-table td.num, .inv-table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.inv-table td.mono { font-family: ui-monospace, Menlo, monospace; color: var(--cyan); white-space: nowrap; }
.snap-older summary { cursor: pointer; color: var(--ink-3); font-size: 0.82rem; margin: 8px 0; }
.snap-older[open] summary { margin-bottom: 10px; }

.inv-line { display: flex; flex-wrap: wrap; gap: 14px; align-items: baseline; font-size: 0.84rem; }
.inv-line .mono { font-family: ui-monospace, Menlo, monospace; color: var(--cyan); }
.inv-amount { margin-left: auto; font-variant-numeric: tabular-nums; font-size: 0.95rem; }

/* ── misc bits ─────────────────────────────────────────────────────── */

.metric-link { color: var(--cyan); }
.metric-link:hover { text-decoration: underline; }
.dl-link { color: var(--cyan); white-space: nowrap; text-decoration: none; }
.dl-link:hover { text-decoration: underline; }

.stat-rows { display: flex; flex-direction: column; }
.stat-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 11px 2px;
  border-bottom: 1px solid var(--line);
  font-size: 0.86rem;
}
.stat-row:last-child { border-bottom: none; }
.stat-row span { color: var(--ink-2); }
.stat-row strong { font-variant-numeric: tabular-nums; }

.draft-to {
  font-size: 0.74rem;
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.tpl-tag {
  font-size: 0.66rem;
  font-weight: 700;
  color: var(--cyan);
  border: 1px solid rgba(34, 217, 230, 0.4);
  border-radius: 999px;
  padding: 1px 8px;
}
.toggle-label {
  font-size: 0.66rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.dim { color: var(--ink-3); }

/* ── rich editor & templates tab ───────────────────────────────────── */

.rich-editor {
  min-height: 170px;
  max-height: 420px;
  overflow-y: auto;
  background: #0a0c11;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 0.88rem;
  line-height: 1.55;
  transition: border-color 0.15s, box-shadow 0.15s;
}
.rich-editor:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 0 3px var(--cyan-soft); }
.rich-editor.dragover { border-color: var(--orange); box-shadow: 0 0 0 3px var(--orange-soft); }
.rich-editor p { margin: 0 0 0.7em; }
.rich-editor ul { margin: 0.4em 0; padding-left: 1.3em; }
.rich-editor img { max-width: 100%; height: auto; border-radius: 6px; }
.rich-editor a { color: var(--cyan); text-decoration: underline; }
.tpl-editor { min-height: 260px; }

.editor-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 4px;
  padding: 6px 8px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-bottom: none;
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.editor-toolbar + .rich-editor { border-top-left-radius: 0; border-top-right-radius: 0; }
.editor-toolbar button, .toolbar-upload {
  font: inherit;
  font-size: 0.76rem;
  color: var(--ink-2);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 6px;
  padding: 4px 9px;
  cursor: pointer;
  transition: color 0.12s, background 0.12s;
}
.editor-toolbar button:hover, .toolbar-upload:hover { color: var(--ink); background: rgba(180, 200, 230, 0.08); }
.toolbar-sep { width: 1px; height: 18px; background: var(--line-strong); margin: 0 6px; }
.toolbar-label { font-size: 0.66rem; letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-3); margin-right: 2px; }
.editor-toolbar .var-chip {
  color: var(--orange-2);
  border-color: rgba(255, 122, 26, 0.3);
  font-family: ui-monospace, Menlo, monospace;
  font-size: 0.7rem;
}
.editor-toolbar .var-chip:hover { background: var(--orange-soft); color: var(--orange-2); }

.tpl-selectors { display: flex; gap: 22px; flex-wrap: wrap; margin-bottom: 16px; }
.tpl-subject { margin-bottom: 14px; }
.field-label {
  font-size: 0.68rem;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--ink-3);
  display: block;
  margin-bottom: 5px;
}
.tpl-actions { display: flex; justify-content: space-between; margin-top: 14px; }
.tpl-status {
  font-size: 0.7rem;
  font-weight: 650;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--ink-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 12px;
}
.tpl-status.customised { color: var(--orange-2); border-color: rgba(255, 122, 26, 0.4); }

.lang-toggle .busy { opacity: 0.5; pointer-events: none; }
form.lang-toggle.busy { opacity: 0.5; pointer-events: none; }

/* ── modal history sections ────────────────────────────────────────── */

.balance-rows { display: flex; flex-direction: column; gap: 6px; }
.balance-row {
  display: grid;
  grid-template-columns: 84px 1fr 92px auto;
  gap: 12px;
  align-items: center;
  font-size: 0.8rem;
}
.balance-row b { font-variant-numeric: tabular-nums; text-align: right; }
.balance-bar { height: 10px; background: rgba(180, 200, 230, 0.06); border-radius: 999px; overflow: hidden; }
.balance-bar i { display: block; height: 100%; border-radius: 999px; background: var(--ink-3); }
.balance-bar .lvl1 { background: var(--l1); }
.balance-bar .lvl2 { background: var(--l2); }
.balance-bar .lvl3 { background: var(--l3); }
.balance-bar .lvl4 { background: var(--l4); }
.mono { font-family: ui-monospace, Menlo, monospace; font-size: 0.9em; }

.reminder-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.78rem;
}
.reminder-row:last-child { border-bottom: none; }
.reminder-subject { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink-2); }

.modal-src { margin-top: 4px; }
.modal-src summary {
  cursor: pointer;
  font-size: 0.78rem;
  color: var(--ink-3);
  padding: 8px 0;
  border-top: 1px solid var(--line);
}
.modal-src summary:hover { color: var(--ink); }
.inv-sep { border: none; border-top: 1px dashed var(--line); margin: 10px 0; }

/* ── status legend ─────────────────────────────────────────────────── */

.status-legend { margin-bottom: 14px; }
.status-legend summary {
  cursor: pointer;
  font-size: 0.76rem;
  color: var(--ink-3);
  padding: 2px 0 8px;
}
.status-legend summary:hover { color: var(--ink); }
.status-legend ul { list-style: none; margin: 0 0 8px; padding: 0; display: flex; flex-direction: column; gap: 7px; }
.status-legend li { font-size: 0.78rem; color: var(--ink-2); display: flex; align-items: baseline; gap: 10px; }
.status-legend .status-chip { flex: none; min-width: 74px; text-align: center; }

/* ── mailbox ───────────────────────────────────────────────────────── */

.mail-client {
  display: grid;
  grid-template-columns: minmax(280px, 400px) 1fr;
  gap: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  height: max(480px, calc(100vh - 285px));
  background: var(--panel-2);
}

/* the mailbox is an app screen, not a document: on desktop the window never
   scrolls — the conversation list, thread, and compose panes scroll inside */
@media (min-width: 861px) {
  body:has(.mail-card) {
    height: 100vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
  }
  body:has(.mail-card) .topbar { flex: none; }
  body:has(.mail-card) .page {
    flex: 1;
    width: 100%;
    min-height: 0;
    padding-bottom: 22px;
  }
  .mail-card {
    flex: 1;
    min-height: 0;
    display: flex;
    flex-direction: column;
  }
  .mail-card .card-head { flex: none; }
  .mail-card .mail-client { flex: 1; height: auto; }
}

/* grid/flex children must be allowed to shrink, otherwise the panes grow
   past the container and the inner scrollbars never engage */
.mail-client > * { min-height: 0; }

.mail-list {
  border-right: 1px solid var(--line);
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.mail-list-empty { margin: auto 14px; }

.mail-toolbar { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }

.mail-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 12px 14px;
  font: inherit;
  text-align: left;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
  transition: background 0.13s;
}
.mail-item:hover { background: rgba(180, 200, 230, 0.04); }
.mail-item.on { background: var(--cyan-soft); box-shadow: inset 2px 0 0 var(--cyan); }

.mail-avatar {
  width: 36px;
  height: 36px;
  flex: none;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: var(--panel-3);
  border: 1px solid var(--line-strong);
  color: var(--ink-2);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}
.mail-item.unread .mail-avatar { border-color: var(--cyan); color: var(--cyan); }

.mail-item-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.mail-item-top { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.mail-item-top b {
  font-size: 0.84rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mail-item-top time { font-size: 0.66rem; color: var(--ink-3); flex: none; font-variant-numeric: tabular-nums; }
.mail-item-snippet {
  font-size: 0.74rem;
  color: var(--ink-3);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.mail-item.unread .mail-item-snippet { color: var(--ink-2); font-weight: 600; }

.mail-unread {
  flex: none;
  min-width: 20px;
  text-align: center;
  font-size: 0.68rem;
  font-weight: 700;
  background: var(--cyan);
  color: #041012;
  border-radius: 999px;
  padding: 2px 6px;
}
.mail-count { flex: none; font-size: 0.68rem; color: var(--ink-3); }

.mail-pane { display: flex; flex-direction: column; min-width: 0; }
.mail-placeholder { margin: auto; border: none; }

.mail-thread-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--line);
}
.mail-thread-head h3 { margin: 0; font-size: 0.95rem; }
.mail-thread-head .dim { font-size: 0.72rem; }
.mail-back { display: none; flex: none; }

.mail-thread {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.mail-body blockquote, .rich-editor blockquote {
  margin: 8px 0 0;
  padding: 6px 0 6px 12px;
  border-left: 3px solid var(--line-strong);
  color: var(--ink-3);
}
.quote-head { color: var(--ink-3); font-size: 0.76rem; margin: 10px 0 2px; }

/* ── compose & reply ───────────────────────────────────────────────── */

.mail-compose {
  grid-column: 2;
  grid-row: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  overflow-y: auto;
}
.mail-compose[hidden], .mail-pane[hidden] { display: none; }
.mail-compose .mail-thread-head h3 { margin: 0; }

.compose-fields {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  flex: 1;
}
.compose-body-field { flex: 1; display: flex; flex-direction: column; }
.compose-editor { flex: 1; min-height: 220px; }

.compose-tpl {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 10px 12px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
}

.compose-actions {
  display: flex;
  gap: 10px;
  padding: 12px 16px 16px;
  border-top: 1px solid var(--line);
}

.mail-reply {
  border-top: 1px solid var(--line);
  padding: 14px 16px 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: var(--panel);
}
.mail-reply[hidden] { display: none; }
.mail-reply .reply-editor { min-height: 120px; max-height: 260px; }
.mail-reply .compose-actions { padding: 0 0 14px; border-top: none; }
.mail-reply-btn { margin-left: auto; }

.mail-msg {
  max-width: 88%;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel);
  padding: 12px 14px;
}
.mail-msg.out { align-self: flex-end; border-color: rgba(255, 122, 26, 0.25); }
.mail-msg.in  { align-self: flex-start; border-color: rgba(34, 217, 230, 0.3); background: rgba(34, 217, 230, 0.04); }

.mail-msg header {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.mail-msg header time { margin-left: auto; font-size: 0.68rem; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.mail-addr { font-size: 0.7rem; color: var(--ink-3); overflow: hidden; text-overflow: ellipsis; }
.mail-addr b { color: var(--ink-2); font-weight: 600; }
.mail-msg h4 { margin: 0 0 6px; font-size: 0.86rem; }
.mail-body { font-size: 0.84rem; color: var(--ink-2); line-height: 1.55; overflow-wrap: anywhere; }
.mail-body p { margin: 0 0 0.6em; }
.mail-body ul { margin: 0.4em 0; padding-left: 1.3em; }
.mail-body img { max-width: 100%; height: auto; border-radius: 6px; }

/* ── attachments: compose dropzone + chips ─────────────────────────── */
.attach-zone { display: flex; flex-direction: column; gap: 8px; }
.attach-drop {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 14px;
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius-sm);
  color: var(--ink-3);
  font-size: 0.8rem;
  transition: border-color 0.14s, background 0.14s, color 0.14s;
}
.attach-drop-icon { font-size: 1rem; }
.attach-browse {
  font: inherit;
  font-size: 0.8rem;
  color: var(--cyan);
  background: none;
  border: none;
  padding: 0;
  cursor: pointer;
  text-decoration: underline;
}
.attach-zone.drag-over .attach-drop {
  border-color: var(--orange);
  background: var(--orange-soft);
  color: var(--ink);
}
.attach-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 8px; }
.attach-zone:not(.has-files) .attach-list { display: none; }
.attach-chip {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 260px;
  padding: 6px 8px 6px 10px;
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  background: var(--panel-2);
  font-size: 0.76rem;
}
.attach-chip-icon { flex: none; }
.attach-chip-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--ink); }
.attach-chip-size { flex: none; color: var(--ink-3); font-variant-numeric: tabular-nums; }
.attach-chip-x {
  flex: none;
  width: 18px; height: 18px;
  display: grid; place-items: center;
  border: none; border-radius: 50%;
  background: var(--panel-3); color: var(--ink-2);
  cursor: pointer; font-size: 0.9rem; line-height: 1;
}
.attach-chip-x:hover { background: var(--l4); color: #fff; }

/* ── attachments: received/sent files inside a message ─────────────── */
.msg-attachments { margin-top: 10px; display: flex; flex-wrap: wrap; gap: 8px; }
.attach-file {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  max-width: 280px;
  padding: 8px 10px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  text-decoration: none;
  transition: border-color 0.14s, background 0.14s;
}
.attach-file:hover { border-color: var(--cyan); background: var(--cyan-soft); }
.attach-file-icon { font-size: 1.1rem; flex: none; }
.attach-file-meta { display: flex; flex-direction: column; min-width: 0; line-height: 1.25; }
.attach-file-meta b { color: var(--ink); font-weight: 600; font-size: 0.78rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.attach-file-meta em { color: var(--ink-3); font-style: normal; font-size: 0.68rem; font-variant-numeric: tabular-nums; }
.attach-file-dl { margin-left: auto; color: var(--cyan); font-weight: 700; flex: none; }

/* ── company/invoice modal enhancements ────────────────────────────── */
.modal.modal-sm { width: min(780px, 96vw); }
#invoice-modal { z-index: 60; }

.cm-stats, .inv-stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(90px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}
.cm-stat, .inv-stat {
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
}
.cm-stat > span, .inv-stat > span {
  display: block;
  font-size: 0.66rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  margin-bottom: 4px;
}
.cm-stat > strong, .inv-stat > strong {
  font-size: 1.15rem;
  font-variant-numeric: tabular-nums;
  display: inline-flex;
  align-items: baseline;
  gap: 2px;
}
.cm-stat > strong em, .inv-stat > strong em { font-style: normal; font-size: 0.7rem; color: var(--ink-3); }

/* per-company mini-dashboard */
.cm-dash {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(104px, 1fr));
  gap: 8px;
  margin-bottom: 10px;
}
.cm-metric {
  padding: 9px 11px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
}
.cm-metric > span {
  display: block;
  font-size: 0.62rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-3);
  margin-bottom: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.cm-metric > strong { font-size: 1.05rem; font-variant-numeric: tabular-nums; }
.cm-metric > strong em { font-style: normal; font-size: 0.68rem; color: var(--ink-3); margin-left: 1px; }
.cm-metric.pos > strong { color: var(--l1); }
.cm-risk {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 18px;
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  font-size: 0.85rem;
}
.cm-risk .cm-risk-label { color: var(--ink-3); text-transform: uppercase; font-size: 0.64rem; letter-spacing: 0.06em; }
.cm-risk b { font-size: 0.95rem; }
.cm-risk .dim { margin-left: auto; font-size: 0.74rem; }
.cm-risk.risk-good   { border-color: rgba(52,211,153,0.4); }
.cm-risk.risk-good b   { color: var(--l1); }
.cm-risk.risk-watch  { border-color: rgba(251,191,36,0.4); }
.cm-risk.risk-watch b  { color: var(--l2); }
.cm-risk.risk-poor   { border-color: rgba(251,146,60,0.45); }
.cm-risk.risk-poor b   { color: var(--l3); }
.cm-risk.risk-high   { border-color: rgba(244,63,94,0.5); }
.cm-risk.risk-high b   { color: var(--l4); }

.danger-link { color: var(--l4); }
.danger-link:hover { text-decoration: underline; }
.file-del-form { display: inline; }

/* invoice bar chart */
.inv-chart { display: block; height: auto; max-width: none; }
/* horizontally scrollable chart wrapper (like table-scroll) — key for many
   invoices and for mobile */
.chart-scroll {
  overflow-x: auto;
  overflow-y: hidden;
  margin: 4px 0 14px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
}
.chart-scroll .inv-chart { margin: 0; }

/* count pill next to a section heading */
.count-pill {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 999px;
  background: var(--panel-3);
  color: var(--ink-2);
  font-size: 0.72rem;
  font-weight: 600;
  vertical-align: middle;
}
.inv-chart .ic-grid { stroke: var(--line); stroke-width: 1; }
.inv-chart .ic-y { fill: var(--ink-3); font-size: 9px; text-anchor: end; font-variant-numeric: tabular-nums; }
.inv-chart .ic-x { fill: var(--ink-2); font-size: 9px; text-anchor: middle; font-family: ui-monospace, Menlo, monospace; }
.inv-chart .ic-x2 { fill: var(--ink-3); font-size: 9px; text-anchor: middle; font-variant-numeric: tabular-nums; }
.inv-chart .inv-bar { cursor: pointer; }
.inv-chart .inv-bar:hover rect, .inv-chart .inv-bar:focus rect { opacity: 1; stroke: var(--ink); stroke-width: 1.5; }
.inv-chart .inv-bar:focus { outline: none; }

/* clickable invoice table rows */
.inv-table-click tbody tr { cursor: pointer; transition: background 0.12s; }
.inv-table-click tbody tr:hover, .inv-table-click tbody tr:focus { background: var(--panel-3); outline: none; }
.inv-go { color: var(--ink-3); text-align: right; font-size: 1.1rem; width: 1%; }
tr.inv-click { cursor: pointer; }
tr.inv-click:hover, tr.inv-click:focus { background: var(--panel-3); outline: none; }
tr.inv-click:hover .inv-go, tr.inv-click:focus .inv-go { color: var(--cyan); }

/* sortable headers */
.th-sort { cursor: pointer; user-select: none; position: relative; white-space: nowrap; }
.th-sort:hover { color: var(--ink); }
.th-sort::after { content: "⇅"; opacity: 0.3; margin-left: 5px; font-size: 0.8em; }
.th-sort[data-dir="asc"]::after { content: "↑"; opacity: 0.9; color: var(--cyan); }
.th-sort[data-dir="desc"]::after { content: "↓"; opacity: 0.9; color: var(--cyan); }
.data-table.sortable th.num.th-sort { text-align: right; }

/* invoice modal: uploaded-document slot */
.inv-doc-present { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.inv-doc-drop { cursor: pointer; }
.inv-doc-drop .attach-browse { pointer-events: none; }
.inv-doc-status { display: inline-block; margin-top: 6px; font-size: 0.78rem; }

/* floating chart tooltip (shows the actual value on hover) */
.chart-tip-float {
  position: fixed;
  z-index: 80;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  gap: 1px;
  padding: 7px 10px;
  background: var(--panel-3);
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  box-shadow: 0 10px 28px -10px rgba(0, 0, 0, 0.8);
}
.chart-tip-float[hidden] { display: none; }
.chart-tip-float b { color: var(--ink-2); font-family: ui-monospace, Menlo, monospace; font-size: 0.7rem; font-weight: 600; }
.chart-tip-float span { color: var(--ink); font-weight: 700; font-size: 0.9rem; font-variant-numeric: tabular-nums; }
.chart-tip-float em { color: var(--ink-3); font-style: normal; font-size: 0.68rem; }

.inv-chart .ch-bar rect { opacity: 0.92; transition: opacity 0.1s; }
.inv-chart .ch-bar:hover rect { opacity: 1; stroke: var(--ink); stroke-width: 1.2; }
.inv-chart .ch-bar { cursor: default; }

/* invoice modal: clear headline + labelled facts */
.inv-hero {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 16px 18px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: var(--panel-2);
  margin-bottom: 8px;
}
.inv-hero.inv-hero-paid { border-color: rgba(52, 211, 153, 0.4); background: rgba(52, 211, 153, 0.07); }
.inv-hero-amount { display: block; font-size: 1.7rem; font-weight: 700; line-height: 1.1; font-variant-numeric: tabular-nums; color: var(--ink); }
.inv-hero-label { font-size: 0.68rem; text-transform: uppercase; letter-spacing: 0.07em; color: var(--ink-3); }
/* paid: greyed rows + a green accent on the collected stat */
.cm-stat-paid > strong { color: var(--l1); }
.paid-table tbody tr.paid-row td { color: var(--ink-3); }
.paid-table tbody tr.paid-row .mono { color: var(--ink-2); }
.inv-hero-status { display: flex; flex-direction: column; align-items: flex-end; gap: 5px; text-align: right; }
.inv-hero-days { font-size: 0.82rem; color: var(--ink-2); }
.inv-company-line { color: var(--ink-2); font-size: 0.9rem; margin: 0 0 4px; }
.inv-facts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1px;
  margin: 0;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  overflow: hidden;
  background: var(--line);
}
.inv-facts > div { background: var(--panel); padding: 9px 12px; display: flex; flex-direction: column; gap: 3px; }
.inv-facts dt { font-size: 0.64rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-3); }
.inv-facts dd { margin: 0; font-size: 0.9rem; color: var(--ink); font-variant-numeric: tabular-nums; }

.mail-chip {
  font-size: 0.64rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border-radius: 999px;
  padding: 2px 9px;
}
.mail-chip.sent { color: var(--orange-2); background: var(--orange-soft); }
.mail-chip.auto { color: var(--cyan); background: var(--cyan-soft); }
.mail-chip.reply { color: var(--l1); background: rgba(52, 211, 153, 0.12); }
.mail-chip.digest { color: var(--l2); background: rgba(251, 191, 36, 0.12); }
.mail-avatar.ceo { color: var(--l2); border-color: rgba(251, 191, 36, 0.4); }
.mail-chip.new { color: #041012; background: var(--cyan); }

@media (max-width: 860px) {
  /* phone: single pane — list first, thread/compose slides in with a back button */
  .mail-client { grid-template-columns: 1fr; height: auto; min-height: 60vh; }
  .mail-list { border-right: none; max-height: none; }
  .mail-pane, .mail-compose { display: none; grid-column: 1; grid-row: auto; }
  .mail-client.thread-open .mail-list { display: none; }
  .mail-client.thread-open .mail-pane:not([hidden]) { display: flex; }
  .mail-client.thread-open .mail-compose:not([hidden]) { display: flex; }
  .mail-back { display: inline-block; }
  .mail-thread { max-height: none; }
  .mail-msg { max-width: 100%; }
}

/* ── flash / empty ─────────────────────────────────────────────────── */

.flash {
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--panel-2);
  padding: 11px 16px;
  font-size: 0.86rem;
  transition: opacity 0.6s;
}
.flash.success { border-color: rgba(52, 211, 153, 0.5); color: var(--l1); }
.flash.error { border-color: rgba(244, 63, 94, 0.5); color: var(--l4); }
.flash.info { color: var(--ink-2); }
.flash.hide { opacity: 0; }

.empty {
  color: var(--ink-3);
  text-align: center;
  padding: 26px 0;
  border: 1.5px dashed var(--line);
  border-radius: var(--radius-sm);
}

/* ── settings page ─────────────────────────────────────────────────── */

.settings-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 20px;
  align-items: start;
}

.rule-pills { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 4px; }
.rule-pills span {
  font-size: 0.72rem;
  color: var(--ink-2);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 11px;
}
.hold-list { display: flex; flex-direction: column; gap: 6px; margin-top: 14px; }
.hold-list span {
  font-size: 0.76rem;
  color: var(--ink-2);
  padding: 7px 11px;
  background: rgba(251, 191, 36, 0.06);
  border: 1px solid rgba(251, 191, 36, 0.18);
  border-radius: var(--radius-sm);
}

/* ── login ─────────────────────────────────────────────────────────── */

.login-wrap {
  position: relative;
  min-height: calc(100vh - 120px);
  display: grid;
  place-items: center;
  isolation: isolate;
}

.login-bg { position: fixed; inset: 0; z-index: -1; overflow: hidden; }
.login-bg .blob {
  position: absolute;
  width: 560px;
  height: 560px;
  border-radius: 50%;
  filter: blur(110px);
  opacity: 0.16;
}
.blob-a { background: var(--orange); top: -180px; left: -120px; animation: drift-a 26s ease-in-out infinite; }
.blob-b { background: var(--cyan); bottom: -220px; right: -140px; opacity: 0.11; animation: drift-b 32s ease-in-out infinite; }

.login-grid {
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(0deg, rgba(34, 217, 230, 0.05) 0 1px, transparent 1px 56px),
    repeating-linear-gradient(90deg, rgba(34, 217, 230, 0.05) 0 1px, transparent 1px 56px);
  mask-image: radial-gradient(620px 480px at 50% 42%, rgba(0, 0, 0, 0.9), transparent 75%);
}

.login-stage {
  width: min(420px, calc(100vw - 40px));
  display: flex;
  flex-direction: column;
  align-items: center;
  animation: rise 0.6s cubic-bezier(0.2, 0.7, 0.3, 1) both;
}

.login-logo-img {
  width: 420px;
  max-width: 94%;
  filter: drop-shadow(0 0 24px rgba(255, 122, 26, 0.35));
  margin-bottom: 10px;
}

.login-card {
  width: 100%;
  padding: 26px 28px 30px;
  background: rgba(13, 15, 21, 0.72);
  backdrop-filter: blur(16px);
  border-color: var(--line-strong);
  box-shadow: 0 30px 70px -30px rgba(0, 0, 0, 0.8), inset 0 1px 0 rgba(255, 255, 255, 0.05);
}

.login-tag {
  text-align: center;
  color: var(--ink-3);
  font-size: 0.76rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin-bottom: 20px;
}

.login-form { display: flex; flex-direction: column; gap: 14px; }

/* login topbar: hide chrome, keep it minimal */
body:has(.login-wrap) .topbar { background: transparent; border-bottom: none; backdrop-filter: none; }
body:has(.login-wrap) .topbar::after { display: none; }
body:has(.login-wrap) .brand { visibility: hidden; }

/* ── responsive ────────────────────────────────────────────────────── */

@media (max-width: 940px) {
  .metrics { grid-template-columns: 1fr 1fr; }
  .hero-metric { grid-column: 1 / -1; }
  .levels-strip { grid-template-columns: 1fr 1fr; }
  .grid-2, .two-fields { grid-template-columns: 1fr; }
  .page { padding: 18px 14px 60px; }
  .nav-logo { width: 148px; height: 42px; }

  /* topbar becomes two rows: brand + actions, then a full-width
     horizontally-scrollable tab strip */
  .topbar {
    flex-wrap: wrap;
    gap: 8px 12px;
    padding: 10px 14px;
    min-height: 0;
  }
  .top-actions { order: 2; margin-left: auto; }
  .top-nav {
    order: 3;
    flex-basis: 100%;
    display: flex;
    margin-right: 0;
    overflow-x: auto;
    scrollbar-width: none;
  }
  .top-nav::-webkit-scrollbar { display: none; }
  .top-nav a { padding: 7px 14px; flex: none; }
}

@media (max-width: 700px) {
  /* draft cards: let the summary row wrap instead of overflowing */
  .draft summary {
    flex-wrap: wrap;
    gap: 6px 10px;
    padding: 12px 34px 12px 14px;
    position: relative;
  }
  .draft summary .chev { position: absolute; right: 16px; top: 21px; }
  .draft-client { flex: 1 0 70%; }
  .draft-to { display: none; }
  .draft-days, .draft-amount { font-size: 0.78rem; }

  .draft-meta { flex-direction: column; align-items: flex-start; }
  .toggles { flex-wrap: wrap; }

  .settings-row { flex-wrap: wrap; }
  .settings-row .btn { width: 100%; }
  .tpl-actions { flex-wrap: wrap; gap: 10px; }
  .tpl-actions form { flex: 1; }
  .tpl-actions .btn { width: 100%; }
  .dropzones { grid-template-columns: 1fr; }
  .upload-form > .btn.primary { align-self: stretch; }
}

@media (max-width: 600px) {
  /* stacked full-width actions inside an open draft */
  .draft-actions .btn { width: 100%; }
  .reject-form { position: static; margin-top: 10px; }
  .reject-form .btn { width: 100%; }

  .metrics { gap: 8px; }
  .metric { padding: 12px 14px 11px; }
  .metric strong { font-size: 1.35rem; }
  .hero-metric strong { font-size: 1.9rem; }
  .levels-strip { gap: 8px; }
  .card { padding: 16px 14px; }
  .card-head { flex-wrap: wrap; }

  .modal-backdrop { padding: 10px; }
  .modal { max-height: 94vh; }
  .modal-head { padding: 14px 16px 10px; }
  .modal-body { padding: 12px 16px 18px; }
  .kv-grid { grid-template-columns: 1fr; }
  .balance-row { grid-template-columns: 72px 1fr 84px; gap: 8px; font-size: 0.74rem; }
  .balance-row > .dim { display: none; }
  .reminder-row { flex-wrap: wrap; }
}

/* ── reduced motion ────────────────────────────────────────────────── */

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
