/* ============================================================
   APAC CEO Dashboard - Core Styles
   Dark theme, data-dense, executive-focused
   ============================================================ */

:root {
  --bg-primary: #0f172a;
  --bg-card: #1e293b;
  --bg-hover: #334155;
  --border: #334155;
  --text-primary: #f1f5f9;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent: #aa0000;
  --accent-hover: #880000;
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
  --orange: #f97316;
}

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

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

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

.sidebar {
  width: 240px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 20px 0;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  overflow-y: auto;
  z-index: 100;
}

.sidebar-header {
  padding: 0 20px 20px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

.sidebar-header h1 { font-size: 15px; font-weight: 700; }
.sidebar-header p { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.sidebar-section { padding: 0 12px; margin-bottom: 16px; }
.sidebar-section-title { font-size: 10px; text-transform: uppercase; letter-spacing: 1px; color: var(--text-muted); padding: 0 8px; margin-bottom: 6px; }

.sidebar-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px; border-radius: 6px;
  color: var(--text-secondary); cursor: pointer;
  font-size: 13px; transition: all 0.15s;
  text-decoration: none;
}
.sidebar-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.sidebar-item.active { background: var(--accent); color: #fff; }

.sidebar-item .flag { font-size: 16px; }
.sidebar-item .dot { width: 8px; height: 8px; border-radius: 50%; }
.sidebar-item .dot.green { background: var(--green); }
.sidebar-item .dot.red { background: var(--red); }
.sidebar-item .dot.yellow { background: var(--yellow); }

.main { margin-left: 240px; flex: 1; padding: 24px 32px; }

/* ---- Top Bar ---- */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 24px;
}
.topbar h2 { font-size: 22px; font-weight: 700; }
.topbar-right { display: flex; gap: 12px; align-items: center; }

.period-selector {
  display: flex; gap: 8px; align-items: center;
}
.period-selector select, .period-selector input {
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-primary); padding: 6px 10px; border-radius: 6px; font-size: 13px;
}

.btn {
  padding: 8px 16px; border-radius: 6px; font-size: 13px; font-weight: 600;
  border: none; cursor: pointer; transition: all 0.15s; text-decoration: none;
  display: inline-flex; align-items: center; gap: 6px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-outline { background: transparent; color: var(--text-secondary); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg-hover); color: var(--text-primary); }
.btn-danger { background: var(--red); color: #fff; }
.btn-sm { padding: 5px 10px; font-size: 12px; }

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

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

.kpi-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 6px; }
.kpi-value { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.kpi-sub { font-size: 12px; margin-top: 4px; display: flex; align-items: center; gap: 4px; }
.kpi-sub.positive { color: var(--green); }
.kpi-sub.negative { color: var(--red); }
.kpi-sub.neutral { color: var(--text-muted); }

/* ---- Cards & Panels ---- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px;
  margin-bottom: 20px;
}

.card-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 16px;
}
.card-title { font-size: 15px; font-weight: 600; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 20px; }

/* ---- Tables ---- */
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}

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

.data-table th.right, .data-table td.right { text-align: right; }

.data-table td {
  padding: 8px 12px;
  border-bottom: 1px solid rgba(51, 65, 85, 0.5);
  color: var(--text-secondary);
}

.data-table tr:hover td { background: rgba(51, 65, 85, 0.3); }
.data-table tr.total td { font-weight: 700; color: var(--text-primary); border-top: 2px solid var(--border); }
.data-table tr.subtotal td { font-weight: 600; color: var(--text-primary); background: rgba(51, 65, 85, 0.2); }

.val-positive { color: var(--green) !important; }
.val-negative { color: var(--red) !important; }

/* ---- Chart Container ---- */
.chart-container {
  position: relative;
  width: 100%;
  height: 300px;
}

.chart-container canvas { width: 100% !important; height: 100% !important; }

/* ---- Tabs ---- */
.tabs { display: flex; gap: 2px; margin-bottom: 20px; border-bottom: 1px solid var(--border); }
.tab {
  padding: 10px 16px; cursor: pointer;
  font-size: 13px; color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}
.tab:hover { color: var(--text-secondary); }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ---- Upload area ---- */
.upload-area {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 40px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
}
.upload-area:hover { border-color: var(--accent); background: rgba(170, 0, 0, 0.05); }
.upload-area.dragging { border-color: var(--accent); background: rgba(170, 0, 0, 0.1); }
.upload-area p { color: var(--text-muted); font-size: 14px; }
.upload-area .icon { font-size: 32px; margin-bottom: 8px; }

/* ---- AI Analysis ---- */
.ai-card {
  background: linear-gradient(135deg, #1e293b 0%, #2a1a1a 100%);
  border: 1px solid #553333;
}

.ai-badge {
  display: inline-flex; align-items: center; gap: 4px;
  background: rgba(170, 0, 0, 0.2); color: #e88;
  font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 4px;
}

.severity-high { color: var(--red); }
.severity-medium { color: var(--orange); }
.severity-low { color: var(--yellow); }

/* ---- Loading ---- */
.spinner {
  display: inline-block; width: 18px; height: 18px;
  border: 2px solid var(--border); border-top-color: var(--accent);
  border-radius: 50%; animation: spin 0.6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  display: flex; align-items: center; justify-content: center;
  padding: 60px; color: var(--text-muted);
}

/* ---- Toast ---- */
.toast {
  position: fixed; bottom: 24px; right: 24px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 8px; padding: 12px 20px;
  box-shadow: 0 8px 30px rgba(0,0,0,0.3);
  font-size: 13px; z-index: 1000;
  transform: translateY(100px); opacity: 0;
  transition: all 0.3s ease;
}
.toast.show { transform: translateY(0); opacity: 1; }
.toast.success { border-left: 4px solid var(--green); }
.toast.error { border-left: 4px solid var(--red); }

/* ---- Responsive ---- */
@media (max-width: 1024px) {
  .sidebar { width: 60px; }
  .sidebar-header h1, .sidebar-header p, .sidebar-section-title, .sidebar-item span { display: none; }
  .sidebar-item { justify-content: center; padding: 10px; }
  .main { margin-left: 60px; padding: 16px; }
  .grid-2 { grid-template-columns: 1fr; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
}
