:root {
  --ink: #1c1917;
  --muted: #6b6259;
  --paper: #f4efe6;
  --card: #fffaf3;
  --line: #e4d9c8;
  --home: #1f4e5f;
  --home-soft: #d7e6ea;
  --dgroup: #b45309;
  --dgroup-soft: #f3ddc8;
  --warn: #9f1239;
  --gold: #c4a574;
  --focus: #1f4e5f;
  --shadow: 0 12px 40px rgba(28, 25, 23, 0.08);
  --radius: 18px;
}

* { box-sizing: border-box; }
html, body { margin: 0; min-height: 100%; }
body {
  font-family: "Source Sans 3", "Segoe UI", sans-serif;
  color: var(--ink);
  background:
    radial-gradient(1200px 500px at 10% -10%, #efe4cf 0%, transparent 50%),
    var(--paper);
  line-height: 1.55;
}

h1, h2, h3, .brand {
  font-family: Fraunces, Georgia, serif;
  font-weight: 640;
  letter-spacing: -0.02em;
}

a { color: inherit; }
button, input { font: inherit; }

.app {
  display: grid;
  grid-template-columns: 260px 1fr;
  min-height: 100vh;
}

.sidebar {
  padding: 28px 22px;
  border-right: 1px solid var(--line);
  background: rgba(255, 250, 243, 0.7);
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.brand-kicker {
  margin: 0;
  text-transform: uppercase;
  letter-spacing: 0.14em;
  font-size: 0.72rem;
  color: var(--muted);
  font-weight: 600;
}
.brand { margin: 0 0 4px; font-size: 1.8rem; }
.brand-sub { margin: 0 0 18px; color: var(--muted); font-size: 0.95rem; }
.sidebar nav { display: flex; flex-direction: column; gap: 6px; }
.sidebar nav a {
  text-decoration: none;
  padding: 10px 12px;
  border-radius: 12px;
  color: var(--muted);
  min-height: 44px;
  display: flex;
  align-items: center;
}
.sidebar nav a.is-active,
.sidebar nav a:hover {
  background: var(--home);
  color: #fff;
}
.sidebar-note { margin-top: auto; color: var(--muted); font-size: 0.9rem; }
.demo-badge {
  display: inline-block;
  margin: 0 0 12px;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--gold);
  color: var(--ink);
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.logout { margin-top: 12px; color: var(--muted); font-size: 0.9rem; }

.main { padding: 28px 32px 56px; }
.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 16px;
  margin-bottom: 24px;
}
.topbar h2 { margin: 0; font-size: 2rem; }
.period-label { margin: 4px 0 0; color: var(--muted); }
.period {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: end;
}
.period label { font-size: 0.85rem; color: var(--muted); display: flex; flex-direction: column; gap: 4px; }
.period input, .period button, .login-card input, .login-card button {
  border: 1px solid var(--line);
  background: var(--card);
  border-radius: 12px;
  padding: 10px 12px;
}
.period button, .login-card button {
  background: var(--home);
  color: #fff;
  border: 0;
  cursor: pointer;
  min-height: 44px;
  padding: 10px 16px;
}
.period button:focus-visible,
.login-card button:focus-visible,
.sidebar nav a:focus-visible,
input:focus-visible {
  outline: 3px solid var(--gold);
  outline-offset: 2px;
}

.kpis {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}
.kpi {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow);
}
.kpi-home { border-top: 3px solid var(--home); }
.kpi-d { border-top: 3px solid var(--dgroup); }
.kpi-warn { border-top: 3px solid var(--warn); }
.kpi-label { margin: 0; color: var(--muted); font-size: 0.86rem; font-weight: 600; }
.kpi-value { margin: 6px 0 0; font-family: Fraunces, serif; font-size: 2.1rem; line-height: 1.1; }
.kpi-value span { font-size: 1.1rem; color: var(--muted); }
.kpi-meta { margin: 6px 0 0; color: var(--muted); font-size: 0.88rem; }

.charts {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 18px;
}
.charts-2 { grid-template-columns: 1.4fr 0.8fr; }
.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
}
.charts .panel {
  margin: 0;
  display: flex;
  flex-direction: column;
}
.chart-box {
  position: relative;
  height: 240px;
  width: 100%;
  flex: 0 0 240px;
}
.chart-box-pie { height: 240px; flex-basis: 240px; }
.chart-box canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}
.panel h3 { margin: 0 0 12px; font-size: 1.15rem; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); font-size: 0.95rem; }
th { color: var(--muted); font-weight: 600; }
.empty { color: var(--muted); margin: 0; }

.calendar-panel { margin-top: 8px; }
.calendar-lede { margin: -4px 0 12px; color: var(--muted); font-size: 0.9rem; }
.calendar-wrap { overflow: auto; max-height: 520px; }
.calendar-table { min-width: 640px; }
.calendar-table tr.is-past td { color: var(--muted); }
.calendar-table tr.is-current td {
  background: var(--home-soft);
  color: var(--ink);
  font-weight: 600;
}
.cal-badge {
  display: inline-block;
  margin-left: 8px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--home);
  color: #fff;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  vertical-align: middle;
}
.cal-kind {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
}
.cal-kind-study { background: var(--home-soft); color: var(--home); }
.cal-kind-communion { background: var(--dgroup-soft); color: var(--dgroup); }
.cal-kind-special { background: #efe4cf; color: var(--ink); }
.cal-meta { color: var(--muted); font-weight: 400; }
.calendar-table a { color: var(--home); }

.week-lesson {
  border-top: 3px solid var(--home);
  margin-bottom: 18px;
}
.week-lesson-kicker {
  margin: 0 0 6px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 0.75rem;
  font-weight: 700;
  color: var(--home);
}
.week-lesson-date {
  margin: 0 0 6px;
  color: var(--muted);
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}
.week-lesson h3 {
  margin: 0 0 10px;
  font-size: 1.45rem;
  line-height: 1.25;
}
.week-lesson-meta,
.week-lesson-refs {
  margin: 0 0 10px;
}
.week-lesson-refs a { color: var(--home); font-weight: 600; }
.week-lesson-label {
  display: block;
  margin: 0 0 4px;
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}
.week-lesson-notes {
  margin-top: 8px;
  padding: 12px 14px;
  border-radius: 14px;
  background: var(--home-soft);
}
.week-lesson-notes p:last-child { margin: 0; }
.name-pills {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}
.name-pills li {
  margin: 0;
  padding: 8px 14px;
  border-radius: 999px;
  background: var(--home-soft);
  color: var(--home);
  font-weight: 600;
  font-size: 0.95rem;
}
.leaders-d .name-pills li {
  background: var(--dgroup-soft);
  color: var(--dgroup);
}

.login-body {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(440px, 100%);
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 36px 32px;
  box-shadow: var(--shadow);
}
.eyebrow { text-transform: uppercase; letter-spacing: 0.16em; font-size: 0.75rem; color: var(--muted); margin: 0; font-weight: 600; }
.login-card h1 { margin: 8px 0 8px; }
.lede { color: var(--muted); margin-top: 0; }
.login-card form { display: flex; flex-direction: column; gap: 8px; margin-top: 20px; }
.login-card label { font-weight: 600; }
.login-card select {
  width: 100%;
  min-height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  padding: 8px 12px;
  background: #fff;
}
.login-split {
  margin: 28px 0 0;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-weight: 600;
  font-size: 0.85rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.error { color: var(--warn); margin: 0; }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--line); }
  .kpis, .charts, .charts-2 { grid-template-columns: 1fr; }
  .topbar { flex-direction: column; align-items: stretch; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation: none !important; }
}
