:root {
  --bg: #0b0f19;
  --surface: #141b2c;
  --surface-2: #1c2540;
  --border: #262f48;
  --text: #eef1f8;
  --text-dim: #93a0bd;
  --accent: #2dd4bf;
  --accent-2: #38bdf8;
  --accent-soft: rgba(45, 212, 191, 0.14);
  --danger: #fb7185;
  --danger-soft: rgba(251, 113, 133, 0.14);
  --warning: #fbbf24;
  --radius-lg: 22px;
  --radius-md: 16px;
  --radius-sm: 10px;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.35);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface-2: #eef1fa;
    --border: #dfe4f0;
    --text: #141a29;
    --text-dim: #5a6479;
    --accent: #0d9488;
    --accent-2: #0284c7;
    --accent-soft: rgba(13, 148, 136, 0.1);
    --danger: #e11d48;
    --danger-soft: rgba(225, 29, 72, 0.1);
    --shadow: 0 12px 28px rgba(30, 41, 70, 0.1);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

body {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  padding-bottom: calc(78px + var(--safe-bottom));
  position: relative;
  overflow-x: hidden;
}

body::before {
  content: "";
  position: fixed;
  inset: -10%;
  z-index: -1;
  background:
    radial-gradient(38% 30% at 15% 8%, rgba(45, 212, 191, 0.16), transparent 60%),
    radial-gradient(45% 35% at 88% 18%, rgba(56, 189, 248, 0.12), transparent 60%),
    radial-gradient(40% 30% at 50% 95%, rgba(45, 212, 191, 0.08), transparent 60%);
  animation: ambientDrift 22s ease-in-out infinite alternate;
  pointer-events: none;
}
@keyframes ambientDrift {
  0% { transform: translate(0, 0) scale(1); }
  100% { transform: translate(-2%, 2%) scale(1.06); }
}

@keyframes fadeSlideUp {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}
.view:not([hidden]) .card {
  animation: fadeSlideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1) backwards;
}
.view:not([hidden]) .card:nth-child(1) { animation-delay: 0.02s; }
.view:not([hidden]) .card:nth-child(2) { animation-delay: 0.07s; }
.view:not([hidden]) .card:nth-child(3) { animation-delay: 0.12s; }
.view:not([hidden]) .card:nth-child(4) { animation-delay: 0.17s; }
.session-item, .calendar-day { animation: fadeSlideUp 0.3s ease backwards; }

svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(16px + var(--safe-top)) 20px 14px;
  position: sticky;
  top: 0;
  background: linear-gradient(180deg, var(--bg) 70%, transparent);
  z-index: 5;
}

.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  font-size: 17px;
  letter-spacing: -0.01em;
}

.brand-mark {
  color: var(--accent);
  width: 24px;
  height: 24px;
}

.topbar-date {
  font-size: 13px;
  color: var(--text-dim);
}

#app {
  flex: 1;
  padding: 4px 16px 24px;
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.view { display: flex; flex-direction: column; gap: 16px; }

.card {
  background: linear-gradient(180deg, var(--surface) 0%, var(--surface) 100%);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px 18px 20px;
  box-shadow: var(--shadow);
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}
@supports (backdrop-filter: blur(1px)) {
  .card { background: color-mix(in srgb, var(--surface) 92%, transparent); backdrop-filter: blur(14px); }
}

.card h2 {
  margin: 0 0 14px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* Timer */
.timer-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  padding: 28px 16px 8px;
}

.timer-ring {
  position: relative;
  width: min(72vw, 260px);
  height: min(72vw, 260px);
}

.ring-glow {
  position: absolute;
  inset: 8%;
  border-radius: 50%;
  background: radial-gradient(circle, var(--accent-2) 0%, transparent 70%);
  opacity: 0;
  filter: blur(18px);
  transition: opacity 0.4s ease, background 0.4s ease;
  pointer-events: none;
}
.timer-ring.is-running .ring-glow { opacity: 0.55; animation: ringGlowPulse 2.4s ease-in-out infinite; }
.timer-ring.is-paused .ring-glow { opacity: 0.35; background: radial-gradient(circle, var(--warning) 0%, transparent 70%); animation: none; }
@keyframes ringGlowPulse {
  0%, 100% { opacity: 0.4; transform: scale(0.96); }
  50% { opacity: 0.7; transform: scale(1.04); }
}

.ring-svg { width: 100%; height: 100%; transform: rotate(-90deg); position: relative; z-index: 1; }
.ring-track {
  fill: none;
  stroke: var(--surface-2);
  stroke-width: 10;
}
.ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 10;
  stroke-linecap: round;
  stroke-dasharray: 565.48;
  stroke-dashoffset: 565.48;
  transition: stroke-dashoffset 1s linear, stroke 0.3s ease;
}
.timer-ring.is-running .ring-progress { stroke: var(--accent-2); }
.timer-ring.is-paused .ring-progress { stroke: var(--warning); }
.timer-ring.is-paused .timer-clock { opacity: 0.6; }

.timer-center {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.timer-clock {
  font-size: clamp(28px, 8vw, 38px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.02em;
}

.timer-label {
  font-size: 13px;
  color: var(--text-dim);
}

.btn-start {
  appearance: none;
  border: none;
  width: 100%;
  max-width: 320px;
  padding: 16px 20px;
  border-radius: 999px;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #062024;
  font-size: 16px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.15s ease;
  box-shadow: 0 10px 24px rgba(45, 212, 191, 0.28);
}
.btn-start:active { transform: scale(0.97); }
.btn-start.is-running {
  background: linear-gradient(135deg, var(--danger), #f97316);
  box-shadow: 0 10px 24px rgba(251, 113, 133, 0.28);
  color: #200608;
}
.btn-start::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: inherit;
  background: linear-gradient(115deg, transparent 20%, rgba(255,255,255,0.35) 40%, transparent 60%);
  background-size: 220% 100%;
  background-position: 120% 0;
  opacity: 0;
  pointer-events: none;
}
.btn-start { position: relative; overflow: hidden; }
.btn-start:not(.is-running):hover::after { animation: btnSheen 1.1s ease; opacity: 1; }
@keyframes btnSheen {
  0% { background-position: 130% 0; opacity: 1; }
  100% { background-position: -30% 0; opacity: 0; }
}

.btn-secondary {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 14px 18px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  flex: 1;
  transition: transform 0.15s ease;
}
.btn-secondary:active { transform: scale(0.96); }

.timer-actions {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 340px;
}
.timer-actions .btn-pause { flex: 1; }
.timer-actions .btn-start.is-running { flex: 1.5; max-width: none; }

.btn-pause {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 14px 12px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: transform 0.15s ease, border-color 0.2s ease, color 0.2s ease, background 0.2s ease;
}
.btn-pause:active { transform: scale(0.95); }
.btn-pause.is-paused {
  border-color: var(--warning);
  background: rgba(251, 191, 36, 0.14);
  color: var(--warning);
}

.live-deliveries {
  display: flex;
  align-items: center;
  gap: 16px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 10px;
  animation: fadeSlideUp 0.3s ease;
}
.live-deliveries-count {
  display: flex;
  flex-direction: column;
  align-items: center;
  min-width: 96px;
}
.live-deliveries-num {
  font-size: 22px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.live-deliveries-label {
  font-size: 11px;
  color: var(--text-dim);
}
.stepper-btn {
  appearance: none;
  border: none;
  background: var(--surface);
  color: var(--text);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: transform 0.12s ease, background 0.15s ease;
}
.stepper-btn svg { width: 18px; height: 18px; }
.stepper-btn:active { transform: scale(0.88); }
.stepper-btn-add { background: var(--accent-soft); color: var(--accent); }

.btn-danger {
  appearance: none;
  border: 1px solid var(--danger);
  background: var(--danger-soft);
  color: var(--danger);
  padding: 12px 18px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}

/* Stat grid */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 12px 16px;
}
.stat { display: flex; flex-direction: column; gap: 2px; }
.stat-value {
  font-size: 19px;
  font-weight: 800;
  letter-spacing: -0.01em;
  font-variant-numeric: tabular-nums;
  display: inline-block;
}
.pulse { animation: statPulse 0.55s ease; }
@keyframes statPulse {
  0% { transform: scale(1); color: var(--text); }
  35% { transform: scale(1.14); color: var(--accent); }
  100% { transform: scale(1); color: var(--text); }
}
.stat-label {
  font-size: 12.5px;
  color: var(--text-dim);
}

.empty-hint {
  margin: 14px 0 0;
  font-size: 13.5px;
  color: var(--text-dim);
  text-align: center;
}

/* Session list */
.session-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
}
.session-item-main { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.session-item-time { font-size: 13px; color: var(--text-dim); }
.session-item-meta { font-size: 12.5px; color: var(--text-dim); }
.session-item-earnings { font-weight: 800; font-size: 15px; white-space: nowrap; }
.session-item-hourly { font-size: 12px; color: var(--accent); font-weight: 700; }
.session-item-del {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  width: 30px; height: 30px;
  border-radius: 8px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.session-item-del:active { background: var(--danger-soft); color: var(--danger); }
.session-item-del svg { width: 17px; height: 17px; }

.pending-item-countdown { font-size: 12px; color: var(--warning); font-weight: 700; }
.pending-item-countdown.is-ready { color: var(--accent); }
.pending-progress {
  height: 4px;
  width: 100%;
  background: var(--surface);
  border-radius: 999px;
  overflow: hidden;
  margin-top: 5px;
}
.pending-progress-fill {
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--warning), var(--accent));
  transition: width 1s linear;
}
.session-item.is-ready {
  border-color: var(--accent);
  animation: readyGlow 1.8s ease-in-out infinite;
}
@keyframes readyGlow {
  0%, 100% { box-shadow: 0 0 0 rgba(45, 212, 191, 0); }
  50% { box-shadow: 0 0 0 4px rgba(45, 212, 191, 0.12); }
}
.pending-item-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.btn-fill {
  appearance: none;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--accent);
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  white-space: nowrap;
}

/* Segmented control */
.segmented {
  display: flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px;
  gap: 4px;
}
.segmented-btn {
  flex: 1;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
}
.segmented-btn.is-active {
  background: var(--accent-soft);
  color: var(--accent);
}

/* Period / calendar nav */
.period-nav, .calendar-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.period-label, .calendar-label {
  font-weight: 800;
  font-size: 15px;
  text-transform: capitalize;
}
.icon-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
}
.icon-btn svg { width: 18px; height: 18px; }

.calendar-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11.5px;
  color: var(--text-dim);
  margin-bottom: 6px;
}
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}
.calendar-day {
  appearance: none;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  border-radius: 12px;
  padding: 6px 2px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  cursor: pointer;
  min-height: 52px;
}
.calendar-day.is-outside { color: var(--text-dim); opacity: 0.35; }
.calendar-day.is-today { border-color: var(--accent); }
.calendar-day.is-selected { background: var(--accent-soft); }
.calendar-day.is-in-week { background: rgba(56, 189, 248, 0.08); }
.calendar-day-num { font-size: 13px; font-weight: 700; }
.calendar-day-dot { width: 5px; height: 5px; border-radius: 50%; background: var(--accent); }
.calendar-day-amount { font-size: 9.5px; color: var(--accent); font-weight: 700; }

.day-detail h2 { text-transform: none; font-size: 16px; color: var(--text); }

/* Vehicle grid */
.vehicle-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
}
.vehicle-btn {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
  border-radius: var(--radius-md);
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 700;
  cursor: pointer;
}
.vehicle-btn svg { width: 30px; height: 30px; }
.vehicle-btn.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--text);
}
.vehicle-btn.is-active svg { color: var(--accent); }

/* Fields */
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field label { font-size: 13px; font-weight: 700; color: var(--text-dim); }
.field input, .field select {
  appearance: none;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  padding: 13px 14px;
  border-radius: var(--radius-sm);
  font-size: 16px;
  width: 100%;
  font-family: inherit;
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.field-hint { font-size: 12.5px; color: var(--text-dim); margin: -4px 0 0; }

/* Bottom nav */
.bottombar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(10px + var(--safe-bottom));
  z-index: 10;
}
.nav-btn {
  flex: 1;
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 6px 4px;
  border-radius: 12px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.nav-btn svg { width: 22px; height: 22px; }
.nav-btn.is-active { color: var(--accent); }

/* Sheet modal */
.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(4, 6, 12, 0.6);
  display: flex;
  align-items: flex-end;
  z-index: 20;
  backdrop-filter: blur(2px);
}
.sheet {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom: none;
  border-radius: 24px 24px 0 0;
  padding: 10px 20px calc(22px + var(--safe-bottom));
  max-width: 560px;
  margin: 0 auto;
  box-shadow: 0 -20px 40px rgba(0,0,0,0.4);
  animation: sheet-up 0.22s ease;
}
@keyframes sheet-up { from { transform: translateY(24px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }
.sheet-handle { width: 36px; height: 4px; background: var(--border); border-radius: 999px; margin: 4px auto 14px; }
.sheet h2 { margin: 0 0 4px; font-size: 17px; }
.sheet-duration { margin: 0 0 18px; color: var(--accent); font-weight: 700; font-size: 14px; }
.sheet-actions { display: flex; gap: 10px; margin-top: 6px; }
.sheet-actions .btn-start { flex: 1.4; }

/* Toast */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(90px + var(--safe-bottom));
  transform: translateX(-50%);
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 999px;
  font-size: 13.5px;
  font-weight: 700;
  box-shadow: var(--shadow);
  z-index: 30;
  animation: toast-in 0.2s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }

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