/* =================================================================
   Loft design system
   ================================================================= */

:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #fbfcfe;
  --ink: #0f172a;
  --ink-2: #334155;
  --muted: #64748b;
  --faint: #94a3b8;
  --line: #e5e9f2;
  --line-strong: #d3dae7;

  --brand: #4338ca;
  --brand-dark: #3730a3;
  --brand-soft: #eef0fe;
  --accent: #0ea5e9;

  --green: #0f9d58;
  --green-soft: #e7f7ee;
  --amber: #b45309;
  --amber-soft: #fef3c7;
  /* Brighter fills for bars/dots: the text-safe amber reads as mud at 6px. */
  --amber-fill: #f59e0b;
  --red-fill: #ef4444;
  --red: #c0392b;
  --red-soft: #fdeaea;
  --slate-soft: #eef1f6;

  --sidebar: #0b1220;
  --sidebar-ink: #cbd5e1;
  --sidebar-dim: #7c8ba5;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px -12px rgba(15, 23, 42, .12);
  --shadow-lg: 0 24px 60px -20px rgba(15, 23, 42, .35);

  --font: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 { margin: 0; font-weight: 650; letter-spacing: -.015em; }
p { margin: 0; }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ------------------------------ boot ------------------------------ */

.boot { display: grid; place-items: center; min-height: 100vh; }
.boot-inner { text-align: center; color: var(--muted); display: grid; gap: 16px; justify-items: center; }

/* ---------------------------- app shell --------------------------- */

.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 252px;
  flex: 0 0 252px;
  background: var(--sidebar);
  color: var(--sidebar-ink);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
  border-right: 1px solid #1a2437;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 20px 18px 16px;
}

.brand-mark {
  width: 30px; height: 30px;
  border-radius: 9px;
  background: linear-gradient(145deg, var(--brand), #6d5ef0);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 800; font-size: 15px;
  letter-spacing: -.02em;
  flex: 0 0 auto;
}
.brand-mark--lg { width: 46px; height: 46px; border-radius: 13px; font-size: 22px; }

.sidebar-brand .name { font-weight: 650; color: #fff; font-size: 15px; letter-spacing: -.01em; }
.sidebar-brand .tag { font-size: 11px; color: var(--sidebar-dim); letter-spacing: .04em; text-transform: uppercase; }

.org-switch {
  margin: 0 12px 14px;
  padding: 10px 12px;
  background: #131c2e;
  border: 1px solid #1e2a41;
  border-radius: var(--radius-sm);
  display: flex; align-items: center; gap: 9px;
  cursor: pointer;
  width: calc(100% - 24px);
  text-align: left;
  transition: border-color .15s ease, background .15s ease;
}
.org-switch:hover { border-color: #2c3d5c; background: #162034; }
.org-switch .dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--green); flex: 0 0 auto;
}
.org-switch .label { font-size: 10px; color: var(--sidebar-dim); text-transform: uppercase; letter-spacing: .06em; }
.org-switch > div { min-width: 0; flex: 1; }
.org-switch .value {
  font-size: 13px; color: #e8eefb; font-weight: 550;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.org-switch .chev { margin-left: auto; color: var(--sidebar-dim); font-size: 11px; flex: 0 0 auto; }

.nav { padding: 4px 10px; overflow-y: auto; flex: 1; }
.nav-group { margin-bottom: 16px; }
.nav-group-title {
  font-size: 10px; text-transform: uppercase; letter-spacing: .08em;
  color: #5b6b85; padding: 4px 10px 6px; font-weight: 600;
}
.nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px;
  border-radius: 9px;
  color: var(--sidebar-ink);
  font-size: 13.5px;
  text-decoration: none;
  margin-bottom: 1px;
  transition: background .12s ease, color .12s ease;
  position: relative;
}
.nav a:hover { background: #162034; color: #fff; text-decoration: none; }
.nav a.active { background: #1d2a44; color: #fff; font-weight: 550; }
.nav a.active::before {
  content: ""; position: absolute; left: -10px; top: 8px; bottom: 8px;
  width: 3px; border-radius: 0 3px 3px 0; background: #6d5ef0;
}
.nav .icon { width: 17px; text-align: center; opacity: .85; font-size: 14px; }
.nav .count {
  margin-left: auto; font-size: 11px; font-weight: 650;
  background: #24334f; color: #cbd8f0; padding: 1px 7px; border-radius: 20px;
}
.nav .count.alert { background: #7f1d1d; color: #fecaca; }

.sidebar-foot {
  padding: 12px;
  border-top: 1px solid #1a2437;
  display: flex; align-items: center; gap: 10px;
}
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  background: #24334f; color: #dbe6ff;
  display: grid; place-items: center;
  font-size: 12px; font-weight: 700; flex: 0 0 auto;
}
.sidebar-foot .who { min-width: 0; flex: 1; }
.sidebar-foot .who .n { font-size: 12.5px; color: #e8eefb; font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sidebar-foot .who .r { font-size: 11px; color: var(--sidebar-dim); text-transform: capitalize; }
.icon-btn {
  background: none; border: 0; color: var(--sidebar-dim);
  cursor: pointer; padding: 6px; border-radius: 7px; line-height: 1;
}
.icon-btn:hover { background: #24334f; color: #fff; }

/* ------------------------------ main ------------------------------ */

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: 62px;
  display: flex; align-items: center; gap: 16px;
  padding: 0 28px;
  background: rgba(255,255,255,.82);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.topbar h1 { font-size: 17px; }
.topbar .sub { font-size: 12.5px; color: var(--muted); }
.topbar .spacer { flex: 1; }

.content { padding: 26px 28px 64px; max-width: 1360px; width: 100%; }

/* --------------------------- primitives --------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-pad { padding: 20px; }
.card-head {
  padding: 16px 20px;
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 12px;
}
.card-head h2 { font-size: 14px; }
.card-head .spacer { flex: 1; }
.card-body { padding: 20px; }
.card-body.flush { padding: 0; }

.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.grid.side { grid-template-columns: minmax(0, 2fr) minmax(0, 1fr); }

.row { display: flex; align-items: center; gap: 10px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.spacer { flex: 1; }
/* align-content keeps cards at their natural height instead of stretching to
   fill a taller grid column, which otherwise leaves large empty card bodies. */
.stack { display: grid; gap: 14px; align-content: start; }
.stack.tight { gap: 8px; }
.mt-16 { margin-top: 16px; } .mt-24 { margin-top: 24px; }

.muted { color: var(--muted); }
.faint { color: var(--faint); }
.small { font-size: 12.5px; }
.mono { font-family: var(--mono); font-size: 12px; }
.nowrap { white-space: nowrap; }
.strong { font-weight: 600; }
.center { text-align: center; }
.right { text-align: right; }

.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 650; margin-bottom: 10px; }

/* ----------------------------- buttons ---------------------------- */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px; font-weight: 550;
  cursor: pointer;
  transition: background .12s ease, border-color .12s ease, transform .06s ease;
  white-space: nowrap;
  text-decoration: none;
}
.btn:hover { background: #f8fafc; border-color: #c2ccdd; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn-primary:hover { background: var(--brand-dark); border-color: var(--brand-dark); }
.btn-danger { color: var(--red); border-color: #f2cfcb; background: #fff; }
.btn-danger:hover { background: var(--red-soft); }
.btn-ghost { border-color: transparent; background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--slate-soft); color: var(--ink); }
.btn-sm { padding: 5px 10px; font-size: 12px; border-radius: 8px; }
.btn-block { width: 100%; }

/* ----------------------------- badges ----------------------------- */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 11.5px; font-weight: 600;
  background: var(--slate-soft); color: var(--ink-2);
  white-space: nowrap;
}
.badge.ok { background: var(--green-soft); color: #0b6b3f; }
.badge.warn { background: var(--amber-soft); color: #92400e; }
.badge.bad { background: var(--red-soft); color: #a1251a; }
.badge.info { background: var(--brand-soft); color: var(--brand-dark); }
.badge.dot::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ----------------------------- tables ----------------------------- */

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left;
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em;
  color: var(--muted); font-weight: 650;
  padding: 10px 14px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-2);
  white-space: nowrap;
}
td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
tbody tr:last-child td { border-bottom: 0; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #f8fafd; }
.t-main { font-weight: 550; }
.t-sub { font-size: 12px; color: var(--muted); }

/* ----------------------------- stats ------------------------------ */

.stat { padding: 18px 20px; }
.stat .k { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 650; }
.stat .v { font-size: 28px; font-weight: 700; letter-spacing: -.03em; margin-top: 6px; line-height: 1.1; }
.stat .d { font-size: 12.5px; color: var(--muted); margin-top: 5px; }
.stat .v.warn { color: var(--amber); }
.stat .v.bad { color: var(--red); }
.stat .v.ok { color: var(--green); }

/* ----------------------------- forms ------------------------------ */

.field { display: grid; gap: 5px; }
.field > label { font-size: 11.5px; font-weight: 600; color: var(--ink-2); letter-spacing: .01em; }
.field .hint { font-size: 11.5px; color: var(--muted); }

input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="datetime-local"], input[type="search"], select, textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  background: #fff;
  font-size: 13.5px;
  transition: border-color .12s ease, box-shadow .12s ease;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(67, 56, 202, .12);
}
textarea { resize: vertical; min-height: 84px; line-height: 1.55; }
select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2364748b' stroke-width='1.6' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center; padding-right: 30px; }

.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.form-grid .span-2 { grid-column: span 2; }

.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.filters .field { min-width: 150px; }

/* ---------------------------- timeline ---------------------------- */

.timeline { position: relative; padding-left: 26px; }
.timeline::before {
  content: ""; position: absolute; left: 8px; top: 6px; bottom: 6px;
  width: 2px; background: var(--line);
}
.tl-item { position: relative; padding: 0 0 18px; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item::before {
  content: ""; position: absolute; left: -22px; top: 4px;
  width: 10px; height: 10px; border-radius: 50%;
  background: #fff; border: 2px solid var(--line-strong);
}
.tl-item.ok::before { border-color: var(--green); }
.tl-item.warn::before { border-color: var(--amber); }
.tl-item.bad::before { border-color: var(--red); }
.tl-item.info::before { border-color: var(--brand); }
.tl-when { font-size: 11.5px; color: var(--muted); }
.tl-what { font-size: 13px; margin-top: 1px; }
.tl-who { font-size: 11.5px; color: var(--faint); margin-top: 1px; }

/* ---------------------------- progress ---------------------------- */

.bar { height: 6px; background: var(--slate-soft); border-radius: 99px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: var(--brand); border-radius: 99px; transition: width .3s ease; }
.bar.ok > i { background: var(--green); }
.bar.warn > i { background: var(--amber-fill); }
.bar.bad > i { background: var(--red-fill); }

/* ----------------------------- modal ------------------------------ */

.modal-backdrop {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(15, 23, 42, .42);
  backdrop-filter: blur(2px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 6vh 16px 16px;
  overflow-y: auto;
  animation: fade .12s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 560px;
  animation: pop .14s ease;
}
.modal.wide { max-width: 760px; }
@keyframes pop { from { transform: translateY(6px) scale(.99); opacity: .6; } to { transform: none; opacity: 1; } }
.modal-head { padding: 18px 22px 0; }
.modal-head h3 { font-size: 16px; }
.modal-head p { font-size: 13px; color: var(--muted); margin-top: 3px; }
.modal-body { padding: 18px 22px; }
.modal-foot { padding: 0 22px 20px; display: flex; gap: 10px; justify-content: flex-end; }

/* ----------------------------- toast ------------------------------ */

.toast-root { position: fixed; right: 18px; bottom: 18px; z-index: 200; display: grid; gap: 8px; }
.toast {
  background: #0b1220; color: #e8eefb;
  padding: 11px 15px;
  border-radius: 10px;
  font-size: 13px;
  box-shadow: var(--shadow-lg);
  animation: slide .18s ease;
  max-width: 380px;
}
.toast.ok { border-left: 3px solid var(--green); }
.toast.err { border-left: 3px solid #ef4444; }
@keyframes slide { from { transform: translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ----------------------------- auth ------------------------------- */

.auth-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg);
}
.auth-art {
  background: radial-gradient(1200px 600px at 20% 10%, #2b2483, transparent),
              radial-gradient(900px 500px at 90% 90%, #0b3b6f, transparent),
              #0b1220;
  color: #fff;
  padding: 56px;
  display: flex; flex-direction: column; justify-content: space-between;
  position: relative; overflow: hidden;
}
.auth-art::after {
  content: ""; position: absolute; inset: 0;
  background-image: linear-gradient(rgba(255,255,255,.035) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(255,255,255,.035) 1px, transparent 1px);
  background-size: 44px 44px;
  mask-image: radial-gradient(circle at 30% 30%, #000, transparent 75%);
}
.auth-art h2 { font-size: 30px; line-height: 1.25; letter-spacing: -.02em; max-width: 420px; position: relative; }
.auth-art .lede { color: #a9b8d4; margin-top: 14px; max-width: 380px; font-size: 14px; position: relative; }
.auth-art ul { list-style: none; padding: 0; margin: 28px 0 0; display: grid; gap: 12px; position: relative; }
.auth-art li { display: flex; gap: 10px; font-size: 13.5px; color: #cbd8f0; }
.auth-art li b { color: #fff; font-weight: 600; }
.tick { color: #6ee7b7; flex: 0 0 auto; }
.auth-art .foot { font-size: 12px; color: #6b7c99; position: relative; }

.auth-panel { display: grid; place-items: center; padding: 40px 24px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card .brand-mark { margin-bottom: 20px; }
.auth-card h1 { font-size: 22px; }
.auth-card .sub { color: var(--muted); margin-top: 6px; font-size: 13.5px; }
.auth-card form { margin-top: 24px; display: grid; gap: 14px; }
.auth-error {
  background: var(--red-soft); color: #a1251a;
  border: 1px solid #f5d3cf;
  padding: 9px 12px; border-radius: 9px; font-size: 12.5px;
}
.auth-alt { margin-top: 18px; font-size: 13px; color: var(--muted); text-align: center; }
.demo-box { margin-top: 22px; border: 1px dashed var(--line-strong); border-radius: 10px; padding: 12px 14px; }
.demo-box .t { font-size: 11px; text-transform: uppercase; letter-spacing: .07em; color: var(--muted); font-weight: 650; margin-bottom: 7px; }
.demo-row { display: flex; justify-content: space-between; gap: 10px; font-size: 12px; padding: 3px 0; }
.demo-row button { background: none; border: 0; color: var(--brand); cursor: pointer; font-size: 11.5px; padding: 0; }
.demo-row .who { color: var(--ink-2); }

/* ---------------------------- misc -------------------------------- */

.empty { text-align: center; padding: 46px 20px; color: var(--muted); }
.empty .big { font-size: 26px; margin-bottom: 10px; opacity: .55; }
.empty h3 { font-size: 14.5px; color: var(--ink-2); margin-bottom: 5px; }

.tag-list { display: flex; flex-wrap: wrap; gap: 6px; }

.kv { display: grid; grid-template-columns: 132px 1fr; gap: 9px 14px; font-size: 13px; }
.kv dt { color: var(--muted); font-size: 12.5px; }
.kv dd { margin: 0; }

.avatar-pair { display: flex; align-items: center; gap: 8px; }
.avatar.sm { width: 26px; height: 26px; font-size: 10.5px; }

.pill-row { display: flex; gap: 6px; flex-wrap: wrap; }

.callout {
  border-left: 3px solid var(--brand);
  background: var(--brand-soft);
  color: var(--brand-dark);
  padding: 11px 14px;
  border-radius: 0 9px 9px 0;
  font-size: 12.5px;
}
.callout.warn { border-color: var(--amber); background: var(--amber-soft); color: #92400e; }
.callout.bad { border-color: var(--red); background: var(--red-soft); color: #a1251a; }

.role-chip { font-size: 11px; padding: 2px 8px; border-radius: 99px; background: var(--slate-soft); color: var(--ink-2); font-weight: 600; text-transform: capitalize; }
.role-chip.owner { background: #ede9fe; color: #5b21b6; }
.role-chip.admin { background: #e0f2fe; color: #075985; }
.role-chip.manager { background: #dcfce7; color: #166534; }
.role-chip.volunteer { background: #f1f5f9; color: #475569; }

.slot { display: flex; align-items: center; gap: 8px; padding: 7px 0; }
.slot + .slot { border-top: 1px dashed var(--line); }

.lesson { display: flex; gap: 12px; padding: 13px 0; }
.lesson + .lesson { border-top: 1px solid var(--line); }
.lesson .num { width: 26px; height: 26px; border-radius: 50%; background: var(--slate-soft); display: grid; place-items: center; font-size: 11.5px; font-weight: 700; color: var(--muted); flex: 0 0 auto; }
.lesson.done .num { background: var(--green-soft); color: var(--green); }
.lesson.done .t { color: var(--muted); }

/* --------------------------- responsive --------------------------- */

@media (max-width: 1080px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.side { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 860px) {
  .sidebar { position: fixed; z-index: 60; transform: translateX(-100%); transition: transform .2s ease; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .grid.cols-2, .grid.cols-3 { grid-template-columns: minmax(0, 1fr); }
  /* Stat tiles stay two-up: stacked full-width they become tall, empty cards. */
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-4 .stat { padding: 14px 15px; }
  .grid.cols-4 .stat .v { font-size: 23px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .form-grid .span-2 { grid-column: auto; }
  .content { padding: 18px 16px 60px; }
  .topbar { padding: 0 16px; height: 56px; }
  .topbar h1 { font-size: 15.5px; }
  .auth-wrap { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .mobile-toggle { display: inline-flex !important; }
  /* Very small phones drop the stat grid to a single column. */
}

@media (max-width: 359px) {
  .grid.cols-4 { grid-template-columns: minmax(0, 1fr); }
}

.mobile-toggle { display: none; background: none; border: 0; font-size: 18px; cursor: pointer; color: var(--ink-2); }

/* ----------------------- signal flow diagram ---------------------- */

.sig-legend {
  display: flex; flex-wrap: wrap; gap: 14px;
  padding: 14px 16px 0; font-size: 11.5px; color: var(--muted);
}
.sig-legend-item { display: inline-flex; align-items: center; gap: 6px; }
.sig-legend-swatch { width: 10px; height: 10px; border-radius: 3px; display: inline-block; }
.sig-legend-dash { width: 16px; border-top: 2px dashed #64748b; display: inline-block; }

.sig-scroll { overflow-x: auto; padding: 8px 12px 18px; }
.sig-svg { display: block; max-width: none; }
.sig-node text { pointer-events: none; user-select: none; }
.sig-node:hover rect:first-of-type { filter: drop-shadow(0 2px 6px rgba(15, 23, 42, .14)); }
.sig-edge path { transition: stroke-width .12s ease, opacity .12s ease; }
.sig-edge:hover path { stroke-width: 3; opacity: 1; }
.sig-arrow { color: var(--faint); text-align: center; width: 26px; }

/* ------------------------ setup pipeline -------------------------- */

.setup-bar { margin: 0 0 16px; }

.setup-steps { display: grid; }

.setup-step {
  display: flex; align-items: flex-start; gap: 13px;
  padding: 11px 2px; border-top: 1px solid var(--line);
}
.setup-step:first-child { border-top: 0; }

.setup-num {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 24px; height: 24px; border-radius: 999px; margin-top: 1px;
  background: var(--slate-soft); color: var(--muted);
  font-size: 11.5px; font-weight: 650;
}
.setup-step.is-done .setup-num { background: var(--green-soft); color: var(--green); }
.setup-step.is-current .setup-num { background: var(--brand); color: #fff; }

.setup-body { flex: 1; min-width: 0; }
.setup-title { font-size: 13px; font-weight: 620; color: var(--ink-2); }
.setup-step.is-done .setup-title { color: var(--muted); }
.setup-step.is-current .setup-title { color: var(--ink); }
.setup-metric { font-size: 11.5px; color: var(--faint); margin-top: 1px; }
.setup-why {
  font-size: 12px; color: var(--muted); line-height: 1.55;
  margin: 7px 0 0; max-width: 68ch;
}
.setup-action { flex: none; display: flex; align-items: center; padding-top: 1px; }

.setup-steps.is-complete .setup-step { padding: 8px 2px; }
.setup-steps.is-complete .setup-action .badge { opacity: .55; }

/* ------------------------- action tiles --------------------------- */

.action-strip {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fit, minmax(178px, 1fr));
  margin-bottom: 24px;
}
.action-tile {
  display: block; text-decoration: none;
  border: 1px solid var(--line); border-radius: 11px;
  background: #fff; padding: 14px 15px;
  transition: border-color .12s ease, box-shadow .12s ease, transform .12s ease;
}
.action-tile:hover {
  border-color: var(--line-strong);
  box-shadow: 0 4px 14px rgba(15, 23, 42, .06);
  transform: translateY(-1px);
}
.action-tile .action-label {
  font-size: 12.5px; font-weight: 640; color: var(--ink);
}
.action-tile .action-detail { font-size: 11.5px; color: var(--muted); margin-top: 3px; }
.action-tile.is-brand { border-color: #dcd9fb; background: var(--brand-soft); }
.action-tile.is-brand .action-label { color: var(--brand-dark); }
.action-tile.is-warn { border-color: #f0dfb4; background: var(--amber-soft); }
.action-tile.is-warn .action-label { color: var(--amber); }

/* ------------------------ assistant modes ------------------------- */

.mode-tabs {
  display: inline-flex; gap: 4px; padding: 3px;
  background: var(--slate-soft); border-radius: 999px;
}
.mode-tab {
  padding: 6px 15px; border-radius: 999px; text-decoration: none;
  font-size: 12.5px; font-weight: 600; color: var(--muted);
}
.mode-tab:hover { color: var(--ink-2); }
.mode-tab.is-active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(15,23,42,.10); }

.asst-empty { padding: 26px 8px; text-align: center; }
.asst-empty h3 { font-size: 15px; margin: 0 0 6px; color: var(--ink); }
.asst-empty p { max-width: 46ch; margin: 0 auto; line-height: 1.6; }

.asst-msg.is-error .asst-bubble { border-color: #f0c9c4; background: var(--red-soft); }
.asst-msg.is-error .asst-text { color: var(--red); }

/* ------------------- model reply formatting ----------------------- */

/* A reply is prose, so block elements need normal whitespace — the plain-text
   bubble uses pre-wrap, which would double every line break. */
.asst-text.asst-rich { white-space: normal; }
.asst-text.asst-rich p { margin: 0 0 9px; }
.asst-text.asst-rich p:last-child { margin-bottom: 0; }
.asst-text.asst-rich ul { margin: 6px 0 10px; padding-left: 19px; }
.asst-text.asst-rich li { margin: 2px 0; }
.asst-text.asst-rich h3,
.asst-text.asst-rich h4,
.asst-text.asst-rich h5,
.asst-text.asst-rich h6 {
  font-size: 13px; font-weight: 680; color: var(--ink);
  margin: 12px 0 6px; letter-spacing: 0;
}
.asst-text.asst-rich h3:first-child,
.asst-text.asst-rich h4:first-child { margin-top: 0; }
.asst-text.asst-rich strong { color: var(--ink); font-weight: 660; }
.asst-text.asst-rich code {
  font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  font-size: 11.5px; background: var(--slate-soft);
  padding: 1px 5px; border-radius: 4px; color: var(--ink-2);
}
.asst-text.asst-rich a { color: var(--brand); }

.md-table { overflow-x: auto; margin: 8px 0 10px; }
.md-table table {
  border-collapse: collapse; font-size: 11.5px; width: 100%;
  background: #fff; border: 1px solid var(--line); border-radius: 8px;
}
.md-table th {
  text-align: left; padding: 6px 9px; background: var(--surface-2);
  border-bottom: 1px solid var(--line); font-size: 10px;
  text-transform: uppercase; letter-spacing: .05em; color: var(--muted);
  white-space: nowrap;
}
.md-table td { padding: 6px 9px; border-bottom: 1px solid var(--line); vertical-align: top; }
.md-table tr:last-child td { border-bottom: 0; }

/* ---------------------------- chat ------------------------------- */

.chat-grid {
  display: grid; gap: 16px;
  grid-template-columns: 236px minmax(0, 1fr) 236px;
  align-items: start;
}
@media (max-width: 1180px) {
  .chat-grid { grid-template-columns: 216px minmax(0, 1fr); }
  .chat-grid > :nth-child(3) { grid-column: 1 / -1; display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
  .chat-grid > :nth-child(3) .card { margin-top: 0 !important; }
}
@media (max-width: 780px) {
  .chat-grid { grid-template-columns: minmax(0, 1fr); }
  .chat-grid > :nth-child(3) { grid-template-columns: 1fr; }
}

.chat-side { position: sticky; top: 16px; }
.chat-list { max-height: 62vh; overflow-y: auto; }
.chat-group {
  padding: 10px 14px 4px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em; color: var(--faint);
}
.chat-item {
  display: flex; align-items: center; gap: 8px;
  padding: 9px 14px; text-decoration: none; color: inherit;
  border-left: 3px solid transparent;
}
.chat-item:hover { background: var(--surface-2); }
.chat-item.is-active { background: var(--brand-soft); border-left-color: var(--brand); }
.chat-item-main { flex: 1; min-width: 0; }
.chat-item-name {
  font-size: 12.5px; font-weight: 620; color: var(--ink);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-kind { font-size: 9.5px; font-weight: 600; color: var(--faint); margin-left: 4px; }
.chat-item-snippet {
  font-size: 11px; color: var(--muted); margin-top: 1px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.chat-unread {
  flex: none; min-width: 18px; height: 18px; border-radius: 999px;
  background: var(--brand); color: #fff; font-size: 10.5px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; padding: 0 5px;
}

.chat-log {
  max-height: 54vh; overflow-y: auto; padding: 16px 18px;
  background: var(--surface-2); display: flex; flex-direction: column; gap: 12px;
}

.chat-post { display: flex; gap: 10px; align-items: flex-start; }
.chat-post.is-mine { flex-direction: row-reverse; }
.chat-avatar {
  flex: none; width: 26px; height: 26px; border-radius: 999px;
  background: var(--slate-soft); color: var(--muted);
  font-size: 10.5px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.chat-bubble {
  max-width: 78%; background: #fff; border: 1px solid var(--line);
  border-radius: 11px; padding: 9px 12px;
}
.chat-post.is-mine .chat-bubble { background: var(--brand-soft); border-color: #dbd7fb; }
.chat-meta { display: flex; align-items: baseline; gap: 7px; margin-bottom: 3px; }
.chat-meta .strong { font-size: 12px; }
.chat-bubble .asst-text { font-size: 12.8px; }
.chat-photo { width: 100%; max-width: 260px; border-radius: 8px; display: block; margin-top: 8px; }
/* An action on every message is noise: reveal it when the message is under the
   pointer, or when keyboard focus reaches it. */
.chat-post-actions {
  margin-top: 7px; opacity: 0;
  transition: opacity .12s ease;
}
.chat-post:hover .chat-post-actions,
.chat-post:focus-within .chat-post-actions { opacity: 1; }
.chat-link {
  border: 0; background: none; padding: 0; cursor: pointer;
  font-size: 11px; color: var(--muted); font-family: inherit;
}
.chat-link:hover { color: var(--brand); text-decoration: underline; }

.chat-todo {
  margin-top: 8px; padding: 6px 9px; border-radius: 8px;
  background: var(--amber-soft); border: 1px solid #f0dfb4;
}
.chat-todo.is-done { background: var(--surface-2); border-color: var(--line); opacity: .65; }
.chat-todo.is-done .strong { text-decoration: line-through; }
.chat-side .chat-todo { background: transparent; border: 0; padding: 2px 0; margin: 0; }
.chat-side .chat-todo.is-done { background: transparent; }

/* --------------------------- photographs -------------------------- */

.photo-grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(132px, 1fr));
}
.photo-tile {
  margin: 0; border: 1px solid var(--line); border-radius: 9px;
  overflow: hidden; background: #fff;
}
.photo-tile img {
  display: block; width: 100%; height: 104px; object-fit: cover;
  background: var(--surface-2);
}
.photo-tile figcaption {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 9px; color: var(--muted);
  border-top: 1px solid var(--line);
}
.photo-tile figcaption .small {
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.photo-del {
  margin-left: auto; border: 0; background: none; cursor: pointer;
  color: var(--faint); font-size: 12px; line-height: 1; padding: 2px 3px;
}
.photo-del:hover { color: var(--red); }

/* --------------------------- assistant ---------------------------- */

.asst-intro h2 { font-size: 17px; margin: 0 0 6px; }
.asst-steps { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 16px; }
.asst-step {
  display: flex; align-items: center; gap: 7px;
  font-size: 12px; color: var(--ink-2); background: var(--surface-2);
  border: 1px solid var(--line); border-radius: 999px; padding: 5px 12px;
}
.asst-step span {
  display: inline-flex; width: 18px; height: 18px; border-radius: 999px;
  background: var(--brand); color: #fff; font-size: 10.5px; font-weight: 650;
  align-items: center; justify-content: center;
}

/* The transcript scrolls, the composer does not. */
.asst-log {
  max-height: 54vh; overflow-y: auto;
  padding: 18px 20px; background: var(--surface-2);
  display: flex; flex-direction: column;
}
.asst-msg { display: flex; margin-bottom: 12px; }
.asst-msg.user { justify-content: flex-end; }
.asst-bubble {
  max-width: 80%; border-radius: 12px; padding: 11px 14px;
  background: #fff; border: 1px solid var(--line);
}
.asst-msg.user .asst-bubble { background: var(--brand-soft); border-color: #dbd7fb; }
.asst-text { white-space: pre-wrap; font-size: 13px; line-height: 1.55; color: var(--ink-2); }
.asst-msg.user .asst-text { color: var(--ink); }

.asst-thumbs, .asst-pending { display: flex; gap: 8px; flex-wrap: wrap; }
.asst-thumbs { margin-top: 10px; }
.asst-pending { margin-bottom: 10px; }
.asst-pending.is-empty { display: none; }
.asst-thumb {
  position: relative; width: 84px; height: 84px; border-radius: 8px;
  overflow: hidden; border: 1px solid var(--line); background: #fff;
}
.asst-thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.asst-thumb-x {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px;
  border-radius: 999px; border: 0; cursor: pointer; line-height: 1;
  background: rgba(15, 23, 42, .72); color: #fff; font-size: 13px;
}

.asst-staged {
  margin-top: 12px; padding: 10px 12px;
  border: 1px dashed var(--line-strong); border-radius: 9px; background: #fff;
}
.asst-staged-head { display: flex; align-items: center; gap: 10px; font-size: 12px; font-weight: 620; }
.asst-staged-head .btn { margin-left: auto; }
.asst-staged ul { margin: 8px 0 0; padding-left: 16px; }
.asst-staged li { font-size: 12px; color: var(--muted); line-height: 1.65; }

.asst-foot { border-top: 1px solid var(--line); padding: 14px 16px; }
.asst-chips { display: flex; gap: 8px; flex-wrap: wrap; padding: 0 16px 12px; }
.chip {
  border: 1px solid var(--line-strong); background: #fff; border-radius: 999px;
  padding: 4px 11px; font-size: 12px; cursor: pointer; color: var(--ink-2);
  font-family: inherit;
}
.chip:hover { border-color: var(--brand); color: var(--brand); }

.asst-composer textarea {
  width: 100%; resize: vertical; min-height: 56px;
  border: 1px solid var(--line-strong); border-radius: 9px;
  padding: 9px 11px; font-family: inherit; font-size: 13px; color: var(--ink);
  background: #fff;
}
.asst-composer textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 2px rgba(67, 56, 202, .10);
}
.asst-composer textarea:disabled { background: var(--surface-2); color: var(--faint); }

/* ------------------------- review queue --------------------------- */

.review-item {
  border: 1px solid var(--line); border-radius: 10px;
  overflow: hidden; background: #fff;
}
.review-item + .review-item { margin-top: 14px; }
.review-item-head {
  display: flex; align-items: flex-start; gap: 12px;
  padding: 12px 16px; background: var(--surface-2);
  border-bottom: 1px solid var(--line);
}
.review-item-title { font-size: 13.5px; font-weight: 620; color: var(--ink); line-height: 1.35; }
.review-item-sub { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.review-item-body { padding: 2px 16px 12px; }
.review-item-body table { width: 100%; border-collapse: collapse; }
.review-item-body th {
  padding: 8px 10px 6px 0; background: none; border-bottom: 1px solid var(--line);
  text-align: left; font-size: 10px;
}
.review-item-body td { padding: 7px 10px 7px 0; border-bottom: 1px solid var(--line); }
.review-item-body tr:last-child td { border-bottom: 0; }
.review-before { color: var(--muted); }
.review-after { font-weight: 600; color: var(--ink); }

/* ------------------------- patch sheet grid ----------------------- */

.sheet-block { border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.sheet-block-head {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 14px; background: var(--surface-2); border-bottom: 1px solid var(--line);
}
.sheet-block-title {
  font-size: 11px; text-transform: uppercase; letter-spacing: .07em;
  font-weight: 650; color: var(--muted);
}
/* Grow to fit the columns and let the wrapper scroll; squeezing 19 desk
   columns into the viewport truncates every value. */
.sheet-table { width: max-content; min-width: 100%; border-collapse: collapse; font-size: 12.5px; }
.sheet-table th {
  background: #fff; border-bottom: 1px solid var(--line);
  padding: 8px 10px; font-size: 10px; white-space: nowrap;
}
.sheet-table td { padding: 2px 4px; border-bottom: 1px solid var(--line); }
.sheet-table tbody tr:last-child td { border-bottom: 0; }
.sheet-table tbody tr:hover { background: #fafbfe; }
.sheet-ch { width: 58px; }
.sheet-input {
  width: 100%; min-width: 86px;
  border: 1px solid transparent; background: transparent;
  padding: 5px 7px; border-radius: 6px; font-size: 12.5px;
}
.sheet-input:hover { border-color: var(--line-strong); }
.sheet-input:focus {
  outline: none; border-color: var(--brand); background: #fff;
  box-shadow: 0 0 0 2px rgba(67, 56, 202, .10);
}
.sheet-input--error { border-color: var(--red-fill); background: var(--red-soft); }
.sheet-check { width: 15px; height: 15px; accent-color: var(--brand); cursor: pointer; }
.sheet-matrix td, .sheet-matrix th { border-left: 1px solid var(--line); }
.sheet-matrix td:first-child, .sheet-matrix th:first-child { border-left: 0; }

/* ==================================================================
   Touch, small screens, and installed (PWA) mode
   ================================================================== */

/*
 * A phone is not a narrow desktop. The card header in particular is a single
 * flex row of title + spacer + actions, and actions that cannot wrap push the
 * card - and the page - wider than the screen. Wrapping is the fix; the spacer
 * becomes pointless once the title owns its own line.
 */
@media (max-width: 560px) {
  .card-head {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 10px;
    padding: 14px 16px;
  }
  .card-head h2 { flex: 1 1 100%; }
  .card-head .spacer { display: none; }
  .card-head .btn, .card-head > .row { flex: 0 0 auto; }

  .card-body { padding: 16px; }
  .card-body.flush { padding: 0; }
  .content { padding: 16px 12px 56px; }

  /* Modals get the screen rather than a fixed width, and the footer stacks so
     "Cancel" and the primary action stay reachable. */
  .modal { width: calc(100vw - 20px); max-height: calc(100vh - 40px); }
  .modal-head { padding: 14px 16px 0; }
  .modal-body { padding: 14px 16px; }
  .modal-foot { padding: 0 16px 16px; flex-wrap: wrap; }
  .modal-foot .btn { flex: 1 1 auto; justify-content: center; }

  /* Tables still scroll, but silently: a hint that there is more to the right. */
  .table-wrap { -webkit-overflow-scrolling: touch; }
  .table-wrap table { min-width: 0; }

  /* A long URL, token prefix or id must wrap, not widen the page. */
  .mono, .t-sub, .hint, input[type="text"] { overflow-wrap: anywhere; }

  .tok, .t-main { overflow-wrap: anywhere; }
}

/* Fingers are not pointers. 40px is a comfortable floor; form controls go to
   16px so iOS does not zoom the page on focus. */
@media (pointer: coarse) {
  .btn, .btn-sm { min-height: 40px; }
  .btn-sm { padding: 8px 12px; }
  .nav a { min-height: 44px; }
  .chat-item { min-height: 48px; }
  .tab, .seg-btn, .chip { min-height: 36px; }
  input, select, textarea { font-size: 16px; }
  .lesson .num { width: 26px; height: 26px; }
}

/*
 * Notches and the home indicator. `viewport-fit=cover` hands the app the whole
 * screen, which means nothing is inset for us any more - the insets have to be
 * honoured here, or the installable app puts its own navigation under the
 * hardware. Insets are 0 in a normal browser tab, so this costs nothing there.
 */
@supports (padding: env(safe-area-inset-top)) {
  .shell {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
  }
  .topbar {
    height: auto;
    min-height: 62px;
    padding-top: env(safe-area-inset-top);
    padding-left: max(16px, env(safe-area-inset-left));
    padding-right: max(16px, env(safe-area-inset-right));
  }
  .sidebar {
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .sidebar-foot { padding-bottom: calc(14px + env(safe-area-inset-bottom)); }
  .content { padding-bottom: calc(64px + env(safe-area-inset-bottom)); }
  .toast-root { bottom: calc(18px + env(safe-area-inset-bottom)); }
  .mobile-toggle { margin-left: calc(-1 * env(safe-area-inset-left)); }
}

@media (max-width: 860px) and (pointer: coarse) {
  .topbar { min-height: 56px; }
  .content { padding-bottom: calc(56px + env(safe-area-inset-bottom)); }
}
/*
 * Grid and flex children default to min-width: auto, which means a table inside
 * one refuses to shrink and pushes its own container off the screen. The table
 * should scroll inside its wrapper, not widen the page.
 */
.grid > *, .stack > *, .grid.side > * { min-width: 0; }
.table-wrap { min-width: 0; max-width: 100%; }
/*
 * Squashing is worse than scrolling. Left to fit, a table's flexible text column
 * collapses and an asset name wraps to two characters per line, which is
 * unreadable; a minimum width keeps the text intact and lets the wrapper scroll.
 */
@media (max-width: 560px) {
  .table-wrap table { min-width: 32rem; }
  .table-wrap th, .table-wrap td { white-space: nowrap; }
}

/* ---------------------- the mobile navigation drawer ---------------------- */

/*
 * Closed by default and only meaningful on the narrow layout. The scrim is what
 * makes "tap anywhere else" work; without it the drawer covers the button that
 * opened it and the only way out is a reload.
 */
.sidebar-close { display: none; }

.sidebar-scrim {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 55;                 /* under the sidebar (60), over the page */
  background: rgba(15, 23, 42, .45);
  border: 0;
  padding: 0;
}

@media (max-width: 860px) {
  .sidebar-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    margin-left: auto;
    width: 36px;
    height: 36px;
    border: 0;
    border-radius: 8px;
    background: rgba(255, 255, 255, .10);
    color: #e8eefb;
    font-size: 14px;
    cursor: pointer;
  }
  .sidebar-close:active { background: rgba(255, 255, 255, .18); }

  .sidebar-scrim.open { display: block; }

  /* Nothing behind the drawer should scroll while it is open. */
  body.nav-open { overflow: hidden; }

  /* Keep the drawer clear of the notch and the home indicator. */
  .sidebar {
    width: min(84vw, 300px);
    max-height: 100vh;
    overflow-y: auto;
    padding-bottom: env(safe-area-inset-bottom);
    transform: translateX(-105%);
  }
  .sidebar.open { transform: none; }
}
  /* 100vh lies about the visible area while the address bar is showing. */
  .sidebar { height: 100vh; height: 100dvh; }

/* The version stamp beside the product name. The tag above it is uppercased, which
   would turn "v1.0.0" into "V1.0.0", so this keeps its own casing and dims down. */
.sidebar-brand .brand-version {
  text-transform: none;
  letter-spacing: 0;
  opacity: .72;
  white-space: nowrap;
}
