/* =============================================
   HENISTEC CRM — Design System
   ============================================= */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

/* ── Variables (Dark — default) ────────────── */
:root {
  /* Backgrounds */
  --bg-base: #0F172A;
  --bg-surface: #1E293B;
  --bg-elevated: #1E293B;
  --bg-card: #1E293B;
  --bg-hover: #263247;
  --border: rgba(255, 255, 255, 0.08);
  --border-focus: #6366F1;

  /* Accent / Primary (Indigo) */
  --accent: #6366F1;
  --accent-dim: rgba(99, 102, 241, 0.15);
  --accent-glow: rgba(99, 102, 241, 0.3);

  /* Text */
  --text-primary: #F1F5F9;
  --text-secondary: #94A3B8;
  --text-muted: #475569;

  /* Shadows */
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.4);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.5);

  /* Status colours */
  --paid: #10B981;
  --paid-bg: rgba(16, 185, 129, 0.12);
  --delivered: #3B82F6;
  --delivered-bg: rgba(59, 130, 246, 0.12);
  --pending: #F59E0B;
  --pending-bg: rgba(245, 158, 11, 0.12);
  --scheduled: #8B5CF6;
  --scheduled-bg: rgba(139, 92, 246, 0.12);
  --dispatched: #0EA5E9;
  --dispatched-bg: rgba(14, 165, 233, 0.12);
  --cancelled: #EF4444;
  --cancelled-bg: rgba(239, 68, 68, 0.12);
  --new-order: #F97316;
  --new-order-bg: rgba(249, 115, 22, 0.12);
  --unreachable: #F43F5E;
  --unreachable-bg: rgba(244, 63, 94, 0.12);
  --abandoned: #F59E0B;
  --abandoned-bg: rgba(245, 158, 11, 0.12);

  /* Layout */
  --sidebar-w: 240px;
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.18s ease;

  /* Sidebar — always dark, no theme override */
  --sb: #0B1120;
  --sb-t: rgba(255, 255, 255, 0.55);
  --sb-ta: #fff;
  --sb-active: rgba(99, 102, 241, 0.85);
  --sb-hover: rgba(255, 255, 255, 0.07);
  --sb-border: rgba(255, 255, 255, 0.07);
}

/* ── Light Mode Overrides ───────────────────── */
[data-theme="light"] {
  --accent: #4F46E5;
  --accent-dim: rgba(79, 70, 229, 0.1);
  --accent-glow: rgba(79, 70, 229, 0.2);
  --border-focus: #4F46E5;

  --bg-base: #F1F5F9;
  --bg-surface: #ffffff;
  --bg-elevated: #F8FAFC;
  --bg-card: #ffffff;
  --bg-hover: #F1F5F9;
  --border: #E2E8F0;

  --text-primary: #0F172A;
  --text-secondary: #475569;
  --text-muted: #94A3B8;

  --shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.12);

  --paid-bg: rgba(16, 185, 129, 0.10);
  --delivered-bg: rgba(59, 130, 246, 0.10);
  --pending-bg: rgba(245, 158, 11, 0.10);
  --scheduled-bg: rgba(139, 92, 246, 0.10);
  --dispatched-bg: rgba(14, 165, 233, 0.10);
  --cancelled-bg: rgba(239, 68, 68, 0.10);
  --new-order-bg: rgba(249, 115, 22, 0.10);
  --unreachable-bg: rgba(244, 63, 94, 0.10);
  --abandoned-bg: rgba(245, 158, 11, 0.10);
}

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

html {
  font-size: 14px;
  scroll-behavior: smooth;
}

body {
  font-family: 'Inter', system-ui, sans-serif;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.5;
  overflow-x: hidden;
}

a {
  color: inherit;
  text-decoration: none;
}

button {
  cursor: pointer;
  font-family: inherit;
}

input,
select,
textarea {
  font-family: inherit;
}

ul {
  list-style: none;
}

/* ── Layout ────────────────────────────────── */
.app-wrapper {
  display: flex;
  min-height: 100vh;
  width: 100%;
}

/* ── Sidebar ───────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sb);
  border-right: 1px solid var(--sb-border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform var(--transition);
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar::-webkit-scrollbar { width: 0; }

.sidebar-logo {
  padding: 18px 16px;
  border-bottom: 1px solid var(--sb-border);
  flex-shrink: 0;
}

.sidebar-logo .logo-mark {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-icon {
  width: 34px;
  height: 34px;
  background: var(--accent);
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}

.logo-text {
  font-size: 14px;
  font-weight: 700;
  color: var(--sb-ta);
  line-height: 1.1;
}

.logo-sub {
  font-size: 10px;
  color: var(--sb-t);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.sidebar-nav {
  padding: 10px 0;
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-nav::-webkit-scrollbar { width: 0; }

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--sb-t);
  opacity: 0.5;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 14px 16px 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 16px;
  margin: 1px 8px;
  border-radius: var(--radius-sm);
  color: var(--sb-t);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  user-select: none;
}

.nav-item:hover {
  background: var(--sb-hover);
  color: var(--sb-ta);
}

.nav-item.active {
  background: var(--sb-active);
  color: var(--sb-ta);
  box-shadow: none;
}

.nav-item .nav-icon {
  width: 15px;
  height: 15px;
  flex-shrink: 0;
  opacity: 0.8;
}

.nav-item.active .nav-icon { opacity: 1; }

.nav-badge {
  margin-left: auto;
  background: var(--cancelled);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.nav-badge.amber { background: var(--abandoned); }

.sidebar-footer {
  padding: 10px 12px;
  border-top: 1px solid var(--sb-border);
  font-size: 12px;
  color: var(--sb-t);
  text-align: center;
  flex-shrink: 0;
}

/* ── Main Content ──────────────────────────── */
.main-content {
  margin-left: var(--sidebar-w);
  flex: 1;
  min-width: 0;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  height: 60px;
  padding: 0 24px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 90;
  backdrop-filter: blur(12px);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 10px;
  flex: 1;
  min-width: 0;
}

.topbar-left > div {
  min-width: 0;
  overflow: hidden;
}

.topbar-title {
  font-size: 16px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}

.page-content {
  padding: 20px;
  flex: 1;
  min-width: 0;
}

/* ── Cards ─────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}

.card:hover {
  border-color: var(--accent-dim);
  box-shadow: var(--shadow);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}

.card-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: 12px;
  color: var(--text-secondary);
  margin-top: 2px;
}

/* ── Stat Cards ────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
  gap: 12px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  position: relative;
  overflow: hidden;
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition);
}

.stat-card:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow);
  border-color: var(--accent-dim);
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 3px;
  border-radius: var(--radius) var(--radius) 0 0;
  background: var(--accent);
}

.stat-card.green::before  { background: var(--paid); }
.stat-card.blue::before   { background: var(--delivered); }
.stat-card.yellow::before { background: var(--pending); }
.stat-card.purple::before { background: var(--scheduled); }
.stat-card.cyan::before   { background: var(--dispatched); }
.stat-card.red::before    { background: var(--cancelled); }
.stat-card.orange::before { background: var(--new-order); }
.stat-card.rose::before   { background: var(--unreachable); }
.stat-card.amber::before  { background: var(--abandoned); }

.stat-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 6px;
  padding-right: 22px; /* avoid overlapping icon */
}

.stat-value {
  font-size: 20px;
  font-weight: 800;
  color: var(--text-primary);
  line-height: 1.15;
  white-space: nowrap;
}

/* ── Pagination ───────────────────────────── */
.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border-top: 1px solid var(--border);
  font-size: 13px;
  color: var(--text-secondary);
  gap: 12px;
  flex-wrap: wrap;
}

.pagination-bar .page-info {
  font-size: 12px;
  color: var(--text-muted);
}

.pagination-bar .page-controls {
  display: flex;
  align-items: center;
  gap: 6px;
}

.pagination-bar .page-btn {
  padding: 5px 12px;
  border-radius: 6px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-secondary);
  transition: all var(--transition);
}

.pagination-bar .page-btn:hover:not(:disabled) {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.pagination-bar .page-btn:disabled {
  opacity: 0.35;
  cursor: not-allowed;
}

.pagination-bar .page-btn.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

.stat-icon {
  position: absolute;
  top: 14px;
  right: 12px;
  font-size: 14px;
  opacity: 0.25;
  pointer-events: none;
  user-select: none;
}

/* ── Dashboard Grid ────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 1fr minmax(300px, 380px);
  gap: 20px;
}

/* Prevent inner tables from stretching grid columns beyond viewport */
.dashboard-grid > * {
  min-width: 0;
}

.dashboard-grid .full-width {
  grid-column: 1 / -1;
}

/* ── Revenue Cards ─────────────────────────── */
.revenue-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px;
  margin-bottom: 20px;
}

.revenue-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.revenue-card .branch {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.revenue-card .amount {
  font-size: 18px;
  font-weight: 700;
  color: var(--accent);
  margin-top: 4px;
  white-space: nowrap;
}

.revenue-card .currency {
  font-size: 11px;
  color: var(--text-muted);
}

/* ── Tables ────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

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

thead th {
  background: var(--bg-elevated);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 12px 14px;
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background var(--transition);
}

tbody tr:last-child {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--bg-hover);
}

tbody td {
  padding: 11px 14px;
  color: var(--text-primary);
  white-space: nowrap;
  vertical-align: middle;
}

td.muted {
  color: var(--text-secondary);
}

/* ── Status Badges ─────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  white-space: nowrap;
}

.badge::before {
  content: '•';
  font-size: 10px;
}

.badge-PAID {
  color: var(--paid);
  background: var(--paid-bg);
}

.badge-DELIVERED {
  color: var(--delivered);
  background: var(--delivered-bg);
}

.badge-PENDING {
  color: var(--pending);
  background: var(--pending-bg);
}

.badge-SCHEDULED {
  color: var(--scheduled);
  background: var(--scheduled-bg);
}

.badge-DISPATCHED {
  color: var(--dispatched);
  background: var(--dispatched-bg);
}

.badge-CANCELLED {
  color: var(--cancelled);
  background: var(--cancelled-bg);
}

.badge-NEW_ORDER {
  color: var(--new-order);
  background: var(--new-order-bg);
}

.badge-UNREACHABLE {
  color: var(--unreachable);
  background: var(--unreachable-bg);
}

.badge-CONFIRMED {
  color: var(--accent);
  background: var(--accent-dim);
}

/* ── Buttons ───────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 18px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  border: none;
  transition: all var(--transition);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover {
  opacity: 0.9;
  transform: translateY(-1px);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-danger {
  background: var(--cancelled-bg);
  color: var(--cancelled);
  border: 1px solid rgba(248, 81, 73, 0.2);
}

.btn-danger:hover {
  background: rgba(248, 81, 73, 0.25);
}

.btn-sm {
  padding: 5px 12px;
  font-size: 12px;
}

.btn-icon {
  padding: 7px;
  border-radius: var(--radius-sm);
}

/* ── Filter Chips ──────────────────────────── */
.filter-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 16px;
}

.chip {
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  transition: all var(--transition);
}

.chip:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.chip.active {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

/* ── Search Input ──────────────────────────── */
.search-wrapper {
  position: relative;
}

.search-wrapper .search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  font-size: 14px;
  color: var(--text-muted);
}

.search-input {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px 9px 36px;
  color: var(--text-primary);
  font-size: 13px;
  width: 240px;
  transition: border-color var(--transition);
  outline: none;
}

.search-input:focus {
  border-color: var(--border-focus);
}

.search-input::placeholder {
  color: var(--text-muted);
}

/* ── Branch Tabs ───────────────────────────── */
.branch-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px;
  margin-bottom: 20px;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}

.branch-tabs::-webkit-scrollbar {
  display: none;
}

.branch-tab {
  padding: 8px 16px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text-secondary);
  border: none;
  background: none;
  transition: all var(--transition);
  white-space: nowrap;
  flex-shrink: 0;
}

.branch-tab:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

.branch-tab.active {
  background: var(--accent);
  color: #fff;
}

/* ── Modal ─────────────────────────────────── */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  backdrop-filter: blur(4px);
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  animation: fadeIn 0.15s ease;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg, var(--shadow));
  animation: mIn 0.18s ease;
}

@keyframes mIn {
  from { opacity: 0; transform: scale(.97) translateY(8px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}

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

.modal-title {
  font-size: 16px;
  font-weight: 700;
}

.modal-close {
  background: var(--bg-hover);
  border: none;
  color: var(--text-secondary);
  width: 30px;
  height: 30px;
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  transition: all var(--transition);
}

.modal-close:hover {
  background: var(--cancelled-bg);
  color: var(--cancelled);
}

.modal-body {
  padding: 20px 24px;
}

.modal-footer {
  padding: 16px 24px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* ── Form Elements ─────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}

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

.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-secondary);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.form-input {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  transition: border-color var(--transition);
  width: 100%;
}

.form-input:focus {
  border-color: var(--border-focus);
}

.form-input::placeholder {
  color: var(--text-muted);
}

select.form-input {
  cursor: pointer;
}

/* ── Section Headers ───────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
  flex-wrap: wrap;
  gap: 10px;
}

.section-header h2 {
  font-size: 16px;
  font-weight: 700;
}

/* ── Empty State ───────────────────────────── */
.empty-state {
  padding: 60px 20px;
  text-align: center;
  color: var(--text-muted);
}

.empty-state .empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
  opacity: 0.4;
}

.empty-state p {
  font-size: 14px;
}

/* ── Customer Cards ────────────────────────── */
.customers-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.customer-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: all var(--transition);
}

.customer-card:hover {
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow);
}

.customer-avatar {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 700;
  color: #fff;
  margin-bottom: 12px;
}

.customer-name {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 4px;
}

.customer-meta {
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 3px;
}

.customer-stats {
  display: flex;
  gap: 12px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

.cstat {
  font-size: 11px;
}

.cstat .val {
  font-size: 15px;
  font-weight: 700;
  color: var(--accent);
  display: block;
}

.cstat .lbl {
  color: var(--text-muted);
}

/* ── Inventory Table Specifics ─────────────── */
.stock-low {
  color: var(--cancelled);
}

.stock-ok {
  color: var(--paid);
}

.stock-warn {
  color: var(--pending);
}

/* ── Progress Bar ──────────────────────────── */
.progress-bar {
  height: 6px;
  background: var(--bg-elevated);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
}

.progress-fill {
  height: 100%;
  border-radius: 3px;
  background: var(--accent);
  transition: width 0.5s ease;
}

/* ── Expense Category Pills ────────────────── */
.cat-pill {
  padding: 2px 10px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}

.cat-pill.cat-Ad_Spend {
  background: rgba(88, 166, 255, 0.12);
  color: #58a6ff;
}

.cat-pill.cat-Restocking {
  background: rgba(16, 185, 129, 0.12);
  color: var(--paid);
}

.cat-pill.cat-Logistics {
  background: rgba(167, 139, 250, 0.12);
  color: #a78bfa;
}

.cat-pill.cat-Other {
  background: rgba(139, 148, 158, 0.12);
  color: #8b949e;
}

/* ── Rates Table ───────────────────────────── */
.rates-input {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 5px 8px;
  color: var(--text-primary);
  font-size: 13px;
  width: 90px;
  outline: none;
  text-align: right;
  transition: border-color var(--transition);
}

.rates-input:focus {
  border-color: var(--border-focus);
}

/* ── Toast Notifications ───────────────────── */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 9px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--paid);
  border-radius: var(--radius-sm);
  padding: 10px 14px;
  font-size: 12px;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: slideInRight 0.2s ease;
  max-width: 300px;
}

.toast.error {
  border-left-color: var(--cancelled);
}

.toast.info {
  border-left-color: var(--delivered);
}

/* ── Responsive sidebar toggle ─────────────── */
.sidebar-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 22px;
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background var(--transition);
}
.sidebar-toggle:hover { background: var(--bg-hover); }

/* ── Animations ────────────────────────────── */
@keyframes fadeIn {
  from {
    opacity: 0;
  }

  to {
    opacity: 1;
  }
}

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

  to {
    opacity: 1;
    transform: translateY(0);
  }
}

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

  to {
    opacity: 1;
    transform: translateX(0);
  }
}

/* ── Scrollbar ─────────────────────────────── */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: var(--bg-base);
}

::-webkit-scrollbar-thumb {
  background: var(--bg-hover);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* ── Responsive ─────────────────────────────────────────────────────────── */

/* Tables always horizontally scrollable */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ─── Tablet (≤900px) ──────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-w: 260px; }

  /* Sidebar slides off-canvas */
  .sidebar {
    transform: translateX(-100%);
    z-index: 200;
    box-shadow: none;
  }
  .sidebar.open {
    transform: translateX(0);
    box-shadow: 6px 0 40px rgba(0, 0, 0, 0.5);
  }

  .main-content  { margin-left: 0; }
  .sidebar-toggle { display: flex; }
  .topbar-subtitle { display: none; }

  /* Collapse multi-col grids */
  .dashboard-grid { grid-template-columns: 1fr; }
  .form-grid      { grid-template-columns: 1fr; }
  .customers-grid { grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); }
  .revenue-grid   { grid-template-columns: repeat(2, 1fr); }
  .stats-grid     { grid-template-columns: repeat(3, 1fr); }
  .g31            { grid-template-columns: 1fr; }

  /* Section headers stack */
  .section-header { flex-direction: column; align-items: flex-start; gap: 10px; }
  .section-header > div:last-child { width: 100%; }

  /* Filter bars scroll horizontally at tablet */
  .filter-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    padding-bottom: 4px;
  }
  .filter-bar::-webkit-scrollbar { display: none; }

  .search-input { width: 220px; }
  .page-content { padding: 16px; }
}

/* ─── Mobile (≤640px) ───────────────────────── */
@media (max-width: 640px) {
  html { font-size: 13px; }

  /* ── Topbar ──────────────────────────── */
  .topbar {
    height: 54px;
    padding: 0 12px;
    gap: 8px;
  }
  .topbar-title { font-size: 15px; }
  #topbar-date  { display: none; }

  /* Keep CTA button visible but compact — it's the only way to add orders on mobile */
  #topbar-cta {
    padding: 6px 10px;
    font-size: 11px;
    gap: 4px;
  }

  /* ── Page ────────────────────────────── */
  .page-content { padding: 10px; }

  /* ── Stats grid — 2 per row ──────────── */
  .stats-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .stat-card  { padding: 12px 10px; }
  .stat-label { font-size: 9px; }
  .stat-value { font-size: 20px; }
  .stat-icon  { top: 10px; right: 8px; }

  /* ── Revenue ─────────────────────────── */
  .revenue-grid { grid-template-columns: 1fr; }
  .revenue-card .amount { font-size: 15px; }

  /* ── Branch tabs ─────────────────────── */
  .branch-tabs {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    gap: 5px;
    padding-bottom: 2px;
  }
  .branch-tabs::-webkit-scrollbar { display: none; }
  .branch-tab { padding: 6px 12px; font-size: 11px; white-space: nowrap; }

  /* ── Filter bar — wrap by default on mobile ── */
  .filter-bar {
    flex-wrap: wrap;
    overflow-x: hidden;
    gap: 8px;
    margin-bottom: 12px;
    padding-bottom: 0;
  }
  /* Branch tabs inside a filter-bar fill full width, then scroll internally */
  .filter-bar > .branch-tabs {
    width: 100%;
    max-width: 100%;
    flex-shrink: 0;
    margin-bottom: 0;
  }
  /* Chip-only filter bars (e.g. status chips) stay on one scrollable row */
  #status-chips {
    overflow-x: auto;
    flex-wrap: nowrap;
    scrollbar-width: none;
    width: 100%;
  }
  #status-chips::-webkit-scrollbar { display: none; }

  /* Search wrapper expands to fill */
  .search-wrapper { flex: 1; min-width: 120px; }
  .search-input   { width: 100%; }

  /* ── Cards ───────────────────────────── */
  .card { padding: 12px; }
  .card-hd { padding: 12px 14px; }
  .card-body { padding: 10px 14px; }
  .card-header { flex-direction: row; align-items: center; gap: 8px; margin-bottom: 12px; }
  .card-title  { font-size: 13px; }

  /* ── Modals — bottom sheet ───────────── */
  .modal-backdrop {
    align-items: flex-end;
    padding: 0;
  }
  .modal {
    max-width: 100%;
    width: 100%;
    max-height: 92vh;
    border-radius: 16px 16px 0 0;
  }
  .modal-header { padding: 16px 18px 12px; }
  .modal-body   { padding: 14px 18px; }
  .modal-footer { padding: 12px 18px; }

  /* ── Tables ──────────────────────────── */
  .table-wrapper { border-radius: 0; }
  .table-wrapper table { min-width: 460px; }
  thead th { padding: 8px 10px; font-size: 10px; }
  tbody td { padding: 9px 10px; font-size: 12px; }

  /* ── Forms ───────────────────────────── */
  .form-grid { grid-template-columns: 1fr; gap: 10px; }
  .form-input { font-size: 14px; } /* prevent iOS zoom on focus */

  /* ── Section headers ─────────────────── */
  .section-header {
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  .section-header > div:last-child {
    width: 100%;
    flex-wrap: wrap;
    gap: 6px;
  }

  /* ── Customers grid — full width ─────── */
  .customers-grid { grid-template-columns: 1fr; }
  .customer-card  { padding: 14px; }

  /* ── Notification panel — constrain to viewport ── */
  #notif-panel {
    width: calc(100vw - 24px) !important;
    right: -46px !important;
    max-height: 65vh;
  }

  /* ── Bulk action bar ─────────────────── */
  #bulk-action-bar {
    width: calc(100% - 20px);
    left: 10px;
    transform: none;
    flex-wrap: wrap;
    gap: 6px;
  }

  /* ── Warn box ────────────────────────── */
  .warn-box { font-size: 11px; padding: 9px 11px; }

  /* ── List items in sidebar cards ─────── */
  .li { padding: 8px 0; }
  .li-label, .li-val { font-size: 11px; }
}

/* ─── Very small (≤390px) ───────────────────── */
@media (max-width: 390px) {
  .stats-grid { gap: 6px; }
  .stat-card  { padding: 10px 8px; }
  .stat-value { font-size: 18px; }
  html { font-size: 12px; }

  /* Hide CTA label on very tiny screens — show + only */
  #topbar-cta .btn-text { display: none; }
}

/* ── Action Buttons In Table ───────────────── */
.action-btns {
  display: flex;
  gap: 5px;
}

.icon-btn {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  cursor: pointer;
  transition: all var(--transition);
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.icon-btn.danger:hover {
  background: var(--cancelled-bg);
  color: var(--cancelled);
  border-color: rgba(248, 81, 73, 0.3);
}

.icon-btn.edit:hover {
  background: var(--accent-dim);
  color: var(--accent);
  border-color: var(--accent);
}

/* ── Info Row ──────────────────────────────── */
.info-row {
  display: flex;
  justify-content: space-between;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.info-row:last-child {
  border-bottom: none;
}

.info-row .lbl {
  color: var(--text-secondary);
}

.info-row .val {
  font-weight: 600;
}

/* ── Sidebar overlay for mobile ──────────────- */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 99;
}

.sidebar-overlay.show {
  display: block;
}

/* ── Order Action Dropdown Menu ───────────────── */
.order-action-wrap {
  position: relative;
  display: inline-block;
}

.order-menu {
  position: absolute;
  right: 0;
  min-width: 148px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg, 0 8px 32px rgba(0, 0, 0, 0.4));
  z-index: 9999;
  overflow: hidden;
  animation: fadeIn 0.12s ease;
}

.order-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition);
  font-family: inherit;
}

.order-menu-item:last-child {
  border-bottom: none;
}

.order-menu-item:hover {
  background: var(--bg-hover);
}

.order-menu-item.danger {
  color: var(--cancelled);
}

.order-menu-item.danger:hover {
  background: var(--cancelled-bg);
}

/* ── Expense Category Pills (extended) ────────── */
.cat-pill.cat-Salaries {
  background: rgba(34, 211, 238, 0.12);
  color: var(--dispatched);
}

.cat-pill.cat-Bonuses {
  background: rgba(167, 139, 250, 0.12);
  color: var(--scheduled);
}

/* ── Stock Inventory Action Dropdown ──────────── */
.stock-action-menu {
  display: none;
  position: absolute;
  right: 0;
  top: 100%;
  min-width: 150px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg, 0 8px 32px rgba(0, 0, 0, 0.4));
  z-index: 500;
  overflow: hidden;
  animation: fadeIn 0.12s ease;
}

.stock-action-menu.open {
  display: block;
}

.stock-action-menu button {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 10px 14px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  text-align: left;
  transition: background var(--transition);
  font-family: inherit;
}

.stock-action-menu button:last-child {
  border-bottom: none;
}

.stock-action-menu button:hover {
  background: var(--bg-hover);
}

.stock-action-menu button.danger-item {
  color: var(--cancelled);
}

.stock-action-menu button.danger-item:hover {
  background: var(--cancelled-bg);
}

/* ── Warn / Info Boxes ────────────────────────── */
.warn-box {
  background: var(--pending-bg);
  border: 1px solid rgba(245, 158, 11, 0.3);
  border-radius: var(--radius-sm);
  padding: 10px 13px;
  font-size: 12px;
  color: var(--pending);
  display: flex;
  gap: 8px;
  align-items: flex-start;
  margin-bottom: 16px;
}

/* ── Act Buttons (small icon buttons in tables) ── */
.acts { display: flex; gap: 4px; }

.act-btn {
  width: 27px;
  height: 27px;
  border-radius: 6px;
  background: transparent;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  transition: all var(--transition);
  cursor: pointer;
  flex-shrink: 0;
}

.act-btn:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.act-btn.danger:hover {
  background: var(--cancelled-bg);
  color: var(--cancelled);
  border-color: var(--cancelled);
}

/* ── Layout Grids ─────────────────────────────── */
.g31 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }

@media (max-width: 900px) { .g31 { grid-template-columns: 1fr; } }

/* ── List Item Rows (used in sidebar cards) ────── */
.li {
  display: flex;
  align-items: center;
  padding: 9px 0;
  border-bottom: 1px solid var(--border);
}
.li:last-child { border-bottom: none; }
.li-label { flex: 1; min-width: 0; font-size: 12px; color: var(--text-secondary); display: flex; align-items: center; gap: 8px; }
.li-val   { font-size: 12px; font-weight: 700; color: var(--text-primary); flex-shrink: 0; white-space: nowrap; margin-left: 8px; }

/* ── Card Body / Card Section Head ────────────── */
.card-body { padding: 14px 18px; }

.card-hd {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}

/* ── Divider ──────────────────────────────────── */
.divider { height: 1px; background: var(--border); margin: 12px 0; }

/* ── Status Badges (OK / LOW / OUT) ───────────── */
.badge-ok  { background: var(--paid-bg);      color: var(--paid); }
.badge-low { background: var(--pending-bg);   color: var(--pending); }
.badge-out { background: var(--cancelled-bg); color: var(--cancelled); }

/* ── Progress bar colour modifiers ────────────── */
.progress-fill.prog-green  { background: var(--paid); }
.progress-fill.prog-amber  { background: var(--pending); }
.progress-fill.prog-red    { background: var(--cancelled); }
.progress-fill.prog-blue   { background: var(--delivered); }
.progress-fill.prog-purple { background: var(--scheduled); }