/* TSD ERP — application styles (themes, layout, components). */
* { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0F1419;
  --surface: #1A1F26;
  --surface-2: #242B33;
  --border: #2D353F;
  --border-light: #3A4350;
  --text: #E8EAED;
  --text-muted: #9AA0A6;
  --text-dim: #6B7280;
  --accent: #4A9EFF;
  --accent-dim: #2C5C99;
  --success: #4ADE80;
  --warning: #FBBF24;
  --danger: #F87171;
  --signed: #4ADE80;
  --quoting: #FBBF24;
  --maint-active: #4A9EFF;
  --maint-quoting: #F87171;
  --shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 12px 40px rgba(0, 0, 0, 0.5);
}

body {
  font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
  line-height: 1.5;
}

/* ============ LAYOUT ============ */
.app {
  display: grid;
  grid-template-columns: 240px 1fr;
  grid-template-areas: "sidebar main";
  min-height: 100vh;
  width: 100%;
}

.sidebar {
  grid-area: sidebar;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  min-width: 0;
}

.logo {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.logo h1 {
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, #4A9EFF 0%, #4ADE80 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.logo p {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

.nav-section {
  padding: 0 12px;
  margin-bottom: 4px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 6px;
}

.nav-title {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--text-dim);
  padding: 10px 12px 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
  user-select: none;
  border-radius: 5px;
  transition: background 0.15s;
}
.nav-title:hover { background: rgba(255,255,255,0.04); }
.nav-toggle { font-size: 9px; opacity: 0.5; transition: transform 0.22s; }
.nav-section.nav-collapsed .nav-toggle { transform: rotate(-90deg); }
.nav-section-body { overflow: hidden; max-height: 2000px; transition: max-height 0.28s ease; }
.nav-section.nav-collapsed .nav-section-body { max-height: 0; }

/* Sub-group label inside a section — e.g. "Project Lifecycle", "Financials" */
.nav-group-label {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-dim);
  padding: 8px 12px 3px;
  opacity: 0.55;
  margin-top: 4px;
}

/* Coming-soon badge on items */
.nav-item-soon .badge { background: rgba(255,255,255,0.07) !important; color: var(--text-dim) !important; font-size: 8px !important; }

.nav-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.15s;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 2px;
}

.nav-item:hover {
  background: var(--surface-2);
  color: var(--text);
}

.nav-item.active {
  background: var(--accent-dim);
  color: white;
}

.nav-item .badge {
  background: var(--surface-2);
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.nav-item.active .badge {
  background: rgba(255, 255, 255, 0.2);
}

.badge-wrap {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 1px;
  line-height: 1;
}

.badge-desc {
  font-size: 9px;
  color: var(--text-dim);
  font-weight: 400;
  letter-spacing: 0.3px;
}

.nav-item.active .badge-desc {
  color: rgba(255, 255, 255, 0.7);
}
/* NV1: My Work shortcuts, pin star, merged-screen type filter */
.nav-item { position: relative; }
.nav-item .nv-pin { position: absolute; inset-inline-end: 4px; top: 50%; transform: translateY(-50%); opacity: 0; font-size: 13px; line-height: 1; padding: 3px 5px; border-radius: 6px; background: var(--surface-2); color: var(--warning, #f59e0b); cursor: pointer; transition: opacity .12s; }
.nav-item:hover .nv-pin, .nav-item .nv-pin:focus { opacity: 1; }
#section-mywork .nav-title small.nv-ar { font-weight: 600; opacity: .75; text-transform: none; letter-spacing: 0; }
#section-mywork .nav-item { padding-top: 7px; padding-bottom: 7px; }
.nv-bar .nv-chip { padding: 5px 12px; font-size: 12px; border-radius: 999px; background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.nv-bar .nv-chip.nv-on { background: #1B378D; border-color: #1B378D; color: #fff; font-weight: 700; }
.nv-bar span.nv-chip { display: inline-block; }

/* NV3: quotation editor tabs (sticky bar, scrolls sideways on a phone) */
/* .main scrolls sideways (overflow-x:auto), which would hold the sticky bar in place: clip instead while the
   editor shows - its wide item tables already scroll inside their own boxes. */
.main:has(#qEdTabs) { overflow-x: clip; }
.q-tabs { position: sticky; top: 0; z-index: 40; display: flex; align-items: flex-end; gap: 10px; background: var(--bg); padding: 6px 0 0; margin: 0 0 14px; border-bottom: 2px solid #1B378D; }
.q-tabs-scroll { display: flex; gap: 4px; overflow-x: auto; overflow-y: hidden; flex: 1; min-width: 0; scrollbar-width: thin; -webkit-overflow-scrolling: touch; }
.q-tab-btn { flex: 0 0 auto; white-space: nowrap; padding: 8px 14px; font-size: 13px; font-weight: 600; border: 1px solid var(--border); border-bottom: none; border-radius: 8px 8px 0 0; background: var(--surface-2); color: var(--text-muted); cursor: pointer; font-family: inherit; }
.q-tab-btn:hover { color: var(--text); }
.q-tab-btn.q-tab-on { background: #1B378D; border-color: #1B378D; color: #fff; }
.q-tab-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.q-tab-total { flex: 0 0 auto; align-self: center; margin-bottom: 4px; white-space: nowrap; font-family: monospace; font-weight: 700; font-size: 12.5px; color: var(--success); background: var(--surface); border: 1px solid var(--success); border-radius: 999px; padding: 4px 10px; }
@media (max-width: 768px) {
  .q-tabs { flex-wrap: wrap; gap: 4px; }
  .q-tab-total { order: -1; margin-left: auto; font-size: 11.5px; }
  .q-tabs-scroll { flex: 1 1 100%; }
  .q-tab-btn { padding: 7px 10px; font-size: 12px; }
}

.main {
  grid-area: main;
  display: block;
  min-width: 0;
  width: 100%;
  padding: 24px 32px;
  max-width: 100%;
  overflow-x: auto;
  box-sizing: border-box;
}

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 24px;
}
/* Arabic: right to left. The buttons along the top wrap instead of running off the screen. */
html[dir="rtl"] .header-actions { flex-wrap: wrap; justify-content: flex-start; row-gap: 6px; }
html[dir="rtl"] .header { gap: 12px; }
html[dir="rtl"] .sidebar { border-right: 0; border-left: 1px solid var(--border); }
html[dir="rtl"] .nav-title, html[dir="rtl"] .nav-item { text-align: right; }
html[dir="rtl"] td.amount, html[dir="rtl"] th.amount { text-align: left; }
html[dir="rtl"] input[type="date"], html[dir="rtl"] input[type="number"], html[dir="rtl"] input[type="email"], html[dir="rtl"] input[type="tel"] { direction: ltr; text-align: right; }

.page-title {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ============ BUTTONS ============ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 16px;
  border-radius: 6px;
  border: 1px solid var(--border-light);
  background: var(--surface-2);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.btn:hover { background: var(--surface); border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: white; }
.btn-primary:hover { background: #5BABFF; border-color: #5BABFF; }
.btn-success { background: var(--success); border-color: var(--success); color: #0F1419; }
.btn-danger { background: transparent; border-color: var(--danger); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: white; }
.btn-icon { padding: 6px 10px; }

/* ============ CARDS ============ */
.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  transition: all 0.15s;
}

.card:hover { border-color: var(--border-light); }

.card-label {
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.card-value {
  font-size: 24px;
  font-weight: 600;
  letter-spacing: -0.5px;
}

.card-detail {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.card.signed { border-left: 3px solid var(--signed); }
.card.quoting { border-left: 3px solid var(--quoting); }
.card.maint-active { border-left: 3px solid var(--maint-active); }
.card.maint-quoting { border-left: 3px solid var(--maint-quoting); }

/* ============ TABLE ============ */
.table-container {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  margin-bottom: 24px;
}

.table-toolbar {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  max-width: 320px;
  position: relative;
}

.search-box input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.search-box::before {
  content: "🔍";
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 12px;
  opacity: 0.5;
}

.table-wrap {
  overflow-x: auto;
  max-height: calc(100vh - 280px);
}
/* A second horizontal scrollbar ABOVE a wide table, kept in step with the one
   at the bottom - so moving sideways never means scrolling down to the end of
   the table and back up again. Added by _tsdTopScrollbars. */
._tsdTopScroll {
  overflow-x: auto; overflow-y: hidden; height: 14px;
  position: sticky; top: 0; z-index: 6;
  background: var(--bg, transparent);
}
._tsdTopScroll > div { height: 1px; }
._tsdTopScroll::-webkit-scrollbar { height: 12px; }
._tsdTopScroll::-webkit-scrollbar-thumb { background: rgba(128,128,160,.55); border-radius: 6px; }
._tsdTopScroll::-webkit-scrollbar-track { background: rgba(128,128,160,.12); }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

thead {
  background: var(--surface-2);
  position: sticky;
  top: 0;
  z-index: 10;
}

th {
  text-align: left;
  padding: 10px 12px;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  /* Allow long text (descriptions, notes) to wrap onto multiple lines
     instead of being cut off with "..." at the end of the cell. */
  white-space: normal;
  word-wrap: break-word;
  overflow-wrap: break-word;
  vertical-align: top;
}

tbody tr:hover { background: var(--surface-2); }
tbody tr:last-child td { border-bottom: none; }

/* Totals row at the bottom of any table. Sticky-positioned so it stays
   visible when scrolling long lists. Inline styles are also set per-row
   by addTableTotalsRow() — these CSS rules cover what inline styles miss. */
tbody tr.totals-row {
  background: linear-gradient(to right, rgba(27,55,141,0.18), rgba(27,55,141,0.05));
  position: sticky;
  bottom: 0;
  z-index: 5;
}
tbody tr.totals-row td {
  border-top: 2px solid #1B378D;
  font-weight: 700;
  padding-top: 12px;
  padding-bottom: 12px;
  white-space: nowrap;
}
tbody tr.totals-row:hover { background: linear-gradient(to right, rgba(27,55,141,0.22), rgba(27,55,141,0.08)); }

.code-cell {
  font-family: 'SF Mono', Monaco, monospace;
  font-weight: 600;
  font-size: 12px;
}

.amount {
  font-family: 'SF Mono', Monaco, monospace;
  text-align: right;
  font-weight: 500;
  white-space: nowrap;
}

.amount.positive { color: var(--success); }
.amount.negative { color: var(--danger); }

.status-pill {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  font-size: 11px;
  font-weight: 600;
}

.status-paid { background: rgba(74, 222, 128, 0.15); color: var(--success); }
.status-unpaid { background: rgba(248, 113, 113, 0.15); color: var(--danger); }
.status-partial { background: rgba(251, 191, 36, 0.15); color: var(--warning); }

.actions-cell {
  display: flex;
  gap: 6px;
  white-space: nowrap;
}

.action-btn {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 11px;
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}

.action-btn:hover { border-color: var(--accent); color: var(--accent); }
.action-btn.delete:hover { border-color: var(--danger); color: var(--danger); }

/* ============ MODAL / FORM ============ */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.active { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  width: 100%;
  max-width: 680px;
  max-height: 95vh;
  box-shadow: var(--shadow-lg);
  animation: slideUp 0.2s ease-out;
  display: flex;
  flex-direction: column;
}

@keyframes slideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal-header {
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
}

.modal-title {
  font-size: 14px;
  font-weight: 600;
}

.modal-close {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 18px;
  cursor: pointer;
  padding: 2px 6px;
  border-radius: 4px;
}

.modal-close:hover { background: var(--surface-2); color: var(--text); }

.modal-body {
  padding: 12px 16px;
  flex: 1;
  overflow-y: auto;
  min-height: 0;
}

.modal-footer {
  padding: 8px 16px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 6px;
  flex-shrink: 0;
  background: var(--surface);
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 8px;
}

.form-grid.single { grid-template-columns: 1fr; }

.form-group {
  display: flex;
  flex-direction: column;
}

.form-group.full { grid-column: span 2; }

.form-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 2px;
  font-weight: 500;
}

.form-label .required { color: var(--danger); }

.form-input, .form-select, .form-textarea {
  padding: 5px 9px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 12px;
  font-family: inherit;
  transition: border-color 0.15s;
  max-width: 100%;
  min-width: 0;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}

.form-textarea {
  white-space: normal;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--accent);
}

.form-input[type="date"] {
  color-scheme: dark;
  cursor: pointer;
}

.form-input[readonly] {
  background: var(--surface);
  color: var(--text-muted);
  cursor: not-allowed;
}

.form-input.auto-generated {
  background: rgba(74, 158, 255, 0.1);
  color: var(--accent);
  font-family: 'SF Mono', Monaco, monospace;
  font-weight: 600;
}

.form-textarea {
  resize: vertical;
  min-height: 38px;
  font-family: inherit;
  white-space: normal;
}

.form-hint {
  font-size: 10px;
  color: var(--text-dim);
  margin-top: 2px;
}

.form-hint.success { color: var(--success); }

/* Type & Payment radio buttons — extra compact */
.type-radio, .pay-radio, .pm-radio {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  transition: all 0.15s;
  user-select: none;
  white-space: nowrap;
  min-width: 100px;
}

.type-radio:hover, .pay-radio:hover, .pm-radio:hover {
  border-color: var(--border-light);
  color: var(--text);
}

.type-radio.active, .pay-radio.active, .pm-radio.active {
  background: var(--accent-dim);
  border-color: var(--accent);
  color: white;
}

/* ============ TOAST ============ */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface);
  border: 1px solid var(--success);
  border-radius: 8px;
  padding: 12px 20px;
  font-size: 13px;
  box-shadow: var(--shadow);
  z-index: 200;
  display: none;
  animation: slideInRight 0.2s ease-out;
}

.toast.show { display: block; }
.toast.error { border-color: var(--danger); }

@keyframes slideInRight {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ============ EMPTY STATE ============ */
.empty {
  text-align: center;
  padding: 60px 20px;
  color: var(--text-muted);
}

.empty-icon {
  font-size: 48px;
  margin-bottom: 12px;
  opacity: 0.5;
}

/* ============ MOBILE ============ */
/* ============ MOBILE RESPONSIVE ============ */
@media (max-width: 768px) {
  body { font-size: 13px; -webkit-text-size-adjust: 100%; overscroll-behavior-y: contain; }

  /* Layout */
  .app { grid-template-columns: 1fr; }

  /* Sidebar — slide-in drawer */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    z-index: 400;
    width: 280px;
    max-width: 85vw;
    transition: transform 0.25s cubic-bezier(0.4,0,0.2,1);
    box-shadow: 0 0 40px rgba(0,0,0,0.6);
    height: 100dvh; /* dynamic viewport height — better on mobile browsers */
    height: 100vh;  /* fallback */
  }
  .sidebar.open { transform: translateX(0); }

  /* Backdrop behind open sidebar */
  .sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.55);
    z-index: 350;
    backdrop-filter: blur(2px);
    -webkit-tap-highlight-color: transparent;
  }
  .sidebar.open ~ .sidebar-backdrop,
  body.sidebar-open .sidebar-backdrop { display: block; }

  /* Main content */
  .main {
    padding: 12px 12px;
    /* Add bottom safe area padding for iPhone home indicator */
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
  }

  /* Header — title row + actions row */
  .header {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    margin-bottom: 14px;
  }
  .header > div:first-child {
    display: flex;
    align-items: center;
    gap: 10px;
    min-width: 0;
  }
  .page-title { font-size: 17px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .page-subtitle { font-size: 11px; display: none; } /* hide subtitle on mobile to save space */
  .menu-toggle { display: block !important; flex-shrink: 0; min-width: 38px; min-height: 38px; font-size: 18px; padding: 4px 8px; }

  /* Header actions — wrap nicely */
  .header-actions { flex-wrap: wrap; gap: 6px; }
  .header-actions > .btn { font-size: 12px; padding: 6px 10px; min-height: 34px; }
  /* Hide auto-save text on mobile */
  .header-actions > span:not(#coSwitch) { display: none !important; }
  /* the company switch (⇄ TET / ⇄ TSD) stays on the phone, compact (OM 2026-10-14) */
  #coSwitch { margin-right: 2px !important; }
  #coSwitch .co-switch { padding: 4px 8px !important; font-size: 11px !important; min-height: 30px; white-space: nowrap; }

  /* Date filter — full row on mobile */
  .date-filter {
    order: 10;
    width: 100%;
    padding: 6px 10px;
    justify-content: space-between;
  }
  .date-filter-label { font-size: 12px; }
  .date-filter-input { width: calc(50% - 24px); font-size: 14px; min-height: 30px; }
  .date-filter-sep { font-size: 12px; }
  .year-picker { order: 9; font-size: 12px; padding: 5px 8px; min-height: 34px; }

  /* Cards — 2 columns */
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 14px; }
  .card { padding: 12px 14px; }
  .card-value { font-size: 18px; }
  .card-label { font-size: 10px; }
  .card-detail { font-size: 11px; }

  /* Forms */
  .form-grid { grid-template-columns: 1fr; gap: 10px; }
  .form-group.full { grid-column: span 1; }

  /* CRITICAL: prevent iOS zoom on input focus — all inputs need font-size 16px */
  input, select, textarea, .form-input, .form-select, .form-textarea {
    font-size: 16px !important;
    -webkit-text-size-adjust: 100%;
  }
  /* But keep badges/pills small */
  .badge, .status-pill, .badge-desc { font-size: inherit !important; }

  /* Modal — full screen on mobile */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    max-width: 100%;
    width: 100%;
    max-height: 96dvh;
    max-height: 96vh;
    border-radius: 16px 16px 0 0;
    border: none;
    border-top: 1px solid var(--border-light);
    display: flex;
    flex-direction: column;
  }
  .modal-header { padding: 14px 16px 10px; position: sticky; top: 0; background: var(--surface); z-index: 5; }
  .modal-header::before {
    content: '';
    display: block;
    width: 40px; height: 4px;
    background: var(--border-light);
    border-radius: 2px;
    margin: 0 auto 12px;
  }
  .modal-title { font-size: 16px; }
  .modal-close { font-size: 22px; min-height: 40px; min-width: 40px; display: flex; align-items: center; justify-content: center; }
  .modal-body { padding: 14px 16px; flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
  .modal-footer {
    padding: 12px 16px;
    padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    position: sticky;
    bottom: 0;
    background: var(--surface);
    z-index: 5;
    box-shadow: 0 -2px 8px rgba(0,0,0,0.2);
  }
  .modal-footer .btn { padding: 12px 18px; font-size: 15px; min-height: 44px; flex: 1; }

  /* Tables */
  .table-container { border-radius: 8px; margin-bottom: 14px; }
  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    max-height: none;
    /* Hint that table scrolls horizontally */
    overscroll-behavior-x: contain;
  }
  table { font-size: 12px; }
  th { padding: 8px 8px; font-size: 10px; white-space: nowrap; }
  td { padding: 8px 8px; }

  /* Table toolbar stacks vertically */
  .table-toolbar {
    flex-direction: column;
    align-items: stretch;
    padding: 10px 10px;
    gap: 8px;
  }
  .search-box { max-width: 100%; }
  .table-toolbar > div { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; width: 100%; }
  .table-toolbar > div > .btn { flex: 1; justify-content: center; min-height: 38px; font-size: 12px; }
  .table-toolbar > div > span { width: 100%; text-align: center; font-size: 11px; order: -1; }

  /* Actions cell — wrap buttons on mobile (override inline white-space:nowrap) */
  .actions-cell { white-space: normal !important; flex-wrap: wrap !important; gap: 4px !important; min-width: 70px; }
  .action-btn { padding: 6px 8px; font-size: 11px; min-height: 30px; min-width: 30px; touch-action: manipulation; }

  /* Buttons — bigger tap targets */
  .btn { min-height: 38px; padding: 8px 14px; touch-action: manipulation; }
  button { touch-action: manipulation; }

  /* Toast — full width at bottom */
  .toast { left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px)); transform: none; width: auto; max-width: none; text-align: center; z-index: 500; }

  /* Radio/checkbox chips wrap */
  .type-radio, .pay-radio, .pm-radio { flex: 1; min-width: 0; text-align: center; font-size: 12px !important; padding: 10px 6px; min-height: 40px; }

  /* Status pills */
  .status-pill { font-size: 10px; padding: 2px 6px; }

  /* Nav section label bigger touch area */
  .nav-title { padding: 12px 14px 8px; min-height: 44px; align-items: center; }
  .nav-item { padding: 12px 14px; min-height: 44px; }
  .nav-group-label { padding: 10px 14px 4px; }

  /* Bank allocation rows */
  .bank-alloc-row { grid-template-columns: 1fr 1fr !important; gap: 4px !important; padding: 8px !important; border-radius: 4px; background: var(--surface); margin-bottom: 4px; }
  .bank-alloc-row > *:first-child { grid-column: 1 / -1; }

  /* Supplier / project contact rows */
  .sup-contact-row, .proj-contact-row { grid-template-columns: 1fr 1fr !important; gap: 6px !important; padding: 8px !important; background: var(--surface); border-radius: 4px; margin-bottom: 6px; }
  .sup-contact-row > input, .proj-contact-row > input { padding: 10px !important; }
  .sup-contact-row > button, .proj-contact-row > button { grid-column: 1 / -1; justify-self: end; margin-top: 4px; min-height: 36px; }
}

/* Very small phones (≤ 390px) */
@media (max-width: 390px) {
  .cards { grid-template-columns: 1fr; }
  .main { padding: 8px 8px; }
  .page-title { font-size: 15px; }
  .saving-dot { display: none !important; }
  .header-actions > .btn { font-size: 11px; padding: 6px 8px; }
  .date-filter-input { width: calc(50% - 20px); font-size: 13px; }
  .modal-footer .btn { font-size: 14px; padding: 10px 12px; }
}

/* Tablet (769px – 1024px) */
@media (min-width: 769px) and (max-width: 1024px) {
  .app { grid-template-columns: 220px 1fr; }
  .main { padding: 16px 18px; }
  .cards { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }
  .action-btn { padding: 5px 8px; font-size: 11px; }
  input, select, textarea { font-size: 16px; } /* prevent iOS zoom on iPad too */
}

/* Touch devices — bigger tap targets, disable hover effects */
@media (hover: none) and (pointer: coarse) {
  .nav-item { padding: 12px 14px; }
  .action-btn { min-height: 34px; min-width: 34px; }
  .btn { min-height: 40px; }
  input[type="checkbox"], input[type="radio"] { transform: scale(1.3); }
  /* Remove hover-only effects that feel broken on touch */
  .card:hover { border-color: var(--border); }
  tbody tr:hover { background: transparent; }
  .nav-item:not(.active):hover { background: transparent; }
}

/* iPhone (home-screen app draws under the status bar): the app starts BELOW the camera island,
   and a solid strip stays behind the status bar so scrolled content never shows there.
   --sat is the status bar height the phone reports (0 on computers). */
:root { --sat: env(safe-area-inset-top, 0px); }
body { padding-top: var(--sat); }
body::before { content: ''; position: fixed; top: 0; left: 0; right: 0; height: var(--sat); background: var(--ws-brand, #1B378D); z-index: 100000; pointer-events: none; }
/* Safe area support (iPhone X+, Android with gesture nav) */
@supports (padding: env(safe-area-inset-bottom)) {
  .sidebar { padding-top: env(safe-area-inset-top, 0px); }
  @media (max-width: 768px) {
    .main { padding-bottom: calc(12px + env(safe-area-inset-bottom, 0px)); }
  }
}

/* Scrollbar styling for webkit */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--surface); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-dim); }


.menu-toggle {
  display: none;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 6px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 16px;
}

.header-actions {
  display: flex;
  gap: 8px;
  align-items: center;
}

/* Date Range Filter */
.date-filter {
  display: flex;
  align-items: center;
  gap: 4px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 2px 6px;
}

.date-filter-label {
  font-size: 13px;
  margin-right: 2px;
}

.date-filter-input {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: 11px;
  font-family: inherit;
  padding: 3px 4px;
  width: 110px;
  color-scheme: dark;
  cursor: pointer;
}

.date-filter-input:focus { outline: none; }

.date-filter-sep {
  color: var(--text-dim);
  font-size: 11px;
}

.date-filter-clear {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 0 4px;
  border-radius: 3px;
}

.date-filter-clear:hover { background: var(--danger); color: white; }

/* Year quick picker */
.year-picker {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text);
  font-size: 11px;
  font-family: inherit;
  padding: 5px 8px;
  cursor: pointer;
}

.year-picker:focus { outline: none; border-color: var(--accent); }

/* Saving indicator */
.saving-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}
  .proj-tip{position:fixed;z-index:99999;background:#1a1a2e;color:#fff;border:1px solid #1B378D;border-radius:8px;padding:10px 14px;font-size:11px;max-width:320px;pointer-events:none;box-shadow:0 4px 20px rgba(0,0,0,0.4);line-height:1.5}
  .proj-tip strong{color:#e6e9f4}
  .proj-tip .pt-label{color:#aaa;font-size:10px}
  .proj-tip .pt-val{color:#fff;font-weight:700}

/* ============================================================
   DASHBOARD V2 — design system (scoped to .dv2, nothing else changes)
   Tokens: colour, spacing, type, radius, shadow. Light and dark are
   both chosen values (not an automatic flip); series/status colours
   follow a palette validated for colour-blind separation.
   ============================================================ */
.dv2 {
  --dv-sp-1: 4px; --dv-sp-2: 8px; --dv-sp-3: 12px; --dv-sp-4: 16px; --dv-sp-5: 24px; --dv-sp-6: 32px;
  --dv-r-sm: 6px; --dv-r-md: 10px; --dv-r-lg: 14px; --dv-r-pill: 999px;
  --dv-font: "Segoe UI", system-ui, -apple-system, "Noto Sans Arabic", "Geeza Pro", Tahoma, sans-serif;
  --dv-fs-xs: 11px; --dv-fs-sm: 12px; --dv-fs-md: 14px; --dv-fs-lg: 18px; --dv-fs-xl: 26px; --dv-fs-hero: 30px;
  --dv-fw-n: 400; --dv-fw-m: 600; --dv-fw-b: 700;
  /* status (fixed, never used as a series colour) */
  --dv-good: #0ca30c; --dv-warn: #fab219; --dv-serious: #ec835a; --dv-crit: #d03b3b; --dv-info: #2a78d6;
  font-family: var(--dv-font);
  color: var(--dv-text);
  font-size: var(--dv-fs-md);
  line-height: 1.5;
}
/* Surfaces and ink come from the user's app theme (THEMES / applyTheme), so
   the dashboard follows whichever of the 16 themes is chosen - no second
   switch. data-mode (light/dark, taken from that theme's own flag) only picks
   the chart series colours and a few chart inks that need their own step. */
.dv2 {
  --dv-page: transparent;
  --dv-surface: var(--surface); --dv-surface-2: var(--surface-2);
  --dv-border: var(--border); --dv-border-2: var(--border);
  --dv-text: var(--text); --dv-text-2: var(--text-muted); --dv-muted: var(--text-muted);
  --dv-accent: var(--accent); --dv-up: var(--success); --dv-down: var(--danger);
  --dv-shadow-1: var(--shadow); --dv-shadow-2: var(--shadow-lg);
}
.dv2[data-mode="light"] {
  --dv-grid: rgba(11,11,11,0.10); --dv-axis: rgba(11,11,11,0.28);
  --dv-accent-wash: rgba(42,120,214,0.10);
  --dv-shadow-1: 0 1px 2px rgba(11,11,11,0.06), 0 1px 1px rgba(11,11,11,0.04);
  --dv-shadow-2: 0 6px 20px rgba(11,11,11,0.10);
  --dv-skel: linear-gradient(90deg, rgba(11,11,11,0.06) 0%, rgba(11,11,11,0.02) 50%, rgba(11,11,11,0.06) 100%);
  --dv-s1: #2a78d6; --dv-s2: #eb6834; --dv-s3: #1baf7a; --dv-s4: #eda100; --dv-s5: #e87ba4; --dv-s6: #008300; --dv-s7: #4a3aa7; --dv-s8: #e34948;
  --dv-seq-1: #86b6ef; --dv-seq-2: #5598e7; --dv-seq-3: #2a78d6; --dv-seq-4: #1c5cab;
}
.dv2[data-mode="dark"] {
  --dv-grid: rgba(255,255,255,0.08); --dv-axis: rgba(255,255,255,0.22);
  --dv-accent-wash: rgba(57,135,229,0.16);
  --dv-skel: linear-gradient(90deg, rgba(255,255,255,0.05) 0%, rgba(255,255,255,0.10) 50%, rgba(255,255,255,0.05) 100%);
  --dv-s1: #3987e5; --dv-s2: #d95926; --dv-s3: #199e70; --dv-s4: #c98500; --dv-s5: #d55181; --dv-s6: #008300; --dv-s7: #9085e9; --dv-s8: #e66767;
  --dv-seq-1: #184f95; --dv-seq-2: #256abf; --dv-seq-3: #3987e5; --dv-seq-4: #6da7ec;
}
.dv2 { background: var(--dv-page); }
.dv2 *, .dv2 *::before, .dv2 *::after { box-sizing: border-box; }
/* numbers stay left-to-right and readable inside Arabic text */
.dv2 .dv-num { direction: ltr; unicode-bidi: isolate; font-variant-numeric: normal; white-space: nowrap; }
.dv2 .dv-tab { font-variant-numeric: tabular-nums; }

/* While the new dashboard is on screen (#content holds .dv2 — CSS only, no
   script, so it follows whatever the app shows): the app's page title /
   "Showing data for", the date filter, the year picker and the per-screen PDF
   export are hidden — the dashboard has its own title and fixed periods.
   Every other screen, and the classic dashboard, keep them. */
.main:has(#content > .dv2) #pageTitle, .main:has(#content > .dv2) #pageSubtitle, .main:has(#content > .dv2) #pageBar, .main:has(#content > .dv2) .page-head { display: none !important; }
/* ---- header / toolbar ---- */
.dv2 .dv-head { display: flex; align-items: center; gap: var(--dv-sp-3); flex-wrap: wrap; margin-bottom: var(--dv-sp-4); }
.dv2 .dv-title { font-size: var(--dv-fs-lg); font-weight: var(--dv-fw-b); margin: 0; }
.dv2 .dv-sub { color: var(--dv-text-2); font-size: var(--dv-fs-sm); }
.dv2 .dv-spacer { flex: 1; }
.dv2 .dv-section { margin-top: var(--dv-sp-5); }
.dv2 .dv-section-h { display: flex; align-items: baseline; gap: var(--dv-sp-2); margin: 0 0 var(--dv-sp-3); font-size: var(--dv-fs-md); font-weight: var(--dv-fw-b); color: var(--dv-text); }
.dv2 .dv-section-h small { font-weight: var(--dv-fw-n); color: var(--dv-muted); font-size: var(--dv-fs-xs); }

/* ---- button ---- */
.dv2 .dv-btn { font: inherit; font-size: var(--dv-fs-sm); font-weight: var(--dv-fw-m); display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; border-radius: var(--dv-r-sm); border: 1px solid var(--dv-border-2); background: var(--dv-surface); color: var(--dv-text);
  cursor: pointer; transition: background .15s, border-color .15s; min-height: 40px; }
.dv2 .dv-btn:hover { background: var(--dv-surface-2); }
.dv2 .dv-btn:focus-visible, .dv2 .dv-kpi:focus-visible, .dv2 .dv-row-link:focus-visible { outline: 2px solid var(--dv-accent); outline-offset: 2px; }
.dv2 .dv-btn.primary { background: var(--dv-accent); border-color: var(--dv-accent); color: #fff; }
.dv2 .dv-btn.primary:hover { filter: brightness(1.08); }
.dv2 .dv-btn.ghost { background: transparent; border-color: transparent; color: var(--dv-text-2); }
.dv2 .dv-btn.ghost:hover { background: var(--dv-surface-2); color: var(--dv-text); }
.dv2 .dv-btn[aria-pressed="true"] { border-color: var(--dv-accent); color: var(--dv-accent); }

/* ---- KPI card ---- */
.dv2 .dv-kpis { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--dv-sp-3); }
.dv2 .dv-kpi { background: var(--dv-surface); border: 1px solid var(--dv-border); border-radius: var(--dv-r-md); box-shadow: var(--dv-shadow-1);
  padding: var(--dv-sp-4); display: flex; flex-direction: column; gap: 6px; min-height: 132px; text-align: start; font: inherit; color: inherit; width: 100%; }
.dv2 button.dv-kpi { cursor: pointer; transition: box-shadow .15s, transform .15s; }
.dv2 button.dv-kpi:hover { box-shadow: var(--dv-shadow-2); transform: translateY(-1px); }
.dv2 .dv-kpi-label { font-size: var(--dv-fs-sm); color: var(--dv-text-2); font-weight: var(--dv-fw-m); display: flex; align-items: center; gap: 6px; }
.dv2 .dv-kpi-value { font-size: var(--dv-fs-xl); font-weight: var(--dv-fw-b); line-height: 1.15; }
.dv2 .dv-cur { margin-inline-start: 4px; color: var(--dv-muted); }
.dv2 .dv-kpi-value .dv-cur { font-size: var(--dv-fs-sm); font-weight: var(--dv-fw-m); }
.dv2 .dv-kpi-sub { font-size: var(--dv-fs-sm); color: var(--dv-text-2); }
.dv2 .dv-kpi-foot { margin-top: auto; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: var(--dv-fs-xs); color: var(--dv-muted); }
.dv2 .dv-delta { font-weight: var(--dv-fw-m); }
.dv2 .dv-delta.up { color: var(--dv-up); }
.dv2 .dv-delta.down { color: var(--dv-down); }
.dv2 .dv-delta.flat { color: var(--dv-muted); }

/* ---- no data / skeleton ---- */
.dv2 .dv-nodata { display: flex; align-items: center; gap: 6px; color: var(--dv-muted); font-size: var(--dv-fs-sm); font-weight: var(--dv-fw-m); }
.dv2 .dv-nodata::before { content: ""; width: 14px; height: 14px; flex: none; border-radius: 50%; border: 2px dashed var(--dv-axis); }
.dv2 .dv-nodata-why { color: var(--dv-muted); font-size: var(--dv-fs-xs); }
.dv2 .dv-skel { background: var(--dv-skel); background-size: 200% 100%; animation: dvSkel 1.2s ease-in-out infinite; border-radius: var(--dv-r-sm); }
@keyframes dvSkel { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .dv2 .dv-skel { animation: none; } }

/* ---- badge ---- */
.dv2 .dv-badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: var(--dv-r-pill); font-size: var(--dv-fs-xs);
  font-weight: var(--dv-fw-m); border: 1px solid var(--dv-border-2); color: var(--dv-text-2); background: var(--dv-surface-2); white-space: nowrap; }
.dv2 .dv-badge::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: var(--dv-muted); }
.dv2 .dv-badge.good::before { background: var(--dv-good); }
.dv2 .dv-badge.warn::before { background: var(--dv-warn); }
.dv2 .dv-badge.serious::before { background: var(--dv-serious); }
.dv2 .dv-badge.crit::before { background: var(--dv-crit); }
.dv2 .dv-badge.info::before { background: var(--dv-info); }

/* ---- alert ---- */
.dv2 .dv-alert { display: flex; align-items: center; gap: var(--dv-sp-3); padding: 10px var(--dv-sp-3); border-radius: var(--dv-r-sm);
  background: var(--dv-surface); border: 1px solid var(--dv-border); border-inline-start: 4px solid var(--dv-muted); }
.dv2 .dv-alert.crit { border-inline-start-color: var(--dv-crit); }
.dv2 .dv-alert.warn { border-inline-start-color: var(--dv-warn); }
.dv2 .dv-alert.info { border-inline-start-color: var(--dv-info); }
.dv2 .dv-alert-ico { font-size: 16px; flex: none; width: 22px; text-align: center; }
.dv2 .dv-alert-body { flex: 1; min-width: 0; }
.dv2 .dv-alert-title { font-weight: var(--dv-fw-m); font-size: var(--dv-fs-md); }
.dv2 .dv-alert-meta { color: var(--dv-text-2); font-size: var(--dv-fs-sm); }
.dv2 .dv-alerts { display: flex; flex-direction: column; gap: var(--dv-sp-2); }
.dv2 .dv-alert-sum { display: flex; gap: var(--dv-sp-2); flex-wrap: wrap; margin-bottom: var(--dv-sp-3); }
.dv2 .dv-nodata.dv-ok::before { border: 0; background: var(--dv-good); width: 10px; height: 10px; }

/* ---- table ---- */
.dv2 .dv-table-wrap { background: var(--dv-surface); border: 1px solid var(--dv-border); border-radius: var(--dv-r-md); overflow: auto; }
.dv2 table.dv-table { width: 100%; border-collapse: collapse; font-size: var(--dv-fs-sm); }
.dv2 .dv-table th { text-align: start; font-weight: var(--dv-fw-m); color: var(--dv-text-2); padding: 10px 12px; border-bottom: 1px solid var(--dv-border-2);
  background: var(--dv-surface-2); position: sticky; top: 0; white-space: nowrap; }
.dv2 .dv-table td { padding: 10px 12px; border-bottom: 1px solid var(--dv-border-2); vertical-align: middle; }
.dv2 .dv-table tr:last-child td { border-bottom: 0; }
.dv2 .dv-table td.n, .dv2 .dv-table th.n { text-align: end; font-variant-numeric: tabular-nums; }
.dv2 .dv-table tbody tr.dv-row-link { cursor: pointer; }
.dv2 .dv-table tbody tr.dv-row-link:hover { background: var(--dv-accent-wash); }
.dv2 .dv-table th button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; padding: 0; }

/* ---- generic panel ---- */
.dv2 .dv-panel { background: var(--dv-surface); border: 1px solid var(--dv-border); border-radius: var(--dv-r-md); box-shadow: var(--dv-shadow-1); padding: var(--dv-sp-4); }
.dv2 .dv-banner-err { border-color: var(--dv-crit); border-inline-start-width: 4px; color: var(--dv-text); margin-bottom: var(--dv-sp-3); display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.dv2 .dv-banner { padding: 10px var(--dv-sp-3); border-radius: var(--dv-r-sm); background: var(--dv-surface-2); border: 1px solid var(--dv-border-2); color: var(--dv-text-2); font-size: var(--dv-fs-sm); }

/* ---- charts (one small in-house renderer: SVG columns + HTML bars) ---- */
.dv2 .dv-charts { display: grid; grid-template-columns: repeat(auto-fit, minmax(340px, 1fr)); gap: var(--dv-sp-3); }
.dv2 .dv-chart { background: var(--dv-surface); border: 1px solid var(--dv-border); border-radius: var(--dv-r-md); box-shadow: var(--dv-shadow-1); padding: var(--dv-sp-4); min-width: 0; }
.dv2 .dv-chart.wide { grid-column: 1 / -1; }
.dv2 .dv-chart-h { font-weight: var(--dv-fw-b); font-size: var(--dv-fs-md); margin: 0; }
.dv2 .dv-chart-sub { color: var(--dv-text-2); font-size: var(--dv-fs-xs); margin: 2px 0 var(--dv-sp-3); }
.dv2 .dv-legend { display: flex; gap: var(--dv-sp-4); flex-wrap: wrap; font-size: var(--dv-fs-xs); color: var(--dv-text-2); margin-bottom: var(--dv-sp-2); }
.dv2 .dv-key { display: inline-flex; align-items: center; gap: 6px; }
.dv2 .dv-key i { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.dv2 .dv-svg-wrap { overflow-x: auto; }
.dv2 .dv-svg-wrap svg { display: block; width: 100%; min-width: 340px; height: auto; }
.dv2 svg .dv-grid { stroke: var(--dv-grid); stroke-width: 1; }
.dv2 svg .dv-base { stroke: var(--dv-axis); stroke-width: 1; }
.dv2 svg text { fill: var(--dv-muted); font-size: 11px; font-family: var(--dv-font); }
.dv2 svg .dv-bar { transition: opacity .15s; }
.dv2 svg .dv-hit:hover + .dv-bar, .dv2 svg .dv-bar:hover { opacity: .8; }
.dv2 .dv-hbars { display: flex; flex-direction: column; gap: 10px; }
.dv2 .dv-hbar { display: grid; grid-template-columns: minmax(110px, 38%) 1fr auto; align-items: center; gap: var(--dv-sp-3); font-size: var(--dv-fs-sm); }
.dv2 .dv-hbar-label { color: var(--dv-text); line-height: 1.3; }
.dv2 .dv-hbar-track { height: 14px; border-radius: 4px; background: var(--dv-surface-2); overflow: hidden; }
.dv2 .dv-hbar-fill { height: 100%; border-start-end-radius: 4px; border-end-end-radius: 4px; min-width: 2px; }
.dv2 .dv-hbar-val { color: var(--dv-text); font-variant-numeric: tabular-nums; text-align: end; white-space: nowrap; }
.dv2 .dv-hbar-val small { color: var(--dv-muted); }
.dv2 .dv-c1 { background: var(--dv-s1); fill: var(--dv-s1); } .dv2 .dv-c2 { background: var(--dv-s2); fill: var(--dv-s2); }
.dv2 .dv-q1 { background: var(--dv-seq-1); } .dv2 .dv-q2 { background: var(--dv-seq-2); } .dv2 .dv-q3 { background: var(--dv-seq-3); } .dv2 .dv-q4 { background: var(--dv-seq-4); }
.dv2 details.dv-data { margin-top: var(--dv-sp-3); font-size: var(--dv-fs-xs); }
.dv2 details.dv-data summary { cursor: pointer; color: var(--dv-text-2); min-height: 40px; display: flex; align-items: center; }
.dv2 details.dv-data .dv-table-wrap { margin-top: var(--dv-sp-2); }
.dv2 .dv-chart-note { margin-top: var(--dv-sp-2); color: var(--dv-muted); font-size: var(--dv-fs-xs); }
#dvTip { position: fixed; z-index: 100000; pointer-events: none; background: var(--surface, #1a1a19); color: var(--text, #fff); border: 1px solid var(--border, #333);
  border-radius: 8px; padding: 6px 10px; font-size: 12px; box-shadow: 0 6px 20px rgba(0,0,0,.25); display: none; white-space: nowrap; }
/* ---- filters ---- */
.dv2 .dv-filters { display: flex; flex-wrap: wrap; gap: var(--dv-sp-2); align-items: center; margin-bottom: var(--dv-sp-3); }
.dv2 .dv-chips { display: flex; flex-wrap: wrap; gap: 6px; }
.dv2 .dv-input { font: inherit; font-size: var(--dv-fs-sm); min-height: 34px; padding: 6px 10px; border-radius: var(--dv-r-sm); border: 1px solid var(--dv-border-2);
  background: var(--dv-surface); color: var(--dv-text); min-width: 220px; flex: 1 1 220px; max-width: 360px; min-height: 40px; }
.dv2 .dv-input:focus-visible { outline: 2px solid var(--dv-accent); outline-offset: 1px; }
.dv2 .dv-pj-count { color: var(--dv-muted); font-size: var(--dv-fs-xs); margin-bottom: 6px; }
/* the projects table scrolls sideways on small screens; the name column stays put */
.dv2 #dvPjTable .dv-table td:first-child, .dv2 #dvPjTable .dv-table th:first-child { position: sticky; inset-inline-start: 0; background: var(--dv-surface); z-index: 1; }
.dv2 #dvPjTable .dv-table th:first-child { background: var(--dv-surface-2); z-index: 2; }
.dv2 #dvPjTable .dv-table td, .dv2 #dvPjTable .dv-table th { white-space: nowrap; }
/* ---- quick actions + search ---- */
.dv2 .dv-actions { display: flex; flex-wrap: wrap; gap: var(--dv-sp-2); }
.dv2 .dv-topbar { display: flex; flex-wrap: wrap; gap: var(--dv-sp-3); align-items: center; margin-bottom: var(--dv-sp-2); }
.dv2 .dv-search { position: relative; flex: 1 1 320px; max-width: 560px; }
.dv2 .dv-search .dv-input { width: 100%; max-width: none; padding-inline-end: 64px; min-height: 40px; }
.dv2 .dv-kbd { position: absolute; inset-inline-end: 8px; top: 50%; transform: translateY(-50%); font: 600 11px var(--dv-font); color: var(--dv-muted);
  border: 1px solid var(--dv-border-2); border-radius: 4px; padding: 1px 6px; background: var(--dv-surface-2); }
.dv2 .dv-sr { position: absolute; inset-inline: 0; top: calc(100% + 4px); z-index: 50; background: var(--dv-surface); border: 1px solid var(--dv-border-2);
  border-radius: var(--dv-r-md); box-shadow: var(--dv-shadow-2); max-height: 60vh; overflow: auto; padding: 6px; }
.dv2 .dv-sr-h { font-size: var(--dv-fs-xs); color: var(--dv-muted); font-weight: var(--dv-fw-b); padding: 6px 8px 2px; text-transform: uppercase; }
.dv2 .dv-sr-item { display: flex; justify-content: space-between; gap: 12px; width: 100%; text-align: start; font: inherit; font-size: var(--dv-fs-sm); color: var(--dv-text);
  background: none; border: 0; border-radius: var(--dv-r-sm); padding: 7px 8px; cursor: pointer; min-height: 40px; align-items: center; }
.dv2 .dv-sr-item small { color: var(--dv-muted); white-space: nowrap; }
.dv2 .dv-sr-item:hover, .dv2 .dv-sr-item.on { background: var(--dv-accent-wash); }
.dv2 .dv-sr-more, .dv2 .dv-sr-none { color: var(--dv-muted); font-size: var(--dv-fs-xs); padding: 6px 8px; }
/* ---- KPI cards: complete rows, never narrower than ~230px ----
   The column count follows the width the cards actually get (container
   queries on .dv-kpis-c), not the screen, so the sidebar, a missing card or a
   big amount can't squeeze them. Gap 12px. Rule per number of cards n:
     n=6: 6 in a row if each gets ≥ 230px (≥ 1440px), else 3+3 (≥ 714px), else 2+2+2, else 1 per row
     n=5: 5 in a row if ≥ 1198px, else 3 + 2 (the 2 share the full row) from 714px, else 2+2+1 (last full)
     n=4: 4 in a row if ≥ 956px, else 2+2 (≥ 472px), else 1 per row
     n=3: 3 in a row if ≥ 714px, else 1 per row
     n=2: 2 in a row if ≥ 472px, else 1 per row;  n=1: full row
   Browsers without container queries fall back to auto-fill columns of ≥ 230px
   (rows may then be uneven, but nothing overflows). Phones keep the strip. */
.dv2 .dv-kpis-c { container-type: inline-size; }
.dv2 .dv-kpis { grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); }
@container (min-width: 0px) { .dv2 .dv-kpis { grid-template-columns: minmax(0, 1fr); } }
@container (min-width: 472px) {
  .dv2 .dv-kpis[data-n="6"], .dv2 .dv-kpis[data-n="5"], .dv2 .dv-kpis[data-n="4"], .dv2 .dv-kpis[data-n="2"] { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dv2 .dv-kpis[data-n="5"] > .dv-kpi:last-child { grid-column: 1 / -1; }
}
@container (min-width: 714px) {
  .dv2 .dv-kpis[data-n="6"], .dv2 .dv-kpis[data-n="3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dv2 .dv-kpis[data-n="5"] { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .dv2 .dv-kpis[data-n="5"] > .dv-kpi { grid-column: span 2; }
  .dv2 .dv-kpis[data-n="5"] > .dv-kpi:nth-child(n+4) { grid-column: span 3; }
}
@container (min-width: 956px) { .dv2 .dv-kpis[data-n="4"] { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
@container (min-width: 1198px) {
  .dv2 .dv-kpis[data-n="5"] { grid-template-columns: repeat(5, minmax(0, 1fr)); }
  .dv2 .dv-kpis[data-n="5"] > .dv-kpi, .dv2 .dv-kpis[data-n="5"] > .dv-kpi:nth-child(n+4) { grid-column: auto; }
}
@container (min-width: 1440px) { .dv2 .dv-kpis[data-n="6"] { grid-template-columns: repeat(6, minmax(0, 1fr)); } }
/* the number scales with its card, so a 9-digit amount + currency fits on one line;
   if it still can't, the currency drops to the next line instead of spilling out */
.dv2 .dv-kpi { container-type: inline-size; }
.dv2 .dv-kpi-value { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 4px; min-width: 0; }
.dv2 .dv-kpi-value .dv-cur { margin-inline-start: 0; }
@container (min-width: 0px) { .dv2 .dv-kpi-value { font-size: clamp(17px, 10.5cqi, 26px); } }
/* chart values: the number never breaks, the currency may wrap */
.dv2 .dv-hbar { grid-template-columns: minmax(80px, 34%) minmax(40px, 1fr) auto; }
.dv2 .dv-hbar-val { white-space: normal; max-width: 100%; }
/* charts: one column on narrow screens, two from 900px (an odd last chart spans the row), three from 1600px */
.dv2 .dv-charts { grid-template-columns: minmax(0, 1fr); align-items: stretch; }
@media (min-width: 900px) {
  .dv2 .dv-charts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dv2 .dv-charts > .dv-chart:last-child:nth-child(odd) { grid-column: 1 / -1; }
}
@media (min-width: 1600px) {
  .dv2 .dv-charts[data-n="3"] { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .dv2 .dv-charts[data-n="3"] > .dv-chart:last-child:nth-child(odd) { grid-column: auto; }
}
/* equal-height cards, "show as table" at the bottom of each */
.dv2 .dv-chart { display: flex; flex-direction: column; }
.dv2 .dv-chart > details.dv-data { margin-top: auto; padding-top: var(--dv-sp-3); }
/* ---- layout: shorter page, important parts higher ---- */
.dv2 .dv-jump { display: flex; flex-wrap: wrap; align-items: center; gap: 2px 6px; margin-top: 4px; color: var(--dv-muted); font-size: var(--dv-fs-xs); }
.dv2 .dv-jump-a { font: inherit; font-weight: var(--dv-fw-m); color: var(--dv-accent); background: none; border: 0; padding: 4px 2px; cursor: pointer; min-height: 40px; }
.dv2 .dv-jump-a:hover { text-decoration: underline; }
.dv2 .dv-alert { padding: 3px var(--dv-sp-3); min-height: 48px; }
.dv2 .dv-alert-title { font-size: 13px; line-height: 1.35; }
.dv2 .dv-alert-meta { font-size: var(--dv-fs-xs); line-height: 1.35; }
/* nothing is cut off: title and details wrap (names, amounts and days stay readable on touch screens) */
.dv2 .dv-alert-title, .dv2 .dv-alert-meta { overflow-wrap: anywhere; }
.dv2 .dv-alert-link { cursor: pointer; }
.dv2 .dv-alert-link:hover { background: var(--dv-surface-2); }
@media (min-width: 1100px) {
  .dv2 .dv-mid { display: grid; grid-template-columns: minmax(0, 38fr) minmax(0, 62fr); gap: var(--dv-sp-4); align-items: start; }
  .dv2 .dv-mid #dv-alerts .dv-alerts { max-height: 420px; overflow-y: auto; padding-inline-end: 2px; }
  .dv2 .dv-mid #dv-cash .dv-chart { height: 100%; }
  .dv2 .dv-mid:has(> .dv-section:only-child) { grid-template-columns: minmax(0, 1fr); }
  /* alerts alone: two columns of alerts inside, so the page does not grow */
  .dv2 .dv-mid > #dv-alerts:only-child .dv-alerts { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); max-height: none; overflow: visible; }
}
@media (max-width: 640px) {
  /* every card in one glance: two compact columns (title, number, comparison);
     the second detail line is left to the details window a tap away. An odd
     last card takes the whole row. The number already scales with its card. */
  .dv2 .dv-kpis, .dv2 .dv-kpis[data-n] { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: var(--dv-sp-2); }
  .dv2 .dv-kpis > .dv-kpi { min-height: 0; padding: 10px var(--dv-sp-3); gap: 2px; grid-column: auto; }
  .dv2 .dv-kpis > .dv-kpi:last-child:nth-child(odd) { grid-column: 1 / -1; }
  .dv2 .dv-kpis .dv-kpi-sub { display: none; }
  .dv2 .dv-kpis .dv-kpi-label { font-size: var(--dv-fs-xs); }
  .dv2 .dv-kpis .dv-kpi-foot { font-size: 10px; flex-wrap: nowrap; }
  .dv2 .dv-kpis .dv-kpi-foot > span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
  .dv2 .dv-jump-a { min-height: 40px; padding: 8px 4px; }
  /* quick actions: one row that scrolls sideways (snaps to each button) instead of three rows */
  .dv2 .dv-actions { flex-wrap: nowrap; overflow-x: auto; scroll-snap-type: x proximity; padding-bottom: 2px; width: 100%; }
  .dv2 .dv-actions .dv-btn { flex: none; scroll-snap-align: start; }
  .dv2 .dv-head { margin-bottom: var(--dv-sp-2); }
  .dv2 .dv-section { margin-top: var(--dv-sp-3); }
}
/* ============================================================
   DASHBOARD V2 — "widgets" look (owner's reference design)
   Gradient banner (Torch maroon → purple), folder tiles for the running
   projects, and every figure in a widget card with a header and ✕.
   Surfaces still come from the user's theme, so light themes stay light.
   ============================================================ */
.dv2 { --dv-r-w: 14px; --dv-brand-1: #1B378D; --dv-brand-2: #1F3E6B; --dv-brand-3: #1D6A95; }
.dv2 .dv-hero { position: relative; overflow: visible; border-radius: var(--dv-r-w); padding: 18px 20px; margin-bottom: var(--dv-sp-3);
  background: radial-gradient(120% 140% at 85% 0%, rgba(255,255,255,0.14) 0%, rgba(255,255,255,0) 45%),
              linear-gradient(115deg, var(--dv-brand-1) 0%, var(--dv-brand-2) 48%, var(--dv-brand-3) 100%);
  color: #fff; display: flex; align-items: center; gap: var(--dv-sp-3); flex-wrap: wrap; box-shadow: 0 10px 30px rgba(77, 20, 60, 0.28); }
.dv2 .dv-hero .dv-title { color: #fff; font-size: 22px; }
.dv2 .dv-hero-sub { color: rgba(255,255,255,0.82); font-size: var(--dv-fs-sm); margin-top: 2px; }
.dv2 .dv-hero .dv-jump-a { color: #fff; opacity: .9; }
.dv2 .dv-hero .dv-jump { color: rgba(255,255,255,0.6); }
.dv2 .dv-hero-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin-inline-start: auto; }
.dv2 .dv-hero .dv-btn { background: rgba(255,255,255,0.14); border-color: rgba(255,255,255,0.25); color: #fff; }
.dv2 .dv-hero .dv-btn:hover { background: rgba(255,255,255,0.24); }
.dv2 .dv-cust { position: relative; }
.dv2 .dv-cust > summary { list-style: none; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; min-height: 40px; padding: 7px 12px; border-radius: var(--dv-r-sm);
  background: rgba(255,255,255,0.92); color: var(--dv-brand-1); font-weight: var(--dv-fw-b); font-size: var(--dv-fs-sm); }
.dv2 .dv-cust > summary::-webkit-details-marker { display: none; }
.dv2 .dv-cust-panel { position: absolute; inset-inline-end: 0; top: calc(100% + 6px); z-index: 60; min-width: 240px; background: var(--dv-surface); color: var(--dv-text);
  border: 1px solid var(--dv-border-2); border-radius: var(--dv-r-md); box-shadow: var(--dv-shadow-2); padding: 8px; }
.dv2 .dv-cust-panel label { display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 4px 8px; border-radius: 6px; cursor: pointer; font-size: var(--dv-fs-sm); }
.dv2 .dv-cust-panel label:hover { background: var(--dv-surface-2); }
.dv2 .dv-cust-panel .dv-cust-h { font-size: var(--dv-fs-xs); color: var(--dv-muted); padding: 4px 8px; }

/* ---- project folders ---- */
.dv2 .dv-folder.dv-folder-one { flex: none; flex-direction: row; display: inline-flex; align-items: center; gap: 12px; min-width: 230px; min-height: 0; padding: 14px 18px; }
.dv2 .dv-folder.dv-folder-one .dv-folder-ico { width: 46px; height: 46px; font-size: 24px; color: #fff; background: linear-gradient(115deg, var(--dv-brand-1), var(--dv-brand-3)); }
.dv2 .dv-folders-all { flex-wrap: wrap; overflow: visible; }
.dv2 .dv-folders-all .dv-folder { flex: 1 1 200px; }
.dv2 .dv-folders { display: flex; gap: var(--dv-sp-3); overflow-x: auto; padding: 12px 2px 6px; scroll-snap-type: x proximity; }
.dv2 .dv-folder { flex: 0 0 210px; scroll-snap-align: start; position: relative; text-align: start; font: inherit; color: var(--dv-text); cursor: pointer;
  background: var(--dv-surface); border: 1px solid var(--dv-border); border-radius: 4px var(--dv-r-w) var(--dv-r-w) var(--dv-r-w); padding: 14px; min-height: 108px;
  box-shadow: var(--dv-shadow-1); transition: transform .15s, box-shadow .15s; display: flex; flex-direction: column; gap: 4px; }
.dv2[dir="rtl"] .dv-folder { border-radius: var(--dv-r-w) 4px var(--dv-r-w) var(--dv-r-w); }
.dv2 .dv-folder:hover { transform: translateY(-2px); box-shadow: var(--dv-shadow-2); }
.dv2 .dv-folder::before { content: ""; position: absolute; top: -7px; inset-inline-start: 0; width: 76px; height: 8px; border-radius: 6px 6px 0 0; background: var(--tab, var(--dv-s1)); }
.dv2 .dv-folder-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.dv2 .dv-folder-ico { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; font-size: 17px; background: color-mix(in srgb, var(--tab, var(--dv-s1)) 18%, transparent); }
.dv2 .dv-folder-name { font-weight: var(--dv-fw-b); font-size: var(--dv-fs-sm); line-height: 1.3; overflow-wrap: anywhere; }
.dv2 .dv-folder-meta { color: var(--dv-muted); font-size: var(--dv-fs-xs); }
.dv2 .dv-folder-pill { font-size: 10px; font-weight: var(--dv-fw-b); padding: 2px 8px; border-radius: 999px; background: color-mix(in srgb, var(--tab, var(--dv-s1)) 20%, transparent); color: var(--dv-text); white-space: nowrap; }

/* ---- widgets ---- */
.dv2 .dv-wgrid-c { container-type: inline-size; }
.dv2 .dv-wgrid { display: grid; gap: var(--dv-sp-3); grid-template-columns: minmax(0, 1fr); grid-auto-flow: row dense; }
@container (min-width: 472px) { .dv2 .dv-wgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); } .dv2 .dv-w.wide { grid-column: span 2; } }
@container (min-width: 760px) { .dv2 .dv-wgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); } }
@container (min-width: 1040px) { .dv2 .dv-wgrid { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.dv2 .dv-w { container-type: inline-size; position: relative; display: flex; flex-direction: column; min-width: 0; border-radius: var(--dv-r-w);
  background: linear-gradient(180deg, color-mix(in srgb, var(--dv-surface) 94%, #fff 6%), var(--dv-surface));
  border: 1px solid var(--dv-border); box-shadow: var(--dv-shadow-1); }
.dv2[data-mode="light"] .dv-w { background: var(--dv-surface); }
.dv2 .dv-w-h { display: flex; align-items: center; gap: 8px; padding: 10px 10px 0 14px; }
.dv2[dir="rtl"] .dv-w-h { padding: 10px 14px 0 10px; }
.dv2 .dv-w-ico { width: 26px; height: 26px; border-radius: 8px; display: grid; place-items: center; font-size: 14px; background: var(--dv-surface-2); flex: none; }
.dv2 .dv-w-t { font-size: var(--dv-fs-sm); font-weight: var(--dv-fw-b); color: var(--dv-text-2); flex: 1; min-width: 0; }
.dv2 .dv-w-x { font: inherit; width: 32px; height: 32px; border-radius: 8px; border: 0; background: transparent; color: var(--dv-muted); cursor: pointer; flex: none; font-size: 16px; line-height: 1; }
.dv2 .dv-w-x:hover { background: var(--dv-surface-2); color: var(--dv-text); }
.dv2 .dv-w-b { padding: 8px 14px 14px; display: flex; flex-direction: column; gap: 6px; flex: 1; min-width: 0; }
.dv2 .dv-w-b.link { cursor: pointer; border-radius: 0 0 var(--dv-r-w) var(--dv-r-w); }
.dv2 .dv-w-b.link:hover { background: color-mix(in srgb, var(--dv-accent) 6%, transparent); }
.dv2 .dv-w-b.link:focus-visible { outline: 2px solid var(--dv-accent); outline-offset: -2px; }
.dv2 .dv-w-big { display: flex; flex-wrap: wrap; align-items: baseline; column-gap: 6px; font-weight: 800; line-height: 1.1; letter-spacing: -0.01em; color: var(--dv-text); }
@container (min-width: 0px) { .dv2 .dv-w-big { font-size: clamp(18px, 10cqi, 30px); } }
.dv2 .dv-w.wide .dv-w-big { font-size: clamp(20px, 6cqi, 32px); }
.dv2 .dv-w-big .dv-cur { font-size: 12px; font-weight: 600; color: var(--dv-muted); margin: 0; }
.dv2 .dv-w-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: var(--dv-fs-xs); color: var(--dv-muted); }
.dv2 .dv-w-sub { font-size: var(--dv-fs-sm); color: var(--dv-text-2); }
.dv2 .dv-pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 999px; font-weight: 700; font-size: 11px; white-space: nowrap; }
.dv2 .dv-pill.up { background: color-mix(in srgb, var(--dv-good) 18%, transparent); color: var(--dv-up); }
.dv2 .dv-pill.down { background: color-mix(in srgb, var(--dv-crit) 16%, transparent); color: var(--dv-down); }
.dv2 .dv-pill.flat { background: var(--dv-surface-2); color: var(--dv-muted); }
.dv2 .dv-tiles { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; margin-top: 4px; }
.dv2 .dv-tile { border-radius: 10px; padding: 8px 10px; min-width: 0; }
.dv2 .dv-tile b { display: block; font-size: 17px; line-height: 1.2; }
.dv2 .dv-tile span { font-size: 11px; color: var(--dv-text-2); }
.dv2 .dv-tile.t1 { background: color-mix(in srgb, var(--dv-s1) 16%, transparent); }
.dv2 .dv-tile.t1 b { color: var(--dv-s1); }
.dv2 .dv-tile.t2 { background: color-mix(in srgb, var(--dv-s4) 18%, transparent); }
.dv2 .dv-tile.t2 b { color: var(--dv-s4); }
.dv2[data-mode="light"] .dv-tile.t2 b { color: #8a5d00; }
.dv2 .dv-spark { width: 100%; height: auto; display: block; margin-top: 4px; }
.dv2 .dv-spark .ln { fill: none; stroke: var(--dv-s3); stroke-width: 2; stroke-linejoin: round; stroke-linecap: round; }
.dv2 .dv-spark .ar { fill: var(--dv-s3); opacity: .14; }
.dv2 .dv-spark .pt { fill: var(--dv-s3); stroke: var(--dv-surface); stroke-width: 2; }
.dv2 .dv-spark .bar { fill: var(--dv-s7); }
.dv2 .dv-spark text { fill: var(--dv-muted); font-size: 10px; font-family: var(--dv-font); }
.dv2 .dv-spark .gl { stroke: var(--dv-grid); stroke-width: 1; }
.dv2 .dv-events { display: flex; flex-direction: column; gap: 8px; }
.dv2 .dv-ev { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 10px; background: var(--dv-surface-2); cursor: pointer; }
.dv2 .dv-ev:hover { background: color-mix(in srgb, var(--dv-accent) 10%, var(--dv-surface-2)); }
.dv2 .dv-ev-d { flex: none; width: 44px; text-align: center; border-radius: 8px; padding: 3px 0; background: var(--dv-surface); border: 1px solid var(--dv-border-2); line-height: 1.1; }
.dv2 .dv-ev-d b { display: block; font-size: 16px; } .dv2 .dv-ev-d small { font-size: 10px; color: var(--dv-muted); }
.dv2 .dv-ev-t { flex: 1; min-width: 0; font-size: var(--dv-fs-sm); overflow-wrap: anywhere; }
.dv2 .dv-ev-t small { display: block; color: var(--dv-muted); font-size: 11px; }
/* the rest of the page in the same card language */
.dv2 .dv-chart, .dv2 .dv-panel, .dv2 .dv-table-wrap { border-radius: var(--dv-r-w); }
@media (max-width: 640px) {
  .dv2 .dv-hero { padding: 14px; } .dv2 .dv-hero .dv-title { font-size: 19px; }
  .dv2 .dv-hero-actions { margin-inline-start: 0; width: 100%; }
  .dv2 .dv-folder { flex-basis: 170px; min-height: 96px; }
  .dv2 .dv-wgrid-c .dv-wgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .dv2 .dv-w.wide, .dv2 .dv-w.list { grid-column: 1 / -1; }
  .dv2 .dv-w-h { padding: 8px 6px 0 10px; } .dv2[dir="rtl"] .dv-w-h { padding: 8px 10px 0 6px; }
  .dv2 .dv-w-b { padding: 6px 10px 10px; }
  .dv2 .dv-w:not(.wide):not(.list) .dv-w-sub { display: none; }
}

/* ============ HEADER + PAGE BAR (HDR1, OM 2026-10-10) ============
   The header keeps what is the same on every page: title, search, bell,
   save state, the user menu. The period and export sit in the page bar
   under it, next to the open tabs. */
.header { gap: 16px; margin-bottom: 14px; }
.header > div:first-child { min-width: 0; flex: 1 1 auto; }
.header-actions { flex: 0 0 auto; }
.page-title { font-size: 21px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.page-subtitle { font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hdr-sync { gap: 6px; padding: 0 9px; width: auto; }
.hdr-sync .saving-dot { display: inline-block !important; }
.hdr-sync-lbl { display: none; font-size: 11.5px; font-weight: 600; }
.hdr-sync.warn { border-color: #f87171; color: #f87171; }
.hdr-sync.warn .hdr-sync-lbl { display: inline; }
.page-strip { display: flex; align-items: flex-end; gap: 8px; margin-bottom: 12px; }
.page-strip > #tabBar { flex: 1 1 auto; min-width: 0; }
.page-bar { display: flex; align-items: center; gap: 6px; flex: 0 0 auto; margin-inline-start: auto; }
.page-bar[hidden] { display: none; }
.pb-item { position: relative; }
.pb-btn { display: inline-flex; align-items: center; gap: 4px; height: 32px; padding: 0 11px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); font-size: 12.5px; font-weight: 600; cursor: pointer; font-family: inherit; white-space: nowrap; }
.pb-btn:hover, .pb-item.open .pb-btn { border-color: var(--accent, #1B378D); }
.pb-caret { opacity: .6; font-size: 10px; }
.pb-pop { position: absolute; top: calc(100% + 6px); right: 0; z-index: 2600; min-width: 270px; padding: 10px; background: var(--surface, #1c1424); color: var(--text); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 14px 34px rgba(0,0,0,.35); display: flex; flex-direction: column; gap: 8px; text-align: start; }
html[dir="rtl"] .pb-pop { right: auto; left: 0; }
.pb-pop[hidden] { display: none; }
.pb-pop-h { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); }
.pb-pop .year-picker { width: 100%; }
.pb-pop .date-filter { width: 100%; box-sizing: border-box; justify-content: space-between; }
.pb-pop .date-filter-input { flex: 1; min-width: 0; }
.pb-link { align-self: flex-start; background: transparent; border: 0; color: var(--accent, #1B378D); font-size: 12px; font-weight: 600; cursor: pointer; padding: 2px 0; font-family: inherit; }
.pb-menu { padding: 6px; gap: 2px; min-width: 280px; }
.pb-menu button { display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%; text-align: start; background: transparent; border: 0; color: var(--text); padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; font-weight: 600; font-family: inherit; }
.pb-menu button small { color: var(--text-muted); font-size: 11px; font-weight: 400; }
.pb-menu button:hover { background: var(--surface-2, rgba(127,127,127,.15)); }
.pb-menu button[disabled] { opacity: .45; cursor: not-allowed; }
.pb-menu .pb-om { border-top: 1px solid var(--border); border-radius: 0 0 7px 7px; margin-top: 2px; }
/* user menu */
.uc-btn { display: inline-flex; align-items: center; gap: 7px; height: 36px; padding: 0 10px 0 4px; border-radius: 20px; background: var(--surface-2); border: 1px solid var(--border); color: var(--text); cursor: pointer; font-size: 12.5px; font-weight: 700; font-family: inherit; }
.uc-av { display: inline-flex; align-items: center; justify-content: center; width: 28px; height: 28px; border-radius: 50%; color: #fff; font-size: 11px; font-weight: 700; flex-shrink: 0; }
.uc-menu { position: absolute; top: calc(100% + 6px); right: 0; z-index: 2600; width: 250px; padding: 6px; background: var(--surface, #1c1424); color: var(--text); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 14px 34px rgba(0,0,0,.35); text-align: start; }
html[dir="rtl"] .uc-menu { right: auto; left: 0; }
.uc-menu[hidden] { display: none; }
.uc-head { display: flex; gap: 10px; align-items: center; padding: 8px 8px 10px; border-bottom: 1px solid var(--border); margin-bottom: 4px; }
.uc-head > span:last-child { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.uc-row { padding: 6px 8px; }
.uc-item { display: block; width: 100%; text-align: start; background: transparent; border: 0; color: var(--text); padding: 8px 10px; border-radius: 7px; cursor: pointer; font-size: 13px; font-family: inherit; }
.uc-item:hover { background: var(--surface-2, rgba(127,127,127,.15)); }
.uc-out { color: #f87171; border-top: 1px solid var(--border); border-radius: 0 0 7px 7px; margin-top: 4px; }
@media (min-width: 769px) {
  html[dir="rtl"] .header-actions { flex-wrap: nowrap; }
  .gs-wrap { flex-basis: 300px; }
}
@media (max-width: 768px) {
  .page-strip { flex-wrap: wrap; align-items: center; margin-bottom: 10px; }
  .page-strip > #tabBar { flex-basis: 100%; }
  .uc-name { display: none; }
  .uc-btn { padding: 0 8px 0 4px; }
  .hdr-sync { height: 34px; }
  .header-actions { justify-content: flex-end; }
}

/* ============ LOOK (HDR2, OM 2026-10-10): one calm top bar, underlined tabs,
   the page title under them. One accent colour, icons without frames,
   every control the same height. ============ */
.header { padding-bottom: 12px; margin-bottom: 0; border-bottom: 1px solid var(--border); min-height: 40px; }
.hdr-left { display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 auto; }
.hdr-crumb { display: flex; align-items: center; gap: 7px; min-width: 0; font-size: 13px; color: var(--text-muted); white-space: nowrap; overflow: hidden; }
.hdr-crumb .hc-sep { opacity: .5; }
.hdr-crumb .hc-page { color: var(--text); font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.header-actions { gap: 4px; }
.hdr-ic { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; padding: 0; border: 0; border-radius: 8px; background: transparent; color: var(--text); font-size: 16px; cursor: pointer; font-family: inherit; }
.hdr-ic:hover { background: var(--surface-2); }
#notifBellCount { top: 1px !important; right: -1px !important; }
.hdr-sep { width: 1px; height: 22px; background: var(--border); margin: 0 6px; }
.uc-btn { background: transparent; border: 0; padding: 0 4px; gap: 4px; }
.uc-btn:hover { background: var(--surface-2); }
.uc-name { display: none; }
.uc-av { width: 32px; height: 32px; }
.gs-wrap input { height: 36px; }
/* tabs */
.page-strip { border-bottom: 1px solid var(--border); margin: 0; align-items: flex-end; }
.page-bar { align-self: center; padding: 4px 0; }
.tb-row { display: flex; align-items: flex-end; gap: 2px; overflow-x: auto; min-height: 42px; }
.tb-tab { display: flex; align-items: center; gap: 6px; white-space: nowrap; cursor: pointer; padding: 10px 12px 9px; margin-bottom: -1px; font-size: 13px; color: var(--text-muted); border-bottom: 2px solid transparent; border-radius: 6px 6px 0 0; }
.tb-tab:hover { color: var(--text); background: var(--surface-2); }
.tb-tab.on { color: var(--text); font-weight: 600; border-bottom-color: var(--accent, #1B378D); }
.tb-ic { opacity: 0; font-size: 12px; line-height: 1; padding: 3px 4px; border-radius: 4px; color: var(--text-muted); }
.tb-tab:hover .tb-ic, .tb-tab.on .tb-ic { opacity: .65; }
/* refresh only on the open tab; close shows on hover */
.tb-tab:not(.on) .tb-rf { display: none; }
.tb-tab { padding-right: 8px; }
html[dir="rtl"] .tb-tab { padding-right: 12px; padding-left: 8px; }
.tb-ic:hover { opacity: 1 !important; background: rgba(127,127,127,.22); color: var(--text); }
@media (hover: none) { .tb-ic { opacity: .5; } }
.tb-fill { flex: 1; min-width: 8px; }
.tb-tool { align-self: center; width: 30px; height: 28px; border: 0; border-radius: 6px; background: transparent; color: var(--text-muted); font-size: 12px; cursor: pointer; letter-spacing: -2px; }
.tb-tool:hover { background: var(--surface-2); color: var(--text); }
.pb-btn { height: 30px; background: transparent; }
.pb-btn:hover, .pb-item.open .pb-btn { background: var(--surface-2); }
/* page title, under the tabs */
.page-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; margin: 18px 0 14px; min-width: 0; }
.page-head:has(#pageTitle:empty) { display: none; }
.page-head .page-title { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: -.2px; color: var(--text); white-space: normal; }
html[data-brand="torch"] .page-head .page-title { background: none; -webkit-text-fill-color: currentColor; color: var(--text); }
.page-head .page-subtitle { margin: 0; font-size: 13px; color: var(--text-muted); white-space: normal; }
@media (max-width: 768px) {
  .header { flex-direction: row !important; align-items: center !important; gap: 6px !important; padding-bottom: 8px; }
  .hdr-crumb { display: none; }
  .header-actions { flex-wrap: nowrap !important; gap: 2px; }
  .hdr-ic { width: 34px; height: 34px; }
  .page-head { margin: 12px 0 10px; }
  .page-head .page-subtitle { display: none; }
  .page-strip { border-bottom: 0; }
  .tb-row { border-bottom: 1px solid var(--border); }
}

.sidebar .nav-section.nav-gone { display: none !important; }

/* ============ GLOBAL SEARCH (NV11) ============ */
.gs-wrap { position: relative; flex: 0 1 260px; min-width: 180px; }
.gs-wrap input { width: 100%; box-sizing: border-box; padding: 8px 12px; border-radius: 8px; border: 1px solid var(--border); background: var(--input-bg, var(--surface-2)); color: var(--text); font-size: 13px; }
.gs-wrap input:focus { outline: 2px solid var(--accent, #1B378D); outline-offset: 0; }
.gs-close { display: none; }
.gs-res { position: absolute; top: calc(100% + 4px); left: 0; width: min(480px, 92vw); max-height: 70vh; overflow: auto; background: var(--surface, #1c1424); color: var(--text); border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 14px 34px rgba(0,0,0,.35); z-index: 3000; padding: 6px; text-align: start; }
html[dir="rtl"] .gs-res { left: auto; right: 0; }
.gs-h { font-size: 11px; font-weight: 800; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); padding: 8px 8px 4px; }
.gs-n { font-weight: 600; opacity: .7; }
.gs-item { display: flex; flex-direction: column; align-items: flex-start; gap: 1px; width: 100%; text-align: start; background: transparent; border: 0; color: var(--text); padding: 7px 10px; border-radius: 6px; cursor: pointer; font-size: 13px; }
.gs-item small { color: var(--text-muted); font-size: 11px; }
.gs-item.on, .gs-item:hover { background: var(--surface-2, rgba(127,127,127,.15)); }
.gs-more, .gs-item.gs-more { font-size: 11.5px; color: var(--accent, #1B378D); padding: 3px 10px 6px; }
div.gs-more { color: var(--text-muted); }
.gs-none { padding: 14px; color: var(--text-muted); font-size: 13px; }
.gs-icon { display: none; }
@media (max-width: 768px) {
  .gs-wrap { display: none; }
  .gs-icon { display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; min-width: 38px; min-height: 38px; background: transparent; border: 1px solid var(--border); color: var(--text); border-radius: 8px; font-size: 16px; cursor: pointer; }
  body.gs-sheet .gs-wrap { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; position: fixed; top: 0; left: 0; right: 0; max-width: none; min-width: 0; z-index: 3500; background: var(--bg, #120c18); padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); box-shadow: 0 8px 24px rgba(0,0,0,.4); }
  body.gs-sheet .gs-wrap input { flex: 1; font-size: 16px; }
  body.gs-sheet .gs-close { display: inline-flex; min-width: 38px; min-height: 38px; align-items: center; justify-content: center; background: transparent; border: 1px solid var(--border); color: var(--text); border-radius: 8px; cursor: pointer; }
  body.gs-sheet .gs-res { position: static; width: 100%; flex-basis: 100%; max-height: calc(100vh - 80px); box-shadow: none; }
}

/* ============ TORCH BRAND (themes torch / torch_dark) ============
   deep red -> purple, as on the Torch website. Only colours; no layout changes. */
html[data-brand="torch"] { --torch-grad: linear-gradient(115deg, #1B378D 0%, #1F3E6B 48%, #1D6A95 100%); --torch-grad-v: linear-gradient(180deg, #1B378D 0%, #1F3E6B 50%, #1D6A95 100%); }
html[data-brand="torch"] body::before { content: ""; position: fixed; top: 0; left: 0; right: 0; height: calc(var(--sat, 0px) + 4px); background: var(--torch-grad); z-index: 100000; pointer-events: none; }
html[data-brand="torch"] .sidebar { background: var(--torch-grad-v); border-right-color: transparent; color: #fff; }
html[data-brand="torch"] .sidebar .logo { border-bottom-color: rgba(255,255,255,0.16); }
html[data-brand="torch"] .sidebar .logo h1 { background: none; -webkit-text-fill-color: #fff; color: #fff; }
html[data-brand="torch"] .sidebar .logo p { color: rgba(255,255,255,0.72); }
html[data-brand="torch"] .sidebar .nav-section { border-bottom-color: rgba(255,255,255,0.12); }
html[data-brand="torch"] .sidebar .nav-title, html[data-brand="torch"] .sidebar .nav-group-label { color: rgba(255,255,255,0.7); }
html[data-brand="torch"] .sidebar .nav-title:hover { background: rgba(255,255,255,0.08); }
html[data-brand="torch"] .sidebar .nav-item { color: rgba(255,255,255,0.84); }
html[data-brand="torch"] .sidebar .nav-item:hover { background: rgba(255,255,255,0.12); color: #fff; }
html[data-brand="torch"] .sidebar .nav-item.active { background: rgba(255,255,255,0.22); color: #fff; box-shadow: inset 3px 0 0 #fff; }
html[data-brand="torch"] .sidebar .nav-item .badge { background: rgba(255,255,255,0.16); color: #fff; }
html[data-brand="torch"] .sidebar .badge-desc { color: rgba(255,255,255,0.62); }
html[data-brand="torch"] .sidebar input { background: rgba(255,255,255,0.14) !important; border-color: rgba(255,255,255,0.28) !important; color: #fff !important; }
html[data-brand="torch"] .sidebar input::placeholder { color: rgba(255,255,255,0.7); }
/* =====================================================================
   DESIGN SYSTEM (WS4, OM 2026-10-11) — one concept for EVERY theme.
   Layout, components and behaviour are the same in all themes; a theme only
   supplies colours (its --bg / --surface / --text / --accent ... variables).
   The --ws-* tokens below are derived from those, and TSD Light pins exact
   values. The Torch themes keep their brand gradient on the sidebar only.
   ===================================================================== */
html {
  --ws-brand: var(--accent); --ws-on-brand: #fff;
  --ws-brand-hover: color-mix(in srgb, var(--accent) 86%, #000);
  --ws-brand-soft: color-mix(in srgb, var(--accent) 10%, var(--surface));
  --ws-brand-line: color-mix(in srgb, var(--accent) 45%, transparent);
  --ws-page: var(--bg); --ws-panel: var(--surface); --ws-panel-2: var(--surface-2);
  --ws-head: var(--surface-2); --ws-head-text: var(--text-muted);
  --ws-row-alt: color-mix(in srgb, var(--surface-2) 40%, var(--surface));
  --ws-row-hover: var(--surface-2);
  --ws-row-sel: color-mix(in srgb, var(--accent) 13%, var(--surface));
  --ws-text: var(--text); --ws-text-2: var(--text-muted); --ws-text-3: var(--text-dim);
  --ws-line: var(--border); --ws-line-2: var(--border-light); --ws-line-soft: color-mix(in srgb, var(--border) 55%, var(--surface));
  --ws-ok: var(--success); --ws-warn: var(--warning); --ws-bad: var(--danger);
  --ws-warn-soft: color-mix(in srgb, var(--warning) 14%, var(--surface)); --ws-warn-line: color-mix(in srgb, var(--warning) 55%, transparent);
  --ws-input: var(--input-bg, var(--surface));
  --ws-shadow: var(--shadow); --ws-shadow-lg: var(--shadow-lg);
  --ws-font: 13px; --ws-font-sm: 12px; --ws-font-xs: 11px;
  --ws-sp-1: 4px; --ws-sp-2: 8px; --ws-sp-3: 12px; --ws-sp-4: 16px;
  --ws-radius: 8px; --ws-radius-sm: 6px; --ws-ctl-h: 32px; --ws-btn-h: 28px;
}
/* TSD Light: exact brand values on a neutral grey page */
html[data-ws="1"] {
  --ws-brand: #1B378D; --ws-brand-hover: #162E76; --ws-brand-soft: #EEF1F8; --ws-brand-line: rgba(27,55,141,0.35);
  --ws-page: #F3F4F6; --ws-panel: #FFFFFF; --ws-panel-2: #F9FAFB; --ws-head: #F9FAFB; --ws-head-text: #374151;
  --ws-row-alt: #FAFAFB; --ws-row-hover: #F3F4F6; --ws-row-sel: #EEF1F8;
  --ws-text: #1F2937; --ws-text-2: #4B5563; --ws-text-3: #6B7280;
  --ws-line: #E5E7EB; --ws-line-2: #D1D5DB; --ws-line-soft: #EEF0F3;
  --ws-warn-soft: #FFFBEB; --ws-warn-line: #FCD34D; --ws-input: #FFFFFF;
}
body { font-size: var(--ws-font); }
html:not([data-dark]) .form-input[type="date"], html:not([data-dark]) .date-filter-input { color-scheme: light; }

/* --- panels --- */
.card, .table-container { background: var(--ws-panel); border: 1px solid var(--ws-line); border-radius: 10px; box-shadow: var(--ws-shadow); }
.card:hover { border-color: var(--ws-line-2); }
.page-head .page-title { color: var(--ws-text); }
.page-title { -webkit-text-fill-color: currentColor; }

/* --- tables: quiet header, zebra rows, selected row, totals --- */
thead { background: var(--ws-head); }
th { background: var(--ws-head); color: var(--ws-head-text); font-weight: 600; font-size: 11.5px; letter-spacing: .4px; border-bottom: 1px solid var(--ws-line); }
th * { color: inherit; }
td { color: var(--ws-text); border-bottom-color: var(--ws-line-soft); }
tbody tr:nth-child(even):not(.totals-row) > td { background: var(--ws-row-alt); }
tbody tr:hover > td { background: var(--ws-row-hover); }
table tbody tr:has(> td input[type="checkbox"]:checked):not(.totals-row) > td { background: var(--ws-row-sel); }
tbody tr:has(> td input[type="checkbox"]:checked) > td:first-child { box-shadow: inset 3px 0 0 var(--ws-brand); }
tbody tr.totals-row, tbody tr.totals-row > td { background: var(--ws-panel-2) !important; color: var(--ws-brand); border-top: 2px solid var(--ws-line) !important; }
tbody tr.totals-row > td { color: var(--ws-brand) !important; }
td.amount, th.amount { font-variant-numeric: tabular-nums; }
th.th-sorted { background: var(--ws-brand-soft) !important; color: var(--ws-brand) !important; box-shadow: inset 0 -2px 0 var(--ws-brand); }
._tsdTopScroll::-webkit-scrollbar-thumb { background: color-mix(in srgb, var(--ws-text-3) 55%, transparent); }

/* --- buttons and fields --- */
.btn:not(.btn-primary):not(.btn-success):not(.btn-danger) { border-color: var(--ws-line-2); }
.btn:not(.btn-primary):not(.btn-success):not(.btn-danger):hover { background: var(--ws-row-hover); border-color: var(--ws-text-3); }
.btn-primary, html[data-brand="torch"] .btn-primary { background: var(--ws-brand); border-color: var(--ws-brand); color: var(--ws-on-brand); }
.btn-primary:hover, html[data-brand="torch"] .btn-primary:hover { background: var(--ws-brand-hover); border-color: var(--ws-brand-hover); filter: none; }
.btn-success { background: var(--ws-ok); border-color: var(--ws-ok); color: #fff; }
.form-input, .form-select, .form-textarea, .search-box input, .gs-wrap input, .main input[type="text"], .main input[type="search"], .main select { background: var(--ws-input); border-color: var(--ws-line-2); color: var(--ws-text); }
.form-input:focus, .form-select:focus, .form-textarea:focus, .search-box input:focus { border-color: var(--ws-brand); box-shadow: 0 0 0 3px var(--ws-brand-soft); }
.form-input[readonly] { background: var(--ws-panel-2); color: var(--ws-text-3); }
.form-label { color: var(--ws-text-2); font-weight: 600; }

/* --- dialogs and menus --- */
.modal { background: var(--ws-panel); border-color: var(--ws-line); border-top: 3px solid var(--ws-brand); }
.modal-header { background: var(--ws-panel); border-bottom: 1px solid var(--ws-line); }
.modal-header .modal-title { color: var(--ws-text); }
.modal-header .modal-close { color: var(--ws-text-3); }
.modal-footer { background: var(--ws-panel-2); }
.pb-pop, .uc-menu, .gs-res { background: var(--ws-panel); border-color: var(--ws-line); box-shadow: var(--ws-shadow-lg); }
.tb-tab.on { color: var(--ws-brand); border-bottom-color: var(--ws-brand); }
.pd-tabs .btn:not(.btn-primary) { background: var(--ws-panel); color: var(--ws-text-2); border-color: var(--ws-line); }
.pd-tabs .btn.btn-primary { background: var(--ws-brand); color: var(--ws-on-brand); border-color: var(--ws-brand); }
.pd-tabs .pd-all:not(.btn-primary) { background: var(--ws-panel) !important; color: var(--ws-brand) !important; }

/* --- toolbar above a table: search on the left, actions grouped on the right --- */
.table-toolbar { background: var(--ws-panel); border-bottom: 1px solid var(--ws-line); justify-content: flex-start; gap: var(--ws-sp-2); padding: 10px 14px; }
.table-toolbar > .search-box { flex: 1 1 260px; max-width: 380px; margin-inline-end: auto; }
.table-toolbar .search-box input { height: var(--ws-ctl-h); }
.table-toolbar .btn { height: var(--ws-ctl-h); padding: 0 14px; font-size: var(--ws-font); border-radius: var(--ws-radius-sm); }
.table-toolbar .btn:not(.btn-primary) { background: var(--ws-panel) !important; color: var(--ws-text) !important; border: 1px solid var(--ws-line-2) !important; }
.table-toolbar .btn:not(.btn-primary):hover { background: var(--ws-row-hover) !important; border-color: var(--ws-text-3) !important; }
.table-toolbar .btn.ws-icon-btn { width: var(--ws-ctl-h); padding: 0; justify-content: center; color: var(--ws-text-2) !important; }
@media (max-width: 768px) {
  .table-toolbar > .search-box { flex: none; max-width: none; margin: 0; }
  .table-toolbar .btn { justify-content: center; }
}

/* --- page header strip with KPI cards --- */
.ws-head { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--ws-line); background: var(--ws-panel); }
.ws-head-t { font-size: 14px; font-weight: 700; }
.ws-head-s { font-size: 11.5px; color: var(--ws-text-2); margin-top: 2px; }
.ws-kpis { display: flex; gap: 8px; flex-wrap: wrap; }
.ws-kpi { min-width: 108px; padding: 7px 12px; border: 1px solid var(--ws-line); border-left: 3px solid var(--ws-line-2); border-radius: 8px; background: var(--ws-panel-2); }
html[dir="rtl"] .ws-kpi { border-left-width: 1px; border-right: 3px solid var(--ws-line-2); }
.ws-kpi-l { font-size: 10.5px; font-weight: 600; letter-spacing: .4px; text-transform: uppercase; color: var(--ws-text-2); }
.ws-kpi-v { font-size: 17px; font-weight: 700; line-height: 1.25; font-variant-numeric: tabular-nums; white-space: nowrap; color: var(--ws-text); }
.ws-kpi-v small { font-size: 11px; font-weight: 600; color: var(--ws-text-2); margin-left: 3px; }
.ws-kpi.t-warn { border-inline-start-color: var(--ws-warn); } .ws-kpi.t-warn .ws-kpi-v { color: var(--ws-warn); }
.ws-kpi.t-ok { border-inline-start-color: var(--ws-ok); } .ws-kpi.t-ok .ws-kpi-v { color: var(--ws-ok); }
.ws-kpi.t-brand { border-inline-start-color: var(--ws-brand); } .ws-kpi.t-brand .ws-kpi-v { color: var(--ws-brand); }
.ws-kpi.t-bad { border-inline-start-color: var(--ws-bad); } .ws-kpi.t-bad .ws-kpi-v { color: var(--ws-bad); }
/* project page: one calm panel with a brand top edge; figure cards on the panel colour */
.pd-head { background: var(--ws-panel) !important; border: 1px solid var(--ws-line) !important; border-top: 3px solid var(--ws-brand) !important; box-shadow: var(--ws-shadow); }
.pd-kpis > div { background: var(--ws-panel) !important; border-top-color: var(--ws-line) !important; border-right-color: var(--ws-line) !important; border-bottom-color: var(--ws-line) !important; box-shadow: var(--ws-shadow); }
.pd-kpis > div > div:first-child { font-weight: 600; letter-spacing: .4px; }
.table-toolbar > div:not(.search-box) { display: flex; gap: var(--ws-sp-2); align-items: center; flex-wrap: wrap; }
.table-toolbar code { height: var(--ws-ctl-h); display: inline-flex; align-items: center; box-sizing: border-box; }

/* --- column helpers (tables that opt in with class ws-table) --- */
.clamp2 { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
table.ws-table { font-size: var(--ws-font); }
table.ws-table th, table.ws-table td { padding: 8px 10px; vertical-align: middle; }
table.ws-table th { white-space: nowrap; }
table.ws-table .col-check { width: 36px; min-width: 36px; max-width: 36px; padding-left: 6px; padding-right: 6px; text-align: center; }
table.ws-table .col-code { min-width: 140px; white-space: nowrap; }
table.ws-table .col-code:not(.sticky-l) { min-width: 118px; }
table.ws-table td.col-code.sticky-l { white-space: normal; }
table.ws-table td.col-code.sticky-l > span:first-child { white-space: nowrap; }
table.ws-table .col-date { min-width: 92px; white-space: nowrap; }
table.ws-table .col-name { min-width: 200px; max-width: 320px; }
table.ws-table .col-text { min-width: 120px; max-width: 220px; }
table.ws-table th.col-name, table.ws-table th.col-text { white-space: nowrap; }
table.ws-table .col-num { min-width: 100px; text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
table.ws-table .col-act { white-space: nowrap; }
table.ws-table td.col-num { font-family: 'SF Mono', Consolas, monospace; font-weight: 600; }
/* sticky identifying columns + actions while scrolling sideways (follows the reading direction) */
table.ws-sticky td.sticky-l, table.ws-sticky th.sticky-l, table.ws-sticky td.sticky-r, table.ws-sticky th.sticky-r { position: sticky; z-index: 2; background: var(--ws-panel); }
table.ws-sticky th.sticky-l, table.ws-sticky th.sticky-r { z-index: 4; background: var(--ws-head); }
/* on a narrow screen the pinned Actions slide UNDER the pinned code / name, like every other column */
table.ws-sticky td.sticky-l { z-index: 3; } table.ws-sticky th.sticky-l { z-index: 5; }
/* phones: the actions column is wider than the screen - it stops being pinned (it scrolls in at the row's end)
   and the list scrolls inside its box so the column names stay at the top while scrolling down */
@media (max-width: 768px) {
  table.ws-sticky td.sticky-r, table.ws-sticky th.sticky-r { position: static; box-shadow: none; }
  .table-wrap:has(> table.ws-table), .table-container:has(> table.ws-table) { max-height: calc(100dvh - 120px); overflow: auto; overscroll-behavior: contain; }
  table.ws-table > thead th { position: sticky; top: 0; z-index: 4; background: var(--ws-head); }
  table.ws-table > thead th.sticky-l { z-index: 6; }
}
table.ws-sticky .sticky-l.l0 { inset-inline-start: 0; } table.ws-sticky .sticky-l.l1 { inset-inline-start: 36px; }
table.ws-sticky .sticky-l.l-last { box-shadow: 1px 0 0 var(--ws-line), 6px 0 8px -6px rgba(0,0,0,.25); }
table.ws-sticky .sticky-r { inset-inline-end: 0; box-shadow: -1px 0 0 var(--ws-line), -6px 0 8px -6px rgba(0,0,0,.25); }
html[dir="rtl"] table.ws-sticky .sticky-r { box-shadow: 1px 0 0 var(--ws-line), 6px 0 8px -6px rgba(0,0,0,.25); }
html[dir="rtl"] table.ws-sticky .sticky-l.l-last { box-shadow: -1px 0 0 var(--ws-line), -6px 0 8px -6px rgba(0,0,0,.25); }
table.ws-sticky tbody tr:nth-child(even):not(.totals-row) > td.sticky-l, table.ws-sticky tbody tr:nth-child(even):not(.totals-row) > td.sticky-r { background: var(--ws-row-alt); }
table.ws-sticky tbody tr:hover > td.sticky-l, table.ws-sticky tbody tr:hover > td.sticky-r { background: var(--ws-row-hover); }
table.ws-sticky tbody tr:has(> td input[type="checkbox"]:checked):not(.totals-row) > td.sticky-l, table.ws-sticky tbody tr:has(> td input[type="checkbox"]:checked):not(.totals-row) > td.sticky-r { background: var(--ws-row-sel); }

/* --- row actions: a few visible, the rest in a ⋯ menu --- */
.ws-act { display: inline-flex; align-items: center; gap: 4px; flex-wrap: nowrap; }
.ws-act .action-btn, .ws-more { height: var(--ws-btn-h); min-width: var(--ws-btn-h); padding: 0 9px; display: inline-flex; align-items: center; justify-content: center; gap: 4px; font-size: var(--ws-font-sm) !important; font-weight: 500; border-radius: var(--ws-radius-sm); background: var(--ws-panel) !important; color: var(--ws-text) !important; border: 1px solid var(--ws-line-2) !important; opacity: 1 !important; white-space: nowrap; line-height: 1; cursor: pointer; }
.ws-act .action-btn:hover, .ws-more:hover, .ws-more[aria-expanded="true"] { background: var(--ws-row-hover) !important; border-color: var(--ws-text-3) !important; }
.ws-act .action-btn.act-primary { color: var(--ws-brand) !important; border-color: var(--ws-brand-line) !important; font-weight: 600; }
.ws-act .action-btn.act-del { color: var(--ws-bad) !important; }
.ws-act .action-btn.act-approve { color: var(--ws-warn) !important; border-color: var(--ws-warn-line) !important; background: var(--ws-warn-soft) !important; font-weight: 600; }
.ws-act .action-btn:focus-visible, .ws-more:focus-visible, .ws-menu button:focus-visible { outline: 2px solid var(--ws-brand); outline-offset: 1px; }
.ws-more { font-size: 15px !important; letter-spacing: 1px; }
.ws-menu { position: fixed; z-index: 9000; min-width: 220px; max-width: 300px; max-height: 60vh; overflow-y: auto; padding: 6px; background: var(--ws-panel); color: var(--ws-text); border: 1px solid var(--ws-line); border-radius: 10px; box-shadow: 0 14px 34px rgba(0,0,0,.25); display: flex; flex-direction: column; gap: 1px; text-align: start; }
.ws-menu[hidden] { display: none; }
.ws-menu > button, .ws-menu > a { all: unset; box-sizing: border-box; display: flex !important; align-items: center; gap: 8px; width: 100%; padding: 7px 10px !important; border-radius: 6px; font-size: 13px !important; color: var(--ws-text) !important; background: transparent !important; cursor: pointer; white-space: nowrap; opacity: 1 !important; }
.ws-menu > button:hover, .ws-menu > a:hover, .ws-menu > button:focus { background: var(--ws-row-hover) !important; }
.ws-menu > button[disabled] { opacity: .45 !important; cursor: not-allowed; }
.ws-menu > .ws-mi-del { color: var(--ws-bad) !important; border-top: 1px solid var(--ws-line); border-radius: 0 0 6px 6px; margin-top: 3px; }
.ws-menu > .ws-mi-info { display: block; padding: 6px 10px 8px; font-size: 11.5px; color: var(--ws-text-2); border-bottom: 1px solid var(--ws-line); margin-bottom: 3px; white-space: normal; }
.ws-menu .ws-mi-l { color: var(--ws-text); font-size: 13px; }

/* --- sidebar: same structure in every theme --- */
.sidebar .nav-title { font-size: 10.5px; letter-spacing: .9px; padding: 12px 14px 6px; }
.sidebar .nav-group-label { font-size: 9.5px; letter-spacing: .7px; padding: 8px 14px 3px; opacity: .6; }
.sidebar .nav-item { padding: 7px 10px 7px 12px; margin: 1px 8px; border-radius: 7px; font-size: 13px; line-height: 1.3; gap: 8px; }
.sidebar .nav-item.active { background: var(--ws-brand-soft); color: var(--ws-brand); font-weight: 600; box-shadow: inset 3px 0 0 var(--ws-brand); }
html[dir="rtl"] .sidebar .nav-item.active { box-shadow: inset -3px 0 0 var(--ws-brand); }
html[data-brand="torch"] .sidebar .nav-item.active { background: rgba(255,255,255,0.2); color: #fff; box-shadow: inset 3px 0 0 #fff; }
html[dir="rtl"][data-brand="torch"] .sidebar .nav-item.active { box-shadow: inset -3px 0 0 #fff; }
.sidebar .nav-item .badge { min-width: 22px; height: 18px; line-height: 18px; padding: 0 6px; border-radius: 9px; font-size: 10.5px; font-weight: 700; text-align: center; box-sizing: border-box; }
.sidebar .badge-desc { font-size: 9px; margin-top: 1px; }
/* My Tasks pinned under the menu search; its old place in Home stays (hidden) for saved orders / permissions */
.sidebar .nav-item.nv-moved { display: none !important; }
.sidebar .nav-pin { padding: 0 6px 6px; }
.sidebar .nav-pin .nav-pin-badge { background: #f59e0b !important; color: #fff !important; }
.sidebar .nav-pin .nav-item { margin: 0 4px; background: rgba(255,255,255,0.10); font-weight: 600; }
html:not([data-brand="torch"]) .sidebar .nav-pin .nav-item { background: var(--ws-brand-soft, rgba(27,55,141,0.08)); }
/* a section heading carries how many records in it wait for YOUR approval */
.sidebar .nav-title .nav-sec-badge { margin-inline-start: auto; margin-inline-end: 6px; min-width: 20px; height: 18px; line-height: 18px; padding: 0 6px; border-radius: 9px;
  font-size: 10.5px; font-weight: 800; text-align: center; background: #f59e0b; color: #fff; letter-spacing: 0; }
/* names get the room: the small note under the number is cut to one short line (full text in its tooltip) */
.sidebar .nav-item > span:first-child { flex: 1 1 auto; min-width: 0; }
.sidebar .nav-item > .badge-wrap { flex: none; margin-inline-start: 6px; max-width: 64px; }
.sidebar .badge-desc { max-width: 64px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@media (min-width: 769px) { .sidebar .nav-section { padding-inline: 6px; } .sidebar .nav-section-body .nav-item { margin-inline: 4px; padding-inline: 10px 8px; } }
.sidebar .nav-item:focus-visible { outline: 2px solid currentColor; outline-offset: -2px; }
/* desktop: the sidebar folds away (☰), remembered per browser */
.menu-toggle { display: inline-flex !important; align-items: center; justify-content: center; width: 34px; height: 34px; padding: 0; border: 0; background: transparent; color: var(--ws-text-2); font-size: 17px; border-radius: 8px; }
.menu-toggle:hover { background: var(--ws-row-hover); }
@media (min-width: 769px) {
  body.sb-hidden .app { grid-template-columns: 0 1fr; }
  body.sb-hidden .sidebar { display: none; }
}

/* No browser header / footer (site address, date, title) when a page of the
   app itself is printed (OM 2026-10-12). Printed documents get the same rule
   from _tsdNoHdr in js/13. */
@page {
  @top-left { content: ""; } @top-center { content: ""; } @top-right { content: ""; }
  @bottom-left { content: ""; } @bottom-center { content: ""; } @bottom-right { content: ""; }
}
