:root {
  color-scheme: light;
  --page: #f9f9f7;
  --surface: #fcfcfb;
  --text-primary: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #898781;
  --gridline: #e1e0d9;
  --baseline: #c3c2b7;
  --border: rgba(11, 11, 11, 0.10);

  --series-1: #2a78d6; /* blue */
  --series-2: #eb6834; /* orange */
  --series-3: #1baf7a; /* aqua */
  --series-4: #eda100; /* yellow */

  --accent: #eb6834;
  --success: #006300;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --page: #0d0d0d;
    --surface: #1a1a19;
    --text-primary: #ffffff;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --gridline: #2c2c2a;
    --baseline: #383835;
    --border: rgba(255, 255, 255, 0.10);

    --series-1: #3987e5;
    --series-2: #d95926;
    --series-3: #199e70;
    --series-4: #c98500;

    --success: #0ca30c;
  }
}

* { box-sizing: border-box; }

/* Author `display` rules below would otherwise beat the UA [hidden] default. */
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--page);
  color: var(--text-primary);
  font-family: system-ui, -apple-system, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.muted { color: var(--text-muted); }

.page {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  gap: 12px;
}

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}
.login-card {
  max-width: 380px;
  width: 100%;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 36px 28px;
}
.login-card .brand-mark { margin: 0 auto 16px; }
.login-card h1 { margin: 0 0 10px; font-size: 20px; }
.login-card p { font-size: 13px; line-height: 1.5; margin: 0 0 22px; }
.login-note { margin: 14px 0 0 !important; font-size: 12px; }
.login-note.error { color: #d03b3b; }

.btn-google {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: #fff;
  color: #1f1f1f;
  border: 1px solid rgba(0, 0, 0, 0.2);
  width: 100%;
  padding: 11px 16px;
  font-size: 14px;
}
.btn-google:hover { background: #f7f7f7; }

.user-area { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.user-chip { display: flex; align-items: center; gap: 8px; }
.user-avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--series-1); color: #fff;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; overflow: hidden; flex-shrink: 0;
}
.user-avatar img { width: 100%; height: 100%; object-fit: cover; }
.user-name { font-size: 13px; color: var(--text-secondary); }
.link-btn {
  background: none; border: none; color: var(--text-muted);
  font-size: 12px; cursor: pointer; padding: 4px 6px; text-decoration: underline;
}
.link-btn:hover { color: var(--text-primary); }

.drive-status {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
  color: var(--text-secondary);
}
.drive-status .drive-info { display: flex; align-items: center; gap: 8px; }
.drive-status .status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--success); flex-shrink: 0; }
.drive-status .status-dot.off { background: var(--text-muted); }

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

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: var(--series-4);
  color: #1a1a19;
  font-weight: 800;
  font-size: 22px;
}

.brand h1 { margin: 0; font-size: 20px; }
.brand p { margin: 2px 0 0; font-size: 13px; }

.dropzone {
  position: relative;
  border: 2px dashed var(--baseline);
  border-radius: 16px;
  background: var(--surface);
  padding: 28px 20px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
  margin-bottom: 24px;
}
.dropzone.dragover {
  border-color: var(--series-1);
  background: color-mix(in oklab, var(--series-1) 6%, var(--surface));
}
.dropzone-title { font-size: 16px; font-weight: 600; margin: 0 0 4px; }

.btn {
  margin-top: 12px;
  padding: 9px 18px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--text-primary);
  color: var(--page);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { opacity: 0.9; }

.upload-status {
  margin-top: 14px;
  text-align: left;
  font-size: 13px;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.upload-status .line { padding: 2px 0; }
.status-added { color: var(--success); }
.status-dup { color: var(--text-muted); }
.status-error { color: #d03b3b; }

.kpis {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
  margin-bottom: 24px;
}
.kpi-tile {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.kpi-label { font-size: 12px; color: var(--text-secondary); margin-bottom: 6px; }
.kpi-value { font-size: 24px; font-weight: 700; font-variant-numeric: tabular-nums; }

.charts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}
.chart-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.chart-card h2 { margin: 0 0 12px; font-size: 14px; color: var(--text-secondary); font-weight: 600; }
.chart-wrap { position: relative; height: 240px; }

.empty-state {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 32px;
  text-align: center;
  color: var(--text-secondary);
}

.receipts-section, .locations-section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
}
.locations-section { margin-bottom: 24px; }

#map {
  height: 360px;
  border-radius: 10px;
  margin-bottom: 14px;
  border: 1px solid var(--border);
  background: var(--page);
}
.leaflet-popup-content-wrapper, .leaflet-popup-tip {
  background: var(--surface);
  color: var(--text-primary);
}
.map-popup { font-size: 13px; line-height: 1.5; }
.map-popup .popup-title { font-weight: 700; margin-bottom: 2px; }
.map-popup .popup-badge { display: inline-block; margin-top: 4px; }

.legend { display: flex; gap: 14px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-secondary); }
.legend-dot { width: 10px; height: 10px; border-radius: 50%; display: inline-block; }

.operator-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--text-secondary);
}
.operator-badge .legend-dot { width: 8px; height: 8px; }
.receipts-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}
.receipts-header h2 { margin: 0; font-size: 16px; }
#searchInput {
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--page);
  color: var(--text-primary);
  font-size: 13px;
  min-width: 220px;
}

.table-wrap { overflow-x: auto; }
.receipts-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.receipts-table th {
  text-align: left;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 8px 10px;
  border-bottom: 1px solid var(--gridline);
}
.receipts-table td {
  padding: 10px;
  border-bottom: 1px solid var(--gridline);
  vertical-align: top;
}
.receipts-table tbody tr { cursor: pointer; }
.receipts-table tbody tr:hover { background: color-mix(in oklab, var(--series-1) 4%, transparent); }
.receipts-table .num { text-align: right; font-variant-numeric: tabular-nums; }
.receipts-table .item-preview { color: var(--text-secondary); max-width: 340px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.icon-btn {
  border: none;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 14px;
  padding: 4px 8px;
  border-radius: 6px;
}
.icon-btn:hover { color: #d03b3b; background: var(--gridline); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.45);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 48px 16px;
  overflow-y: auto;
  z-index: 20;
}
.modal {
  position: relative;
  background: var(--surface);
  border-radius: 14px;
  border: 1px solid var(--border);
  max-width: 520px;
  width: 100%;
  padding: 24px;
}
.modal-close {
  position: absolute;
  top: 12px;
  right: 12px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}
.modal h3 { margin: 0 0 4px; font-size: 17px; }
.modal .modal-meta { color: var(--text-secondary); font-size: 13px; margin-bottom: 16px; }
.modal pre {
  background: var(--page);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  font-size: 12px;
  white-space: pre-wrap;
  line-height: 1.5;
  max-height: 320px;
  overflow-y: auto;
}
.modal .modal-total { font-size: 20px; font-weight: 700; margin: 12px 0; }

@media (max-width: 720px) {
  .kpis { grid-template-columns: repeat(2, 1fr); }
  .charts-grid { grid-template-columns: 1fr; }
  .receipts-header { flex-direction: column; align-items: stretch; }
  #searchInput { min-width: 0; }
}
