/* ═══════════════════════════════════════════════════════════════
   Retailytics Design System - Production Grade
   Aesthetic: Refined Dark-Zinc / Warm Amber / Glassmorphism
   ═══════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700;1,9..40,400&family=DM+Mono:wght@400;500&family=Syne:wght@700;800&display=swap');

/* ── CSS Variables ─────────────────────────────────────────── */
:root {
  /* Core Palette — Dark Mode (default) */
  --bg-base:        #0e0f11;
  --bg-elevated:    #141619;
  --bg-surface:     #1a1c21;
  --bg-overlay:     #1f2228;
  --bg-hover:       #242830;

  --border-subtle:  rgba(255,255,255,0.06);
  --border-default: rgba(255,255,255,0.10);
  --border-strong:  rgba(255,255,255,0.16);

  /* Text */
  --text-primary:   #f0f1f3;
  --text-secondary: #9ba3af;
  --text-tertiary:  #5c6370;
  --text-inverse:   #0e0f11;

  /* Accent — Warm Amber */
  --accent-50:   #fffbeb;
  --accent-100:  #fef3c7;
  --accent-200:  #fde68a;
  --accent-300:  #fcd34d;
  --accent-400:  #fbbf24;
  --accent-500:  #f59e0b;
  --accent-600:  #d97706;
  --accent-700:  #b45309;
  --accent-800:  #92400e;
  --accent-900:  #78350f;

  /* Semantic colors */
  --success-bg:   rgba(16,185,129,0.12);
  --success-text: #34d399;
  --success-border: rgba(52,211,153,0.25);

  --warning-bg:   rgba(251,191,36,0.12);
  --warning-text: #fbbf24;
  --warning-border: rgba(251,191,36,0.25);

  --danger-bg:    rgba(239,68,68,0.12);
  --danger-text:  #f87171;
  --danger-border: rgba(248,113,113,0.25);

  --info-bg:      rgba(99,102,241,0.12);
  --info-text:    #818cf8;
  --info-border:  rgba(129,140,248,0.25);

  /* Shadows */
  --shadow-sm:  0 1px 3px rgba(0,0,0,0.4), 0 1px 2px rgba(0,0,0,0.3);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.5), 0 2px 6px rgba(0,0,0,0.3);
  --shadow-lg:  0 10px 30px rgba(0,0,0,0.6), 0 4px 12px rgba(0,0,0,0.4);
  --shadow-glow: 0 0 0 1px rgba(245,158,11,0.2), 0 4px 20px rgba(245,158,11,0.1);

  /* Radius */
  --radius-sm:  6px;
  --radius-md:  10px;
  --radius-lg:  14px;
  --radius-xl:  20px;
  --radius-2xl: 28px;

  /* Transitions */
  --transition: 150ms cubic-bezier(0.4, 0, 0.2, 1);
  --transition-slow: 250ms cubic-bezier(0.4, 0, 0.2, 1);

  /* Sidebar */
  --sidebar-w: 260px;
}

/* Light Mode */
[data-theme="light"] {
  --bg-base:        #f4f5f7;
  --bg-elevated:    #ffffff;
  --bg-surface:     #ffffff;
  --bg-overlay:     #f8f9fb;
  --bg-hover:       #f1f3f6;

  --border-subtle:  rgba(0,0,0,0.05);
  --border-default: rgba(0,0,0,0.09);
  --border-strong:  rgba(0,0,0,0.15);

  --text-primary:   #111318;
  --text-secondary: #5c6472;
  --text-tertiary:  #9ba3af;
  --text-inverse:   #ffffff;

  --shadow-sm:  0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md:  0 4px 12px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
  --shadow-lg:  0 10px 30px rgba(0,0,0,0.10), 0 4px 12px rgba(0,0,0,0.06);
  --shadow-glow: 0 0 0 1px rgba(245,158,11,0.25), 0 4px 20px rgba(245,158,11,0.12);
}


html { color-scheme: dark; }
html[data-theme="light"] { color-scheme: light; }

/* Prevent color/transition flashes during page navigation and theme hydration. */
html[data-theme="dark"] body,
html[data-theme="light"] body { transition: background-color 0s, color 0s; }

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

html {
  font-size: 15px;
  scroll-behavior: smooth;
  font-variation-settings: 'wght' 450;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

body {
  font-family: 'DM Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-weight: 400;
  letter-spacing: 0.02em;
  line-height: 1.45;
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  overflow-x: hidden;
}

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* Selection */
::selection { background: rgba(245,158,11,0.25); color: var(--text-primary); }

/* ── Typography ────────────────────────────────────────────── */
.font-display { font-family: 'Syne', system-ui, sans-serif; }
.font-mono    { font-family: 'DM Mono', monospace; }

h1, h2, h3 { font-weight: 700; line-height: 1.25; color: var(--text-primary); }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.375rem; }
h3 { font-size: 1.125rem; }
p  { color: var(--text-secondary); }
a  { color: var(--accent-400); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-300); }

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

/* ── Sidebar ───────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--bg-elevated);
  border-right: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  transition: transform var(--transition-slow), width var(--transition-slow);
  position: relative;
  z-index: 40;
}

.sidebar::after {
  content: '';
  position: absolute;
  top: 0; right: 0;
  width: 1px; height: 100%;
  background: linear-gradient(to bottom, transparent, var(--accent-500) 40%, transparent);
  opacity: 0.15;
}

.sidebar-brand {
  padding: 20px 18px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; gap: 11px;
}

.sidebar-logo {
  width: 36px; height: 36px;
  border-radius: 10px;
  background: rgba(255,255,255,0.04);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  overflow: hidden;
  box-shadow: 0 0 0 1px rgba(245,158,11,0.20), 0 4px 12px rgba(0,0,0,0.18);
}

.sidebar-logo svg { width: 18px; height: 18px; color: #0e0f11; }
.sidebar-logo img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.brand-logo {
  display: block;
  object-fit: contain;
}
.auth-logo {
  width: 58px;
  height: 58px;
  object-fit: contain;
  display: block;
  margin: 0 auto 14px;
}
.brand-mark img {
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}

.sidebar-brand-text { min-width: 0; }
.sidebar-brand-text h1 {
  font-family: 'Syne', sans-serif;
  font-size: 0.92rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: 0.02em;
  line-height: 1.15;
}
.sidebar-brand-text p {
  font-size: 0.66rem;
  color: var(--text-tertiary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}

/* Nav */
.sidebar-nav {
  flex: 1;
  padding: 14px 10px;
  overflow-y: auto;
  overflow-x: hidden;
}

.nav-section-label {
  font-size: 0.625rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  padding: 14px 10px 6px;
}

.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  white-space: nowrap;
  text-decoration: none;
}

.nav-item:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
  text-decoration: none;
}

.nav-item.active {
  color: var(--accent-400);
  background: rgba(245,158,11,0.10);
  font-weight: 600;
}

.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 20%; height: 60%;
  width: 3px;
  background: var(--accent-500);
  border-radius: 0 3px 3px 0;
}

.nav-item svg { width: 16px; height: 16px; flex-shrink: 0; opacity: 0.8; }
.nav-item.active svg { opacity: 1; }

.nav-badge {
  margin-left: auto;
  font-size: 0.65rem;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 99px;
  background: var(--danger-bg);
  color: var(--danger-text);
  border: 1px solid var(--danger-border);
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border-subtle);
}

.user-card {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: background var(--transition);
  position: relative;
}
.user-card:hover { background: var(--bg-hover); }

.user-avatar {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, #f59e0b, #d97706);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.66rem; font-weight: 800;
  color: #0e0f11;
  flex-shrink: 0;
}

.user-info { min-width: 0; flex: 1; }
.user-name { font-size: 0.74rem; font-weight: 600; color: var(--text-primary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 0.60rem; color: var(--text-tertiary); }

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

/* ── Topbar ────────────────────────────────────────────────── */
.topbar {
  height: 58px;
  background: var(--bg-elevated);
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center;
  padding: 0 24px;
  gap: 16px;
  flex-shrink: 0;
  position: relative;
  z-index: 30;
}

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

.breadcrumb { display: flex; align-items: center; gap: 6px; }
.breadcrumb-item { font-size: 0.8rem; color: var(--text-tertiary); }
.breadcrumb-current { font-size: 0.875rem; font-weight: 600; color: var(--text-primary); }
.breadcrumb-sep { color: var(--text-tertiary); font-size: 0.75rem; }

.topbar-search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 6px 12px;
  transition: all var(--transition);
  width: 240px;
  max-width: 100%;
}
.topbar-search:focus-within {
  border-color: var(--accent-500);
  box-shadow: 0 0 0 3px rgba(245,158,11,0.12);
  width: 300px;
}
.topbar-search svg { width: 14px; height: 14px; color: var(--text-tertiary); flex-shrink: 0; }
.topbar-search input {
  background: none; border: none; outline: none;
  font-size: 0.825rem; color: var(--text-primary);
  width: 100%;
  font-family: 'DM Sans', sans-serif;
}
.topbar-search input::placeholder { color: var(--text-tertiary); }

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

.icon-btn {
  width: 34px; height: 34px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}
.icon-btn:hover { color: var(--text-primary); border-color: var(--border-default); background: var(--bg-hover); }
.icon-btn svg { width: 15px; height: 15px; }

.notif-badge {
  position: absolute; top: -3px; right: -3px;
  width: 16px; height: 16px;
  background: #ef4444;
  border-radius: 99px;
  font-size: 0.6rem; font-weight: 700;
  color: white;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--bg-elevated);
}

/* Theme toggle */
.theme-toggle {
  width: 34px; height: 34px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  color: var(--text-secondary);
  transition: all var(--transition);
}
.theme-toggle:hover { color: var(--accent-400); border-color: rgba(245,158,11,0.3); background: rgba(245,158,11,0.06); }
.theme-toggle svg { width: 15px; height: 15px; }

/* ── Page Area ─────────────────────────────────────────────── */
.page-area {
  flex: 1;
  overflow-y: auto;
  padding: 24px 28px;
  position: relative;
}

.page-header {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 20px; gap: 14px; flex-wrap: wrap;
}
.page-title-area h2 { font-family: 'Syne', sans-serif; font-size: 1.2rem; font-weight: 800; letter-spacing: -0.02em; margin-bottom: 2px; }
.page-title-area p  { font-size: 0.75rem; color: var(--text-tertiary); margin-top: 2px; }
.page-actions { display: flex; align-items: center; gap: 8px; flex-shrink: 0; flex-wrap: wrap; }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 0.825rem;
  font-weight: 600;
  font-family: 'DM Sans', sans-serif;
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
  line-height: 1;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn svg { width: 14px; height: 14px; flex-shrink: 0; }

.btn-primary {
  background: linear-gradient(135deg, #f59e0b, #d97706);
  color: #0e0f11;
  border-color: rgba(245,158,11,0.3);
  box-shadow: 0 1px 4px rgba(245,158,11,0.3), inset 0 1px 0 rgba(255,255,255,0.15);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #fbbf24, #f59e0b);
  box-shadow: 0 4px 14px rgba(245,158,11,0.4);
  transform: translateY(-1px);
}
.btn-primary:active { transform: translateY(0); }

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border-color: var(--border-default);
}
.btn-secondary:hover {
  color: var(--text-primary);
  border-color: var(--border-strong);
  background: var(--bg-hover);
}

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

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-color: var(--danger-border);
}
.btn-danger:hover { background: rgba(239,68,68,0.2); }

.btn-success {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: var(--success-border);
}
.btn-success:hover { background: rgba(16,185,129,0.2); }

.btn-sm { padding: 6px 12px; font-size: 0.775rem; border-radius: var(--radius-sm); }
.btn-sm svg { width: 12px; height: 12px; }
.btn-lg { padding: 11px 22px; font-size: 0.9rem; border-radius: var(--radius-lg); }

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  overflow: hidden;
  transition: border-color var(--transition);
}
.card:hover { border-color: var(--border-default); }

.card-glass {
  background: rgba(255,255,255,0.03);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
}
[data-theme="light"] .card-glass { background: rgba(255,255,255,0.7); }

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: space-between;
  gap: 12px;
}
.card-title { font-size: 0.875rem; font-weight: 700; color: var(--text-primary); }
.card-subtitle { font-size: 0.75rem; color: var(--text-tertiary); margin-top: 2px; }
.card-body { padding: 20px; }
.card-footer { padding: 14px 20px; border-top: 1px solid var(--border-subtle); display: flex; align-items: center; justify-content: space-between; }

/* ── Stat Cards ────────────────────────────────────────────── */
.stat-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-xl);
  padding: 16px;
  position: relative;
  overflow: hidden;
  transition: all var(--transition-slow);
}
.stat-card::before {
  content: '';
  position: absolute;
  inset: 0;
  background: linear-gradient(135deg, transparent 60%, rgba(245,158,11,0.04));
  pointer-events: none;
}
.stat-card:hover { border-color: var(--border-default); transform: translateY(-1px); box-shadow: var(--shadow-md); }

.stat-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 12px;
}
.stat-icon svg { width: 16px; height: 16px; }

.stat-label { font-size: 0.64rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-tertiary); margin-bottom: 5px; }
.stat-value { font-family: 'Syne', sans-serif; font-size: 1.4rem; font-weight: 700; color: var(--text-primary); letter-spacing: -0.02em; line-height: 1.1; }
.stat-meta { font-size: 0.72rem; color: var(--text-tertiary); margin-top: 6px; display: flex; align-items: center; gap: 5px; }
.stat-up   { color: var(--success-text); }
.stat-down { color: var(--danger-text); }

/* ── Forms ─────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 0.775rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}
.form-label .req { color: var(--danger-text); margin-left: 2px; }

.form-input, .form-select, .form-textarea {
  width: 100%;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-md);
  padding: 9px 13px;
  font-size: 0.85rem;
  color: var(--text-primary);
  font-family: 'DM Sans', sans-serif;
  transition: all var(--transition);
  outline: none;
  appearance: none;
}
.form-input::placeholder, .form-textarea::placeholder { color: var(--text-tertiary); }

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--accent-500);
  box-shadow: 0 0 0 3px rgba(245,158,11,0.12);
  background: var(--bg-overlay);
}

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239ba3af' stroke-width='2'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
  cursor: pointer;
}

.form-textarea { resize: vertical; min-height: 80px; line-height: 1.6; }

.form-hint { font-size: 0.725rem; color: var(--text-tertiary); margin-top: 5px; }
.form-error { font-size: 0.725rem; color: var(--danger-text); margin-top: 5px; }

.input-group { display: flex; gap: 0; }
.input-group .form-input { border-radius: var(--radius-md) 0 0 var(--radius-md); }
.input-group .btn { border-radius: 0 var(--radius-md) var(--radius-md) 0; border-left: 0; }

/* ── Tables ────────────────────────────────────────────────── */
.data-table-wrap { overflow-x: auto; border-radius: var(--radius-xl); }

.data-table { width: 100%; border-collapse: collapse; font-size: 0.845rem; }

.data-table thead { background: var(--bg-surface); border-bottom: 1px solid var(--border-subtle); }
.data-table thead th {
  padding: 11px 16px;
  text-align: left;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.07em;
  text-transform: uppercase;
  color: var(--text-tertiary);
  white-space: nowrap;
}
.data-table thead th:first-child { border-radius: var(--radius-lg) 0 0 0; }
.data-table thead th:last-child  { border-radius: 0 var(--radius-lg) 0 0; }

.data-table tbody tr {
  border-bottom: 1px solid var(--border-subtle);
  transition: background var(--transition);
}
.data-table tbody tr:hover { background: var(--bg-hover); }
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody td { padding: 13px 16px; color: var(--text-secondary); vertical-align: middle; }
.data-table tbody td strong, .data-table tbody td .cell-primary { color: var(--text-primary); font-weight: 600; }
.data-table tbody td .cell-sub { font-size: 0.75rem; color: var(--text-tertiary); margin-top: 2px; }

/* ── Badges / Pills ────────────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.03em;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge::before { content: ''; width: 5px; height: 5px; border-radius: 50%; background: currentColor; display: inline-block; }

.badge-draft   { background: rgba(92,99,112,0.15); color: var(--text-secondary); border-color: var(--border-subtle); }
.badge-sent    { background: var(--info-bg);    color: var(--info-text);    border-color: var(--info-border); }
.badge-viewed  { background: rgba(139,92,246,0.12); color: #a78bfa; border-color: rgba(167,139,250,0.25); }
.badge-partial { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
.badge-paid    { background: var(--success-bg); color: var(--success-text); border-color: var(--success-border); }
.badge-overdue { background: var(--danger-bg);  color: var(--danger-text);  border-color: var(--danger-border); }
.badge-cancelled { background: var(--bg-hover); color: var(--text-tertiary); border-color: var(--border-subtle); }

/* ── Tabs ──────────────────────────────────────────────────── */
.tabs {
  display: flex; gap: 2px;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 3px;
}
.tab-item {
  padding: 7px 14px;
  border-radius: var(--radius-md);
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-tertiary);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.tab-item:hover { color: var(--text-secondary); background: var(--bg-hover); }
.tab-item.active { background: var(--bg-elevated); color: var(--text-primary); box-shadow: var(--shadow-sm); }

/* ── Filter chips ──────────────────────────────────────────── */
.filter-chip {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 0.775rem;
  font-weight: 600;
  background: var(--bg-surface);
  border: 1px solid var(--border-default);
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.filter-chip:hover { border-color: var(--border-strong); color: var(--text-primary); background: var(--bg-hover); }
.filter-chip.active {
  background: rgba(245,158,11,0.12);
  border-color: rgba(245,158,11,0.35);
  color: var(--accent-400);
}

/* ── Alerts / Messages ─────────────────────────────────────── */
.alert {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  font-size: 0.825rem;
}
.alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.alert-success { background: var(--success-bg); border-color: var(--success-border); color: var(--success-text); }
.alert-warning { background: var(--warning-bg); border-color: var(--warning-border); color: var(--warning-text); }
.alert-danger  { background: var(--danger-bg);  border-color: var(--danger-border);  color: var(--danger-text); }
.alert-info    { background: var(--info-bg);     border-color: var(--info-border);    color: var(--info-text); }

/* ── Avatar ────────────────────────────────────────────────── */
.avatar {
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #f59e0b, #d97706);
  display: flex; align-items: center; justify-content: center;
  font-weight: 800; color: #0e0f11;
  flex-shrink: 0;
}
.avatar-sm { width: 28px; height: 28px; font-size: 0.65rem; border-radius: 7px; }
.avatar-md { width: 36px; height: 36px; font-size: 0.8rem; border-radius: 9px; }
.avatar-lg { width: 48px; height: 48px; font-size: 1rem; border-radius: 12px; }
.avatar-xl { width: 64px; height: 64px; font-size: 1.25rem; border-radius: 16px; }

/* ── Divider ───────────────────────────────────────────────── */
.divider { height: 1px; background: var(--border-subtle); margin: 16px 0; }
.divider-vertical { width: 1px; background: var(--border-subtle); align-self: stretch; }

/* ── Empty state ───────────────────────────────────────────── */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  padding: 60px 24px; text-align: center; gap: 12px;
}
.empty-icon {
  width: 56px; height: 56px;
  border-radius: var(--radius-xl);
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 4px;
}
.empty-icon svg { width: 24px; height: 24px; color: var(--text-tertiary); }
.empty-title { font-weight: 700; color: var(--text-primary); }
.empty-desc  { font-size: 0.825rem; color: var(--text-tertiary); max-width: 280px; }

/* ── Progress bar ──────────────────────────────────────────── */
.progress { height: 4px; background: var(--bg-hover); border-radius: 99px; overflow: hidden; }
.progress-bar { height: 100%; background: linear-gradient(to right, var(--accent-500), var(--accent-400)); border-radius: 99px; transition: width 0.5s ease; }

/* ── Dropdown ──────────────────────────────────────────────── */
.dropdown {
  position: absolute;
  z-index: 100;
  background: var(--bg-elevated);
  border: 1px solid var(--border-default);
  border-radius: var(--radius-lg);
  padding: 6px;
  box-shadow: var(--shadow-lg);
  min-width: 170px;
}
.dropdown-item {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all var(--transition);
}
.dropdown-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.dropdown-item.danger { color: var(--danger-text); }
.dropdown-item.danger:hover { background: var(--danger-bg); }
.dropdown-item svg { width: 14px; height: 14px; }
.dropdown-sep { height: 1px; background: var(--border-subtle); margin: 4px 0; }

/* ── Checkbox / Radio ──────────────────────────────────────── */
.checkbox, .radio {
  width: 16px; height: 16px;
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  background: var(--bg-surface);
  cursor: pointer;
  accent-color: var(--accent-500);
  flex-shrink: 0;
}
.radio { border-radius: 50%; }

/* ── Toast / Flash ─────────────────────────────────────────── */
.toast-container {
  position: fixed; top: 16px; right: 16px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  pointer-events: none;
}
.toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  border: 1px solid transparent;
  font-size: 0.825rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  pointer-events: all;
  animation: toast-in 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
  max-width: 360px;
  backdrop-filter: blur(20px);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(100%) scale(0.9); }
  to   { opacity: 1; transform: translateX(0) scale(1); }
}
.toast-success { background: rgba(16,185,129,0.15); border-color: var(--success-border); color: var(--success-text); }
.toast-warning { background: rgba(251,191,36,0.15); border-color: var(--warning-border); color: var(--warning-text); }
.toast-error   { background: rgba(239,68,68,0.15);  border-color: var(--danger-border);  color: var(--danger-text); }
.toast-info    { background: rgba(99,102,241,0.15);  border-color: var(--info-border);    color: var(--info-text); }
.toast svg     { width: 15px; height: 15px; flex-shrink: 0; }
.toast-close   { margin-left: auto; opacity: 0.6; cursor: pointer; }
.toast-close:hover { opacity: 1; }

/* ── Mobile Sidebar Overlay ────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.7);
  backdrop-filter: blur(4px);
  z-index: 39;
}

/* ── Animations ────────────────────────────────────────────── */
@keyframes fade-up {
  from { opacity: 0; transform: translateY(14px); }
  to   { opacity: 1; transform: translateY(0); }
}
@keyframes fade-in {
  from { opacity: 0; }
  to   { opacity: 1; }
}
@keyframes scale-in {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}
.anim-fade-up  { animation: fade-up  0.35s cubic-bezier(0.22, 1, 0.36, 1) both; }
.anim-fade-in  { animation: fade-in  0.25s ease both; }
.anim-scale-in { animation: scale-in 0.2s cubic-bezier(0.22, 1, 0.36, 1) both; }

.stagger > * { animation: fade-up 0.35s cubic-bezier(0.22, 1, 0.36, 1) both; }
.stagger > *:nth-child(1) { animation-delay: 0ms; }
.stagger > *:nth-child(2) { animation-delay: 60ms; }
.stagger > *:nth-child(3) { animation-delay: 120ms; }
.stagger > *:nth-child(4) { animation-delay: 180ms; }
.stagger > *:nth-child(5) { animation-delay: 240ms; }
.stagger > *:nth-child(6) { animation-delay: 300ms; }

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 1024px) {
  :root { --sidebar-w: 240px; }
  .page-area { padding: 20px; }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0; top: 0; bottom: 0;
    z-index: 40;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-overlay.visible { display: block; }

  .topbar { padding: 0 16px; }
  .topbar-search { display: none; }
  .page-area { padding: 16px; }
  .page-header { margin-bottom: 16px; }
  .page-title-area h2 { font-size: 1.25rem; }

  .stat-card { padding: 16px; }
  .stat-value { font-size: 1.5rem; }
}

@media (max-width: 480px) {
  .page-area { padding: 12px; }
  .card-body { padding: 14px; }
  .card-header { padding: 12px 14px; }
  .page-actions .btn span { display: none; }
}

/* ── Print ─────────────────────────────────────────────────── */
@media print {
  .sidebar, .topbar, .page-actions, .btn, .no-print { display: none !important; }
  body { background: white; color: black; }
  .card { border: 1px solid #e2e8f0; box-shadow: none; }
  .page-area { padding: 0; overflow: visible; }
  .main-content { overflow: visible; }
}

/* ── Chart area ────────────────────────────────────────────── */
.chart-container { position: relative; width: 100%; }

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

@media (max-width: 1100px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 768px)  { .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 520px)  { .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; } }

/* ── Misc helpers ──────────────────────────────────────────── */
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-right { text-align: right; }
.text-center { text-align: center; }
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.ml-auto { margin-left: auto; }
.w-full { width: 100%; }
.hidden { display: none !important; }

/* ── Compatibility utilities for older Tailwind-styled templates ───── */
.table-container { overflow-x:auto; border-radius: var(--radius-xl); }
.page-title { font-family:'Syne',sans-serif; font-size:1.35rem; font-weight:800; color:var(--text-primary); letter-spacing:-0.03em; }
.page-subtitle { color:var(--text-tertiary); font-size:.85rem; }
.fade-in { animation: fade-up .3s cubic-bezier(.22,1,.36,1) both; }
.btn-primary, .btn-secondary, .btn-ghost, .btn-success, .btn-danger { text-decoration:none; }
button.btn-primary, a.btn-primary, .btn-primary:not(.btn) { display:inline-flex; align-items:center; gap:7px; padding:8px 16px; border-radius:var(--radius-md); font-size:.825rem; font-weight:700; border:1px solid rgba(245,158,11,.3); cursor:pointer; background:linear-gradient(135deg,#f59e0b,#d97706); color:#0e0f11; box-shadow:0 1px 4px rgba(245,158,11,.25); }
button.btn-secondary, a.btn-secondary, .btn-secondary:not(.btn) { display:inline-flex; align-items:center; gap:7px; padding:8px 16px; border-radius:var(--radius-md); font-size:.825rem; font-weight:700; border:1px solid var(--border-default); background:var(--bg-surface); color:var(--text-secondary); }
button.btn-primary:hover, a.btn-primary:hover { background:linear-gradient(135deg,#fbbf24,#f59e0b); color:#0e0f11; }
button.btn-secondary:hover, a.btn-secondary:hover { background:var(--bg-hover); color:var(--text-primary); }
.badge-paid, .badge-completed { display:inline-flex; align-items:center; gap:4px; padding:3px 9px; border-radius:99px; font-size:.68rem; font-weight:700; background:var(--success-bg); color:var(--success-text); border:1px solid var(--success-border); }
.badge-cancelled, .badge-failed { display:inline-flex; align-items:center; gap:4px; padding:3px 9px; border-radius:99px; font-size:.68rem; font-weight:700; background:var(--bg-hover); color:var(--text-tertiary); border:1px solid var(--border-subtle); }
.badge-refunded { display:inline-flex; align-items:center; gap:4px; padding:3px 9px; border-radius:99px; font-size:.68rem; font-weight:700; background:var(--info-bg); color:var(--info-text); border:1px solid var(--info-border); }
.card .bg-white, [data-theme="dark"] .bg-white { background: var(--bg-elevated) !important; }
[data-theme="dark"] .text-slate-900, [data-theme="dark"] .text-slate-800, [data-theme="dark"] .text-slate-700 { color: var(--text-primary) !important; }
[data-theme="dark"] .text-slate-600, [data-theme="dark"] .text-slate-500 { color: var(--text-secondary) !important; }
[data-theme="dark"] .text-slate-400, [data-theme="dark"] .text-slate-300 { color: var(--text-tertiary) !important; }
[data-theme="dark"] .border-slate-100, [data-theme="dark"] .border-slate-200 { border-color: var(--border-subtle) !important; }
[data-theme="dark"] .divide-slate-100 > :not([hidden]) ~ :not([hidden]) { border-color: var(--border-subtle) !important; }
[data-theme="dark"] .bg-slate-50, [data-theme="dark"] .bg-slate-100 { background: var(--bg-surface) !important; }
[data-theme="dark"] .bg-emerald-50, [data-theme="dark"] .bg-emerald-100 { background: var(--success-bg) !important; }
[data-theme="dark"] .bg-red-50, [data-theme="dark"] .bg-red-100 { background: var(--danger-bg) !important; }
[data-theme="dark"] .bg-blue-50, [data-theme="dark"] .bg-blue-100 { background: var(--info-bg) !important; }
[data-theme="dark"] .bg-amber-50, [data-theme="dark"] .bg-amber-100 { background: var(--warning-bg) !important; }
@media (max-width: 768px){
  .page-actions, .topbar-actions { width:100%; justify-content:flex-start; }
  .topbar { height:auto; min-height:58px; flex-wrap:wrap; padding-top:10px; padding-bottom:10px; }
  .topbar-actions .btn { padding:7px 10px; }
  .data-table thead { display:none; }
  .data-table tbody tr { display:block; padding:10px 0; }
  .data-table tbody td { display:flex; justify-content:space-between; gap:16px; padding:8px 14px; white-space:normal; }
  .data-table tbody td:empty { display:none; }
}

/* ═══════════════════════════════════════════════════════════════
   Final UI Polish — dashboard, CRUD pages, forms, and buttons
   ═══════════════════════════════════════════════════════════════ */

/* Better global reading size without making the interface bulky */
html { font-size: 16px; }
body { letter-spacing: 0.005em; }
.page-area > .stagger,
.page-area > .fade-in,
.page-area > .space-y-5,
.page-area > .space-y-6,
.crud-page {
  max-width: 1480px;
  margin-left: auto;
  margin-right: auto;
  width: 100%;
}

.page-header { margin-bottom: 24px; }
.page-title-area h2,
.page-title { font-size: clamp(1.35rem, 1vw + 1rem, 1.85rem); }
.page-title-area p,
.page-subtitle { font-size: .92rem; line-height: 1.55; }
.card-title { font-size: .98rem; }
.card-subtitle { font-size: .82rem; line-height: 1.45; }

/* Dashboard cards: less stretched, more readable, stronger height */
.dashboard-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 18px;
  margin-bottom: 20px;
}
.dashboard-chart-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 380px);
  gap: 18px;
  margin-bottom: 20px;
}
.dashboard-table-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
}
.dashboard-kpi-grid .stat-card {
  min-height: 158px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.dashboard-kpi-grid .stat-icon { width: 44px; height: 44px; margin-bottom: 14px; }
.dashboard-kpi-grid .stat-icon svg { width: 21px; height: 21px; }
.dashboard-kpi-grid .stat-label { font-size: .72rem; margin-bottom: 8px; }
.dashboard-kpi-grid .stat-value { font-size: clamp(1.65rem, 1.2vw + 1.1rem, 2.25rem); }
.dashboard-kpi-grid .stat-meta { font-size: .84rem; margin-top: 10px; }
.chart-container { min-height: 240px; }

/* CRUD/form layout helpers */
.crud-page { padding-bottom: 28px; }
.crud-header .page-actions { align-items: center; }
.crud-form { width: 100%; }
.form-layout-2-1 {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
  gap: 22px;
  align-items: start;
}
.form-main-stack,
.form-sidebar-stack { display: flex; flex-direction: column; gap: 18px; }
.form-section-card { box-shadow: var(--shadow-sm); }
.form-section-card .card-header { padding: 18px 22px; }
.form-section-card .card-body { padding: 22px; }
.form-grid { display: grid; gap: 18px; }
.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.form-grid-span-2 { grid-column: span 2; }
.form-grid-span-3 { grid-column: span 3; }
.form-group { margin-bottom: 0; }
.form-input, .form-select, .form-textarea {
  min-height: 44px;
  font-size: .92rem;
  border-radius: 12px;
  padding: 11px 14px;
}
.form-textarea { min-height: 104px; }
.form-label { font-size: .84rem; margin-bottom: 7px; }
.input-with-suffix { position: relative; }
.input-with-suffix .form-input { padding-right: 58px; }
.input-with-suffix span {
  position: absolute;
  right: 13px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-tertiary);
  font-size: .78rem;
  pointer-events: none;
}
.sticky-form-card { position: sticky; top: 24px; }
.form-sidebar-actions { display: flex; flex-direction: column; gap: 10px; }
.toggle-row { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.toggle-card {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: 13px;
  cursor: pointer;
}
.toggle-card:hover { border-color: var(--border-default); background: var(--bg-hover); }
.toggle-card strong { display: block; color: var(--text-primary); font-size: .88rem; }
.toggle-card small { display: block; color: var(--text-tertiary); margin-top: 3px; line-height: 1.35; }

/* Button consistency, including templates that use btn-primary without btn */
.btn,
button.btn-primary, a.btn-primary, .btn-primary:not(.btn),
button.btn-secondary, a.btn-secondary, .btn-secondary:not(.btn),
button.btn-danger, a.btn-danger, .btn-danger:not(.btn),
button.btn-success, a.btn-success, .btn-success:not(.btn) {
  min-height: 40px;
  line-height: 1.2;
  justify-content: center;
}
.btn-sm, button.btn-sm, a.btn-sm { min-height: 34px; }
.btn-lg, button.btn-lg, a.btn-lg { min-height: 48px; font-size: .95rem; }
.btn i, .btn svg, button.btn-primary i, a.btn-primary i, button.btn-secondary i, a.btn-secondary i,
button.btn-danger i, a.btn-danger i { width: 16px; height: 16px; flex-shrink: 0; }

/* Tables/cards: cleaner spacing and mobile-safe scrolling */
.card { box-shadow: var(--shadow-sm); }
.data-table { font-size: .9rem; }
.data-table thead th { padding: 13px 16px; font-size: .72rem; }
.data-table tbody td { padding: 15px 16px; }
.table-container, .data-table-wrap, .overflow-x-auto { overflow-x: auto; -webkit-overflow-scrolling: touch; }

/* Missing brand utilities used by templates. They map to the amber design system. */
.text-brand-300 { color: var(--accent-300) !important; }
.text-brand-400, .text-brand-500, .text-brand-600, .text-brand-700, .text-brand-800 { color: var(--accent-400) !important; }
.bg-brand-50 { background: rgba(245,158,11,.08) !important; }
.bg-brand-100 { background: rgba(245,158,11,.12) !important; }
.bg-brand-200 { background: rgba(245,158,11,.18) !important; }
.bg-brand-400, .bg-brand-500, .bg-brand-600 { background: linear-gradient(135deg, var(--accent-500), var(--accent-600)) !important; }
.border-brand-200 { border-color: rgba(245,158,11,.26) !important; }
.hover\:text-brand-600:hover { color: var(--accent-300) !important; }
.hover\:bg-brand-600:hover { background: linear-gradient(135deg, var(--accent-400), var(--accent-500)) !important; }
.from-brand-50 { --tw-gradient-from: rgba(245,158,11,.08) var(--tw-gradient-from-position); --tw-gradient-to: rgba(245,158,11,0) var(--tw-gradient-to-position); --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to); }
.from-brand-400, .from-brand-500 { --tw-gradient-from: var(--accent-500) var(--tw-gradient-from-position); --tw-gradient-to: rgba(245,158,11,0) var(--tw-gradient-to-position); --tw-gradient-stops: var(--tw-gradient-from), var(--tw-gradient-to); }
.to-purple-50 { --tw-gradient-to: rgba(168,85,247,.08) var(--tw-gradient-to-position); }
.to-purple-500, .to-purple-600 { --tw-gradient-to: #a855f7 var(--tw-gradient-to-position); }

/* Dark/light compatibility for Tailwind-only utility fragments */
[data-theme="dark"] .bg-slate-50,
[data-theme="dark"] .bg-slate-100,
[data-theme="dark"] .bg-white { background-color: var(--bg-surface) !important; }
[data-theme="dark"] .border-slate-100,
[data-theme="dark"] .border-slate-200 { border-color: var(--border-subtle) !important; }
[data-theme="dark"] .text-slate-900,
[data-theme="dark"] .text-slate-800,
[data-theme="dark"] .text-slate-700 { color: var(--text-primary) !important; }
[data-theme="dark"] .text-slate-600,
[data-theme="dark"] .text-slate-500 { color: var(--text-secondary) !important; }
[data-theme="dark"] .text-slate-400,
[data-theme="dark"] .text-slate-300 { color: var(--text-tertiary) !important; }
[data-theme="dark"] .bg-amber-50 { background-color: rgba(251,191,36,.10) !important; }
[data-theme="dark"] .text-amber-900,
[data-theme="dark"] .text-amber-800,
[data-theme="dark"] .text-amber-700,
[data-theme="dark"] .text-amber-600 { color: var(--warning-text) !important; }
[data-theme="dark"] .border-amber-200 { border-color: var(--warning-border) !important; }
[data-theme="dark"] .bg-blue-50 { background-color: var(--info-bg) !important; }
[data-theme="dark"] .border-blue-200 { border-color: var(--info-border) !important; }
[data-theme="dark"] .text-blue-700 { color: var(--info-text) !important; }
[data-theme="dark"] input[type="file"] { color: var(--text-secondary); }
input[type="color"] {
  background: var(--bg-surface);
  border: 1px solid var(--border-default) !important;
  border-radius: 12px;
  min-height: 44px;
}

/* Invoices: responsive line items look like form cards on smaller screens */
.line-item-row { background: var(--bg-elevated) !important; }
.line-item-row:nth-child(even) { background: var(--bg-surface) !important; }
.invoice-line-head { background: var(--bg-surface) !important; border-color: var(--border-subtle) !important; color: var(--text-tertiary) !important; }
#lineItems { border-color: var(--border-subtle) !important; }

@media (max-width: 1180px) {
  .dashboard-chart-grid,
  .dashboard-table-grid,
  .form-layout-2-1 { grid-template-columns: 1fr; }
  .sticky-form-card { position: static; }
}
@media (max-width: 820px) {
  html { font-size: 15px; }
  .page-area { padding: 18px; }
  .dashboard-kpi-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dashboard-kpi-grid .stat-card { min-height: 148px; }
  .form-grid-2,
  .form-grid-3,
  .toggle-row { grid-template-columns: 1fr; }
  .form-grid-span-2,
  .form-grid-span-3 { grid-column: span 1; }
  .form-section-card .card-header,
  .form-section-card .card-body { padding: 18px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
}
@media (max-width: 540px) {
  .page-area { padding: 14px; }
  .dashboard-kpi-grid { grid-template-columns: 1fr; }
  .dashboard-kpi-grid .stat-card { min-height: 150px; }
  .dashboard-chart-grid, .dashboard-table-grid { gap: 14px; }
  .card-header { align-items: flex-start; flex-direction: column; }
  .card-header .btn, .card-header .btn-primary, .card-header .btn-secondary { width: 100%; }
  .page-actions .btn span { display: inline; }
}

/* Status badges also work when templates use only badge-STATUS without .badge */
.badge-draft, .badge-sent, .badge-viewed, .badge-partial, .badge-overdue,
.badge-paid, .badge-completed, .badge-cancelled, .badge-failed, .badge-refunded {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px;
  border-radius: 99px;
  font-size: .72rem;
  font-weight: 700;
  letter-spacing: .02em;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge-draft { background: rgba(92,99,112,.15); color: var(--text-secondary); border-color: var(--border-subtle); }
.badge-sent { background: var(--info-bg); color: var(--info-text); border-color: var(--info-border); }
.badge-viewed { background: rgba(139,92,246,.12); color: #a78bfa; border-color: rgba(167,139,250,.25); }
.badge-partial { background: var(--warning-bg); color: var(--warning-text); border-color: var(--warning-border); }
.badge-overdue { background: var(--danger-bg); color: var(--danger-text); border-color: var(--danger-border); }

/* ═══════════════════════════════════════════════════════════════
   Professional UI Resizing Patch — compact cards, readable forms
   ═══════════════════════════════════════════════════════════════ */
:root { --sidebar-w: 248px; }
html { font-size: 15.5px; }
body { letter-spacing: 0; }

/* Replace the oversized display heading look with clean app typography. */
.page-title-area h2,
.page-title,
.stat-value,
.sidebar-brand-text h1 {
  font-family: 'DM Sans', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif !important;
}
.page-title-area h2,
.page-title {
  font-size: clamp(1.22rem, .72vw + 1rem, 1.58rem) !important;
  line-height: 1.22 !important;
  font-weight: 760 !important;
  letter-spacing: -0.025em !important;
}
.page-title-area p,
.page-subtitle { font-size: .86rem !important; line-height: 1.45 !important; }
.page-header { margin-bottom: 18px !important; }
.page-area { padding: 22px 26px !important; }
.page-area > .stagger,
.page-area > .fade-in,
.crud-page { max-width: 1360px !important; }
.stagger { display: flex; flex-direction: column; gap: 18px; }
.stagger > * { margin-top: 0 !important; }

/* Sidebar: smaller footer/profile, no oversized chevron. */
.sidebar-brand { padding: 17px 17px; }
.sidebar-nav { padding: 12px 10px; }
.nav-section-label { padding: 12px 10px 6px; }
.nav-item { min-height: 38px; padding: 8px 10px; font-size: .86rem; }
.sidebar-footer { padding: 10px; background: linear-gradient(180deg, transparent, rgba(255,255,255,.015)); }
.sidebar-footer .user-card {
  min-height: 48px;
  padding: 8px;
  border: 1px solid var(--border-subtle);
  background: var(--bg-surface);
}
.sidebar-footer .user-card:hover { border-color: var(--border-default); }
.sidebar-footer .user-card > svg { width: 13px !important; height: 13px !important; max-width: 13px !important; max-height: 13px !important; }
.user-info { max-width: 145px; }
.user-name { font-size: .76rem; }
.user-role { font-size: .64rem; }
.avatar-sm { width: 27px; height: 27px; }

/* Compact dashboard cards with real spacing. */
.dashboard-kpi-grid,
.grid-4 {
  display: grid !important;
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 16px !important;
  margin-bottom: 0 !important;
}
.grid-3 { display: grid !important; grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 16px !important; }
.grid-2 { gap: 16px !important; }
.dashboard-chart-grid,
.dashboard-table-grid { gap: 16px !important; margin-bottom: 0 !important; }
.dashboard-kpi-grid .stat-card,
.grid-4 .stat-card,
.grid-3 .stat-card {
  min-height: 124px !important;
  padding: 16px !important;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.stat-card { border-radius: 18px !important; }
.dashboard-kpi-grid .stat-icon,
.grid-4 .stat-icon,
.grid-3 .stat-icon { width: 36px !important; height: 36px !important; margin-bottom: 10px !important; }
.dashboard-kpi-grid .stat-icon svg,
.grid-4 .stat-icon svg,
.grid-3 .stat-icon svg { width: 17px !important; height: 17px !important; }
.stat-label { font-size: .66rem !important; margin-bottom: 6px !important; }
.stat-value { font-size: clamp(1.35rem, .8vw + .95rem, 1.72rem) !important; line-height: 1.12 !important; letter-spacing: -.03em !important; }
.stat-meta { font-size: .76rem !important; margin-top: 7px !important; }
.card { border-radius: 18px !important; }
.card-header { padding: 15px 18px !important; }
.card-body { padding: 18px !important; }
.card-title { font-size: .94rem !important; }
.card-subtitle { font-size: .78rem !important; }

/* Forms: more user friendly, 2-column until phone size. */
.form-layout-2-1 { grid-template-columns: minmax(0, 1fr) minmax(280px, 330px) !important; gap: 18px !important; }
.form-main-stack,
.form-sidebar-stack { gap: 16px !important; }
.form-section-card .card-header { padding: 16px 18px !important; }
.form-section-card .card-body { padding: 18px !important; }
.form-grid { gap: 16px !important; }
.form-grid-2 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
.form-grid-3 { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; }
.form-grid-span-2 { grid-column: span 2 !important; }
.form-grid-span-3 { grid-column: span 3 !important; }
.form-input, .form-select, .form-textarea { min-height: 42px !important; font-size: .9rem !important; padding: 10px 13px !important; }
.form-label { font-size: .8rem !important; }
.toggle-card { padding: 12px !important; }
.toggle-card strong { font-size: .85rem !important; }
.toggle-card small { font-size: .73rem !important; }
.sticky-form-card { top: 18px !important; }

/* Invoice builder */
.invoice-builder-layout { align-items: start; }
.compact-select { width: min(220px, 100%); }
.client-select-row { display: flex; gap: 10px; align-items: center; }
.icon-only-btn { width: 42px; min-width: 42px; padding-left: 0 !important; padding-right: 0 !important; }
.invoice-items-card .card-header { align-items: center !important; }
.invoice-item-head,
.invoice-item-card {
  display: grid;
  grid-template-columns: minmax(280px, 2.2fr) 78px 78px 105px 92px 78px 120px 38px;
  gap: 10px;
  align-items: start;
}
.invoice-item-head {
  padding: 12px 18px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-tertiary);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.invoice-item-list { display: flex; flex-direction: column; gap: 10px; padding: 14px; }
.invoice-item-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: 16px;
  padding: 14px;
}
.invoice-item-card:hover { border-color: var(--border-default); }
.invoice-item-main { display: grid; gap: 9px; }
.item-details-input { min-height: 36px !important; font-size: .82rem !important; color: var(--text-secondary); }
.item-stock-note { color: var(--warning-text); font-size: .72rem; margin-top: 6px; font-weight: 700; }
.number-input { text-align: right; }
.invoice-row-total {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  font-weight: 800;
  color: var(--accent-400);
  white-space: nowrap;
  font-size: .92rem;
}
.invoice-remove-btn { width: 36px; height: 42px; padding: 0 !important; color: var(--danger-text); }
.mobile-only-label { display: none !important; }
.form-notes-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.summary-line,
.summary-total { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 8px 0; }
.summary-line { color: var(--text-secondary); font-size: .88rem; }
.summary-line strong { color: var(--text-primary); }
.summary-total { border-top: 1px solid var(--border-subtle); margin-top: 8px; padding-top: 16px; font-weight: 800; }
.summary-total strong { color: var(--accent-400); font-size: 1.4rem; }
.summary-discount-box { background: var(--bg-surface); border: 1px solid var(--border-subtle); border-radius: 14px; padding: 12px; margin: 8px 0; }
.discount-row { display: grid; grid-template-columns: 92px 1fr; gap: 8px; }
.mt-soft { margin-top: 16px; }
.subtle-tip-card .card-body { display: grid; gap: 8px; color: var(--text-secondary); font-size: .82rem; }
.tip-icon { width: 34px; height: 34px; display: flex; align-items: center; justify-content: center; border-radius: 12px; background: var(--warning-bg); color: var(--warning-text); }

/* Settings tabs polish */
.settings-shell { max-width: 1100px !important; }
.settings-tabs { display:flex; gap:6px; background:var(--bg-surface); border:1px solid var(--border-subtle); border-radius:16px; padding:5px; width:max-content; max-width:100%; flex-wrap:wrap; }
.settings-tab { border:0; background:transparent; color:var(--text-secondary); padding:8px 14px; border-radius:12px; font-weight:700; font-size:.84rem; cursor:pointer; }
.settings-tab.active { background:var(--bg-elevated); color:var(--text-primary); box-shadow:var(--shadow-sm); }
.settings-grid { display:grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap:16px; }

@media (max-width: 1240px) {
  .invoice-item-head { display: none !important; }
  .invoice-item-card { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .invoice-item-main { grid-column: 1 / -1; }
  .invoice-row-total { grid-column: span 2; justify-content: flex-start; }
  .invoice-remove-btn { grid-column: span 1; }
  .mobile-only-label { display: block !important; }
}
@media (max-width: 1100px) {
  .dashboard-kpi-grid,
  .grid-4 { grid-template-columns: repeat(2, minmax(0, 1fr)) !important; }
  .form-layout-2-1 { grid-template-columns: 1fr !important; }
  .sticky-form-card { position: static !important; }
}
@media (max-width: 760px) {
  html { font-size: 15px; }
  .page-area { padding: 16px !important; }
  .page-title-area h2, .page-title { font-size: 1.22rem !important; }
  .dashboard-kpi-grid,
  .grid-4,
  .grid-3,
  .grid-2,
  .form-notes-grid,
  .settings-grid { grid-template-columns: 1fr !important; }
  .form-grid-2,
  .form-grid-3,
  .toggle-row { grid-template-columns: 1fr !important; }
  .form-grid-span-2,
  .form-grid-span-3 { grid-column: span 1 !important; }
  .invoice-item-card { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .invoice-row-total { grid-column: 1 / -1; }
  .invoice-remove-btn { grid-column: 1 / -1; width: 100%; }
  .client-select-row { align-items: stretch; }
  .card-header { align-items: flex-start !important; flex-direction: column; }
  .card-header .btn, .card-header .form-select { width: 100%; }
  .summary-total strong { font-size: 1.2rem; }
}
@media (max-width: 480px) {
  .page-area { padding: 12px !important; }
  .invoice-item-card { grid-template-columns: 1fr; }
  .discount-row { grid-template-columns: 1fr; }
  .topbar-actions .btn span { display: none; }
}

/* ── Invoice item builder v2: product/custom friendly UI ───────────── */
.invoice-item-builder-card {
  overflow: hidden;
}
.invoice-items-header-v2 {
  gap: 14px !important;
}
.invoice-add-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.invoice-item-helper-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
  padding: 12px 16px;
  border-top: 1px solid var(--border-subtle);
  border-bottom: 1px solid var(--border-subtle);
  background: linear-gradient(180deg, rgba(255,255,255,0.025), rgba(255,255,255,0.01));
}
.invoice-item-helper-strip > div {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  min-width: 0;
  color: var(--text-secondary);
  font-size: .78rem;
  line-height: 1.45;
}
.invoice-item-helper-strip svg {
  width: 16px;
  height: 16px;
  color: var(--accent-400);
  flex: 0 0 auto;
  margin-top: 1px;
}
.invoice-item-helper-strip strong {
  color: var(--text-primary);
}
.invoice-item-list-v2 {
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 16px;
}
.invoice-item-card-v2 {
  display: block;
  border: 1px solid var(--border-subtle);
  background: linear-gradient(180deg, var(--bg-surface), rgba(255,255,255,0.018));
  border-radius: 18px;
  padding: 14px;
  box-shadow: var(--shadow-sm);
  transition: border-color var(--transition), transform var(--transition), box-shadow var(--transition);
}
.invoice-item-card-v2:hover {
  border-color: var(--border-default);
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}
.invoice-item-card-v2.is-product-mode {
  border-color: rgba(245,158,11,0.18);
}
.invoice-item-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}
.invoice-item-title-block {
  min-width: 0;
  display: grid;
  gap: 3px;
}
.invoice-item-title-block strong {
  color: var(--text-primary);
  font-size: .98rem;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.invoice-item-number {
  width: max-content;
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 9px;
  background: var(--bg-elevated);
  border: 1px solid var(--border-subtle);
  color: var(--text-tertiary);
  font-size: .68rem;
  font-weight: 800;
  letter-spacing: .07em;
  text-transform: uppercase;
}
.invoice-item-toolbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 0 0 auto;
}
.item-mode-switch {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--border-subtle);
  border-radius: 14px;
  background: var(--bg-elevated);
}
.item-mode-switch button {
  height: 34px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: 0;
  border-radius: 10px;
  padding: 0 10px;
  background: transparent;
  color: var(--text-secondary);
  font-size: .78rem;
  font-weight: 800;
  cursor: pointer;
  transition: background var(--transition), color var(--transition), box-shadow var(--transition);
}
.item-mode-switch button:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}
.item-mode-switch button.active {
  background: var(--accent-500);
  color: #111318;
  box-shadow: var(--shadow-glow);
}
.item-mode-switch svg,
.invoice-item-remove svg {
  width: 15px;
  height: 15px;
}
.invoice-item-remove {
  width: 38px;
  height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  background: var(--bg-elevated);
  color: var(--danger-text);
  cursor: pointer;
  transition: background var(--transition), border-color var(--transition), opacity var(--transition);
}
.invoice-item-remove:hover:not(:disabled) {
  background: var(--danger-bg);
  border-color: var(--danger-border);
}
.invoice-item-remove:disabled {
  opacity: .38;
  cursor: not-allowed;
}
.invoice-product-panel {
  display: grid;
  gap: 12px;
  padding: 13px;
  margin-bottom: 14px;
  border: 1px solid rgba(245,158,11,0.16);
  border-radius: 16px;
  background: rgba(245,158,11,0.055);
}
.product-picker-field {
  margin-bottom: 0 !important;
}
.selected-product-preview {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
}
.selected-product-preview > div {
  min-width: 0;
  border: 1px solid var(--border-subtle);
  background: rgba(0,0,0,0.10);
  border-radius: 13px;
  padding: 10px;
}
.selected-product-preview span,
.line-total-card span {
  display: block;
  color: var(--text-tertiary);
  font-size: .68rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 4px;
}
.selected-product-preview strong {
  display: block;
  color: var(--text-primary);
  font-size: .86rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.product-empty-note,
.stock-alert {
  margin: 0;
  font-size: .78rem;
  line-height: 1.45;
}
.product-empty-note {
  color: var(--text-secondary);
}
.stock-alert {
  color: var(--danger-text);
  background: var(--danger-bg);
  border: 1px solid var(--danger-border);
  border-radius: 12px;
  padding: 9px 11px;
  font-weight: 800;
}
.custom-item-panel {
  display: flex;
  align-items: flex-start;
  gap: 9px;
  padding: 11px 12px;
  margin-bottom: 14px;
  border: 1px solid var(--info-border);
  border-radius: 14px;
  color: var(--info-text);
  background: var(--info-bg);
  font-size: .8rem;
  line-height: 1.45;
}
.custom-item-panel svg {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  margin-top: 2px;
}
.invoice-item-fields-grid {
  display: grid;
  grid-template-columns: minmax(260px, 1.45fr) minmax(220px, 1fr) 76px 86px 110px 98px 86px 130px;
  gap: 11px;
  align-items: end;
}
.invoice-field-description,
.invoice-field-details {
  min-width: 0;
}
.item-mini-textarea {
  min-height: 42px !important;
  height: 42px;
  resize: vertical;
  line-height: 1.35 !important;
}
.line-total-card {
  min-height: 42px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-end;
  border: 1px solid var(--border-subtle);
  border-radius: 13px;
  background: var(--bg-elevated);
  padding: 7px 10px;
}
.line-total-card strong {
  color: var(--accent-400);
  font-size: .96rem;
  line-height: 1.15;
  white-space: nowrap;
}

@media (max-width: 1380px) {
  .invoice-item-fields-grid {
    grid-template-columns: repeat(6, minmax(0, 1fr));
  }
  .invoice-field-description,
  .invoice-field-details {
    grid-column: span 3;
  }
  .line-total-card {
    grid-column: span 2;
  }
}
@media (max-width: 980px) {
  .invoice-item-helper-strip,
  .selected-product-preview {
    grid-template-columns: 1fr 1fr;
  }
  .invoice-item-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }
  .invoice-item-toolbar-actions,
  .item-mode-switch {
    width: 100%;
  }
  .item-mode-switch button {
    flex: 1;
  }
  .invoice-item-remove {
    width: 42px;
    min-width: 42px;
  }
  .invoice-item-fields-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  .invoice-field-description,
  .invoice-field-details,
  .line-total-card {
    grid-column: 1 / -1;
  }
}
@media (max-width: 640px) {
  .invoice-add-actions,
  .invoice-add-actions .btn,
  .invoice-item-toolbar-actions {
    width: 100%;
  }
  .invoice-add-actions .btn {
    justify-content: center;
  }
  .invoice-item-helper-strip,
  .selected-product-preview,
  .invoice-item-fields-grid {
    grid-template-columns: 1fr;
  }
  .invoice-item-list-v2 {
    padding: 12px;
  }
  .invoice-item-card-v2 {
    border-radius: 16px;
    padding: 12px;
  }
  .invoice-item-toolbar-actions {
    align-items: stretch;
  }
  .invoice-item-remove {
    height: 42px;
  }
  .item-mode-switch {
    flex: 1 1 auto;
  }
  .item-mode-switch button span {
    display: inline;
  }
  .line-total-card {
    align-items: flex-start;
  }
}

/* --------------------------------------------------------------------------
   Invoice item responsive hotfix
   Fixes laptop/tablet overflow where Discount, Tax, and Total could collide
   with the sticky invoice summary sidebar.
---------------------------------------------------------------------------- */
.invoice-builder-layout,
.invoice-builder-layout .form-main-stack,
.invoice-builder-layout .form-sidebar-stack,
.invoice-builder-layout .card,
.invoice-builder-layout .card-body,
.invoice-builder-layout .invoice-item-card-v2,
.invoice-builder-layout .invoice-item-fields-grid,
.invoice-builder-layout .form-group {
  min-width: 0 !important;
}

.invoice-builder-layout {
  grid-template-columns: minmax(0, 1fr) minmax(260px, 300px) !important;
  gap: 16px !important;
}

.invoice-items-card,
.invoice-item-builder-card,
.invoice-item-card-v2 {
  overflow: hidden !important;
}

.invoice-item-fields-grid {
  grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  gap: 12px !important;
  align-items: end !important;
}

.invoice-field-description,
.invoice-field-details {
  grid-column: span 2 !important;
}

.invoice-item-fields-grid .form-input,
.invoice-item-fields-grid .form-select,
.invoice-item-fields-grid .form-textarea,
.invoice-item-fields-grid input,
.invoice-item-fields-grid textarea {
  width: 100% !important;
  max-width: 100% !important;
  box-sizing: border-box !important;
}

.line-total-card {
  grid-column: span 1 !important;
  min-width: 0 !important;
}

.line-total-card strong {
  max-width: 100% !important;
  overflow: hidden !important;
  text-overflow: ellipsis !important;
}

.invoice-summary-card {
  max-width: 300px !important;
  width: 100% !important;
}

@media (min-width: 1500px) {
  .invoice-builder-layout {
    grid-template-columns: minmax(0, 1fr) minmax(280px, 320px) !important;
    gap: 18px !important;
  }

  .invoice-item-fields-grid {
    grid-template-columns: minmax(260px, 1.25fr) minmax(220px, 1fr) 76px 82px 104px 94px 82px 126px !important;
  }

  .invoice-field-description,
  .invoice-field-details,
  .line-total-card {
    grid-column: span 1 !important;
  }
}

@media (max-width: 1180px) {
  .invoice-builder-layout {
    grid-template-columns: 1fr !important;
  }

  .invoice-summary-card {
    max-width: none !important;
  }

  .invoice-summary-card.sticky-form-card {
    position: static !important;
  }
}

@media (max-width: 860px) {
  .invoice-item-fields-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }

  .invoice-field-description,
  .invoice-field-details,
  .line-total-card {
    grid-column: 1 / -1 !important;
  }

  .line-total-card {
    align-items: flex-start !important;
  }
}

@media (max-width: 560px) {
  .invoice-item-fields-grid,
  .selected-product-preview,
  .invoice-item-helper-strip {
    grid-template-columns: 1fr !important;
  }
}

/* --------------------------------------------------------------------------
   Retailytics Phase 1 light theme polish
   Cleaner daily-use retail/POS visual system for owners, managers and cashiers.
---------------------------------------------------------------------------- */
[data-theme="light"] {
  --bg-base: #f6f8fb;
  --bg-elevated: #ffffff;
  --bg-surface: #ffffff;
  --bg-overlay: #f8fafc;
  --bg-hover: #eef4ff;
  --border-subtle: rgba(15, 23, 42, 0.06);
  --border-default: rgba(15, 23, 42, 0.10);
  --border-strong: rgba(15, 23, 42, 0.16);
  --text-primary: #101828;
  --text-secondary: #475467;
  --text-tertiary: #98a2b3;
  --accent-400: #2563eb;
  --accent-500: #2563eb;
  --accent-600: #1d4ed8;
  --accent-700: #1e40af;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, .05);
  --shadow-md: 0 8px 24px rgba(15, 23, 42, .07);
  --shadow-lg: 0 18px 48px rgba(15, 23, 42, .10);
  --shadow-glow: 0 0 0 1px rgba(37, 99, 235, .16), 0 12px 32px rgba(37, 99, 235, .12);
}

[data-theme="light"] body {
  background:
    radial-gradient(circle at top left, rgba(37, 99, 235, .06), transparent 32rem),
    linear-gradient(180deg, #f8fafc 0%, #f4f7fb 100%);
  letter-spacing: 0;
}

[data-theme="light"] .sidebar {
  background: rgba(255,255,255,.92);
  backdrop-filter: blur(16px);
  border-right-color: rgba(15,23,42,.08);
}

[data-theme="light"] .sidebar-logo,
[data-theme="light"] .brand-mark {
  background: rgba(15,23,42,.04) !important;
  color: #fff;
}

[data-theme="light"] .nav-link.active,
[data-theme="light"] .nav-link:hover {
  background: #eff6ff;
  color: #1d4ed8;
}

[data-theme="light"] .nav-link.active::before {
  background: #2563eb;
}

[data-theme="light"] .topbar,
[data-theme="light"] .card,
[data-theme="light"] .stat-card,
[data-theme="light"] .form-section-card {
  background: rgba(255,255,255,.96);
  border-color: rgba(15,23,42,.08);
  box-shadow: 0 10px 32px rgba(15,23,42,.06);
}

[data-theme="light"] .card-header {
  border-bottom-color: rgba(15,23,42,.07);
}

[data-theme="light"] .form-input,
[data-theme="light"] .form-select,
[data-theme="light"] .form-textarea {
  background: #fff;
  border-color: #d9e0ea;
  color: #101828;
  box-shadow: 0 1px 2px rgba(15,23,42,.03);
}

[data-theme="light"] .form-input:focus,
[data-theme="light"] .form-select:focus,
[data-theme="light"] .form-textarea:focus {
  border-color: #2563eb;
  box-shadow: 0 0 0 4px rgba(37,99,235,.11);
}

[data-theme="light"] .btn-primary {
  background: linear-gradient(135deg, #2563eb, #1d4ed8);
  color: #fff;
  box-shadow: 0 10px 22px rgba(37,99,235,.20);
}

[data-theme="light"] .btn-secondary {
  background: #fff;
  border-color: #d9e0ea;
  color: #344054;
}

[data-theme="light"] .btn-secondary:hover {
  background: #f8fafc;
  border-color: #c8d3e2;
  color: #101828;
}

.settings-branch-panel {
  margin-top: 18px;
  padding: 16px;
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  background: linear-gradient(135deg, rgba(37,99,235,.055), rgba(6,182,212,.045));
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: flex-start;
}
.settings-branch-panel strong { color: var(--text-primary); font-size: .95rem; }
.settings-branch-panel p { margin-top: 4px; font-size: .82rem; max-width: 560px; }
.settings-branch-list { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.purchase-item-row,
.inventory-summary-card,
.retail-soft-panel {
  border: 1px solid var(--border-subtle);
  border-radius: 18px;
  background: var(--bg-overlay);
}

@media (max-width: 760px) {
  .settings-branch-panel { flex-direction: column; }
  .settings-branch-list { justify-content: flex-start; }
}

/* Phase 2 POS payment status badges */
.badge-due { display:inline-flex; align-items:center; gap:4px; padding:3px 9px; border-radius:99px; font-size:.68rem; font-weight:700; background:var(--danger-bg); color:var(--danger-text); border:1px solid var(--danger-border); }
.badge-partial { display:inline-flex; align-items:center; gap:4px; padding:3px 9px; border-radius:99px; font-size:.68rem; font-weight:700; background:var(--warning-bg); color:var(--warning-text); border:1px solid var(--warning-border); }

/* Phase 3 report polish */
.grid-5 { display:grid; grid-template-columns: repeat(5, minmax(0,1fr)); gap:16px; }
.report-card-link .card-title { margin-bottom: 5px; }
.report-card-link:hover .card-title { color: var(--accent-500); }
.badge-stock_in, .badge-purchase, .badge-return { background: var(--success-bg); color: var(--success-text); border: 1px solid var(--success-border); }
.badge-stock_out, .badge-sale { background: var(--info-bg); color: var(--info-text); border: 1px solid var(--info-border); }
.badge-adjustment { background: var(--warning-bg); color: var(--warning-text); border: 1px solid var(--warning-border); }
.badge-damage { background: var(--danger-bg); color: var(--danger-text); border: 1px solid var(--danger-border); }
@media(max-width:1200px){ .grid-5 { grid-template-columns: repeat(3, minmax(0,1fr)); } }
@media(max-width:768px){ .grid-5 { grid-template-columns: repeat(2, minmax(0,1fr)); } form.card .card-body[style*="grid-template-columns"] { grid-template-columns: 1fr !important; } }
@media(max-width:520px){ .grid-5 { grid-template-columns: 1fr; } }


/* Dark-mode sidebar polish: stable active state with no route-load flicker. */
html[data-theme="dark"] .sidebar,
html[data-theme="dark"] .topbar { background: #121418; }
html[data-theme="dark"] .nav-item.active {
  background: rgba(245, 158, 11, 0.14);
  color: #fbbf24;
  box-shadow: inset 0 0 0 1px rgba(245, 158, 11, 0.08);
}
html[data-theme="dark"] .nav-item:hover { background: rgba(255,255,255,0.045); }
