/* FullCircle AT — WCAG 2.2 AAA-conformant styles.
   Palette designed for >= 7:1 contrast (normal text) and >= 4.5:1 (large text).
   Target sizes >= 44×44 CSS px on interactive controls (2.5.5).
   Honours prefers-reduced-motion (2.3.3 / 2.2.2).
*/

/* ---------- Design tokens (AAA palette) ---------- */
:root {
  --fg:           #111111;  /* normal text on white = 18.88:1 */
  --fg-muted:     #424242;  /* on white = 9.74:1 */
  --bg:           #ffffff;
  --bg-alt:       #f3f4f6;  /* light gray surface */
  --bg-card:      #ffffff;
  --border:       #4f4f4f;  /* 8.6:1 against white */
  --border-soft:  #b1b1b1;  /* used only for decorative dividers, never for text */
  --brand-primary: #003e5c; /* default; overridden inline by branding */
  --brand-accent:  #6a3b00;
  --link:         #00496c;  /* 8.9:1 on white */
  --link-visited: #5a2d8a;  /* 7.3:1 on white */
  --link-hover:   #002335;
  --success-fg:   #0b4220;  /* on #ddf3e5 = 10.7:1 */
  --success-bg:   #ddf3e5;
  --warn-fg:      #5c1f00;  /* on #ffe6d6 = 9.4:1 */
  --warn-bg:      #ffe6d6;
  --danger-fg:    #5c0000;  /* on #ffe1e1 = 11.3:1 */
  --danger-bg:    #ffe1e1;
  --focus:        #ffbf00;  /* high-visibility focus indicator */
  --focus-shadow: 0 0 0 3px rgba(255,191,0,0.6);
  --radius:       6px;
  --shadow:       0 1px 2px rgba(0,0,0,0.08);
  --target-min:   44px;
  --line-height:  1.55;  /* AAA 1.4.8 line spacing >= 1.5 */
  --paragraph-spacing: 1.6em;
}

/* High contrast — pure black/white */
body.hc {
  --fg: #000000;
  --fg-muted: #000000;
  --bg: #ffffff;
  --bg-alt: #ffffff;
  --bg-card: #ffffff;
  --border: #000000;
  --border-soft: #000000;
  --link: #000000;
  --link-visited: #000000;
  --link-hover: #000000;
  --success-fg: #000000;
  --success-bg: #ffffff;
  --warn-fg: #000000;
  --warn-bg: #ffffff;
  --danger-fg: #000000;
  --danger-bg: #ffffff;
  --brand-primary: #000000;
  --brand-accent: #000000;
  --focus: #000000;
  --focus-shadow: 0 0 0 4px #ffbf00;
}
body.hc * { text-shadow: none !important; }
body.hc a { text-decoration: underline; }
body.hc .pill, body.hc .btn, body.hc .card { border-width: 2px; }

/* Dyslexia-friendly font */
body.dys {
  font-family: "OpenDyslexic", "Atkinson Hyperlegible", "Comic Sans MS", system-ui, sans-serif;
  letter-spacing: 0.04em;
  word-spacing: 0.12em;
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { font-size: 100%; -webkit-text-size-adjust: 100%; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 1rem;
  line-height: var(--line-height);
  min-height: 100vh;
}

/* AAA 1.4.8 visual presentation — comfortable measure on body text */
main p, main li, main dd, main td { max-width: 80ch; }
main p + p { margin-top: var(--paragraph-spacing); }
p { line-height: var(--line-height); }

/* Honour reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important;
                           transition-duration: 0.001ms !important; }
}
body.rm *, body.rm *::before, body.rm *::after {
  animation-duration: 0.001ms !important;
  transition-duration: 0.001ms !important;
}

/* ---------- Skip link (2.4.1) ---------- */
.skip-link {
  position: absolute;
  top: -40px; left: 0;
  background: var(--brand-primary);
  color: #ffffff;
  padding: 0.75rem 1rem;
  z-index: 9999;
  text-decoration: underline;
  font-weight: 700;
}
.skip-link:focus { top: 0; outline: 3px solid var(--focus); }

/* ---------- Focus (2.4.7, 2.4.11, 2.4.13) ---------- */
:focus { outline: none; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  box-shadow: var(--focus-shadow);
}
/* Ensure focus is not obscured (2.4.11) — see scroll-margin on headings */
main :target, h1, h2, h3 { scroll-margin-top: 80px; }

/* ---------- Typography ---------- */
h1, h2, h3, h4 { line-height: 1.25; margin: 0 0 0.6rem; color: var(--fg); }
h1 { font-size: 1.75rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.1rem; }
.muted { color: var(--fg-muted); }
.small { font-size: 0.92rem; }
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0;
  margin: -1px; overflow: hidden; clip: rect(0,0,0,0); border: 0; white-space: nowrap;
}

/* ---------- Links (1.4.1 don't rely on color: underline always) ---------- */
a { color: var(--link); text-decoration: underline; text-underline-offset: 2px; }
a:visited { color: var(--link-visited); }
a:hover { color: var(--link-hover); text-decoration-thickness: 2px; }

/* ---------- Topbar ---------- */
.topbar {
  background: var(--brand-primary);
  color: #ffffff;
  display: flex; justify-content: space-between; align-items: center;
  padding: 0.75rem 1rem;
  gap: 1rem;
}
.topbar a, .topbar .brand-name { color: #ffffff; }
.topbar a:visited { color: #ffffff; }
.brand { display: flex; align-items: center; gap: 0.6rem; min-height: var(--target-min); }
.brand-name { font-weight: 700; font-size: 1.15rem; text-decoration: none; }
.brand-name:hover { text-decoration: underline; }
.logo { max-height: 40px; width: auto; }
.topbar-right { display: flex; align-items: center; gap: 1rem; }
.user-chip { background: rgba(255,255,255,0.18); padding: 0.3rem 0.75rem; border-radius: 999px; }
.user-chip .role { opacity: 0.85; font-size: 0.85rem; }

/* ---------- Layout ---------- */
.app { display: grid; grid-template-columns: 240px 1fr; min-height: calc(100vh - 64px); }
.sidebar {
  background: var(--bg-alt);
  border-right: 1px solid var(--border);
  padding: 0.75rem;
}
.sidebar a.nav-link {
  display: block;
  padding: 0.65rem 0.75rem;
  border-radius: 4px;
  color: var(--fg);
  text-decoration: none;
  min-height: var(--target-min);
  display: flex; align-items: center;
  margin-bottom: 2px;
  border-left: 4px solid transparent;
}
.sidebar a.nav-link:hover { background: var(--bg-card); text-decoration: underline; }
.sidebar a.nav-link[aria-current="page"] {
  background: var(--bg-card);
  border-left-color: var(--brand-primary);
  font-weight: 700;
}
.nav-section {
  margin: 1rem 0 0.25rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--fg-muted);
  font-weight: 700;
}
.nav-sub { list-style: none; padding: 0; margin: 0; }
.prefs-form label {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.4rem 0; font-size: 0.95rem; cursor: pointer;
  min-height: var(--target-min);
}
.prefs-form input[type=checkbox] { width: 20px; height: 20px; }

.content {
  padding: 1.5rem;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
}
.content.unauth { margin: 5vh auto; max-width: 480px; }

/* ---------- Cards / grid ---------- */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow);
}
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}
.grid .card { margin: 0; }
.grid .span-2 { grid-column: span 2; }

.page-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem;
}
.page-head h1 { margin: 0; }

.big-stat { font-size: 2.4rem; font-weight: 700; color: var(--brand-primary); margin: 0.3rem 0; }
.big-stat small { font-size: 1rem; font-weight: 400; color: var(--fg-muted); }

/* ---------- Forms (3.3.x) ---------- */
label { display: block; font-weight: 600; margin-bottom: 0.3rem; }
input, select, textarea {
  font: inherit;
  width: 100%;
  padding: 0.6rem 0.7rem;
  border: 2px solid var(--border);
  border-radius: 4px;
  background: var(--bg-card);
  color: var(--fg);
  min-height: var(--target-min);
}
input[type=checkbox], input[type=radio] {
  width: 24px; height: 24px; min-height: 24px;
  vertical-align: middle; margin-right: 0.4rem;
}
textarea { min-height: 6rem; resize: vertical; line-height: var(--line-height); }
input[type=color] { padding: 0.2rem; height: var(--target-min); }
input:invalid { border-color: var(--danger-fg); }
.field-error {
  color: var(--danger-fg);
  background: var(--danger-bg);
  border-left: 4px solid var(--danger-fg);
  padding: 0.3rem 0.6rem; margin-top: 0.3rem;
  font-size: 0.95rem;
}
.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 1rem;
}
.form-grid .full { grid-column: 1 / -1; }
.checkbox-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 0.3rem; }
.checkbox-grid label { font-weight: 400; display: flex; align-items: center; gap: 0.3rem; }
.inline-form { display: flex; gap: 0.5rem; align-items: end; flex-wrap: wrap; }
.small-input { width: 12rem; }

/* ---------- Buttons (2.5.5 size, 1.4.3/1.4.6 contrast, 2.4.6 labels) ---------- */
.btn, button {
  font: inherit;
  cursor: pointer;
  background: var(--bg-alt);
  color: var(--fg);
  border: 2px solid var(--border);
  border-radius: 4px;
  padding: 0.55rem 1rem;
  min-height: var(--target-min);
  min-width: var(--target-min);
  text-decoration: none;
  display: inline-flex; align-items: center; justify-content: center;
  font-weight: 600;
}
.btn:hover, button:hover { background: var(--bg-card); }
.btn-primary {
  background: var(--brand-primary);
  color: #ffffff;
  border-color: var(--brand-primary);
}
.btn-primary:hover { background: var(--link-hover); color: #ffffff; }
.btn-primary:visited { color: #ffffff; }
.btn-danger {
  background: var(--danger-bg);
  color: var(--danger-fg);
  border-color: var(--danger-fg);
}
.btn-danger:hover { background: var(--danger-fg); color: #ffffff; }
.btn-link {
  background: none; border: none; color: var(--link);
  text-decoration: underline; padding: 0.4rem 0.5rem;
  min-height: var(--target-min);
}
.inline { display: inline-block; margin-right: 0.5rem; }

/* Reverse contrast inside dark topbar */
.topbar .btn-link { color: #ffffff; text-decoration: underline; }

/* ---------- Tables (1.3.1 semantics) ---------- */
table { width: 100%; border-collapse: collapse; margin: 0.5rem 0; }
caption { caption-side: top; text-align: left; font-weight: 700; margin-bottom: 0.4rem; }
th, td {
  text-align: left;
  padding: 0.65rem 0.7rem;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}
th {
  background: var(--bg-alt);
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  border-bottom: 2px solid var(--border);
}
tr:nth-child(even) td { background: rgba(0,0,0,0.02); }

/* ---------- Pills / status indicators (with text, not color alone — 1.4.1) ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 0.3rem;
  padding: 0.15rem 0.65rem;
  border-radius: 999px;
  background: var(--bg-alt);
  border: 1px solid var(--border);
  color: var(--fg);
  font-size: 0.88rem;
  margin-right: 0.3rem;
  font-weight: 600;
}
.pill.ok::before     { content: "✓"; }
.pill.warn::before   { content: "⚠"; }
.pill.danger::before { content: "✕"; }
.pill.ok      { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-fg); }
.pill.warn    { background: var(--warn-bg);    color: var(--warn-fg);    border-color: var(--warn-fg); }
.pill.danger  { background: var(--danger-bg);  color: var(--danger-fg);  border-color: var(--danger-fg); }

/* Note-type pills — distinct text plus background */
.pill-attempt_contact { background: #e1ecf6; color: #0a3461; border-color: #0a3461; }
.pill-training_event  { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-fg); }
.pill-progress_report { background: #fff3cc; color: #5b4400; border-color: #5b4400; }
.pill-tech_rec        { background: #f1e3f8; color: #4a1066; border-color: #4a1066; }
.pill-general         { background: var(--bg-alt); color: var(--fg); border-color: var(--border); }

/* ---------- Tabs ---------- */
.tabs {
  display: flex; flex-wrap: wrap;
  gap: 0.1rem;
  border-bottom: 2px solid var(--border);
  margin: 0 0 1rem;
}
.tabs a {
  padding: 0.7rem 1rem;
  text-decoration: none;
  color: var(--fg);
  border: 2px solid transparent;
  border-bottom: none;
  margin-bottom: -2px;
  min-height: var(--target-min);
  display: inline-flex; align-items: center;
  font-weight: 600;
}
.tabs a[aria-current="page"] {
  background: var(--bg-card);
  border-color: var(--border);
  border-bottom-color: var(--bg-card);
  color: var(--brand-primary);
}
.tabs a:hover { background: var(--bg-alt); text-decoration: underline; }

/* ---------- Flash messages ---------- */
.flashes { margin-bottom: 1rem; }
.flash {
  padding: 0.75rem 1rem;
  border-radius: 4px;
  margin-bottom: 0.5rem;
  border-left: 6px solid;
}
.flash::before { font-weight: 700; margin-right: 0.4rem; }
.flash-success { background: var(--success-bg); color: var(--success-fg); border-color: var(--success-fg); }
.flash-success::before { content: "Success: "; }
.flash-error   { background: var(--danger-bg);  color: var(--danger-fg);  border-color: var(--danger-fg); }
.flash-error::before { content: "Error: "; }
.flash-info    { background: #e1ecf6; color: #0a3461; border-color: #0a3461; }
.flash-info::before { content: "Note: "; }

/* ---------- Auth card ---------- */
.auth-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  max-width: 440px;
  margin: 4rem auto;
  box-shadow: var(--shadow);
}
.auth-card h1 { color: var(--brand-primary); margin-top: 0; }
.auth-card label { margin-top: 0.8rem; }

/* ---------- Filter bar ---------- */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: end;
  margin-bottom: 0.8rem;
}
.filter-bar input, .filter-bar select { width: auto; min-width: 12rem; }

/* ---------- Notes ---------- */
.notes { list-style: none; padding: 0; margin: 0; }
.notes > li {
  background: var(--bg-alt);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
  margin-bottom: 0.6rem;
}
.notes header { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin-bottom: 0.3rem; }
.notes p { margin: 0; white-space: pre-wrap; }

/* ---------- Messages / threads ---------- */
.messages { list-style: none; padding: 0; margin: 0 0 1rem; }
.messages li {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 0.6rem;
  max-width: 75%;
  border: 1px solid var(--border-soft);
  background: var(--bg-alt);
}
.messages li.from-staff { background: #e1ecf6; border-color: #0a3461; }
.messages li.from-client { margin-left: auto; background: var(--bg-card); border-color: var(--border-soft); }
.messages header { display: flex; gap: 0.4rem; font-size: 0.85rem; color: var(--fg-muted); margin-bottom: 0.3rem; }
.messages p { margin: 0; white-space: pre-wrap; }

/* ---------- Profile head / presence ---------- */
.profile-head {
  display: flex; flex-wrap: wrap; gap: 0.5rem 1rem; align-items: center;
  margin-bottom: 0.5rem;
}
.profile-head h1 { margin: 0; }
.profile-actions { margin-left: auto; display: flex; gap: 0.5rem; }
.presence { margin: 0.5rem 0; }
.presence-badge {
  display: inline-flex; align-items: center; gap: 0.3rem;
  background: var(--warn-bg); color: var(--warn-fg); border: 1px solid var(--warn-fg);
  padding: 0.2rem 0.7rem; border-radius: 999px; font-size: 0.88rem;
  font-weight: 600;
}
.presence-badge::before { content: "👁"; }
body.dys .presence-badge::before, body.hc .presence-badge::before { content: "[viewing] "; }

/* ---------- Open clock card ---------- */
.open-clock {
  background: #fff3cc;
  border: 2px solid #5b4400;
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 1rem;
}

/* ---------- Toasts (1.4.13 hover/focus, 4.1.3 status messages) ---------- */
.toast-zone {
  position: fixed; right: 1rem; bottom: 1rem; z-index: 1000;
  display: flex; flex-direction: column; gap: 0.5rem; max-width: 380px;
}
.toast {
  background: var(--brand-primary);
  color: #ffffff;
  padding: 0.8rem 1rem;
  border-radius: var(--radius);
  border: 2px solid #ffffff;
  box-shadow: 0 2px 6px rgba(0,0,0,0.25);
  text-decoration: none;
  display: block;
  font-weight: 600;
}
.toast:hover, .toast:focus-visible { background: var(--link-hover); color: #ffffff; }
.toast .dismiss {
  background: none; border: 2px solid #ffffff; color: #ffffff;
  padding: 0.1rem 0.5rem; border-radius: 4px; margin-left: 0.5rem;
}

/* ---------- Calendar ---------- */
.calendar { border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.cal-row { display: grid; grid-template-columns: repeat(7, 1fr); }
.cal-cell {
  border-top: 1px solid var(--border-soft);
  border-left: 1px solid var(--border-soft);
  min-height: 6.5rem; padding: 0.4rem;
  background: var(--bg-card);
}
.cal-cell.head {
  background: var(--bg-alt); font-weight: 700; min-height: 0;
  text-align: center; padding: 0.5rem;
}
.cal-cell.empty { background: var(--bg-alt); }
.cal-date a { font-weight: 700; color: var(--fg); text-decoration: none; }
.cal-date a:hover, .cal-date a:focus-visible { text-decoration: underline; }
.cal-appt {
  display: block; font-size: 0.85rem; padding: 0.2rem 0.4rem;
  background: var(--brand-primary); color: #ffffff; border-radius: 3px;
  margin-top: 0.2rem; text-decoration: none;
}
.cal-appt:hover, .cal-appt:focus-visible { background: var(--link-hover); }

/* ---------- Activity / lists ---------- */
.activity { list-style: none; padding: 0; margin: 0; }
.activity li { padding: 0.5rem 0; border-bottom: 1px solid var(--border-soft); }
.thread-list { list-style: none; padding: 0; }
.thread-list li {
  padding: 0.7rem 0; border-bottom: 1px solid var(--border-soft);
  display: flex; gap: 0.5rem; align-items: center; flex-wrap: wrap;
}

/* ---------- Info grid ---------- */
.info-grid { display: grid; grid-template-columns: max-content 1fr; gap: 0.5rem 1.2rem; }
.info-grid dt { font-weight: 700; color: var(--fg-muted); }
.info-grid dd { margin: 0; }

/* ---------- Link card ---------- */
.link-card {
  text-decoration: none; color: var(--fg); display: block;
}
.link-card:hover, .link-card:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  text-decoration: underline;
}

/* ---------- Responsive ---------- */
@media (max-width: 880px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); }
  .form-grid { grid-template-columns: 1fr; }
  .grid .span-2 { grid-column: span 1; }
}

/* ---------- Print ---------- */
@media print {
  .topbar, .sidebar, .toast-zone, .skip-link, .prefs-form { display: none !important; }
  .content { max-width: none; padding: 0; }
  .card { box-shadow: none; border-color: #000; }
}
