/* =========================================================
   Design tokens
   ========================================================= */
:root {
  --bg-page: #f4f6fb;
  --bg-panel: #ffffff;
  --bg-panel-muted: #f8fafc;
  --border: #e5e9f2;
  --border-strong: #d7deeb;

  --text-primary: #1f2937;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --text-on-accent: #ffffff;

  --accent-primary: #4f46e5;
  --accent-primary-hover: #4338ca;
  --accent-primary-soft: #eef2ff;
  --accent-success: #16a34a;
  --accent-success-hover: #15803d;
  --accent-success-soft: #ecfdf5;
  --accent-warning: #d97706;
  --accent-warning-soft: #fffbeb;
  --accent-info: #0891b2;
  --accent-info-soft: #ecfeff;

  --shadow-card: 0 1px 2px rgba(15, 23, 42, 0.04), 0 8px 24px rgba(15, 23, 42, 0.06);
  --shadow-card-hover: 0 1px 2px rgba(15, 23, 42, 0.05), 0 12px 32px rgba(15, 23, 42, 0.09);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;

  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --space-7: 48px;

  --font-sans: "Segoe UI", Inter, system-ui, -apple-system, sans-serif;
  --fs-h1: clamp(1.35rem, 1.1rem + 1vw, 1.85rem);
  --fs-h2: clamp(1.05rem, 0.95rem + 0.4vw, 1.25rem);
  --fs-body: 1rem;
  --fs-small: 0.875rem;
  --fs-xsmall: 0.78rem;
}

/* =========================================================
   Base / reset
   ========================================================= */
* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
}

body {
  min-height: 100vh;
  font-family: var(--font-sans);
  color: var(--text-primary);
  background: var(--bg-page);
}

a {
  color: var(--accent-primary);
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.3;
}

button,
input {
  font-family: inherit;
}

:focus-visible {
  outline: 2px solid var(--accent-primary);
  outline-offset: 2px;
}

/* =========================================================
   Topbar + stepper
   ========================================================= */
.topbar {
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  padding: var(--space-4) var(--space-6);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-5);
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}

.brand {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-weight: 700;
  font-size: 1.05rem;
  color: var(--text-primary);
  white-space: nowrap;
}

.brand .icon {
  color: var(--accent-primary);
}

.stepper {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  list-style: none;
  margin: 0;
  padding: 0;
}

.step {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-muted);
  font-size: var(--fs-small);
  font-weight: 600;
}

.step-badge {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--fs-xsmall);
  color: var(--text-muted);
  flex-shrink: 0;
  background: var(--bg-panel);
}

.step.is-done .step-badge {
  border-color: var(--accent-success);
  background: var(--accent-success);
  color: var(--text-on-accent);
}

.step.is-active .step-badge {
  border-color: var(--accent-primary);
  color: var(--accent-primary);
  font-weight: 700;
}

.step.is-active {
  color: var(--text-primary);
}

.step-sep {
  width: 28px;
  height: 2px;
  background: var(--border-strong);
}

.step-label {
  white-space: nowrap;
}

/* =========================================================
   Page shell / panel
   ========================================================= */
.page-content {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-6) var(--space-5) var(--space-7);
}

.page-content.narrow {
  max-width: 560px;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: calc(100vh - 68px);
  justify-content: center;
  padding-top: var(--space-6);
  padding-bottom: var(--space-6);
}

.panel {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-6) var(--space-5);
}

.panel + .panel {
  margin-top: var(--space-5);
}

/* =========================================================
   Icons
   ========================================================= */
.icon {
  width: 1.15em;
  height: 1.15em;
  stroke: currentColor;
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  vertical-align: -0.2em;
  flex-shrink: 0;
}

.icon-lg {
  width: 2.5rem;
  height: 2.5rem;
  color: var(--accent-primary);
}

/* =========================================================
   Upload panel (index.html)
   ========================================================= */
.upload-panel {
  width: 100%;
  text-align: center;
}

.upload-panel h1 {
  font-size: var(--fs-h1);
  margin: var(--space-4) 0 var(--space-2);
}

.upload-panel .subcopy {
  color: var(--text-secondary);
  font-size: var(--fs-small);
  margin-bottom: var(--space-5);
}

.file-field {
  border: 1.5px dashed var(--border-strong);
  border-radius: var(--radius-md);
  padding: var(--space-6) var(--space-4);
  margin-bottom: var(--space-5);
  background: var(--bg-panel-muted);
  transition: border-color 0.15s ease, background 0.15s ease;
}

.file-field:focus-within,
.file-field:hover {
  border-color: var(--accent-primary);
  background: var(--accent-primary-soft);
}

.file-field-hint {
  display: block;
  color: var(--text-muted);
  font-size: var(--fs-xsmall);
  margin-top: var(--space-2);
}

input[type="file"] {
  width: 100%;
  color: var(--text-secondary);
  font-size: var(--fs-small);
}

input[type="file"]::file-selector-button {
  font-family: inherit;
  font-weight: 600;
  font-size: var(--fs-small);
  color: var(--text-on-accent);
  background: var(--accent-primary);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.55rem 1.1rem;
  margin-right: var(--space-3);
  cursor: pointer;
  transition: background 0.15s ease;
}

input[type="file"]::file-selector-button:hover {
  background: var(--accent-primary-hover);
}

/* =========================================================
   Buttons
   ========================================================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0.8rem 1.6rem;
  font-weight: 600;
  font-size: var(--fs-body);
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s ease, box-shadow 0.15s ease, transform 0.1s ease;
}

.btn:active {
  transform: translateY(1px);
}

.btn-primary {
  background: var(--accent-primary);
  color: var(--text-on-accent);
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
}

.btn-success {
  background: var(--accent-success);
  color: var(--text-on-accent);
}

.btn-success:hover {
  background: var(--accent-success-hover);
}

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

.btn-secondary:hover {
  background: var(--bg-panel-muted);
}

.actions-row {
  display: flex;
  gap: var(--space-3);
  justify-content: center;
  flex-wrap: wrap;
  margin-top: var(--space-5);
}

/* =========================================================
   Page header (preview / view)
   ========================================================= */
.page-header {
  margin-bottom: var(--space-5);
}

.page-header h1 {
  font-size: var(--fs-h1);
  overflow-wrap: anywhere;
}

.page-header h1 .icon {
  margin-right: var(--space-2);
  color: var(--accent-primary);
}

.page-header p {
  color: var(--text-secondary);
  margin-top: var(--space-2);
}

/* =========================================================
   KPI stat cards (view.html)
   ========================================================= */
.kpi-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-4);
  margin-bottom: var(--space-5);
}

.kpi-card {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-card);
  padding: var(--space-4) var(--space-4);
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
}

.kpi-icon {
  width: 38px;
  height: 38px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-icon .icon {
  width: 1.25rem;
  height: 1.25rem;
}

.kpi-card.tone-primary .kpi-icon {
  background: var(--accent-primary-soft);
  color: var(--accent-primary);
}

.kpi-card.tone-info .kpi-icon {
  background: var(--accent-info-soft);
  color: var(--accent-info);
}

.kpi-card.tone-warning .kpi-icon {
  background: var(--accent-warning-soft);
  color: var(--accent-warning);
}

.kpi-card.tone-success .kpi-icon {
  background: var(--accent-success-soft);
  color: var(--accent-success);
}

.kpi-value {
  font-size: 1.4rem;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.kpi-label {
  color: var(--text-secondary);
  font-size: var(--fs-small);
}

/* =========================================================
   Tables
   ========================================================= */
.table-scroll {
  overflow-x: auto;
  overflow-y: auto;
  max-height: 420px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  -webkit-overflow-scrolling: touch;
}

.table-scroll table,
table.dataframe {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--fs-small);
  color: var(--text-primary);
}

.table-scroll th,
.table-scroll td,
table.dataframe th,
table.dataframe td {
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border);
  text-align: left;
  white-space: nowrap;
}

.table-scroll thead th,
table.dataframe thead th {
  position: sticky;
  top: 0;
  background: var(--bg-panel-muted);
  color: var(--text-primary);
  font-weight: 600;
  z-index: 1;
  border-bottom: 1px solid var(--border-strong);
}

.table-scroll tbody tr:nth-child(even),
table.dataframe tbody tr:nth-child(even) {
  background: var(--bg-panel-muted);
}

.table-scroll tbody tr:hover,
table.dataframe tbody tr:hover {
  background: var(--accent-primary-soft);
}

/* Numeric columns in view.html (Nilai, Parkir/Tips, Total Grand) */
.division-table td:nth-child(3),
.division-table td:nth-child(4),
.division-table td:nth-child(5),
.division-table th:nth-child(3),
.division-table th:nth-child(4),
.division-table th:nth-child(5),
.rekap-table td:nth-child(2),
.rekap-table td:nth-child(3),
.rekap-table td:nth-child(4),
.rekap-table th:nth-child(2),
.rekap-table th:nth-child(3),
.rekap-table th:nth-child(4) {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.row-total td {
  background: var(--accent-primary-soft) !important;
  border-top: 1px solid var(--border-strong);
  font-weight: 700;
  color: var(--text-primary);
}

.row-grand-total td {
  background: var(--accent-warning-soft) !important;
  border-top: 1px solid #fcd34d;
  font-weight: 700;
  color: var(--accent-warning);
}

/* =========================================================
   Division sections (view.html)
   ========================================================= */
.division-section {
  margin-bottom: var(--space-5);
}

.division-title {
  display: flex;
  align-items: center;
  gap: var(--space-2);
  color: var(--text-primary);
  font-size: var(--fs-h2);
  margin-bottom: var(--space-3);
}

.division-title .icon {
  color: var(--accent-primary);
}

/* =========================================================
   Responsive
   ========================================================= */
@media (max-width: 768px) {
  .topbar {
    padding: var(--space-3) var(--space-4);
  }
  .step-label {
    display: none;
  }
  .page-content {
    padding: var(--space-5) var(--space-4) var(--space-6);
  }
  .panel {
    padding: var(--space-5) var(--space-4);
  }
  .kpi-row {
    grid-template-columns: repeat(2, 1fr);
  }
  .table-scroll {
    max-height: 320px;
  }
  .actions-row .btn {
    width: 100%;
  }
}

@media (max-width: 480px) {
  .kpi-row {
    grid-template-columns: 1fr;
  }
  .btn {
    padding: 0.75rem 1.25rem;
    font-size: var(--fs-small);
  }
}

/* Static (Cloudflare Pages) additions */
[hidden] { display: none !important; }
.error-box {
  margin-top: var(--space-4);
  padding: var(--space-3) var(--space-4);
  border-radius: var(--radius-sm);
  background: #fef2f2;
  color: #b91c1c;
  font-size: var(--fs-small);
  text-align: left;
}
.privacy-note {
  margin-top: var(--space-4);
  color: var(--text-muted);
  font-size: var(--fs-xsmall);
}
