/* ============================================================================
 * app-modern.css — SNS UPVC EMS modern design system (reskin layer)
 * ----------------------------------------------------------------------------
 * Loaded AFTER bootstrap.min.css + startmin.css, so equal-specificity rules
 * win without !important. Restyles the existing Bootstrap-3 / SB-Admin-2 DOM
 * in place — no page markup is rewritten.
 *
 *   1. Fonts            2. Design tokens (light + dark)
 *   3. Base + type      4. App shell (sidebar / topbar / page)
 *   5. Components       6. Auth (login)
 *   7. Responsive       8. Motion / a11y
 * ============================================================================ */

/* 1. FONTS ----------------------------------------------------------------- */
@font-face {
  font-family: "InterVar";
  src: url("../fonts/inter-var.woff2") format("woff2");
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}
@font-face {
  font-family: "SpaceGroteskVar";
  src: url("../fonts/space-grotesk-var.woff2") format("woff2");
  font-weight: 300 700;
  font-style: normal;
  font-display: swap;
}

/* 2. DESIGN TOKENS --------------------------------------------------------- */
:root {
  /* Brand accent — change ONLY this line to re-theme the app (Lohakar = #e74c3c) */
  --brand: #ff6b35;
  --brand-strong: #e8541f;
  --brand-ink: #ffffff;

  /* Surfaces (light) */
  --bg: #eef1f6;
  --surface: #ffffff;
  --surface-2: #f5f7fa;
  --surface-3: #eef1f6;

  /* Text */
  --ink: #14181e;
  --ink-soft: #3d4651;
  --muted: #6c7682;
  --faint: #97a1ad;

  /* Lines */
  --border: #e3e8ef;
  --border-strong: #cfd6e0;

  /* Accent derivatives */
  --accent: var(--brand);
  --accent-strong: var(--brand-strong);
  --accent-soft: rgba(255, 107, 53, 0.10);
  --accent-tint: rgba(255, 107, 53, 0.16);
  --ring: rgba(255, 107, 53, 0.32);

  /* Semantic */
  --info: #2f6fed;   --info-soft: rgba(47, 111, 237, 0.12);
  --ok: #16a34a;     --ok-soft: rgba(22, 163, 74, 0.12);
  --warn: #d97706;   --warn-soft: rgba(217, 119, 6, 0.14);
  --danger: #dc2626; --danger-soft: rgba(220, 38, 38, 0.12);

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.05);
  --shadow-md: 0 4px 12px rgba(16, 24, 40, 0.08), 0 2px 4px rgba(16, 24, 40, 0.04);
  --shadow-lg: 0 16px 40px rgba(16, 24, 40, 0.16);

  /* Geometry */
  --radius: 14px;
  --radius-sm: 10px;
  --radius-xs: 8px;
  --sidebar-w: 264px;
  --topbar-h: 62px;

  /* Type */
  --font-ui: "InterVar", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --font-display: "SpaceGroteskVar", "InterVar", system-ui, sans-serif;
  --font-mono: "SpaceGroteskVar", ui-monospace, "SFMono-Regular", Menlo, monospace;

  color-scheme: light;
}

[data-theme="dark"] {
  --bg: #0c0f14;
  --surface: #151a21;
  --surface-2: #1b212a;
  --surface-3: #222a34;

  --ink: #e8edf3;
  --ink-soft: #c2cad4;
  --muted: #8b95a3;
  --faint: #6a7482;

  --border: #262e39;
  --border-strong: #36404d;

  --brand: #ff7a47;
  --brand-strong: #ff6b35;
  --accent: var(--brand);
  --accent-strong: var(--brand-strong);
  --accent-soft: rgba(255, 122, 71, 0.13);
  --accent-tint: rgba(255, 122, 71, 0.20);
  --ring: rgba(255, 122, 71, 0.36);

  --info-soft: rgba(47, 111, 237, 0.18);
  --ok-soft: rgba(22, 163, 74, 0.18);
  --warn-soft: rgba(217, 119, 6, 0.20);
  --danger-soft: rgba(220, 38, 38, 0.18);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow-md: 0 6px 18px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 22px 48px rgba(0, 0, 0, 0.6);

  color-scheme: dark;
}

/* 3. BASE + TYPOGRAPHY ----------------------------------------------------- */
body {
  background-color: var(--bg);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: 14.5px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv05" 1, "ss01" 1;
}
h1, h2, h3, h4, h5, .page-header, .panel-title, .huge {
  font-family: var(--font-display);
  letter-spacing: -0.01em;
  color: var(--ink);
}
.page-header {
  border-bottom: 1px solid var(--border);
  margin: 6px 0 22px;
  padding-bottom: 12px;
  font-weight: 600;
}
a { color: var(--accent); }
a:hover, a:focus { color: var(--accent-strong); }
hr { border-top: 1px solid var(--border); }
small, .small { color: var(--muted); }
.text-muted { color: var(--muted) !important; }
code, kbd, pre { font-family: var(--font-mono); }

/* Numeric alignment for money / quantity columns */
.table td, .table th, .huge, .form-control[type="number"], input.amount, .text-right {
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

::selection { background: var(--accent-tint); color: var(--ink); }

/* Themed scrollbars */
* { scrollbar-width: thin; scrollbar-color: var(--border-strong) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 8px; border: 2px solid transparent; background-clip: content-box; }
*::-webkit-scrollbar-thumb:hover { background: var(--muted); background-clip: content-box; }

/* 4. APP SHELL ------------------------------------------------------------- */
#wrapper { width: 100%; background: var(--bg); }

/* --- Sidebar (fixed rail) --- */
.app-sidebar {
  position: fixed;
  top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 1040;
  transition: transform 0.26s cubic-bezier(0.4, 0, 0.2, 1);
}
.sidebar-head {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
}
.sidebar-brand {
  display: flex; align-items: center; gap: 11px;
  text-decoration: none; min-width: 0; flex: 1;
}
.sidebar-brand:hover, .sidebar-brand:focus { text-decoration: none; }
.sidebar-logo {
  width: 36px; height: 36px;
  object-fit: contain; flex: 0 0 auto;
}
.sidebar-brandname {
  font-family: var(--font-display);
  font-weight: 600; font-size: 16px; letter-spacing: -0.01em;
  color: var(--ink); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.sidebar-close {
  display: none; background: none; border: 0; color: var(--muted);
  font-size: 19px; padding: 6px; cursor: pointer; border-radius: 8px;
}
.sidebar-close:hover { background: var(--surface-2); color: var(--ink); }

.sidebar-scroll { flex: 1 1 auto; overflow-y: auto; padding: 12px 12px 24px; }

/* Sidebar menu (#side-menu) */
.app-sidebar #side-menu { margin: 0; padding: 0; }
.app-sidebar #side-menu > li { border: 0; margin: 1px 0; }
.app-sidebar #side-menu li { border: 0 !important; }
.app-sidebar #side-menu a {
  position: relative;
  display: flex; align-items: center; gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-xs);
  color: var(--ink-soft);
  font-size: 14px; font-weight: 500;
  text-decoration: none;
  transition: background 0.15s, color 0.15s;
}
.app-sidebar #side-menu a:hover,
.app-sidebar #side-menu a:focus { background: var(--surface-2); color: var(--ink); }
.app-sidebar #side-menu > li > a > i,
.app-sidebar #side-menu a > i:first-child {
  width: 20px; text-align: center; font-size: 15px;
  color: var(--faint); flex: 0 0 auto; transition: color 0.15s;
}
.app-sidebar #side-menu a:hover > i:first-child { color: var(--muted); }
.app-sidebar #side-menu .arrow { margin-left: auto; font-size: 11px; color: var(--faint); }

/* Active item — signature accent tick */
.app-sidebar #side-menu a.active,
.app-sidebar #side-menu li.active > a {
  background: var(--accent-soft);
  color: var(--accent-strong);
  font-weight: 600;
}
.app-sidebar #side-menu a.active > i:first-child,
.app-sidebar #side-menu li.active > a > i:first-child { color: var(--accent); }
.app-sidebar #side-menu a.active::before,
.app-sidebar #side-menu li.active > a::before {
  content: ""; position: absolute; left: -4px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px; border-radius: 0 3px 3px 0;
  background: var(--accent);
}

/* Sub-menus */
.app-sidebar .nav-second-level { padding-left: 0; margin: 2px 0 6px; list-style: none; }
.app-sidebar .nav-second-level li { list-style: none; }
.app-sidebar .nav-second-level li a {
  padding: 7px 12px 7px 34px; font-size: 13.5px; font-weight: 500; color: var(--muted);
}
.app-sidebar .nav-second-level li a:hover { color: var(--ink); }
.app-sidebar .nav-second-level li.active a,
.app-sidebar .nav-second-level li a.active { color: var(--accent-strong); background: transparent; }
.app-sidebar .nav-second-level li.active a::before,
.app-sidebar .nav-second-level li a.active::before { display: none; }

/* MetisMenu arrow rotation */
.app-sidebar #side-menu .fa.arrow:before { content: "\f105"; transition: transform 0.2s; }
.app-sidebar #side-menu .active > a > .fa.arrow:before { transform: rotate(90deg); }

/* Backdrop (mobile) */
.sidebar-backdrop {
  position: fixed; inset: 0; background: rgba(8, 12, 18, 0.5);
  opacity: 0; visibility: hidden; transition: opacity 0.25s; z-index: 1039;
  -webkit-backdrop-filter: blur(1px); backdrop-filter: blur(1px);
}

/* --- Topbar (sticky) --- */
.app-topbar {
  position: fixed; top: 0; right: 0; left: var(--sidebar-w);
  height: var(--topbar-h);
  display: flex; align-items: center; gap: 8px;
  padding: 0 18px;
  background: var(--surface);
  background: color-mix(in srgb, var(--surface) 86%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
  backdrop-filter: saturate(1.4) blur(10px);
  border-bottom: 1px solid var(--border);
  z-index: 1030;
}
.topbar-burger, .topbar-brand-mobile { display: none; }
.topbar-burger {
  background: none; border: 0; color: var(--ink); font-size: 18px;
  width: 40px; height: 40px; border-radius: 10px; cursor: pointer;
}
.topbar-burger:hover { background: var(--surface-2); }
.topbar-brand-mobile { align-items: center; gap: 9px; text-decoration: none; }
.topbar-brand-mobile img { width: 28px; height: 28px; border-radius: 7px; }
.topbar-brand-mobile span { font-family: var(--font-display); font-weight: 600; color: var(--ink); font-size: 15px; }
.topbar-spacer { flex: 1 1 auto; }
.topbar-actions { display: flex; align-items: center; gap: 4px; }

.icon-btn {
  background: none; border: 0; color: var(--ink-soft);
  width: 40px; height: 40px; border-radius: 10px;
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 16px; cursor: pointer; transition: background 0.15s, color 0.15s;
}
.icon-btn:hover, .icon-btn:focus { background: var(--surface-2); color: var(--ink); }
.theme-toggle .fa-sun { display: none; }
[data-theme="dark"] .theme-toggle .fa-moon { display: none; }
[data-theme="dark"] .theme-toggle .fa-sun { display: inline; }

/* Topbar dropdown triggers */
.topbar-dropdown { display: inline-flex; }
.topbar-dropdown > a.dropdown-toggle {
  display: inline-flex; align-items: center; gap: 7px;
  height: 40px; padding: 0 11px; border-radius: 10px;
  color: var(--ink-soft); text-decoration: none; font-weight: 500; font-size: 13.5px;
}
.topbar-dropdown > a.dropdown-toggle:hover { background: var(--surface-2); color: var(--ink); }
.topbar-dropdown > a.dropdown-toggle.icon-btn { width: 40px; padding: 0; gap: 0; }
.topbar-dropdown .fa-user, .topbar-dropdown .fa-bell { font-size: 15px; }
.topbar-dropdown .caret { color: var(--faint); }

/* --- Page content area --- */
#page-wrapper {
  margin-left: var(--sidebar-w);
  padding: calc(var(--topbar-h) + 22px) 30px 40px;
  min-height: 100vh;
  border-left: 0;
  background: var(--bg);
}

/* 5. COMPONENTS ------------------------------------------------------------ */

/* Cards (Bootstrap-3 panels) */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  margin-bottom: 24px;
}
.panel-heading {
  background: transparent;
  border-bottom: 1px solid var(--border);
  padding: 15px 20px;
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--ink);
  font-weight: 600;
}
.panel-title { font-size: 15px; font-weight: 600; letter-spacing: -0.01em; }
.panel-body { padding: 20px; color: var(--ink-soft); }
.panel-footer {
  background: var(--surface-2); border-top: 1px solid var(--border);
  border-radius: 0 0 var(--radius) var(--radius); color: var(--muted);
}
.panel-default > .panel-heading { background: var(--surface-2); color: var(--ink); }

/* Dashboard stat panels — restrained: neutral card + colored accent, not flooded color */
.panel-primary, .panel-green, .panel-yellow, .panel-red, .panel-info {
  background: var(--surface); color: var(--ink-soft);
  border-color: var(--border); position: relative; overflow: hidden;
}
.panel-primary > .panel-heading, .panel-green > .panel-heading,
.panel-yellow > .panel-heading, .panel-red > .panel-heading, .panel-info > .panel-heading {
  color: var(--brand-ink); border: 0;
}
.panel-primary > .panel-heading { background: var(--accent); }
.panel-green > .panel-heading { background: var(--ok); }
.panel-yellow > .panel-heading { background: var(--warn); }
.panel-red > .panel-heading { background: var(--danger); }
.panel-info > .panel-heading { background: var(--info); }
.panel-primary > .panel-heading .huge, .panel-green > .panel-heading .huge,
.panel-yellow > .panel-heading .huge, .panel-red > .panel-heading .huge,
.panel-info > .panel-heading .huge { color: var(--brand-ink); }
.panel-primary, .panel-green, .panel-yellow, .panel-red, .panel-info { box-shadow: var(--shadow-sm); }
.huge { font-family: var(--font-display); font-size: 30px; font-weight: 600; line-height: 1.1; }
.panel a.panel-footer-link, .panel .panel-footer a { color: inherit; }

/* Buttons */
.btn {
  border-radius: var(--radius-xs);
  font-weight: 600; font-size: 13.5px;
  padding: 8px 16px;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s, transform 0.05s;
}
.btn:active { transform: translateY(1px); }
.btn:focus, .btn:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.btn-lg { padding: 11px 22px; font-size: 15px; border-radius: var(--radius-sm); }
.btn-sm, .btn-xs { padding: 5px 11px; font-size: 12.5px; }

.btn-default {
  background: var(--surface); color: var(--ink); border-color: var(--border-strong);
}
.btn-default:hover, .btn-default:focus { background: var(--surface-2); color: var(--ink); border-color: var(--muted); }

.btn-primary { background: var(--accent); border-color: var(--accent); color: var(--brand-ink); }
.btn-primary:hover, .btn-primary:focus, .btn-primary:active,
.open > .dropdown-toggle.btn-primary {
  background: var(--accent-strong); border-color: var(--accent-strong); color: var(--brand-ink);
}
.btn-success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn-success:hover, .btn-success:focus { background: #128a3e; border-color: #128a3e; color: #fff; }
.btn-info { background: var(--info); border-color: var(--info); color: #fff; }
.btn-info:hover, .btn-info:focus { background: #2560cf; border-color: #2560cf; color: #fff; }
.btn-warning { background: var(--warn); border-color: var(--warn); color: #fff; }
.btn-warning:hover, .btn-warning:focus { background: #b86205; border-color: #b86205; color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover, .btn-danger:focus { background: #b91c1c; border-color: #b91c1c; color: #fff; }
.btn-link { color: var(--accent); font-weight: 500; }
.btn-outline, .btn-primary.btn-outline { background: transparent; color: var(--accent); border-color: var(--accent); }
.btn-primary.btn-outline:hover { background: var(--accent); color: var(--brand-ink); }

/* Forms */
.form-control {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs);
  color: var(--ink);
  font-size: 14px;
  height: 40px;
  padding: 8px 12px;
  box-shadow: none;
  transition: border-color 0.15s, box-shadow 0.15s;
}
textarea.form-control { height: auto; }
.form-control::placeholder { color: var(--faint); }
.form-control:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--ring);
  background: var(--surface);
}
.form-control[disabled], .form-control[readonly], fieldset[disabled] .form-control {
  background: var(--surface-2); color: var(--muted); cursor: not-allowed;
}
.input-lg { height: 48px; font-size: 16px; border-radius: var(--radius-sm); }
.input-sm { height: 34px; font-size: 13px; }
label, .control-label { color: var(--ink-soft); font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.help-block { color: var(--muted); font-size: 12.5px; }
.input-group-addon {
  background: var(--surface-2); border: 1px solid var(--border-strong); color: var(--muted);
  border-radius: var(--radius-xs);
}
select.form-control { -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236c7682' stroke-width='2.5'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center; padding-right: 34px;
}
/* Small (input-sm) selects inherit the legacy 30px line-height, which overflows their
   short content box and clips the value top+bottom; trim line-height + vertical padding
   so the value centres. (Card-grid selects override with their own values.) */
select.form-control.input-sm { line-height: 1.4; padding-top: 4px; padding-bottom: 4px; }
.has-error .form-control { border-color: var(--danger); }
.has-error .form-control:focus { box-shadow: 0 0 0 3px var(--danger-soft); }
.has-success .form-control { border-color: var(--ok); }

/* ── Form card ─────────────────────────────────────────────────────────────────
 * Mobile-first container for create/edit forms — replaces the legacy
 * `<table class="table-bordered">`-for-layout pattern (which cramps columns on phones
 * and overflows sideways). Pair with Bootstrap `.row` + `.col-sm-*` for a grid that
 * collapses to one column under 768px. */
.form-card {
  max-width: 760px; margin: 6px auto 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow-sm);
  padding: 26px 26px 20px;
}
.form-card-head { margin-bottom: 20px; }
.form-card-title { font-family: var(--font-display); font-weight: 600; font-size: 21px; margin: 0; color: var(--ink); }
.form-card-sub { color: var(--muted); font-size: 13.5px; margin: 4px 0 0; }
.form-card .form-group { margin-bottom: 15px; }
.form-card label, .form-card .control-label { display: block; }
.form-card label.required::after { content: " *"; color: var(--danger); font-weight: 700; }
.form-actions {
  display: flex; gap: 10px; justify-content: flex-end; align-items: center;
  margin-top: 22px; padding-top: 18px; border-top: 1px solid var(--border);
}
.form-actions .btn { min-width: 120px; }
@media (max-width: 767px) {
  .form-card { padding: 18px 15px 14px; border-radius: var(--radius-sm); margin-top: 0; }
  .form-card-title { font-size: 19px; }
  /* 16px inputs stop iOS auto-zoom on focus; taller targets for thumbs */
  .form-card .form-control { font-size: 16px; height: 46px; }
  .form-card select.form-control { height: 46px; }
  .form-card textarea.form-control { height: auto; min-height: 96px; }
  /* full-width, thumb-reachable actions; primary on top */
  .form-actions { flex-direction: column-reverse; gap: 10px; align-items: stretch; }
  .form-actions .btn { width: 100%; min-width: 0; padding: 12px; font-size: 15px; }
}

/* ── Collapsible detail sections ───────────────────────────────────────────────
 * Fold the many drill-down sections on a detail page (Contacts, Orders, Invoices…)
 * into tappable bars so the page isn't an endless scroll. Wrapped client-side by
 * setupCollapsibleSections() (in customers.php). Collapsed by default; count badge. */
.collapse-section {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: var(--surface); margin-bottom: 12px; overflow: hidden;
}
.collapse-section.open { box-shadow: var(--shadow-sm); }
.collapse-section-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  width: 100%; text-align: left; border: 0; background: transparent;
  padding: 14px 18px; cursor: pointer; color: var(--ink);
  font-family: var(--font-display); font-weight: 600; font-size: 15.5px;
}
.collapse-section-head:hover { background: var(--surface-2); }
.collapse-section-head:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.collapse-section-title { flex: 1 1 auto; }
.collapse-section-meta { display: flex; align-items: center; gap: 12px; flex: 0 0 auto; }
.collapse-section-count {
  min-width: 22px; text-align: center; padding: 2px 9px; border-radius: 999px;
  background: var(--surface-3); color: var(--ink-soft);
  font-family: var(--font-ui); font-size: 12.5px; font-weight: 600;
}
.collapse-section.open .collapse-section-count { background: var(--accent-soft); color: var(--accent); }
.collapse-section-chevron { color: var(--muted); font-size: 13px; transition: transform 0.2s ease; }
.collapse-section.open .collapse-section-chevron { transform: rotate(180deg); }
.collapse-section-body { padding: 16px 18px; border-top: 1px solid var(--border); }
@media (max-width: 767px) {
  .collapse-section-head { padding: 13px 14px; font-size: 15px; }
  .collapse-section-body { padding: 14px 12px; }
}
/* Detail-view info tables (Customer Details, Account Statement) carry an inner
 * `h2.modal-title`; give them the same bottom gap as the collapsible bars below
 * them so the sections don't sit flush against each other. */
.table-responsive:has(h2.modal-title) { margin-bottom: 12px; }

/* Tables */
.table { color: var(--ink-soft); margin-bottom: 0; }
.table > thead > tr > th {
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  border-top: 0;
  color: var(--muted);
  font-family: var(--font-ui);
  font-weight: 600; font-size: 11.5px; letter-spacing: 0.04em; text-transform: uppercase;
  padding: 12px 14px; vertical-align: middle; white-space: nowrap;
}
.table > tbody > tr > td {
  border-top: 1px solid var(--border);
  padding: 12px 14px; vertical-align: middle; color: var(--ink);
}
.table > tbody > tr:hover > td { background: var(--surface-2); }
.table-striped > tbody > tr:nth-of-type(odd) > td { background: var(--surface-2); }
.table-striped > tbody > tr:nth-of-type(odd):hover > td { background: var(--surface-3); }
.table-bordered, .table-bordered > tbody > tr > td, .table-bordered > thead > tr > th { border-color: var(--border); }
.panel > .table, .panel > .table-responsive > .table { margin-bottom: 0; }

/* Dark-mode: form/entry tables (the item grids on quotations / invoice / delivery-
 * challan / credit-note / drawings) put rows DIRECTLY in <table> (no <thead>/<tbody>),
 * so the `.table > thead`/`> tbody` selectors above partly miss them and the cells can
 * render light on a dark page. Force a dark surface on every NON-DataTable table cell
 * (DataTables keep their own stripe/hover styling). !important also beats any inline white. */
[data-theme="dark"] .table:not(.dataTable) > thead > tr > th,
[data-theme="dark"] .table:not(.dataTable) > tbody > tr > th,
[data-theme="dark"] .table:not(.dataTable) > tr > th {
  background-color: var(--surface-3) !important;
  color: var(--ink-soft) !important;
}
[data-theme="dark"] .table:not(.dataTable) > tbody > tr > td,
[data-theme="dark"] .table:not(.dataTable) > tr > td {
  background-color: var(--surface-2) !important;
  color: var(--ink) !important;
}
/* The table element itself gets a dark bg so any region NOT covered by a cell renders
 * dark, not white. (The per-row delete column is added by JS to body rows only, so the
 * header rows are one column short and the top-right corner has no cell.) */
[data-theme="dark"] .table:not(.dataTable) { background-color: var(--surface-2) !important; }
/* Soften the bordered grid: the no-<thead> form cells otherwise keep Bootstrap's light
 * #ddd border (only some cell variants were recoloured), giving a harsh mismatched grid.
 * Unify every cell variant to the subtle --border. */
[data-theme="dark"] .table-bordered,
[data-theme="dark"] .table-bordered > tbody > tr > td,
[data-theme="dark"] .table-bordered > tbody > tr > th,
[data-theme="dark"] .table-bordered > thead > tr > th,
[data-theme="dark"] .table-bordered > tr > td,
[data-theme="dark"] .table-bordered > tr > th {
  border-color: var(--border) !important;
}

/* Responsive table affordance — sticky first column + scroll hint */
.table-responsive {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  position: relative;
  -webkit-overflow-scrolling: touch;
}
.panel .table-responsive { border: 0; border-radius: 0; }

/* DataTables — unified across v1 (legacy + bootstrap pagination) and v2 (.dt-*) so
 * every page's table looks identical in both themes. The app mixes DataTables 1.10
 * (some pages with dataTables.bootstrap.css) and 2.0.8 (CDN, new .dt-* classes). */
.dataTables_wrapper, .dt-container { padding: 4px 2px; }
.dataTables_length, .dataTables_filter, .dataTables_info,
.dt-length, .dt-search, .dt-info { color: var(--muted); font-size: 13px; }
.dataTables_length select, .dataTables_filter input,
.dt-length select, .dt-search input {
  background: var(--surface); border: 1px solid var(--border-strong);
  border-radius: var(--radius-xs); color: var(--ink); height: 36px; padding: 4px 10px;
}
.dataTables_filter input:focus, .dt-search input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--ring); outline: none;
}

/* Pagination — one identical pill button across all three renderers */
.dataTables_paginate a.paginate_button,
.dataTables_paginate ul.pagination > li > a,
.dataTables_paginate ul.pagination > li > span,
div.dt-container .dt-paging .dt-paging-button {
  display: inline-block;
  border-radius: var(--radius-xs) !important;
  border: 1px solid var(--border) !important;
  background: var(--surface) !important;
  color: var(--ink-soft) !important;
  padding: 5px 11px !important;
  margin: 2px 0 2px 4px !important;
  min-width: 36px; text-align: center; cursor: pointer;
  font-size: 13px; line-height: 1.4; text-decoration: none;
}
/* the bootstrap <li> wrapper must NOT draw its own box (caused the ghost boxes) */
.dataTables_paginate ul.pagination { display: inline-flex; flex-wrap: wrap; padding-left: 0; margin: 2px 0; }
.dataTables_paginate ul.pagination > li,
.dataTables_paginate ul.pagination > li.paginate_button {
  border: 0 !important; background: transparent !important; padding: 0 !important; margin: 0 !important;
}
/* hover */
.dataTables_paginate a.paginate_button:hover,
.dataTables_paginate ul.pagination > li > a:hover,
div.dt-container .dt-paging .dt-paging-button:hover {
  background: var(--surface-2) !important; color: var(--ink) !important; border-color: var(--border-strong) !important;
}
/* active / current */
.dataTables_paginate a.paginate_button.current,
.dataTables_paginate a.paginate_button.current:hover,
.dataTables_paginate ul.pagination > li.active > a,
.dataTables_paginate ul.pagination > li.active > a:hover,
div.dt-container .dt-paging .dt-paging-button.current,
div.dt-container .dt-paging .dt-paging-button.current:hover {
  background: var(--accent) !important; border-color: var(--accent) !important; color: var(--brand-ink) !important;
}
/* disabled (Previous/Next at the ends) + ellipsis */
.dataTables_paginate a.paginate_button.disabled,
.dataTables_paginate ul.pagination > li.disabled > a,
.dataTables_paginate ul.pagination > li.disabled > span,
div.dt-container .dt-paging .dt-paging-button.disabled {
  color: var(--faint) !important; background: var(--surface) !important;
  border-color: var(--border) !important; cursor: default; opacity: 0.55;
}
div.dt-container .dt-paging .dt-paging-button.ellipsis,
.dataTables_paginate ul.pagination > li > span.ellipsis {
  border: 0 !important; background: transparent !important; min-width: 0;
}

/* Make DataTables-2 pagination match the DataTables-1 pages: hide first/last,
 * show the words "Previous"/"Next" instead of « ‹ › » arrows, and keep the
 * disabled words visible on dark (DT2's own .disabled rule forces black-50%). */
div.dt-container .dt-paging .dt-paging-button.first,
div.dt-container .dt-paging .dt-paging-button.last { display: none !important; }
div.dt-container .dt-paging .dt-paging-button.previous,
div.dt-container .dt-paging .dt-paging-button.next { font-size: 0 !important; }
div.dt-container .dt-paging .dt-paging-button.previous::after { content: "Previous"; font-size: 13px; }
div.dt-container .dt-paging .dt-paging-button.next::after { content: "Next"; font-size: 13px; }
div.dt-container .dt-paging .dt-paging-button.disabled,
div.dt-container .dt-paging .dt-paging-button.disabled:hover,
div.dt-container .dt-paging .dt-paging-button.disabled:active {
  color: var(--faint) !important; opacity: 1;
}

table.dataTable tbody tr { background: transparent; }
table.dataTable, table.dataTable td, table.dataTable th { border-color: var(--border) !important; }

/* Responsive DataTables — on phones, stack each row into a labelled card (no
 * horizontal scroll). Cells get their data-label from js/app-modern.js. */
@media (max-width: 767px) {
  table.dataTable > thead {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
  }
  table.dataTable, table.dataTable > tbody { display: block; width: 100%; }
  table.dataTable > tbody > tr {
    display: block; margin: 0 0 12px; border: 1px solid var(--border);
    border-radius: 12px; background: var(--surface); box-shadow: var(--shadow-sm); overflow: hidden;
  }
  table.dataTable > tbody > tr > td {
    display: block; width: auto !important; border: 0;
    border-bottom: 1px solid var(--border); padding: 9px 14px;
    text-align: left !important; white-space: normal;
  }
  table.dataTable > tbody > tr > td:last-child { border-bottom: 0; }
  table.dataTable > tbody > tr > td[data-label]::before {
    content: attr(data-label); display: block; margin-bottom: 3px;
    font-weight: 600; font-size: 10.5px; letter-spacing: 0.05em;
    text-transform: uppercase; color: var(--muted);
  }
  /* once stacked, no horizontal scroll needed */
  .table-responsive { overflow-x: visible !important; border: 0; }
  /* stack the controls + full-width search */
  div.dt-container .dt-layout-row { display: block; }
  .dataTables_wrapper .dataTables_length,
  .dataTables_wrapper .dataTables_filter { float: none !important; text-align: left; margin-bottom: 8px; }
  .dataTables_filter input, .dt-search input, .dt-search label { width: 100%; }
}

/* >=768px: tables keep single-line cells (no wrapping). A table wider than the screen
 * scrolls INSIDE its own box, so the PAGE never scrolls sideways. Phones: card view above. */
@media (min-width: 768px) {
  .table-responsive { overflow-x: auto; max-width: 100%; }
  .table-responsive table.dataTable > thead > tr > th,
  .table-responsive table.dataTable > tbody > tr > td { white-space: nowrap; }
}

/* Dropdown menus */
.dropdown-menu {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  padding: 6px;
  margin-top: 8px;
}
.dropdown-menu > li > a {
  color: var(--ink-soft); border-radius: var(--radius-xs); padding: 8px 12px; font-size: 13.5px; font-weight: 500;
}
.dropdown-menu > li > a:hover, .dropdown-menu > li > a:focus { background: var(--surface-2); color: var(--ink); }
.dropdown-menu > li > a > i { width: 18px; color: var(--faint); }

/* bootstrap-multiselect dropdown items (the Design Specification picker etc.): Bootstrap's
 * `.checkbox` label adds 10px top/bottom margins and absolutely-positions the input, so the
 * checkbox and its text don't sit centred on one line and rows get big uneven gaps. Lay each
 * item out as a tight, vertically-centred flex row. (No vendor multiselect CSS is loaded —
 * scoped to the dropdown items; the toggle button and panel background are left as-is.) */
.multiselect-container > li > a { padding: 5px 14px; }
.multiselect-container > li > a > label.checkbox,
.multiselect-container > li > a > label.radio {
  display: flex; align-items: center; gap: 8px;
  margin: 0; padding: 0; min-height: 0; font-weight: 500;
}
.multiselect-container > li > a > label.checkbox > input[type="checkbox"],
.multiselect-container > li > a > label.radio > input[type="radio"] {
  position: static; margin: 0; flex: 0 0 auto;
}
.dropdown-menu .divider { background: var(--border); margin: 6px 2px; }
.dropdown-menu.dropdown-alerts, .dropdown-menu.dropdown-user { right: 0; left: auto; min-width: 240px; }

/* Modals */
.modal-content {
  background: var(--surface); color: var(--ink);
  border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
}
.modal-header { border-bottom: 1px solid var(--border); padding: 18px 22px; }
.modal-title { font-family: var(--font-display); font-weight: 600; }
.modal-body { padding: 22px; color: var(--ink-soft); }
.modal-footer { border-top: 1px solid var(--border); padding: 16px 22px; }
.modal-backdrop.in { opacity: 0.55; }
.close { color: var(--muted); opacity: 0.8; text-shadow: none; }
.close:hover { color: var(--ink); opacity: 1; }

/* Alerts + login bg-* messages */
.alert, .bg-danger, .bg-warning, .bg-success, .bg-info {
  border-radius: var(--radius-sm); border: 1px solid transparent; padding: 13px 16px; font-size: 13.5px;
}
.alert-success, .bg-success { background: var(--ok-soft); border-color: rgba(22,163,74,0.3); color: #0f7a37; }
.alert-danger, .bg-danger { background: var(--danger-soft); border-color: rgba(220,38,38,0.3); color: #b91c1c; }
.alert-warning, .bg-warning { background: var(--warn-soft); border-color: rgba(217,119,6,0.3); color: #a85c05; }
.alert-info, .bg-info { background: var(--info-soft); border-color: rgba(47,111,237,0.3); color: #2560cf; }
[data-theme="dark"] .alert-success, [data-theme="dark"] .bg-success { color: #4ade80; }
[data-theme="dark"] .alert-danger, [data-theme="dark"] .bg-danger { color: #f87171; }
[data-theme="dark"] .alert-warning, [data-theme="dark"] .bg-warning { color: #fbbf24; }
[data-theme="dark"] .alert-info, [data-theme="dark"] .bg-info { color: #60a5fa; }

/* Labels / badges */
.label, .badge {
  font-weight: 600; font-size: 11px; letter-spacing: 0.02em; border-radius: 999px; padding: 3px 9px;
}
.badge { background: var(--surface-3); color: var(--ink-soft); }
.label-default { background: var(--surface-3); color: var(--ink-soft); }
.label-primary { background: var(--accent-soft); color: var(--accent-strong); }
.label-success { background: var(--ok-soft); color: #0f7a37; }
.label-danger { background: var(--danger-soft); color: #b91c1c; }
.label-warning { background: var(--warn-soft); color: #a85c05; }
.label-info { background: var(--info-soft); color: #2560cf; }

/* Pagination / breadcrumb / wells / tabs */
.pagination > li > a, .pagination > li > span {
  color: var(--ink-soft); background: var(--surface); border-color: var(--border);
}
.pagination > .active > a, .pagination > .active > a:hover, .pagination > .active > span {
  background: var(--accent); border-color: var(--accent); color: var(--brand-ink);
}
.breadcrumb { background: transparent; padding: 0; margin-bottom: 16px; color: var(--muted); }
.breadcrumb > .active { color: var(--ink); }
.well { background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); box-shadow: none; }
.nav-tabs { border-bottom: 1px solid var(--border); }
.nav-tabs > li > a { color: var(--muted); border: 0; border-bottom: 2px solid transparent; border-radius: 0; margin-right: 4px; }
.nav-tabs > li > a:hover { background: transparent; color: var(--ink); border-bottom-color: var(--border-strong); }
.nav-tabs > li.active > a, .nav-tabs > li.active > a:hover, .nav-tabs > li.active > a:focus {
  color: var(--accent-strong); background: transparent; border: 0; border-bottom: 2px solid var(--accent);
}
.list-group-item { background: var(--surface); border-color: var(--border); color: var(--ink-soft); }
.progress { background: var(--surface-3); border-radius: 999px; box-shadow: none; height: 8px; }
.progress-bar { background: var(--accent); }

/* Focus-visible ring for keyboard users */
a:focus-visible, button:focus-visible, .btn:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}

/* 6. AUTH (LOGIN) ---------------------------------------------------------- */
body.auth-page {
  background: var(--bg);
  background-image:
    radial-gradient(60% 50% at 50% -10%, var(--accent-soft), transparent 70%);
  min-height: 100vh; padding-top: 0 !important;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
}
body.auth-page .container { width: 100%; flex: 0 0 auto; }
body.auth-page .auth-footer { flex: 0 0 auto; }
body.auth-page form#loginForm {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 34px 32px 30px;
  max-width: 420px;
  margin: 24px auto;
}
body.auth-page .auth-brand { text-align: center; margin-bottom: 22px; }
body.auth-page .auth-brand img { width: 64px; height: 64px; object-fit: contain; }
body.auth-page .auth-brand .auth-name {
  display: block; font-family: var(--font-display); font-weight: 600; font-size: 19px; margin-top: 12px; color: var(--ink);
}
body.auth-page .auth-brand .auth-sub { color: var(--muted); font-size: 13px; }
body.auth-page form#loginForm h2 { font-size: 20px; font-weight: 600; margin: 0 0 4px; }
body.auth-page form#loginForm hr { margin: 16px 0; }
body.auth-page .theme-toggle.auth-theme {
  position: fixed; top: 18px; right: 18px;
  background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow-sm);
}
body.auth-page .auth-footer { text-align: center; color: var(--muted); font-size: 12.5px; margin-top: 18px; }
body.auth-page .auth-footer a { color: var(--muted); text-decoration: underline; }
body.auth-page .auth-footer a:hover { color: var(--accent); }

/* 7. RESPONSIVE ------------------------------------------------------------ */
@media (max-width: 991px) {
  :root { --sidebar-w: 280px; }
  .app-sidebar { transform: translateX(-100%); box-shadow: var(--shadow-lg); }
  body.sidebar-open .app-sidebar { transform: translateX(0); }
  body.sidebar-open .sidebar-backdrop { opacity: 1; visibility: visible; }
  .sidebar-close { display: inline-flex; }
  .app-topbar { left: 0; padding: 0 12px; }
  .topbar-burger { display: inline-flex; align-items: center; justify-content: center; }
  .topbar-brand-mobile { display: inline-flex; }
  #page-wrapper { margin-left: 0; padding: calc(var(--topbar-h) + 16px) 16px 32px; }
  body.sidebar-open { overflow: hidden; }
}
@media (max-width: 767px) {
  .topbar-dropdown > a.dropdown-toggle .username-label { display: none; }
  body.auth-page form#loginForm { padding: 26px 20px; }
  .huge { font-size: 26px; }
  #page-wrapper { padding-left: 12px; padding-right: 12px; }
  .panel-body { padding: 16px; }
  /* Make wide DATA tables clearly horizontally scrollable on phones. EXCLUDE
   * form-layout tables (any .table-responsive that wraps inputs) — forcing those to
   * 560px made simple add/edit forms overflow the box and scroll sideways. */
  .table-responsive:not(:has(.form-control)) > .table { min-width: 560px; }
  /* Info tables (Customer Details, Account Statement) are label|value display tables,
   * not wide data grids — let them fit the phone instead of the 560px min-width, and
   * wrap long values. Identified by their inner h2.modal-title (same as the spacing rule). */
  .table-responsive:has(h2.modal-title) > .table { min-width: 0; width: 100%; }
  .table-responsive:has(h2.modal-title) > .table > tbody > tr > td,
  .table-responsive:has(h2.modal-title) > .table > tr > td { white-space: normal; word-break: break-word; }
  /* keep the narrow label column on one line; only the value column wraps */
  .table-responsive:has(h2.modal-title) > .table > tbody > tr > td:first-child,
  .table-responsive:has(h2.modal-title) > .table > tr > td:first-child { white-space: nowrap; word-break: normal; }
}

/* ── Status tone cells ─────────────────────────────────────────────────────────
 * Order / site / payment / order-status cells (orders list + customer detail orders
 * table). These were coloured by an INLINE background-color set in JS (a fixed pale
 * pastel), which the dark theme could not reach — light text on light pastel = unread-
 * able. Now applied as classes: light mode keeps the exact original pales; dark mode
 * uses a readable dark tint + matching text. `!important` mirrors the old inline win
 * (so the table-stripe doesn't override the status colour on alternate rows). */
.st-tone-danger  { background-color: #f2dede !important; }
.st-tone-warning { background-color: #fcf8e3 !important; }
.st-tone-success { background-color: #dff0d8 !important; }
.st-tone-info    { background-color: #d9edf7 !important; }
/* SOLID (opaque) dark tints — a semi-transparent rgba composites over the row stripe,
 * so odd (striped) rows looked washed-out vs even rows. Solid colours render identically. */
[data-theme="dark"] .st-tone-danger  { background-color: #38222a !important; color: #fca5a5 !important; font-weight: 600; }
[data-theme="dark"] .st-tone-warning { background-color: #37311c !important; color: #fcd34d !important; font-weight: 600; }
[data-theme="dark"] .st-tone-success { background-color: #1c322a !important; color: #86efac !important; font-weight: 600; }
[data-theme="dark"] .st-tone-info    { background-color: #1e2e44 !important; color: #93c5fd !important; font-weight: 600; }

/* Bootstrap contextual table rows/cells in dark mode — the decorative thead `.warning`
 * trash headers, the `.success` Grand-Total rows in preview modals, and `.info` divider
 * rows render as pale pastels otherwise. Give them a readable dark surface. */
[data-theme="dark"] .table > thead > tr.warning > th,
[data-theme="dark"] .table > tbody > tr.warning > td,
[data-theme="dark"] .table > tbody > tr.warning > th { background-color: var(--surface-3) !important; color: var(--ink-soft) !important; }
[data-theme="dark"] .table > tbody > tr.success > td,
[data-theme="dark"] .table > tbody > tr.success > th,
[data-theme="dark"] .table > tbody > tr > td.success { background-color: #1c322a !important; color: var(--ink) !important; }
[data-theme="dark"] .table > tbody > tr.info > td,
[data-theme="dark"] .table > tbody > tr > td.info { background-color: var(--surface-2) !important; color: var(--ink) !important; }
[data-theme="dark"] .table > tbody > tr > td.danger { background-color: #38222a !important; color: var(--ink) !important; }
[data-theme="dark"] .table > tbody > tr > td.warning { background-color: #37311c !important; color: var(--ink) !important; }

/* PWA update toast */
.app-toast {
  position: fixed; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(140%);
  background: var(--ink); color: var(--surface);
  padding: 12px 18px; border-radius: 999px; box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: 14px; font-size: 13.5px; font-weight: 500;
  z-index: 2000; transition: transform 0.35s cubic-bezier(0.4,0,0.2,1); max-width: 92vw;
}
/* Re-assert flex on the shown state — Bootstrap's `.show{display:block!important}`
 * (the toast also carries the `.show` class) was overriding the flex layout. */
.app-toast.show { transform: translateX(-50%) translateY(0); display: flex !important; }
.app-toast button {
  background: var(--accent); color: var(--brand-ink); border: 0;
  padding: 6px 14px; border-radius: 999px; font-weight: 700; font-size: 12.5px; cursor: pointer;
}
.app-toast button.app-toast-close {
  background: transparent; color: var(--surface); opacity: 0.6;
  padding: 2px 4px; font-size: 18px; font-weight: 400; line-height: 1;
}
.app-toast button.app-toast-close:hover { opacity: 1; }
/* Phones: the centered 999px pill wraps the message into a lumpy blob — switch to a
 * clean full-width bottom bar (rectangular, text left / actions right, bigger taps). */
@media (max-width: 767px) {
  .app-toast {
    display: flex; flex-wrap: wrap; align-items: center; justify-content: center;
    left: 12px; right: 12px; max-width: none;
    transform: translateY(170%);
    border-radius: var(--radius); padding: 12px 14px; gap: 8px 10px;
  }
  .app-toast.show { transform: translateY(0); }
  .app-toast > span { line-height: 1.35; text-align: center; }
  .app-toast > button { flex: 0 0 auto; padding: 9px 16px; font-size: 13px; }
  .app-toast button.app-toast-close { padding: 6px 6px; font-size: 22px; }
}

/* 8. MOTION / A11Y --------------------------------------------------------- */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.001ms !important; animation-duration: 0.001ms !important; }
}

/* 9. DARK-MODE HARDENING --------------------------------------------------- */
/* Third-party widgets + dashboard cards that bake in LIGHT colors (inline styles,
 * dashboard.css, SVG charts) which design tokens can't reach. ALL rules are
 * scoped to [data-theme="dark"] so LIGHT mode (the locked reference) is untouched. */

/* --- ApexCharts (dashboard Revenue/Expenses/Invoices/Taxes lines + donuts) --- */
[data-theme="dark"] .apexcharts-gridRow,
[data-theme="dark"] .apexcharts-grid-row { fill: transparent !important; }          /* kills the gray stripe bands */
[data-theme="dark"] .apexcharts-gridline,
[data-theme="dark"] .apexcharts-grid line { stroke: var(--border) !important; }
[data-theme="dark"] .apexcharts-text,
[data-theme="dark"] .apexcharts-xaxis-label,
[data-theme="dark"] .apexcharts-yaxis-label { fill: var(--muted) !important; }
[data-theme="dark"] .apexcharts-title-text { fill: var(--ink) !important; }
[data-theme="dark"] .apexcharts-legend-text { color: var(--ink-soft) !important; }
[data-theme="dark"] .apexcharts-tooltip,
[data-theme="dark"] .apexcharts-tooltip.apexcharts-theme-light {
  background: var(--surface-2) !important; border-color: var(--border) !important;
  color: var(--ink) !important; box-shadow: var(--shadow-md) !important;
}
[data-theme="dark"] .apexcharts-tooltip-title {
  background: var(--surface-3) !important; border-color: var(--border) !important; color: var(--ink-soft) !important;
}
[data-theme="dark"] .apexcharts-tooltip-text { color: var(--ink) !important; }
[data-theme="dark"] .apexcharts-menu {
  background: var(--surface-2) !important; border-color: var(--border) !important; color: var(--ink) !important;
}
[data-theme="dark"] .apexcharts-menu-item:hover { background: var(--surface-3) !important; }
[data-theme="dark"] .apexcharts-toolbar svg { fill: var(--muted) !important; }

/* --- Morris (legacy donut/legend, where still used) --- */
[data-theme="dark"] .morris-legend-text { fill: var(--ink-soft) !important; color: var(--ink-soft) !important; }
[data-theme="dark"] .morris-hover { background: var(--surface-2) !important; border-color: var(--border) !important; color: var(--ink) !important; }

/* --- Dashboard stat cards (.dash-card variants from dashboard.css) --- */
/* Flat dark surface; keep the coloured left edge (slightly brightened for dark). */
[data-theme="dark"] .dash-card { background: var(--surface) !important; border-color: var(--border); box-shadow: var(--shadow-sm); }
[data-theme="dark"] .dash-card.dash-revenue   { border-left-color: #6fb582 !important; }
[data-theme="dark"] .dash-card.dash-expense   { border-left-color: #d98a8a !important; }
[data-theme="dark"] .dash-card.dash-invoice   { border-left-color: #7196cc !important; }
[data-theme="dark"] .dash-card.dash-tax       { border-left-color: #c6a46e !important; }
[data-theme="dark"] .dash-card.dash-pending   { border-left-color: #c19c74 !important; }
[data-theme="dark"] .dash-card.dash-info      { border-left-color: #6fadbe !important; }
[data-theme="dark"] .dash-card.dash-secondary { border-left-color: #8e8ea0 !important; }
/* the inline "0% ~" black span inside the cards -> readable on dark */
[data-theme="dark"] .dash-card span[style*="color: black"],
[data-theme="dark"] .dash-card span[style*="color:black"] { color: var(--muted) !important; }

/* --- Inline white/grey boxes (stable classes/ids) the tokens can't reach --- */
[data-theme="dark"] #reportrange { background: var(--surface-2) !important; color: var(--ink) !important; border: 1px solid var(--border) !important; }
[data-theme="dark"] .quotation-checklist,
[data-theme="dark"] .dc-checklist { background: var(--surface-2) !important; border-color: var(--border) !important; color: var(--ink) !important; }
[data-theme="dark"] .stats-card { background: var(--surface) !important; border-color: var(--border) !important; }
[data-theme="dark"] .user-agent-display,
[data-theme="dark"] #modal-details { background: var(--surface-2) !important; color: var(--ink) !important; border-color: var(--border) !important; }

/* --- Date-range picker popup (dashboard) --- */
[data-theme="dark"] .daterangepicker { background: var(--surface) !important; border-color: var(--border) !important; color: var(--ink); box-shadow: var(--shadow-lg) !important; }
[data-theme="dark"] .daterangepicker:after { border-bottom-color: var(--surface) !important; }
[data-theme="dark"] .daterangepicker:before { border-bottom-color: var(--border) !important; }
[data-theme="dark"] .daterangepicker .calendar-table { background: var(--surface) !important; border-color: var(--border) !important; }
[data-theme="dark"] .daterangepicker td.available:hover,
[data-theme="dark"] .daterangepicker th.available:hover { background: var(--surface-3) !important; }
[data-theme="dark"] .daterangepicker td.off,
[data-theme="dark"] .daterangepicker td.off.in-range { background: var(--surface-2) !important; color: var(--faint) !important; }
[data-theme="dark"] .daterangepicker td.in-range { background: var(--accent-soft) !important; color: var(--ink) !important; }
[data-theme="dark"] .daterangepicker td.active,
[data-theme="dark"] .daterangepicker td.active:hover { background: var(--accent) !important; color: #fff !important; }
[data-theme="dark"] .daterangepicker .ranges li { color: var(--ink-soft) !important; }
[data-theme="dark"] .daterangepicker .ranges li:hover { background: var(--surface-3) !important; }
[data-theme="dark"] .daterangepicker .ranges li.active { background: var(--accent) !important; color: #fff !important; }
[data-theme="dark"] .daterangepicker select,
[data-theme="dark"] .daterangepicker input { background: var(--surface-2) !important; color: var(--ink) !important; border-color: var(--border) !important; }

/* ============================================================================
 * Dark-mode theming for remaining third-party widgets that ship their own LIGHT
 * stylesheet (FullCalendar v3 calendar.css, Select2 CDN). Light theme untouched.
 * ========================================================================== */

/* FullCalendar v3 (calendar.php) — calendar.css hardcodes #fff popover, #eee headers,
 * #fcf8e3 today, #ddd grid lines, and light gradient toolbar buttons. */
[data-theme="dark"] .fc-unthemed th,
[data-theme="dark"] .fc-unthemed td,
[data-theme="dark"] .fc-unthemed thead,
[data-theme="dark"] .fc-unthemed tbody,
[data-theme="dark"] .fc-unthemed .fc-divider,
[data-theme="dark"] .fc-unthemed .fc-row,
[data-theme="dark"] .fc-unthemed .fc-content,
[data-theme="dark"] .fc-unthemed .fc-popover,
[data-theme="dark"] .fc-unthemed .fc-list-view,
[data-theme="dark"] .fc-unthemed .fc-list-heading td { border-color: var(--border); }
[data-theme="dark"] .fc-unthemed td.fc-today { background: var(--accent-soft); }
[data-theme="dark"] .fc-unthemed .fc-popover { background-color: var(--surface); box-shadow: var(--shadow-lg); }
[data-theme="dark"] .fc-unthemed .fc-divider,
[data-theme="dark"] .fc-unthemed .fc-popover .fc-header,
[data-theme="dark"] .fc-unthemed .fc-list-heading td { background: var(--surface-2); }
[data-theme="dark"] .fc-list-empty { background: var(--surface-2); color: var(--muted); }
[data-theme="dark"] .fc-list-item td { border-color: var(--border); }
[data-theme="dark"] .fc-list-item:hover td { background: var(--surface-2); }
[data-theme="dark"] .fc-day-number,
[data-theme="dark"] .fc-week-number { color: var(--ink-soft); }
[data-theme="dark"] .fc-unthemed .fc-disabled-day { background: transparent; }
[data-theme="dark"] .fc button,
[data-theme="dark"] .fc .fc-button,
[data-theme="dark"] .fc .fc-state-default {
  background: var(--surface-2); background-image: none;
  color: var(--ink-soft); border: 1px solid var(--border);
  text-shadow: none; box-shadow: none;
}
[data-theme="dark"] .fc .fc-state-hover,
[data-theme="dark"] .fc .fc-button:hover { background: var(--surface-3); color: var(--ink); }
[data-theme="dark"] .fc .fc-state-active,
[data-theme="dark"] .fc .fc-state-down { background: var(--accent); color: #fff; border-color: var(--accent); }
[data-theme="dark"] .fc .fc-state-disabled { color: var(--faint); opacity: .6; }

/* Select2 v4 (Lohakar calculator.php; CDN ships light CSS) */
[data-theme="dark"] .select2-container--default .select2-selection--single,
[data-theme="dark"] .select2-container--default .select2-selection--multiple {
  background: var(--surface); border-color: var(--border-strong); color: var(--ink);
}
[data-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__rendered { color: var(--ink); }
[data-theme="dark"] .select2-container--default .select2-selection__placeholder { color: var(--muted); }
[data-theme="dark"] .select2-container--default .select2-selection--single .select2-selection__arrow b { border-color: var(--muted) transparent transparent; }
[data-theme="dark"] .select2-dropdown { background: var(--surface); border-color: var(--border); box-shadow: var(--shadow-lg); }
[data-theme="dark"] .select2-container--default .select2-search--dropdown .select2-search__field {
  background: var(--surface-2); border-color: var(--border); color: var(--ink);
}
[data-theme="dark"] .select2-container--default .select2-results__option { color: var(--ink-soft); }
[data-theme="dark"] .select2-container--default .select2-results__option--highlighted[aria-selected] { background: var(--accent); color: #fff; }
[data-theme="dark"] .select2-container--default .select2-results__option[aria-selected=true] { background: var(--surface-2); color: var(--ink); }
[data-theme="dark"] .select2-container--default .select2-results__group { color: var(--muted); }
[data-theme="dark"] .select2-container--default .select2-selection--multiple .select2-selection__choice {
  background: var(--surface-2); border-color: var(--border); color: var(--ink);
}
[data-theme="dark"] .select2-container--default .select2-selection--clearable .select2-selection__clear { color: var(--muted); }

/* ── Google Maps InfoWindow content (locations.php) ──
   Google draws InfoWindow bubbles WHITE in both themes. In dark mode the page's
   light --ink cascades in by inheritance and washes out the body text (site name,
   customer details, the ~/straight-line distance boxes). The floating "Nearby
   Locations" panel is already safe (every item carries an explicit inline color),
   so only the InfoWindow — which I tag with .map-iw — needs pinning.
   Non-!important so inline-coloured icons (fa-car #1976d2, fa-location-arrow #ff9800)
   and .btn-* buttons keep their own colours. */
[data-theme="dark"] .map-iw,
[data-theme="dark"] .map-iw h4,
[data-theme="dark"] .map-iw p,
[data-theme="dark"] .map-iw strong,
[data-theme="dark"] .map-iw span { color: #1f2937; }

/* The InfoWindow's close (X) button is a mask-icon tinted by `currentColor` (and its
   span's background-color). The map stays LIGHT in both themes (operator's decision), but
   in dark mode the reskin's light `--ink` cascades into Google's chrome and turns the X
   white → invisible on the white bubble. Pin both the button colour and the span
   background dark so the X shows in dark mode (light mode was already fine). Targets
   Google's `.gm-ui-hover-effect` — revisit if the Maps API renames it (Core Rule 9). */
[data-theme="dark"] .gm-style .gm-ui-hover-effect { color: #5f6368 !important; }
[data-theme="dark"] .gm-style .gm-ui-hover-effect > span { background-color: #5f6368 !important; }

/* Add/Edit Location form — group related fields into subtle boxes so they read as units:
   [Latitude · Longitude · Use my current location] and [Image · Take a photo]. Tight
   spacing WITHIN each box, a clear gap BETWEEN them, and a light border so each group is
   visually identifiable (operator: keep lat/lng/my-location together, image/take-photo
   together). */
.loc-group {
  margin: 8px 0 18px; padding: 10px 12px 12px;
  border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2);
}
.loc-group label { display: block; margin: 10px 0 4px; }
.loc-group > label:first-child { margin-top: 0; }
.loc-group .form-control { margin-bottom: 4px; }
.loc-group .btn { margin-top: 2px; }

/* ── Item entry as a card grid (2026-07-03) ──────────────────────────────────
 * Line-item tables tagged `.mobile-card-grid` render each item as a CARD whose
 * fields flow in a responsive grid that WRAPS (multi-column on desktop → single
 * column on phones) instead of cramming ~20 columns into one horizontal row that
 * clips fields. Field labels come from the header via js/app-modern.js `labelGrid`
 * (data-label, colspan-aware); a MutationObserver keeps dynamically added rows
 * labelled. Markup + POST unchanged — presentation only, so item_*[] submission is
 * untouched. Header rows hidden; the row checkbox + Sr + remove-X float into a card
 * header. `display` on field cells is NON-!important so a page's own inline
 * display:none (e.g. a unit-column toggle) still hides fields (no empty cards).
 * Supersedes the earlier mobile-only #invoice-item-table card block (which also
 * missed dc-item-table / cn-item-table). */
/* min-width:0 defeats the `.table-responsive:not(:has(.form-control)) > .table { min-width:560px }`
 * data-grid rule: a card-grid table WITHOUT form-control cells (e.g. a read-only list like the Users
 * table) otherwise stays 560px wide and overflows a 360px phone even after card-stacking. Verified
 * live: without this the Users card-grid sits at 560px; with it, 296px and fits. Harmless to the
 * document item grids (they carry .form-control, so they were already exempt from the 560 rule). */
.mobile-card-grid, .mobile-card-grid > tbody { display: block; width: 100%; min-width: 0 !important; }
.mobile-card-grid > thead,
.mobile-card-grid > tbody > tr:has(> th) { display: none; }

.mobile-card-grid > tbody > tr:not(:has(> th)) {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 12px 14px; align-items: start;
  position: relative;
  margin: 0 0 14px; padding: 42px 16px 16px;
  border: 1px solid var(--border-strong); border-radius: 12px;
  background: var(--surface); box-shadow: var(--shadow-sm);
}
.mobile-card-grid > tbody > tr > td {
  display: block; border: 0; padding: 0;
  text-align: left; white-space: normal; word-break: break-word;
}
.mobile-card-grid > tbody > tr > td[data-label]::before {
  content: attr(data-label); display: block; margin-bottom: 5px;
  font-weight: 700; font-size: 10px; letter-spacing: 0.04em; text-transform: uppercase;
  color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.mobile-card-grid .form-control { width: 100%; min-width: 0; height: 38px; }
.mobile-card-grid textarea.form-control { height: auto; }
/* <select> inherits a 30px line-height from the legacy theme → value sits above
   centre in the 38px card box; match the text inputs (1.5) so it centres vertically */
.mobile-card-grid select.form-control { line-height: 1.5; }

/* card header strip: [☐] Item N ......................... [✕] */
.mobile-card-grid > tbody > tr > td:has(input[type="checkbox"]) {
  position: absolute; top: 12px; left: 15px; width: auto; padding: 0;
}
.mobile-card-grid > tbody > tr > td:has(input[type="checkbox"])::before { content: none; }
.mobile-card-grid > tbody > tr > td:has(input[type="checkbox"]) input[type="checkbox"] {
  width: 16px; height: 16px; margin: 0; vertical-align: middle;
}
/* Sr number cell → "Item N" title. Identify it structure-agnostically (NOT by fixed
   position — forms without a leading checkbox have Sr as the first cell, so nth-child(2)
   grabbed the Item Name input and overlapped the grid):
     (a) the cell right after a leading checkbox (quotations), or
     (b) the first cell when it is display-only (invoice/DC/CN/purchase — no checkbox). */
.mobile-card-grid > tbody > tr > td:has(input[type="checkbox"]) + td,
.mobile-card-grid > tbody > tr > td:first-child:not(:has(input)):not(:has(select)):not(:has(textarea)):not(:has(button)):not(:has(a)) {
  position: absolute; top: 11px; width: auto; padding: 0;
  font-weight: 700; font-size: 13px; color: var(--ink);
}
.mobile-card-grid > tbody > tr > td:has(input[type="checkbox"]) + td { left: 40px; }
.mobile-card-grid > tbody > tr > td:first-child:not(:has(input)):not(:has(select)):not(:has(textarea)):not(:has(button)):not(:has(a)) { left: 15px; }
.mobile-card-grid > tbody > tr > td:has(input[type="checkbox"]) + td::before,
.mobile-card-grid > tbody > tr > td:first-child:not(:has(input)):not(:has(select)):not(:has(textarea)):not(:has(button)):not(:has(a))::before {
  content: "Item "; display: inline; margin: 0;
  font-size: 13px; font-weight: 700; letter-spacing: 0; text-transform: none; color: var(--muted);
}
.mobile-card-grid > tbody > tr > td:has(.remove_row),
.mobile-card-grid > tbody > tr > td:has(.remove_old_row) {
  position: absolute; top: 9px; right: 12px; width: auto; padding: 0;
}
.mobile-card-grid > tbody > tr > td:has(.remove_row)::before,
.mobile-card-grid > tbody > tr > td:has(.remove_old_row)::before { content: none; }

/* phones: one field per row, larger inputs (legibility) */
@media (max-width: 560px) {
  .mobile-card-grid > tbody > tr:not(:has(> th)) { grid-template-columns: 1fr; padding-top: 40px; }
  .mobile-card-grid .form-control { height: 44px; font-size: 15px; }
}

/* ── .stack-on-mobile — MOBILE-ONLY row-to-card stacking for LIST/DATA tables (2026-07-22) ──
 * Unlike `.mobile-card-grid` (which is a card grid at ALL widths, for item-entry forms), this class
 * leaves a plain DATA table completely UNTOUCHED on desktop and only stacks each row into a labelled
 * card at <=767px. Use it for read-only lists (Users, Roles, Employee Payments, Attendance) that must
 * stay a normal table on desktop but overflow a phone otherwise. Labels come from the thead via
 * js/app-modern.js labelGrid() (data-label). Deliberately :has()-FREE (plain thead{display:none} +
 * td::before) so it also works on an old Android WebView with no :has() support. Presentation only —
 * markup, ids and POST field names untouched. */
@media (max-width: 767px) {
  .stack-on-mobile { display: block; width: 100%; min-width: 0 !important; border: 0; }
  .stack-on-mobile > thead { display: none; }
  .stack-on-mobile > tbody { display: block; width: 100%; }
  .stack-on-mobile > tbody > tr {
    display: block; margin: 0 0 12px; padding: 10px 12px;
    border: 1px solid var(--border); border-radius: 10px; background: var(--surface);
  }
  .stack-on-mobile > tbody > tr > td {
    display: block; width: auto !important; border: 0 !important;
    padding: 5px 0; text-align: left !important; white-space: normal; word-break: break-word;
  }
  .stack-on-mobile > tbody > tr > td[data-label]::before {
    content: attr(data-label); display: block; margin-bottom: 2px;
    font-weight: 600; font-size: 10.5px; letter-spacing: 0.05em;
    text-transform: uppercase; color: var(--muted);
  }
  .stack-on-mobile > tbody > tr > td:empty { display: none; }
  .stack-on-mobile .form-control { width: 100%; font-size: 16px; height: 44px; }
  .stack-on-mobile textarea.form-control { height: auto; }

  /* .mobile-wrap-cells — for a single-row STAT STRIP (e.g. useractivity "Creates 5 Updates 3…"):
   * let the cells flow inline and WRAP to more lines instead of forcing a wide row that scrolls. */
  .mobile-wrap-cells, .mobile-wrap-cells > tbody, .mobile-wrap-cells > tbody > tr { display: block; min-width: 0 !important; }
  .mobile-wrap-cells > tbody > tr > td { display: inline-block; border: 0 !important; padding: 3px 12px 3px 0; white-space: nowrap; }
}
