:root {
  /* Market Day theme: soft green-grey ground, deep indigo, marigold. */
  --primary: #2B2A8C;
  --primary-dark: #1F1E6B;
  --on-primary: #FFFFFF;
  --primary-bg: #E7E7F7;
  --focus-ring: rgba(43, 42, 140, 0.18);
  --sun: #F4B23E;
  --sun-bg: #FFF1D6;
  --sun-text: #7A4B00;
  --success: #1D6B3F;
  --success-bg: #DDF1E4;
  --danger: #A8261A;
  --danger-bg: #FBE3E0;
  --danger-border: #F2C2BC;
  --warning: #9A5300;
  --bg: #EEF1EA;
  --card-bg: #FFFFFF;
  --border: #DCE1D5;
  --text: #1A1F16;
  --text-muted: #4F5848;
  --sidebar-bg: #EEF1EA;
  --sidebar-border: #DCE1D5;
  --nav-hover: #E2E7DB;
  --th-bg: #F6F8F3;
  --input-bg: #FFFFFF;
  --row-hover: #F6F8F3;
  --kpi-bg: #23226F;
  --sidebar-w: 248px;
  --font-body: 'Figtree', 'Noto Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-display: 'Bricolage Grotesque', 'Noto Sans', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}
:root[data-theme="dark"] {
  --primary: #9E9CFF;
  --primary-dark: #B7B5FF;
  --on-primary: #12140F;
  --primary-bg: #26254F;
  --focus-ring: rgba(158, 156, 255, 0.25);
  --sun-bg: #3A2E12;
  --sun-text: #F7C873;
  --success: #7BD6A0;
  --success-bg: #183323;
  --danger: #FF8A7A;
  --danger-bg: #3A1D19;
  --danger-border: #5C2A23;
  --warning: #F7C873;
  --bg: #12140F;
  --card-bg: #1C1F18;
  --border: #30352B;
  --text: #EEF1E8;
  --text-muted: #A9B2A0;
  --sidebar-bg: #12140F;
  --sidebar-border: #262A21;
  --nav-hover: #252920;
  --th-bg: #22261E;
  --input-bg: #171A13;
  --row-hover: #22261E;
  --kpi-bg: #1F1E4A;
}
:root[data-theme="dark"] body { color: var(--text); }

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: var(--app-font, var(--font-body));
  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 var(--focus-ring);
}
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 var(--focus-ring);
}
.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: var(--primary-bg); color: var(--primary); font-weight: 600; }

/* ---------- 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, .field textarea { width: 100%; }
.field textarea { resize: vertical; min-height: 64px; }
.field input[type=checkbox], .field input[type=radio] { width: auto; }
.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;
  /* Fixed to the window height, so on short screens the nav must scroll or
     the bottom items (Settings, Users, theme, sign-out area) are unreachable. */
  overflow-y: auto;
  overscroll-behavior: contain;
}
.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; }

/* ---------- Branches ---------- */
.branch-switcher { margin: 0 12px 10px; padding: 10px 12px 12px; background: var(--card-bg); border: 1px solid var(--sidebar-border); border-radius: 14px; }
.branch-switcher-label { display: block; font-size: 10.5px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--text-muted); margin-bottom: 6px; }
.branch-switcher .custom-select-trigger { min-height: 36px; font-size: 13px; font-weight: 600; }
.branch-locked { display: flex; align-items: center; gap: 7px; font-size: 13px; font-weight: 600; color: var(--text); }
.branch-locked svg { width: 15px; height: 15px; color: var(--primary); flex-shrink: 0; }
.branch-pill { display: inline-flex; align-items: center; gap: 5px; margin-left: 10px; padding: 3px 10px 3px 8px; border-radius: 999px; background: var(--nav-hover); color: var(--text); font-size: 12px; font-weight: 600; white-space: nowrap; max-width: 40vw; min-width: 0; flex-shrink: 0; }
.branch-pill span { overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.branch-pill svg { width: 13px; height: 13px; color: var(--primary); flex-shrink: 0; }
/* The title side of the top bar gives way (ellipsis) before the sign-out
   side does, so a branch pill can never push Logout off a phone screen. */
.topbar > div:first-child { min-width: 0; flex: 1 1 auto; }
.topbar h2 { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.topbar .user-chip { flex-shrink: 0; margin-left: 10px; }
@media (max-width: 560px) {
  .topbar h2 { font-size: 16px; }
  .branch-pill { flex-shrink: 1; max-width: 34vw; margin-left: 8px; font-size: 11.5px; }
}
.branch-note { margin: -4px 0 14px; padding: 8px 12px; border-radius: 8px; background: var(--th-bg); border: 1px solid var(--border); font-size: 12.5px; color: var(--text-muted); line-height: 1.45; }
.branch-note b { color: var(--text); }
.hint-block { margin: 10px 0 0; font-size: 12.5px; color: var(--text-muted); line-height: 1.5; }
tr.clickable-row { cursor: pointer; }
tr.clickable-row:hover td { background: var(--row-hover); }

/* ---------- Money accounts & business position ---------- */
.money-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 12px; }
.money-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 14px 16px; display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.money-card-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; font-size: 13px; font-weight: 600; color: var(--text); }
.money-card-head span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.money-card .value { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.position-list { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.position-list td { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 14px; }
.position-list td.num { text-align: right; white-space: nowrap; padding-left: 12px; }
.position-list tr.sub td { padding-left: 14px; font-size: 13px; color: var(--text-muted); }
.position-list tr.sub td.num { color: var(--text-muted); }
.position-list tr.total td { border-bottom: none; border-top: 2px solid var(--border); font-weight: 700; padding-top: 12px; }
.position-list tr.muted td { color: var(--text-muted); }
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 10px; flex-wrap: wrap; }
.card-head h3 { margin: 0; font-size: 15px; }
.card-head .text-muted { font-size: 12px; }
.period-bar { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; }
.period-bar .field { margin: 0; }
.period-bar input[type="date"] { min-width: 150px; }
.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; }
.badge-blue { background: #dbeafe; color: #1e40af; }
:root[data-theme="dark"] .badge-blue { background: #1e3a5f; color: #bfdbfe; }

/* ---------- 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"] .badge-green { background: #173d2a; color: #86efac; }
:root[data-theme="dark"] .badge-orange { background: #452a14; color: #fdba74; }
:root[data-theme="dark"] .badge-red { background: #4a1d1d; color: #fca5a5; }
: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; } }

/* ---------- Segmented choice (e.g. theme) ---------- */
.segmented { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; border: 1px solid var(--border); border-radius: 12px; background: var(--th-bg); }
.seg-opt { position: relative; cursor: pointer; margin: 0; }
.seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.seg-opt span { display: block; padding: 7px 14px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--text-muted); transition: background 0.15s ease, color 0.15s ease; }
.seg-opt input:checked + span { background: var(--card-bg); color: var(--primary); box-shadow: 0 1px 3px rgba(15,23,42,0.12), inset 0 0 0 1.5px var(--primary); }
.seg-opt input:focus-visible + span { outline: 2px solid var(--primary); outline-offset: 1px; }

/* ---------- Sidebar sections ---------- */
.nav-groups { display: flex; flex-direction: column; gap: 2px; padding-bottom: 6px; }
.nav-group-head {
  display: flex; align-items: center; justify-content: space-between; width: calc(100% - 24px);
  margin: 10px 12px 2px; padding: 4px 14px; background: none; border: none; border-radius: 8px;
  color: var(--text-muted); font-size: 11px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; opacity: 0.75;
}
.nav-group-head:hover { opacity: 1; background: var(--nav-hover); }
.nav-group-head[data-locked] { cursor: default; }
.nav-group-head[data-locked]:hover { background: none; }
.nav-group-head:focus-visible, .nav-item:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
.nav-group-chevron { width: 14px; height: 14px; transition: transform 0.18s ease; transform: rotate(-90deg); }
.nav-group.open .nav-group-chevron { transform: none; }
.nav-group-head[data-locked] .nav-group-chevron { opacity: 0; }
.nav-group-items { display: none; }
.nav-group.open .nav-group-items { display: block; }
.nav-groups .nav-item { padding: 9px 14px; margin: 2px 12px; }

/* ---------- Inventory: variations ---------- */
.btn-link { background: none; border: none; padding: 0 6px 0 0; color: var(--text-muted); font-size: 13px; cursor: pointer; }
.btn-link:hover { color: var(--text); }
.variant-row td { background: var(--th-bg); font-size: 13.5px; }
.row-muted td { opacity: 0.6; }

.row-menu { position: fixed; z-index: 1000; min-width: 170px; padding: 6px; background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; box-shadow: 0 12px 28px rgba(15,23,42,0.16); }
.row-menu button { display: block; width: 100%; text-align: left; padding: 8px 12px; border: none; background: none; border-radius: 8px; font-size: 14px; color: var(--text); }
.row-menu button:hover, .row-menu button:focus-visible { background: var(--nav-hover); outline: none; }
.row-menu button.danger { color: var(--danger); }
[data-more], [data-vmore] { min-width: 34px; padding-left: 8px; padding-right: 8px; font-weight: 700; letter-spacing: 1px; }

.set-row { display: grid; grid-template-columns: minmax(110px, 160px) 1fr auto; gap: 10px; align-items: end; margin-bottom: 4px; }
.set-row .field { margin-bottom: 10px; }
.set-row .set-remove { margin-bottom: 12px; }

.unit-row { display: grid; grid-template-columns: minmax(80px, 1fr) auto 70px auto minmax(90px, 1fr) auto; gap: 6px; align-items: center; margin-bottom: 6px; font-size: 13px; }
.unit-row input { padding: 7px 9px !important; }

/* Inventory: let the item column wrap so row actions stay on screen */
#inv-tbody td:first-child { white-space: normal; min-width: 180px; max-width: 300px; }
#inv-tbody td:first-child .badge { margin-top: 2px; }

/* =====================================================================
   Market Day theme layer. Same screens, same data - only the look.
   ===================================================================== */
h1, h2, h3, .topbar h2, .modal h3, .section-title, .card-head h3, .brand-text,
.stat-card .value, .ztile-value, .money-card .value, .gauge-score, .empty-title {
  font-family: var(--app-font, var(--font-display));
  letter-spacing: -0.01em;
}
.stat-card .value, .ztile-value, .money-card .value { letter-spacing: -0.02em; font-variant-numeric: tabular-nums; }

/* Inputs: a little taller, softer corners */
input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea, .custom-select-trigger {
  border-radius: 12px; min-height: 42px;
}
textarea { min-height: 64px; }
.custom-select-trigger:hover { border-color: var(--text-muted); }
.field label { color: var(--text); font-weight: 700; }

/* Buttons: pill shaped, bold */
.btn { border-radius: 999px; padding: 10px 18px; font-weight: 700; min-height: 40px; transition: background 0.15s ease, opacity 0.15s ease; }
.btn-sm { padding: 6px 13px; min-height: 34px; font-size: 13px; }
.btn-primary { color: var(--on-primary); }
.btn-outline { background: var(--card-bg); border: 1.5px solid var(--border); }
.btn-outline:hover { border-color: var(--text-muted); }
.btn-danger { background: var(--danger-bg); color: var(--danger); border: 1.5px solid var(--danger-border); }
.btn-danger-solid { background: var(--danger); color: #fff; }
.btn-danger-solid:hover { background: var(--danger); opacity: 0.9; }
:root[data-theme="dark"] .btn-danger-solid { color: #12140F; }
:root[data-theme="dark"] .btn-danger { background: var(--danger-bg); border-color: var(--danger-border); }
.btn-primary:focus-visible, .btn:focus-visible { outline: 3px solid var(--focus-ring); outline-offset: 2px; }
.error-msg { background: var(--danger-bg); color: var(--danger); border-radius: 12px; }

/* Cards and tables sit on the ground without hard outlines */
.card, .table-wrap, .money-card, .ztile, .branch-switcher { border-color: transparent; }
.card { border-radius: 22px; }
.table-wrap { border-radius: 20px; }
.money-card { border-radius: 18px; }
th { background: var(--th-bg); letter-spacing: 0.04em; }
.modal { border-radius: 24px; }
.modal-overlay { background: rgba(18, 20, 15, 0.55); }

/* Badges */
.badge { padding: 4px 10px; font-size: 11.5px; }
.badge-green { background: var(--success-bg); color: var(--success); }
.badge-red { background: var(--danger-bg); color: var(--danger); }
.badge-orange { background: var(--sun-bg); color: var(--sun-text); }
.badge-blue { background: var(--primary-bg); color: var(--primary); }
.badge-gray { background: var(--th-bg); color: var(--text-muted); }
:root[data-theme="dark"] .badge-green { background: var(--success-bg); color: var(--success); }
:root[data-theme="dark"] .badge-red { background: var(--danger-bg); color: var(--danger); }
:root[data-theme="dark"] .badge-orange { background: var(--sun-bg); color: var(--sun-text); }
:root[data-theme="dark"] .badge-blue { background: var(--primary-bg); color: var(--primary); }
:root[data-theme="dark"] .badge-gray { background: var(--th-bg); color: var(--text-muted); }
.chg.up { background: var(--success-bg); color: var(--success); }
.chg.down { background: var(--danger-bg); color: var(--danger); }

/* Sidebar */
.sidebar { border-right: none; padding: 10px 0; }
.brand-mark { background: var(--primary); border-radius: 12px; }
.brand-text { font-size: 16px; }
.nav-item { color: var(--text); border-radius: 12px; min-height: 42px; }
.nav-item:hover { background: var(--nav-hover); }
.nav-item.active { background: var(--primary); color: var(--on-primary); font-weight: 700; box-shadow: none; }
.nav-group-head { color: var(--text-muted); opacity: 1; }
.branch-switcher { background: var(--card-bg); border-radius: 16px; }
.theme-toggle { border-radius: 999px; border-color: var(--border); color: var(--text); }
.sidebar-footer { border-top-color: var(--border); }
.avatar { background: var(--sun); color: #1A1F16; }

/* Top bar blends into the page */
.topbar { background: var(--bg); border-bottom: none; padding: 16px 24px 8px; }
.topbar h2 { font-size: 24px; font-weight: 800; }
:root[data-theme="dark"] .topbar { border-bottom: none; }
.branch-pill { background: var(--card-bg); }

/* Dashboard tiles: no side stripes; the first tile carries the colour */
.ztile { border-radius: 22px; }
.ztile::before { display: none; }
.ztile.a-indigo { background: var(--primary); color: var(--on-primary); }
.ztile.a-indigo .ztile-label, .ztile.a-indigo .ztile-sub { color: var(--on-primary); opacity: 0.85; }
.ztile.a-rose { background: var(--sun-bg); }
.ztile:hover { box-shadow: none; transform: none; }
.zkpi { background: var(--kpi-bg); border-radius: 22px; }
.segmented { border-radius: 999px; border-color: var(--border); background: var(--card-bg); }
.seg-opt span { border-radius: 999px; }
.seg-opt input:checked + span { background: var(--primary); color: var(--on-primary); box-shadow: none; }

/* Login: solid indigo with the marigold mark */
.auth { background: #2B2A8C; --primary: #2B2A8C; --primary-dark: #1F1E6B; --on-primary: #FFFFFF; --primary-bg: #E7E7F7; --focus-ring: rgba(43, 42, 140, 0.18); --danger: #A8261A; --danger-bg: #FBE3E0; --th-bg: #F6F8F3; }
.auth .login-card { border-radius: 24px; border: none; }
.login-card h1 { font-family: var(--font-display); font-size: 26px; font-weight: 800; }
.auth-brand h2 { font-family: var(--font-display); font-size: 38px; letter-spacing: -0.02em; }
.auth .btn-primary { background: #2B2A8C; color: #fff; }
.auth .avatar, .auth .brand-mark { background: #F4B23E; color: #1A1F16; }

.toast { border-radius: 14px; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
:root[data-theme="dark"] .toast.error, :root[data-theme="dark"] .toast.success { color: #12140F; }
.spinner { border-color: var(--border); border-top-color: var(--primary); }
.empty-icon { color: var(--border); }

/* ---------- Phones ---------- */
.tabbar { display: none; }
@media (max-width: 768px) {
  .tabbar {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 35;
    background: var(--card-bg); border-radius: 22px 22px 0 0;
    box-shadow: 0 -1px 0 var(--border), 0 -8px 24px rgba(18, 20, 15, 0.06);
    padding: 4px 4px calc(6px + env(safe-area-inset-bottom));
  }
  .tab-item {
    flex: 1 1 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    min-height: 54px; border: 0; background: none; color: var(--text-muted);
    font-size: 11.5px; font-weight: 700; border-radius: 14px; padding: 4px 0;
  }
  .tab-item .nav-svg { width: 22px; height: 22px; }
  .tab-item.active { color: var(--primary); }
  .tab-item:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
  .content { padding-bottom: 104px; }
  .toast { bottom: 92px; left: 16px; right: 16px; }
  .topbar { padding: 12px 16px 6px; }
  .topbar h2 { font-size: 20px; }
  /* Bigger tap targets; 16px text stops phones zooming into fields */
  input:not([type=checkbox]):not([type=radio]):not([type=file]), select, textarea, .custom-select-trigger { font-size: 16px; min-height: 46px; }
  .btn { min-height: 44px; }
  .btn-sm { min-height: 38px; }
  .nav-item { min-height: 46px; }
  /* Pop-ups rise from the bottom and use the full width */
  .modal-overlay { padding: 24px 0 0; align-items: flex-end; }
  .modal { border-radius: 24px 24px 0 0; max-width: 100%; padding: 22px 18px calc(24px + env(safe-area-inset-bottom)); }
}

/* ---------- SabiLedger admin console ---------- */
.admin-auth { background: #1A1F16; }
.admin-auth .login-card { text-align: left; }
.admin-mark, .admin-brand { width: 44px; height: 44px; border-radius: 14px; background: #1A1F16; color: #F4B23E; display: flex; align-items: center; justify-content: center; margin-bottom: 14px; }
.admin-mark svg, .admin-brand svg { width: 24px; height: 24px; }
.admin-brand { width: 36px; height: 36px; margin: 0; border-radius: 12px; }
:root[data-theme="dark"] .admin-brand { background: #F4B23E; color: #1A1F16; }
.admin-auth .login-card h1, .admin-auth .login-card p.sub { text-align: left; }
.otp-input { letter-spacing: 6px; font-size: 20px !important; text-align: center; }
.admin-banner { display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; margin-bottom: 16px; border-radius: 16px; background: var(--primary-bg); color: var(--text); font-size: 13.5px; line-height: 1.5; }
.admin-banner svg { width: 18px; height: 18px; flex-shrink: 0; color: var(--primary); margin-top: 1px; }
.admin-tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(200px, 100%), 1fr)); gap: 12px; }
.admin-tile { background: var(--card-bg); border-radius: 22px; padding: 18px 20px; min-width: 0; }
.admin-tile-label { font-size: 13.5px; font-weight: 600; color: var(--text-muted); }
.admin-tile-value { font-family: var(--app-font, var(--font-display)); font-size: 28px; font-weight: 800; letter-spacing: -0.02em; margin-top: 4px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.admin-tile-note { font-size: 12.5px; font-weight: 600; color: var(--text-muted); margin-top: 2px; }
.admin-tile.primary { background: var(--primary); }
.admin-tile.ink { background: var(--text); }
.admin-tile.primary div, .admin-tile.primary .admin-tile-label, .admin-tile.primary .admin-tile-note { color: var(--on-primary); }
.admin-tile.ink div, .admin-tile.ink .admin-tile-label, .admin-tile.ink .admin-tile-note { color: var(--bg); }
.admin-biz-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; flex-wrap: wrap; margin: 16px 0; }
.admin-biz-head h1 { margin: 0; font-size: 30px; font-weight: 800; letter-spacing: -0.02em; }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 16px; margin-top: 16px; align-items: start; }
.admin-feed-row { display: grid; grid-template-columns: 10px 1fr; gap: 12px; padding: 9px 0; border-top: 1px solid var(--border); font-size: 14px; }
.admin-feed-row:first-child { border-top: none; }
.admin-dot { width: 10px; height: 10px; border-radius: 999px; background: var(--primary); margin-top: 5px; }
.admin-team-row { display: flex; justify-content: space-between; gap: 12px; padding: 10px 0; border-top: 1px solid var(--border); font-size: 14px; }
.admin-team-row:first-of-type { border-top: none; }
.btn-svg { width: 16px; height: 16px; }
