:root {
  --bg: #111111;
  --bg-elev: #171717;
  --surface: #1a1a1a;
  --card: #222222;
  --muted: #2a2a2a;
  --border: #3d3d3d;
  --text: #f2f2f2;
  --text-muted: #a8a8a8;
  --accent: #f2f2f2;
  --accent-dim: #2a2a2a;
  --on-accent: #111111;
  --danger: #f2f2f2;
  --danger-bg: #2a2a2a;
  --ring: #f2f2f2;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --space-6: 32px;
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --radius-xl: 20px;
  --icon: 22px;
  --touch: 44px;
  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.28);
  --nav-h: 72px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-size-adjust: 100%;
}
button, input { font: inherit; color: inherit; }
button {
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; display: block; }

:focus { outline: none; }
:focus-visible {
  outline: 2px solid var(--ring);
  outline-offset: 2px;
}

html.authed #login { display: none !important; }
html.authed #app { display: flex; }
#app { display: none; }
html.authed #app.hidden { display: none !important; }

.skip {
  position: absolute;
  left: -999px;
  top: 8px;
  z-index: 40;
  background: var(--accent);
  color: var(--on-accent);
  padding: 8px 12px;
  border-radius: 8px;
  font-weight: 700;
}
.skip:focus, .skip:focus-visible { left: 8px; }

.shell {
  width: min(100%, 560px);
  margin: 0 auto;
}

@media (min-width: 600px) {
  .login-card {
    background: var(--bg-elev);
    border: 1px solid var(--border);
    border-radius: 24px;
    padding: 32px;
    box-shadow: var(--shadow);
  }
}

@media (min-width: 768px) {
  .shell { width: min(100%, 720px); }
  .page-head .title { font-size: 26px; }
}
@media (min-width: 1024px) {
  .shell { width: min(100%, 960px); }
}

.login {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
}
.login-card {
  width: min(100%, 400px);
}
.brand {
  width: 56px;
  height: 56px;
  border-radius: var(--radius-lg);
  background: var(--card);
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  color: var(--text);
  margin-bottom: var(--space-4);
}
.kicker {
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  margin: 0 0 6px;
}
h1, .title {
  font-size: 28px;
  line-height: 1.2;
  font-weight: 700;
  letter-spacing: -0.02em;
  margin: 0 0 8px;
}
.sub {
  color: var(--text-muted);
  margin: 0 0 var(--space-5);
}
label {
  display: block;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 var(--space-2);
}
input {
  width: 100%;
  min-height: 52px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 14px;
}
#pin { letter-spacing: 0.24em; }
select {
  width: 100%;
  min-height: 52px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 0 14px;
  color: inherit;
}
input:focus-visible {
  border-color: var(--accent);
  outline-offset: 0;
}
.btn, .btn-secondary, .btn-ghost {
  width: 100%;
  min-height: 48px;
  border-radius: var(--radius-md);
  font-weight: 700;
  border: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: opacity 160ms var(--ease), background-color 160ms var(--ease);
}
.btn { background: var(--text); color: var(--bg); margin-top: var(--space-4); }
.btn:hover { background: #ffffff; }
.btn:active, .btn-secondary:active, .icon-btn:active, .chip:active, .day:active, .tabs button:active {
  opacity: 0.82;
}
.btn:disabled, .btn-secondary:disabled { opacity: 0.55; cursor: not-allowed; }
.btn-secondary {
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  margin-top: var(--space-3);
}
.btn-ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  margin-top: var(--space-3);
}
.error {
  color: var(--text);
  background: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin: 12px 0 0;
  font-size: 14px;
}
.install {
  margin-top: var(--space-5);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px 14px 12px;
}
.install summary {
  min-height: var(--touch);
  display: flex;
  align-items: center;
  font-weight: 600;
  cursor: pointer;
  list-style: none;
}
.install summary::-webkit-details-marker { display: none; }
.install ol {
  margin: 0 0 8px;
  padding-left: 20px;
  color: var(--text-muted);
}
.install strong { color: var(--text); }

.app {
  min-height: 100dvh;
  flex-direction: column;
}
.screen {
  flex: 1;
  padding: calc(16px + env(safe-area-inset-top)) 16px calc(var(--nav-h) + 16px + env(safe-area-inset-bottom));
}
.page-head { margin-bottom: var(--space-4); }
.page-head .title { margin-bottom: 6px; font-size: 22px; }
.meta {
  color: var(--text-muted);
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.pill {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
}
.pill.warn, .pill.bad { background: var(--muted); }

.toggle {
  display: flex;
  gap: 4px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 4px;
  margin-bottom: var(--space-5);
}
.toggle button {
  flex: 1;
  min-height: var(--touch);
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 600;
}
.toggle button.active {
  background: var(--text);
  color: var(--bg);
}

.list { display: grid; gap: 10px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 72px;
}
.avatar {
  width: 40px;
  height: 40px;
  border-radius: 20px;
  background: var(--muted);
  display: grid;
  place-items: center;
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
}
.name { font-weight: 650; }
.status { color: var(--text-muted); font-size: 13px; margin-top: 2px; }
.grow { flex: 1; min-width: 0; }
.badge {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--muted);
  color: var(--text);
  font-size: 13px;
  font-weight: 700;
  white-space: nowrap;
}
.day-codes {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--text);
  line-height: 1.2;
  text-align: center;
}

.page-head .nav { margin-bottom: 4px; }
.nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: var(--space-4);
}
.nav .title {
  flex: 1;
  text-align: center;
  font-size: 20px;
  line-height: 1.25;
}
.icon-btn {
  width: var(--touch);
  height: var(--touch);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.icon-btn svg { width: var(--icon); height: var(--icon); }
.head-actions { display: flex; gap: 8px; }

.week, .grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
}
.week {
  margin-bottom: 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 700;
  text-align: center;
}
.day {
  min-height: 44px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-weight: 650;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 8px 2px;
}
.day.today { border-width: 2px; border-color: var(--text); font-weight: 800; }
.day.selected { outline: 2px solid var(--text); outline-offset: 1px; }
.day.empty { background: transparent; border: 0; min-height: 44px; }
.day-num { font-size: 14px; }
.day-mark {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: transparent;
}
.day.has-remind .day-mark { background: var(--text); }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 10px 14px;
  margin: 14px 0 8px;
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 600;
}
.legend span { display: inline-flex; align-items: center; gap: 6px; }

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: var(--space-4);
}
.chip {
  min-height: var(--touch);
  padding: 0 14px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text-muted);
  font-weight: 600;
}
.chip.active {
  background: var(--text);
  border-color: var(--text);
  color: var(--bg);
}

.metrics {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: var(--space-4);
}
.metric {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
}
.metric b { display: block; font-size: 28px; letter-spacing: -0.03em; }
.metric span { color: var(--text-muted); font-size: 13px; }

.rep-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 20px;
}
.rep-card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 8px;
  text-align: center;
  min-height: 88px;
}
.rep-card b {
  display: block;
  font-size: 26px;
  letter-spacing: -0.03em;
  line-height: 1.1;
}
.rep-card .rep-code {
  display: block;
  font-weight: 700;
  margin-top: 6px;
}
.rep-card .rep-hint {
  display: block;
  color: var(--text-muted);
  font-size: 12px;
  margin-top: 2px;
}
.rep-who {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 14px;
}

.row {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 12px;
}
.row.selected, .sched-table tr.selected { outline: 2px solid var(--text); outline-offset: -2px; }
.help {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: var(--space-4);
  color: var(--text-muted);
  margin: var(--space-4) 0;
}

.group { margin-bottom: var(--space-5); }
.group-title {
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin: 0 0 8px;
}

.month-list { display: grid; gap: 8px; margin-top: var(--space-4); }
.month-row {
  display: grid;
  grid-template-columns: 72px 1fr;
  gap: 10px;
  align-items: center;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
  min-height: 48px;
}
.month-row.today { border-width: 2px; border-color: var(--text); }
.month-date { font-weight: 700; font-size: 13px; }
.month-shifts { display: flex; flex-wrap: wrap; gap: 6px; justify-content: flex-end; }

.tabs {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  border-top: 1px solid var(--border);
  padding-bottom: env(safe-area-inset-bottom);
  backdrop-filter: blur(12px);
  z-index: 20;
}
.tabs button {
  min-height: 64px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
}
.tabs button svg { width: 22px; height: 22px; }
.tabs button.active { color: var(--text); box-shadow: inset 0 2px 0 var(--text); }
.hidden { display: none !important; }

.banner {
  display: none;
  margin: 0 0 12px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  background: var(--muted);
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
}
.banner.show { display: block; }

.state {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 24px 16px;
  text-align: center;
}
.state p { color: var(--text-muted); margin: 0 0 16px; }
.state .btn { width: auto; min-width: 160px; margin: 0 auto; }

.skeleton { pointer-events: none; }
.skel {
  background: linear-gradient(90deg, var(--muted) 25%, var(--card) 50%, var(--muted) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s ease-in-out infinite;
  border-radius: 8px;
}
.skel-title { height: 28px; width: 70%; margin: 8px 0 16px; }
.skel-card { height: 72px; margin-bottom: 10px; }

.cal-split { display: grid; gap: 20px; }
@media (min-width: 1024px) {
  .cal-split { grid-template-columns: 1fr 1fr; align-items: start; }
  .sheet { align-items: center; }
  .sheet-card { border-radius: 16px; }
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(var(--nav-h) + env(safe-area-inset-bottom) + 12px);
  transform: translateX(-50%) translateY(12px);
  background: var(--card);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 10px 14px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 180ms var(--ease), transform 180ms var(--ease);
  z-index: 30;
  max-width: calc(100% - 32px);
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.popup {
  position: fixed;
  inset: 0;
  z-index: 80;
  background: rgba(0, 0, 0, 0.78);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(24px + env(safe-area-inset-top)) 20px calc(24px + env(safe-area-inset-bottom));
}
.popup[hidden] { display: none !important; }
.popup-card {
  width: min(100%, 400px);
  background: #f2f2f2;
  color: #111111;
  border-radius: 16px;
  padding: 24px 20px;
}
.popup-card .kicker { color: #444444; margin-bottom: 8px; }
.popup-card h2 {
  margin: 0 0 12px;
  font-size: 22px;
  line-height: 1.25;
  color: #111111;
}
.popup-card p#popup-body {
  margin: 0 0 20px;
  font-size: 16px;
  line-height: 1.45;
  color: #111111;
}
.popup-card .btn {
  margin-top: 0;
  background: #111111;
  color: #f2f2f2;
}

.sheet {
  position: fixed;
  inset: 0;
  z-index: 70;
  background: rgba(0, 0, 0, 0.72);
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 16px 16px calc(16px + env(safe-area-inset-bottom));
}
.sheet[hidden] { display: none !important; }
.sheet-card {
  width: min(100%, 480px);
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: 20px 20px 16px 16px;
  padding: 20px 16px 16px;
}
.sheet-card h2 {
  margin: 0 0 16px;
  font-size: 20px;
}
.field { margin-bottom: 14px; }
.field label { margin-bottom: 6px; }

.choices {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 8px 0 20px;
}
.choice {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  font-weight: 650;
}
.choice.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}
.setting { margin-bottom: 8px; }
.setting p {
  margin: 0;
  font-weight: 650;
}
.setting .hint {
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  margin: 2px 0 0;
}

.btn-compact {
  width: auto;
  min-width: 140px;
  margin-top: 12px;
}
.remind-list { display: grid; gap: 8px; margin: 12px 0; }
.remind-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 48px;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 8px 10px;
}
.remind-actions { display: flex; gap: 8px; flex-shrink: 0; }
.remind-item button,
.remind-actions button {
  width: auto;
  min-height: 44px;
  margin: 0;
  padding: 0 12px;
}

.sched-wrap {
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  margin-top: 4px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
}
.sched-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.sched-table th,
.sched-table td {
  padding: 12px 6px;
  text-align: center;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.sched-table th {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 700;
  background: var(--card);
}
.sched-table td:first-child,
.sched-table th:first-child {
  text-align: left;
  font-weight: 650;
  white-space: nowrap;
  padding-left: 12px;
}
.sched-table tbody tr { cursor: pointer; }
.sched-table tbody tr:active { background: var(--muted); }
.sched-table tr.today td { font-weight: 800; }
.sched-table tr.selected { background: var(--muted); }
.sched-table tbody tr:last-child td { border-bottom: 0; }
.jump-row {
  width: 100%;
  border: 0;
  background: transparent;
  padding: 0;
  text-align: inherit;
}

@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
@keyframes shimmer {
  0% { background-position: 100% 0; }
  100% { background-position: -100% 0; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

@media (max-width: 374px) {
  .title, h1 { font-size: 24px; }
  .day { min-height: 48px; }
  .badge { font-size: 12px; padding: 0 8px; }
}
