:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --sidebar: #0f172a;
  --sidebar-hover: #1e293b;
  --sidebar-active: #2563eb;
  --border: #e6e8eb;
  --text: #0f172a;
  --text-soft: #64748b;
  --text-faint: #94a3b8;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --amber: #d97706;
  --amber-bg: #fef3c7;
  --blue-bg: #dbeafe;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(15, 23, 42, .06), 0 1px 2px rgba(15, 23, 42, .04);
  --shadow-lg: 0 20px 40px rgba(15, 23, 42, .18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}

.app { display: flex; min-height: 100vh; }

/* ---------- Login screen ---------- */
.login-screen {
  position: fixed; inset: 0; z-index: 100;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, #0f172a, #1e293b); padding: 24px;
}
.login-card {
  background: var(--surface); width: 380px; max-width: 100%;
  border-radius: 16px; box-shadow: var(--shadow-lg); padding: 32px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; }
.login-title { font-size: 22px; font-weight: 700; }
.login-help { color: var(--text-soft); font-size: 13px; margin: 4px 0 22px; }
.login-error { color: var(--red); font-size: 13px; font-weight: 600; min-height: 18px; margin-bottom: 8px; }
.login-submit { width: 100%; justify-content: center; padding: 12px; font-size: 14px; }

.logout-btn {
  width: 100%; margin-top: 12px; padding: 10px; border-radius: 9px;
  background: transparent; color: #94a3b8; border: 1px solid #1e293b;
  font-family: inherit; font-size: 13px; font-weight: 600; cursor: pointer;
  transition: background .15s, color .15s;
}
.logout-btn:hover { background: var(--sidebar-hover); color: #fff; }

/* ---------- Sidebar ---------- */
.sidebar {
  width: 248px;
  background: var(--sidebar);
  color: #cbd5e1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  flex-shrink: 0;
}
.brand {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 22px 22px 18px;
}
.brand-mark {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: linear-gradient(135deg, #3b82f6, #2563eb);
  display: grid; place-items: center;
  font-weight: 700; font-size: 20px; color: #fff;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.15; }
.brand-name { font-weight: 700; color: #fff; font-size: 16px; }
.brand-sub { font-size: 11px; color: #94a3b8; letter-spacing: .08em; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px; flex: 1; }
.nav-label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .08em;
  color: #64748b; padding: 12px 12px 6px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 10px 12px; border-radius: 9px;
  color: #cbd5e1; cursor: pointer; font-weight: 500;
  transition: background .15s, color .15s;
  user-select: none;
}
.nav-item:hover { background: var(--sidebar-hover); color: #fff; }
.nav-item.active { background: var(--sidebar-active); color: #fff; }
.nav-ico { width: 20px; text-align: center; font-size: 15px; }

.sidebar-foot { padding: 16px; }
.store-pill {
  display: flex; align-items: center; gap: 10px;
  background: var(--sidebar-hover); padding: 10px 12px; border-radius: 10px;
}
.store-pill .dot {
  width: 9px; height: 9px; border-radius: 50%; background: #22c55e;
  box-shadow: 0 0 0 3px rgba(34,197,94,.2);
}
.store-name { color: #fff; font-weight: 600; font-size: 13px; }
.store-status { color: #94a3b8; font-size: 11px; }

/* ---------- Main ---------- */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; }

.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 28px; background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 20;
}
.topbar-left h1 { font-size: 20px; font-weight: 700; }
.page-sub { color: var(--text-soft); font-size: 13px; margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.search {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border);
  padding: 9px 14px; border-radius: 9px; width: 320px;
}
.search-ico { color: var(--text-faint); font-size: 15px; }
.search input { border: none; background: none; outline: none; flex: 1; font-size: 13px; color: var(--text); }

.avatar {
  width: 36px; height: 36px; border-radius: 50%;
  background: linear-gradient(135deg, #6366f1, #2563eb);
  color: #fff; font-weight: 600; font-size: 13px;
  display: grid; place-items: center; cursor: pointer;
}

.content { padding: 26px 28px; }

/* ---------- Buttons ---------- */
.btn-primary, .btn-secondary, .btn-ghost {
  font-family: inherit; font-size: 13px; font-weight: 600;
  border-radius: 9px; cursor: pointer; border: 1px solid transparent;
  display: inline-flex; align-items: center; gap: 7px;
  transition: background .15s, border-color .15s, transform .05s;
}
.btn-primary { background: var(--primary); color: #fff; padding: 10px 16px; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: translateY(1px); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); padding: 10px 16px; }
.btn-secondary:hover { background: var(--bg); }
.btn-ghost { background: transparent; color: var(--text-soft); padding: 8px 10px; font-size: 16px; }
.btn-ghost:hover { background: var(--bg); }

/* ---------- Stat cards ---------- */
.stat-grid {
  display: grid; grid-template-columns: repeat(4, 1fr);
  gap: 16px; margin-bottom: 22px;
}
.stat-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 18px 20px; box-shadow: var(--shadow);
}
.stat-card.stat-clickable { cursor: pointer; transition: box-shadow .15s, transform .05s, border-color .15s; }
.stat-card.stat-clickable:hover { border-color: var(--primary); box-shadow: 0 6px 18px rgba(37,99,235,.12); }
.stat-card.stat-clickable:active { transform: translateY(1px); }
.stat-card .label { color: var(--text-soft); font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.stat-card .value { font-size: 26px; font-weight: 700; margin-top: 8px; }
.stat-card .trend { font-size: 12px; margin-top: 6px; display: flex; align-items: center; gap: 5px; font-weight: 600; }
.trend.up { color: var(--green); }
.trend.down { color: var(--red); }
.stat-icon {
  float: right; width: 40px; height: 40px; border-radius: 10px;
  display: grid; place-items: center; font-size: 18px;
}
.bg-blue { background: var(--blue-bg); }
.bg-green { background: var(--green-bg); }
.bg-amber { background: var(--amber-bg); }
.bg-red { background: var(--red-bg); }

/* ---------- Panel / Table ---------- */
.panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden;
  margin-bottom: 22px;
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px; border-bottom: 1px solid var(--border);
}
.panel-head h3 { font-size: 15px; font-weight: 700; }
.panel-head .sub { color: var(--text-soft); font-size: 12px; margin-top: 2px; }
.panel-actions { display: flex; gap: 8px; align-items: center; }

.toolbar {
  display: flex; gap: 10px; align-items: center;
  padding: 14px 20px; border-bottom: 1px solid var(--border); flex-wrap: wrap;
}
.filter-input, .filter-select {
  font-family: inherit; font-size: 13px; padding: 8px 12px;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface);
  color: var(--text); outline: none;
}
.filter-input:focus, .filter-select:focus { border-color: var(--primary); }
.toolbar .spacer { flex: 1; }
.toolbar.filter-row { background: #fafbfc; }
.filter-tag { font-size: 12px; font-weight: 600; color: var(--text-soft); }
.filter-select:disabled { opacity: .5; cursor: not-allowed; }

.search-mini {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg); border: 1px solid var(--border);
  padding: 8px 12px; border-radius: 8px; min-width: 280px;
}
.search-mini .search-ico { color: var(--text-faint); font-size: 14px; }
.search-mini .filter-input { border: none; background: none; padding: 0; flex: 1; }
.search-mini .filter-input:focus { border: none; }
.csv-hint {
  font-size: 11px; color: var(--text-faint); font-weight: 600;
  background: var(--bg); border: 1px dashed var(--border);
  padding: 6px 10px; border-radius: 8px;
}

table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .05em;
  color: var(--text-soft); font-weight: 600; padding: 12px 20px;
  background: #fafbfc; border-bottom: 1px solid var(--border);
}
tbody td { padding: 14px 20px; border-bottom: 1px solid var(--border); font-size: 13px; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: #fafbfc; }
.t-right { text-align: right; }
.t-strong { font-weight: 600; }
.t-muted { color: var(--text-soft); }
.t-mono { font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

.prod-cell { display: flex; align-items: center; gap: 12px; }
.prod-thumb {
  width: 36px; height: 36px; border-radius: 8px; flex-shrink: 0;
  background: linear-gradient(135deg, #e0e7ff, #c7d2fe); display: grid; place-items: center;
  font-size: 16px;
}
.prod-name { font-weight: 600; }
.prod-sku { color: var(--text-faint); font-size: 12px; }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge.green { background: var(--green-bg); color: #15803d; }
.badge.red { background: var(--red-bg); color: #b91c1c; }
.badge.amber { background: var(--amber-bg); color: #b45309; }
.badge.blue { background: var(--blue-bg); color: #1d4ed8; }
.badge.gray { background: #f1f5f9; color: #475569; }

/* ---------- Empty / misc ---------- */
.section-grid-2 { display: grid; grid-template-columns: 2fr 1fr; gap: 16px; }

.mini-list { padding: 8px 0; }
.mini-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
}
.mini-row:last-child { border-bottom: none; }
.mini-left { display: flex; align-items: center; gap: 12px; }

.bar-track { height: 8px; background: var(--bg); border-radius: 999px; overflow: hidden; width: 120px; }
.bar-fill { height: 100%; border-radius: 999px; background: var(--primary); }

/* ---------- Drawer ---------- */
.overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  opacity: 0; visibility: hidden; transition: opacity .2s; z-index: 40;
}
.overlay.open { opacity: 1; visibility: visible; }
.drawer {
  position: fixed; top: 0; right: 0; height: 100vh; width: 440px; max-width: 92vw;
  background: var(--surface); box-shadow: var(--shadow-lg);
  transform: translateX(100%); transition: transform .25s ease; z-index: 50;
  display: flex; flex-direction: column;
}
.drawer.open { transform: translateX(0); }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 22px; border-bottom: 1px solid var(--border);
}
.drawer-head h2 { font-size: 17px; font-weight: 700; }
.drawer-body { padding: 22px; overflow-y: auto; flex: 1; }
.drawer-foot {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 16px 22px; border-top: 1px solid var(--border);
}

.field { margin-bottom: 16px; }
.field label { display: block; font-size: 12px; font-weight: 600; color: var(--text-soft); margin-bottom: 6px; }
.field input, .field select, .field textarea {
  width: 100%; font-family: inherit; font-size: 13px; padding: 10px 12px;
  border: 1px solid var(--border); border-radius: 8px; outline: none; color: var(--text);
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--primary); }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- Stat drill-down modal ---------- */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15,23,42,.45);
  display: flex; align-items: center; justify-content: center;
  opacity: 0; visibility: hidden; transition: opacity .18s; z-index: 60; padding: 24px;
}
.modal-overlay.open { opacity: 1; visibility: visible; }
.modal {
  background: var(--surface); border-radius: var(--radius); box-shadow: var(--shadow-lg);
  width: 640px; max-width: 100%; max-height: 80vh; display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 18px 22px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-size: 16px; font-weight: 700; }
.modal-tools { display: flex; align-items: center; gap: 10px; padding: 12px 22px; border-bottom: 1px solid var(--border); }
.modal-tools .search-mini { min-width: 240px; }
.modal-tools .spacer { flex: 1; }
.modal-body { overflow-y: auto; }
.modal-body thead th { position: sticky; top: 0; }

/* Dashboard right-panel drill-down */
.drill-scroll { max-height: 430px; overflow-y: auto; }
.drill-scroll thead th { position: sticky; top: 0; }

@media (max-width: 1024px) {
  .stat-grid { grid-template-columns: repeat(2, 1fr); }
  .section-grid-2 { grid-template-columns: 1fr; }
}
@media (max-width: 720px) {
  .sidebar { display: none; }
  .search { width: 180px; }
}
