/* ============================================================
   Grace Notes — app styles (mobile-first, 8px grid)
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }

html { font-size: 100%; }
body {
  margin: 0;
  font-family: var(--font-body);
  font-size: var(--text-base);
  line-height: var(--leading-body);
  color: var(--color-text);
  background: var(--color-bg);
  -webkit-font-smoothing: antialiased;
}

h1, h2 { font-family: var(--font-display); font-weight: 700; line-height: var(--leading-tight); margin: 0 0 var(--space-2); }
h1 { font-size: var(--text-2xl); }
h2 { font-size: var(--text-xl); }
h3, h4 { font-family: var(--font-body); font-weight: 600; line-height: var(--leading-tight); margin: 0 0 var(--space-1); font-size: var(--text-base); }
p { margin: 0 0 var(--space-2); }
a { color: var(--color-primary); text-decoration-thickness: 1px; text-underline-offset: 2px; transition: color var(--duration) var(--ease); }
a:hover { color: var(--color-primary-hover); }

:focus-visible { outline: 3px solid var(--color-primary); outline-offset: 2px; border-radius: 4px; }

/* ---------- App shell ---------- */
.shell { min-height: 100vh; display: flex; flex-direction: column; }
.main { flex: 1; width: 100%; max-width: var(--content-max); margin: 0 auto; padding: var(--space-2) var(--space-2) calc(var(--tap-target) + var(--space-6)); }

/* Mobile top bar */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; justify-content: space-between;
  min-height: var(--space-6);
  padding: var(--space-1) var(--space-2);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
}
.brand { display: flex; align-items: center; gap: var(--space-1); font-family: var(--font-display); font-weight: 700; font-size: var(--text-lg); color: var(--color-text); text-decoration: none; }
.brand-mark { display: inline-flex; align-items: center; justify-content: center; width: 32px; height: 32px; border-radius: var(--radius-sm); background: var(--color-primary); color: var(--color-text-inverse); font-size: var(--text-sm); }

/* Bottom tab bar (mobile nav) */
.tabbar {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 20;
  display: flex;
  background: var(--color-surface);
  border-top: 1px solid var(--color-border);
  padding-bottom: env(safe-area-inset-bottom, 0);
}
.tabbar a {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  min-height: var(--tap-target); padding: var(--space-1) 4px;
  font-size: var(--text-xs); font-weight: 500; text-decoration: none; color: var(--color-text-muted);
  transition: color var(--duration) var(--ease), background var(--duration) var(--ease);
}
.tabbar a .icon { font-size: 20px; line-height: 1; }
.tabbar a[aria-current="page"] { color: var(--color-primary); }
.tabbar a:active { background: var(--color-primary-soft); }

/* Desktop sidebar */
.sidebar { display: none; }

@media (min-width: 1024px) {
  .shell { flex-direction: row; }
  .topbar, .tabbar { display: none; }
  .sidebar {
    display: flex; flex-direction: column;
    width: var(--sidebar-w); flex-shrink: 0;
    position: sticky; top: 0; height: 100vh;
    padding: var(--space-3) var(--space-2);
    background: var(--color-surface);
    border-right: 1px solid var(--color-border);
  }
  .sidebar .brand { padding: 0 var(--space-1) var(--space-3); font-size: var(--text-xl); }
  .sidebar nav { display: flex; flex-direction: column; gap: 4px; }
  .sidebar nav a {
    display: flex; align-items: center; gap: var(--space-1);
    min-height: var(--tap-target); padding: 0 var(--space-2);
    border-radius: var(--radius-sm);
    font-weight: 500; text-decoration: none; color: var(--color-text-muted);
    transition: background var(--duration) var(--ease), color var(--duration) var(--ease);
  }
  .sidebar nav a:hover { background: var(--color-bg); color: var(--color-text); }
  .sidebar nav a[aria-current="page"] { background: var(--color-primary-soft); color: var(--color-primary); font-weight: 600; }
  .sidebar .sidebar-foot { margin-top: auto; padding-top: var(--space-2); border-top: 1px solid var(--color-border); }
  .main { padding: var(--space-4) var(--space-4) var(--space-6); }
}

/* ---------- Page header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-3); }
.page-head .sub { color: var(--color-text-muted); font-size: var(--text-sm); margin: 0; }

/* ---------- Cards & grid ---------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  padding: var(--space-3);
  transition: box-shadow var(--duration) var(--ease), transform var(--duration) var(--ease);
}
a.card { display: block; text-decoration: none; color: inherit; }
.card.is-interactive:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.card.is-interactive:active { transform: translateY(0); box-shadow: var(--shadow-sm); }
.card-title { display: flex; align-items: center; justify-content: space-between; gap: var(--space-1); margin-bottom: var(--space-2); }
.card-title h2 { margin: 0; font-size: var(--text-lg); }

.grid { display: grid; gap: var(--space-2); grid-template-columns: 1fr; }
@media (min-width: 640px)  { .grid-2 { grid-template-columns: repeat(2, 1fr); } }
@media (min-width: 1024px) { .grid-2 { grid-template-columns: repeat(2, 1fr); } .grid-4 { grid-template-columns: repeat(4, 1fr); } .grid { gap: var(--space-3); } }

.stat { display: flex; flex-direction: column; gap: 4px; }
.stat .stat-value { font-family: var(--font-display); font-size: var(--text-3xl); font-weight: 700; line-height: 1; }
.stat .stat-label { font-size: var(--text-sm); color: var(--color-text-muted); font-weight: 500; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--space-1);
  min-height: var(--tap-target); padding: 0 var(--space-3);
  border: 1px solid transparent; border-radius: var(--radius-sm);
  font: inherit; font-weight: 600; font-size: var(--text-sm);
  cursor: pointer; text-decoration: none;
  transition: background var(--duration) var(--ease), box-shadow var(--duration) var(--ease), transform var(--duration) var(--ease), opacity var(--duration) var(--ease);
}
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--color-primary); color: var(--color-text-inverse); }
.btn-primary:hover { background: var(--color-primary-hover); box-shadow: var(--shadow-sm); }
.btn-secondary { background: var(--color-surface); color: var(--color-text); border-color: var(--color-border-strong); }
.btn-secondary:hover { background: var(--color-bg); box-shadow: var(--shadow-sm); }
.btn-ghost { background: transparent; color: var(--color-primary); }
.btn-ghost:hover { background: var(--color-primary-soft); }
.btn-danger { background: var(--color-surface); color: var(--color-error); border-color: var(--color-border-strong); }
.btn-danger:hover { background: var(--color-error-soft); }
.btn-sm { min-height: 40px; padding: 0 var(--space-2); }
@media (min-width: 1024px) { .btn { min-height: 40px; } .btn-sm { min-height: 32px; } }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: var(--space-2); }
.field label { font-size: var(--text-sm); font-weight: 600; }
.field .hint { font-size: var(--text-xs); color: var(--color-text-muted); }
input[type="text"], input[type="email"], input[type="tel"], input[type="date"], input[type="time"],
input[type="password"], input[type="search"], select, textarea {
  width: 100%; min-height: var(--tap-target);
  padding: var(--space-1) var(--space-2);
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm);
  background: var(--color-surface); color: var(--color-text);
  font: inherit; font-size: var(--text-base);
  transition: border-color var(--duration) var(--ease), box-shadow var(--duration) var(--ease);
}
textarea { min-height: 96px; resize: vertical; line-height: var(--leading-body); }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--color-primary); box-shadow: 0 0 0 3px var(--color-primary-soft); }
.form-row { display: grid; gap: var(--space-2); grid-template-columns: 1fr; }
@media (min-width: 640px) { .form-row-2 { grid-template-columns: 1fr 1fr; } .form-row-3 { grid-template-columns: 1fr 1fr 1fr; } }
fieldset { border: 1px solid var(--color-border); border-radius: var(--radius-sm); padding: var(--space-2); margin: 0 0 var(--space-2); }
legend { font-weight: 600; font-size: var(--text-sm); padding: 0 var(--space-1); }

/* ---------- Progressive disclosure ---------- */
details.disclosure { border: 1px solid var(--color-border); border-radius: var(--radius-sm); background: var(--color-surface); margin-bottom: var(--space-2); }
details.disclosure > summary {
  display: flex; align-items: center; justify-content: space-between;
  min-height: var(--tap-target); padding: var(--space-1) var(--space-2);
  font-weight: 600; cursor: pointer; list-style: none;
  transition: background var(--duration) var(--ease);
}
details.disclosure > summary::-webkit-details-marker { display: none; }
details.disclosure > summary::after { content: "▾"; color: var(--color-text-muted); transition: transform var(--duration) var(--ease); }
details.disclosure[open] > summary::after { transform: rotate(180deg); }
details.disclosure > summary:hover { background: var(--color-bg); }
details.disclosure > .disclosure-body { padding: var(--space-2); border-top: 1px solid var(--color-border); }
@media (min-width: 1024px) { details.disclosure.desktop-open-hint > summary { pointer-events: auto; } }

/* ---------- Tables (desktop) / stacked rows (mobile) ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--color-border); border-radius: var(--radius-md); background: var(--color-surface); box-shadow: var(--shadow-sm); }
table.data { width: 100%; border-collapse: collapse; font-size: var(--text-sm); }
table.data th { text-align: left; font-size: var(--text-xs); text-transform: uppercase; letter-spacing: .04em; color: var(--color-text-muted); padding: var(--space-1) var(--space-2); border-bottom: 1px solid var(--color-border); background: var(--color-bg); }
table.data td { padding: var(--space-1) var(--space-2); border-bottom: 1px solid var(--color-border); vertical-align: middle; }
table.data tr:last-child td { border-bottom: none; }
table.data tbody tr { transition: background var(--duration) var(--ease); }
table.data tbody tr:hover { background: var(--color-bg); }

/* ---------- List rows (mobile-friendly) ---------- */
.rowlist { display: flex; flex-direction: column; gap: var(--space-1); }
.rowitem {
  display: flex; align-items: center; gap: var(--space-2);
  min-height: var(--tap-target); padding: var(--space-1) var(--space-2);
  background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--radius-sm);
  text-decoration: none; color: inherit;
  transition: box-shadow var(--duration) var(--ease), transform var(--duration) var(--ease);
}
.rowitem:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }
.rowitem .grow { flex: 1; min-width: 0; }
.rowitem .meta { font-size: var(--text-sm); color: var(--color-text-muted); }

.avatar {
  flex-shrink: 0; display: inline-flex; align-items: center; justify-content: center;
  width: 40px; height: 40px; border-radius: var(--radius-full);
  background: var(--color-primary-soft); color: var(--color-primary);
  font-weight: 700; font-size: var(--text-sm);
}

/* ---------- Badges ---------- */
.badge { display: inline-flex; align-items: center; gap: 4px; padding: 2px var(--space-1); border-radius: var(--radius-full); font-size: var(--text-xs); font-weight: 600; }
.badge-success { background: var(--color-success-soft); color: var(--color-success); }
.badge-error   { background: var(--color-error-soft);   color: var(--color-error); }
.badge-warn    { background: var(--color-warn-soft);    color: var(--color-warn); }
.badge-neutral { background: var(--color-bg); color: var(--color-text-muted); border: 1px solid var(--color-border); }
.badge-primary { background: var(--color-primary-soft); color: var(--color-primary); }

/* ---------- Attendance segmented control ---------- */
.seg { display: flex; gap: 4px; flex-wrap: wrap; }
.seg button {
  min-height: var(--tap-target); min-width: var(--tap-target); padding: 0 var(--space-2);
  border: 1px solid var(--color-border-strong); border-radius: var(--radius-sm);
  background: var(--color-surface); color: var(--color-text-muted);
  font: inherit; font-size: var(--text-sm); font-weight: 600; cursor: pointer;
  transition: all var(--duration) var(--ease);
}
.seg button[aria-pressed="true"][data-status="present"] { background: var(--color-success-soft); border-color: var(--color-success); color: var(--color-success); }
.seg button[aria-pressed="true"][data-status="absent"]  { background: var(--color-error-soft);   border-color: var(--color-error);   color: var(--color-error); }
.seg button[aria-pressed="true"][data-status="late"]    { background: var(--color-warn-soft);    border-color: var(--color-warn);    color: var(--color-warn); }
.seg button[aria-pressed="true"][data-status="excused"] { background: var(--color-primary-soft); border-color: var(--color-primary); color: var(--color-primary); }
@media (min-width: 1024px) { .seg button { min-height: 36px; min-width: 0; } }

/* ---------- Data states ---------- */
.state-empty {
  display: flex; flex-direction: column; align-items: center; gap: var(--space-1);
  padding: var(--space-6) var(--space-3); text-align: center;
  color: var(--color-text-muted);
}
.state-empty .glyph { font-size: 40px; line-height: 1; }
.state-empty h3 { color: var(--color-text); }
.state-error {
  padding: var(--space-2); border-radius: var(--radius-sm);
  background: var(--color-error-soft); color: var(--color-error);
  display: flex; flex-direction: column; gap: var(--space-1); font-size: var(--text-sm);
}
.state-error strong { font-size: var(--text-base); }

.skeleton { display: flex; flex-direction: column; gap: var(--space-1); }
.skeleton .bone {
  height: 16px; border-radius: 6px;
  background: linear-gradient(90deg, var(--color-border) 25%, var(--color-bg) 50%, var(--color-border) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s ease infinite;
}
.skeleton .bone.lg { height: 40px; }
.skeleton .bone.w-60 { width: 60%; } .skeleton .bone.w-40 { width: 40%; } .skeleton .bone.w-80 { width: 80%; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
@media (prefers-reduced-motion: reduce) { .skeleton .bone { animation: none; } }

/* ---------- Flash messages ---------- */
.flash { padding: var(--space-2); border-radius: var(--radius-sm); margin-bottom: var(--space-2); font-size: var(--text-sm); font-weight: 500; }
.flash-success { background: var(--color-success-soft); color: var(--color-success); }
.flash-error { background: var(--color-error-soft); color: var(--color-error); }

/* ---------- Trend bars ---------- */
.trend { display: flex; align-items: flex-end; gap: var(--space-1); height: 96px; }
.trend .bar-col { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.trend .bar { width: 100%; max-width: 40px; border-radius: 6px 6px 0 0; background: var(--color-primary); opacity: .85; transition: opacity var(--duration) var(--ease); min-height: 4px; }
.trend .bar:hover { opacity: 1; }
.trend .bar-label { font-size: var(--text-xs); color: var(--color-text-muted); white-space: nowrap; }

/* ---------- Utilities (8px grid only) ---------- */
.mt-1 { margin-top: var(--space-1); } .mt-2 { margin-top: var(--space-2); } .mt-3 { margin-top: var(--space-3); } .mt-4 { margin-top: var(--space-4); }
.mb-1 { margin-bottom: var(--space-1); } .mb-2 { margin-bottom: var(--space-2); } .mb-3 { margin-bottom: var(--space-3); }
.stack-1 > * + * { margin-top: var(--space-1); } .stack-2 > * + * { margin-top: var(--space-2); }
.cluster { display: flex; flex-wrap: wrap; gap: var(--space-1); align-items: center; }
.muted { color: var(--color-text-muted); } .small { font-size: var(--text-sm); }
.right { text-align: right; }
.visually-hidden { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Auth screen ---------- */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: var(--space-2); }
.auth-card { width: 100%; max-width: 400px; }
