@import url('https://fonts.googleapis.com/css2?family=Syne:wght@600;700;800&family=JetBrains+Mono:wght@400;500;700&display=swap');

:root {
  --bg: #0d0d10;
  --bg-raised: #17171b;
  --bg-card: #1c1c21;
  --border: #2a2a31;
  --text: #eceef1;
  --text-dim: #8d8d96;
  --gold: #f0a030;
  --gold-dim: #7a5420;
  --teal: #32b896;
  --teal-dim: #1c5f4d;
  --danger: #e0555a;
  --radius: 14px;
  --font-head: 'Syne', system-ui, sans-serif;
  --font-num: 'JetBrains Mono', 'SFMono-Regular', monospace;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  -webkit-tap-highlight-color: transparent;
}

body {
  padding-bottom: 76px; /* clear the bottom nav */
  min-height: 100vh;
}

h1, h2, h3 {
  font-family: var(--font-head);
  font-weight: 700;
  margin: 0 0 12px;
  letter-spacing: -0.01em;
}

button, input, select {
  font-family: inherit;
  color: inherit;
}

a { color: var(--teal); }

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

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}

/* ---------- App shell ---------- */

.app-header {
  padding: 20px 16px 12px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
}

.app-header .brand {
  font-family: var(--font-head);
  font-weight: 800;
  font-size: 20px;
}
.app-header .brand .accent { color: var(--gold); }

.app-header .subtitle {
  font-size: 12px;
  color: var(--text-dim);
}

.screen {
  padding: 0 16px 24px;
  max-width: 560px;
  margin: 0 auto;
}

.screen[hidden] { display: none; }

/* ---------- Bottom nav ---------- */

.bottom-nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--bg-raised);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 20;
}

.nav-btn {
  flex: 1;
  background: none;
  border: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px;
  border-radius: 10px;
  color: var(--text-dim);
  font-size: 10px;
}

.nav-btn .icon { font-size: 18px; line-height: 1; }

.nav-btn.active {
  color: var(--gold);
}

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

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

.card-title {
  font-family: var(--font-head);
  font-weight: 700;
  font-size: 14px;
  color: var(--text-dim);
  margin-bottom: 10px;
}

/* ---------- KPI strip ---------- */

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
  margin-bottom: 14px;
}

.kpi {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 10px;
  text-align: left;
}

.kpi .kpi-label {
  font-size: 11px;
  color: var(--text-dim);
  margin-bottom: 6px;
}

.kpi .kpi-value {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 17px;
  color: var(--teal);
}

.kpi.gold .kpi-value { color: var(--gold); }

/* ---------- Bar chart (pure CSS/SVG, no external lib) ---------- */

.bar-chart { display: flex; flex-direction: column; gap: 10px; }

.bar-row { display: flex; align-items: center; gap: 10px; }

.bar-row .bar-label {
  width: 88px;
  flex-shrink: 0;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bar-track {
  flex: 1;
  background: var(--bg-raised);
  border-radius: 6px;
  height: 18px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--teal-dim), var(--teal));
  border-radius: 6px;
}

.bar-row .bar-value {
  font-family: var(--font-num);
  font-size: 12px;
  color: var(--text-dim);
  width: 72px;
  text-align: right;
  flex-shrink: 0;
}

/* ---------- Dept table ---------- */

table.dept-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.dept-table th {
  text-align: left;
  color: var(--text-dim);
  font-weight: 600;
  padding: 6px 4px;
  border-bottom: 1px solid var(--border);
}
table.dept-table td {
  padding: 8px 4px;
  border-bottom: 1px solid var(--border);
}
table.dept-table td.num, table.dept-table th.num {
  font-family: var(--font-num);
  text-align: right;
}

/* ---------- Forms ---------- */

.field {
  margin-bottom: 14px;
}
.field label {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field input[type="text"],
.field input[type="date"],
.field input[type="time"],
.field input[type="number"],
.field select,
.field textarea {
  width: 100%;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  font-size: 15px;
  color: var(--text);
}
.field textarea { resize: vertical; min-height: 60px; }

.field-row {
  display: flex;
  gap: 10px;
}
.field-row > .field { flex: 1; }

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
}

.switch {
  position: relative;
  width: 42px;
  height: 24px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 999px;
  transition: background 0.15s;
}
.switch .track::before {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  left: 2px; top: 2px;
  background: var(--text-dim);
  border-radius: 50%;
  transition: transform 0.15s, background 0.15s;
}
.switch input:checked + .track { background: var(--gold-dim); border-color: var(--gold); }
.switch input:checked + .track::before { transform: translateX(18px); background: var(--gold); }

.dept-chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.dept-chip {
  border: 1px solid var(--border);
  background: var(--bg-raised);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text-dim);
}
.dept-chip.selected {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(240,160,48,0.08);
}

.pay-preview {
  background: var(--bg-raised);
  border: 1px dashed var(--teal-dim);
  border-radius: 10px;
  padding: 12px;
  margin-top: 4px;
}
.pay-preview .preview-amount {
  font-family: var(--font-num);
  font-weight: 700;
  font-size: 22px;
  color: var(--teal);
}
.pay-preview .preview-detail {
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 4px;
}

/* ---------- Buttons ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn-primary { background: var(--gold); color: #1a1300; }
.btn-secondary { background: var(--bg-raised); color: var(--text); border: 1px solid var(--border); }
.btn-danger { background: rgba(224,85,90,0.12); color: var(--danger); border: 1px solid var(--danger); }
.btn-block { width: 100%; }
.btn-sm { padding: 7px 12px; font-size: 12px; }

.btn-row { display: flex; gap: 10px; margin-top: 6px; }

/* ---------- Log list ---------- */

.log-item {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.log-item:last-child { border-bottom: none; }

.log-item .log-main { flex: 1; }
.log-item .log-dept { font-size: 13px; color: var(--text-dim); }
.log-item .log-date { font-weight: 600; font-size: 14px; }
.log-item .log-time { font-family: var(--font-num); font-size: 12px; color: var(--text-dim); }
.log-item .log-pay { font-family: var(--font-num); color: var(--teal); font-weight: 700; font-size: 15px; white-space: nowrap; }

.log-actions { display: flex; gap: 6px; margin-top: 6px; }
.icon-btn {
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-dim);
  border-radius: 8px;
  padding: 4px 9px;
  font-size: 12px;
}
.icon-btn.danger { color: var(--danger); border-color: rgba(224,85,90,0.4); }

.filter-row {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 10px;
}
.filter-chip {
  flex-shrink: 0;
  border: 1px solid var(--border);
  background: var(--bg-raised);
  color: var(--text-dim);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 12px;
  white-space: nowrap;
}
.filter-chip.active { border-color: var(--teal); color: var(--teal); }

.totals-bar {
  display: flex;
  justify-content: space-between;
  padding: 12px 4px 0;
  font-family: var(--font-num);
  font-size: 13px;
  color: var(--text-dim);
}
.totals-bar strong { color: var(--teal); }

/* ---------- Import preview ---------- */

.import-row {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 13px;
}
.import-row.bad { border-color: rgba(224,85,90,0.5); background: rgba(224,85,90,0.06); }
.import-row .raw-line { color: var(--text-dim); font-size: 11px; margin-bottom: 4px; font-family: var(--font-num); }
.import-row .parsed { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.import-row .tag { font-size: 10px; padding: 2px 6px; border-radius: 4px; background: var(--bg-raised); color: var(--text-dim); }
.import-row .tag.holiday { color: var(--gold); }
.import-row .tag.crossmidnight { color: var(--teal); }

/* ---------- Empty state ---------- */

.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-dim);
}
.empty-state .emoji { font-size: 32px; margin-bottom: 10px; }

/* ---------- Toast ---------- */

#toast {
  position: fixed;
  bottom: 88px;
  left: 50%;
  transform: translateX(-50%) translateY(10px);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 10px;
  font-size: 13px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50;
  max-width: 90vw;
}
#toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* ---------- Rules editor grid ---------- */

.rate-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

hr.sep {
  border: none;
  border-top: 1px solid var(--border);
  margin: 16px 0;
}

@media print {
  .bottom-nav, .app-header { display: none !important; }
}
