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

:root {
  /* — Deep purple / electric blue palette — */
  --bg-primary:    #ffffff;
  --bg-secondary:  #f5f4fb;
  --bg-tertiary:   #edeaf6;
  --bg-sidebar:    #0f0a1e;
  --bg-sidebar-hover:   #1a1133;
  --bg-sidebar-active:  #221545;

  --text-primary:   #0f0a1e;
  --text-secondary: #5e5680;
  --text-muted:     #a09bc0;
  --text-sidebar:   #8f87b8;

  --border:    rgba(15,10,30,0.08);
  --border-md: rgba(15,10,30,0.16);

  --accent:       #3b82f6;
  --accent-dark:  #1d4ed8;
  --accent-light: #eff6ff;
  --accent-text:  #1e40af;

  --green:       #16a34a;
  --green-light: #f0fdf4;
  --green-text:  #15803d;

  --amber-light: #fffbeb;
  --amber-text:  #b45309;

  --red-light:   #fef2f2;
  --red-text:    #dc2626;

  --blue-light:  #eff6ff;
  --blue-text:   #1d4ed8;

  --radius-sm: 5px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  --shadow-sm: 0 1px 3px rgba(15,10,30,0.07), 0 1px 2px rgba(15,10,30,0.04);
  --shadow-md: 0 4px 12px rgba(15,10,30,0.10), 0 2px 4px rgba(15,10,30,0.05);
  --shadow-lg: 0 12px 32px rgba(15,10,30,0.14), 0 4px 8px rgba(15,10,30,0.07);

  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  --font-mono: 'JetBrains Mono', 'SF Mono', monospace;

  --sidebar-w: 220px;
  --topbar-h: 56px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg-primary:   #120e22;
    --bg-secondary: #1a1530;
    --bg-tertiary:  #0d0a1a;
    --bg-sidebar:   #07050f;
    --bg-sidebar-hover:  #100c1f;
    --bg-sidebar-active: #1a1438;
    --text-primary:   #ece8ff;
    --text-secondary: #9490b8;
    --text-muted:     #534e72;
    --border:    rgba(255,255,255,0.06);
    --border-md: rgba(255,255,255,0.12);
    --accent-light: #0f1740;
    --accent-text:  #93c5fd;
    --green-light: #052012;
    --green-text:  #4ade80;
    --amber-light: #1c1000;
    --amber-text:  #fbbf24;
    --red-light:   #1c0606;
    --red-text:    #f87171;
    --blue-light:  #0a1640;
    --blue-text:   #93c5fd;
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.35);
    --shadow-lg: 0 12px 32px rgba(0,0,0,0.4);
  }
}

/* ===== BASE ===== */
body {
  font-family: var(--font-sans);
  font-size: 14px;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

/* ===== LOGIN ===== */
#login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-sidebar);
  background-image:
    radial-gradient(ellipse 60% 50% at 30% 40%, rgba(59,130,246,0.14) 0%, transparent 70%),
    radial-gradient(ellipse 40% 60% at 80% 70%, rgba(99,102,241,0.08) 0%, transparent 70%);
  padding: 1.5rem;
}

.login-box {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 2.75rem 2.25rem;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-lg);
}

.login-logo { text-align: center; margin-bottom: 2rem; }
.login-icon {
  width: 60px; height: 60px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-radius: 16px;
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto 14px;
  box-shadow: 0 6px 20px rgba(59,130,246,0.3);
}
.login-icon i { font-size: 28px; color: #fff; }
.login-logo h1 { font-size: 20px; font-weight: 700; letter-spacing: -0.02em; }
.login-logo p  { font-size: 13px; color: var(--text-secondary); margin-top: 4px; }

.login-box .form-group { margin-bottom: 14px; }
.btn-full { width: 100%; justify-content: center; }

.alert { padding: 10px 13px; border-radius: var(--radius-md); font-size: 13px; margin-bottom: 14px; font-weight: 500; }
.alert-error   { background: var(--red-light);   color: var(--red-text);   border: 1px solid rgba(220,38,38,0.15); }
.alert-success { background: var(--green-light); color: var(--green-text); border: 1px solid rgba(22,163,74,0.15); }

/* ===== APP LAYOUT — DESKTOP ===== */
.app { display: flex; min-height: 100vh; }

/* ===== SIDEBAR ===== */
.sidebar {
  width: var(--sidebar-w);
  min-width: var(--sidebar-w);
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  overscroll-behavior: contain;
  z-index: 200;
  transition: transform 0.25s ease;
}

.sidebar-logo {
  padding: 1.1rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  display: flex;
  align-items: center;
  gap: 10px;
}

.sidebar-brand-icon {
  width: 34px; height: 34px;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-radius: 9px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(59,130,246,0.3);
}
.sidebar-brand-icon i { font-size: 17px; color: #fff; }
.sidebar-brand-text h2 { font-size: 12.5px; font-weight: 700; color: #fff; letter-spacing: -0.01em; line-height: 1.2; }
#sidebar-user { font-size: 11px; color: var(--text-sidebar); margin-top: 2px; }

.section-divider {
  font-size: 10px; font-weight: 600;
  color: rgba(255,255,255,0.22);
  text-transform: uppercase; letter-spacing: 0.09em;
  padding: 1rem 1.1rem 0.3rem;
}

.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 1.1rem;
  font-size: 13px; color: var(--text-sidebar);
  cursor: pointer;
  border-left: 2px solid transparent;
  transition: all 0.12s ease;
  user-select: none; font-weight: 450;
}
.nav-item i { font-size: 17px; flex-shrink: 0; }
.nav-item:hover { background: var(--bg-sidebar-hover); color: #fff; }
.nav-item.active { background: var(--bg-sidebar-active); color: var(--accent); border-left-color: var(--accent); font-weight: 600; }
.nav-item.hidden { display: none; }

.sidebar-footer {
  margin-top: auto;
  padding: 14px 1.1rem;
  border-top: 1px solid rgba(255,255,255,0.06);
}
.sidebar-footer .btn {
  background: rgba(255,255,255,0.05);
  border-color: rgba(255,255,255,0.1);
  color: var(--text-sidebar);
  width: 100%; justify-content: center;
}
.sidebar-footer .btn:hover { background: rgba(255,255,255,0.1); color: #fff; }

/* ===== MOBILE TOP BAR ===== */
.topbar {
  display: none;
  position: sticky; top: 0; z-index: 300;
  height: var(--topbar-h);
  background: var(--bg-sidebar);
  align-items: center;
  padding: 0 1rem;
  gap: 12px;
  border-bottom: 1px solid rgba(255,255,255,0.07);
}

.topbar-brand { display: flex; align-items: center; gap: 9px; flex: 1; min-width: 0; }
.topbar-title { font-size: 13.5px; font-weight: 700; color: #fff; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-icon {
  width: 28px; height: 28px; flex-shrink: 0;
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 2px 6px rgba(59,130,246,0.3);
}
.topbar-icon i { font-size: 14px; color: #fff; }
.topbar-menu-btn {
  background: rgba(255,255,255,0.08); border: none;
  width: 36px; height: 36px; border-radius: var(--radius-md);
  color: #fff; font-size: 20px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* Mobile overlay */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 199;
  backdrop-filter: blur(2px);
}
.sidebar-overlay.visible { display: block; }

/* Lock page scroll when mobile menu is open */
body.menu-open { overflow: hidden; touch-action: none; }

/* ===== MAIN ===== */
.main { flex: 1; padding: 1.75rem 2rem; overflow-x: hidden; min-width: 0; }
.page { display: none; }
.page.active { display: block; }

.page-header { margin-bottom: 1.75rem; display: flex; align-items: flex-end; justify-content: space-between; flex-wrap: wrap; gap: 10px; }
.page-header-left h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.page-header-left p  { font-size: 13px; color: var(--text-secondary); margin-top: 3px; }
.page-header h1 { font-size: 22px; font-weight: 700; letter-spacing: -0.02em; }
.page-header p  { font-size: 13px; color: var(--text-secondary); margin-top: 3px; }

/* ===== METRICS ===== */
.metric-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px; margin-bottom: 1.25rem;
}

.metric {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
}
.metric::before {
  content: '';
  position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--accent-dark));
  opacity: 0; transition: opacity 0.2s;
}
.metric:hover::before { opacity: 1; }

.metric-label { font-size: 11px; color: var(--text-secondary); margin-bottom: 6px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em; }
.metric-value { font-size: 22px; font-weight: 700; letter-spacing: -0.03em; font-family: var(--font-mono); }
.metric-sub   { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

/* ===== CARDS ===== */
.card {
  background: var(--bg-primary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
}

.card-title {
  font-size: 14px; font-weight: 600; letter-spacing: -0.01em;
  margin-bottom: 1rem;
  display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
}

/* ===== TABLES ===== */
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left; padding: 8px 10px;
  font-weight: 600; color: var(--text-secondary);
  font-size: 11px; border-bottom: 1px solid var(--border);
  background: var(--bg-secondary); white-space: nowrap;
  text-transform: uppercase; letter-spacing: 0.04em;
}
td { padding: 9px 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg-secondary); }

.table-footer { padding: 10px 0 0; font-size: 13px; color: var(--text-secondary); }
.empty-state  { text-align: center; padding: 2rem; color: var(--text-muted); font-size: 13px; }

/* ===== FORMS ===== */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 12px; margin-bottom: 12px;
}

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-group label {
  font-size: 11px; color: var(--text-secondary);
  font-weight: 600; text-transform: uppercase; letter-spacing: 0.05em;
}

input[type=text], input[type=number], input[type=password],
input[type=date], input[type=month], input[type=tel], select, textarea {
  font-family: var(--font-sans); font-size: 14px;
  padding: 8px 11px;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-md);
  background: var(--bg-primary); color: var(--text-primary);
  width: 100%;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none; -webkit-appearance: none;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(59,130,246,0.12);
}
input::placeholder { color: var(--text-muted); }
.input-sm { font-size: 12px; padding: 5px 9px; width: auto; }
input[readonly] { background: var(--bg-secondary, #f2f2ee); color: var(--text-secondary); cursor: not-allowed; }

/* ===== BUTTONS ===== */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 15px;
  border: 1px solid var(--border-md);
  border-radius: var(--radius-md);
  background: var(--bg-primary); color: var(--text-primary);
  font-size: 13px; font-family: var(--font-sans); font-weight: 500;
  cursor: pointer; transition: all 0.12s ease; white-space: nowrap;
}
.btn:hover { background: var(--bg-secondary); }
.btn:active { transform: scale(0.98); }

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff; border-color: transparent;
  box-shadow: 0 2px 8px rgba(59,130,246,0.25);
}
.btn-primary:hover {
  background: linear-gradient(135deg, #60a5fa, var(--accent));
  box-shadow: 0 4px 14px rgba(59,130,246,0.35);
}

.btn-danger { color: var(--red-text); border-color: rgba(220,38,38,0.2); }
.btn-danger:hover { background: var(--red-light); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-full { width: 100%; justify-content: center; }

/* ===== BADGES ===== */
.badge {
  display: inline-flex; align-items: center;
  padding: 3px 9px; border-radius: 20px;
  font-size: 11px; font-weight: 600; letter-spacing: 0.02em;
}
.badge-green { background: var(--green-light); color: var(--green-text); }
.badge-amber { background: var(--amber-light); color: var(--amber-text); }
.badge-red   { background: var(--red-light);   color: var(--red-text);   }
.badge-blue  { background: var(--blue-light);  color: var(--blue-text);  }
.badge-teal  { background: var(--accent-light); color: var(--accent-text); }

/* ===== CALC PREVIEW ===== */
.calc-preview {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 10px 13px;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-md); margin-bottom: 12px; font-size: 13px;
}
.calc-label { color: var(--text-secondary); font-size: 12px; font-weight: 500; }
.calc-preview strong { font-family: var(--font-mono); font-size: 13px; font-weight: 600; }

/* ===== PERMISSIONS ===== */
.perms-table { border: 1px solid var(--border); border-radius: var(--radius-md); overflow: hidden; font-size: 13px; }
.perms-header, .perms-row {
  display: grid;
  grid-template-columns: 1fr 70px 100px 70px;
  align-items: center; padding: 8px 12px;
}
.perms-header { background: var(--bg-secondary); font-size: 11px; font-weight: 600; color: var(--text-secondary); text-transform: uppercase; letter-spacing: 0.04em; }
.perms-row { border-top: 1px solid var(--border); }
.perms-row span { display: flex; align-items: center; gap: 7px; font-weight: 500; }
.perms-row span i { font-size: 15px; color: var(--text-secondary); }
.perms-row input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); cursor: pointer; }

/* ===== MODAL ===== */
.modal {
  position: fixed; inset: 0;
  background: rgba(7,5,15,0.6); backdrop-filter: blur(4px);
  z-index: 500; display: flex;
  align-items: center; justify-content: center;
  padding: 1rem;
}
.modal-box {
  background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 1.75rem; width: 100%; max-width: 600px;
  max-height: 90vh; overflow-y: auto;
  box-shadow: var(--shadow-lg);
}
.modal-title {
  font-size: 16px; font-weight: 700; letter-spacing: -0.02em;
  margin-bottom: 1.25rem;
  display: flex; align-items: center; justify-content: space-between;
}
.modal-close {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: var(--radius-sm); cursor: pointer;
  color: var(--text-secondary); font-size: 16px; padding: 4px 6px;
  transition: all 0.12s;
}
.modal-close:hover { background: var(--red-light); color: var(--red-text); border-color: transparent; }

/* ===== TOAST ===== */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg-sidebar); color: #fff;
  padding: 11px 18px; border-radius: var(--radius-md);
  font-size: 13px; font-weight: 500; z-index: 9999;
  box-shadow: var(--shadow-lg); border: 1px solid rgba(255,255,255,0.1);
  animation: slideInToast 0.2s ease;
}
@keyframes slideInToast {
  from { transform: translateY(10px); opacity: 0; }
  to   { transform: translateY(0);    opacity: 1; }
}
.toast.success { background: var(--green);    border-color: transparent; }
.toast.error   { background: var(--red-text); border-color: transparent; }

/* ===== SPINNER ===== */
.spinner {
  width: 38px; height: 38px;
  border: 3px solid rgba(255,255,255,0.2);
  border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== UTILITIES ===== */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.profit-pos { color: var(--green);    font-weight: 600; font-family: var(--font-mono); }
.profit-neg { color: var(--red-text); font-weight: 600; font-family: var(--font-mono); }

/* ===== REPORTS: FILTER CHIPS ===== */
.chip-row { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  padding: 7px 15px; border-radius: 999px;
  border: 1px solid var(--border-md);
  background: var(--bg-primary); color: var(--text-secondary);
  font-size: 12.5px; font-weight: 600; font-family: var(--font-sans);
  cursor: pointer; transition: all 0.15s ease; white-space: nowrap;
}
.chip:hover { background: var(--bg-secondary); }
.chip.active {
  background: linear-gradient(135deg, var(--accent), var(--accent-dark));
  color: #fff; border-color: transparent;
  box-shadow: 0 2px 8px rgba(59,130,246,0.25);
}

/* ===== REPORTS: KPI DELTAS ===== */
.metric-delta { font-size: 11px; font-weight: 600; margin-top: 4px; display: inline-flex; align-items: center; gap: 3px; }
.metric-delta.up   { color: var(--green-text); }
.metric-delta.down { color: var(--red-text); }
.metric-delta i { font-size: 13px; }

/* ===== REPORTS: CHARTS ===== */
.chart-wrap { position: relative; height: 280px; }
.chart-wrap-sm { height: 220px; }
.add-section {}

/* ===== RESPONSIVE — TABLET ===== */
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .main { padding: 1.25rem; }
}

/* ===== RESPONSIVE — MOBILE ===== */
@media (max-width: 700px) {
  /* Show topbar */
  .topbar { display: flex; }

  /* Sidebar slides in over content */
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    transform: translateX(-100%);
    width: 260px; min-width: 0;
    height: 100dvh;
    box-shadow: var(--shadow-lg);
    z-index: 400;
  }
  .sidebar.open { transform: translateX(0); }

  /* App row: sidebar is fixed so main fills full width */
  .app { display: block; }

  /* Main content sits below the sticky topbar */
  .main {
    padding: 1rem;
    min-height: calc(100dvh - var(--topbar-h));
  }

  /* Metrics 2-up */
  .metric-grid { grid-template-columns: 1fr 1fr; gap: 10px; }
  .metric-value { font-size: 18px; }
  .metric { padding: 0.85rem 1rem; }

  /* Single-column forms */
  .form-grid { grid-template-columns: 1fr; }

  /* Smaller charts on phones */
  .chart-wrap { height: 220px; }
  .chart-wrap-sm { height: 200px; }

  /* Smaller headings */
  .page-header { margin-bottom: 1.1rem; flex-direction: column; align-items: flex-start; gap: 4px; }
  .page-header h1,
  .page-header-left h1 { font-size: 19px; }

  .card { padding: 0.9rem 1rem; }

  /* Tables scroll horizontally */
  table { font-size: 12px; }
  th, td { padding: 7px 8px; }

  /* Calc preview */
  .calc-preview { gap: 8px; flex-wrap: wrap; }

  /* Modals sheet up from bottom */
  .modal { padding: 0; align-items: flex-end; }
  .modal-box {
    border-radius: var(--radius-xl) var(--radius-xl) 0 0;
    max-height: 92dvh; padding: 1.25rem;
    width: 100%; max-width: 100%;
  }

  /* Toast full-width */
  .toast { left: 1rem; right: 1rem; bottom: 1rem; text-align: center; }

  .two-col { grid-template-columns: 1fr; }

  /* Permissions table smaller */
  .perms-header, .perms-row {
    grid-template-columns: 1fr 50px 80px 50px;
    padding: 7px 10px; font-size: 12px;
  }
}
/* Out-of-stock validation highlight */
.input-error {
  border-color: #e5484d !important;
  box-shadow: 0 0 0 2px rgba(229, 72, 77, 0.15);
}