:root {
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --text: #1c2530;
  --text-muted: #6b7685;
  --border: #e2e6ec;
  --primary: #d1152a;
  --primary-dark: #a30f20;
  --primary-tint: rgba(209, 21, 42, 0.06);
  --accent: #123f8c;
  --success: #0f9d78;
  --danger: #d64545;
  --shadow: 0 1px 3px rgba(20, 30, 50, 0.06), 0 1px 2px rgba(20, 30, 50, 0.04);
  --shadow-lg: 0 10px 24px rgba(20, 30, 50, 0.08), 0 2px 6px rgba(20, 30, 50, 0.05);
  --radius: 14px;
  font-family: -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #12161d;
    --card-bg: #1a2029;
    --text: #e6e9ee;
    --text-muted: #9aa4b2;
    --border: #2a313c;
    --primary-tint: rgba(209, 21, 42, 0.12);
    --shadow: 0 1px 3px rgba(0,0,0,0.4);
    --shadow-lg: 0 10px 24px rgba(0,0,0,0.4);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ---------- Header ---------- */

.topbar {
  background: linear-gradient(135deg, var(--accent) 0%, #0a2a63 100%);
  color: white;
  padding: 28px 20px;
  box-shadow: var(--shadow-lg);
}
.topbar-inner {
  max-width: 1140px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: 20px;
}
.brand-logo {
  height: 60px;
  width: 60px;
  object-fit: contain;
  background: white;
  border-radius: 14px;
  padding: 6px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.25);
  flex-shrink: 0;
}
.topbar-text h1 { margin: 0 0 4px; font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; }
.subtitle { margin: 0; opacity: 0.85; font-size: 0.9rem; }

.container {
  max-width: 1140px;
  margin: 0 auto;
  padding: 28px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 22px;
}

/* ---------- Cards ---------- */

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 26px;
  box-shadow: var(--shadow);
}
.card h2 {
  margin: 0 0 16px;
  font-size: 1.05rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  gap: 8px;
}
.card h2 .muted { font-weight: 500; font-size: 0.85rem; color: var(--text-muted); }
.card-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 6px; }
.card-header h2 { margin: 0; }
.card-hint { color: var(--text-muted); font-size: 0.85rem; margin: 0 0 10px; }

.hidden { display: none !important; }

.results-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.file-meta { color: var(--text-muted); font-size: 0.85rem; }

/* ---------- Upload zone ---------- */

.upload-zone {
  border: 2px dashed var(--border);
  border-radius: 10px;
  padding: 48px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}
.upload-zone:hover, .upload-zone.dragover {
  border-color: var(--primary);
  background: var(--primary-tint);
}
.upload-icon { font-size: 2.2rem; margin-bottom: 8px; }
.upload-title { font-weight: 600; margin: 0 0 6px; }
.upload-hint { color: var(--text-muted); font-size: 0.85rem; max-width: 480px; margin: 0 auto 18px; }

.btn-primary, .btn-secondary {
  border: none;
  border-radius: 8px;
  padding: 10px 18px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.btn-primary { background: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-primary:active { transform: scale(0.98); }
.btn-secondary { background: transparent; color: var(--primary); border: 1px solid var(--primary); }
.btn-secondary:hover { background: var(--primary-tint); }
.btn-danger { background: transparent; color: var(--danger); border: 1px solid var(--danger); border-radius: 6px; padding: 4px 10px; cursor: pointer; font-size: 0.8rem; }

.progress-zone { text-align: center; padding: 40px 0; }
.spinner {
  width: 36px; height: 36px; margin: 0 auto 14px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- De-Para editor ---------- */

.depara-editor { margin-top: 12px; }
.depara-table { width: 100%; border-collapse: collapse; font-size: 0.9rem; }
.depara-table th, .depara-table td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); }
.depara-table input {
  width: 100%; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--card-bg); color: var(--text); font-size: 0.9rem;
}
.depara-actions { display: flex; gap: 10px; margin-top: 14px; }

/* ---------- KPI tiles ---------- */

.kpi-row { display: flex; flex-wrap: wrap; gap: 12px; margin-bottom: 22px; }
.kpi-tile {
  flex: 1 1 110px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  text-align: center;
  transition: transform .12s;
}
.kpi-tile .label { font-size: 0.72rem; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; font-weight: 600; }
.kpi-tile .value { font-size: 1.5rem; font-weight: 800; margin-top: 6px; letter-spacing: -0.01em; }
.kpi-tile.overall {
  background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
  color: white; border-color: transparent;
  box-shadow: 0 6px 16px rgba(209,21,42,0.28);
}
.kpi-tile.overall .label { color: rgba(255,255,255,0.85); }

.chart-wrap { width: 100%; overflow-x: auto; }
#trendChart { width: 100%; height: 220px; }

/* ---------- Tables ---------- */

.table-scroll { overflow-x: auto; border-radius: 10px; border: 1px solid var(--border); }
table.data-table { border-collapse: separate; border-spacing: 0; width: 100%; font-size: 0.88rem; white-space: nowrap; }
.data-table th, .data-table td { padding: 10px 16px; text-align: right; }
.data-table th:first-child, .data-table td:first-child { text-align: left; }
.data-table thead th {
  background: var(--accent);
  color: white;
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  position: sticky;
  top: 0;
  padding: 12px 16px;
}
.data-table tbody td { border-bottom: 1px solid var(--border); font-variant-numeric: tabular-nums; }
.data-table tbody tr:nth-child(even):not(.row-total) { background: var(--bg); }
.data-table tbody tr:hover:not(.row-total) { background: var(--primary-tint); }
.data-table tbody tr.row-total {
  font-weight: 800;
  background: var(--primary-tint);
  border-top: 2px solid var(--primary);
}
.data-table tbody tr.row-total td:first-child { color: var(--primary-dark); }
.data-table tbody tr.row-pct td { color: var(--accent); font-weight: 700; }

.user-cell { display: flex; align-items: center; gap: 10px; }
.avatar {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--accent); color: white;
  font-size: 0.7rem; font-weight: 700; flex-shrink: 0;
}

.footer { text-align: center; color: var(--text-muted); font-size: 0.8rem; padding: 20px; }

/* ---------- Print / PDF export ---------- */

.print-header { display: none; }

@media print {
  .no-print { display: none !important; }
  body { background: white; }
  .container { max-width: 100%; padding: 0 12px; gap: 14px; }
  .topbar { display: none; }
  .print-header {
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 10px 0 16px;
    border-bottom: 3px solid var(--primary);
    margin-bottom: 6px;
  }
  .print-logo { height: 52px; }
  .print-header h2 { margin: 0; font-size: 1.2rem; }
  .print-header p { margin: 2px 0 0; color: var(--text-muted); font-size: 0.85rem; }
  .card { box-shadow: none; border: 1px solid #ccc; break-inside: avoid; padding: 14px 16px; }
  .data-table thead { display: table-header-group; }
  .data-table tbody tr { break-inside: avoid; }
  .kpi-tile.overall { background: var(--primary) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .data-table thead th { background: var(--accent) !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .chart-wrap { break-inside: avoid; }
}
