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

:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --text-primary: #e2e8f0;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --border: #334155;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --critical: #ef4444;
  --warning: #f59e0b;
  --success: #10b981;
  --info: #3b82f6;
  --purple: #8b5cf6;
  --sidebar-width: 240px;
  --header-height: 56px;
  --radius: 8px;
  --radius-lg: 12px;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  overflow: hidden;
  height: 100vh;
}

#app {
  display: flex;
  height: 100vh;
}

/* ── Sidebar ─────────────────────────────────────────────────── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  overflow-y: auto;
  z-index: 100;
}

.sidebar__brand {
  padding: var(--space-5);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: var(--space-3);
}

.sidebar__icon { font-size: 1.5rem; }
.sidebar__title { font-size: 1rem; font-weight: 700; color: var(--text-primary); }

.sidebar__nav {
  flex: 1;
  padding: var(--space-3);
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
}

.sidebar__footer {
  padding: var(--space-3);
  border-top: 1px solid var(--border);
}

.nav-item {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  border: none;
  background: none;
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-family: inherit;
  border-radius: var(--radius);
  cursor: pointer;
  width: 100%;
  text-align: left;
  text-decoration: none;
  transition: all 0.15s;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item--active { background: var(--accent); color: #fff; }
.nav-item--active:hover { background: var(--accent-hover); }
.nav-item--logout { color: var(--text-muted); }
.nav-icon { font-size: 1.1rem; width: 1.5rem; text-align: center; }

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

.mobile-header {
  display: none;
  align-items: center;
  gap: var(--space-3);
  padding: var(--space-3) var(--space-4);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  height: var(--header-height);
}

.hamburger {
  background: none;
  border: none;
  color: var(--text-primary);
  font-size: 1.5rem;
  cursor: pointer;
  padding: var(--space-2);
}

.mobile-header__title {
  font-weight: 600;
  font-size: 1rem;
}

.page-content {
  flex: 1;
  overflow-y: auto;
  padding: var(--space-5);
}

.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 99;
}

/* ── Cards ───────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-5);
  margin-bottom: var(--space-4);
}

.card--clickable { cursor: pointer; transition: border-color 0.15s; }
.card--clickable:hover { border-color: var(--accent); }

/* ── Stat Cards ──────────────────────────────────────────────── */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-4);
  text-align: center;
  cursor: pointer;
  transition: all 0.15s;
}

.stat-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.stat-card--critical { border-left: 3px solid var(--critical); }
.stat-card--warning { border-left: 3px solid var(--warning); }
.stat-card--upcoming { border-left: 3px solid var(--info); }
.stat-card--dead { border-left: 3px solid var(--text-muted); }
.stat-card--po { border-left: 3px solid var(--purple); }
.stat-card--healthy { border-left: 3px solid var(--success); }

.stat-card__value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
  margin-bottom: var(--space-2);
}

.stat-card__label {
  font-size: 0.75rem;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

/* ── Tables ──────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

th {
  text-align: left;
  padding: var(--space-3) var(--space-4);
  background: var(--bg-primary);
  color: var(--text-secondary);
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: var(--space-3) var(--space-4);
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

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

/* ── Badges ──────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 0.75rem;
  font-weight: 600;
  white-space: nowrap;
}

.badge--critical { background: rgba(239,68,68,0.2); color: #fca5a5; }
.badge--reorder_now { background: rgba(245,158,11,0.2); color: #fcd34d; }
.badge--upcoming { background: rgba(59,130,246,0.2); color: #93c5fd; }
.badge--healthy { background: rgba(16,185,129,0.2); color: #6ee7b7; }
.badge--dead_stock { background: rgba(100,116,139,0.2); color: #94a3b8; }
.badge--discontinue { background: rgba(100,116,139,0.2); color: #94a3b8; text-decoration: line-through; }

.badge--up { background: rgba(16,185,129,0.2); color: #6ee7b7; }
.badge--stable { background: rgba(59,130,246,0.2); color: #93c5fd; }
.badge--down { background: rgba(239,68,68,0.2); color: #fca5a5; }

.badge--active { background: rgba(16,185,129,0.2); color: #6ee7b7; }
.badge--slow_mover { background: rgba(245,158,11,0.2); color: #fcd34d; }
.badge--discontinued { background: rgba(100,116,139,0.2); color: #94a3b8; text-decoration: line-through; }
.badge--new { background: rgba(139,92,246,0.2); color: #c4b5fd; }

/* PO statuses */
.badge--draft { background: rgba(100,116,139,0.2); color: #94a3b8; }
.badge--sent { background: rgba(59,130,246,0.2); color: #93c5fd; }
.badge--confirmed { background: rgba(139,92,246,0.2); color: #c4b5fd; }
.badge--in_production { background: rgba(245,158,11,0.2); color: #fcd34d; }
.badge--shipped { background: rgba(16,185,129,0.2); color: #6ee7b7; }
.badge--in_transit { background: rgba(16,185,129,0.2); color: #6ee7b7; }
.badge--received { background: rgba(16,185,129,0.3); color: #6ee7b7; }
.badge--closed { background: rgba(100,116,139,0.2); color: #94a3b8; }

/* ── Buttons ─────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  padding: var(--space-3) var(--space-4);
  border: none;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn--primary { background: var(--accent); color: #fff; }
.btn--primary:hover { background: var(--accent-hover); }
.btn--ghost { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn--ghost:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn--danger { background: var(--critical); color: #fff; }
.btn--danger:hover { background: #dc2626; }
.btn--sm { padding: var(--space-2) var(--space-3); font-size: 0.8rem; }
.btn--full { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* ── Forms ────────────────────────────────────────────────────── */
.form-input, .form-select {
  width: 100%;
  padding: var(--space-3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-primary);
  color: var(--text-primary);
  font-size: 0.875rem;
  font-family: inherit;
}

.form-input:focus, .form-select:focus {
  outline: none;
  border-color: var(--accent);
}

.form-label {
  display: block;
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: var(--space-2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.form-group { margin-bottom: var(--space-4); }

/* ── Filters ─────────────────────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: var(--space-3);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
  align-items: center;
}

.filter-bar .form-input,
.filter-bar .form-select {
  width: auto;
  min-width: 160px;
}

.filter-pills {
  display: flex;
  gap: var(--space-2);
  flex-wrap: wrap;
  margin-bottom: var(--space-4);
}

.pill {
  padding: var(--space-2) var(--space-3);
  border: 1px solid var(--border);
  border-radius: 99px;
  background: none;
  color: var(--text-secondary);
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  transition: all 0.15s;
}

.pill:hover { background: var(--bg-hover); color: var(--text-primary); }
.pill--active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* ── Section headers ─────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--space-4);
}

.section-title {
  font-size: 1.25rem;
  font-weight: 700;
}

.section-subtitle {
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* ── Page title ──────────────────────────────────────────────── */
.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: var(--space-5);
}

/* ── Loading / Empty ─────────────────────────────────────────── */
.loading {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-6);
  color: var(--text-muted);
}

.empty-state {
  text-align: center;
  padding: var(--space-6);
  color: var(--text-muted);
}

.empty-state__icon { font-size: 3rem; margin-bottom: var(--space-3); }
.empty-state__title { font-size: 1.1rem; font-weight: 600; margin-bottom: var(--space-2); }
.empty-state__desc { font-size: 0.875rem; }

/* ── Toast ───────────────────────────────────────────────────── */
.toast {
  position: fixed;
  bottom: var(--space-5);
  right: var(--space-5);
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: var(--space-3) var(--space-5);
  color: var(--text-primary);
  font-size: 0.875rem;
  box-shadow: 0 4px 24px rgba(0,0,0,0.3);
  z-index: 200;
  transform: translateY(100px);
  opacity: 0;
  transition: all 0.3s;
}

.toast--visible { transform: translateY(0); opacity: 1; }

/* ── Alert rows ──────────────────────────────────────────────── */
.alert-row {
  display: flex;
  align-items: flex-start;
  gap: var(--space-3);
  padding: var(--space-4);
  border-bottom: 1px solid var(--border);
}

.alert-row:last-child { border-bottom: none; }
.alert-row__icon { font-size: 1.25rem; flex-shrink: 0; }
.alert-row__content { flex: 1; }
.alert-row__title { font-weight: 600; margin-bottom: var(--space-1); }
.alert-row__meta { font-size: 0.8rem; color: var(--text-secondary); }
.alert-row__action { flex-shrink: 0; }

/* ── Kanban (PO Tracker) ────────────────────────────────────── */
.kanban {
  display: flex;
  gap: var(--space-4);
  overflow-x: auto;
  padding-bottom: var(--space-4);
}

.kanban-col {
  min-width: 240px;
  flex-shrink: 0;
}

.kanban-col__header {
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-secondary);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
}

.kanban-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--space-3);
  margin-bottom: var(--space-2);
  cursor: pointer;
  transition: border-color 0.15s;
}

.kanban-card:hover { border-color: var(--accent); }
.kanban-card__supplier { font-weight: 600; font-size: 0.875rem; margin-bottom: var(--space-1); }
.kanban-card__meta { font-size: 0.75rem; color: var(--text-secondary); }
.kanban-card--overdue { border-left: 3px solid var(--critical); }

/* ── Sparkline placeholder ───────────────────────────────────── */
.sparkline {
  display: inline-flex;
  align-items: flex-end;
  gap: 2px;
  height: 24px;
}

.sparkline__bar {
  width: 4px;
  background: var(--accent);
  border-radius: 2px;
  min-height: 2px;
}

/* ── Checkbox ────────────────────────────────────────────────── */
.checkbox-cell { width: 40px; text-align: center; }
input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--accent); }

/* ── Order builder cart ──────────────────────────────────────── */
.cart-bar {
  position: fixed;
  bottom: 0;
  left: var(--sidebar-width);
  right: 0;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  padding: var(--space-3) var(--space-5);
  display: flex;
  align-items: center;
  justify-content: space-between;
  z-index: 50;
  box-shadow: 0 -4px 24px rgba(0,0,0,0.2);
}

.cart-bar__info { font-size: 0.875rem; }
.cart-bar__value { font-weight: 700; color: var(--accent); }

/* ── Responsive ──────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: -var(--sidebar-width);
    top: 0;
    bottom: 0;
    transition: left 0.3s;
    z-index: 100;
  }

  .sidebar--open { left: 0; }
  .sidebar--open + .main .sidebar-overlay { display: block; }
  .sidebar-overlay.visible { display: block; }

  .mobile-header { display: flex; }

  .page-content { padding: var(--space-4); }

  .stat-grid { grid-template-columns: repeat(2, 1fr); }

  .kanban { flex-direction: column; }
  .kanban-col { min-width: 100%; }

  .cart-bar { left: 0; }

  .filter-bar { flex-direction: column; }
  .filter-bar .form-input, .filter-bar .form-select { width: 100%; min-width: auto; }
}
