:root {
  --purple: #7c5cf0;
  --purple-dark: #6e2f8f;
  --purple-light: #9a5fb8;
  --ink: #1c1c28;
  --bg: #ffffff;
  --bg-page: #f4f4f8;
  --bg-soft: #f6f4fb;
  --bg-soft-2: #eee9f7;
  --sidebar-active: #ede8fd;
  --border: #e5e3ec;
  --muted: #6b6878;
  --red: #b3261e;
  --amber: #c58a1c;
  --amber-accent: #e8a13c;
  --green: #1e7d32;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(20, 15, 40, 0.04), 0 8px 24px rgba(20, 15, 40, 0.06);
}

[data-theme="dark"] {
  --ink: #f1eef8;
  --bg: #201c29;
  --bg-page: #16131d;
  --bg-soft: #221e2c;
  --bg-soft-2: #2a2434;
  --sidebar-active: #362d4d;
  --border: #35304333;
  --border: #3a3446;
  --muted: #b3aec2;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.35);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg-page);
  color: var(--ink);
}

.container { max-width: 960px; margin: 0 auto; padding: 0 20px; }

/* ---------- App shell: sidebar + content ---------- */
.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 240px;
  flex-shrink: 0;
  background: var(--bg);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
}
.sidebar-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 10px 24px;
  font-weight: 700;
  font-size: 1.05rem;
}
.sidebar-header img { height: 34px; width: auto; }

.sidebar-nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.sidebar-nav-group-label {
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--muted);
  padding: 16px 14px 4px;
}
.sidebar-nav-group-label:first-child { padding-top: 4px; }
.sidebar-nav button {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  font-weight: 600;
  font-size: 0.95rem;
  color: var(--ink);
  cursor: pointer;
}
.sidebar-nav button:hover { background: var(--bg-soft); }
.sidebar-nav button.active { background: var(--sidebar-active); color: var(--purple-dark); }

/* ---------- Content area: sticky top bar + scrolling main content ---------- */
.content-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 10px;
  padding: 18px 40px 0;
  background: var(--bg-page);
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 9px 16px;
  font-weight: 600;
  font-size: 0.85rem;
  color: var(--ink);
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-soft); }
.icon-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }
.icon-btn-danger { color: var(--red); }

.main-content { flex: 1; padding: 16px 40px 36px; min-width: 0; }
.main-content-inner { max-width: 1080px; }

.page-title h1 { margin: 0 0 4px; font-size: 2rem; }
.page-title p { margin: 0 0 28px; color: var(--muted); }

/* ---------- Cards ---------- */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 24px;
  margin-bottom: 18px;
}

.grid { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

/* ---------- Two-column content layout ---------- */
.two-col { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; align-items: start; }

/* ---------- Stat strip: one light container, no per-item boxes ---------- */
.stat-strip {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  overflow: hidden;
}
.stat-item {
  padding: 20px 22px;
  border-right: 1px solid var(--border);
}
.stat-item:last-child { border-right: none; }
.stat-item .stat-label { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 0.85rem; font-weight: 600; margin-bottom: 6px; }
.stat-item .stat-value { font-size: 1.5rem; font-weight: 800; line-height: 1.2; }

/* ---------- This-week strip ---------- */
.week-strip { display: flex; flex-wrap: wrap; gap: 10px; }
.week-day { width: 60px; text-align: center; }
.week-day .week-day-label { font-size: 0.75rem; color: var(--muted); margin-bottom: 4px; }
.week-day .week-day-pill {
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-soft-2);
  color: var(--muted);
  font-weight: 700;
}
.week-day.done .week-day-pill { background: var(--green); color: #fff; }
.week-day.today .week-day-pill { outline: 2px solid var(--purple); outline-offset: 2px; }

/* ---------- Admin: temp PIN banner ---------- */
.pin-banner { border-color: var(--purple-light); }
.pin-banner-head { display: flex; align-items: center; justify-content: space-between; }
.pin-banner-code {
  margin-top: 10px;
  font-size: 1.8rem;
  font-weight: 800;
  letter-spacing: 0.08em;
  color: var(--purple-dark);
}

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  border: none;
  font-weight: 700;
  cursor: pointer;
  text-decoration: none;
  font-size: 0.95rem;
}
.btn-primary { background: var(--purple); color: #fff; }
.btn-primary:hover { background: var(--purple-dark); }
.btn-secondary { background: var(--bg-soft-2); border: none; color: var(--purple-dark); border-radius: 999px; padding: 8px 16px; }
.btn-secondary.active-pill { background: var(--purple); color: #fff; }
.btn-block { display: block; width: 100%; text-align: center; }
.btn[disabled] { opacity: 0.4; cursor: not-allowed; }

/* ---------- Forms ---------- */
input, select, textarea {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  color: var(--ink);
  font-size: 1rem;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--purple); outline-offset: 1px; }
label { display: block; font-weight: 600; margin: 12px 0 6px; font-size: 0.9rem; }

.badge { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 700; }
.badge-green { background: #e4f4e6; color: var(--green); }
.badge-amber { background: #fdf0d5; color: var(--amber); }
.badge-red { background: #fbe4e2; color: var(--red); }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-size: 0.85rem; text-transform: uppercase; letter-spacing: 0.03em; }

.error-text { color: var(--red); font-weight: 600; }
.muted { color: var(--muted); }

/* ---------- Work history calendar ---------- */
.cal-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }

.cal-legend { display: flex; gap: 18px; margin-bottom: 12px; font-size: 0.85rem; color: var(--muted); }
.cal-swatch { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; vertical-align: middle; }
.cal-swatch.has-entries { background: var(--green); }
.cal-swatch.missing { background: var(--red); }

.cal-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  margin-bottom: 6px;
  text-align: center;
  font-weight: 600;
  color: var(--muted);
  font-size: 0.8rem;
}

.cal-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; }

.cal-day {
  aspect-ratio: 1 / 1;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg-soft);
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  padding: 4px;
}
.cal-day:hover { filter: brightness(0.96); }
.cal-day.empty-cell { background: transparent; border-color: transparent; cursor: default; }
.cal-day .cal-day-num { font-size: 0.95rem; }
.cal-day .cal-day-count { font-size: 0.65rem; font-weight: 600; margin-top: 2px; }

.cal-day.has-entries { background: rgba(30, 125, 50, 0.16); border-color: rgba(30, 125, 50, 0.35); color: var(--green); }
.cal-day.missing { background: rgba(179, 38, 30, 0.1); border-color: rgba(179, 38, 30, 0.28); color: var(--red); }
.cal-day.today { outline: 2px solid var(--purple); outline-offset: 2px; }
.cal-day.selected { box-shadow: 0 0 0 2px var(--purple-dark) inset; }

.cal-day-detail {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}
.cal-day-detail h4 { margin: 0 0 10px; }
.cal-day-detail-row { padding: 10px 0; border-bottom: 1px solid var(--border); }
.cal-day-detail-row:last-child { border-bottom: none; }

/* ---------- Announcement items ---------- */
.announcement-item {
  border-left: 4px solid var(--amber-accent);
  background: var(--bg-soft);
  border-radius: var(--radius-sm);
  padding: 16px 18px;
  margin-bottom: 12px;
}
.announcement-item .announcement-date { color: var(--muted); font-size: 0.85rem; margin-top: 4px; }
.announcement-item .btn-secondary { margin-top: 10px; }

.section-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.section-head h3 { margin: 0; }

/* ---------- Login ---------- */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-page);
}
#login-view { width: 100%; max-width: 380px; padding: 20px; }
#login-view .card { text-align: center; padding: 32px 28px; }
#login-view .login-logo { height: 88px; width: auto; margin-bottom: 14px; }
#login-view h1 { font-size: 1.5rem; margin: 0 0 4px; }
#login-view .login-subtitle { color: var(--muted); margin: 0 0 22px; }
#login-view form { text-align: left; }
#login-view label { text-transform: none; }

/* ---------- Mobile bottom nav ---------- */
.mobile-nav {
  display: none;
  position: fixed;
  bottom: 0; left: 0; right: 0;
  background: var(--bg);
  border-top: 1px solid var(--border);
  padding: 6px 0 max(6px, env(safe-area-inset-bottom));
  z-index: 50;
}
.mobile-nav-inner { display: flex; justify-content: space-around; }
.mobile-nav button {
  background: none; border: none; cursor: pointer;
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  color: var(--muted); font-size: 0.7rem; font-weight: 600;
  padding: 6px 8px;
}
.mobile-nav button svg { width: 20px; height: 20px; stroke: var(--muted); fill: none; stroke-width: 2; }
.mobile-nav button.active { color: var(--purple); }
.mobile-nav button.active svg { stroke: var(--purple); }

.checkbox-list { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
.checkbox-list label { display: flex; align-items: center; gap: 6px; font-weight: 400; margin: 0; text-transform: none; }
.checkbox-list input { width: auto; }

.hidden { display: none !important; }

@media (max-width: 820px) {
  .sidebar { display: none; }
  .topbar { padding: 14px 16px 0; }
  .icon-btn span { display: none; }
  .main-content { padding: 12px 16px 90px; }
  .mobile-nav { display: block; }
  .two-col { grid-template-columns: 1fr; }
  .stat-strip { grid-template-columns: repeat(2, 1fr); }
  .stat-item { border-right: none; border-bottom: 1px solid var(--border); }
  .stat-item:nth-child(odd) { border-right: 1px solid var(--border); }
  .stat-item:nth-last-child(-n+2) { border-bottom: none; }

  .card { padding: 16px; }
  .page-title h1 { font-size: 1.5rem; }
  .page-title p { margin-bottom: 18px; }

  .cal-day { border-radius: 8px; padding: 2px; }
  .cal-day .cal-day-num { font-size: 0.8rem; }
  .cal-day .cal-day-count { font-size: 0.55rem; }
  .cal-weekdays, .cal-grid { gap: 4px; }
  .cal-weekdays { font-size: 0.7rem; }
  .cal-legend { font-size: 0.78rem; gap: 12px; }
}

/* Comfortable tap targets everywhere on touch devices */
@media (pointer: coarse) {
  .btn, .icon-btn, .sidebar-nav button, .cal-day, input, select, textarea {
    min-height: 44px;
  }
}
