:root {
  --bg: #0f172a;
  --panel: #ffffff;
  --panel-alt: #f8fafc;
  --border: #e2e8f0;
  --text: #1e293b;
  --muted: #64748b;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --violet: #7c3aed;
  --sidebar-w: 220px;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: "Segoe UI", Tahoma, Arial, sans-serif;
  background: var(--panel-alt);
  color: var(--text);
  font-size: 14px;
}
#app { display: flex; height: 100vh; overflow: hidden; }

/* Sidebar */
#sidebar {
  width: var(--sidebar-w);
  background: #0f172a;
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}
#sidebar .brand {
  padding: 18px 16px;
  font-weight: 700;
  font-size: 16px;
  color: #fff;
  border-bottom: 1px solid #1e293b;
}
#sidebar nav { flex: 1; overflow-y: auto; padding: 8px; }
.nav-section-label {
  font-size: 10.5px; font-weight: 700; letter-spacing: .03em; color: #475569; text-transform: uppercase;
  padding: 14px 12px 6px; margin: 0;
}
.nav-section-label:first-child { padding-top: 4px; }
#sidebar .nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 8px;
  cursor: pointer;
  margin-bottom: 2px;
  color: #cbd5e1;
  font-size: 13.5px;
}
#sidebar .nav-item:hover { background: #1e293b; color: #fff; }
#sidebar .nav-item.active { background: var(--accent); color: #fff; }
#sidebar .nav-item .icon { font-size: 16px; width: 20px; text-align: center; }
#sidebar .footer { padding: 10px 16px; font-size: 11px; color: #64748b; border-top: 1px solid #1e293b; }

/* mainWrap holds a slim persistent topbar (the "back" button, which survives every route change
   since #main's whole innerHTML is replaced on navigation) above #main itself. */
#mainWrap { flex: 1; display: flex; flex-direction: column; min-height: 0; overflow: hidden; }
#topbar { flex: none; padding: 14px 26px 0; }
.topbar-back {
  display: inline-flex; align-items: center; gap: 6px; background: none; border: 1px solid transparent;
  color: var(--muted); font-size: 12.5px; font-weight: 600; padding: 5px 10px; border-radius: 7px; cursor: pointer;
}
.topbar-back:hover { background: var(--panel-alt); color: var(--text); border-color: var(--border); }
html[dir="rtl"] .topbar-back .ic { transform: scaleX(-1); }
#topbar { display: flex; align-items: center; justify-content: space-between; }
.topbar-user { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 8px; }
.topbar-user .link { cursor: pointer; }

/* ---- Login screen ---- */
#loginScreen {
  position: fixed; inset: 0; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(160deg, #0f172a 0%, #1e293b 100%); z-index: 1000;
}
.login-box {
  background: var(--panel); border-radius: 16px; padding: 32px 30px; width: 320px;
  box-shadow: 0 20px 50px rgba(0,0,0,.35); display: flex; flex-direction: column; gap: 12px;
}
.login-brand { font-size: 19px; font-weight: 800; text-align: center; }
.login-logo { width: 96px; height: 96px; display: block; margin: 0 auto 2px; filter: drop-shadow(0 4px 10px rgba(0,0,0,.18)); }
#sidebar .brand { display: flex; align-items: center; gap: 10px; }
#sidebar .brand-logo { width: 38px; height: 38px; flex-shrink: 0; }
.login-sub { text-align: center; color: var(--muted); font-size: 13px; margin: 0 0 6px; }
.login-box label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; color: var(--muted); font-weight: 600; }
.login-box input { padding: 9px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px; }
.login-box button { margin-top: 6px; padding: 10px; font-size: 14px; }
.login-error { color: var(--red); font-size: 12.5px; min-height: 16px; }

/* ---- Permissions checkbox grid (المستخدمون والصلاحيات) ---- */
.perm-groups { display: flex; flex-direction: column; gap: 14px; }
.perm-group-title { font-size: 12.5px; font-weight: 700; color: var(--muted); margin-bottom: 6px; }
.perm-checks { display: flex; flex-wrap: wrap; gap: 8px 18px; }
.perm-check { display: flex; align-items: center; gap: 6px; font-size: 13px; }

/* Main — the window itself never scrolls; each screen fits the available height and only its data
   area (a table's rows, or a report's body) scrolls internally. See .page-flex/.page-head/.page-scroll
   /.panel-flex below, used by every screen instead of letting #main itself grow and scroll. */
#main { flex: 1; overflow: hidden; padding: 10px 26px 22px; display: flex; flex-direction: column; min-height: 0; }
.page-title { font-size: 20px; font-weight: 700; margin: 0 0 16px 0; display:flex; align-items:center; justify-content:space-between; flex: none; }
.page-title .actions { display:flex; gap:8px; }

/* A screen's root layout: fixed, always-visible header (title/stats/toolbar) + one flexible area
   that absorbs all remaining height and scrolls on its own — a table's rows for list screens, or
   the whole report body for a dashboard-style screen (still "data", per the no-page-scroll rule). */
.page-flex { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.page-head { flex: none; }
.page-scroll { flex: 1; min-height: 0; overflow-y: auto; padding-left: 2px; margin-right: -2px; }
.panel-flex { flex: 1; min-height: 0; display: flex; flex-direction: column; margin-bottom: 0; }
.panel-flex .table-wrap { flex: 1; min-height: 0; max-height: none; }
.panel-flex .pager { flex: none; }

/* Compact summary panels above a list screen's toolbar (e.g. التحصيلات) — smaller padding and a
   capped list height, so the fixed header stays short and leaves most of the window to the table. */
.panel-compact { padding: 12px 16px; margin-bottom: 0; }
.panel-compact .section-head { margin-bottom: 8px; }
.rank-list-compact { max-height: 130px; }

/* Type-breakdown table (Payments screen) — a dense, icon-led scrollable table instead of tall
   meter bars. Two panels in .pay-summary-row size to their own content (no forced stretch), so
   this only needs a cap for the rare case of many categories, not to match the panel beside it. */
.type-breakdown-table { display: block; max-height: 176px; overflow-y: auto; }
.type-breakdown-table tbody { display: block; }
.type-breakdown-table tr { display: flex; align-items: center; }
.type-breakdown-table td { flex: 1; padding: 6px 8px; border-bottom: 1px solid var(--panel-alt); font-size: 12.5px; display: flex; align-items: center; gap: 8px; }
.type-breakdown-table td:first-child { flex: 1.4; }
.type-breakdown-table td.num { flex: 0.8; text-align: left; font-variant-numeric: tabular-nums; display: block; }

/* Small icon chip leading each type row (color follows the same tone as the type's badge). */
.row-icon {
  flex: none; width: 24px; height: 24px; border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
}
.row-icon.tone-blue   { background: #dbeafe; color: var(--accent-dark); }
.row-icon.tone-green  { background: #dcfce7; color: var(--green); }
.row-icon.tone-amber  { background: #fef3c7; color: var(--amber); }
.row-icon.tone-violet { background: #ede9fe; color: var(--violet); }

/* Currency-symbol icon chip atop each currency card (Payments screen). */
.curr-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 999px; font-size: 11.5px; font-weight: 800; margin-bottom: 6px;
}
.curr-icon.tone-blue   { background: #dbeafe; color: var(--accent-dark); }
.curr-icon.tone-green  { background: #dcfce7; color: var(--green); }
.curr-icon.tone-amber  { background: #fef3c7; color: var(--amber); }
.curr-icon.tone-violet { background: #ede9fe; color: var(--violet); }

/* Payments screen's two summary panels: sit in the same grid row (equal height, aligned bottom
   edges — align-items defaults to stretch), but the shorter currency panel's cards are vertically
   centered in that height instead of pinned to the top with a flat empty strip below them. */
.panel-compact { display: flex; flex-direction: column; }
.panel-compact .section-head { flex: none; }
.panel-compact .type-breakdown-table { flex: none; }
.panel-compact .curr-grid { flex: 1; align-content: center; }

/* Two side-by-side panels (e.g. dashboard's "top debtors" / "recent bookings") that split the
   remaining window height, each scrolling its own table independently. */
.dash-row { flex: 1; min-height: 0; display: grid; grid-template-columns: 1.1fr 1fr; gap: 18px; }
.dash-row .panel { min-height: 0; }
@media (max-width: 1100px) { .dash-row { grid-template-columns: 1fr; } }

.cards { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 20px; }
.card {
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 16px 18px;
}
.card .label { color: var(--muted); font-size: 12.5px; margin-bottom: 6px; }
.card .value { font-size: 22px; font-weight: 700; }
.card .value.green { color: var(--green); }
.card .value.red { color: var(--red); }

.panel { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 18px; margin-bottom: 18px; }
.panel h3 { margin: 0 0 12px 0; font-size: 15px; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
thead th {
  text-align: center; padding: 9px 10px; background: #f1f5f9; color: var(--muted);
  font-weight: 600; font-size: 12px; border-bottom: 1px solid var(--border); position: sticky; top:0;
}
tbody td { padding: 8px 10px; border-bottom: 1px solid #f1f5f9; text-align: start; }
tbody tr:hover { background: #f8fafc; }
.table-wrap { max-height: 60vh; overflow-y: auto; border: 1px solid var(--border); border-radius: 10px; }
.num { font-variant-numeric: tabular-nums; text-align: end; }
.pos { color: var(--green); }
.neg { color: var(--red); }

.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; align-items: center; }
input, select, textarea {
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; font-family: inherit;
  background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #93c5fd; border-color: var(--accent); }
button {
  padding: 8px 14px; border-radius: 8px; border: 1px solid var(--border); background: #fff; cursor: pointer;
  font-size: 13px; font-family: inherit;
}
button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
button.primary:hover { background: var(--accent-dark); }
button.danger { color: var(--red); border-color: #fecaca; }
button.danger:hover { background: #fef2f2; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.small { padding: 4px 10px; font-size: 12px; }

.badge { display:inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11.5px; font-weight:600; }
.badge.paid { background:#dcfce7; color:#166534; }
.badge.notpaid { background:#fee2e2; color:#991b1b; }
.badge.tone-green  { background:#dcfce7; color:#166534; }
.badge.tone-blue   { background:#dbeafe; color:#1e40af; }
.badge.tone-amber  { background:#fef3c7; color:#92400e; }
.badge.tone-violet { background:#ede9fe; color:#5b21b6; }

.form-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.form-grid .full { grid-column: 1 / -1; }
.form-grid label { display:flex; flex-direction:column; gap:4px; font-size:12.5px; color:var(--muted); min-width: 0; }
.form-grid label input, .form-grid label select, .form-grid label textarea { width: 100%; min-width: 0; }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(15,23,42,0.5); display:flex; align-items:center; justify-content:center; z-index: 50;
}
.modal { background:#fff; border-radius: 14px; padding: 22px; width: 720px; max-width: 92vw; max-height: 88vh; overflow-y:auto; }
.modal.wide { width: 900px; }
.modal h3 { margin-top:0; }
.modal .modal-actions { display:flex; justify-content:flex-end; gap:8px; margin-top:16px; }

/* Grouped, labeled sections inside a form (used by the booking form) — breaks a long flat grid of
   fields into scannable chunks so a person entering many records a day can find the right field
   at a glance instead of hunting across one big block. */
.form-section { border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 12px; background: var(--panel-alt); }
.form-section:last-of-type { margin-bottom: 0; }
.form-section h4 { margin: 0 0 10px 0; font-size: 12.5px; font-weight:700; color: var(--accent-dark); text-transform: none; display:flex; align-items:center; justify-content:space-between; gap:10px; }
.form-section h4 .actions { font-weight: 400; }
.form-grid.cols-2 { grid-template-columns: repeat(2, minmax(0,1fr)); }
.form-grid.cols-3 { grid-template-columns: repeat(3, minmax(0,1fr)); }
.form-grid.cols-4 { grid-template-columns: repeat(4, minmax(0,1fr)); }

.price-section { background: #eff6ff; border-color: #bfdbfe; }
.price-hint { font-size: 12px; color: var(--muted); margin-bottom: 10px; line-height: 1.7; }
.price-badge { display:inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight:600; margin-left: 6px; }
.price-badge.auto { background:#dcfce7; color:#166534; }
.price-badge.manual { background:#fef3c7; color:#92400e; }
input.locked { background:#f1f5f9; color:#334155; cursor:not-allowed; }
button.small { font-size: 11.5px; padding: 4px 9px; }
.session-log-section { background:#f0fdf4; border-color:#bbf7d0; }
.session-log-section table { font-size: 12px; }
.session-log-section tr.editing-row { background:#fef9c3; }

/* Auto/locked, no-label fields (group_type, region, area) — shown as compact read-only chips in
   their own strip rather than labeled inputs, since a person never types these by hand. */
.auto-chips-section { padding: 8px 16px; background:#f8fafc; }
.chips-row { display:flex; flex-wrap:wrap; gap:8px; align-items:center; }
.chip { display:inline-flex; align-items:center; padding: 5px 12px; border-radius: 8px; background:#e2e8f0; color:#334155; font-size: 12.5px; font-weight:600; min-width: 60px; justify-content:center; }

.pager { display:flex; gap:8px; align-items:center; margin-top:10px; justify-content:flex-end; }

/* Bulk-selection toolbar above a table (e.g. التحصيلات) — appears once at least one row is checked. */
.selection-bar {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: #eff6ff;
  border-bottom: 1px solid var(--border); font-size: 13px; flex: none;
}
.selection-bar .sp { flex: 1; }
.selection-bar button.danger { background: #fff; }
.muted { color: var(--muted); }
.hint { font-size: 12px; color: var(--muted); margin-top: 4px; }
.tag { background:#eff6ff; color:#1d4ed8; border-radius:6px; padding:2px 8px; font-size:11.5px; }

a.link { color: var(--accent); cursor: pointer; text-decoration: none; }
a.link:hover { text-decoration: underline; }

.progress-box { font-family: monospace; font-size: 12px; background:#0f172a; color:#a7f3d0; padding:14px; border-radius:10px; max-height: 260px; overflow-y:auto; white-space:pre-wrap; }

/* ================= Ageing screen ================= */
.ageing-kpis { grid-template-columns: repeat(7, 1fr); }
.ageing-filters { padding: 14px 18px; }
.ageing-filters .fl { display:flex; flex-direction:column; gap:4px; font-size:12px; color:var(--muted); }
.ageing-panel { }
.ageing-table-wrap { max-height: 74vh; overflow: auto; border-radius: 10px; }
.ageing-table-wrap table { min-width: 100%; }
.ageing-table-wrap thead th { white-space: nowrap; }
.ageing-table-wrap tbody td { white-space: nowrap; }

.badge.status-good { background:#dcfce7; color:#166534; }
.badge.status-watch { background:#fef3c7; color:#92400e; }
.badge.status-late { background:#ffedd5; color:#9a3412; }
.badge.status-bad { background:#fee2e2; color:#991b1b; }

tr.st-good { background: #f0fdf4; }
tr.st-watch { background: #fffbeb; }
tr.st-late { background: #fff7ed; }
tr.st-bad { background: #fef2f2; }
tr.st-good:hover, tr.st-watch:hover, tr.st-late:hover, tr.st-bad:hover { filter: brightness(0.97); }

/* Pin the status + code + name columns to the reading-start edge (left in LTR/English, right in
   RTL/Arabic — inset-inline-start follows the page's dir automatically) so the customer stays
   identifiable while the many month columns scroll past underneath. */
.ageing-table-wrap th:nth-child(1), .ageing-table-wrap td:nth-child(1) { position: sticky; inset-inline-start: 0; min-width: 100px; z-index: 2; }
.ageing-table-wrap th:nth-child(2), .ageing-table-wrap td:nth-child(2) { position: sticky; inset-inline-start: 100px; min-width: 70px; z-index: 2; }
.ageing-table-wrap th:nth-child(3), .ageing-table-wrap td:nth-child(3) { position: sticky; inset-inline-start: 170px; min-width: 170px; max-width: 220px; white-space: normal; z-index: 2; box-shadow: 2px 0 4px rgba(0,0,0,0.06); }
.ageing-table-wrap thead th:nth-child(1), .ageing-table-wrap thead th:nth-child(2), .ageing-table-wrap thead th:nth-child(3) { z-index: 3; }
.ageing-table-wrap tbody td:nth-child(1), .ageing-table-wrap tbody td:nth-child(2), .ageing-table-wrap tbody td:nth-child(3) { background: #fff; }
.ageing-table-wrap tr.st-good td:nth-child(1), .ageing-table-wrap tr.st-good td:nth-child(2), .ageing-table-wrap tr.st-good td:nth-child(3) { background: #f0fdf4; }
.ageing-table-wrap tr.st-watch td:nth-child(1), .ageing-table-wrap tr.st-watch td:nth-child(2), .ageing-table-wrap tr.st-watch td:nth-child(3) { background: #fffbeb; }
.ageing-table-wrap tr.st-late td:nth-child(1), .ageing-table-wrap tr.st-late td:nth-child(2), .ageing-table-wrap tr.st-late td:nth-child(3) { background: #fff7ed; }
.ageing-table-wrap tr.st-bad td:nth-child(1), .ageing-table-wrap tr.st-bad td:nth-child(2), .ageing-table-wrap tr.st-bad td:nth-child(3) { background: #fef2f2; }

/* ================= Transactions (bookings) screen — wide table ================= */
/* The transactions table shows every column from the original Excel sheet, so it's much wider than
   the window. overflow:auto scrolls both directions inside the table's own box (never the whole
   page), white-space:nowrap keeps every header cell the same width as the data below it (a wrapped
   header or a wrapped cell is what makes a header drift out of line with its column), and pinning
   the date + customer columns keeps the row identifiable while the rest scrolls past underneath. */
.bookings-table-wrap { max-height: 68vh; overflow: auto; border-radius: 10px; }
.bookings-table-wrap table { min-width: 100%; }
.bookings-table-wrap thead th { white-space: nowrap; }
.bookings-table-wrap tbody td { white-space: nowrap; }
.bookings-table-wrap th:nth-child(1), .bookings-table-wrap td:nth-child(1) { position: sticky; inset-inline-start: 0; min-width: 96px; z-index: 2; background: #fff; }
.bookings-table-wrap th:nth-child(2), .bookings-table-wrap td:nth-child(2) { position: sticky; inset-inline-start: 96px; min-width: 150px; max-width: 200px; white-space: normal; z-index: 2; background: #fff; box-shadow: 2px 0 4px rgba(0,0,0,0.06); }
.bookings-table-wrap thead th:nth-child(1), .bookings-table-wrap thead th:nth-child(2) { z-index: 3; }
.bookings-table-wrap tbody tr:hover td:nth-child(1), .bookings-table-wrap tbody tr:hover td:nth-child(2) { background: #f8fafc; }

/* ================= Print (Ageing report) ================= */
#printArea { }
.print-header { display:none; }
.print-table { display:none; }
.print-footer { display:none; }

@media print {
  body.printing-ageing #app { display: none !important; }
  body.printing-ageing #modal-root { display: none !important; }
  body.printing-ageing #printArea { display: block !important; }
  body.printing-ageing .print-header {
    display:flex; align-items:center; gap:14px; margin-bottom:14px; border-bottom: 2px solid #0f172a; padding-bottom:10px;
  }
  body.printing-ageing .print-logo { height: 48px; }
  body.printing-ageing .print-company { font-size: 18px; font-weight: 800; color:#0f172a; }
  body.printing-ageing .print-sub { font-size: 12px; color:#334155; margin-top:2px; }
  body.printing-ageing .print-table {
    display: table; width: 100%; border-collapse: collapse; font-size: 9px; direction: rtl;
  }
  body.printing-ageing .print-table th, body.printing-ageing .print-table td {
    border: 1px solid #94a3b8; padding: 3px 5px; white-space: nowrap; text-align: center;
  }
  body.printing-ageing .print-table thead th { background: #e2e8f0; font-weight:700; }
  body.printing-ageing .print-table tbody tr:nth-child(even) { background: #f8fafc; }
  body.printing-ageing .print-footer { display:block; margin-top: 10px; font-size: 10px; color:#64748b; }
  /* Page size (width sized to the number of month columns) is injected dynamically at print
     time — see printAgeing() in app.js, #dynamicPrintPageSize. */
}

/* ===== Analytics dashboard — icon-led, no charting library ===== */
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.ic { display: block; }

/* -- icon badges (identity/decoration, not data-encoded) -- */
.icon-badge {
  flex: none; width: 38px; height: 38px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
}
.icon-badge.tone-blue   { background: #dbeafe; color: var(--accent-dark); }
.icon-badge.tone-green  { background: #dcfce7; color: var(--green); }
.icon-badge.tone-amber  { background: #fef3c7; color: var(--amber); }
.icon-badge.tone-violet { background: #ede9fe; color: var(--violet); }

/* -- KPI stat tiles -- */
.stat-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 16px; }
.stat-tile { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; display: flex; align-items: center; gap: 12px; }
.stat-tile-body { min-width: 0; }
.stat-label { font-size: 12px; color: var(--muted); margin-bottom: 3px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stat-value { font-size: 20px; font-weight: 800; line-height: 1.2; }
.stat-sub { font-size: 11px; color: var(--muted); margin-top: 2px; }

/* -- section header (icon + title) used atop every panel -- */
.section-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.section-head h3 { margin: 0; font-size: 14.5px; }

/* -- month/year comparison cards -- */
.compare-body { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.compare-side { text-align: center; flex: 1; }
.compare-value { font-size: 17px; font-weight: 800; margin-top: 2px; }
.compare-arrow { color: var(--muted); font-size: 11px; font-weight: 700; flex: none; }
.compare-foot { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding-top: 12px; border-top: 1px dashed var(--border); }

.delta-chip { display: inline-flex; align-items: center; gap: 4px; padding: 3px 9px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.delta-chip.good { background: #dcfce7; color: var(--green); }
.delta-chip.bad  { background: #fee2e2; color: var(--red); }
.delta-chip.flat { background: var(--panel-alt); color: var(--muted); }

/* -- ranked lists (replace bar charts: rank + name + meter + value) -- */
.rank-list { display: flex; flex-direction: column; gap: 9px; max-height: 300px; overflow-y: auto; padding-left: 2px; }
.rank-row { display: flex; align-items: center; gap: 10px; }
.rank-badge {
  flex: none; width: 22px; height: 22px; border-radius: 999px; background: var(--panel-alt); color: var(--muted);
  font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.rank-badge.medal { background: transparent; font-size: 15px; }
.rank-main { flex: 1; min-width: 0; }
.rank-name { font-size: 12.5px; margin-bottom: 4px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rank-value { flex: none; font-size: 12.5px; font-weight: 700; min-width: 78px; text-align: left; }

.meter-track { background: var(--panel-alt); border-radius: 5px; height: 8px; overflow: hidden; }
.meter-fill { height: 100%; border-radius: 5px; background: var(--accent); transition: width .2s ease; }
.meter-fill.tone-good { background: var(--green); }
.meter-fill.tone-mid  { background: var(--amber); }
.meter-fill.tone-bad  { background: var(--red); }

/* -- capacity cards: gauge + mini stats + per-trip-time meters -- */
.cap-card { }
.cap-body { display: flex; align-items: center; gap: 20px; margin-bottom: 14px; }
.cap-stats { flex: 1; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.cap-stat { text-align: center; background: var(--panel-alt); border-radius: 10px; padding: 10px 6px; }
.cap-stat-value { font-size: 17px; font-weight: 800; }
.cap-stat-label { font-size: 10.5px; color: var(--muted); margin-top: 2px; }

.notice-row { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--amber); background: #fef3c7; border-radius: 8px; padding: 7px 10px; margin-bottom: 12px; }

.slot-list { display: flex; flex-direction: column; gap: 8px; }
.slot-row { display: grid; grid-template-columns: 48px 1fr 46px 62px; align-items: center; gap: 10px; }
.slot-time { font-size: 12px; font-weight: 700; color: var(--text); }
.slot-pct { font-size: 12px; font-weight: 700; text-align: left; }
.slot-pct.tone-good { color: var(--green); }
.slot-pct.tone-mid  { color: var(--amber); }
.slot-pct.tone-bad  { color: var(--red); }
.slot-trips { font-size: 10.5px; text-align: left; white-space: nowrap; }

/* -- capacity gauge ring (conic-gradient; percentage read in the center) -- */
.gauge {
  flex: none; border-radius: 50%; display: flex; align-items: center; justify-content: center; position: relative;
  background: conic-gradient(var(--gauge-color) calc(var(--pct) * 1%), var(--panel-alt) 0);
}
.gauge.tone-good { --gauge-color: var(--green); }
.gauge.tone-mid  { --gauge-color: var(--amber); }
.gauge.tone-bad  { --gauge-color: var(--red); }
.gauge-hole {
  position: absolute; inset: 10px; border-radius: 50%; background: var(--panel);
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
.gauge-value { font-size: 19px; font-weight: 800; }
.gauge-caption { font-size: 10.5px; color: var(--muted); margin-top: 1px; }

/* KPI row now flexes to fit however many tiles are passed (4 or 5) instead of a fixed count. */
.stat-grid { grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); }

.today-panel { border-color: #bfdbfe; background: linear-gradient(180deg, #eff6ff 0%, var(--panel) 90px); }
.mini-title { font-size: 12px; font-weight: 700; color: var(--muted); margin-bottom: 8px; }
.full-span { grid-column: 1 / -1; margin-bottom: 16px; }
.rank-list-wide { display: block; column-count: 2; column-gap: 22px; max-height: none; }
.rank-list-wide .rank-row { break-inside: avoid; margin-bottom: 9px; }

/* -- compact data tables (boat performance, 12-month history) — used when a category has more than
   one attribute worth showing, per the "table over chart" rule for multi-attribute comparisons -- */
.mini-table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.mini-table th { text-align: right; font-weight: 700; color: var(--muted); font-size: 11px; padding: 6px 8px; border-bottom: 1px solid var(--border); position: sticky; top: 0; background: var(--panel); }
.mini-table td { padding: 7px 8px; border-bottom: 1px solid var(--panel-alt); }
.mini-table td.num, .mini-table th.num { text-align: left; font-variant-numeric: tabular-nums; }
.mini-table tbody tr:hover { background: var(--panel-alt); }

/* -- currency composition mini-grid (4 fixed columns, reuses .cap-stat card look) -- */
.curr-grid { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 1100px) {
  .curr-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 1100px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .cap-body { flex-direction: column; }
  .rank-list-wide { column-count: 1; }
}

/* ===================== Responsive fit for every desktop/laptop screen size =====================
   On a tall screen each page still fits the window and only its table scrolls. On a short or
   narrow screen, each flexible data area keeps a usable minimum height instead of collapsing to
   nothing, and the page itself scrolls (#main) to reveal whatever no longer fits. */
#main { overflow-y: auto; overflow-x: hidden; }
.panel-flex { min-height: 340px; }
.panel-flex .table-wrap { min-height: 240px; }
.page-scroll { min-height: 320px; }
.dash-row { min-height: 320px; }
.dash-row .panel { min-height: 300px; }
.dash-row .panel .table-wrap { min-height: 200px; }
.page-flex::after { content: ""; display: block; flex: none; height: 1px; }

/* Toolbars / filter rows wrap instead of pushing controls off-screen. */
.toolbar, .filters, .page-title .actions { flex-wrap: wrap; }

/* Laptops and small monitors. */
@media (max-width: 1280px) {
  :root { --sidebar-w: 200px; }
  #main { padding: 8px 18px 18px; }
  #topbar { padding: 12px 18px 0; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
}
@media (max-width: 1100px) {
  :root { --sidebar-w: 184px; }
  #sidebar .brand span { font-size: 14px; }
  .page-title { flex-wrap: wrap; gap: 8px; }
}
/* Short screens (e.g. 1366x768 with browser bars): tighten vertical spacing. */
@media (max-height: 700px) {
  .page-title { margin-bottom: 10px; }
  .cards { margin-bottom: 12px; }
  #sidebar .brand { padding: 12px 14px; }
}
