:root {
  --bg: #f2f4f8;
  --card: #ffffff;
  --ink: #14171f;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --present: #16a34a;
  --present-bg: #dcfce7;
  --absent: #dc2626;
  --absent-bg: #fee2e2;
  --unmarked-bg: #e5e7eb;
  --border: #e5e7eb;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --card: #161d2e;
    --ink: #f3f4f6;
    --muted: #9aa4b2;
    --accent: #3b82f6;
    --present: #22c55e;
    --present-bg: rgba(34, 197, 94, 0.16);
    --absent: #f87171;
    --absent-bg: rgba(248, 113, 113, 0.16);
    --unmarked-bg: #232c40;
    --border: #232c40;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.4), 0 4px 12px rgba(0, 0, 0, 0.3);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: contain;
}
#app { display: flex; flex-direction: column; min-height: 100vh; }

button { font-family: inherit; }
input { font-family: inherit; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 10;
  padding: calc(14px + var(--safe-top)) 20px 14px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.topbar h1 { font-size: 20px; font-weight: 700; margin: 0; letter-spacing: -0.01em; }
.topbar .user-chip {
  font-size: 13px;
  color: var(--muted);
  display: flex;
  align-items: center;
  gap: 8px;
}
.icon-btn {
  border: none;
  background: var(--card);
  color: var(--ink);
  width: 34px;
  height: 34px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
}

main {
  flex: 1;
  padding: 16px 16px calc(96px + var(--safe-bottom));
  max-width: 560px;
  width: 100%;
  margin: 0 auto;
}

.card {
  background: var(--card);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 18px;
  margin-bottom: 14px;
}

.section-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin: 22px 4px 10px;
}
.section-title:first-child { margin-top: 4px; }

.worker-card { display: flex; flex-direction: column; gap: 12px; }
.worker-head { display: flex; align-items: center; justify-content: space-between; }
.worker-name { font-size: 17px; font-weight: 700; }
.worker-role { font-size: 12px; color: var(--muted); margin-top: 2px; }

.shift-row { display: flex; gap: 10px; }
.shift-block {
  flex: 1;
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.shift-icon { font-size: 22px; margin-bottom: 4px; line-height: 1; }
.shift-label { font-size: 12px; color: var(--muted); margin-bottom: 10px; font-weight: 700; text-align: center; text-transform: uppercase; letter-spacing: 0.04em; }
.shift-buttons { display: flex; flex-direction: column; gap: 8px; width: 100%; }

.pill-btn {
  flex: 1;
  padding: 11px 8px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: transparent;
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  transition: transform 0.08s ease;
}
.pill-btn:active { transform: scale(0.96); }
.pill-btn.present.active { background: var(--present-bg); color: var(--present); border-color: var(--present); }
.pill-btn.absent.active { background: var(--absent-bg); color: var(--absent); border-color: var(--absent); }

.tabbar {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  display: flex;
  background: color-mix(in srgb, var(--card) 92%, transparent);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
  padding-bottom: var(--safe-bottom);
  z-index: 10;
}
.tab-btn {
  flex: 1;
  border: none;
  background: none;
  color: var(--muted);
  padding: 10px 4px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 11px;
  font-weight: 600;
}
.tab-btn .tab-icon { font-size: 21px; line-height: 1; }
.tab-btn.active { color: var(--accent); }

.worker-tabs {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
  margin-bottom: 14px;
  scrollbar-width: none;
}
.worker-tabs::-webkit-scrollbar { display: none; }
.worker-chip {
  flex-shrink: 0;
  padding: 9px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--card);
  color: var(--ink);
  font-size: 13.5px;
  font-weight: 600;
  white-space: nowrap;
}
.worker-chip.active { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.month-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}
.month-nav .month-label { font-size: 17px; font-weight: 700; }
.month-nav-btn {
  border: none;
  background: var(--card);
  color: var(--ink);
  width: 36px;
  height: 36px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  font-size: 16px;
}

.calendar { }
.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  text-align: center;
  font-size: 11px;
  color: var(--muted);
  font-weight: 700;
  margin-bottom: 6px;
}
.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }
.cal-cell {
  aspect-ratio: 1;
  border-radius: 12px;
  border: none;
  background: var(--card);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  position: relative;
  color: var(--ink);
}
.cal-cell.empty { background: transparent; box-shadow: none; }
.cal-cell.today { box-shadow: inset 0 0 0 2px var(--accent); }
.cal-cell .day-num { font-size: 13px; font-weight: 600; }
.cal-dots { display: flex; gap: 3px; }
.dot { width: 7px; height: 7px; border-radius: 999px; background: var(--unmarked-bg); }
.dot.present { background: var(--present); }
.dot.absent { background: var(--absent); }
.cal-cell.full-present { background: var(--present-bg); }
.cal-cell.full-absent { background: var(--absent-bg); }

.summary-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 6px; }
.stat-tile { background: var(--card); border-radius: 14px; padding: 14px; box-shadow: var(--shadow); }
.stat-tile .stat-label { font-size: 11.5px; color: var(--muted); font-weight: 600; margin-bottom: 4px; }
.stat-tile .stat-value { font-size: 20px; font-weight: 700; }
.stat-tile.wide { grid-column: span 2; }
.stat-tile.highlight { background: var(--accent); color: var(--accent-ink); }
.stat-tile.highlight .stat-label { color: color-mix(in srgb, var(--accent-ink) 80%, transparent); }

.field { margin-bottom: 14px; }
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 6px; }
.field input, .field select {
  width: 100%;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--ink);
  font-size: 16px;
}

.btn {
  width: 100%;
  padding: 14px;
  border-radius: 14px;
  border: none;
  background: var(--accent);
  color: var(--accent-ink);
  font-size: 16px;
  font-weight: 700;
}
.btn:active { opacity: 0.85; }
.btn.secondary { background: var(--unmarked-bg); color: var(--ink); }
.btn.danger { background: var(--absent-bg); color: var(--absent); }

.center-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}
.auth-box { width: 100%; max-width: 380px; }
.auth-title { font-size: 26px; font-weight: 800; text-align: center; margin-bottom: 6px; letter-spacing: -0.02em; }
.auth-subtitle { font-size: 14px; color: var(--muted); text-align: center; margin-bottom: 28px; }
.error-msg { color: var(--absent); font-size: 13.5px; margin: -4px 0 14px; text-align: center; }
.divider { height: 1px; background: var(--border); margin: 22px 0; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: 6px; }

.sheet-backdrop {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4); z-index: 20;
  display: flex; align-items: flex-end;
}
.sheet {
  background: var(--card);
  width: 100%;
  border-radius: 22px 22px 0 0;
  padding: 10px 20px calc(24px + var(--safe-bottom));
  max-height: 80vh;
  overflow-y: auto;
}
.sheet-handle { width: 36px; height: 5px; border-radius: 999px; background: var(--border); margin: 8px auto 16px; }
.sheet-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }

.worker-list-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 0; border-bottom: 1px solid var(--border);
}
.worker-list-item:last-child { border-bottom: none; }
.link-btn { border: none; background: none; color: var(--accent); font-weight: 600; font-size: 14px; }

.marked-by { font-size: 11.5px; color: var(--muted); margin-top: 2px; }

.loading-spin {
  width: 28px; height: 28px; border-radius: 999px;
  border: 3px solid var(--border); border-top-color: var(--accent);
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
