:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --danger: #dc2626;
  --warning: #d97706;
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --sidebar-bg: #f5f6fa;
  --sidebar-border: #ebedf2;
  --nav-hover: #e9edf4;
  --th-bg: #f8fafc;
  --input-bg: #ffffff;
  --row-hover: #f8fafc;
  --sidebar-w: 220px;
}
:root[data-theme="dark"] {
  --primary: #3b82f6;
  --primary-dark: #2563eb;
  --bg: #0b1220;
  --card-bg: #131c2e;
  --border: #253248;
  --text: #e5edf7;
  --text-muted: #93a4bd;
  --sidebar-bg: #0e1626;
  --sidebar-border: #1e293b;
  --nav-hover: #1b2740;
  --th-bg: #172033;
  --input-bg: #0f1a2b;
  --row-hover: #172033;
}
:root[data-theme="dark"] body { color: var(--text); }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
}

a { text-decoration: none; color: inherit; }
button { font-family: inherit; cursor: pointer; }
/* Consistent form controls */
input:not([type=checkbox]):not([type=radio]):not([type=file]),
select,
textarea {
  font-family: inherit;
  font-size: 14px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--text);
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:not([type=checkbox]):not([type=radio]):not([type=file]):focus,
select:focus,
textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
select {
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
  padding-right: 34px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%2364748b' stroke-width='1.7' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
}
input[type=checkbox] {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}

/* Native date/month pickers render their calendar-picker icon and popup
   using OS/browser chrome, not page CSS - without telling the browser which
   scheme is active, that chrome defaults to light and becomes unreadable
   (dark icon on a dark input, or a light popup that clashes) once the app
   is in dark mode. color-scheme is the correct fix: it's the same signal
   the browser uses for every other native control (scrollbars, etc). */
input[type=date], input[type=month], input[type=time], input[type=datetime-local] {
  color-scheme: light;
}
:root[data-theme="dark"] input[type=date],
:root[data-theme="dark"] input[type=month],
:root[data-theme="dark"] input[type=time],
:root[data-theme="dark"] input[type=datetime-local] {
  color-scheme: dark;
}

/* ---------- Custom dropdown (progressive enhancement over <select>) ---------- */
.custom-select { position: relative; width: 100%; }
.custom-select-native {
  position: absolute; inset: 0; width: 100%; height: 100%;
  opacity: 0; pointer-events: none;
}
.custom-select-trigger {
  width: 100%; display: flex; align-items: center; justify-content: space-between; gap: 8px;
  font-family: inherit; font-size: 14px; text-align: left;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--input-bg); color: var(--text); cursor: pointer;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.custom-select-trigger:hover { border-color: #94a3b8; }
.custom-select.open .custom-select-trigger,
.custom-select-native:focus + .custom-select-trigger {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}
.custom-select-trigger:disabled { opacity: 0.6; cursor: not-allowed; }
.custom-select-label { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.custom-select-chevron { flex-shrink: 0; color: var(--text-muted); display: flex; transition: transform 0.15s ease; }
.custom-select.open .custom-select-chevron { transform: rotate(180deg); }
.custom-select-listbox {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 60;
  background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 12px 28px rgba(15,23,42,0.16);
  max-height: 260px; overflow-y: auto; padding: 6px;
  opacity: 0; transform: translateY(-6px) scale(0.98); pointer-events: none;
  transition: opacity 0.14s ease, transform 0.14s ease;
}
.custom-select-listbox.drop-up { top: auto; bottom: calc(100% + 6px); transform: translateY(6px) scale(0.98); }
.custom-select.open .custom-select-listbox { opacity: 1; transform: none; pointer-events: auto; }
.custom-select-option {
  padding: 9px 10px; border-radius: 8px; font-size: 14px; cursor: pointer;
  color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.custom-select-option:hover, .custom-select-option.active { background: var(--nav-hover); }
.custom-select-option.selected { background: rgba(37,99,235,0.1); color: var(--primary); font-weight: 600; }
:root[data-theme="dark"] .custom-select-option.selected { background: rgba(59,130,246,0.18); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(1100px 550px at 50% -10%, #e7edff, #f4f6f9 62%);
}
.login-card {
  background: #fff;
  border-radius: 18px;
  padding: 38px 34px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 14px 44px rgba(15,23,42,0.10);
  border: 1px solid #eef1f6;
}
.login-card h1 {
  font-size: 22px;
  margin: 0 0 4px;
  text-align: center;
}
.login-card p.sub {
  color: var(--text-muted);
  margin: 0 0 24px;
  font-size: 14px;
  text-align: center;
}

/* ---------- Loading spinner ---------- */
.loading-state { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 64px 20px; gap: 14px; }
.spinner { width: 40px; height: 40px; border-radius: 50%; border: 3px solid #e2e8f0; border-top-color: var(--primary); animation: spin 0.75s linear infinite; }
.loading-text { color: var(--text-muted); font-size: 13px; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Auth / login screen ---------- */
/* This screen is a fixed brand treatment (blue gradient + a white card) that
   was never designed to have a dark variant - but its text/input colors
   still read from the shared theme variables, which DO flip when the viewer
   has dark mode on (a real, pre-login-reachable state: it's read from
   localStorage before any login happens). That left pale-on-white headings
   and a dark input box stranded inside the always-white card. Re-pinning the
   variables to their light values here, scoped to .auth, makes the whole
   screen immune to the app's dark-mode toggle instead of half-applying it. */
.auth {
  --text: #1e293b;
  --text-muted: #64748b;
  --border: #e2e8f0;
  --input-bg: #ffffff;
  --card-bg: #ffffff;
  --nav-hover: #e9edf4;
  /* `color` is inherited, and body already resolved it to the dark-mode
     value before this override point in the tree - re-declaring it here
     (not just the custom properties above) forces everything under .auth
     that doesn't set its own color to re-resolve against the light values. */
  color: var(--text);
  min-height: 100vh;
  position: relative;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 64px;
  padding: 40px;
  background: linear-gradient(145deg, #1e3a8a 0%, #2563eb 52%, #6d5efc 100%);
}
.auth-pattern { position: absolute; inset: 0; width: 100%; height: 100%; opacity: 0.13; pointer-events: none; }
.auth-brand { position: relative; z-index: 1; color: #fff; max-width: 400px; animation: zFadeUp 0.6s ease; }
.auth-brand .storefront { width: 150px; height: auto; margin-bottom: 22px; }
.auth-brand h2 { font-size: 30px; line-height: 1.15; margin: 0 0 12px; font-weight: 800; }
.auth-brand > p { font-size: 15px; line-height: 1.55; opacity: 0.9; margin: 0 0 22px; }
.auth-feats { list-style: none; margin: 0; padding: 0; }
.auth-feats li { position: relative; padding: 8px 0 8px 30px; font-size: 14.5px; opacity: 0.96; }
.auth-feats li::before { content: ''; position: absolute; left: 0; top: 8px; width: 19px; height: 19px; border-radius: 50%; background: rgba(255,255,255,0.22); }
.auth-feats li::after { content: ''; position: absolute; left: 6px; top: 12px; width: 5px; height: 9px; border: solid #fff; border-width: 0 2px 2px 0; transform: rotate(45deg); }
.auth-form { position: relative; z-index: 1; width: 400px; max-width: 100%; animation: zFadeUp 0.6s ease 0.05s both; }
.auth-form .login-card { box-shadow: 0 24px 60px rgba(15,23,42,0.28); }
@media (max-width: 880px) {
  .auth { padding: 20px; gap: 0; }
  .auth-brand { display: none; }
}
.field { margin-bottom: 16px; }
.field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
.field input, .field select { width: 100%; }
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-weight: 600;
  font-size: 14px;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-block { width: 100%; }
.btn-outline { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-danger { background: #fef2f2; color: var(--danger); border: 1px solid #fecaca; }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: #b91c1c; }
.btn-sm { padding: 6px 10px; font-size: 13px; }
.error-msg { background: #fef2f2; color: var(--danger); padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 16px; }
.hint { font-size: 12px; color: var(--text-muted); margin-top: 16px; text-align: center; }

/* ---------- App shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  color: var(--text);
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; bottom: 0; left: 0;
  transition: transform 0.2s ease;
  z-index: 40;
  border-right: 1px solid var(--sidebar-border);
  padding: 8px 0;
}
.sidebar .brand {
  padding: 14px 16px 18px;
  display: flex;
  align-items: center;
  gap: 11px;
}
.brand-mark {
  width: 36px; height: 36px; border-radius: 10px; flex-shrink: 0; overflow: hidden;
  background: linear-gradient(140deg, #2563eb, #6366f1);
  color: #fff; display: flex; align-items: center; justify-content: center;
}
.brand-mark svg { width: 21px; height: 21px; }
.brand-mark img { width: 100%; height: 100%; object-fit: cover; }
.brand-text { display: flex; flex-direction: column; font-weight: 700; font-size: 15px; color: var(--text); line-height: 1.2; min-width: 0; }
.brand-text small { font-weight: 400; font-size: 11px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  margin: 3px 12px;
  border-radius: 14px;
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.nav-item:hover { background: var(--nav-hover); color: var(--text); }
.nav-item.active { background: var(--card-bg); color: var(--primary); font-weight: 600; box-shadow: 0 2px 8px rgba(15,23,42,0.07); }
.nav-svg { width: 19px; height: 19px; flex-shrink: 0; }
.sidebar-backdrop { display: none; }
.sidebar-footer { margin-top: auto; padding: 12px 16px; border-top: 1px solid var(--sidebar-border); display: flex; align-items: center; gap: 10px; }
.sidebar-footer .avatar { width: 30px; height: 30px; font-size: 12px; }
.sidebar-footer-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.35; }
.sidebar-footer-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer-role { font-size: 11px; color: var(--text-muted); text-transform: capitalize; }

.main {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}
.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 30;
}
.topbar h2 { margin: 0; font-size: 18px; }
.topbar .user-chip { display: flex; align-items: center; gap: 10px; font-size: 13px; }
.topbar .greeting { color: var(--text-muted); }
.topbar .greeting b { color: var(--text); font-weight: 600; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(140deg, #2563eb, #6366f1);
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 13px; text-transform: uppercase;
}
@media (max-width: 560px) { .topbar .user-chip .uname { display: none; } }
.menu-toggle { display: none; background: none; border: none; font-size: 20px; margin-right: 12px; color: var(--text); }

.content { padding: 20px 24px 60px; flex: 1; }

/* ---------- Cards & grids ---------- */
.grid { display: grid; gap: 16px; }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-2 { grid-template-columns: repeat(2, 1fr); }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 20px;
}
.stat-card .label { font-size: 12px; color: var(--text-muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; }
.stat-card .value { font-size: 24px; font-weight: 700; margin-top: 6px; }
.stat-card .sub { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.stat-card.accent-green .value { color: var(--success); }
.stat-card.accent-red .value { color: var(--danger); }
.stat-card.accent-blue .value { color: var(--primary); }
.stat-card.accent-orange .value { color: var(--warning); }

.section-title { font-size: 15px; font-weight: 700; margin: 28px 0 12px; }
.section-title:first-child { margin-top: 0; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; background: var(--card-bg); border: 1px solid var(--border); border-radius: 16px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); white-space: nowrap; }
th { background: var(--th-bg); font-weight: 600; color: var(--text-muted); font-size: 12px; text-transform: uppercase; }
tr:last-child td { border-bottom: none; }
td.num, th.num { text-align: right; }

.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 11px; font-weight: 700; }
.badge-green { background: #dcfce7; color: #166534; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-orange { background: #ffedd5; color: #9a3412; }
.badge-gray { background: #f1f5f9; color: #475569; }

/* ---------- Forms / Modals ---------- */
.toolbar { display: flex; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.toolbar .filters { display: flex; gap: 8px; flex-wrap: wrap; }
.search-input { min-width: 220px; }

.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 40px 16px; overflow-y: auto; z-index: 100;
  animation: overlayIn 0.18s ease;
}
.modal-overlay .modal { animation: modalIn 0.24s cubic-bezier(0.2, 0.8, 0.2, 1); }
.modal-overlay.closing { animation: overlayOut 0.18s ease forwards; }
.modal-overlay.closing .modal { animation: modalOut 0.16s ease forwards; }
@keyframes overlayIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes overlayOut { from { opacity: 1; } to { opacity: 0; } }
@keyframes modalIn { from { opacity: 0; transform: translateY(14px) scale(0.97); } to { opacity: 1; transform: none; } }
@keyframes modalOut { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(8px) scale(0.98); } }
@media (prefers-reduced-motion: reduce) {
  .modal-overlay, .modal-overlay .modal, .modal-overlay.closing, .modal-overlay.closing .modal { animation: none; }
}
.modal {
  background: var(--card-bg); border-radius: 20px; padding: 24px; width: 100%; max-width: 520px;
}
.modal h3 { margin: 0 0 18px; font-size: 17px; }
.modal .form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; }

.line-items-table { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -4px; padding: 0 4px; }
.line-items-table table { min-width: 480px; }
.line-items-table input, .line-items-table select { width: 100%; padding: 6px 8px !important; border-radius: 8px; min-width: 60px; }
.text-muted { color: var(--text-muted); }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.mt-0 { margin-top: 0; }
.toast {
  position: fixed; bottom: 20px; right: 20px; background: #111827; color: #fff;
  padding: 12px 18px; border-radius: 8px; font-size: 13px; z-index: 200; box-shadow: 0 8px 20px rgba(0,0,0,0.2);
}
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
.empty-state { text-align: center; padding: 48px 20px; color: var(--text-muted); }
.empty-icon { width: 54px; height: 54px; margin: 0 auto 14px; color: #cbd5e1; }
.empty-icon svg { width: 100%; height: 100%; }
.empty-title { font-size: 15px; font-weight: 600; color: var(--text); }
.empty-sub { font-size: 13px; margin-top: 4px; max-width: 340px; margin-left: auto; margin-right: auto; line-height: 1.5; }

/* ---------- Responsive tables -> cards on small screens ---------- */
@media (max-width: 640px) {
  .table-wrap:not(.line-items-table) table thead { display: none; }
  .table-wrap:not(.line-items-table) table,
  .table-wrap:not(.line-items-table) table tbody { display: block; width: 100%; }
  .table-wrap:not(.line-items-table) table tr {
    display: block; padding: 6px 12px 10px;
    border-bottom: 1px solid var(--border);
  }
  .table-wrap:not(.line-items-table) table tr:last-child { border-bottom: none; }
  .table-wrap:not(.line-items-table) table td {
    display: flex; justify-content: space-between; align-items: center; gap: 14px;
    padding: 7px 0; border: none; white-space: normal; text-align: right;
  }
  .table-wrap:not(.line-items-table) table td::before {
    content: attr(data-label); font-weight: 600; color: var(--text-muted);
    font-size: 12px; text-align: left; flex-shrink: 0;
  }
  .table-wrap:not(.line-items-table) table td[colspan] { display: block; text-align: center; }
  .table-wrap:not(.line-items-table) table td[colspan]::before { display: none; }
  .table-wrap:not(.line-items-table) table td:not([data-label]) { justify-content: flex-end; flex-wrap: wrap; }
}

/* ---------- Responsive ---------- */
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main { margin-left: 0; }
  .menu-toggle { display: inline-block; }
  .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .modal .form-row { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .topbar { padding: 12px 16px; }
  /* A real element (not just a box-shadow) so it can actually capture the
     tap: closes the menu and swallows the click instead of letting it pass
     through to whatever button happens to be underneath. */
  .sidebar-backdrop {
    display: block;
    position: fixed; inset: 0;
    background: rgba(0,0,0,0.4);
    z-index: 39;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.2s ease;
  }
  .sidebar.open + .sidebar-backdrop { opacity: 1; pointer-events: auto; }
}
@media (max-width: 480px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
  .toolbar { flex-direction: column; align-items: stretch; }
  .search-input { width: 100%; }
}

/* ---------- Redesigned dashboard ---------- */
@keyframes zFadeUp { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes zFadeIn { from { opacity: 0; } to { opacity: 1; } }

.zgrid-anim { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.zcard { opacity: 0; animation: zFadeUp 0.55s ease forwards; }
.zcard:nth-child(1) { animation-delay: 0.02s; }
.zcard:nth-child(2) { animation-delay: 0.10s; }
.zcard:nth-child(3) { animation-delay: 0.18s; }
.zcard:nth-child(4) { animation-delay: 0.26s; }
.zcard:nth-child(5) { animation-delay: 0.34s; }

.ztiles { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; }
.ztile { border: 1px solid var(--border); border-radius: 16px; padding: 16px; position: relative; overflow: hidden; background: var(--card-bg); transition: transform 0.15s ease, box-shadow 0.15s ease; }
.ztile:hover { transform: translateY(-2px); box-shadow: 0 8px 20px rgba(15,23,42,0.07); }
.ztile::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; }
.ztile.a-indigo::before { background: #6366f1; }
.ztile.a-violet::before { background: #8b5cf6; }
.ztile.a-green::before { background: #22c55e; }
.ztile.a-rose::before { background: #ec4899; }
.ztile-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.ztile-label { font-size: 12px; color: var(--text-muted); font-weight: 600; }
.ztile-value { font-size: 24px; font-weight: 800; margin-top: 8px; letter-spacing: -0.5px; }
.ztile-sub { font-size: 11px; color: var(--text-muted); margin-top: 4px; }
.chg { font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 999px; white-space: nowrap; }
.chg.up { background: #dcfce7; color: #166534; }
.chg.down { background: #fee2e2; color: #991b1b; }

.zexp { display: flex; align-items: center; gap: 18px; }
.zexp-chart { width: 170px; flex-shrink: 0; }
.zexp-legend { flex: 1; min-width: 0; }
.leg-row { display: flex; align-items: center; gap: 10px; padding: 6px 0; font-size: 13px; opacity: 0; animation: zFadeIn 0.5s ease forwards; }
.leg-dot { width: 11px; height: 11px; border-radius: 3px; flex-shrink: 0; }
.leg-name { flex: 1; color: var(--text); }
.leg-pct { font-weight: 700; }

.zgauge { display: flex; flex-direction: column; align-items: center; }
.gauge-svg { width: 100%; max-width: 260px; }
.gauge-readout { text-align: center; margin-top: -6px; }
.gauge-score { font-size: 26px; font-weight: 800; }
.gauge-label { font-size: 13px; color: var(--text-muted); }

.zkpi { background: linear-gradient(150deg, #0f2417, #0b1120 72%); color: #e5e7eb; border: none; border-radius: 24px; }
.zkpi strong { color: #fff; }
.kpi-row { display: flex; align-items: center; justify-content: space-between; padding: 13px 2px; border-bottom: 1px solid rgba(255,255,255,0.08); font-size: 14px; opacity: 0; animation: zFadeIn 0.5s ease forwards; }
.kpi-row:last-child { border-bottom: none; }
.kpi-val { font-weight: 700; color: #fff; }

@media (max-width: 900px) {
  .zgrid-anim { grid-template-columns: 1fr; }
  .ztiles { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .ztiles { grid-template-columns: 1fr; }
  .zexp { flex-direction: column; }
  .zexp-chart { width: 200px; }
}
@media (prefers-reduced-motion: reduce) {
  .zcard, .leg-row, .kpi-row { animation: none; opacity: 1; }
  #gauge-needle { transition: none !important; }
}

/* ---------- Row hover + theme toggle ---------- */
.table-wrap:not(.line-items-table) table tbody tr { transition: background 0.12s ease; }
@media (min-width: 641px) {
  .table-wrap:not(.line-items-table) table tbody tr:hover { background: var(--row-hover); }
}
.theme-toggle {
  display: flex; align-items: center; gap: 9px; width: calc(100% - 24px);
  margin: 0 12px 8px; padding: 9px 12px; border-radius: 12px;
  background: transparent; border: 1px solid var(--sidebar-border);
  color: var(--text-muted); font-size: 13px; font-weight: 500; cursor: pointer;
  transition: background 0.15s ease, color 0.15s ease;
}
.theme-toggle:hover { background: var(--nav-hover); color: var(--text); }
.theme-toggle svg { width: 17px; height: 17px; }

/* Dark-mode tweaks for elements that read poorly on dark */
:root[data-theme="dark"] .btn-danger { background: rgba(220,38,38,0.14); border-color: rgba(220,38,38,0.35); }
:root[data-theme="dark"] .badge-gray { background: #24324a; color: #aebfd6; }
:root[data-theme="dark"] .ztile:hover { box-shadow: 0 8px 22px rgba(0,0,0,0.35); }
:root[data-theme="dark"] .topbar { border-bottom-color: var(--border); }

.sidebar-bottom { margin-top: auto; }

/* ---------- Skeleton shimmer ---------- */
.skel { position: relative; overflow: hidden; background: var(--border); border-radius: 8px; }
.skel::after { content: ''; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, rgba(255,255,255,0.45), transparent); animation: shimmer 1.3s infinite; }
:root[data-theme="dark"] .skel::after { background: linear-gradient(90deg, transparent, rgba(255,255,255,0.07), transparent); }
@keyframes shimmer { 100% { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .skel::after { animation: none; } }
