/* ==========================================================================
   موقف الفواتير — لوحة تحكم مالية
   Design tokens, app shell, dashboard cards, tables and forms.
   ========================================================================== */

:root {
  color-scheme: light;
  --bg: #f2f6f5;
  --surface: #ffffff;
  --surface-2: #f6faf9;
  --surface-3: #edf4f2;
  --ink: #0f201d;
  --ink-2: #33463f;
  --muted: #647a74;
  --line: #e0e9e6;
  --line-strong: #cddad6;
  --primary: #0d7a68;
  --primary-strong: #0a6154;
  --primary-soft: #e4f5f1;
  --on-primary: #ffffff;
  --sidebar: #0a2c27;
  --sidebar-ink: #dcebe7;
  --sidebar-muted: #8fafa8;

  --ok: #15803d;
  --ok-bg: #e7f7ed;
  --ok-line: #bfe8cd;
  --warn: #b45309;
  --warn-bg: #fdf1df;
  --warn-line: #f1d6a6;
  --stop: #b91c1c;
  --stop-bg: #fdeaea;
  --stop-line: #f5c7c7;
  --paid: #52646e;
  --paid-bg: #edf1f4;
  --paid-line: #d9e1e6;

  --c-stop: #dc2626;
  --c-warn: #f59e0b;
  --c-ok: #10b981;
  --c-paid: #94a3b8;

  --shadow-sm: 0 1px 2px rgba(12, 40, 34, .05), 0 1px 3px rgba(12, 40, 34, .04);
  --shadow-md: 0 10px 28px -14px rgba(12, 40, 34, .28), 0 2px 6px rgba(12, 40, 34, .05);
  --shadow-lg: 0 28px 70px -28px rgba(5, 26, 21, .38);

  --radius: 16px;
  --radius-sm: 10px;
  --sidebar-w: 264px;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #091210;
    --surface: #111c19;
    --surface-2: #16231f;
    --surface-3: #1b2b26;
    --ink: #e8f1ee;
    --ink-2: #c3d3ce;
    --muted: #94a8a1;
    --line: #22332e;
    --line-strong: #2f443e;
    --primary: #2dd4bf;
    --primary-strong: #5eead4;
    --primary-soft: rgba(45, 212, 191, .13);
    --on-primary: #052420;
    --ok: #4ade80;
    --ok-bg: rgba(34, 197, 94, .13);
    --ok-line: rgba(34, 197, 94, .26);
    --warn: #fbbf24;
    --warn-bg: rgba(245, 158, 11, .13);
    --warn-line: rgba(245, 158, 11, .26);
    --stop: #f87171;
    --stop-bg: rgba(239, 68, 68, .13);
    --stop-line: rgba(239, 68, 68, .26);
    --paid: #a9bcc6;
    --paid-bg: rgba(148, 163, 184, .13);
    --paid-line: rgba(148, 163, 184, .24);
    --c-paid: #64748b;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
    --shadow-md: 0 12px 30px -16px rgba(0, 0, 0, .7);
    --shadow-lg: 0 30px 80px -30px rgba(0, 0, 0, .8);
  }
}

:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #091210;
  --surface: #111c19;
  --surface-2: #16231f;
  --surface-3: #1b2b26;
  --ink: #e8f1ee;
  --ink-2: #c3d3ce;
  --muted: #94a8a1;
  --line: #22332e;
  --line-strong: #2f443e;
  --primary: #2dd4bf;
  --primary-strong: #5eead4;
  --primary-soft: rgba(45, 212, 191, .13);
  --on-primary: #052420;
  --ok: #4ade80;
  --ok-bg: rgba(34, 197, 94, .13);
  --ok-line: rgba(34, 197, 94, .26);
  --warn: #fbbf24;
  --warn-bg: rgba(245, 158, 11, .13);
  --warn-line: rgba(245, 158, 11, .26);
  --stop: #f87171;
  --stop-bg: rgba(239, 68, 68, .13);
  --stop-line: rgba(239, 68, 68, .26);
  --paid: #a9bcc6;
  --paid-bg: rgba(148, 163, 184, .13);
  --paid-line: rgba(148, 163, 184, .24);
  --c-paid: #64748b;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .3);
  --shadow-md: 0 12px 30px -16px rgba(0, 0, 0, .7);
  --shadow-lg: 0 30px 80px -30px rgba(0, 0, 0, .8);
}

/* ---- base ---------------------------------------------------------------- */

*,
*::before,
*::after { box-sizing: border-box; }

html { scroll-behavior: smooth; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  background-image:
    radial-gradient(900px 420px at 100% -8%, var(--primary-soft), transparent 62%),
    radial-gradient(700px 380px at 0% 110%, var(--surface-3), transparent 60%);
  background-attachment: fixed;
  color: var(--ink);
  font: 14.5px/1.6 system-ui, "Segoe UI", "Noto Sans Arabic", Dubai, Tahoma, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4, p { margin: 0; }
a { color: inherit; text-decoration: none; }
[hidden] { display: none !important; }
::selection { background: var(--primary); color: var(--on-primary); }

.sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

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

.muted { color: var(--muted); font-size: 12.5px; }

/* ---- buttons ------------------------------------------------------------- */

button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 9px 16px;
  font: inherit;
  font-size: 13px;
  font-weight: 700;
  color: var(--on-primary);
  background: var(--primary);
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  cursor: pointer;
  white-space: nowrap;
  transition: background .15s ease, border-color .15s ease, color .15s ease,
              box-shadow .15s ease, transform .1s ease;
}

button:hover { background: var(--primary-strong); border-color: var(--primary-strong); }
button:active { transform: translateY(1px); }
button:disabled { opacity: .55; cursor: not-allowed; transform: none; }

button.ghost {
  color: var(--primary);
  background: var(--surface);
  border-color: var(--line-strong);
}
button.ghost:hover {
  background: var(--primary-soft);
  border-color: var(--primary);
  color: var(--primary);
}

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

.icon-btn {
  width: 38px;
  height: 38px;
  padding: 0;
  color: var(--muted);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.icon-btn:hover {
  color: var(--ink);
  background: var(--surface-2);
  border-color: var(--line-strong);
}
.icon-btn.on-dark {
  color: var(--sidebar-ink);
  background: rgba(255, 255, 255, .07);
  border-color: rgba(255, 255, 255, .1);
}
.icon-btn.on-dark:hover { background: rgba(255, 255, 255, .14); }

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible,
a:focus-visible,
tr:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  * { transition: none !important; animation: none !important; }
}

/* ---- app shell ----------------------------------------------------------- */

.app { display: flex; min-height: 100vh; }

.sidebar {
  position: sticky;
  top: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  flex: none;
  width: var(--sidebar-w);
  height: 100vh;
  padding: 20px 16px 16px;
  overflow-y: auto;
  color: var(--sidebar-ink);
  background:
    radial-gradient(520px 280px at 100% 0%, rgba(20, 184, 166, .22), transparent 65%),
    linear-gradient(180deg, #0b322b 0%, #09241f 55%, #071c18 100%);
  border-inline-start: 0;
  border-inline-end: 1px solid rgba(255, 255, 255, .06);
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 4px 8px 20px;
  color: #fff;
}

.brand-mark {
  display: grid;
  place-items: center;
  flex: none;
  width: 42px;
  height: 42px;
  color: #fff;
  background: linear-gradient(135deg, #14b8a6, #0f766e);
  border-radius: 13px;
  box-shadow: 0 10px 24px -8px rgba(20, 184, 166, .65);
}
.brand-mark .icon { width: 22px; height: 22px; stroke-width: 2.1; }
.brand-mark.large { width: 56px; height: 56px; border-radius: 18px; }
.brand-mark.large .icon { width: 28px; height: 28px; }

.brand-text strong { display: block; font-size: 16.5px; font-weight: 800; letter-spacing: .2px; }
.brand-text small { display: block; font-size: 11px; color: var(--sidebar-muted); }

.nav { display: flex; flex-direction: column; gap: 3px; flex: 1; }

.nav-label {
  padding: 16px 10px 6px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: .14em;
  color: rgba(220, 235, 231, .38);
}

.nav button {
  position: relative;
  justify-content: flex-start;
  width: 100%;
  padding: 10px 12px;
  font-size: 13.5px;
  font-weight: 600;
  color: rgba(226, 240, 236, .78);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 11px;
}
.nav button:hover {
  color: #fff;
  background: rgba(255, 255, 255, .07);
  border-color: transparent;
}
.nav button .icon { color: rgba(45, 212, 191, .7); }
.nav button[aria-current="page"] {
  color: #fff;
  background: rgba(45, 212, 191, .14);
  border-color: rgba(45, 212, 191, .22);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, .06);
}
.nav button[aria-current="page"]::before {
  content: "";
  position: absolute;
  inset-inline-start: -1px;
  top: 50%;
  width: 3px;
  height: 20px;
  background: #2dd4bf;
  border-radius: 2px;
  transform: translateY(-50%);
}
.nav button[aria-current="page"] .icon { color: #2dd4bf; }

.sidebar-foot {
  margin-top: auto;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, .08);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 13px;
}

.avatar {
  display: grid;
  place-items: center;
  flex: none;
  width: 36px;
  height: 36px;
  font-size: 15px;
  font-weight: 800;
  color: #04241f;
  background: linear-gradient(135deg, #5eead4, #14b8a6);
  border-radius: 50%;
}

.user-meta { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.user-meta small { font-size: 9.5px; letter-spacing: .04em; color: var(--sidebar-muted); }
.user-meta #whoami {
  overflow: hidden;
  font-size: 11.5px;
  color: #eaf5f2;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sidebar-note {
  padding: 12px 6px 0;
  font-size: 10.5px;
  line-height: 1.55;
  color: rgba(220, 235, 231, .4);
}

.install-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  margin-top: 10px;
  padding: 9px 12px;
  font-size: 12px;
  font-weight: 700;
  color: #d7f5ef;
  background: rgba(45, 212, 191, .12);
  border: 1px solid rgba(45, 212, 191, .3);
  border-radius: 12px;
}
.install-btn:hover {
  color: #ecfffb;
  background: rgba(45, 212, 191, .2);
  border-color: rgba(45, 212, 191, .5);
}
.install-btn[hidden] { display: none; }
.install-btn .icon { width: 16px; height: 16px; }

#installHelp { width: min(480px, calc(100vw - 32px)); }
#installHelp p { line-height: 1.8; }

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

/* ---- topbar -------------------------------------------------------------- */

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 14px;
  min-height: 68px;
  padding: 10px 26px;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
}

.page-heading { flex: 1; min-width: 0; }
.page-heading h1 {
  overflow: hidden;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -.2px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.page-heading p {
  overflow: hidden;
  margin-top: 1px;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

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

.stamp {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 360px;
  padding: 7px 12px;
  font-size: 11.5px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.stamp .icon { width: 14px; height: 14px; }
.stamp #stamp {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

@media (max-width: 1100px) {
  .stamp { display: none; }
}

.only-mobile { display: none; }

/* ---- banner & content ---------------------------------------------------- */

.banner {
  margin: 16px 26px 0;
  padding: 12px 16px;
  font-size: 12.5px;
  font-weight: 600;
  line-height: 1.65;
  color: var(--warn);
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: 12px;
}
.banner.error { color: var(--stop); background: var(--stop-bg); border-color: var(--stop-line); }

.content {
  width: 100%;
  margin: 0;
  padding: 22px 26px 56px;
}

/* The sidebar folds away on wide screens too, so tables use the whole width. */
@media (min-width: 901px) {
  .sidebar { transition: width .24s cubic-bezier(.2, .7, .3, 1), padding .24s cubic-bezier(.2, .7, .3, 1); }
  body.nav-collapsed .sidebar {
    width: 0;
    padding-inline: 0;
    border-inline-end: 0;
    overflow: hidden;
  }
  body.nav-collapsed .brand,
  body.nav-collapsed .nav,
  body.nav-collapsed .sidebar-foot { opacity: 0; pointer-events: none; }
}
@media (prefers-reduced-motion: reduce) {
  .sidebar { transition: none !important; }
}

#view-invoices > * + *,
#view-analytics > * + *,
#view-check > * + *,
#view-checks > * + *,
#view-users > * + *,
#view-settings > * + * { margin-top: 16px; }

#view-invoices,
#view-analytics,
#view-check,
#view-checks,
#view-customer,
#view-requests,
#view-users,
#view-settings { animation: rise .3s ease both; }

/* ---- KPI cards ----------------------------------------------------------- */

.kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.kpis-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

@media (min-width: 1650px) {
  .kpis { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .kpis.kpis-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
}

.kpi {
  position: relative;
  padding: 16px 18px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.kpi::before {
  content: "";
  position: absolute;
  inset-block-start: 0;
  inset-inline: 0;
  height: 3px;
  background: var(--tone);
}
.kpi:hover { box-shadow: var(--shadow-md); }

.kpi-top { display: flex; align-items: center; gap: 9px; margin-bottom: 12px; }

.kpi-icon {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  color: var(--tone);
  background: var(--tone-bg);
  border-radius: 10px;
}
.kpi-icon .icon { width: 17px; height: 17px; }

.kpi-label { font-size: 12px; font-weight: 700; color: var(--muted); }

.kpi-value {
  display: block;
  font-size: 25px;
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -.6px;
  font-variant-numeric: tabular-nums;
}

.kpi-sub { display: block; margin-top: 6px; font-size: 11px; color: var(--muted); }

.kpi-primary { --tone: var(--primary); --tone-bg: var(--primary-soft); }
.kpi-warn { --tone: var(--warn); --tone-bg: var(--warn-bg); }
.kpi-stop { --tone: var(--stop); --tone-bg: var(--stop-bg); }
.kpi-ok { --tone: var(--ok); --tone-bg: var(--ok-bg); }
.kpi-info { --tone: #2563eb; --tone-bg: rgba(37, 99, 235, .11); }
:root[data-theme="dark"] .kpi-info { --tone: #60a5fa; --tone-bg: rgba(96, 165, 250, .14); }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .kpi-info { --tone: #60a5fa; --tone-bg: rgba(96, 165, 250, .14); }
}

@keyframes rise {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}/* ---- cards & charts ------------------------------------------------------ */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.charts {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(0, 1fr);
  gap: 14px;
  margin-top: 16px;
}

.chart-card {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 18px 20px 16px;
}

.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
}
.card-head h2 { font-size: 14.5px; font-weight: 800; }
.card-head p { margin-top: 2px; font-size: 11.5px; }

/* aging bar chart */
.aging {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  flex: 1;
  min-height: 186px;
}

.aging .bar-col {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 6px;
  height: 100%;
  min-height: 178px;
  padding: 4px 2px;
  font-weight: 600;
  color: var(--muted);
  background: transparent;
  border: 0;
  border-radius: 10px;
}
.aging .bar-col:hover { background: var(--surface-2); color: var(--ink-2); }
.aging .bar-col[aria-pressed="true"] {
  background: var(--primary-soft);
  box-shadow: inset 0 0 0 1px var(--primary);
}

.bar-value {
  align-self: end;
  font-size: 10.5px;
  font-weight: 700;
  color: var(--ink-2);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.bar-track {
  display: flex;
  align-items: flex-end;
  justify-content: center;
  height: 112px;
  min-height: 112px;
}

.bar {
  display: block;
  width: min(100%, 44px);
  min-height: 5px;
  border-radius: 8px 8px 4px 4px;
  transition: height .55s cubic-bezier(.2, .7, .3, 1), filter .15s ease;
}
.bar-col:hover .bar { filter: brightness(1.08) saturate(1.05); }

.bar-label {
  font-size: 10px;
  line-height: 1.35;
  color: var(--muted);
  text-align: center;
}

.bar-0 { background: linear-gradient(180deg, #2dd4bf, #0d9488); }
.bar-1 { background: linear-gradient(180deg, #a3e635, #65a30d); }
.bar-2 { background: linear-gradient(180deg, #fcd34d, #f59e0b); }
.bar-3 { background: linear-gradient(180deg, #fb923c, #ea580c); }
.bar-4 { background: linear-gradient(180deg, #f87171, #dc2626); }
.bar-5 { background: linear-gradient(180deg, #ef4444, #991b1b); }

/* donut chart */
.status-chart {
  display: flex;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
}

.donut {
  position: relative;
  display: grid;
  place-items: center;
  flex: none;
  width: 142px;
  height: 142px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .04);
}

.donut-hole {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  width: 96px;
  height: 96px;
  text-align: center;
  background: var(--surface);
  border-radius: 50%;
}
.donut-hole span { font-size: 10.5px; color: var(--muted); }
.donut-hole strong {
  font-size: 17px;
  font-weight: 800;
  line-height: 1.2;
  font-variant-numeric: tabular-nums;
}
.donut-hole small { font-size: 9.5px; color: var(--muted); }

.legend {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px 14px;
  width: 100%;
  margin: 0;
  padding: 0;
  list-style: none;
  font-size: 11.5px;
}

.legend li { display: flex; align-items: center; gap: 7px; color: var(--muted); }
.legend .dot {
  flex: none;
  width: 8px;
  height: 8px;
  background: var(--dc);
  border-radius: 50%;
}
.legend b {
  margin-inline-start: auto;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--ink);
  font-variant-numeric: tabular-nums;
}

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

.table-card { padding: 0; overflow: hidden; }
.table-card > .card-head { padding: 18px 20px 12px; }
.table-card .filters { padding: 0 20px 14px; margin: 0; }
.table-card .table-wrap { max-height: 72vh; }

.table-wrap {
  overflow: auto;
  background: var(--surface);
  border-top: 1px solid var(--line);
}
.table-wrap:focus-within { scrollbar-color: var(--primary) transparent; }

table { width: 100%; border-collapse: collapse; min-width: 1080px; }
th, td {
  padding: 11px 14px;
  text-align: start;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}
th {
  position: sticky;
  top: 0;
  z-index: 2;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: .01em;
  color: var(--muted);
  white-space: nowrap;
  background: var(--surface-2);
}
tbody tr:last-child td { border-bottom: 0; }
td { font-size: 13px; }

/* A sortable header keeps the cell's padding on its button, so the whole header
   is the click target and the row height does not change. */
th.sortable { padding: 0; }
th.sortable .th-sort {
  display: inline-flex;
  align-items: center;
  justify-content: flex-start;
  gap: 5px;
  width: 100%;
  min-height: 40px;
  padding: 11px 14px;
  background: none;
  border: 0;
  font: inherit;
  color: inherit;
  cursor: pointer;
}
th.n.sortable .th-sort { justify-content: flex-end; }
th.sortable .th-sort::after {
  content: '⇅';
  font-size: 10px;
  opacity: .35;
}
th.sortable .th-sort:hover { color: var(--ink); }
th.sortable .th-sort:hover::after { opacity: .7; }
th[aria-sort="ascending"] .th-sort::after,
th[aria-sort="descending"] .th-sort::after {
  opacity: 1;
  color: var(--primary);
}
th[aria-sort="ascending"] .th-sort::after { content: '↑'; }
th[aria-sort="descending"] .th-sort::after { content: '↓'; }
th.sortable .th-sort:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

#rows tr { cursor: pointer; transition: background .12s ease; }
#rows tr:hover { background: var(--surface-2); }
#rows tr:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

#requestRows tr { cursor: pointer; transition: background .12s ease; }
#requestRows tr:hover { background: var(--surface-2); }
#requestRows tr:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }

td .sub { display: block; margin-top: 1px; font-size: 11px; color: var(--muted); }
td.date, .n { font-variant-numeric: tabular-nums; white-space: nowrap; }
.n { text-align: end; }
.start { text-align: start; }

.empty { padding: 34px; text-align: center; color: var(--muted); }
.more { display: flex; margin: 14px auto 18px; }

/* A customer name or invoice number that opens its file without changing the row action. */
.link-btn {
  padding: 0;
  font: inherit;
  font-weight: 700;
  color: var(--primary);
  text-align: start;
  background: none;
  border: 0;
  border-radius: 4px;
  cursor: pointer;
}
.link-btn:hover { text-decoration: underline; }
.link-btn:focus-visible { outline: 2px solid var(--primary); outline-offset: 2px; }

#view-checks table { min-width: 980px; }
#view-customer table { min-width: 860px; }
#view-customer .compact-table table { min-width: 0; }

.users-table table { min-width: 820px; }
#view-requests table { min-width: 940px; }
#view-audit table { min-width: 720px; }

/* ---- request selection & bulk actions ------------------------------------ */

.select-col { width: 40px; min-width: 40px; padding-inline: 8px; text-align: center; }
.select-col input {
  width: 16px;
  height: 16px;
  margin: 0 auto;
  padding: 0;
  accent-color: var(--primary);
  cursor: pointer;
}
.select-col input:disabled { cursor: not-allowed; opacity: .55; }
#requestRows tr.selected { background: var(--primary-soft); }
#requestRows tr.selected:hover { background: var(--primary-soft); }

.bulk-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 20px 12px;
  padding: 10px 14px;
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: var(--radius-sm);
}
.bulk-bar[hidden] { display: none; }
.bulk-bar .actions { gap: 8px; }

/* ---- bulk edit & import -------------------------------------------------- */

.bulk-edit-grid {
  display: grid;
  grid-template-columns: minmax(150px, auto) minmax(0, 1fr);
  gap: 10px 14px;
  align-items: center;
  margin-top: 14px;
}
.bulk-edit-grid .check { margin: 0; }
.bulk-edit-grid input, .bulk-edit-grid textarea { margin-top: 0; }
.bulk-edit-grid input:disabled, .bulk-edit-grid textarea:disabled {
  background: var(--surface-2);
  color: var(--muted);
  cursor: not-allowed;
  opacity: .75;
}

#importFile { margin-top: 8px; }
.paste-area {
  margin-top: 8px;
  min-height: 150px;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
  line-height: 1.7;
  white-space: pre;
  overflow: auto;
  tab-size: 12;
}
.inline-file { color: var(--primary); cursor: pointer; text-decoration: underline; }
.inline-file input { display: none; }
.import-preview { margin-top: 14px; }
.import-preview:empty { display: none; }
.import-preview .compact-table {
  max-height: 46vh;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.import-preview table { min-width: 640px; }
#importSummary { margin-top: 10px; }
#importSummary .chip { margin-inline-end: 6px; }
#requestImport { width: min(900px, calc(100vw - 32px)); }
#bulkEditDialog, #bulkDecision { width: min(620px, calc(100vw - 32px)); }
#bulkEditDialog .actions, #bulkDecision .actions { margin-top: 16px; justify-content: flex-end; }
#bulkEditDialog .form-error, #bulkDecision .form-error { margin-top: 10px; }

@media (max-width: 620px) {
  .bulk-edit-grid { grid-template-columns: 1fr; }
  .bulk-bar { margin-inline: 12px; }
}

/* ---- tags & notes -------------------------------------------------------- */

.tag {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  font-size: 11px;
  font-weight: 700;
  white-space: nowrap;
  border: 1px solid transparent;
  border-radius: 999px;
}
.tag::before {
  content: "";
  width: 6px;
  height: 6px;
  background: currentColor;
  border-radius: 50%;
}
.tag.ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-line); }
.tag.warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.tag.stop { color: var(--stop); background: var(--stop-bg); border-color: var(--stop-line); }
.tag.paid { color: var(--paid); background: var(--paid-bg); border-color: var(--paid-line); }

.note {
  display: inline-flex;
  flex-direction: column;
  font-size: 12px;
  font-weight: 600;
  line-height: 1.4;
}
.note small {
  margin-top: 1px;
  font-size: 10.5px;
  font-weight: 500;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
.note.ok { color: var(--ok); }
.note.warn { color: var(--warn); }
.note.stop { color: var(--stop); }
.note.none { font-weight: 500; color: var(--muted); }

/* ---- stat chips ---------------------------------------------------------- */

#requestsCount { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 3px; }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.chip.warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }

/* ---- filters & fields ---------------------------------------------------- */

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 12px;
  margin: 14px 0 6px;
}

.field { display: flex; flex-direction: column; flex: 0 1 190px; min-width: 150px; }
.field.grow { flex: 1 1 260px; }
.field.compact { min-width: 176px; max-width: 220px; }

label {
  display: block;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

input, select, textarea {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 10px 12px;
  font: inherit;
  font-size: 13px;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  transition: border-color .15s ease, box-shadow .15s ease, background .15s ease;
}
input:hover, select:hover, textarea:hover { border-color: var(--muted); }
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
textarea { resize: vertical; min-height: 72px; }
select {
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%),
                    linear-gradient(135deg, var(--muted) 50%, transparent 50%);
  background-position: 14px calc(50% + 1px), 19px calc(50% + 1px);
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  padding-inline-end: 34px;
}

.input-wrap { position: relative; display: block; }
.input-wrap .icon {
  position: absolute;
  inset-inline-start: 12px;
  top: calc(50% + 3px);
  width: 16px;
  height: 16px;
  color: var(--muted);
  pointer-events: none;
  transform: translateY(-50%);
}
.input-wrap input { padding-inline-start: 38px; }

.check {
  display: flex;
  align-items: center;
  gap: 9px;
  font-size: 13px;
  font-weight: 600;
  color: var(--ink);
}
.check input {
  width: 17px;
  height: 17px;
  margin: 0;
  padding: 0;
  accent-color: var(--primary);
}

/* A user can hold more than one permission, so the form shows checkboxes. */
.perm-field { display: grid; gap: 7px; }
.perm-title { font-size: 12px; font-weight: 700; color: var(--muted); }
.perm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 14px; }
.perm-grid .check { margin: 0; }
.perm-grid .check input:disabled { cursor: not-allowed; opacity: .6; }
.perm-hint { margin: 0; font-size: 11.5px; line-height: 1.6; }
.perm-list { display: flex; flex-wrap: wrap; gap: 4px; }

.actions { display: flex; flex-wrap: wrap; align-items: center; gap: 9px; }
.card-head .actions { align-items: flex-end; }

.head-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.head-actions .btn { padding-block: 8px; font-size: 12px; }
.btn.is-done { color: var(--ok, #0f766e); border-color: currentColor; }

/* ---- forms & panels ------------------------------------------------------ */

.panel {
  padding: 20px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.form { display: grid; gap: 14px; max-width: 560px; margin: 0 auto; }
.form h2 { font-size: 16px; font-weight: 800; }

.grid-2 {
  display: grid;
  grid-template-columns: minmax(0, 430px) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.grid-2 .form { max-width: none; margin: 0; }

/* ---- customer profile ---------------------------------------------------- */

.customer-view { display: grid; gap: 16px; }

.profile-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 16px;
  padding: 18px 20px;
}
.profile-head .avatar.lg {
  width: 54px;
  height: 54px;
  font-size: 21px;
  box-shadow: 0 0 0 4px var(--primary-soft);
}
.profile-id { flex: 1 1 260px; min-width: 0; }
.profile-id h2 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 19px;
  font-weight: 800;
  line-height: 1.4;
}
.profile-id p { margin-top: 3px; }
.profile-head .actions { margin-inline-start: auto; }

.profile-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 16px;
  align-items: start;
}
.profile-grid .panel > h3 { margin-bottom: 12px; font-size: 14px; font-weight: 800; }
.profile-grid .sub-head { margin: 18px 0 8px; font-size: 12.5px; font-weight: 800; color: var(--muted); }
.profile-grid .compact-table { max-height: 310px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.profile-note { padding: 10px 18px 14px; }
.customer-requests > h3 { margin-bottom: 12px; font-size: 14px; font-weight: 800; }
.customer-requests .table-wrap { margin-top: 10px; border: 1px solid var(--line); border-radius: var(--radius-sm); }
.customer-requests .profile-note { padding: 8px 0 0; }

.form-error {
  padding: 9px 12px;
  font-size: 12.5px;
  font-weight: 700;
  color: var(--stop);
  background: var(--stop-bg);
  border: 1px solid var(--stop-line);
  border-radius: var(--radius-sm);
}
.ok-msg {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--ok);
}

.note-box {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin: 12px 0;
  padding: 13px 14px;
  font-size: 12.5px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.note-box .tag { margin-inline-start: 2px; }
.note-box .sub { flex-basis: 100%; font-size: 11.5px; color: var(--muted); line-height: 1.6; }

.busy {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 4px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}
.spinner {
  flex: none;
  width: 14px;
  height: 14px;
  border: 2px solid var(--line-strong);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.request-form { display: grid; gap: 12px; }

/* ---- check view ---------------------------------------------------------- */

.check-layout { display: grid; gap: 18px; }
.check-layout > .form { width: 100%; max-width: 660px; }
.check-layout .form > button { justify-self: start; }

.result { display: grid; gap: 14px; max-width: 100%; margin: 0; }

.decision {
  padding: 18px 22px;
  font-size: 18px;
  font-weight: 800;
  line-height: 1.45;
  border: 1px solid transparent;
  border-radius: var(--radius);
}
.decision small {
  display: block;
  margin-top: 5px;
  font-size: 12.5px;
  font-weight: 500;
  line-height: 1.6;
  opacity: .92;
}
.decision.ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-line); }
.decision.warn { color: var(--warn); background: var(--warn-bg); border-color: var(--warn-line); }
.decision.stop { color: var(--stop); background: var(--stop-bg); border-color: var(--stop-line); }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 12px;
}
.cards .panel h3 { margin-bottom: 8px; font-size: 13.5px; font-weight: 800; }
.cards .why { margin-top: 8px; font-size: 12px; line-height: 1.65; color: var(--muted); }

dl { display: grid; grid-template-columns: auto 1fr; gap: 6px 18px; margin: 0; font-size: 13px; }
dt { color: var(--muted); }
dd { margin: 0; font-weight: 600; text-align: end; font-variant-numeric: tabular-nums; }

/* ---- login --------------------------------------------------------------- */

body[data-view="login"] .sidebar,
body[data-view="login"] .topbar { display: none; }
body[data-view="login"] .content { max-width: none; padding: 0; }
body[data-view="login"] #banner { display: none !important; }

.login-view {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 32px 20px;
}

.login-card {
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  width: 100%;
  max-width: 940px;
  overflow: hidden;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 24px;
  box-shadow: var(--shadow-lg);
}

.login-intro {
  position: relative;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 14px;
  padding: 44px 38px;
  overflow: hidden;
  color: #eaf5f2;
  background:
    radial-gradient(420px 300px at 85% 0%, rgba(45, 212, 191, .28), transparent 65%),
    linear-gradient(155deg, #0e3f36 0%, #08231e 70%, #061a16 100%);
}
.login-intro::after {
  content: "";
  position: absolute;
  inset-block-start: -140px;
  inset-inline-end: -90px;
  width: 340px;
  height: 340px;
  border: 1px solid rgba(94, 234, 212, .18);
  border-radius: 50%;
  box-shadow: 0 0 0 40px rgba(94, 234, 212, .04), 0 0 0 90px rgba(94, 234, 212, .03);
  pointer-events: none;
}
.login-intro > * { position: relative; z-index: 1; }
.login-intro h2 { font-size: 24px; font-weight: 800; letter-spacing: -.3px; }
.login-intro p { max-width: 340px; font-size: 13px; line-height: 1.75; color: rgba(226, 240, 236, .78); }

.feature-list {
  display: grid;
  gap: 10px;
  margin: 4px 0 0;
  padding: 0;
  font-size: 12.5px;
  color: rgba(226, 240, 236, .9);
  list-style: none;
}
.feature-list li { display: flex; align-items: flex-start; gap: 9px; }
.feature-list .icon { width: 17px; height: 17px; margin-top: 1px; color: #2dd4bf; }

.login-foot {
  margin-top: 10px;
  font-size: 10.5px !important;
  letter-spacing: .1em;
  color: rgba(226, 240, 236, .45) !important;
}

.login-form {
  align-content: center;
  gap: 13px;
  max-width: none;
  margin: 0;
  padding: 40px;
  background: var(--surface);
  border: 0;
  border-radius: 0;
  box-shadow: none;
}
.login-form h2 { font-size: 21px; }
.login-form .actions { margin-top: 4px; }
.login-form .actions .ghost { flex: 1; }

/* ---- dialogs ------------------------------------------------------------- */

dialog {
  width: min(780px, calc(100vw - 32px));
  max-height: calc(100vh - 48px);
  padding: 24px;
  overflow: auto;
  color: var(--ink);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: var(--shadow-lg);
}
dialog::backdrop {
  background: rgba(3, 15, 12, .55);
  backdrop-filter: blur(3px);
}
dialog h2 {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 800;
}
dialog h3 {
  margin: 18px 0 8px;
  font-size: 12.5px;
  font-weight: 800;
  letter-spacing: .01em;
  color: var(--muted);
}
dialog form[method="dialog"] { margin-top: 18px; text-align: end; }
dialog .panel { background: var(--surface-2); box-shadow: none; }
dialog .inner-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
}
dialog table { min-width: 520px; }
dialog th { position: static; }
dialog label { display: block; }
dialog .cards { margin-top: 4px; }

#decision { width: min(820px, calc(100vw - 32px)); }
#decision .actions { margin-top: 16px; justify-content: flex-end; }
#decision .form-error { margin-top: 12px; }

/* A single review dialog: request facts, the registered check and the decision.
   The live check and the decision controls only appear when the request can act. */
.review-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 12.5px;
  color: var(--muted);
}

.review-details {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  margin-top: 14px;
}

.review-block {
  padding: 13px 15px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.review-block.full { grid-column: 1 / -1; }
.review-block > h3 {
  margin: 0 0 9px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}
.review-block dl { gap: 5px 16px; font-size: 12.5px; }
.review-block dd .sub { display: block; margin-top: 2px; }

.review-note {
  margin-top: 9px;
  padding: 8px 10px;
  font-size: 12.5px;
  line-height: 1.65;
  color: var(--ink);
  background: var(--surface);
  border: 1px dashed var(--line-strong);
  border-radius: 8px;
}
.review-note strong {
  display: block;
  margin-bottom: 2px;
  font-size: 11px;
  color: var(--muted);
}
.review-note .tag { margin-top: 1px; }

.review-notice {
  grid-column: 1 / -1;
  padding: 10px 12px;
  font-size: 12.5px;
  font-weight: 700;
  line-height: 1.6;
  color: var(--warn);
  background: var(--warn-bg);
  border: 1px solid var(--warn-line);
  border-radius: var(--radius-sm);
}

/* The delivery clerk's small form inside the review dialog. */
.delivery-editor {
  margin-top: 14px;
  padding: 13px 15px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.delivery-editor > h3 {
  margin: 0 0 10px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}
.delivery-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
}
.delivery-editor .field { max-width: none; }
.delivery-editor .actions { margin-top: 10px; justify-content: flex-start; }
.delivery-editor .form-error { margin-top: 8px; }

.late { color: var(--stop); font-weight: 700; }
.chip.stop { color: var(--stop); background: var(--stop-bg); border-color: var(--stop-line); }
.chip.ok { color: var(--ok); background: var(--ok-bg); border-color: var(--ok-line); }

/* The agreed value stays, and the invoice value sits under it with the gap. */
.actual { display: block; font-weight: 700; color: var(--ink); }
.actual-line { display: block; margin-top: 2px; }
.diff-up { color: var(--stop); font-weight: 700; }
.diff-down { color: var(--ok); font-weight: 700; }

.delivery-actual {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px dashed var(--line);
}
.delivery-actual > h4 {
  margin: 0 0 9px;
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
}
.delivery-actual .delivery-grid { margin-bottom: 6px; }
.delivery-actual .sub { margin: 0; }

/* Payment plan fields: method, advance and weekly amount. */
.pay-grid, .edit-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px 12px;
}
.edit-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.request-form .field, #requestEdit .field { max-width: none; }
#requestEdit { width: min(560px, calc(100vw - 32px)); }
.row-actions { white-space: nowrap; }
.row-actions .ghost { margin-inline-start: 4px; }

/* ---- scrollbars ---------------------------------------------------------- */

@media (pointer: fine) {
  * { scrollbar-width: thin; scrollbar-color: var(--line-strong) transparent; }
  ::-webkit-scrollbar { width: 10px; height: 10px; }
  ::-webkit-scrollbar-thumb {
    background: var(--line-strong);
    background-clip: padding-box;
    border: 3px solid transparent;
    border-radius: 10px;
  }
  ::-webkit-scrollbar-track { background: transparent; }
}

/* ---- responsive ---------------------------------------------------------- */

@media (max-width: 1180px) {
  .charts { grid-template-columns: 1fr; }
  .status-chart { flex-direction: row; flex-wrap: wrap; justify-content: center; gap: 22px; }
  .legend { width: auto; min-width: 230px; }
  .grid-2 { grid-template-columns: 1fr; }
  .profile-grid { grid-template-columns: 1fr; }
  .profile-grid .compact-table { max-height: none; }
}

@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    inset-block: 0;
    inset-inline-start: 0;
    z-index: 50;
    width: 284px;
    transform: translateX(100%);
    transition: transform .28s cubic-bezier(.2, .7, .3, 1);
    box-shadow: -24px 0 60px rgba(0, 0, 0, .4);
  }
  body.nav-open .sidebar { transform: none; }
  body.nav-open { overflow: hidden; }
  body.nav-open::after {
    content: "";
    position: fixed;
    inset: 0;
    z-index: 45;
    background: rgba(3, 15, 12, .52);
    backdrop-filter: blur(2px);
  }

  .only-mobile { display: inline-flex; }
  .topbar { gap: 10px; padding: 10px 16px; }
  .content { padding: 18px 16px 48px; }
  .banner { margin: 14px 16px 0; }
  .stamp { display: none; }
  .login-card { max-width: 620px; }
  .kpis-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .profile-head .actions { margin-inline-start: 0; width: 100%; }
}

@media (max-width: 640px) {
  body { font-size: 14px; }
  .page-heading h1 { font-size: 16px; }
  .page-heading p { display: none; }
  #reload { width: 38px; padding: 0; }
  #reload span { display: none; }

  .kpis { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
  .kpi { padding: 13px 14px; }
  .kpi-top { gap: 7px; margin-bottom: 9px; }
  .kpi-icon { width: 28px; height: 28px; border-radius: 9px; }
  .kpi-icon .icon { width: 15px; height: 15px; }
  .kpi-label { font-size: 10.5px; }
  .kpi-value { font-size: 19px; letter-spacing: -.3px; }
  .kpi-sub { font-size: 10px; }

  .aging { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; min-height: auto; }
  .aging .bar-col { min-height: 148px; }
  .bar-track { height: 92px; min-height: 92px; }

  .chart-card, .panel { padding: 16px; }
  .card-head { padding: 16px 16px 10px; }
  .chart-card .card-head { padding: 0; }
  .table-card .filters { padding: 0 16px 12px; }
  .table-card .table-wrap { max-height: none; }
  .table-card th { position: static; }
  th, td { padding: 9px 11px; }
  .field { flex: 1 1 100%; }
  .pay-grid, .edit-grid { grid-template-columns: 1fr; }

  .login-view { padding: 18px 14px; }
  .login-card { grid-template-columns: 1fr; border-radius: 18px; }
  .login-intro { gap: 9px; padding: 26px 22px 22px; }
  .login-intro h2 { font-size: 20px; }
  .login-intro p { font-size: 12px; }
  .feature-list, .login-foot { display: none; }
  .login-form { padding: 24px 22px 26px; }
  .login-form h2 { font-size: 18px; }

  .decision { padding: 15px 16px; font-size: 16px; }
  #decision { width: calc(100vw - 16px); max-height: calc(100vh - 16px); padding: 18px; }
  .review-details { grid-template-columns: 1fr; }
  .delivery-grid { grid-template-columns: 1fr; }
  .legend { grid-template-columns: 1fr 1fr; min-width: 0; width: 100%; }
  .status-chart { gap: 16px; }
}

@media (max-width: 380px) {
  .kpis { grid-template-columns: 1fr; }
  .aging { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

/* ---- command dashboard --------------------------------------------------- */

#view-dashboard { animation: rise .3s ease both; }

.dash-hero {
  position: relative;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(330px, .74fr);
  gap: 24px;
  padding: 24px 26px;
  overflow: hidden;
  color: #eaf7f4;
  background:
    radial-gradient(520px 300px at 92% -10%, rgba(45, 212, 191, .3), transparent 65%),
    radial-gradient(420px 280px at 0% 120%, rgba(20, 184, 166, .14), transparent 70%),
    linear-gradient(135deg, #0d3b32 0%, #082820 55%, #061d18 100%);
  border: 1px solid rgba(94, 234, 212, .14);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.dash-hero::after {
  content: "";
  position: absolute;
  inset-block-start: -170px;
  inset-inline-end: -110px;
  width: 390px;
  height: 390px;
  border: 1px solid rgba(94, 234, 212, .16);
  border-radius: 50%;
  box-shadow: 0 0 0 46px rgba(94, 234, 212, .035), 0 0 0 100px rgba(94, 234, 212, .025);
  pointer-events: none;
}
.dash-hero > * { position: relative; z-index: 1; }

.dash-eyebrow {
  display: flex;
  align-items: center;
  gap: 7px;
  margin-bottom: 8px;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: .12em;
  color: #5eead4;
}
.dash-eyebrow .icon { width: 15px; height: 15px; }

.dash-hero h2 {
  font-size: clamp(21px, 2vw, 27px);
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: -.4px;
}
.dash-hero-copy > p {
  max-width: 720px;
  margin-top: 6px;
  font-size: 12.5px;
  line-height: 1.7;
  color: rgba(226, 240, 236, .72);
}

.dash-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 18px; }
.dash-hero .dash-actions button { padding: 9px 13px; font-size: 12.5px; border-radius: 10px; }
.dash-hero .dash-actions .ghost {
  color: #dcebe7;
  background: rgba(255, 255, 255, .06);
  border-color: rgba(255, 255, 255, .14);
}
.dash-hero .dash-actions .ghost:hover {
  color: #fff;
  background: rgba(255, 255, 255, .12);
  border-color: rgba(94, 234, 212, .4);
}

.dash-hero-stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  align-self: stretch;
}
.dash-hero-stat {
  display: flex;
  flex-direction: column;
  justify-content: center;
  min-width: 0;
  padding: 12px 13px;
  background: rgba(255, 255, 255, .055);
  border: 1px solid rgba(255, 255, 255, .1);
  border-radius: 12px;
}
.dash-hero-stat span { font-size: 10px; line-height: 1.3; color: rgba(220, 235, 231, .62); }
.dash-hero-stat strong {
  margin: 3px 0 1px;
  overflow: hidden;
  font-size: 23px;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
  letter-spacing: -.5px;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dash-hero-stat small {
  overflow: hidden;
  font-size: 9.5px;
  color: rgba(220, 235, 231, .5);
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dash-hero-stat.warn { border-color: rgba(251, 191, 36, .3); }
.dash-hero-stat.warn strong { color: #fcd34d; }
.dash-hero-stat.stop { border-color: rgba(248, 113, 113, .3); }
.dash-hero-stat.stop strong { color: #fca5a5; }

#view-dashboard .kpis { margin-top: 16px; }

.dash-grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
  margin-top: 16px;
}
.dash-span-7 { grid-column: span 7; }
.dash-span-5 { grid-column: span 5; }
.dash-span-12 { grid-column: 1 / -1; }

.dash-card {
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  padding: 18px 20px;
}
.dash-card .card-head { align-items: flex-start; }
.dash-card .card-head h2 { font-size: 14px; }
.dash-card .card-head p { font-size: 11px; }

.dash-list { display: flex; flex-direction: column; margin: 0; padding: 0; list-style: none; }
.dash-item {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
  padding: 9px 0;
  border-bottom: 1px solid var(--line);
}
.dash-item:last-child { padding-bottom: 0; border-bottom: 0; }
.dash-item-main {
  display: block;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-align: start;
}
.dash-item-title {
  display: block;
  overflow: hidden;
  font-size: 12.5px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dash-item-title small { margin-inline-start: 4px; font-size: 10px; font-weight: 600; color: var(--muted); }
.dash-item-sub {
  display: block;
  overflow: hidden;
  margin-top: 1px;
  font-size: 10.5px;
  color: var(--muted);
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dash-empty {
  padding: 15px 14px;
  font-size: 11.5px;
  line-height: 1.65;
  color: var(--muted);
  text-align: center;
  background: var(--surface-2);
  border: 1px dashed var(--line-strong);
  border-radius: 10px;
}

.dash-pipeline { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.dash-stage {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 9px 11px;
  font-size: 10.5px;
  color: var(--muted);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 10px;
}
.dash-stage strong { font-size: 17px; color: var(--ink); font-variant-numeric: tabular-nums; }
.dash-stage.ok strong { color: var(--ok); }
.dash-stage.stop strong { color: var(--stop); }

.dash-table { max-height: 340px; margin-top: 2px; border: 1px solid var(--line); border-radius: 10px; }
.dash-table table { min-width: 620px; }
.dash-table th { position: sticky; top: 0; z-index: 2; }
.dash-table td { font-size: 12.5px; }
.dash-table tr[data-review],
.dash-table tr[data-promise-edit] { cursor: pointer; }
.dash-table tr[data-review]:hover,
.dash-table tr[data-promise-edit]:hover { background: var(--surface-2); }
.dash-table tr[data-review]:focus-visible,
.dash-table tr[data-promise-edit]:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.dash-span-12 .dash-table table { min-width: 720px; }

@media (max-width: 1180px) {
  .dash-hero { grid-template-columns: 1fr; }
  .dash-grid { grid-template-columns: 1fr; }
  .dash-span-7, .dash-span-5, .dash-span-12 { grid-column: 1 / -1; }
}

@media (max-width: 640px) {
  .dash-hero { gap: 18px; padding: 18px; }
  .dash-hero h2 { font-size: 20px; }
  .dash-hero-stats { grid-template-columns: 1fr; }
  .dash-actions button { flex: 1 1 auto; }
  .dash-card { padding: 16px; }
  .dash-table { max-height: none; }
}

/* ---- payment promises ---------------------------------------------------- */

#view-promises { animation: rise .3s ease both; }
#view-promises > * + * { margin-top: 16px; }
#view-promises table { min-width: 1060px; }
#view-promises tr[data-promise-edit] { cursor: pointer; }
#view-promises tr[data-promise-edit]:hover { background: var(--surface-2); }
#view-promises tr[data-promise-edit]:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
#promisesCount { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 3px; }
#promisesCount .chip.stop { color: var(--stop); border-color: var(--stop); }

.promise-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px 12px;
}
#promiseDialog { width: min(680px, calc(100vw - 32px)); }
#promiseDialog .field { max-width: none; }
#promiseDialog .actions { margin-top: 14px; }

/* The movement-based analysis shown inside the promise dialog, beside the
   manual status fields. */
.promise-analysis { margin-top: 12px; }
.promise-analysis:empty { display: none; }
.promise-analysis .review-block { padding: 12px 14px; }
.promise-analysis .compact-table { max-height: 220px; margin-top: 8px; }

.customer-promises .card-head {
  align-items: center;
  padding: 0;
}
.customer-promises > .card-head h3 { font-size: 14px; font-weight: 800; }
.customer-promises .compact-table {
  max-height: 300px;
  margin-top: 8px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}
.customer-promises .empty { padding: 16px; }

@media (max-width: 640px) {
  .promise-grid { grid-template-columns: 1fr; }
}

/* ---- global filters and analytics ---- */
.global-filters {
  margin: 0 var(--gutter, 24px) 12px; padding: 10px 14px; border: 1px solid var(--line);
  border-radius: 12px; background: var(--surface);
}
.gf-fields { display: flex; flex-wrap: wrap; gap: 8px 12px; }
.gf-fields .field { flex: 1 1 150px; min-width: 130px; max-width: 220px; font-size: 12px; }
.gf-foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-top: 6px; min-height: 28px; }
.global-filters.active { border-color: var(--primary); box-shadow: inset 0 0 0 1px var(--primary); }
.dim-tabs { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.dim-tabs button {
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
  border-radius: 999px; padding: 6px 14px; font-weight: 700; cursor: pointer;
}
.dim-tabs button[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--primary-ink, #fff); }
#analyticsRows tr { cursor: pointer; }
#analyticsFoot td { font-weight: 800; border-top: 2px solid var(--line); }
.analytics-note { margin-top: 8px; }
@media (max-width: 640px) {
  .global-filters { margin: 0 16px 12px; }
  .gf-fields .field { max-width: none; }
}

/* ---- analytics charts ---- */
.metric-pick {
  display: flex;
  flex: none;
  align-items: center;
  gap: 6px;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted);
  white-space: nowrap;
}
.metric-pick select { width: auto; min-width: 128px; margin-top: 0; padding: 6px 10px; padding-inline-end: 28px; font-size: 12px; }

.analytics-bars { grid-template-columns: repeat(auto-fit, minmax(84px, 1fr)); min-height: 0; }
.analytics-bars .bar-col { min-height: 172px; cursor: pointer; }
.analytics-bars .bar-col.rest { cursor: default; opacity: .7; }

#view-analytics .legend li[data-key] { cursor: pointer; border-radius: 6px; padding: 2px 4px; }
#view-analytics .legend li[data-key]:hover { color: var(--ink-2); background: var(--surface-2); }

.stack-legend { display: flex; flex-wrap: wrap; gap: 4px 12px; font-size: 10.5px; color: var(--muted); }
.stack-legend span { display: inline-flex; align-items: center; gap: 5px; }
.stack-legend i { display: block; width: 8px; height: 8px; border-radius: 2px; }
.stack-legend i.s1, .stack-seg.s1 { background: #fbbf24; }
.stack-legend i.s2, .stack-seg.s2 { background: #fb923c; }
.stack-legend i.s3, .stack-seg.s3 { background: #f87171; }
.stack-legend i.s4, .stack-seg.s4 { background: #dc2626; }
.stack-legend i.sales { background: #0d9488; }
.stack-legend i.coll { background: #65a30d; }

.stack-list { display: flex; flex-direction: column; gap: 6px; }
.stack-row {
  display: grid;
  grid-template-columns: minmax(88px, 150px) minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  padding: 4px 6px;
  font: inherit;
  color: var(--ink);
  text-align: start;
  background: transparent;
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}
.stack-row:hover { background: var(--surface-2); }
.stack-name { overflow: hidden; font-size: 12px; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.stack-track { display: flex; height: 16px; overflow: hidden; background: var(--surface-2); border-radius: 6px; }
.stack-seg { height: 100%; min-width: 2px; }
.stack-total { font-size: 11.5px; font-weight: 700; font-variant-numeric: tabular-nums; white-space: nowrap; }

.trend { display: grid; grid-template-columns: repeat(12, minmax(0, 1fr)); gap: 4px; align-items: end; }
.trend-col { display: flex; flex-direction: column; align-items: center; gap: 6px; }
.trend-pair { display: flex; align-items: flex-end; justify-content: center; gap: 3px; width: 100%; height: 116px; }
.trend-bar { display: block; width: min(46%, 18px); border-radius: 4px 4px 2px 2px; transition: height .5s ease; }
.trend-bar.sales { background: linear-gradient(180deg, #2dd4bf, #0d9488); }
.trend-bar.coll { background: linear-gradient(180deg, #a3e635, #65a30d); }
.trend-month { font-size: 9.5px; line-height: 1.3; color: var(--muted); text-align: center; }
.trend-year { display: block; font-size: 8.5px; opacity: .8; }

@media (max-width: 640px) {
  .metric-pick { flex-direction: column; align-items: stretch; gap: 2px; }
  .trend-pair { height: 88px; }
  .stack-row { grid-template-columns: minmax(66px, 104px) minmax(0, 1fr) auto; gap: 6px; }
}
