/* ═══════════════════════════════════════════════════════════════════════════
   Sprocket Partners — Dashboard Styles
   ═══════════════════════════════════════════════════════════════════════════ */

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

:root {
  --navy:    #0f2d56;
  --navy-lt: #1e3a5f;
  --teal:    #0ea5e9;
  --teal-dk: #0284c7;
  --green:   #22c55e;
  --amber:   #f59e0b;
  --red:     #ef4444;
  --purple:  #8b5cf6;
  --orange:  #f97316;

  --bg:      #f1f5f9;
  --card:    #ffffff;
  --border:  #e2e8f0;
  --text:    #1e293b;
  --text-md: #475569;
  --text-sm: #94a3b8;

  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow:    0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -2px rgba(0,0,0,.06);
  --shadow-lg: 0 10px 25px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.08);

  --radius: 10px;
  --radius-sm: 6px;
  --radius-lg: 14px;
}

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

html { font-size: 14px; }

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

/* ── HEADER ─────────────────────────────────────────────────────────────── */
header {
  background: var(--navy);
  color: white;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}

.header-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 56px;
}

.header-brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.brand-logo {
  width: 32px;
  height: 32px;
  background: var(--teal);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 18px;
  font-weight: 800;
  color: white;
  letter-spacing: -1px;
}

.brand-name {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: -0.3px;
}

.brand-sub {
  font-size: 0.72rem;
  color: #94a3b8;
  font-weight: 400;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.connection-status {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.75rem;
  color: #94a3b8;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #64748b;
}

.status-dot.connected    { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.disconnected { background: #64748b; }
.status-dot.error        { background: var(--red); }

.last-updated {
  font-size: 0.72rem;
  color: #94a3b8;
}

/* ── NAV TABS ───────────────────────────────────────────────────────────── */
nav.tabs {
  display: flex;
  border-top: 1px solid rgba(255,255,255,0.08);
  overflow-x: auto;
  scrollbar-width: none;
}

nav.tabs::-webkit-scrollbar { display: none; }

.tab {
  padding: 0.6rem 1.2rem;
  font-size: 0.82rem;
  font-weight: 500;
  color: #94a3b8;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: all 0.15s;
  user-select: none;
}

.tab:hover   { color: #cbd5e1; border-bottom-color: #334155; }
.tab.active  { color: var(--teal); border-bottom-color: var(--teal); }

/* ── MAIN LAYOUT ─────────────────────────────────────────────────────────── */
main {
  max-width: 1600px;
  margin: 0 auto;
  padding: 1.25rem 1.5rem 2rem;
}

/* alert/banner */
.alert {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  margin-bottom: 1rem;
}

.alert-warning { background: #fef3c7; color: #92400e; border: 1px solid #fcd34d; }
.alert-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-success { background: #dcfce7; color: #166534; border: 1px solid #86efac; }
.alert-info    { background: #e0f2fe; color: #075985; border: 1px solid #7dd3fc; }

/* panel (tab content) */
.panel { display: none; }
.panel.active { display: block; }

/* ── KPI CARDS ──────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.875rem;
  margin-bottom: 1.25rem;
}

.kpi-card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  cursor: pointer;
  transition: box-shadow 0.15s, transform 0.15s;
}

.kpi-card:hover {
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}

.kpi-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 3px;
  background: var(--teal);
}

.kpi-card.green::before  { background: var(--green); }
.kpi-card.amber::before  { background: var(--amber); }
.kpi-card.red::before    { background: var(--red); }
.kpi-card.purple::before { background: var(--purple); }
.kpi-card.navy::before   { background: var(--navy); }

.kpi-label {
  font-size: 0.72rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-md);
  margin-bottom: 0.35rem;
}

.kpi-value {
  font-size: 1.7rem;
  font-weight: 700;
  line-height: 1.1;
  color: var(--text);
  margin-bottom: 0.3rem;
}

.kpi-value.loading { color: var(--text-sm); font-size: 1rem; }

.kpi-meta {
  font-size: 0.72rem;
  color: var(--text-md);
  display: flex;
  align-items: center;
  gap: 0.3rem;
  flex-wrap: wrap;
}

.kpi-badge {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  padding: 1px 6px;
  border-radius: 20px;
  font-size: 0.68rem;
  font-weight: 600;
}

.badge-green  { background: #dcfce7; color: #16a34a; }
.badge-amber  { background: #fef3c7; color: #d97706; }
.badge-red    { background: #fee2e2; color: #dc2626; }
.badge-gray   { background: #f1f5f9; color: #64748b; }
.badge-teal   { background: #e0f2fe; color: #0284c7; }

.kpi-plan {
  font-size: 0.7rem;
  color: var(--text-sm);
}

/* Progress bar inside KPI card */
.kpi-progress {
  margin-top: 0.5rem;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}

.kpi-progress-fill {
  height: 100%;
  background: var(--teal);
  border-radius: 2px;
  transition: width 0.8s ease;
}

.kpi-progress-fill.green  { background: var(--green); }
.kpi-progress-fill.amber  { background: var(--amber); }
.kpi-progress-fill.red    { background: var(--red); }

/* ── CHART CARDS ─────────────────────────────────────────────────────────── */
.chart-grid {
  display: grid;
  gap: 1rem;
  margin-bottom: 1rem;
}

.chart-grid-2 { grid-template-columns: repeat(2, 1fr); }
.chart-grid-3 { grid-template-columns: repeat(3, 1fr); }
.chart-grid-12 { grid-template-columns: 1fr 2fr; }
.chart-grid-21 { grid-template-columns: 2fr 1fr; }

@media (max-width: 900px) {
  .chart-grid-2,
  .chart-grid-3,
  .chart-grid-12,
  .chart-grid-21 { grid-template-columns: 1fr; }
}

.chart-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border);
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

.chart-card.span-2 { grid-column: span 2; }
.chart-card.span-3 { grid-column: span 3; }

.chart-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  padding: 0.9rem 1rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.chart-title {
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--text);
}

.chart-subtitle {
  font-size: 0.72rem;
  color: var(--text-sm);
  margin-top: 2px;
}

.chart-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  flex-shrink: 0;
}

.chart-body {
  padding: 0.75rem 1rem 1rem;
  flex: 1;
  position: relative;
  min-height: 240px;
}

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

/* ── BUTTONS ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.45rem 0.9rem;
  border-radius: var(--radius-sm);
  font-size: 0.8rem;
  font-weight: 500;
  cursor: pointer;
  border: none;
  transition: all 0.15s;
  white-space: nowrap;
  font-family: inherit;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--teal);
  color: white;
}
.btn-primary:hover:not(:disabled) { background: var(--teal-dk); }

.btn-navy {
  background: var(--navy);
  color: white;
}
.btn-navy:hover:not(:disabled) { background: var(--navy-lt); }

.btn-outline {
  background: transparent;
  color: var(--text-md);
  border: 1px solid var(--border);
}
.btn-outline:hover:not(:disabled) { background: var(--bg); border-color: #cbd5e1; }

.btn-ghost {
  background: transparent;
  color: var(--text-sm);
  padding: 0.35rem 0.6rem;
}
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text-md); }

.btn-danger {
  background: var(--red);
  color: white;
}
.btn-danger:hover:not(:disabled) { background: #dc2626; }

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.74rem;
}

.btn-icon {
  font-size: 1rem;
  padding: 0.35rem;
}

/* ── DATA TABLE ──────────────────────────────────────────────────────────── */
.data-table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

table.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

table.data-table th {
  background: #f8fafc;
  padding: 0.55rem 0.85rem;
  text-align: right;
  font-weight: 600;
  font-size: 0.72rem;
  color: var(--text-md);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

table.data-table th:first-child { text-align: left; }

table.data-table td {
  padding: 0.5rem 0.85rem;
  text-align: right;
  border-bottom: 1px solid var(--border);
  color: var(--text);
}

table.data-table td:first-child { text-align: left; font-weight: 500; }

table.data-table tr:last-child td { border-bottom: none; }
table.data-table tbody tr:hover { background: #f8fafc; }

table.data-table tr.section-header td {
  background: var(--navy);
  color: white;
  font-weight: 600;
  padding: 0.4rem 0.85rem;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

table.data-table tr.subtotal td {
  background: #f8fafc;
  font-weight: 600;
  border-top: 1px solid var(--border);
}

table.data-table tr.total td {
  background: var(--navy);
  color: white;
  font-weight: 700;
}

.variance-pos { color: var(--green); font-weight: 600; }
.variance-neg { color: var(--red); font-weight: 600; }
.variance-neu { color: var(--text-sm); }

/* ── MODAL ───────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.6);
  z-index: 1000;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 2rem 1rem;
  overflow-y: auto;
  backdrop-filter: blur(2px);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}

.modal-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.modal {
  background: var(--card);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 900px;
  margin: auto;
  overflow: hidden;
  transform: translateY(-20px);
  transition: transform 0.2s;
}

.modal-overlay.open .modal { transform: translateY(0); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--navy);
  color: white;
}

.modal-title { font-size: 1rem; font-weight: 600; }
.modal-subtitle { font-size: 0.76rem; color: #94a3b8; margin-top: 2px; }

.modal-close {
  background: transparent;
  border: none;
  color: #94a3b8;
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  padding: 0.2rem;
  transition: color 0.15s;
}
.modal-close:hover { color: white; }

.modal-body {
  padding: 1.25rem;
  max-height: 75vh;
  overflow-y: auto;
}

.modal-tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.modal-tab {
  padding: 0.5rem 1rem;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-md);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
}

.modal-tab.active {
  color: var(--teal);
  border-bottom-color: var(--teal);
}

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

/* ── EXPORT PANEL ─────────────────────────────────────────────────────────── */
.export-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1rem;
  margin-top: 1rem;
}

.export-card {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.export-icon {
  font-size: 2.5rem;
  line-height: 1;
}

.export-title {
  font-size: 1rem;
  font-weight: 600;
  color: var(--text);
}

.export-desc {
  font-size: 0.8rem;
  color: var(--text-md);
  line-height: 1.5;
}

.export-includes {
  font-size: 0.76rem;
  color: var(--text-sm);
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.export-includes li::before {
  content: '✓ ';
  color: var(--green);
  font-weight: 600;
}

/* ── LOADING SPINNER ─────────────────────────────────────────────────────── */
.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid #e2e8f0;
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* ── SECTION HEADER ──────────────────────────────────────────────────────── */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.section-title {
  font-size: 0.78rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-sm);
}

/* ── LEGEND ──────────────────────────────────────────────────────────────── */
.chart-legend {
  display: flex;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 0 1rem 0.75rem;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  font-size: 0.72rem;
  color: var(--text-md);
}

.legend-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}

.legend-line {
  width: 18px;
  height: 2px;
  flex-shrink: 0;
}

.legend-dashed {
  width: 18px;
  height: 0;
  border-top: 2px dashed;
  flex-shrink: 0;
}

/* ── WATERFALL ──────────────────────────────────────────────────────────── */
.waterfall-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.8rem;
}

.waterfall-table td {
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

.waterfall-table td:first-child { color: var(--text-md); }
.waterfall-table td:last-child  { text-align: right; font-weight: 600; font-family: 'SF Mono', 'Fira Code', monospace; }

.waterfall-positive { color: var(--green); }
.waterfall-negative { color: var(--red); }
.waterfall-total    { background: #f8fafc; font-weight: 700 !important; color: var(--text) !important; }

/* ── ASSUMPTIONS ─────────────────────────────────────────────────────────── */
.assumptions-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.75rem;
}

.assumption-item {
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  border: 1px solid var(--border);
}

.assumption-label {
  font-size: 0.7rem;
  color: var(--text-sm);
  margin-bottom: 0.25rem;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.assumption-value {
  font-size: 1rem;
  font-weight: 700;
  color: var(--navy);
}

/* ── PRINT STYLES ──────────────────────────────────────────────────────── */
@media print {
  header nav.tabs { display: none; }
  .panel { display: block !important; }
  .btn, .chart-actions { display: none !important; }
  .chart-card { break-inside: avoid; }
  .modal-overlay { display: none !important; }
}

/* ── SCROLL BAR ──────────────────────────────────────────────────────────── */
::-webkit-scrollbar       { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #cbd5e1; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #94a3b8; }

/* ── TOOLTIPS ────────────────────────────────────────────────────────────── */
[title] { cursor: help; }
