:root {
  --bg: #f5f5f7;
  --surface: #ffffff;
  --surface-raised: #ffffff;
  --text: #1a1a1e;
  --text-dim: #6b6b70;
  --border: #e3e3e6;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --good: #1a9e5c;
  --good-bg: #e6f6ee;
  --warn: #b5790a;
  --warn-bg: #fdf1dc;
  --danger: #c23a3a;
  --danger-bg: #fbe9e9;
  --radius-lg: 20px;
  --radius-md: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,0.04), 0 8px 24px rgba(0,0,0,0.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --surface: #1a1c22;
    --surface-raised: #212330;
    --text: #f2f2f4;
    --text-dim: #9a9aa2;
    --border: #2c2e38;
    --accent: #5b8def;
    --accent-text: #0f1115;
    --good: #3dd68c;
    --good-bg: #113826;
    --warn: #e3ab3d;
    --warn-bg: #3a2c0f;
    --danger: #ef6a6a;
    --danger-bg: #3a1414;
    --shadow: 0 1px 2px rgba(0,0,0,0.3), 0 8px 24px rgba(0,0,0,0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
  height: 100%;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  padding: max(20px, env(safe-area-inset-top)) 18px calc(28px + env(safe-area-inset-bottom));
  max-width: 480px;
  margin: 0 auto;
  width: 100%;
}

.top-date {
  margin-top: 8px;
}
.top-date .day {
  font-size: 15px;
  font-weight: 600;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.top-date .date {
  font-size: 28px;
  font-weight: 800;
  margin-top: 2px;
}

.top-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}
.qr-btn {
  margin-top: 8px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  box-shadow: var(--shadow);
  flex-shrink: 0;
}

.sheet-hint {
  margin: -6px 0 16px;
  font-size: 14px;
  line-height: 1.45;
  color: var(--text-dim);
}
.field input[type="file"] { font-family: inherit; font-size: 14px; color: var(--text); max-width: 100%; }
.qr-preview {
  margin-bottom: 16px;
  padding: 12px;
  background: #ffffff;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  text-align: center;
}
.qr-preview img { max-width: 100%; max-height: 220px; object-fit: contain; }
.btn:disabled { opacity: 0.45; }

/* Always white: scanners need dark-on-light contrast, whatever the theme. */
.qr-fullscreen {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: #ffffff;
  color: #1a1a1e;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: max(24px, env(safe-area-inset-top)) 20px calc(20px + env(safe-area-inset-bottom));
}
.qr-image-wrap {
  flex: 1;
  width: 100%;
  max-width: 480px;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.qr-image-wrap img { max-width: 100%; max-height: 100%; object-fit: contain; }
.qr-tip { font-size: 13px; color: #6b6b70; text-align: center; margin: 16px 0 8px; }
.qr-actions { display: flex; gap: 28px; margin-bottom: 12px; }
.qr-link {
  background: none;
  border: none;
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  color: #2563eb;
  padding: 10px 4px;
}
.qr-link-danger { color: #c23a3a; }
.qr-fullscreen .qr-done { flex: none; width: 100%; max-width: 480px; background: #1a1a1e; color: #ffffff; padding: 16px; font-size: 16px; }

.banner {
  margin-top: 18px;
  padding: 14px 16px;
  border-radius: var(--radius-md);
  background: var(--warn-bg);
  color: var(--warn);
  font-size: 14px;
  line-height: 1.4;
}
.banner strong { display: block; margin-bottom: 6px; font-size: 15px; }
.banner.danger { background: var(--danger-bg); color: var(--danger); }
.banner .banner-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
  flex-wrap: wrap;
}
.banner button {
  border: 1px solid currentColor;
  background: transparent;
  color: inherit;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
}

.card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 20px;
  margin-top: 18px;
  box-shadow: var(--shadow);
}

.location-toggle {
  display: flex;
  background: var(--bg);
  border-radius: 999px;
  padding: 4px;
  margin-top: 16px;
  gap: 4px;
}
.location-toggle button {
  flex: 1;
  border: none;
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 0;
  border-radius: 999px;
  transition: background 0.15s, color 0.15s;
}
.location-toggle button.active {
  background: var(--surface-raised);
  color: var(--text);
  box-shadow: var(--shadow);
}
.location-toggle button:disabled { opacity: 0.5; }

.primary-action {
  margin-top: 22px;
  width: 100%;
  border: none;
  border-radius: var(--radius-lg);
  padding: 28px 20px;
  font-family: inherit;
  font-size: 22px;
  font-weight: 800;
  color: var(--accent-text);
  background: var(--accent);
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
}
.primary-action.logout { background: var(--warn); }
.primary-action .sub {
  font-size: 14px;
  font-weight: 600;
  opacity: 0.85;
}
.primary-action .running {
  font-size: 15px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  opacity: 0.95;
}

.summary {
  margin-top: 22px;
}
.summary-row {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
}
.summary-row:last-child { border-bottom: none; }
.summary-row .label { color: var(--text-dim); }
.summary-row .value { font-weight: 700; font-variant-numeric: tabular-nums; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  background: var(--good-bg);
  color: var(--good);
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

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

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 999px;
  background: var(--bg);
  color: var(--text-dim);
  white-space: nowrap;
}

.icon-btn {
  background: none;
  border: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 13px;
  font-weight: 700;
  padding: 4px 0;
}

.table-wrap {
  overflow-x: auto;
  margin-top: 16px;
  -webkit-overflow-scrolling: touch;
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
}
table.timesheet {
  border-collapse: collapse;
  width: 100%;
  min-width: 640px;
  font-size: 13px;
  background: var(--surface);
}
table.timesheet th, table.timesheet td {
  border-bottom: 1px solid var(--border);
  padding: 8px 10px;
  text-align: left;
  white-space: nowrap;
}
table.timesheet th {
  color: var(--text-dim);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}
table.timesheet tr:last-child td { border-bottom: none; }
table.timesheet tr.off-row td { color: var(--text-dim); }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%) translateY(20px);
  background: var(--surface-raised);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 14px;
  font-weight: 600;
  opacity: 0;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 100;
  max-width: 90vw;
  text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

.text-link {
  background: none;
  border: none;
  color: var(--accent);
  font-family: inherit;
  font-size: 14px;
  font-weight: 700;
  padding: 10px 0;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: flex-end;
  z-index: 50;
}
@media (min-width: 540px) {
  .modal-overlay { align-items: center; justify-content: center; }
}
.modal-sheet {
  background: var(--surface);
  border-radius: 24px 24px 0 0;
  padding: 22px 20px calc(22px + env(safe-area-inset-bottom));
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
}
@media (min-width: 540px) {
  .modal-sheet { border-radius: var(--radius-lg); }
}
.modal-sheet h2 { margin: 0 0 16px; font-size: 18px; font-weight: 800; }
.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.field input[type="time"],
.field input[type="date"],
.field input[type="text"],
.field select,
.field textarea {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
}
.field-checkbox {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 14px;
}
.field-checkbox input { width: 18px; height: 18px; }

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}
.btn {
  flex: 1;
  border: none;
  border-radius: var(--radius-sm);
  padding: 14px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 700;
}
.btn-primary { background: var(--accent); color: var(--accent-text); }
.btn-secondary { background: var(--bg); color: var(--text); }
.btn-danger { background: var(--danger-bg); color: var(--danger); }

.error-text {
  color: var(--danger);
  font-size: 13px;
  margin-top: -8px;
  margin-bottom: 14px;
}
.error-text div { margin-bottom: 4px; }

.warning-box {
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  font-size: 13px;
  line-height: 1.4;
  margin-bottom: 14px;
}
.warning-box strong { display: block; margin-bottom: 4px; font-size: 14px; }

/* Settings */
.field input[type="number"] {
  width: 100%;
  padding: 12px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 16px;
}
.settings-heading {
  margin: 24px 4px 8px;
  font-size: 13px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.settings-heading.danger { color: var(--danger); }
.danger-card { border: 1px solid var(--danger-bg); }
.weekday-picks { display: flex; flex-wrap: wrap; gap: 8px 14px; }
.weekday-picks .field-checkbox { display: flex; font-size: 15px; min-height: 32px; color: var(--text); font-weight: 500; margin: 0; }
.btn:disabled { opacity: 0.45; }
