:root {
  --bg: #04140f;
  --bg-2: #0a221a;
  --card: #0e2a20;
  --card-2: #11332705;
  --line: #1d4a3a;
  --text: #eaf5f0;
  --muted: #8fb5a6;
  --accent: #10b981;
  --accent-2: #059669;
  --ot: #f5a524;
  --danger: #f87171;
  --radius: 16px;
  --shadow: 0 6px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

html { color-scheme: dark; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif;
  background: radial-gradient(120% 60% at 50% 0%, #0a2a20 0%, var(--bg) 60%);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
  min-height: 100vh;
}

/* ---------- App bar + tabs ---------- */
.appbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(env(safe-area-inset-top) + 12px) 16px 12px;
  background: rgba(4, 20, 15, 0.85);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: 700;
  letter-spacing: 0.2px;
  font-size: 18px;
}
.brand img { border-radius: 6px; }

.tabs {
  display: flex;
  gap: 6px;
  padding: 12px 16px 4px;
  max-width: 640px;
  margin: 0 auto;
}
.tab {
  flex: 1;
  padding: 10px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.tab.is-active {
  background: var(--accent-2);
  border-color: var(--accent-2);
  color: #fff;
}

main {
  max-width: 640px;
  margin: 0 auto;
  padding: 12px 16px 48px;
}

/* ---------- Hero / current period ---------- */
.hero {
  background: linear-gradient(160deg, #0f3b2c 0%, #0b2a20 100%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 16px;
}
.hero .label { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: 0.6px; }
.hero .net { font-size: 40px; font-weight: 800; line-height: 1.1; margin: 4px 0 2px; }
.hero .net small { font-size: 15px; font-weight: 600; color: var(--muted); }
.hero .gross-line { color: var(--muted); font-size: 14px; margin-bottom: 14px; }
.hero .gross-line b { color: var(--text); font-weight: 700; }

.stat-row { display: flex; gap: 8px; }
.stat {
  flex: 1;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px;
  text-align: center;
}
.stat .v { font-size: 18px; font-weight: 700; }
.stat .v.ot { color: var(--ot); }
.stat .k { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.4px; }

.breakdown {
  margin-top: 12px;
  border-top: 1px dashed var(--line);
  padding-top: 10px;
}
.breakdown .ln { display: flex; justify-content: space-between; font-size: 14px; padding: 3px 0; color: var(--muted); }
.breakdown .ln b { color: var(--text); font-weight: 600; }
.breakdown .ln.net { color: var(--accent); font-weight: 700; }
.breakdown .ln.net b { color: var(--accent); }
.breakdown .ln.sub { border-top: 1px solid var(--line); margin-top: 4px; padding-top: 7px; }

.stat-row.four .stat { padding: 8px 4px; }
.stat-row.four .stat .v { font-size: 15px; }
.stat-row.four .stat .k { font-size: 10px; }

/* per-cycle / per-week breakdown in the shifts list */
.cycle-stats {
  font-size: 12.5px;
  color: var(--muted);
  padding: 10px 14px;
  border-bottom: 1px solid rgba(29, 74, 58, 0.5);
}
.cycle-stats b { color: var(--text); }
.cycle-stats .ot { color: var(--ot); font-weight: 700; }
.week-block { border-bottom: 1px solid rgba(29, 74, 58, 0.5); }
.week-block:last-of-type { border-bottom: 0; }
.wk-sub {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  padding: 10px 14px 2px;
  font-weight: 700;
  font-size: 14px;
}
.wk-sub b { color: var(--accent); }
.wk-stats { font-size: 12px; color: var(--muted); padding: 0 14px 8px; }
.week-card .breakdown { margin: 0; padding: 12px 14px; border-top: 1px solid var(--line); }
.preview .muted { color: var(--muted); font-weight: 400; }

/* ---------- Goal ---------- */
.goal {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 16px;
}
.goal .top { display: flex; justify-content: space-between; align-items: baseline; }
.goal .top .name { font-weight: 700; }
.goal .top .pct { color: var(--accent); font-weight: 700; }
.bar { height: 12px; background: rgba(255,255,255,0.06); border-radius: 999px; overflow: hidden; margin: 10px 0 8px; }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, var(--accent-2), var(--accent)); border-radius: 999px; }
.goal .sub { font-size: 13px; color: var(--muted); display: flex; justify-content: space-between; }
.goal .sub b { color: var(--text); }

/* ---------- Sections / shifts ---------- */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 8px 2px 12px;
}
.section-head h2 { font-size: 18px; margin: 0; }

.week-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 14px;
  overflow: hidden;
}
.week-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: rgba(255,255,255,0.03);
  border-bottom: 1px solid var(--line);
}
.week-head .wk { font-weight: 700; font-size: 15px; }
.week-head .wk small { display: block; color: var(--muted); font-weight: 500; font-size: 12px; }
.week-head .wk-net { text-align: right; }
.week-head .wk-net .v { font-weight: 800; font-size: 17px; }
.week-head .wk-net .k { font-size: 11px; color: var(--muted); }

.shift {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid rgba(29, 74, 58, 0.5);
  cursor: pointer;
}
.shift:last-child { border-bottom: 0; }
.shift:active { background: rgba(255,255,255,0.03); }
.shift .day {
  width: 44px;
  text-align: center;
  flex-shrink: 0;
}
.shift .day .dow { font-size: 12px; color: var(--muted); text-transform: uppercase; }
.shift .day .dnum { font-size: 20px; font-weight: 800; line-height: 1; }
.shift .mid { flex: 1; min-width: 0; }
.shift .mid .time { font-size: 14px; font-weight: 600; }
.shift .mid .meta { font-size: 12px; color: var(--muted); }
.shift .mid .meta .ot-badge { color: var(--ot); font-weight: 700; }
.shift .mid .note { font-size: 12px; color: var(--muted); font-style: italic; }
.shift .pay { text-align: right; flex-shrink: 0; }
.shift .pay .amt { font-weight: 700; }
.shift .pay .hrs { font-size: 12px; color: var(--muted); }

/* ---------- Empty states ---------- */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 28px 16px;
  background: var(--card);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
}
.empty .big { font-size: 40px; margin-bottom: 6px; }
.empty a { color: var(--accent); cursor: pointer; text-decoration: underline; }

/* ---------- Forms ---------- */
form fieldset {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin: 0 0 16px;
  padding: 14px;
  background: var(--card);
}
form legend { font-weight: 700; padding: 0 6px; color: var(--text); }
label { display: block; font-size: 14px; color: var(--muted); margin-bottom: 12px; }
label:last-child { margin-bottom: 0; }
small { display: block; color: var(--muted); font-size: 12px; margin-top: 4px; }
small.hint { margin: 0 0 12px; }

input, select {
  width: 100%;
  margin-top: 6px;
  padding: 11px 12px;
  font-size: 16px; /* >=16px avoids iOS zoom */
  background: var(--bg-2);
  border: 1px solid var(--line);
  border-radius: 12px;
  color: var(--text);
}
input:focus, select:focus { outline: 2px solid var(--accent-2); border-color: var(--accent-2); }

.with-prefix { position: relative; }
.with-prefix .prefix {
  position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  color: var(--muted); font-size: 16px; pointer-events: none;
}
.with-prefix input { padding-left: 26px; }

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

.deduction-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.deduction-row input.dname { flex: 1; margin-top: 0; }
.deduction-row .pct-wrap { position: relative; width: 96px; }
.deduction-row .pct-wrap input { margin-top: 0; padding-right: 26px; }
.deduction-row .pct-wrap .suffix { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); pointer-events: none; }
.deduction-row .del { flex-shrink: 0; }

.row-btns { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Buttons ---------- */
button { font-family: inherit; cursor: pointer; }
.primary {
  background: var(--accent-2);
  color: #fff;
  border: 0;
  border-radius: 999px;
  padding: 10px 16px;
  font-weight: 700;
  font-size: 14px;
}
.primary:active { background: var(--accent); }
.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 9px 14px;
  font-weight: 600;
  font-size: 14px;
}
.danger {
  background: transparent;
  color: var(--danger);
  border: 1px solid rgba(248, 113, 113, 0.4);
  border-radius: 999px;
  padding: 9px 14px;
  font-weight: 600;
  font-size: 14px;
}
.small { padding: 8px 12px; font-size: 13px; }
.del-x {
  width: 38px; height: 38px; flex-shrink: 0;
  border-radius: 10px; border: 1px solid rgba(248,113,113,0.4);
  background: transparent; color: var(--danger); font-size: 18px; line-height: 1;
}

/* ---------- Dialog ---------- */
dialog#shift-dialog {
  width: min(440px, calc(100vw - 24px));
  border: 1px solid var(--line);
  border-radius: 20px;
  background: var(--bg-2);
  color: var(--text);
  padding: 18px;
  box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(2px); }
dialog h3 { margin: 0 0 14px; }
.preview {
  background: rgba(16, 185, 129, 0.1);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 14px;
  margin: 4px 0 14px;
  min-height: 20px;
}
.preview .amt { font-weight: 800; color: var(--accent); }
.preview .ot { color: var(--ot); font-weight: 700; }
.dialog-actions { display: flex; align-items: center; gap: 8px; margin: 0; padding: 0; }
.dialog-actions .spacer { flex: 1; }

.footnote { text-align: center; color: var(--muted); font-size: 12px; margin: 8px 0 0; }

/* ---------- Lock screen ---------- */
body.locked { overflow: hidden; }
body.locked .appbar, body.locked .tabs, body.locked main { visibility: hidden; }
.auth-screen {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px calc(16px + env(safe-area-inset-left)) calc(24px + env(safe-area-inset-bottom));
  background: radial-gradient(120% 70% at 50% 0%, #0d3a2c 0%, var(--bg) 65%);
}
.auth-card {
  width: min(380px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 24px 20px;
  box-shadow: var(--shadow);
}
.auth-brand { text-align: center; margin-bottom: 18px; }
.auth-brand img { border-radius: 14px; box-shadow: var(--shadow); }
.auth-brand h1 { margin: 10px 0 2px; font-size: 24px; letter-spacing: 0.2px; }
.auth-tag { margin: 0; color: var(--muted); font-size: 13px; }
.auth-h2 { margin: 0 0 4px; font-size: 18px; }
.auth-sub { margin: 0 0 16px; color: var(--muted); font-size: 13px; }
.auth-form label { color: var(--muted); }
.block { display: block; width: 100%; margin-top: 8px; padding: 13px; font-size: 15px; }

/* password field with show/hide toggle */
.pw-field { position: relative; }
.pw-field input { padding-right: 48px; }
.pw-toggle {
  position: absolute;
  right: 6px;
  top: 50%;
  transform: translateY(-50%);
  width: 38px;
  height: 38px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--muted);
}
.pw-toggle:active { color: var(--text); background: rgba(255,255,255,0.05); }
/* nudge for the label-wrapped inputs (label adds margin-top:6px to input) */
.pw-field input { margin-top: 6px; }
.pw-field .pw-toggle { top: calc(50% + 3px); }

/* ---------- Toasts ---------- */
#toast-host {
  position: fixed;
  left: 50%;
  top: calc(env(safe-area-inset-top) + 12px);
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  width: min(440px, calc(100vw - 24px));
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 12px 14px;
  border-radius: 12px;
  font-size: 14px;
  font-weight: 600;
  color: #fff;
  background: #1f2937;
  border: 1px solid rgba(255,255,255,0.12);
  box-shadow: var(--shadow);
  opacity: 0;
  transform: translateY(-10px);
  transition: opacity 0.2s ease, transform 0.2s ease;
}
.toast.in { opacity: 1; transform: translateY(0); }
.toast.error { background: #7f1d1d; border-color: rgba(248,113,113,0.5); }
.toast.success { background: #064e3b; border-color: rgba(16,185,129,0.5); }
.toast.info { background: #1e3a34; border-color: var(--line); }
