/* ─── Reset & Variables ─────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #0b0d13;
  --surface: #141720;
  --surface-2: #1a1e2b;
  --surface-3: #212638;
  --border: #252a3a;
  --border-light: #2e3447;
  --accent: #5b7fff;
  --accent-2nd: #8b6bff;
  --accent-dim: rgba(91, 127, 255, 0.15);
  --accent-2: #00d4aa;
  --accent-2-dim: rgba(0, 212, 170, 0.12);
  --warn: #f59e0b;
  --warn-dim: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.12);
  --success: #22c55e;
  --success-dim: rgba(34, 197, 94, 0.12);
  --text: #e8ecf4;
  --text-2: #98a2b8;
  --text-3: #666f87;
  --sidebar-w: 232px;
  --radius: 10px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.24);
  --shadow-md: 0 8px 24px rgba(0,0,0,0.28);
  --mono: 'JetBrains Mono', monospace;
  --sans: 'Inter', system-ui, sans-serif;
}

html[data-theme="light"] {
  --bg: #f2f4f9;
  --surface: #ffffff;
  --surface-2: #f5f7fb;
  --surface-3: #eaeef6;
  --border: #e7eaf3;
  --border-light: #d8dded;
  --accent: #4f6ef7;
  --accent-2nd: #7c5cff;
  --accent-dim: rgba(79, 110, 247, 0.1);
  --accent-2: #00967a;
  --accent-2-dim: rgba(0, 150, 122, 0.1);
  --warn: #b45309;
  --warn-dim: rgba(180, 83, 9, 0.1);
  --danger: #dc2626;
  --danger-dim: rgba(220, 38, 38, 0.1);
  --success: #16a34a;
  --success-dim: rgba(22, 163, 74, 0.1);
  --text: #1a2033;
  --text-2: #5b6478;
  --text-3: #8891a5;
  --shadow-sm: 0 1px 2px rgba(30,41,80,0.06);
  --shadow-md: 0 12px 28px rgba(30,41,80,0.08);
}

html, body { height: 100%; font-family: var(--sans); background: var(--bg); color: var(--text); font-size: 14px; }
body { transition: background 0.15s ease, color 0.15s ease; }
::selection { background: var(--accent); color: #fff; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 20px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: var(--text-3); }

/* ─── Layout ────────────────────────────────────────────────────── */
.app-layout { display: flex; height: 100vh; overflow: hidden; }

/* ─── Sidebar ───────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  overflow-x: hidden;
}
.sidebar::-webkit-scrollbar { width: 6px; }

.sidebar-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 18px 16px;
  border-bottom: 1px solid var(--border);
  position: relative;
}

.hamburger-btn, .sidebar-close-btn, .sidebar-backdrop { display: none; }

.brand-logo {
  width: 100%;
  max-width: 164px;
  height: auto;
  background: #ffffff;
  border-radius: 12px;
  padding: 10px 12px;
  display: block;
  box-shadow: var(--shadow-sm);
}

.brand-mark {
  width: 32px; height: 32px;
  background: var(--accent);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
  font-weight: 700; font-size: 16px; color: #fff;
  flex-shrink: 0;
}

.brand-name { font-weight: 700; font-size: 15px; display: block; line-height: 1.2; }
.brand-sub { font-size: 10px; color: var(--text-3); letter-spacing: 0.08em; text-transform: uppercase; display: block; }

.sidebar-nav { flex: 1; padding: 14px 10px; }

.nav-section { margin-bottom: 18px; }
.nav-section:last-child { margin-bottom: 0; }

.nav-label {
  font-size: 10px; font-weight: 700; letter-spacing: 0.09em;
  text-transform: uppercase; color: var(--text-3);
  padding: 0 10px; display: block; margin-bottom: 6px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: var(--radius);
  color: var(--text-2); text-decoration: none;
  font-size: 13.5px; font-weight: 500;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  margin-bottom: 2px;
  position: relative;
}
.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.65; transition: opacity 0.15s; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item:hover svg { opacity: 1; }
.nav-item.active {
  background: linear-gradient(90deg, var(--accent-dim), transparent);
  color: var(--accent); font-weight: 600;
}
.nav-item.active::before {
  content: ''; position: absolute; left: -10px; top: 50%; transform: translateY(-50%);
  width: 3px; height: 18px; border-radius: 0 4px 4px 0;
  background: linear-gradient(180deg, var(--accent), var(--accent-2nd));
}
.nav-item.active svg { opacity: 1; }

.sidebar-footer { padding: 12px; border-top: 1px solid var(--border); }
.seed-btn {
  display: block; text-align: center; padding: 7px 12px;
  border: 1px dashed var(--border-light); border-radius: var(--radius);
  color: var(--text-3); font-size: 12px; text-decoration: none;
  transition: all 0.15s;
}
.seed-btn:hover { color: var(--text-2); border-color: var(--text-3); }

.user-chip { display: flex; align-items: center; gap: 10px; padding: 10px 8px; border-top: 1px solid var(--border); margin-bottom: 8px; }
.user-avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-2nd));
  color: #fff; display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700;
}
.user-chip-body { min-width: 0; flex: 1; }
.user-chip-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-chip-role { font-size: 11px; color: var(--text-3); }

/* ─── Main Content ──────────────────────────────────────────────── */
.main-content { flex: 1; display: flex; flex-direction: column; overflow: hidden; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 28px;
  height: 64px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
  position: sticky; top: 0; z-index: 50;
}

.page-title { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }

.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar-right { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }
.topbar-right .btn, .topbar-right form { flex: 0 0 auto; }

.content-area { flex: 1; overflow-y: auto; padding: 28px; }
.content-area::-webkit-scrollbar { width: 8px; }

/* ─── Theme toggle switch ───────────────────────────────────────── */
.theme-toggle {
  display: inline-flex; align-items: center; gap: 6px;
  width: 46px; height: 26px; padding: 3px;
  border-radius: 999px; border: 1px solid var(--border-light);
  background: var(--surface-2); cursor: pointer; flex-shrink: 0;
  position: relative;
}
.theme-toggle-knob {
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent); color: #fff;
  display: flex; align-items: center; justify-content: center;
  transition: transform 0.15s ease;
  transform: translateX(0);
}
.theme-toggle-knob svg { width: 12px; height: 12px; }
html[data-theme="light"] .theme-toggle-knob { transform: translateX(20px); }

/* ─── Two-column split layouts (used on order/restock/edit/etc. pages) ──── */
.split-layout { display: grid; grid-template-columns: 1fr 340px; gap: 18px; align-items: start; }
.split-layout.split-380 { grid-template-columns: 1fr 380px; }
.split-layout.split-even { grid-template-columns: 1fr 1fr; }
.split-layout.split-reverse { grid-template-columns: 340px 1fr; }
.split-layout > * { min-width: 0; } /* grid items default to min-width:auto and won't shrink otherwise */
.dashboard-grid > *, .detail-grid > * { min-width: 0; }


.flash-messages { margin-bottom: 20px; }
.flash {
  padding: 10px 14px; border-radius: var(--radius);
  font-size: 13.5px; margin-bottom: 8px;
}
.flash-success { background: var(--success-dim); color: var(--success); border: 1px solid rgba(34,197,94,0.2); }
.flash-error { background: var(--danger-dim); color: var(--danger); border: 1px solid rgba(239,68,68,0.2); }
.flash-info { background: var(--accent-dim); color: var(--accent); border: 1px solid rgba(79,124,255,0.2); }

/* ─── Stat Cards ────────────────────────────────────────────────── */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-bottom: 26px; }

.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 18px 20px;
  position: relative; overflow: hidden;
  box-shadow: var(--shadow-sm);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

.stat-icon {
  width: 36px; height: 36px; border-radius: 11px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 14px;
}
.stat-icon svg { width: 18px; height: 18px; }
.stat-card.blue .stat-icon { background: var(--accent-dim); color: var(--accent); }
.stat-card.green .stat-icon { background: var(--success-dim); color: var(--success); }
.stat-card.yellow .stat-icon { background: var(--warn-dim); color: var(--warn); }
.stat-card.red .stat-icon { background: var(--danger-dim); color: var(--danger); }
.stat-card.teal .stat-icon { background: var(--accent-2-dim); color: var(--accent-2); }

.stat-label { font-size: 11.5px; font-weight: 600; letter-spacing: 0.03em; color: var(--text-3); margin-bottom: 6px; }
.stat-value { font-size: 25px; font-weight: 700; line-height: 1.15; letter-spacing: -0.01em; }
.stat-value.mono { font-family: var(--mono); }
.stat-sub { font-size: 11.5px; color: var(--text-3); margin-top: 5px; }

/* ─── Tables ────────────────────────────────────────────────────── */
.table-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.table-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  gap: 10px; flex-wrap: wrap;
}
.table-title { font-weight: 700; font-size: 14px; letter-spacing: -0.01em; }

table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; padding: 11px 18px;
  font-size: 10.5px; font-weight: 700; letter-spacing: 0.07em;
  text-transform: uppercase; color: var(--text-3);
  background: var(--surface-2); border-bottom: 1px solid var(--border);
}
td {
  padding: 12px 18px; border-bottom: 1px solid var(--border);
  font-size: 13.5px; vertical-align: middle;
}
tr:last-child td { border-bottom: none; }
tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--surface-2); }

.mono { font-family: var(--mono); }

/* ─── Badges / Status ───────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px 4px 8px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
}
.badge::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; flex-shrink: 0;
}
.badge-pending { background: var(--warn-dim); color: var(--warn); }
.badge-dispatched { background: var(--accent-dim); color: var(--accent); }
.badge-delivered { background: var(--success-dim); color: var(--success); }
.badge-returned { background: var(--danger-dim); color: var(--danger); }
.badge-return_ho { background: var(--warn-dim); color: var(--warn); }
.badge-return_branch { background: var(--warn-dim); color: var(--warn); }
.badge-cancelled { background: var(--surface-3); color: var(--text-3); }
.badge-approved { background: var(--success-dim); color: var(--success); }
.badge-blacklist { background: var(--danger-dim); color: var(--danger); }
.badge-low { background: var(--warn-dim); color: var(--warn); }

/* ─── Buttons ───────────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 17px; border-radius: 999px;
  font-size: 13.5px; font-weight: 600; cursor: pointer;
  border: none; text-decoration: none; transition: all 0.15s;
  font-family: var(--sans); line-height: 1;
}
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2nd)); color: #fff; box-shadow: 0 4px 14px rgba(91,127,255,0.32); }
.btn-primary:hover { filter: brightness(1.08); transform: translateY(-1px); box-shadow: 0 6px 18px rgba(91,127,255,0.4); }
.btn-secondary { background: var(--surface-3); color: var(--text); border: 1px solid var(--border-light); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger-dim); color: var(--danger); border: 1px solid rgba(239,68,68,0.2); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }
.btn-sm { padding: 6px 13px; font-size: 12px; }
.btn-ghost { background: transparent; color: var(--text-2); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

/* ─── Forms ─────────────────────────────────────────────────────── */
.form-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 24px;
  max-width: 680px;
  box-shadow: var(--shadow-sm);
}
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-group.full { grid-column: 1 / -1; }
.form-label { font-size: 12px; font-weight: 600; color: var(--text-2); letter-spacing: 0.04em; }
.form-input, .form-select, .form-textarea {
  background: var(--surface-2); border: 1px solid var(--border-light);
  border-radius: var(--radius); padding: 8px 12px;
  color: var(--text); font-family: var(--sans); font-size: 13.5px;
  transition: border-color 0.15s;
  width: 100%;
  min-width: 0; /* prevent inputs from refusing to shrink inside flex rows on narrow screens */
}
.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-dim);
}
.form-textarea { resize: vertical; min-height: 80px; }
.form-select { cursor: pointer; }
.form-actions { display: flex; gap: 10px; margin-top: 20px; }

/* ── Searchable combobox — search box lives inside the opened panel ── */
.combobox { position: relative; }
.combobox-trigger {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  width: 100%; text-align: left; font-family: var(--sans); font-size: 13.5px;
  background: var(--surface-2); border: 1px solid var(--border-light);
  border-radius: var(--radius); padding: 8px 12px; color: var(--text); cursor: pointer;
}
.combobox-trigger.placeholder { color: var(--text-3); }
.combobox-trigger:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-dim); }
.combobox-trigger::after { content: '▾'; font-size: 10px; color: var(--text-3); flex-shrink: 0; }
.combobox-panel {
  /* position:fixed (top/left/width set from JS) so the panel always escapes
     any ancestor's overflow clipping — e.g. .items-table-wrap's overflow-x:auto,
     which would otherwise clip an absolutely-positioned panel's vertical extent. */
  display: none; position: fixed; z-index: 1000;
  background: var(--surface); border: 1px solid var(--border-light); border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.28); overflow: hidden;
}
.combobox-panel.open { display: block; }
.combobox-search {
  width: 100%; border: none; border-bottom: 1px solid var(--border); border-radius: 0;
  background: var(--surface-2); padding: 8px 12px; font-size: 13px; color: var(--text);
}
.combobox-search:focus { outline: none; }
.combobox-list { max-height: 220px; overflow-y: auto; }
.combobox-option { padding: 8px 12px; font-size: 13px; cursor: pointer; }
.combobox-option:hover { background: var(--surface-2); }
.combobox-option.selected { color: var(--accent); font-weight: 600; }
.combobox-empty { padding: 10px 12px; font-size: 12.5px; color: var(--text-3); }

.form-section-title {
  font-size: 12px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-3);
  padding-bottom: 10px; border-bottom: 1px solid var(--border);
  margin-bottom: 16px; margin-top: 24px;
}

/* ─── Filters bar ───────────────────────────────────────────────── */
.filter-bar {
  display: flex; align-items: center; gap: 10px;
  margin-bottom: 18px; flex-wrap: wrap;
}
.filter-bar .form-input { max-width: 260px; }
.filter-tabs { display: flex; gap: 4px; flex-wrap: wrap; }
.filter-tab {
  padding: 7px 15px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
  cursor: pointer; text-decoration: none; transition: all 0.15s;
}
.filter-tab:hover { background: var(--surface-2); color: var(--text); }
.filter-tab.active { background: linear-gradient(135deg, var(--accent), var(--accent-2nd)); color: #fff; border-color: transparent; box-shadow: 0 3px 10px rgba(91,127,255,0.3); }

/* ─── Dashboard grid ────────────────────────────────────────────── */
.dashboard-grid { display: grid; grid-template-columns: 1fr 340px; gap: 18px; margin-top: 4px; }
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
  box-shadow: var(--shadow-sm);
}
.panel-header {
  padding: 15px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.panel-title { font-weight: 700; font-size: 13.5px; letter-spacing: -0.01em; }
.panel-body { padding: 0; }
.panel-link { font-size: 12px; color: var(--accent); text-decoration: none; font-weight: 600; }
.panel-link:hover { text-decoration: underline; }

/* ─── Order items builder ───────────────────────────────────────── */
.items-table { width: 100%; border-collapse: collapse; }
.items-table-wrap { overflow-x: auto; }
.items-table th { font-size: 11px; text-transform: uppercase; color: var(--text-3); padding: 8px 10px; }
.items-table td { padding: 8px 10px; border-bottom: 1px solid var(--border); }
.items-table .form-input, .items-table .form-select { padding: 6px 10px; }
.item-row-remove { background: none; border: none; color: var(--danger); cursor: pointer; font-size: 16px; padding: 4px; }

.add-item-btn {
  margin-top: 10px; background: none; border: 1px dashed var(--border-light);
  border-radius: var(--radius); color: var(--text-3); cursor: pointer;
  padding: 8px 14px; font-size: 13px; width: 100%;
  transition: all 0.15s;
}
.add-item-btn:hover { border-color: var(--accent); color: var(--accent); }

.order-summary {
  background: var(--surface-2); border-radius: var(--radius);
  padding: 14px; margin-top: 12px;
}
.summary-row { display: flex; justify-content: space-between; padding: 4px 0; font-size: 13.5px; color: var(--text-2); }
.summary-row.total { font-weight: 700; color: var(--text); font-size: 15px; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 10px; }
.summary-row.profit { color: var(--success); }

/* ─── Detail view ───────────────────────────────────────────────── */
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.detail-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 20px;
  box-shadow: var(--shadow-sm);
}
.detail-card.full { grid-column: 1 / -1; }
.detail-card-title { font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text-3); margin-bottom: 14px; }
.detail-row { display: flex; justify-content: space-between; align-items: flex-start; padding: 7px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.detail-row:last-child { border-bottom: none; }
.detail-key { color: var(--text-3); }
.detail-val { font-weight: 500; text-align: right; max-width: 65%; }

/* ─── Profit page ───────────────────────────────────────────────── */
.profit-highlight { font-size: 32px; font-weight: 700; font-family: var(--mono); color: var(--success); }
.profit-meta { font-size: 12px; color: var(--text-3); margin-top: 4px; }

/* ─── Empty state ───────────────────────────────────────────────── */
.empty-state { padding: 60px 20px; text-align: center; color: var(--text-3); }
.empty-state h3 { font-size: 16px; color: var(--text-2); margin-bottom: 6px; }
.empty-state p { font-size: 13.5px; margin-bottom: 16px; }

/* ─── Dashboard charts (dependency-free bar / line charts) ─────── */
.charts-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 18px; }
.chart-panel-body { padding: 20px 22px 16px; }
.chart-total { font-size: 22px; font-weight: 700; letter-spacing: -0.01em; }
.chart-total-sub { font-size: 11.5px; color: var(--text-3); margin-top: 2px; margin-bottom: 16px; }

.bar-chart { display: flex; align-items: flex-end; gap: 8px; height: 130px; }
.bar-chart-col { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; gap: 6px; }
.bar-chart-value { font-size: 10.5px; color: var(--text-3); font-weight: 700; }
.bar-chart-bar {
  width: 100%; max-width: 30px; border-radius: 7px 7px 3px 3px;
  background: var(--surface-3); min-height: 4px;
  transition: transform 0.15s ease, filter 0.15s ease;
}
.bar-chart-bar.filled { background: linear-gradient(180deg, var(--accent), var(--accent-2nd)); }
.bar-chart-bar.today { background: linear-gradient(180deg, var(--accent-2), #00a884); }
.bar-chart-col:hover .bar-chart-bar { transform: scaleX(1.12); filter: brightness(1.08); }
.bar-chart-label { font-size: 11px; color: var(--text-3); font-weight: 600; margin-top: 8px; }
.bar-chart-label.active { color: var(--accent); font-weight: 700; }
.bar-chart-labels { display: flex; gap: 8px; }
.bar-chart-labels > span { flex: 1; text-align: center; }

.line-chart-labels { display: flex; justify-content: space-between; margin-top: 6px; }
.line-chart-labels > span { font-size: 11px; color: var(--text-3); font-weight: 600; }
.line-chart-labels > span.active { color: var(--accent); font-weight: 700; }

/* ─── Row avatars (initials chips for list/table rows) ─────────── */
.row-avatar {
  width: 32px; height: 32px; border-radius: 50%; flex-shrink: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: #fff;
}
.row-avatar-1 { background: linear-gradient(135deg, #5b7fff, #8b6bff); }
.row-avatar-2 { background: linear-gradient(135deg, #00d4aa, #00a884); }
.row-avatar-3 { background: linear-gradient(135deg, #f59e0b, #f97316); }
.row-avatar-4 { background: linear-gradient(135deg, #ef4444, #ec4899); }
.row-avatar-5 { background: linear-gradient(135deg, #06b6d4, #3b82f6); }

/* ─── Utils ─────────────────────────────────────────────────────── */
.text-success { color: var(--success) !important; }
.text-danger { color: var(--danger) !important; }
.text-warn { color: var(--warn) !important; }
.text-muted { color: var(--text-3); }
.text-right { text-align: right; }
.text-bold { font-weight: 600; }
.gap-8 { gap: 8px; }
.flex { display: flex; }
.flex-center { display: flex; align-items: center; }
.lkr::before { content: 'Rs '; font-size: 0.85em; opacity: 0.7; }

/* ─── Mobile (phones / narrow tablets) ──────────────────────────── */
@media (max-width: 880px) {
  html, body { font-size: 14px; }

  /* Mobile browsers (iOS Safari, Chrome) don't report a stable 100vh — it's
     sized as if the address bar/toolbar were hidden, so a fixed-height layout
     can render with its top portion sitting behind the browser's own UI.
     100dvh ("dynamic viewport height") was introduced specifically to track
     the ACTUAL visible area as the toolbar shows/hides, so the layout always
     fits the real visible space. (vh stays as a fallback for old browsers —
     dvh on the line below simply overrides it where supported.) */
  .app-layout { height: 100vh; height: 100dvh; }

  /* Sidebar becomes a slide-in drawer instead of a permanent column */
  .app-layout { position: relative; }
  .sidebar {
    position: fixed; top: 0; left: 0; height: 100%; z-index: 1000;
    width: 260px; min-width: 260px;
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    box-shadow: 2px 0 24px rgba(0,0,0,0.4);
  }
  .app-layout.sidebar-open .sidebar { transform: translateX(0); }

  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(0,0,0,0.5);
    z-index: 999; opacity: 0; pointer-events: none; transition: opacity 0.22s ease;
  }
  .app-layout.sidebar-open .sidebar-backdrop { opacity: 1; pointer-events: auto; }

  .sidebar-close-btn {
    display: flex; align-items: center; justify-content: center;
    position: absolute; top: 10px; right: 10px;
    width: 30px; height: 30px; border-radius: 50%;
    background: var(--surface-2); color: var(--text-2); border: none;
    font-size: 14px; cursor: pointer;
  }

  .hamburger-btn {
    display: flex; align-items: center; justify-content: center;
    width: 34px; height: 34px; border-radius: var(--radius);
    background: transparent; border: none; color: var(--text);
    cursor: pointer; flex-shrink: 0; margin-right: 4px;
  }
  .hamburger-btn svg { width: 20px; height: 20px; }
  .hamburger-btn:hover { background: var(--surface-2); }

  /* Topbar: stack title row + action buttons, allow wrapping, shrink padding */
  .topbar {
    height: auto; min-height: 56px;
    padding: 10px 14px;
    flex-wrap: wrap; gap: 8px;
    position: sticky; top: 0; z-index: 50;
  }
  .topbar-left { display: flex; align-items: center; min-width: 0; }
  .page-title { font-size: 15px; white-space: normal; }
  .topbar-right { width: 100%; display: flex; flex-wrap: wrap; gap: 8px; }
  .topbar-right .btn, .topbar-right form { flex: 0 0 auto; }
  .topbar-right .btn { padding: 7px 11px; font-size: 12.5px; }

  .content-area { padding: 14px; }
  .form-card, .detail-card { padding: 16px; }

  /* Two-column layouts stack into one column */
  .split-layout, .split-layout.split-380, .split-layout.split-even, .split-layout.split-reverse {
    grid-template-columns: 1fr !important;
  }
  .dashboard-grid { grid-template-columns: 1fr !important; }
  .detail-grid { grid-template-columns: 1fr !important; }

  /* Sticky sidebars inside split layouts shouldn't stick on mobile */
  [style*="sticky"] { position: static !important; top: auto !important; }

  /* Tables: scroll horizontally inside their own card instead of
     blowing out the page width */
  .table-card { overflow-x: auto; }
  .table-card table { min-width: 640px; }
  .items-table-wrap table { min-width: 560px; }

  .stat-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; }

  /* Forms: most form-grids are 2-up — collapse to 1 column */
  .form-grid { grid-template-columns: 1fr !important; }

  .btn { padding: 9px 14px; font-size: 13px; }
}

