@import url('https://fonts.googleapis.com/css2?family=DM+Sans:ital,opsz,wght@0,9..40,300;0,9..40,400;0,9..40,500;0,9..40,600;0,9..40,700&family=DM+Mono:wght@400;500&display=swap');

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --border: #e2e8f2;
  --border-strong: #c8d4e8;
  --text: #0d1829;
  --muted: #64748b;
  --primary: #1847d4;
  --primary-dark: #1238a8;
  --primary-light: #eef2ff;
  --accent: #0ea5e9;
  --green: #059669;
  --amber: #d97706;
  --violet: #7c3aed;
  --danger: #dc2626;
  --shadow-xs: 0 1px 2px rgba(13,24,41,.06);
  --shadow-sm: 0 2px 8px rgba(13,24,41,.07);
  --shadow: 0 4px 24px rgba(13,24,41,.09);
  --shadow-lg: 0 16px 48px rgba(13,24,41,.14);
  --r: 14px;
  --r-sm: 9px;
}

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

body {
  font-family: 'DM Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  padding: 0 0 48px;
  background-image:
    radial-gradient(ellipse 70% 30% at 60% -5%, rgba(24,71,212,.08) 0%, transparent 65%),
    radial-gradient(ellipse 40% 20% at 10% 50%, rgba(14,165,233,.05) 0%, transparent 60%);
  min-height: 100vh;
}

/* ── TOPBAR ───────────────────────────────────── */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 14px 28px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow-xs);
}

.topbar-brand { display: flex; align-items: center; gap: 14px; }

.brand-mark {
  width: 38px; height: 38px;
  background: linear-gradient(135deg, var(--primary) 0%, var(--accent) 100%);
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 12px rgba(24,71,212,.3);
  flex-shrink: 0;
  color: white;
}
.brand-mark svg { width: 18px; height: 18px; }

.brand-label {
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .1em;
  color: var(--primary);
  margin-bottom: 1px;
}

h1 { font-size: 1.05rem; font-weight: 700; color: var(--text); letter-spacing: -.01em; }

.topbar-right { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; justify-content: flex-end; }

.status-pill {
  display: flex; align-items: center; gap: 7px;
  font-size: .76rem; color: var(--muted);
  padding: 5px 11px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 99px;
  font-family: 'DM Mono', monospace;
}

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 2px rgba(5,150,105,.2);
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%,100% { box-shadow: 0 0 0 2px rgba(5,150,105,.2); }
  50% { box-shadow: 0 0 0 4px rgba(5,150,105,.1); }
}

.auth-cluster { display: flex; align-items: center; gap: 8px; }
.auth-email { font-size: .76rem; color: var(--muted); font-family: 'DM Mono', monospace; max-width: 200px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ── META BAR ─────────────────────────────────── */
.meta-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 28px;
  font-size: .75rem;
  color: var(--muted);
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
}
.meta-bar strong { color: var(--text); font-weight: 600; }
.meta-sep { color: var(--border-strong); }

/* ── BUTTONS ──────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 15px;
  border-radius: var(--r-sm);
  border: 1px solid transparent;
  font: 500 .83rem 'DM Sans', sans-serif;
  cursor: pointer;
  transition: all .15s ease;
  white-space: nowrap;
}
.btn-ghost {
  background: transparent;
  color: var(--muted);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--bg); color: var(--text); border-color: var(--border-strong); }

.btn-accent {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
  box-shadow: 0 2px 8px rgba(24,71,212,.3);
}
.btn-accent:hover { background: var(--primary-dark); transform: translateY(-1px); box-shadow: 0 4px 14px rgba(24,71,212,.4); }

.btn-sm { padding: 5px 11px; font-size: .78rem; }

/* ── KPI STRIP ────────────────────────────────── */
.kpi-strip {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0;
  margin: 24px 28px 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.kpi-item {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 20px 22px;
  border-right: 1px solid var(--border);
  position: relative;
  transition: background .15s;
}
.kpi-item:last-child { border-right: none; }
.kpi-item:hover { background: #fafcff; }

.kpi-item::after {
  content: '';
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  border-radius: 0 0 2px 2px;
}
.kpi-item[data-color="blue"]::after { background: var(--primary); }
.kpi-item[data-color="green"]::after { background: var(--green); }
.kpi-item[data-color="violet"]::after { background: var(--violet); }
.kpi-item[data-color="amber"]::after { background: var(--amber); }

.kpi-icon {
  font-size: 1.4rem;
  width: 42px; height: 42px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 11px;
  flex-shrink: 0;
}
.kpi-item[data-color="blue"] .kpi-icon { background: #eef2ff; }
.kpi-item[data-color="green"] .kpi-icon { background: #ecfdf5; }
.kpi-item[data-color="violet"] .kpi-icon { background: #f5f3ff; }
.kpi-item[data-color="amber"] .kpi-icon { background: #fffbeb; }

.kpi-body { min-width: 0; }
.kpi-label {
  display: block;
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  color: var(--muted);
  margin-bottom: 3px;
}
.kpi-item strong {
  font-size: 1.5rem;
  font-weight: 700;
  font-family: 'DM Mono', monospace;
  color: var(--text);
  letter-spacing: -.03em;
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── PANEL ────────────────────────────────────── */
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--r);
  box-shadow: var(--shadow-sm);
  margin: 18px 28px 0;
  padding: 20px 22px;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: .9rem;
  font-weight: 600;
  color: var(--text);
}
.panel-title svg { color: var(--muted); }

/* ── FILTERS ──────────────────────────────────── */
.filters-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0,1fr));
  gap: 12px;
}
.field-wide { grid-column: span 3; }

.field { display: flex; flex-direction: column; gap: 5px; }

label {
  font-size: .7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
}

input, select {
  font: 400 .875rem 'DM Sans', sans-serif;
  width: 100%;
  padding: 8px 11px;
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  background: white;
  color: var(--text);
  transition: border-color .14s, box-shadow .14s;
  -webkit-appearance: none;
  appearance: none;
}
select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='11' height='7' viewBox='0 0 11 7'%3E%3Cpath d='M1 1l4.5 4.5L10 1' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
  padding-right: 30px;
}
input:focus, select:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(24,71,212,.1); }

.input-icon-wrap { position: relative; }
.input-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.input-icon-wrap input { padding-left: 32px; }

/* ── CHARTS ───────────────────────────────────── */
.charts-row { display: grid; gap: 14px; margin-bottom: 14px; }
.charts-row:last-of-type { margin-bottom: 0; }
.two-col { grid-template-columns: repeat(2, 1fr); }
.one-col { grid-template-columns: 1fr; }
.three-col { grid-template-columns: repeat(3, 1fr); }

.chart-card {
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 16px;
  background: white;
  position: relative;
  transition: box-shadow .18s, border-color .18s;
}
.chart-card:hover { box-shadow: var(--shadow); border-color: var(--border-strong); }

.chart-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 14px;
}
.chart-title {
  flex: 1;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.chart-badge {
  font-size: .66rem;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 99px;
  background: var(--primary-light);
  color: var(--primary);
  white-space: nowrap;
  flex-shrink: 0;
}
.expand-btn {
  width: 26px; height: 26px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: white;
  color: var(--muted);
  font-size: 1rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  transition: all .14s;
  line-height: 1;
}
.expand-btn:hover { background: var(--primary-light); color: var(--primary); border-color: var(--primary); }

.chart-area {
  position: relative;
  height: 240px;
}
.chart-area canvas { width: 100% !important; height: 100% !important; }
.chart-card.tall .chart-area { height: 300px; }

.chart-empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--muted);
  font-size: .9rem;
}
.chart-empty-state div { font-size: 2.5rem; margin-bottom: 10px; opacity: .35; }

/* ── TABLE ────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
}
table { border-collapse: collapse; width: 100%; min-width: 1500px; font-size: .8rem; }
th, td { padding: 9px 11px; border-bottom: 1px solid #eef2f9; vertical-align: middle; }
thead th {
  background: #f8faff;
  font-size: .68rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  white-space: nowrap;
}
tbody tr { transition: background .1s; }
tbody tr:hover { background: #f6f9ff; }
tbody tr:last-child td { border-bottom: none; }
.right { text-align: right; }
td.right { font-family: 'DM Mono', monospace; color: var(--green); font-weight: 500; font-size: .78rem; }

/* ── MISC ─────────────────────────────────────── */
.hidden { display: none !important; }
.muted { color: var(--muted); }

.empty-state {
  text-align: center;
  color: var(--muted);
  padding: 40px 20px;
  font-size: .875rem;
}

.toast-message {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #0f1c2e;
  color: white;
  padding: 10px 20px;
  border-radius: 99px;
  font-size: .83rem;
  box-shadow: var(--shadow-lg);
  z-index: 3000;
  opacity: 0;
  transition: opacity .2s;
  pointer-events: none;
  white-space: nowrap;
}
.toast-message.visible { opacity: 1; pointer-events: all; }
.toast-message.error { background: var(--danger); }

.field-error { font-size: .8rem; color: var(--danger); margin-top: 8px; min-height: 18px; }

/* ── MODALS ───────────────────────────────────── */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(13,24,41,.55);
  backdrop-filter: blur(5px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 1000;
  animation: fadeIn .18s ease;
}
.modal.hidden { display: none !important; }

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal-box {
  background: white;
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 24px;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
  animation: slideUp .2s ease;
}
.modal-box-wide { max-width: 900px; }

@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.modal-header h3 { font-size: .95rem; font-weight: 600; }
.modal-close {
  width: 30px; height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: white;
  color: var(--muted);
  font-size: .95rem;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: all .13s;
}
.modal-close:hover { background: #fff0f0; color: var(--danger); border-color: #fecaca; }

.modal-footer { display: flex; justify-content: flex-end; margin-top: 20px; }

.file-drop-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  border: 2px dashed var(--border);
  border-radius: var(--r-sm);
  padding: 28px 20px;
  position: relative;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  color: var(--muted);
  font-size: .83rem;
}
.file-drop-area:hover { border-color: var(--primary); background: var(--primary-light); color: var(--primary); }
.file-drop-area input {
  position: absolute; inset: 0;
  opacity: 0; cursor: pointer;
  width: 100%; height: 100%;
}

.chart-modal-body {
  position: relative;
  height: 500px;
}
.chart-modal-body canvas { width: 100% !important; height: 100% !important; }

/* ── RESPONSIVE ───────────────────────────────── */
@media (max-width: 1200px) {
  .three-col { grid-template-columns: repeat(2, 1fr); }
  .three-col .chart-card:last-child { grid-column: span 2; }
}
@media (max-width: 1000px) {
  .kpi-strip { grid-template-columns: repeat(2, 1fr); }
  .kpi-item:nth-child(2) { border-right: none; }
  .two-col, .three-col { grid-template-columns: 1fr; }
  .three-col .chart-card:last-child { grid-column: span 1; }
  .filters-grid { grid-template-columns: repeat(2, 1fr); }
  .field-wide { grid-column: span 2; }
}
@media (max-width: 700px) {
  .topbar { padding: 12px 16px; }
  .panel { margin-left: 14px; margin-right: 14px; padding: 16px; }
  .kpi-strip { margin-left: 14px; margin-right: 14px; grid-template-columns: repeat(2, 1fr); }
  .meta-bar { padding: 6px 16px; }
  .filters-grid { grid-template-columns: 1fr; }
  .field-wide { grid-column: span 1; }
  h1 { font-size: .9rem; }
  .brand-label { display: none; }
  .auth-email { display: none; }
}
@media (max-width: 480px) {
  .kpi-strip { grid-template-columns: 1fr; }
  .kpi-item { border-right: none; border-bottom: 1px solid var(--border); }
  .kpi-item:last-child { border-bottom: none; }
}
