/* MaxLiberty — flat, touch-first, mobile-first */

:root {
  --primary: #2563EB;
  --on-primary: #FFFFFF;
  --primary-soft: #DBEAFE;
  --accent: #059669;
  --accent-soft: #D1FAE5;
  --warn: #B45309;
  --warn-soft: #FEF3C7;
  --danger: #DC2626;
  --danger-soft: #FEE2E2;
  --leave: #7C3AED;
  --leave-soft: #EDE9FE;
  --bg: #F4F6FB;
  --surface: #FFFFFF;
  --surface-2: #EEF2F9;
  --fg: #0F172A;
  --muted-fg: #55627A;
  --border: #DFE5F0;
  --navy: #0C1B33;
  --on-navy: #F4F7FC;
  --ring: #2563EB;
  --radius: 14px;
  --radius-sm: 10px;
  --nav-h: 64px;
  --font: "Plus Jakarta Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

[data-theme="dark"] {
  --primary: #5B8DF6;
  --on-primary: #071224;
  --primary-soft: #1B2C4F;
  --accent: #34D399;
  --accent-soft: #123B2E;
  --warn: #FBBF24;
  --warn-soft: #3A2C0D;
  --danger: #F87171;
  --danger-soft: #431418;
  --leave: #A78BFA;
  --leave-soft: #2A2145;
  --bg: #0A1220;
  --surface: #121C30;
  --surface-2: #1A2740;
  --fg: #E8EDF6;
  --muted-fg: #9AA8C0;
  --border: #26344F;
  --navy: #0C1B33;
  --on-navy: #F4F7FC;
  --ring: #5B8DF6;
}

* { box-sizing: border-box; }

/* Author display rules (flex/grid) must never beat the hidden attribute. */
[hidden] { display: none !important; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--fg);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

h1, h2, h3, p { margin: 0; }

button { font: inherit; color: inherit; }

svg { display: block; }

/* ---------- Layout shells ---------- */

#app, .gate-inner {
  max-width: 560px;
  margin: 0 auto;
}

#main {
  padding: 12px 12px calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 20px);
  display: block;
}

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

.app-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(12px + env(safe-area-inset-top, 0px)) 16px 12px;
  background: var(--navy);
  color: var(--on-navy);
}

.bar-anchor { width: 22px; height: 22px; color: #F5C64F; }
.bar-title { font-weight: 800; font-size: 18px; letter-spacing: 0.2px; }
.bar-badge {
  margin-left: auto;
  font-size: 13px;
  font-weight: 700;
  background: rgba(255, 255, 255, 0.14);
  padding: 4px 10px;
  border-radius: 999px;
}

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

.bottom-nav {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translateX(-50%);
  width: 100%;
  max-width: 560px;
  height: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  display: flex;
  background: var(--surface);
  border-top: 1px solid var(--border);
  z-index: 50;
}

.nav-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  background: none;
  border: 0;
  color: var(--muted-fg);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  transition: color 150ms ease;
}

.nav-btn svg { width: 24px; height: 24px; }
.nav-btn.is-active { color: var(--primary); }
.nav-btn:active { transform: scale(0.97); }

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

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}

.card-title { font-size: 17px; font-weight: 800; margin-bottom: 10px; }
.card-subtitle { font-size: 14px; font-weight: 700; margin: 16px 0 8px; color: var(--fg); }
.card-head-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
  flex-wrap: wrap;
}
.card-sub { font-size: 13px; color: var(--muted-fg); font-weight: 600; }

.stack { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

.hint { font-size: 13.5px; color: var(--muted-fg); margin-bottom: 10px; }
.helper { font-size: 12.5px; color: var(--muted-fg); margin-top: 4px; }
.fine-print { font-size: 12.5px; color: var(--muted-fg); margin: 10px 0; }

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

.field { display: flex; flex-direction: column; margin-bottom: 12px; flex: 1; min-width: 0; }
.field label { font-size: 13.5px; font-weight: 700; margin-bottom: 5px; }
.field-row { display: flex; gap: 10px; }

input[type="text"], input[type="email"], input[type="password"],
input[type="number"], input[type="date"], select {
  width: 100%;
  height: 48px;
  padding: 0 12px;
  font: inherit;
  font-size: 16px;
  color: var(--fg);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  transition: border-color 150ms ease;
  -webkit-appearance: none;
  appearance: none;
}

input:focus-visible, select:focus-visible {
  border-color: var(--ring);
}

input[aria-invalid="true"] { border-color: var(--danger); }

.field-error {
  color: var(--danger);
  font-size: 13px;
  font-weight: 600;
  margin-top: 4px;
}

.check-field {
  flex-direction: row;
  align-items: flex-start;
  gap: 10px;
}
.check-field input[type="checkbox"] {
  width: 22px; height: 22px;
  margin: 2px 0 0;
  accent-color: var(--primary);
  flex-shrink: 0;
}
.check-field label { font-size: 14px; font-weight: 500; margin: 0; }
.check-field a { color: var(--primary); font-weight: 700; }

.pass-wrap { position: relative; }
.pass-toggle {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: none;
  color: var(--primary);
  font-size: 13px;
  font-weight: 700;
  padding: 8px 10px;
  cursor: pointer;
  border-radius: 8px;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 18px;
  border: 0;
  border-radius: var(--radius-sm);
  font-weight: 700;
  font-size: 15.5px;
  cursor: pointer;
  transition: transform 120ms ease, background-color 150ms ease, opacity 150ms ease;
}
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.5; cursor: default; }
.btn svg { width: 20px; height: 20px; }

.btn-block { width: 100%; }
.btn-primary { background: var(--primary); color: var(--on-primary); }
.btn-secondary { background: var(--primary-soft); color: var(--primary); }
[data-theme="dark"] .btn-secondary { color: #BDD3FF; }
.btn-ghost { background: none; color: var(--primary); }
.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn + .btn { margin-top: 8px; }

.link-btn {
  border: 0; background: none; padding: 0;
  color: var(--primary); font-weight: 700; font-size: inherit;
  cursor: pointer; text-decoration: underline;
}

.icon-btn {
  width: 44px; height: 44px;
  display: inline-flex; align-items: center; justify-content: center;
  border: 0; background: var(--surface-2);
  border-radius: 12px; cursor: pointer;
  color: var(--fg);
  transition: transform 120ms ease;
}
.icon-btn:active { transform: scale(0.94); }
.icon-btn svg { width: 20px; height: 20px; }

:where(button, a, input, select):focus-visible {
  outline: 3px solid color-mix(in srgb, var(--ring) 55%, transparent);
  outline-offset: 1px;
}

/* ---------- Chips ---------- */

.chip-row { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.chip {
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--muted-fg);
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: all 150ms ease;
}
.chip.is-active {
  background: var(--primary);
  border-color: var(--primary);
  color: var(--on-primary);
}

/* ---------- Duty list rows ---------- */

.duty-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  text-align: left;
  width: 100%;
  transition: transform 120ms ease;
}
.duty-row:active { transform: scale(0.98); }

.duty-date-box {
  width: 48px;
  text-align: center;
  flex-shrink: 0;
  background: var(--primary);
  color: var(--on-primary);
  border-radius: 10px;
  padding: 5px 0;
  line-height: 1.15;
}
.duty-date-box .d { font-size: 18px; font-weight: 800; display: block; }
.duty-date-box .m { font-size: 11px; font-weight: 700; text-transform: uppercase; display: block; }
.duty-row.is-off .duty-date-box { background: var(--surface); color: var(--muted-fg); border: 1px solid var(--border); }

.duty-main { flex: 1; min-width: 0; }
.duty-main .t { font-weight: 700; font-size: 15px; }
.duty-main .s { font-size: 13px; color: var(--muted-fg); }
.duty-row.is-off .t { text-decoration: line-through; color: var(--muted-fg); }

.badge {
  display: inline-block;
  font-size: 11.5px;
  font-weight: 700;
  border-radius: 999px;
  padding: 2px 8px;
  margin-right: 4px;
  white-space: nowrap;
}
.badge-weekend { background: var(--surface-2); color: var(--muted-fg); border: 1px solid var(--border); }
.badge-holiday { background: var(--accent-soft); color: var(--accent); }
.badge-exc { background: var(--warn-soft); color: var(--warn); }
.badge-duty { background: var(--primary-soft); color: var(--primary); }
.badge-leave { background: var(--leave-soft); color: var(--leave); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }

/* ---------- Calendar ---------- */

.cal-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 10px;
}
.cal-title {
  border: 0; background: none;
  font-size: 17px; font-weight: 800;
  cursor: pointer; padding: 8px 12px; border-radius: 10px;
  color: var(--fg);
}

#cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 3px; }

.cal-wd {
  text-align: center;
  font-size: 11.5px;
  font-weight: 700;
  color: var(--muted-fg);
  padding: 4px 0;
  text-transform: uppercase;
}

.cal-cell {
  position: relative;
  aspect-ratio: 1 / 1.15;
  min-height: 44px;
  border: 0;
  border-radius: 10px;
  background: var(--surface);
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  padding: 4px 0 2px;
  gap: 2px;
  transition: transform 120ms ease;
}
.cal-cell:active { transform: scale(0.94); }
.cal-cell.is-outside { opacity: 0.35; }
.cal-cell.is-weekend { background: var(--surface-2); }
.cal-cell.is-holiday { background: var(--accent-soft); }
.cal-cell.is-today { box-shadow: inset 0 0 0 2px var(--primary); }

.cal-num {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  color: var(--fg);
}
.cal-cell.is-duty .cal-num { background: var(--primary); color: var(--on-primary); font-weight: 800; }
.cal-cell.is-exc-removed .cal-num {
  background: none;
  box-shadow: inset 0 0 0 2px var(--warn);
  color: var(--warn);
  text-decoration: line-through;
}
.cal-cell.is-exc-picked .cal-num { box-shadow: 0 0 0 2px var(--warn); }

.cal-dots { display: flex; gap: 3px; height: 6px; }
.dot {
  width: 6px; height: 6px;
  border-radius: 999px;
  display: inline-block;
  flex-shrink: 0;
}
.dot-duty { background: var(--primary); }
.dot-weekend { background: var(--muted-fg); }
.dot-holiday { background: var(--accent); }
.dot-exc { background: var(--warn); }
.dot-leave { background: var(--leave); }

.cal-leave-bar {
  position: absolute;
  bottom: 3px; left: 15%; right: 15%;
  height: 3px;
  border-radius: 2px;
  background: var(--leave);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  margin-top: 12px;
  font-size: 12.5px;
  color: var(--muted-fg);
  font-weight: 600;
}
.legend .lg { display: inline-flex; align-items: center; gap: 5px; }
.legend .dot { width: 8px; height: 8px; }

/* ---------- Notices ---------- */

.notice {
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13.5px;
  margin: 10px 0;
}
.notice-warn { background: var(--warn-soft); color: var(--warn); }
.notice-danger { background: var(--danger-soft); color: var(--danger); }
.notice-ok { background: var(--accent-soft); color: var(--accent); }
.notice-info { background: var(--primary-soft); color: var(--primary); }
[data-theme="dark"] .notice-info { color: #BDD3FF; }
.notice strong { font-weight: 800; }
.notice code { font-size: 12px; }

/* ---------- Leave / optimizer ---------- */

.proj-row { display: flex; gap: 12px; align-items: flex-end; margin-top: 12px; }
.proj-row output {
  flex: 1;
  font-size: 22px;
  font-weight: 800;
  padding-bottom: 10px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.sug-card {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  background: var(--surface-2);
}
.sug-card.is-top { border-color: var(--primary); }
.sug-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.sug-rank {
  background: var(--primary);
  color: var(--on-primary);
  font-weight: 800;
  font-size: 12px;
  border-radius: 999px;
  padding: 2px 9px;
}
.sug-range { font-weight: 800; font-size: 15px; }
.sug-stats {
  display: flex;
  gap: 16px;
  margin: 8px 0 6px;
  font-variant-numeric: tabular-nums;
}
.sug-stat .n { font-size: 20px; font-weight: 800; display: block; line-height: 1.2; }
.sug-stat .l { font-size: 11.5px; color: var(--muted-fg); font-weight: 600; }
.sug-why { font-size: 13px; color: var(--muted-fg); margin-bottom: 8px; }
.sug-actions { display: flex; gap: 8px; }
.sug-actions .btn { min-height: 40px; font-size: 14px; flex: 1; margin: 0; }

.man-stats { display: flex; gap: 14px; flex-wrap: wrap; margin: 12px 0 6px; }
.man-stat { min-width: 84px; }
.man-stat .n { font-size: 22px; font-weight: 800; display: block; font-variant-numeric: tabular-nums; }
.man-stat .l { font-size: 12px; color: var(--muted-fg); font-weight: 600; }

.plan-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.plan-main { flex: 1; min-width: 0; }
.plan-main .t { font-weight: 700; font-size: 14.5px; }
.plan-main .s { font-size: 12.5px; color: var(--muted-fg); }

/* ---------- Settings rows ---------- */

.hol-row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}
.hol-row label { flex: 1; font-size: 14.5px; font-weight: 600; cursor: pointer; }
.hol-row input[type="checkbox"] {
  width: 22px; height: 22px;
  accent-color: var(--primary);
  cursor: pointer;
}

.app-foot {
  text-align: center;
  padding: 8px 16px 16px;
  font-size: 13px;
  color: var(--muted-fg);
}
.app-foot a { color: var(--primary); font-weight: 700; }
.app-foot p { margin-top: 8px; }

/* ---------- Auth gate ---------- */

#gate { min-height: 100dvh; padding: 24px 16px calc(24px + env(safe-area-inset-bottom, 0px)); }

.gate-brand { text-align: center; padding: 20px 0 18px; }
.brand-anchor { width: 46px; height: 46px; margin: 0 auto 10px; color: var(--primary); }
.gate-brand h1 { font-size: 26px; font-weight: 800; }
.gate-tag { color: var(--muted-fg); font-size: 14.5px; margin-top: 2px; }

.gate-panel { margin-bottom: 14px; }
.gate-panel h2 { font-size: 20px; font-weight: 800; margin-bottom: 8px; }

.feature-list { margin: 10px 0; padding: 0 0 0 2px; list-style: none; }
.feature-list li {
  position: relative;
  padding: 5px 0 5px 28px;
  font-size: 14.5px;
}
.feature-list li::before {
  content: "";
  position: absolute;
  left: 0; top: 9px;
  width: 16px; height: 16px;
  border-radius: 999px;
  background: var(--accent-soft);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23059669' stroke-width='3.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M20 6 9 17l-5-5'/%3E%3C/svg%3E");
  background-size: 10px;
  background-position: center;
  background-repeat: no-repeat;
}

.price-box { text-align: center; margin: 6px 0 12px; }
.price { font-size: 44px; font-weight: 800; letter-spacing: -1px; }
.price-sub { display: block; color: var(--muted-fg); font-size: 13.5px; font-weight: 600; }

.gate-foot {
  text-align: center;
  font-size: 12.5px;
  color: var(--muted-fg);
  padding: 8px 12px;
}
.gate-foot a { color: var(--primary); font-weight: 700; }
.gate-foot p { margin-top: 8px; }

/* ---------- Bottom sheet ---------- */

#sheet-scrim {
  position: fixed;
  inset: 0;
  background: rgba(4, 10, 22, 0.55);
  z-index: 90;
  opacity: 1;
  transition: opacity 200ms ease;
}
#sheet-scrim.is-hiding { opacity: 0; }

#sheet {
  position: fixed;
  bottom: 0;
  left: 50%;
  transform: translate(-50%, 0);
  width: 100%;
  max-width: 560px;
  max-height: 82dvh;
  overflow-y: auto;
  background: var(--surface);
  border-radius: 18px 18px 0 0;
  padding: 10px 16px calc(20px + env(safe-area-inset-bottom, 0px));
  z-index: 100;
  transition: transform 220ms cubic-bezier(0.2, 0.9, 0.3, 1);
}
#sheet.is-hiding { transform: translate(-50%, 105%); }

.sheet-grip {
  width: 42px; height: 5px;
  border-radius: 3px;
  background: var(--border);
  margin: 2px auto 8px;
}
.sheet-x { position: absolute; top: 12px; right: 12px; }

.sheet-title { font-size: 18px; font-weight: 800; padding-right: 48px; margin-bottom: 2px; }
.sheet-sub { color: var(--muted-fg); font-size: 14px; margin-bottom: 12px; }
.sheet-section { margin-top: 14px; }
.sheet-section h4 { margin: 0 0 8px; font-size: 14px; font-weight: 700; }

.status-line {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 0;
  font-size: 14.5px;
  font-weight: 600;
}
.status-line .dot { width: 9px; height: 9px; }

textarea {
  width: 100%;
  min-height: 64px;
  padding: 10px 12px;
  font: inherit;
  font-size: 15px;
  color: var(--fg);
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  resize: vertical;
  outline: none;
}
textarea:focus-visible { border-color: var(--ring); }

/* ---------- Exception log ---------- */

.ex-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.ex-icon {
  width: 34px; height: 34px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--warn-soft);
  color: var(--warn);
  flex-shrink: 0;
}
.ex-icon svg { width: 18px; height: 18px; }
.ex-main { flex: 1; min-width: 0; }
.ex-main .t { font-weight: 700; font-size: 14.5px; }
.ex-main .s { font-size: 13px; color: var(--muted-fg); overflow-wrap: anywhere; }
.duty-main .t, .duty-main .s,
.ex-main .t, .ex-main .s,
.plan-main .t, .plan-main .s { display: block; }

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

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom, 0px) + 16px);
  transform: translateX(-50%);
  background: var(--navy);
  color: var(--on-navy);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  z-index: 200;
  max-width: min(92vw, 480px);
  text-align: center;
  transition: opacity 200ms ease;
}
#toast.toast-error { background: var(--danger); color: #fff; }

.empty-note {
  text-align: center;
  color: var(--muted-fg);
  font-size: 14px;
  padding: 14px 8px;
}

/* ---------- Static pages (terms/privacy) ---------- */

.page-wrap { max-width: 680px; margin: 0 auto; padding: 20px 16px 60px; }
.page-wrap h1 { font-size: 26px; margin: 18px 0 6px; }
.page-wrap h2 { font-size: 18px; margin: 22px 0 6px; }
.page-wrap p, .page-wrap li { font-size: 15px; color: var(--fg); margin: 8px 0; }
.page-wrap .meta { color: var(--muted-fg); font-size: 13.5px; }
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--primary);
  font-weight: 700;
  text-decoration: none;
  min-height: 44px;
}

/* ---------- Misc ---------- */

@media (min-width: 560px) {
  #main { padding-left: 0; padding-right: 0; }
}

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