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

/* ── Color System ── */
:root {
  --bg-primary: #0F1117;
  --bg-secondary: #1C1E26;
  --bg-tertiary: #252830;
  --bg-hover: #2D3040;
  --border: #2A2D38;
  --border-light: #353844;

  --text-primary: #F8F9FA;
  --text-secondary: #9CA3AF;
  --text-muted: #6B7280;
  --text-faint: #4B5563;

  --accent: #0EA5E9;
  --accent-hover: #0284C7;
  --accent-dim: rgba(14, 165, 233, 0.12);
  --accent-glow: rgba(14, 165, 233, 0.25);

  /* Status colors */
  --status-measuring: #3B82F6;
  --status-measuring-bg: rgba(59, 130, 246, 0.12);
  --status-ordering: #EAB308;
  --status-ordering-bg: rgba(234, 179, 8, 0.12);
  --status-production: #F97316;
  --status-production-bg: rgba(249, 115, 22, 0.12);
  --status-ready: #22C55E;
  --status-ready-bg: rgba(34, 197, 94, 0.12);
  --status-scheduled: #14B8A6;
  --status-scheduled-bg: rgba(20, 184, 166, 0.12);
  --status-complete: #6B7280;
  --status-complete-bg: rgba(107, 114, 128, 0.12);
  --status-risk: #EF4444;
  --status-risk-bg: rgba(239, 68, 68, 0.12);
  --status-warning: #F59E0B;
  --status-warning-bg: rgba(245, 158, 11, 0.12);

  --sidebar-width: 224px;
  --topbar-height: 56px;

  --radius-sm: 6px;
  --radius-md: 10px;
  --radius-lg: 14px;
  --radius-xl: 20px;

  --shadow-sm: 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.4);
  --shadow-lg: 0 8px 32px rgba(0,0,0,0.5);
}

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

html { font-size: 14px; -webkit-font-smoothing: antialiased; }

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

a { color: var(--accent); text-decoration: none; transition: color 0.15s; }
a:hover { color: var(--accent-hover); }

/* ── App Layout ── */
.app-layout {
  display: flex;
  min-height: 100vh;
}

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  height: 100vh;
  z-index: 100;
}

.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 20px 16px;
  border-bottom: 1px solid var(--border);
}

.logo-mark {
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 7px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.logo-mark svg { width: 16px; height: 16px; }

.logo-text {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

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

.nav-section-label {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-faint);
  padding: 8px 10px 4px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
  text-decoration: none;
  margin-bottom: 1px;
}

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

.nav-item.active {
  background: var(--accent-dim);
  color: var(--accent);
}

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

.nav-badge {
  margin-left: auto;
  background: var(--accent);
  color: white;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 20px;
  line-height: 16px;
}

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

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

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background 0.12s;
}

.user-card:hover { background: var(--bg-hover); }

.avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #818CF8);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
  color: white;
  flex-shrink: 0;
}

.user-info { flex: 1; min-width: 0; }
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--text-muted); }

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

/* ── Top Bar ── */
.topbar {
  height: var(--topbar-height);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

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

.topbar-subtitle {
  font-size: 13px;
  color: var(--text-muted);
}

.search-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 7px 12px;
  flex: 1;
  max-width: 360px;
  margin-left: auto;
}

.search-bar input {
  background: none;
  border: none;
  outline: none;
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  width: 100%;
}

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

.search-bar svg { color: var(--text-muted); width: 14px; height: 14px; flex-shrink: 0; }

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

.icon-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-secondary);
  transition: all 0.12s;
  position: relative;
}

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

.icon-btn svg { width: 17px; height: 17px; }

.notif-dot {
  width: 7px;
  height: 7px;
  background: var(--accent);
  border-radius: 50%;
  position: absolute;
  top: 6px;
  right: 6px;
  border: 1.5px solid var(--bg-secondary);
}

/* ── Page Content ── */
.page-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
}

/* ── Cards ── */
.card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.card-sm { padding: 16px; }
.card-lg { padding: 28px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  line-height: 1;
  white-space: nowrap;
}

.btn svg { width: 14px; height: 14px; }

.btn-primary {
  background: var(--accent);
  color: white;
}
.btn-primary:hover { background: var(--accent-hover); transform: translateY(-1px); box-shadow: 0 4px 12px var(--accent-glow); }

.btn-secondary {
  background: var(--bg-tertiary);
  color: var(--text-primary);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-light); }

.btn-ghost {
  background: none;
  color: var(--text-secondary);
  border: 1px solid var(--border);
}
.btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }

.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 12px 24px; font-size: 14px; }

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

.badge-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
}

.badge-measuring { color: var(--status-measuring); background: var(--status-measuring-bg); }
.badge-ordering { color: var(--status-ordering); background: var(--status-ordering-bg); }
.badge-production { color: var(--status-production); background: var(--status-production-bg); }
.badge-ready { color: var(--status-ready); background: var(--status-ready-bg); }
.badge-scheduled { color: var(--status-scheduled); background: var(--status-scheduled-bg); }
.badge-complete { color: var(--status-complete); background: var(--status-complete-bg); }
.badge-risk { color: var(--status-risk); background: var(--status-risk-bg); }
.badge-warning { color: var(--status-warning); background: var(--status-warning-bg); }
.badge-accent { color: var(--accent); background: var(--accent-dim); }

/* ── Stats / KPI ── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
}

.kpi-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.kpi-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.kpi-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -0.5px;
  line-height: 1;
}

.kpi-sub {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
}

.kpi-change {
  font-size: 12px;
  font-weight: 600;
  margin-top: 4px;
}

.kpi-change.up { color: var(--status-ready); }
.kpi-change.down { color: var(--status-risk); }

/* ── Tables ── */
.data-table {
  width: 100%;
  border-collapse: collapse;
}

.data-table th {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 10px 16px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}

.data-table td {
  padding: 13px 16px;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

.data-table tr:last-child td { border-bottom: none; }

.data-table tbody tr {
  transition: background 0.1s;
  cursor: pointer;
}

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

/* ── Filter Tabs ── */
.filter-tabs {
  display: flex;
  gap: 4px;
  background: var(--bg-tertiary);
  border-radius: var(--radius-md);
  padding: 4px;
  width: fit-content;
}

.filter-tab {
  padding: 7px 16px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  color: var(--text-muted);
  transition: all 0.12s;
  background: none;
  border: none;
  font-family: inherit;
}

.filter-tab.active {
  background: var(--bg-secondary);
  color: var(--text-primary);
  box-shadow: var(--shadow-sm);
}

.filter-tab:hover:not(.active) { color: var(--text-secondary); }

/* ── Margin Indicator ── */
.margin-bar {
  display: flex;
  align-items: center;
  gap: 8px;
}

.margin-track {
  width: 60px;
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  overflow: hidden;
}

.margin-fill {
  height: 100%;
  border-radius: 2px;
  background: var(--status-ready);
}

.margin-fill.warn { background: var(--status-warning); }
.margin-fill.bad { background: var(--status-risk); }

.margin-pct {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
}

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

.section-title {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.2px;
}

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

/* ── Page Header ── */
.page-header {
  margin-bottom: 24px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.5px;
}

.page-desc {
  font-size: 14px;
  color: var(--text-muted);
  margin-top: 4px;
}

/* ── Divider ── */
.divider {
  border: none;
  border-top: 1px solid var(--border);
  margin: 20px 0;
}

/* ── Scrollbar ── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-faint); }

/* ── Animations ── */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.fade-in { animation: fadeIn 0.3s ease forwards; }

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main-content { margin-left: 0; }
  .kpi-grid { grid-template-columns: 1fr 1fr; }
}
