/* Maati Living app styles. Sections: base, layout, navigation, components, views.
   Class names are flat (one class per thing) so rules don't fight each other. */

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: var(--fs-base) / var(--lh) var(--font);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
h1, h2, h3 { margin: 0; line-height: var(--lh-tight); font-weight: 650; letter-spacing: -0.01em; }
p { margin: 0; }
a { color: var(--primary); }
button, input, select, textarea { font: inherit; color: inherit; }
img, svg { display: block; }
[hidden] { display: none !important; }

:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; border-radius: var(--r-sm); }

.skip-link {
  position: absolute; left: var(--s3); top: -60px; z-index: 100;
  padding: var(--s2) var(--s4); background: var(--surface); border-radius: var(--r-sm);
}
.skip-link:focus { top: var(--s3); }

.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap;
}

.icon {
  width: 20px; height: 20px; flex: none;
  fill: none; stroke: currentColor; stroke-width: 1.75; stroke-linecap: round; stroke-linejoin: round;
}
.icon-sm { width: 16px; height: 16px; }

/* ---------- Boot and full-page messages ---------- */
.boot, .fullpage {
  min-height: 100dvh; display: grid; place-items: center; padding: var(--s5); text-align: center;
}
.boot p { color: var(--text-muted); }
.fullpage-card { max-width: 420px; display: grid; gap: var(--s3); justify-items: center; }
.fullpage-card h1 { font-size: var(--fs-xl); }
.fullpage-card p { color: var(--text-muted); }

/* ---------- Layout ---------- */
.layout { min-height: 100dvh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0; width: var(--sidebar-w);
  display: none; flex-direction: column;
  background: var(--surface); border-right: 1px solid var(--border);
}

.workspace { min-height: 100dvh; padding-bottom: calc(var(--bottomnav-h) + env(safe-area-inset-bottom)); }

.topbar {
  position: sticky; top: 0; z-index: 20;
  height: var(--topbar-h); display: flex; align-items: center; gap: var(--s3);
  padding: 0 var(--s4); background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}

.main { padding: var(--s5) var(--s4) var(--s6); max-width: 1180px; margin: 0 auto; }
.main:focus { outline: none; }


/* ---------- Brand ---------- */
.brand { display: flex; align-items: center; gap: var(--s3); text-decoration: none; color: var(--text); }
.brand-mark { width: 36px; height: 36px; border-radius: var(--r-sm); object-fit: cover; }
.brand-name { font-weight: 650; font-size: var(--fs-md); line-height: 1.1; }
.brand-sub { font-size: var(--fs-xs); color: var(--text-muted); }
.sidebar-brand { padding: var(--s4) var(--s4) var(--s3); }

/* ---------- Sidebar navigation ---------- */
.nav { flex: 1; overflow-y: auto; padding: var(--s2) var(--s3) var(--s4); }
.nav-group + .nav-group { margin-top: var(--s4); }
.nav-group-label { padding: 0 var(--s3) var(--s1); font-size: var(--fs-xs); color: var(--text-muted); font-weight: 600; }
.nav-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.nav-link {
  display: flex; align-items: center; gap: var(--s3); min-height: 38px;
  padding: 0 var(--s3); border-radius: var(--r-sm);
  color: var(--text); text-decoration: none; font-size: var(--fs-sm); font-weight: 500;
  transition: background var(--t-fast) var(--ease);
}
.nav-link .icon { color: var(--text-muted); }
.nav-link:hover { background: var(--surface-sunken); }
.nav-link[aria-current="page"] { background: var(--primary-soft); color: var(--primary-hover); font-weight: 600; }
.nav-link[aria-current="page"] .icon { color: var(--primary); }

.sidebar-foot { padding: var(--s3) var(--s4) var(--s4); border-top: 1px solid var(--border); font-size: var(--fs-xs); color: var(--text-muted); }

/* ---------- Topbar ---------- */
.topbar-brand > span { display: none; }
.topbar-spacer { display: none; }
.topbar-actions { display: flex; align-items: center; gap: var(--s2); }
.icon-button {
  width: 40px; height: 40px; display: grid; place-items: center;
  border: 0; border-radius: var(--r-pill); background: transparent; color: var(--text-muted); cursor: pointer;
}
.icon-button:hover { background: var(--surface-sunken); color: var(--text); }
.icon-button:disabled { opacity: 0.45; cursor: not-allowed; }
.avatar {
  width: 34px; height: 34px; border-radius: var(--r-pill); display: grid; place-items: center;
  background: var(--primary); color: var(--on-primary); font-size: var(--fs-sm); font-weight: 650;
}

/* ---------- Global search ---------- */
.search { position: relative; flex: 1; max-width: 460px; }
.search-input {
  width: 100%; height: 40px; padding: 0 var(--s3) 0 38px;
  border: 1px solid var(--border); border-radius: var(--r-pill); background: var(--surface);
}
.search-input::placeholder { color: var(--text-muted); }
.search-input:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }
.search-icon { position: absolute; left: 12px; top: 10px; color: var(--text-muted); pointer-events: none; }
.search-key {
  position: absolute; right: 10px; top: 9px; padding: 0 6px; font-size: var(--fs-xs);
  border: 1px solid var(--border); border-radius: 4px; color: var(--text-muted); background: var(--surface-sunken);
}
.search-results {
  position: absolute; left: 0; right: 0; top: calc(100% + 6px); z-index: 30;
  list-style: none; margin: 0; padding: var(--s2); max-height: 60vh; overflow-y: auto;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-overlay);
}
.search-option { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s2) var(--s3); border-radius: var(--r-sm); cursor: pointer; }
.search-option[aria-selected="true"] { background: var(--primary-soft); }
.search-option small { display: block; color: var(--text-muted); font-size: var(--fs-xs); }
.search-empty { padding: var(--s3); color: var(--text-muted); font-size: var(--fs-sm); }
@media (max-width: 599px) { .search-key { display: none; } }

/* ---------- Bottom navigation (phones) ---------- */
.bottom-nav {
  position: fixed; inset: auto 0 0 0; z-index: 20;
  display: grid; grid-template-columns: repeat(5, 1fr);
  height: calc(var(--bottomnav-h) + env(safe-area-inset-bottom)); padding-bottom: env(safe-area-inset-bottom);
  background: var(--surface); border-top: 1px solid var(--border);
}
.bottom-link {
  display: grid; justify-items: center; align-content: center; gap: 2px;
  border: 0; background: none; color: var(--text-muted); text-decoration: none;
  font-size: 11px; font-weight: 500; cursor: pointer;
}
.bottom-link[aria-current="page"] { color: var(--primary); font-weight: 650; }
.bottom-link[aria-current="page"] .icon { stroke-width: 2.25; }

/* "More" sheet uses the native <dialog> (focus trap and Esc for free). */
.sheet {
  width: 100%; max-width: 520px; max-height: 85dvh; margin: auto auto 0; padding: 0;
  border: 0; border-radius: var(--r-lg) var(--r-lg) 0 0; background: var(--surface); color: var(--text);
}
.sheet::backdrop { background: rgb(35 38 43 / 0.4); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--border); }
.sheet-body { padding: var(--s2) var(--s2) calc(var(--s5) + env(safe-area-inset-bottom)); overflow-y: auto; }
@media (min-width: 600px) { .sheet { margin: auto; border-radius: var(--r-lg); } }

/* ---------- Page header ---------- */
.page-head { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s3) var(--s5); margin-bottom: var(--s5); }
.page-title { font-size: var(--fs-2xl); }
.page-lead { margin-top: var(--s2); max-width: 62ch; color: var(--text-muted); }
.page-actions { display: flex; flex-wrap: wrap; gap: var(--s2); }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 40px; padding: 0 var(--s4); border: 1px solid var(--border-strong); border-radius: var(--r-sm);
  background: var(--surface); color: var(--text); font-weight: 600; font-size: var(--fs-sm);
  text-decoration: none; cursor: pointer; transition: background var(--t-fast) var(--ease), border-color var(--t-fast) var(--ease);
}
.btn:hover { background: var(--surface-sunken); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-quiet { border-color: transparent; background: transparent; color: var(--primary); }
.btn-quiet:hover { background: var(--primary-soft); }
.btn-danger { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)); }

/* ---------- Panels ---------- */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); }
.panel-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); padding: var(--s4) var(--s5) 0; }
.panel-title { font-size: var(--fs-md); font-weight: 650; }
.panel-sub { margin-top: 2px; font-size: var(--fs-sm); color: var(--text-muted); }
.panel-body { padding: var(--s4) var(--s5) var(--s5); }
.stack { display: grid; gap: var(--s4); }
.grid-2 { display: grid; gap: var(--s4); align-items: start; }
@media (min-width: 900px) { .grid-2 { grid-template-columns: 1fr 1fr; } }

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px;
  border-radius: var(--r-pill); font-size: var(--fs-xs); font-weight: 600; white-space: nowrap;
  background: var(--surface-sunken); color: var(--text-muted); border: 1px solid var(--border);
}
.badge-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.badge-warning { background: var(--warning-soft); color: var(--warning); border-color: transparent; }
.badge-danger { background: var(--danger-soft); color: var(--danger); border-color: transparent; }
.badge-info { background: var(--info-soft); color: var(--info); border-color: transparent; }
.badge-accent { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
/* Status dot uses the pipeline colour; the text stays dark for contrast. */
.status { background: var(--surface); color: var(--text); }
.status::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--dot, var(--text-muted)); }
.status-planned { --dot: var(--status-planned); }
.status-shot { --dot: var(--status-shot); }
.status-editing { --dot: var(--status-editing); }
.status-needs_approval { --dot: var(--status-approval); background: var(--accent-soft); border-color: transparent; }
.status-approved { --dot: var(--status-approved); }
.status-scheduled { --dot: var(--status-scheduled); }
.status-posted { --dot: var(--status-posted); }

/* ---------- Empty states ---------- */
.empty { display: grid; justify-items: start; gap: var(--s2); padding: var(--s5); border: 1px dashed var(--border-strong); border-radius: var(--r-md); background: var(--surface-sunken); }
.empty-icon { color: var(--primary); }
.empty-title { font-weight: 650; }
.empty-body { color: var(--text-muted); max-width: 56ch; }
.empty .btn { margin-top: var(--s2); }

/* ---------- Skeleton loaders ---------- */
.skeleton { display: grid; gap: var(--s3); }
.skeleton-line {
  height: 14px; border-radius: var(--r-sm);
  background: linear-gradient(90deg, var(--stone-300) 0%, var(--stone-100) 50%, var(--stone-300) 100%);
  background-size: 200% 100%; animation: shimmer 1.4s linear infinite;
}
.skeleton-line:nth-child(3n) { width: 60%; }
.skeleton-line:nth-child(3n+2) { width: 85%; }
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

/* ---------- Notices ---------- */
.notice { display: flex; gap: var(--s3); align-items: flex-start; padding: var(--s3) var(--s4); border-radius: var(--r-md); font-size: var(--fs-sm); background: var(--info-soft); color: var(--text); }
.notice .icon { color: var(--info); margin-top: 1px; }
.notice-warning { background: var(--warning-soft); }
.notice-warning .icon { color: var(--warning); }
.notice-danger { background: var(--danger-soft); }
.notice-danger .icon { color: var(--danger); }

/* ---------- Form fields ---------- */
.field { display: grid; gap: 6px; }
.field-label { font-size: var(--fs-sm); font-weight: 600; }
.field-help { font-size: var(--fs-xs); color: var(--text-muted); }
.input {
  width: 100%; min-height: 42px; padding: 0 var(--s3);
  border: 1px solid var(--border-strong); border-radius: var(--r-sm); background: var(--surface);
}
.input:focus { outline: 2px solid var(--focus); outline-offset: 0; border-color: transparent; }

/* ---------- Toasts (see public/css/features.css) ---------- */

/* ---------- Today view ---------- */
.today-hero { position: relative; padding: var(--s2) 0 72px; margin-bottom: var(--s5); }
.today-date { font-size: var(--fs-sm); color: var(--text-muted); font-weight: 500; }
.today-greeting { margin-top: var(--s1); font-size: var(--fs-3xl); font-weight: 680; letter-spacing: -0.02em; }
.today-line { margin-top: var(--s2); color: var(--text-muted); max-width: 52ch; }
/* The ridge: a Kumaon skyline drawn once on load. */
.ridge { position: absolute; left: 0; right: 0; bottom: 0; width: 100%; height: 56px; color: var(--primary); }
.ridge-far { color: var(--stone-400); }
.ridge path { fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linejoin: round; vector-effect: non-scaling-stroke; }
/* Dash length in screen pixels (non-scaling stroke), longer than any ridge can be. */
.ridge-draw path { stroke-dasharray: 3000; stroke-dashoffset: 3000; animation: ridge 1.6s var(--ease) 0.15s forwards; }
.ridge-sun { fill: var(--highlight); stroke: none; opacity: 0; animation: sun 0.6s var(--ease) 1.4s forwards; }
@keyframes ridge { to { stroke-dashoffset: 0; } }
@keyframes sun { to { opacity: 1; } }

.phases { list-style: none; margin: 0; padding: 0; display: grid; }
.phase { display: grid; grid-template-columns: 28px 1fr auto; gap: var(--s3); align-items: start; padding: var(--s3) 0; border-top: 1px solid var(--border); }
.phase:first-child { border-top: 0; padding-top: 0; }
.phase-num {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  font-size: var(--fs-xs); font-weight: 700; font-family: var(--font-num);
  border: 1px solid var(--border-strong); color: var(--text-muted);
}
.phase-done .phase-num { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.phase-next .phase-num { border-color: var(--accent); color: var(--accent); }
.phase-name { font-weight: 600; }
.phase-desc { font-size: var(--fs-sm); color: var(--text-muted); }

.swatches { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(120px, 100%), 1fr)); gap: var(--s3); }
.swatch { border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; background: var(--surface); }
.swatch-chip { height: 56px; }
.swatch-label { padding: var(--s2) var(--s3); font-size: var(--fs-xs); }
.swatch-label b { display: block; font-size: var(--fs-sm); }
.row { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }

/* ---------- Desktop layout (kept last so it wins over the phone defaults above) ---------- */
@media (min-width: 900px) {
  .sidebar { display: flex; }
  .workspace { margin-left: var(--sidebar-w); padding-bottom: 0; }
  .topbar { padding: 0 var(--s5); }
  .topbar-spacer { display: block; flex: 1; }
  .main { padding: var(--s6) var(--s6) var(--s7); }
  .bottom-nav, .topbar-brand { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-delay: 0ms !important; transition-duration: 0.01ms !important; }
  .ridge-draw path { stroke-dashoffset: 0; }
  .ridge-sun { opacity: 1; }
}

/* =====================================================================
   Phase 2: sign-in screens, forms, dialogs, menus, people and properties
   ===================================================================== */

/* ---------- Sign-in pages ---------- */
.auth { min-height: 100dvh; display: grid; place-items: center; padding: var(--s5) var(--s4); }
.auth-card {
  width: min(100%, 420px); display: grid; gap: var(--s4);
  padding: var(--s6) var(--s5); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg);
}
.auth-brand { display: flex; align-items: center; gap: var(--s3); }
.auth-brand .brand-mark { width: 40px; height: 40px; }
.auth-title { font-size: var(--fs-xl); }
.auth-lead { color: var(--text-muted); margin-top: calc(-1 * var(--s2)); }
.auth-foot { font-size: var(--fs-sm); color: var(--text-muted); text-align: center; }

/* ---------- Forms ---------- */
.form { display: grid; gap: var(--s4); }
.form-inline { grid-template-columns: 1fr; align-items: end; }
@media (min-width: 600px) { .form-inline { grid-template-columns: 1fr auto; } .form-inline .form-error { grid-column: 1 / -1; } }
.btn-block { width: 100%; }
.field-optional { font-weight: 400; color: var(--text-muted); }
.form-error { margin: 0; padding: var(--s2) var(--s3); border-radius: var(--r-sm); background: var(--danger-soft); color: var(--danger); font-size: var(--fs-sm); font-weight: 500; }
.select { appearance: none; padding-right: 36px; background-image: linear-gradient(45deg, transparent 50%, var(--text-muted) 50%), linear-gradient(135deg, var(--text-muted) 50%, transparent 50%); background-position: calc(100% - 18px) 50%, calc(100% - 13px) 50%; background-size: 5px 5px; background-repeat: no-repeat; }
.checks { border: 0; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.checks legend { margin-bottom: var(--s2); padding: 0; }
.check { display: flex; gap: var(--s3); align-items: flex-start; font-size: var(--fs-sm); cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 2px 0 0; accent-color: var(--primary); flex: none; }
.check small { display: block; }
.steps { margin: 0; padding-left: 1.2em; display: grid; gap: var(--s3); }
.code-box { margin: var(--s2) 0; padding: var(--s3); border-radius: var(--r-sm); background: var(--surface-sunken); border: 1px solid var(--border); overflow-wrap: anywhere; }
.code-box code, .codes code { font: 600 var(--fs-sm) / 1.5 ui-monospace, "Cascadia Mono", Consolas, monospace; letter-spacing: 0.02em; }
.codes { list-style: none; margin: 0; padding: var(--s3); display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s2) var(--s4); background: var(--surface-sunken); border-radius: var(--r-sm); }

/* ---------- Dialogs ---------- */
.modal {
  width: min(560px, calc(100vw - 24px)); max-height: min(88dvh, 760px); padding: 0;
  border: 0; border-radius: var(--r-lg); background: var(--surface); color: var(--text); box-shadow: var(--shadow-overlay);
}
.modal-wide { width: min(820px, calc(100vw - 24px)); }
.modal::backdrop { background: rgb(35 38 43 / 0.45); }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s3) var(--s3) var(--s3) var(--s5); border-bottom: 1px solid var(--border); }
.modal-body { padding: var(--s5); overflow-y: auto; }
.modal-foot { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: var(--s2); padding: var(--s3) var(--s5) var(--s4); border-top: 1px solid var(--border); }

/* ---------- Account menu and workspace switcher ---------- */
.menu-wrap { position: relative; }
.avatar-button { padding: 0; border: 0; border-radius: var(--r-pill); background: none; cursor: pointer; }
.menu {
  position: absolute; right: 0; top: calc(100% + 8px); z-index: 40; min-width: 240px; padding: var(--s2);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); box-shadow: var(--shadow-overlay);
}
.menu-head { display: grid; padding: var(--s2) var(--s3) var(--s3); border-bottom: 1px solid var(--border); margin-bottom: var(--s2); }
.menu-head span { font-size: var(--fs-xs); color: var(--text-muted); }
.menu-item {
  display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 40px; padding: 0 var(--s3);
  border: 0; border-radius: var(--r-sm); background: none; color: var(--text); text-decoration: none; font-size: var(--fs-sm); cursor: pointer; text-align: left;
}
.menu-item:hover { background: var(--surface-sunken); }
.tenant-select { width: auto; max-width: 180px; min-height: 36px; font-size: var(--fs-sm); font-weight: 600; }
@media (max-width: 599px) { .tenant-select { max-width: 110px; } }

/* ---------- People and properties ---------- */
.people { list-style: none; margin: 0; padding: 0; display: grid; }
.person { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s3) var(--s4); padding: var(--s3) 0; border-top: 1px solid var(--border); }
.person:first-child { border-top: 0; padding-top: 0; }
.person.is-inactive .person-name { color: var(--text-muted); }
.person-main { flex: 1 1 240px; min-width: 0; }
.person-name { font-weight: 600; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.person-meta { font-size: var(--fs-sm); color: var(--text-muted); }
.row-actions { display: flex; flex-wrap: wrap; gap: var(--s2); }
.row-actions .btn { min-height: 34px; padding: 0 var(--s3); }
.avatar-soft { background: var(--primary-soft); color: var(--primary-hover); flex: none; }
.property-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s4); grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); }
.property-card { display: grid; gap: var(--s4); align-content: space-between; padding: var(--s4) var(--s5); }
.property-card .panel-title { display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.property-card.is-inactive { opacity: 0.7; }
.mini-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }

/* ---------- Tabs and activity ---------- */
.tabs { display: flex; gap: var(--s1); margin-bottom: var(--s4); border-bottom: 1px solid var(--border); overflow-x: auto; }
.tab { padding: var(--s3) var(--s4); border: 0; border-bottom: 2px solid transparent; background: none; color: var(--text-muted); font-weight: 600; font-size: var(--fs-sm); cursor: pointer; white-space: nowrap; }
.tab[aria-selected="true"] { color: var(--primary-hover); border-bottom-color: var(--primary); }
.activity { list-style: none; margin: 0; padding: 0; display: grid; }
.activity li { display: grid; grid-template-columns: 120px 1fr; gap: var(--s3); padding: var(--s2) 0; border-top: 1px solid var(--border); font-size: var(--fs-sm); }
.activity li:first-child { border-top: 0; }
.activity time { color: var(--text-muted); }
.activity .is-warning { background: var(--warning-soft); }
@media (max-width: 599px) { .activity li { grid-template-columns: 1fr; gap: 2px; } }

/* =====================================================================
   Phase 3: tasks, CRM, OTA tracker, volunteers, audits, scripts, reports
   ===================================================================== */

/* ---------- Form layout ---------- */
.form-row { display: grid; gap: var(--s4); }
@media (min-width: 600px) { .form-row { grid-template-columns: 1fr 1fr; } }
.form-grid { display: grid; gap: var(--s4); }
@media (min-width: 700px) { .form-grid { grid-template-columns: 1fr 1fr; } .form-grid .field:has(textarea) { grid-column: 1 / -1; } }
.form-section { margin: 0; padding: var(--s4) 0 0; border: 0; border-top: 1px solid var(--border); }
.form-section legend { padding: 0 var(--s2) 0 0; font-weight: 650; font-size: var(--fs-md); }
.textarea { min-height: 84px; padding: var(--s2) var(--s3); line-height: 1.5; resize: vertical; }
.sticky-actions { position: sticky; bottom: calc(-1 * var(--s5)); margin: 0 calc(-1 * var(--s5)) calc(-1 * var(--s5)); padding: var(--s3) var(--s5); background: var(--surface); border-top: 1px solid var(--border); }

/* ---------- Toolbars, filters and chips ---------- */
.toolbar { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s4); }
.toolbar .tabs { margin-bottom: 0; border-bottom: 0; }
.filters { display: grid; gap: var(--s3); margin-bottom: var(--s4); }
.filters .row .input { width: auto; min-width: 180px; flex: 1 1 180px; }
.range { display: flex; flex-wrap: wrap; align-items: flex-end; gap: var(--s2); }
.range .field { width: 150px; }
.picker { display: grid; gap: 4px; min-width: 200px; }
.chips { display: flex; gap: var(--s2); overflow-x: auto; padding-bottom: 2px; scrollbar-width: thin; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; min-height: 34px; padding: 0 var(--s3); white-space: nowrap;
  border: 1px solid var(--border-strong); border-radius: var(--r-pill); background: var(--surface); color: var(--text);
  font-size: var(--fs-sm); font-weight: 500; cursor: pointer;
}
.chip[aria-pressed="true"] { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.chip-count { min-width: 20px; padding: 0 6px; border-radius: var(--r-pill); background: var(--surface-sunken); color: var(--text-muted); font-size: var(--fs-xs); text-align: center; }
.chip[aria-pressed="true"] .chip-count { background: rgb(255 255 255 / 0.2); color: inherit; }

/* ---------- Numbers ---------- */
.stats { display: grid; gap: var(--s3); grid-template-columns: repeat(2, 1fr); margin-bottom: var(--s4); }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(3, 1fr); } .stats-4 { grid-template-columns: repeat(4, 1fr); } }
.stat { padding: var(--s3) var(--s4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-md); }
.stat-label { font-size: var(--fs-sm); color: var(--text-muted); }
.stat-value { font-size: var(--fs-xl); font-weight: 680; font-family: var(--font-num); letter-spacing: -0.01em; }
.stat-sub { font-size: var(--fs-xs); color: var(--text-muted); }
.channel-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); }
.channel-head { display: flex; justify-content: space-between; gap: var(--s3); font-size: var(--fs-sm); margin-bottom: 4px; }
.channel-head span { color: var(--text-muted); }
.bar { display: block; height: 8px; border-radius: var(--r-pill); background: var(--surface-sunken); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--primary); border-radius: inherit; }

/* ---------- Lists ---------- */
.list-panel { padding: var(--s2) var(--s5); }
.list-panel .person:first-child { padding-top: var(--s3); }
.tasks { list-style: none; margin: 0; padding: var(--s2) var(--s5); }
.task { display: flex; flex-wrap: wrap; align-items: flex-start; gap: var(--s3); padding: var(--s3) 0; border-top: 1px solid var(--border); }
.task:first-child { border-top: 0; }
.task-check { width: 22px; flex: none; color: var(--success); padding-top: 1px; }
.task-main { flex: 1 1 260px; min-width: 0; }
.task-desc { margin-top: 4px; font-size: var(--fs-sm); white-space: pre-line; }
.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.task.is-done .person-name { color: var(--text-muted); }
.task.is-late { box-shadow: inset 3px 0 0 var(--danger); padding-left: var(--s3); }
.photo-preview { display: grid; place-items: center; gap: var(--s2); min-height: 160px; border: 1px dashed var(--border-strong); border-radius: var(--r-md); background: var(--surface-sunken); color: var(--text-muted); overflow: hidden; }
.photo-preview img, .proof-img { width: 100%; max-height: 60vh; object-fit: contain; border-radius: var(--r-sm); }
.ota-list { list-style: none; margin: 0; padding: var(--s2) var(--s5); }
.ota-row { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2) var(--s4); padding: var(--s3) 0; border-top: 1px solid var(--border); }
.ota-row:first-child { border-top: 0; }
.status-select { width: auto; min-height: 34px; font-size: var(--fs-sm); }
.draft { margin-top: var(--s4); }

/* =====================================================================
   Phase 4: calendar, items, threads, approvals, notifications
   ===================================================================== */

/* ---------- Notification bell ---------- */
.bell { position: relative; }
.bell-count { position: absolute; top: 4px; right: 2px; min-width: 18px; height: 18px; padding: 0 5px; border-radius: var(--r-pill); background: var(--accent); color: #fff; font-size: 11px; font-weight: 700; line-height: 18px; text-align: center; }
.bell-panel { width: min(380px, calc(100vw - 24px)); padding: 0; }
.bell-head { display: flex; align-items: center; justify-content: space-between; padding: var(--s2) var(--s2) var(--s2) var(--s4); border-bottom: 1px solid var(--border); }
.bell-list { list-style: none; margin: 0; padding: var(--s2); max-height: 60vh; overflow-y: auto; }
.bell-item { display: grid; gap: 2px; width: 100%; padding: var(--s2) var(--s3); border: 0; border-radius: var(--r-sm); background: none; text-align: left; cursor: pointer; color: var(--text); }
.bell-item:hover { background: var(--surface-sunken); }
.bell-item.is-unread { background: var(--primary-soft); }
.bell-title { font-weight: 600; font-size: var(--fs-sm); }
.bell-body, .bell-time { font-size: var(--fs-xs); color: var(--text-muted); }

/* ---------- Calendar ---------- */
.cal-title { font-size: var(--fs-lg); }
.cal { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.cal-head, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); }
.cal-head span { padding: var(--s2); font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); text-align: center; border-bottom: 1px solid var(--border); }
.cal-day { min-height: 118px; padding: var(--s1); border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); display: grid; align-content: start; gap: 3px; min-width: 0; }
.cal-day:nth-child(7n) { border-right: 0; }
.cal-day.is-other { background: var(--surface-sunken); }
.cal-day.is-other .cal-date span { color: var(--text-muted); }
.cal-date { display: flex; align-items: center; justify-content: space-between; padding: 2px 4px; font-size: var(--fs-xs); font-weight: 600; }
.cal-day.is-today .cal-date span { display: inline-grid; place-items: center; min-width: 22px; height: 22px; border-radius: var(--r-pill); background: var(--primary); color: var(--on-primary); }
.cal-add { width: 22px; height: 22px; border: 0; border-radius: var(--r-sm); background: none; color: var(--text-muted); cursor: pointer; opacity: 0; font-size: 16px; line-height: 1; }
.cal-day:hover .cal-add, .cal-add:focus-visible { opacity: 1; }
.cal-add:hover { background: var(--primary-soft); color: var(--primary); }
.cal-pill {
  display: flex; align-items: center; gap: 4px; width: 100%; min-width: 0; padding: 3px 6px; border: 0; border-left: 3px solid var(--dot, var(--text-muted));
  border-radius: 4px; background: var(--surface-sunken); color: var(--text); font-size: 12px; text-align: left; cursor: pointer;
}
.cal-pill span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cal-pill .icon { width: 13px; height: 13px; color: var(--text-muted); }
.cal-pill:hover { background: var(--primary-soft); }
.cal-pill.status-needs_approval { background: var(--accent-soft); }
.cal-more { font-size: var(--fs-xs); color: var(--text-muted); padding-left: 6px; }
.day-title { font-size: var(--fs-md); padding-top: var(--s3); }
.day-title.is-today::after { content: " · today"; color: var(--primary); }
.person-name .icon-sm { color: var(--text-muted); }

/* ---------- Item detail ---------- */
.item-detail { display: grid; gap: var(--s4); }
.item-edit { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s3) var(--s4); }
.item-edit summary { cursor: pointer; font-weight: 600; }
.item-edit[open] summary { margin-bottom: var(--s4); }
.danger-row { margin-top: var(--s4); padding-top: var(--s3); border-top: 1px solid var(--border); }
.decision, .footage { display: grid; gap: var(--s3); padding: var(--s4); border-radius: var(--r-md); background: var(--accent-soft); }
.footage { background: var(--surface-sunken); }
.decision .person-name, .footage .person-name { display: flex; align-items: center; gap: var(--s2); }
.footage-form { display: grid; grid-template-columns: 1fr auto; gap: var(--s2); }
.footage-form .form-error { grid-column: 1 / -1; }
.caption { white-space: pre-line; padding: var(--s3); background: var(--surface-sunken); border-radius: var(--r-sm); font-size: var(--fs-sm); }
.brief { margin: 0; white-space: pre-wrap; font: var(--fs-sm) / 1.6 ui-monospace, Consolas, monospace; }
.link-button { display: inline-flex; align-items: center; gap: 6px; padding: 0; border: 0; background: none; color: var(--primary); font-weight: 600; cursor: pointer; text-align: left; }
.link-button:hover { text-decoration: underline; }

/* ---------- Threads ---------- */
.thread { border-top: 1px solid var(--border); padding-top: var(--s4); display: grid; gap: var(--s3); }
.thread-title { font-size: var(--fs-md); }
.thread-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); }
.comment { display: flex; gap: var(--s3); }
.comment-main { flex: 1; min-width: 0; }
.comment-head { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); font-size: var(--fs-sm); }
.comment-head time { color: var(--text-muted); font-size: var(--fs-xs); }
.comment-body { margin-top: 2px; white-space: pre-line; overflow-wrap: anywhere; }
.mention { color: var(--primary-hover); }
.thread-form { display: grid; gap: var(--s2); }
.mention-wrap { position: relative; }
.mention-list { top: auto; bottom: calc(100% + 4px); }
.select-small { width: auto; min-height: 40px; }

/* ---------- Approvals ---------- */
.approvals { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); }
.approval { display: grid; gap: var(--s3); padding: var(--s4) var(--s5); scroll-margin-top: 80px; }
.approval:target { outline: 2px solid var(--accent); }
.approval-main { display: grid; gap: var(--s2); }
.approval-main .person-name { display: flex; align-items: center; gap: var(--s2); }
.approval-actions { display: grid; gap: var(--s2); }
@media (max-width: 899px) { .cal-day { min-height: 96px; } .cal-pill { font-size: 11px; padding: 2px 4px; } }

/* =====================================================================
   Calendar v2: responsive views, time grid, live updates, drag and drop
   ===================================================================== */
.cal-toolbar { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: var(--s3); margin-bottom: var(--s3); }
.cal-nav { display: flex; align-items: center; gap: var(--s2); min-width: 0; }
.cal-nav .cal-title { margin-left: var(--s2); white-space: nowrap; }
.cal-controls { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); }
.cal-controls .select { width: auto; min-width: 170px; }
.live-dot { display: inline-flex; align-items: center; gap: 6px; margin-left: var(--s2); font-size: var(--fs-xs); font-weight: 600; color: var(--text-muted); white-space: nowrap; }
.live-dot::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--text-muted); }
.live-dot.is-live { color: var(--success); }
.live-dot.is-live::before { background: var(--success); box-shadow: 0 0 0 0 rgb(46 125 79 / 0.5); animation: pulse 2s infinite; }
.live-dot.is-connecting { color: var(--warning); }
.live-dot.is-connecting::before { background: var(--warning); }
@keyframes pulse { 70% { box-shadow: 0 0 0 6px rgb(46 125 79 / 0); } 100% { box-shadow: 0 0 0 0 rgb(46 125 79 / 0); } }

/* Month (wide) */
.cal-daynum { min-width: 24px; height: 24px; padding: 0 4px; border: 0; border-radius: var(--r-pill); background: none; color: inherit; font: inherit; font-weight: 600; cursor: pointer; }
.cal-daynum:hover { background: var(--primary-soft); }
.cal-day.is-today .cal-daynum { background: var(--primary); color: var(--on-primary); }
.cal-day.is-today .cal-date span { all: unset; }
.cal-more { border: 0; background: none; text-align: left; cursor: pointer; }
.cal-more:hover { color: var(--primary); }
.cal-day.is-drop, .tg-col.is-drop, .tg-allday-cell.is-drop { background: var(--primary-soft); outline: 2px dashed var(--primary); outline-offset: -2px; }
.cal-pill.is-dragging { opacity: 0.4; }
.cal-pill[draggable="true"] { cursor: grab; }
.is-flash { animation: flash 2.4s var(--ease); }
@keyframes flash { 0%, 30% { box-shadow: 0 0 0 3px var(--highlight); } 100% { box-shadow: 0 0 0 0 transparent; } }

/* Month (phones): dots + chosen day */
.cal-compact .cal-head span { padding: var(--s1); }
.cal-cell { display: grid; justify-items: center; align-content: start; gap: 3px; min-height: 52px; padding: 6px 0; border: 0; border-right: 1px solid var(--border); border-bottom: 1px solid var(--border); background: var(--surface); color: var(--text); cursor: pointer; font: inherit; }
.cal-cell:nth-child(7n) { border-right: 0; }
.cal-cell.is-other { background: var(--surface-sunken); color: var(--text-muted); }
.cal-cell-num { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; font-size: var(--fs-sm); font-weight: 600; }
.cal-cell.is-today .cal-cell-num { color: var(--primary); box-shadow: inset 0 0 0 2px var(--primary); }
.cal-cell.is-selected .cal-cell-num { background: var(--primary); color: var(--on-primary); box-shadow: none; }
.cal-dots { display: flex; align-items: center; gap: 2px; min-height: 6px; }
.cal-dots .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--dot, var(--text-muted)); }
.cal-dots b { font-size: 9px; line-height: 6px; color: var(--text-muted); }
.day-list-head { display: flex; align-items: center; justify-content: space-between; gap: var(--s2); }
.day-empty { padding: var(--s2) 0 var(--s4); }

/* Week / Day: time grid */
.tg { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); overflow: hidden; }
.tg-head, .tg-allday { display: grid; grid-template-columns: 56px repeat(var(--days), minmax(0, 1fr)); border-bottom: 1px solid var(--border); }
.tg-gutter { border-right: 1px solid var(--border); }
.tg-dayhead { display: grid; justify-items: center; gap: 2px; padding: var(--s2) 0; border: 0; border-right: 1px solid var(--border); background: none; color: var(--text-muted); font: inherit; font-size: var(--fs-xs); cursor: pointer; }
.tg-dayhead:last-child { border-right: 0; }
.tg-dayhead b { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 50%; font-size: var(--fs-md); color: var(--text); }
.tg-dayhead.is-today { color: var(--primary); }
.tg-dayhead.is-today b { background: var(--primary); color: var(--on-primary); }
.tg-allday-label { display: grid; place-items: center; padding: 4px; font-size: 10px; color: var(--text-muted); text-align: center; }
.tg-allday-cell { display: grid; align-content: start; gap: 3px; min-height: 34px; padding: 4px; border-right: 1px solid var(--border); }
.tg-allday-cell:last-child { border-right: 0; }
.tg-scroll { max-height: min(70vh, 720px); overflow-y: auto; overscroll-behavior: contain; }
.tg-body { display: grid; grid-template-columns: 56px 1fr; position: relative; }
.tg-hours { display: grid; grid-auto-rows: 52px; border-right: 1px solid var(--border); }
.tg-hour { position: relative; top: -8px; padding-right: 6px; font-size: 10px; color: var(--text-muted); text-align: right; }
.tg-cols { display: grid; grid-template-columns: repeat(var(--days), minmax(0, 1fr)); }
.tg-col {
  position: relative; height: calc(52px * 24); border-right: 1px solid var(--border);
  background-image: linear-gradient(to bottom, var(--border) 1px, transparent 1px), linear-gradient(to bottom, var(--surface-sunken) 1px, transparent 1px);
  background-size: 100% 52px, 100% 26px;
}
.tg-col:last-child { border-right: 0; }
.tg-col.is-today { background-color: color-mix(in srgb, var(--primary-soft) 35%, transparent); }
.tg-item { position: absolute; align-items: flex-start; padding-top: 4px; overflow: hidden; z-index: 1; }
.tg-item span { white-space: normal; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.now-line { position: absolute; left: 0; right: 0; height: 2px; background: var(--danger); z-index: 2; pointer-events: none; }
.now-line::before { content: ""; position: absolute; left: -5px; top: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--danger); }

@media (max-width: 699px) {
  .cal-toolbar { align-items: stretch; }
  .cal-nav { width: 100%; }
  .cal-nav .cal-title { font-size: var(--fs-md); margin-left: var(--s1); overflow: hidden; text-overflow: ellipsis; }
  .cal-controls { width: 100%; display: grid; gap: var(--s2); }
  .cal-controls .select { width: 100%; min-width: 0; }
  /* Only the coloured dot on phones; the word stays available to screen readers via the title. */
  .live-dot { font-size: 0; gap: 0; }
  .tg-head, .tg-allday { grid-template-columns: 44px repeat(var(--days), minmax(0, 1fr)); }
  .tg-body { grid-template-columns: 44px 1fr; }
  .tg-scroll { max-height: 62vh; }
}
@media (prefers-reduced-motion: reduce) { .live-dot.is-live::before, .is-flash { animation: none; } }

/* =====================================================================
   Phase 5: Ask panel, chat, AI planner, assistant training, usage
   ===================================================================== */

/* ---------- Ask: side drawer (full screen on phones) ---------- */
.ask-button { gap: var(--s1); }
@media (max-width: 599px) { .ask-label { display: none; } .ask-button { padding-inline: var(--s2); } }
.drawer {
  width: 100%; max-width: 100%; height: 100dvh; max-height: 100dvh; margin: 0; padding: 0; border: 0;
  display: none; flex-direction: column; background: var(--surface); color: var(--text);
}
.drawer[open] { display: flex; }
.drawer::backdrop { background: rgb(35 38 43 / 0.35); }
@media (min-width: 700px) {
  .drawer { width: 440px; margin: 0 0 0 auto; border-left: 1px solid var(--border); box-shadow: var(--shadow-overlay); }
}
.drawer-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s3); padding: var(--s4); border-bottom: 1px solid var(--border); }
.ask-picker { padding: var(--s3) var(--s4) 0; }
.ask-picker .picker { display: grid; gap: var(--s1); }
.ask-body { flex: 1; min-height: 0; display: flex; flex-direction: column; }
.ask-body .chat { flex: 1; min-height: 0; }
.ask-foot { padding: 0 var(--s4) calc(var(--s3) + env(safe-area-inset-bottom)); }

/* ---------- Chat ---------- */
.chat { display: flex; flex-direction: column; gap: var(--s3); min-height: 0; }
.chat-scroll { flex: 1; min-height: 0; overflow-y: auto; padding: var(--s4); display: grid; align-content: start; gap: var(--s3); overscroll-behavior: contain; }
.chat-empty { color: var(--text-muted); font-size: var(--fs-sm); margin: 0 0 var(--s3); }
.chat-starters .chips { flex-wrap: wrap; }
.chat-starters .chip { white-space: normal; text-align: left; }
.chat-log { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); }
.chat-msg { max-width: 88%; padding: var(--s3) var(--s3); border-radius: var(--r-md); font-size: var(--fs-sm); }
.chat-user { justify-self: end; background: var(--primary); color: var(--on-primary); border-bottom-right-radius: var(--r-sm); }
.chat-assistant { justify-self: start; background: var(--surface-sunken); border: 1px solid var(--border); border-bottom-left-radius: var(--r-sm); }
.chat-error { background: var(--danger-soft); border-color: transparent; color: var(--danger); }
.chat-text { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.is-thinking .chat-text { color: var(--text-muted); }
.chat-sources { margin-top: var(--s2); padding-top: var(--s2); border-top: 1px dashed var(--border-strong); font-size: var(--fs-xs); color: var(--text-muted); }
.chat-sources-label { font-weight: 650; }
.chat-sources ol { margin: var(--s1) 0 0; padding-left: 1.4em; display: grid; gap: 2px; }
.chat-source-cat { margin-left: var(--s2); opacity: 0.8; }
.chat-mock { margin-top: var(--s2); }
.chat-form { display: grid; grid-template-columns: 1fr auto; gap: var(--s2); align-items: end; padding: 0 var(--s4) var(--s3); }
.chat-input { min-height: 44px; resize: none; }
.test-chat { border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); }
.test-chat .chat-scroll { max-height: 52vh; min-height: 220px; }

/* ---------- AI planner ---------- */
.planner-top { align-items: start; }
.season-themes { margin: var(--s1) 0 0; padding-left: 1.2em; display: grid; gap: 2px; font-size: var(--fs-sm); }
.season-dates { list-style: none; margin: var(--s2) 0 0; padding: 0; display: grid; gap: var(--s2); font-size: var(--fs-sm); }
.season-dates li { display: grid; grid-template-columns: 36px 1fr; gap: var(--s2); align-items: baseline; }
.season-day { font-family: var(--font-num); font-weight: 700; font-size: var(--fs-md); color: var(--primary); text-align: right; }
.season-check { display: block; font-size: var(--fs-xs); color: var(--warning); }
.suggestions { list-style: none; margin: var(--s3) 0; padding: 0; display: grid; }
.suggestion { display: grid; grid-template-columns: 56px 1fr auto; gap: var(--s3); padding: var(--s3) 0; border-top: 1px solid var(--border); }
.suggestion:first-child { border-top: 0; }
.suggestion-date { display: grid; justify-items: center; align-content: start; line-height: 1.15; }
.suggestion-wd { font-size: var(--fs-xs); color: var(--text-muted); }
.suggestion-day { font-family: var(--font-num); font-size: var(--fs-xl); font-weight: 700; }
.suggestion-time { font-size: var(--fs-xs); color: var(--text-muted); }
.suggestion-main { min-width: 0; display: grid; gap: 2px; }
.suggestion-title { font-weight: 650; cursor: pointer; }
.suggestion-meta, .suggestion-why { margin: 0; font-size: var(--fs-xs); color: var(--text-muted); }
.suggestion-hook { margin: 0; font-size: var(--fs-sm); }
.suggestion-more { font-size: var(--fs-sm); }
.suggestion-more summary { cursor: pointer; color: var(--primary); font-size: var(--fs-xs); font-weight: 600; }
.suggestion-more p { margin: var(--s1) 0 0; white-space: pre-wrap; }
.suggestion-tags { color: var(--info); }
.suggestion-pick input { width: 22px; height: 22px; accent-color: var(--primary); margin-top: 4px; }

/* ---------- Assistant training ---------- */
.kb-layout { display: grid; gap: var(--s4); }
@media (min-width: 1000px) { .kb-layout { grid-template-columns: 260px minmax(0, 1fr); align-items: start; } .kb-side { position: sticky; top: calc(var(--topbar-h) + var(--s4)); } }
.kb-assistants { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.kb-assistant {
  width: 100%; display: grid; gap: 2px; text-align: left; padding: var(--s3); border: 1px solid var(--border);
  border-radius: var(--r-md); background: var(--surface); color: var(--text); font: inherit; cursor: pointer;
}
.kb-assistant:hover { border-color: var(--border-strong); }
.kb-assistant[aria-current="true"] { border-color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); }
.kb-assistant-name { font-weight: 650; }
.kb-assistant-meta { font-size: var(--fs-xs); color: var(--text-muted); }
.kb-assistant-flags { display: flex; flex-wrap: wrap; gap: var(--s1); }
.kb-assistant-flags:empty { display: none; }
.kb-toolbar { display: grid; gap: var(--s3); }
.kb-filters .input { width: auto; flex: 1 1 180px; }
.kb-list { list-style: none; margin: 0; padding: 0; display: grid; }
.kb-item { display: grid; grid-template-columns: 1fr auto; gap: var(--s3); padding: var(--s3) 0; border-top: 1px solid var(--border); }
.kb-item:first-child { border-top: 0; }
.kb-item.is-stale { box-shadow: inset 3px 0 0 var(--accent); padding-left: var(--s3); }
.kb-item-main { min-width: 0; display: grid; gap: 2px; }
.kb-item-title { margin: 0; font-weight: 650; display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.kb-item-body { margin: 0; font-size: var(--fs-sm); white-space: pre-wrap; }
.kb-review.is-overdue { color: var(--accent); font-weight: 600; }
@media (max-width: 599px) { .kb-item, .suggestion { grid-template-columns: 1fr; } .suggestion { grid-template-columns: 48px 1fr auto; } .kb-item .row-actions { justify-content: flex-start; } }
.versions { list-style: none; margin: 0; padding: 0; display: grid; }
.version { display: grid; grid-template-columns: 1fr auto; gap: var(--s3); padding: var(--s3) 0; border-top: 1px solid var(--border); }
.version:first-child { border-top: 0; }
.version-main { min-width: 0; display: grid; gap: 2px; }
.version-main p { margin: 0; }
.version-changes { font-size: var(--fs-sm); }
.version-changes summary { cursor: pointer; color: var(--primary); font-size: var(--fs-xs); font-weight: 600; }
.version-changes ul { margin: var(--s1) 0 0; padding: 0; list-style: none; display: grid; gap: 2px; }
.chg { display: inline-block; min-width: 64px; font-size: var(--fs-xs); font-weight: 650; }
.chg-add { color: var(--success); } .chg-edit { color: var(--info); } .chg-del { color: var(--danger); }
@media (max-width: 599px) { .version { grid-template-columns: 1fr; } }

/* ---------- Usage table ---------- */
.table-wrap { overflow-x: auto; }
.data-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); }
.data-table th { text-align: left; font-size: var(--fs-xs); color: var(--text-muted); font-weight: 600; padding: var(--s2); border-bottom: 1px solid var(--border-strong); white-space: nowrap; }
.data-table td { padding: var(--s2); border-bottom: 1px solid var(--border); vertical-align: top; }
.data-table .num { text-align: right; font-family: var(--font-num); font-variant-numeric: tabular-nums; white-space: nowrap; }
.mono { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; font-size: 0.92em; }
.mini-list-kv li { display: flex; justify-content: space-between; gap: var(--s3); font-size: var(--fs-sm); }
@media (max-width: 599px) {
  .planner-results .panel-head { flex-wrap: wrap; }
  .planner-results .panel-head > .btn { width: 100%; }
}

/* AI roles (0.5.1) */
.kb-select { width: 100%; }
.kb-groups { display: none; }
@media (min-width: 1000px) {
  .kb-select { display: none; }
  .kb-groups { display: grid; gap: var(--s4); }
}
.kb-group { display: grid; gap: var(--s2); }
.kb-group-title { margin: 0; font-size: var(--fs-xs); font-weight: 650; color: var(--text-muted); }
.ai-slot { display: contents; }
.ai-request { display: grid; grid-template-columns: 1fr auto; gap: var(--s2); align-items: end; }
@media (max-width: 599px) { .ai-request { grid-template-columns: 1fr; } }
.ai-output { font-size: var(--fs-sm); line-height: 1.5; }
.ai-actions { justify-content: flex-end; flex-wrap: wrap; }
.kb-layout > *, .kb-layout .panel { min-width: 0; }
.tabs { overflow-x: auto; scrollbar-width: none; }
.kb-toolbar .row { flex-wrap: wrap; }

/* =====================================================================
   Phase 6: publishing, ad plans, DM inbox
   ===================================================================== */
.publish { display: grid; gap: var(--s2); padding: var(--s3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface-sunken); }
.publish .person-name { display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); margin: 0; }
.meta-row { justify-content: flex-start; flex-wrap: wrap; padding-top: var(--s2); border-top: 1px dashed var(--border); }
.meta-row > .person-meta { flex-basis: 100%; }
.meta-row .person-meta { display: inline-flex; align-items: center; gap: var(--s1); }

.queue, .ad-list { list-style: none; margin: 0; padding: 0; display: grid; }
.queue-row, .ad-card { display: grid; grid-template-columns: auto 1fr auto; gap: var(--s3); padding: var(--s3) 0; border-top: 1px solid var(--border); align-items: start; }
.ad-card { grid-template-columns: 1fr auto; }
.queue-row:first-child, .ad-card:first-child { border-top: 0; }
.queue-when { display: grid; justify-items: center; min-width: 52px; line-height: 1.15; }
.queue-error { margin: var(--s1) 0 0; font-size: var(--fs-sm); color: var(--danger); }
.ad-audience, .ad-copy { margin: var(--s1) 0 0; font-size: var(--fs-sm); }
@media (max-width: 599px) {
  .queue-row { grid-template-columns: auto 1fr; }
  .queue-row .row-actions, .ad-card .row-actions { grid-column: 1 / -1; justify-content: flex-start; }
  .ad-card { grid-template-columns: 1fr; }
}

.dm-layout { display: grid; gap: var(--s4); }
@media (min-width: 1000px) { .dm-layout { grid-template-columns: 340px minmax(0, 1fr); align-items: start; } }
.dm-layout > * { min-width: 0; }
.dm-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.dm-item { width: 100%; display: grid; gap: 2px; text-align: left; padding: var(--s3); border: 1px solid var(--border); border-radius: var(--r-md); background: var(--surface); color: var(--text); font: inherit; cursor: pointer; }
.dm-item:hover { border-color: var(--border-strong); }
.dm-item[aria-current="true"] { border-color: var(--primary); box-shadow: inset 3px 0 0 var(--primary); }
.dm-item-top { display: flex; justify-content: space-between; gap: var(--s2); }
.dm-preview { font-size: var(--fs-sm); color: var(--text-muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dm-thread { border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); padding: var(--s4); }
.dm-thread:empty { display: none; }
.dm-head { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--s3); flex-wrap: wrap; }
.dm-head .panel-title { margin: 0; }
.dm-log { max-height: 55vh; overflow-y: auto; padding: var(--s2) 0; }
.dm-meta { margin: var(--s1) 0 0; font-size: var(--fs-xs); opacity: 0.8; }

/* 0.6.5 automation */
.check-row { display: flex; gap: var(--s2); align-items: flex-start; cursor: pointer; }
.check-row input { width: 18px; height: 18px; margin-top: 3px; accent-color: var(--primary); flex: none; }
.check-row .field-help { display: block; margin-top: 2px; }
.check-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(170px, 100%), 1fr)); gap: var(--s2); margin-top: var(--s2); }
fieldset.placements { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s3); margin: 0; }
.best-slots { margin: 0; padding-left: 1.4em; display: grid; gap: 2px; font-size: var(--fs-sm); }
.publish-top { align-items: start; }
.ad-totals { margin: var(--s1) 0 0; font-size: var(--fs-sm); font-weight: 600; color: var(--primary); }
.rule-form { margin-top: var(--s3); padding-top: var(--s3); border-top: 1px dashed var(--border); }

/* =====================================================================
   Phase 7: outreach and influencers
   ===================================================================== */
.step-box { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s3); margin: 0; display: grid; gap: var(--s3); }
.step-summary { margin: 0; padding-left: 1.4em; display: grid; gap: 2px; font-size: var(--fs-sm); }
.pick-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); max-height: 50vh; overflow-y: auto; }
.email-previews { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); }
.email-preview { border: 1px solid var(--border); border-radius: var(--r-md); padding: var(--s3); display: grid; gap: var(--s1); }
.email-preview .person-name, .email-preview .person-meta { margin: 0; }
.clamp-cell { max-width: 260px; font-size: var(--fs-sm); }
.input-sm { min-height: 34px; padding-block: 4px; font-size: var(--fs-sm); width: auto; }
.inf-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fill, minmax(min(280px, 100%), 1fr)); }
.inf-card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s4); display: grid; gap: var(--s2); align-content: start; }
.inf-card p { margin: 0; }
.inf-head { display: flex; justify-content: space-between; gap: var(--s3); align-items: flex-start; }
.inf-fit { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center; font-family: var(--font-num); font-weight: 700; border: 2px solid currentColor; }
.inf-fit.tone-success { color: var(--success); } .inf-fit.tone-info { color: var(--info); } .inf-fit.tone-warning { color: var(--warning); }
.inf-tags { display: flex; flex-wrap: wrap; gap: var(--s1); }
.inf-card .row-actions { justify-content: flex-start; }
/* Public unsubscribe page */
.unsub-page { min-height: 100vh; display: grid; place-items: center; background: var(--bg); padding: var(--s4); }
.unsub { max-width: 440px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); padding: var(--s6, 32px); display: grid; gap: var(--s3); text-align: center; }
.unsub h1 { margin: 0; font-size: var(--fs-xl); }
.unsub p { margin: 0; }
.kb-filters { min-width: 0; }
.kb-filters > .chips { min-width: 0; max-width: 100%; flex: 1 1 100%; }

/* =====================================================================
   Phase 8: reports and billing
   ===================================================================== */
/* Billing banner under the top bar */
.bill-banner { display: flex; align-items: center; gap: var(--s3); padding: var(--s2) var(--s4); font-size: var(--fs-sm); background: var(--warning-soft); border-bottom: 1px solid var(--border); }
.bill-banner p { margin: 0; flex: 1; min-width: 0; }
.bill-banner .icon { color: var(--warning); flex: none; }
.bill-banner-due { background: var(--info-soft); }
.bill-banner-due .icon { color: var(--info); }
.bill-banner-locked { background: var(--danger-soft); }
.bill-banner-locked .icon { color: var(--danger); }
.btn-sm { min-height: 32px; padding: 0 var(--s3); font-size: var(--fs-sm); flex: none; }

/* Reports */
.report-toolbar { align-items: center; }
.period-nav { gap: var(--s1); }
.period-label { min-width: 13ch; text-align: center; font-weight: 650; font-family: var(--font-num); }
.report-stats .stat-value { font-size: var(--fs-lg); }
.delta { margin-top: 2px; }
.delta-up { color: var(--success); }
.delta-down { color: var(--danger); }
.highlights { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.highlights li { padding-left: var(--s4); position: relative; }
.highlights li::before { content: ""; position: absolute; left: 0; top: 0.55em; width: 8px; height: 8px; border-radius: 50%; background: var(--success); }
.highlights li.is-down::before { background: var(--danger); }
.bar-list { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s2); }
.bar-list li { display: grid; grid-template-columns: minmax(80px, 30%) 1fr 3ch; gap: var(--s3); align-items: center; font-size: var(--fs-sm); }
.bar-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar-track { height: 10px; border-radius: var(--r-pill); background: var(--surface-sunken); overflow: hidden; }
.bar-fill { display: block; height: 100%; border-radius: inherit; background: var(--primary); }
.bar-value { text-align: right; font-family: var(--font-num); font-weight: 650; }
.prose { margin: 0; white-space: pre-line; }
.pre-line { white-space: pre-line; }
.report-cards { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fill, minmax(min(260px, 100%), 1fr)); }
.report-card { width: 100%; display: grid; gap: var(--s1); text-align: left; padding: var(--s4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); cursor: pointer; color: inherit; font: inherit; }
.report-card:hover { border-color: var(--primary); }
.report-card:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }
.report-card-kind { font-size: var(--fs-xs); color: var(--text-muted); }
.report-card-title { font-size: var(--fs-md); font-weight: 680; }
.report-card-nums { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s3); font-size: var(--fs-sm); color: var(--text-muted); }
.report-card-nums b { color: var(--text); font-family: var(--font-num); }

/* Billing */
.invoice-card { display: grid; gap: var(--s4); padding: var(--s4); background: var(--surface); border: 1px solid var(--border); border-radius: var(--r-lg); }
@media (min-width: 720px) { .invoice-card { grid-template-columns: 1fr auto; align-items: start; } }
.invoice-main { display: grid; gap: var(--s2); align-content: start; }
.invoice-main p { margin: 0; }
.invoice-number { font-weight: 650; display: flex; flex-wrap: wrap; gap: var(--s2); align-items: center; }
.invoice-total { font-size: var(--fs-2xl); font-weight: 700; font-family: var(--font-num); letter-spacing: -0.01em; }
.qr-box { display: grid; justify-items: center; gap: var(--s2); padding: var(--s3); border: 1px solid var(--border); border-radius: var(--r-md); background: #fff; max-width: 240px; justify-self: center; }
.qr-img { width: 180px; height: 180px; image-rendering: pixelated; }
.qr-help { margin: 0; font-size: var(--fs-xs); color: var(--text-muted); text-align: center; }
.qr-box .link-button { font-family: var(--font-num); overflow-wrap: anywhere; }
/* "Open in a UPI app" only helps on phones */
@media (min-width: 900px) { .upi-app { display: none; } }
.data-table .num { font-family: var(--font-num); white-space: nowrap; }
@media (min-width: 600px) { .form-row-3 { grid-template-columns: 1fr 1fr 1fr; } }
.line-row { display: grid; gap: var(--s2); align-items: end; grid-template-columns: 1fr 1fr; }
.line-row .field:first-child { grid-column: 1 / -1; }
@media (min-width: 640px) { .line-row { grid-template-columns: 1fr 80px 130px auto; } .line-row .field:first-child { grid-column: auto; } }
/* Grid children may shrink, so wide tables scroll inside their box instead of widening the page. */
.stack > *, .grid-2 > * { min-width: 0; }

/* =====================================================================
   Phase 9: owner dashboard and bug feed
   ===================================================================== */
.stat-warn { border-color: var(--warning); background: var(--warning-soft); }
.ws-grid { list-style: none; margin: 0; padding: 0; display: grid; gap: var(--s3); grid-template-columns: repeat(auto-fill, minmax(min(300px, 100%), 1fr)); }
.ws-card { display: grid; gap: var(--s2); align-content: start; padding: var(--s4); border: 1px solid var(--border); border-radius: var(--r-lg); background: var(--surface); min-width: 0; }
.ws-card.needs-you { border-color: var(--warning); }
.ws-card p { margin: 0; }
.ws-head { display: flex; justify-content: space-between; gap: var(--s2); align-items: flex-start; }
.ws-name { margin: 0; font-size: var(--fs-md); }
.ws-nums { margin: 0; display: grid; grid-template-columns: 1fr 1fr; gap: var(--s2); }
.ws-nums div { display: grid; }
.ws-nums dt { font-size: var(--fs-xs); color: var(--text-muted); }
.ws-nums dd { margin: 0; font-weight: 650; font-family: var(--font-num); }
.ws-attention { margin: 0; padding: var(--s2) var(--s3); list-style: none; display: grid; gap: 2px; background: var(--warning-soft); border-radius: var(--r-sm); font-size: var(--fs-sm); }
.ws-ok { font-size: var(--fs-sm); color: var(--success); }
.job-list li, .service-list li { display: flex; justify-content: space-between; gap: var(--s3); font-size: var(--fs-sm); }
.job-list li.is-bad { color: var(--danger); }
.job-list .person-meta { text-align: right; overflow-wrap: anywhere; }
.service-list { list-style: none; margin: 0 0 var(--s3); padding: 0; display: grid; gap: var(--s2); grid-template-columns: repeat(auto-fill, minmax(min(220px, 100%), 1fr)); }
.service-list li { align-items: center; padding: var(--s2) var(--s3); border: 1px solid var(--border); border-radius: var(--r-md); }
.bug-list { list-style: none; margin: 0; padding: 0; display: grid; }
.bug-row { border-bottom: 1px solid var(--border); }
.bug-row:last-child { border-bottom: 0; }
.bug-row.is-fresh { background: var(--warning-soft); }
.bug-open { width: 100%; display: grid; gap: 4px; padding: var(--s3) var(--s2); text-align: left; border: 0; background: none; color: inherit; font: inherit; cursor: pointer; border-radius: var(--r-sm); }
.bug-open:hover { background: var(--surface-sunken); }
.bug-open:focus-visible { outline: 2px solid var(--focus); outline-offset: -2px; }
.bug-top { display: flex; flex-wrap: wrap; gap: var(--s1); }
.bug-msg { font-weight: 600; overflow-wrap: anywhere; }
.bug-meta { font-size: var(--fs-xs); color: var(--text-muted); overflow-wrap: anywhere; }
.bug-message, .bug-stack pre { margin: 0; padding: var(--s3); background: var(--surface-sunken); border-radius: var(--r-sm); font-size: var(--fs-sm); white-space: pre-wrap; overflow-wrap: anywhere; max-height: 40vh; overflow: auto; }
.bug-stack summary { cursor: pointer; font-weight: 600; font-size: var(--fs-sm); padding: var(--s1) 0; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: var(--fs-xs); }
/* Filter chips scroll sideways inside the toolbar instead of widening the page. */
.chips-box { min-width: 0; max-width: 100%; }
.gh-panel > summary { cursor: pointer; padding: var(--s4) var(--s5); list-style-position: inside; }
.gh-panel[open] > summary { border-bottom: 1px solid var(--border); }

/* OTA listing updates: one collapsible row per channel */
.ota-update-item { border-top: 1px solid var(--border); padding: var(--s3) 0; }
.ota-update-item:first-child { border-top: 0; }
.ota-update-item > summary { cursor: pointer; list-style: none; display: flex; flex-wrap: wrap; align-items: center; gap: var(--s2); min-height: 40px; }
.ota-update-item > summary::-webkit-details-marker { display: none; }
.ota-update-item > summary::before { content: "▸"; color: var(--text-muted); }
.ota-update-item[open] > summary::before { content: "▾"; }
.ota-update-item > .stack { margin-top: var(--s3); }
/* =====================================================================
   Phase 10: accessibility (reflow at 320px, WCAG 1.4.10)
   ===================================================================== */
/* Long words and links inside list rows wrap instead of widening the page. */
.person-main, .task-desc { overflow-wrap: anywhere; }
/* Very narrow screens (320px, or 400% zoom): the top bar tightens instead of overflowing. */
@media (max-width: 379px) {
  .topbar { gap: var(--s2); padding: 0 var(--s3); }
  .topbar-actions { gap: var(--s1); min-width: 0; }
  .tenant-select { max-width: 84px; padding-left: var(--s2); padding-right: var(--s5); }
}
/* Number tiles shrink with the screen; big figures get a little smaller on very narrow ones. */
.stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (min-width: 900px) { .stats { grid-template-columns: repeat(3, minmax(0, 1fr)); } .stats-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); } }
.stat { min-width: 0; overflow-wrap: anywhere; }
@media (max-width: 379px) { .stat { padding: var(--s3); } .stat-value { font-size: var(--fs-md); } }
