/* ==========================================================================
   App shell CSS — loaded after css/styles.css on authenticated pages only.
   Extends the existing design tokens/components rather than inventing a
   new visual language.
   ========================================================================== */

/* ---- App-shell cards are structural containers, not clickable link-cards
   like the marketing site's — the lift-on-hover flourish reads as a false
   affordance here, so it's switched off for anything under .app-panel. --- */
.app-panel .card:hover { transform: none; box-shadow: none; border-color: var(--border); }
/* A touch more breathing room than the marketing card default — these hold
   dense operational content (forms, tables, records), not a short feature
   blurb, so the padding needed to feel uncramped is larger. */
.app-panel .card { padding: var(--space-4); }
@media (max-width: 640px) { .app-panel .card { padding: var(--space-3); } }

/* ---- Standalone hint (the marketing tokens only define `.field .hint`;
   both dashboards render plenty of hint text outside forms — empty states,
   file lists, note timestamps — which needs the same muted small voice) --- */
.hint { font-size: 0.8125rem; color: var(--text-faint); }

/* ---- App typography: one family carries the whole task surface. Fraunces
   is reserved for exactly one spot (the page-level panel title) as the
   single brand accent; every section head, label, and data value is sans,
   on a tighter scale than the marketing site per Operate-mode guidance. --- */
.app-panel h1,
.app-panel h2,
.app-panel h3 {
  font-family: var(--font-body);
  letter-spacing: -0.01em;
}
.panel-title {
  font-family: var(--font-display);
  font-weight: 500;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
  color: var(--text);
}
.section-heading {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-faint);
  margin-bottom: var(--space-2);
}
.section-heading svg { width: 15px; height: 15px; flex-shrink: 0; }

.auth-shell {
  min-height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--space-4) var(--space-3);
  background: var(--paper);
}
.auth-card {
  width: 100%;
  max-width: 440px;
}
.auth-card__brand {
  display: flex;
  justify-content: center;
  margin-bottom: var(--space-4);
}
.auth-card .form-card {
  max-width: none;
}
.auth-card__foot {
  text-align: center;
  margin-top: var(--space-3);
  font-size: 0.9375rem;
  color: var(--text-muted);
}
.auth-card__foot a { font-weight: 600; color: var(--ink); border-bottom: 1px solid var(--border-strong); }

/* ---- Password strength meter ---- */
.strength-meter { margin-top: 0.6rem; }
.strength-meter__bars {
  display: flex;
  gap: 0.4rem;
}
.strength-meter__bars .progress-track__seg { height: 4px; }
.strength-meter__bars .progress-track__seg.is-filled::after { width: 100%; }
.strength-meter__bars .progress-track__seg[data-tier="0"].is-filled::after { background: var(--danger); }
.strength-meter__bars .progress-track__seg[data-tier="1"].is-filled::after { background: #c47a2b; }
.strength-meter__bars .progress-track__seg[data-tier="2"].is-filled::after { background: var(--accent); }
.strength-meter__bars .progress-track__seg[data-tier="3"].is-filled::after,
.strength-meter__bars .progress-track__seg[data-tier="4"].is-filled::after { background: #3f6b4f; }
.strength-meter__row {
  display: flex;
  justify-content: space-between;
  margin-top: 0.4rem;
  font-size: 0.8125rem;
}
.strength-meter__row [data-label] { font-weight: 600; color: var(--text-muted); }
.strength-meter__row [data-hint] { color: var(--text-faint); }

/* ---- Toasts ---- */
.toast-stack {
  position: fixed;
  bottom: var(--space-3);
  right: var(--space-3);
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  max-width: 360px;
}
.toast {
  background: var(--ink);
  color: var(--white);
  padding: 0.8rem 1.1rem;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 0.9375rem;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity var(--dur-base) var(--ease-out), transform var(--dur-base) var(--ease-out);
}
.toast.is-visible { opacity: 1; transform: translateY(0); }
.toast--error { background: var(--danger); }
.toast--success { background: #1e6b4d; }
@media (prefers-reduced-motion: reduce) { .toast { transition: none; } }

/* ---- App shell (dashboard / staff) — a dark masthead band anchors the
   page (reads as a private, considered space rather than a blank canvas)
   with a single horizontal tab strip underneath; content scrolls normally
   below it instead of living in a separate rail-scroll region. Moved from
   a left rail to a top bar deliberately: a vertical rail reads as generic
   ops-console chrome, while a masthead + underlined tabs reads closer to
   the editorial, boutique-advisory tone the rest of the site already has. */
.app-shell {
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--paper);
}
.app-topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  background: var(--ink);
  color: var(--on-ink);
}
.app-topbar__inner {
  max-width: 1280px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  gap: var(--space-4);
  padding: 0 var(--space-4);
  height: 60px;
}
.app-topbar__brand { color: var(--white); flex-shrink: 0; }
.app-topbar__brand span { display: none; }
@media (min-width: 640px) { .app-topbar__brand span { display: inline; } }

.app-topbar__nav {
  display: flex;
  align-items: stretch;
  gap: 0.1rem;
  flex: 1;
  min-width: 0;
  height: 100%;
  overflow-x: auto;
  -ms-overflow-style: none;
  scrollbar-width: none;
}
.app-topbar__nav::-webkit-scrollbar { display: none; }
.app-topbar__nav-divider {
  flex-shrink: 0;
  width: 1px;
  margin: 0.9rem 0.5rem;
  background: rgba(245,243,238,0.14);
}

.app-rail__link {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 100%;
  padding: 0 0.85rem;
  color: var(--on-ink-muted);
  font-size: 0.875rem;
  font-weight: 600;
  white-space: nowrap;
  flex-shrink: 0;
  border-bottom: 2px solid transparent;
  transition: color var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out);
}
.app-rail__link svg { width: 16px; height: 16px; flex-shrink: 0; }
.app-rail__link:hover { color: var(--white); }
.app-rail__link.is-active { color: var(--white); border-color: var(--accent); }
.app-rail__link .badge-count {
  background: var(--accent);
  color: var(--white);
  font-size: 0.6875rem;
  font-weight: 700;
  padding: 0.05rem 0.4rem;
  border-radius: 999px;
}

.app-topbar__utility { display: flex; align-items: center; gap: var(--space-2); flex-shrink: 0; }
.app-topbar__logout {
  color: var(--on-ink-muted);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.5rem 0.6rem;
}
.app-topbar__logout:hover { color: var(--white); }
.app-topbar__logout span { display: none; }
@media (min-width: 640px) { .app-topbar__logout span { display: inline; } }

.app-rail__company { display: flex; align-items: center; gap: 0.5rem; flex-shrink: 0; }
.app-rail__company-select {
  background: rgba(245,243,238,0.08);
  border: 1px solid rgba(245,243,238,0.16);
  color: var(--white);
  font-size: 0.8125rem;
  font-weight: 600;
  padding: 0.4rem 1.6rem 0.4rem 0.7rem;
  border-radius: 999px;
  appearance: none;
  cursor: pointer;
  max-width: 160px;
  text-overflow: ellipsis;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23a7a49b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  background-size: 13px;
}
@media (min-width: 640px) { .app-rail__company-select { max-width: 220px; } }
.app-rail__company-select:focus { outline: 1px solid var(--accent); outline-offset: 1px; }
.app-rail__add-company {
  flex-shrink: 0;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 1px solid rgba(245,243,238,0.2);
  color: var(--on-ink-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: color var(--dur-base) var(--ease-out), border-color var(--dur-base) var(--ease-out), background-color var(--dur-base) var(--ease-out);
}
.app-rail__add-company svg { width: 14px; height: 14px; }
.app-rail__add-company:hover { color: var(--white); border-color: rgba(245,243,238,0.4); background: rgba(245,243,238,0.08); }

/* ---- Persistent context strip: which company you're looking at, always
   visible regardless of which tab is active — the shell's own presence,
   not something that only exists inside the Overview panel. ---- */
.app-context-bar {
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.app-context-bar__inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-2) var(--space-4);
  display: flex;
  align-items: center;
  gap: var(--space-2);
  font-size: 0.8125rem;
  color: var(--text-faint);
}
.app-context-bar__name { font-weight: 700; color: var(--text); font-family: var(--font-display); font-size: 0.9375rem; }
.app-context-bar__sep { color: var(--border-strong); }

.app-main {
  flex: 1;
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: var(--space-5) var(--space-4) var(--space-7);
}
@media (max-width: 720px) {
  .app-topbar__inner { padding: 0 var(--space-2); gap: var(--space-2); }
  .app-context-bar__inner { padding: var(--space-2); }
  .app-main { padding: var(--space-4) var(--space-2) var(--space-6); }
  /* Icon-only tabs so a handful of nav items fit without horizontal
     scroll on a phone-width screen — the scroll still works as a
     fallback on consoles with more items (staff). */
  .app-rail__link { padding: 0 0.55rem; gap: 0.35rem; }
  .app-rail__link span:not(.badge-count) { display: none; }
  .app-topbar__logout span { display: none; }
  .app-rail__company-select { max-width: 110px; }
}

.app-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: var(--space-2) var(--space-3);
  margin-bottom: var(--space-4);
}
.app-header__text { flex: 1; min-width: 0; }
.app-header h1 { margin-bottom: 0.3rem; }
.app-header p { color: var(--text-muted); font-size: 0.9375rem; }
.app-header__id { font-size: 0.8125rem; color: var(--text-faint); margin-top: 0.3rem; font-variant-numeric: tabular-nums; }
.app-header__actions { display: flex; gap: var(--space-2); flex-shrink: 0; }

/* ---- Card header (title + description + optional action). Previously led
   with a colored icon chip on every single card — repeated across a dozen
   unrelated sections it read as decoration rather than information, exactly
   the "icon + heading + text as page structure" pattern that makes an
   interface feel templated. Dropped in favor of plain typographic
   hierarchy; a thin accent rule takes the icon's old job of marking "this
   is a titled section" without the visual noise. ---- */
.card-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: var(--space-3);
  margin-bottom: var(--space-3);
  padding-bottom: var(--space-2);
  border-bottom: 1px solid var(--border);
}
.card-head__text { display: flex; align-items: flex-start; gap: 0.7rem; min-width: 0; }
.card-head__icon { display: none; }
.card-head__title { font-size: 1rem; font-weight: 700; color: var(--text); letter-spacing: -0.01em; }
.card-head__desc { font-size: 0.8125rem; color: var(--text-faint); margin-top: 0.2rem; }
.card-head__action { flex-shrink: 0; }

/* ---- Stat tile ---- */
.stat-tile { display: flex; flex-direction: column; gap: 0.4rem; }
.stat-tile__icon { display: none; }
.stat-tile__value { font-size: 1.875rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1; font-variant-numeric: tabular-nums; }
.stat-tile__label { font-size: 0.8125rem; color: var(--text-muted); font-weight: 500; }

/* ---- Empty state ---- */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 0.5rem;
  padding: var(--space-4) var(--space-3);
  color: var(--text-faint);
}
.empty-state__icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--surface-alt);
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 0.3rem;
}
.empty-state__icon svg { width: 19px; height: 19px; color: var(--text-faint); }
.empty-state__title { font-size: 0.9375rem; font-weight: 600; color: var(--text-muted); }
.empty-state__desc { font-size: 0.8125rem; max-width: 34ch; }

/* ---- Avatar chip (initials) ---- */
.avatar-chip {
  width: 34px; height: 34px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--ink);
  color: var(--on-ink);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.avatar-chip--accent { background: var(--accent); color: var(--white); }

/* ---- Filter bar (search + selects, matches .field control vocabulary) ---- */
.filter-bar { display: flex; gap: var(--space-2); margin-bottom: var(--space-3); flex-wrap: wrap; }
.filter-bar__search { flex: 1; min-width: 220px; position: relative; }
.filter-bar__search svg {
  position: absolute; left: 0.85rem; top: 50%; transform: translateY(-50%);
  width: 16px; height: 16px; color: var(--text-faint); pointer-events: none;
}
.filter-bar input[type="text"],
.filter-bar input[type="search"],
.filter-bar select {
  width: 100%;
  min-height: 44px;
  padding: 0.65rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--white);
  font-size: 0.875rem;
  transition: border-color var(--dur-base) var(--ease-out), box-shadow var(--dur-base) var(--ease-out);
}
.filter-bar__search input { padding-left: 2.4rem; }
.filter-bar input:focus, .filter-bar select:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(11,11,12,0.08);
  outline: none;
}
.filter-bar select { min-width: 180px; flex-shrink: 0; }

/* ---- Inline form card (declineForm / addNoteForm / broadcast-adjacent
   composer blocks previously assembled from one-off inline styles) ---- */
.inline-form-card {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: var(--space-2) var(--space-3) var(--space-3);
}
.inline-form-card textarea,
.inline-form-card input[type="text"] {
  width: 100%;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--white);
  font-size: 0.9375rem;
  margin-bottom: 0.5rem;
}
.inline-form-card textarea:focus,
.inline-form-card input[type="text"]:focus {
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(11,11,12,0.08);
  outline: none;
}
.inline-form-card__actions { display: flex; gap: var(--space-2); margin-top: 0.3rem; }

/* ---- Tabs ---- */
.tabs {
  display: flex;
  gap: var(--space-1);
  border-bottom: 1px solid var(--border);
  margin-bottom: var(--space-4);
  flex-wrap: wrap;
}
.tabs__item {
  padding: 0.75rem 0.25rem;
  margin-right: var(--space-3);
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs__item.is-active { color: var(--ink); border-color: var(--ink); }
.tabs__item:hover { color: var(--ink); }

/* ---- Switch (toggle) ---- */
.switch-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
}
.switch-row__label { font-weight: 600; font-size: 0.9375rem; }
.switch-row__desc { font-size: 0.8125rem; color: var(--text-faint); margin-top: 0.2rem; }
.switch {
  position: relative;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
  border-radius: 999px;
  background: var(--border-strong);
  cursor: pointer;
  border: none;
  transition: background-color var(--dur-base) var(--ease-out);
}
.switch::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: var(--white);
  transition: transform var(--dur-base) var(--ease-out);
  box-shadow: var(--shadow-sm);
}
.switch.is-on { background: var(--ink); }
.switch.is-on::after { transform: translateX(18px); }

/* ---- Locked record (the submitted application — read-only) ---- */
.locked-record {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  padding: var(--space-3) var(--space-4);
}
.record-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0;
  border-top: 1px solid var(--border);
}
@media (max-width: 640px) { .record-grid { grid-template-columns: 1fr; } }
.locked-field {
  padding: 0.65rem 0;
  border-bottom: 1px solid var(--border);
}
.record-grid .locked-field:nth-child(odd) { padding-right: var(--space-3); }
.record-grid .locked-field:nth-child(even) { padding-left: var(--space-3); }
@media (max-width: 640px) {
  .record-grid .locked-field:nth-child(odd),
  .record-grid .locked-field:nth-child(even) { padding-inline: 0; }
}
.locked-field__label {
  display: block;
  font-size: 0.75rem;
  color: var(--text-faint);
  margin-bottom: 0.2rem;
}
.locked-field__value {
  display: block;
  font-size: 0.9375rem;
  font-weight: 600;
  color: var(--text);
  word-break: break-word;
}
.locked-field--wide { grid-column: 1 / -1; }
.locked-field--wide.locked-field:nth-child(odd),
.locked-field--wide.locked-field:nth-child(even) { padding-inline: 0; }

/* ---- Stepper (application journey) ---- */
.stepper { display: flex; flex-direction: column; }
.stepper__item {
  display: flex;
  align-items: flex-start;
  gap: 0.85rem;
  position: relative;
  padding-bottom: 1.4rem;
}
.stepper__item:last-child { padding-bottom: 0; }
.stepper__item:not(:last-child)::before {
  content: '';
  position: absolute;
  left: 9px;
  top: 20px;
  bottom: 0;
  width: 2px;
  background: var(--border);
}
.stepper__item--done:not(:last-child)::before { background: var(--ink); }
.stepper__icon {
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2px solid var(--border-strong);
  background: var(--paper);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  position: relative;
  z-index: 1;
}
.stepper__icon svg { width: 11px; height: 11px; }
.stepper__item--done .stepper__icon { background: var(--ink); border-color: var(--ink); color: var(--white); }
.stepper__item--active .stepper__icon { border-color: var(--accent); background: var(--white); }
.stepper__item--active .stepper__icon::after { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.stepper__body { padding-top: 0.05rem; }
.stepper__label { font-size: 0.9375rem; color: var(--text-faint); }
.stepper__item--done .stepper__label { color: var(--text); font-weight: 500; }
.stepper__item--active .stepper__label { color: var(--text); font-weight: 700; }
.stepper__meta { font-size: 0.8125rem; color: var(--text-faint); margin-top: 0.1rem; }

/* ---- Status badge vocabulary (Restrained: neutral by default, accent
   only for "in motion", green/red reserved for the two terminal states) --- */
.badge--neutral .badge__dot { background: var(--text-faint); }
.badge--progress { background: rgba(147,113,47,0.1); border-color: rgba(147,113,47,0.3); }
.badge--progress .badge__dot { background: var(--accent); }
.badge--success { background: rgba(63,107,79,0.1); border-color: rgba(63,107,79,0.3); color: #2c4f39; }
.badge--success .badge__dot { background: #3f6b4f; }
.badge--danger { background: rgba(172,43,33,0.08); border-color: rgba(172,43,33,0.25); color: var(--danger); }
.badge--danger .badge__dot { background: var(--danger); }

/* ---- Session item ---- */
.session-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-3);
  padding: var(--space-2) 0;
  border-bottom: 1px solid var(--border);
}
.session-item:last-child { border-bottom: none; }
.session-item__meta { font-size: 0.8125rem; color: var(--text-faint); margin-top: 0.2rem; }
.session-item.is-current .badge { background: var(--ink); color: var(--white); border-color: var(--ink); }

/* ---- QR frame ---- */
.qr-frame {
  display: flex;
  justify-content: center;
  padding: var(--space-3);
  background: var(--white);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-block: var(--space-3);
}
.qr-frame svg { width: 180px; height: 180px; }
.secret-code {
  font-family: monospace;
  font-size: 0.9375rem;
  letter-spacing: 0.05em;
  text-align: center;
  padding: 0.6rem;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  word-break: break-all;
}

/* ---- Skeleton loaders ---- */
.skel-line, .skel-circle {
  position: relative;
  overflow: hidden;
  background: var(--surface-alt);
  border-radius: var(--radius-sm);
  display: block;
}
.skel-line::after, .skel-circle::after {
  content: '';
  position: absolute;
  inset: 0;
  transform: translateX(-100%);
  background: linear-gradient(90deg, transparent, rgba(255,255,255,0.7), transparent);
  animation: skel-shimmer 1.4s ease-in-out infinite;
}
@keyframes skel-shimmer { 100% { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) {
  .skel-line::after, .skel-circle::after { animation: none; }
}
.skel-line { height: 0.85rem; margin-bottom: 0.5rem; }
.skel-line:last-child { margin-bottom: 0; }
.skel-line--sm { height: 0.65rem; }
.skel-line--lg { height: 1.4rem; }
.skel-line--25 { width: 25%; }
.skel-line--40 { width: 40%; }
.skel-line--60 { width: 60%; }
.skel-line--80 { width: 80%; }
.skel-line--100 { width: 100%; }
.skel-circle { border-radius: 50%; flex-shrink: 0; }

.badge.is-loading .badge__dot { background: var(--border-strong); }
.badge .skel-line { margin-bottom: 0; vertical-align: middle; }

/* ---- Data table ---- */
.table-wrap {
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  overflow: auto;
  background: var(--surface);
}
.data-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.data-table th {
  text-align: left;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-faint);
  font-weight: 700;
  padding: 0.85rem 1rem;
  border-bottom: 1px solid var(--border-strong);
  background: var(--surface);
  position: sticky;
  top: 0;
  white-space: nowrap;
}
.data-table td {
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover { background: var(--surface-alt); }
.data-table tbody tr.is-priority { background: rgba(147,113,47,0.045); }
.data-table tbody tr.is-priority:hover { background: rgba(147,113,47,0.09); }
.data-table--clickable tbody tr { cursor: pointer; }
.data-table td.is-muted { color: var(--text-faint); font-variant-numeric: tabular-nums; }
.data-table td.is-empty { padding: var(--space-4); }

/* ---- Chat ---- */
.chat { display: flex; flex-direction: column; gap: var(--space-2); }
.chat__bubble-row { display: flex; }
/* The bubble + its meta line share an unstyled wrapper div (see
   dashboard-messages.js / staff.js) so they stack and share one max-width.
   That constraint has to live here, on the actual flex item — a percentage
   max-width on .chat__bubble itself can't resolve against this wrapper's
   auto/shrink-to-fit width, which collapsed bubbles down to near-zero and
   forced text to wrap character by character. */
.chat__bubble-row > div { max-width: 70%; min-width: 0; }
.chat__bubble-row--out { justify-content: flex-end; }
.chat__bubble {
  padding: 0.7rem 0.9rem;
  border-radius: var(--radius-md);
  font-size: 0.9375rem;
  white-space: pre-wrap;
  word-break: break-word;
}
.chat__bubble-row--in .chat__bubble { background: var(--surface-alt); border: 1px solid var(--border); }
.chat__bubble-row--out .chat__bubble { background: var(--ink); color: var(--white); }
.chat__bubble-row--system .chat__bubble { background: transparent; color: var(--text-faint); font-size: 0.8125rem; text-align: center; margin-inline: auto; }
.chat__meta { font-size: 0.75rem; color: var(--text-faint); margin-top: 0.25rem; }
.chat__bubble-row--out .chat__meta { text-align: right; }
.chat__attach {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-top: 0.5rem;
  padding: 0.5rem 0.7rem;
  background: rgba(255,255,255,0.08);
  border-radius: var(--radius-sm);
  font-size: 0.8125rem;
}
.chat__bubble-row--in .chat__attach { background: var(--white); border: 1px solid var(--border); }
.chat__attach svg { width: 14px; height: 14px; flex-shrink: 0; }
.chat__attach a { color: inherit; text-decoration: underline; }

.choice-card { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 0.6rem; }
.choice-option {
  text-align: left;
  padding: 0.6rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--white);
  /* Explicit, not inherited: this always has a white background, but
     without its own color it inherited whatever the surrounding chat
     bubble set — white, for the sender's own "outgoing" (dark) bubble —
     making the text invisible against this element's own white background. */
  color: var(--ink);
  font-size: 0.875rem;
  font-weight: 600;
  transition: all var(--dur-base) var(--ease-out);
}
.choice-option:hover { border-color: var(--ink); }
.choice-option.is-selected { background: var(--ink); border-color: var(--ink); color: var(--white); }
.choice-option:disabled { cursor: default; opacity: 0.7; }

/* ---- Onboarding chat (scripted post-payment intake) ---- */
.chat__bubble-row--enter { animation: xy-bubble-in var(--dur-base) var(--ease-out) both; }
@keyframes xy-bubble-in {
  0% { opacity: 0; transform: translateY(6px); }
  100% { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .chat__bubble-row--enter { animation: none; }
}
.chat-answer-card { box-shadow: var(--shadow-sm); }
.chat__typing .chat__bubble { display: flex; align-items: center; gap: 0.25rem; padding: 0.85rem 1rem; }
.chat__typing-dot {
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--text-faint);
  animation: xy-typing-bounce 1.2s var(--ease-out) infinite;
}
.chat__typing-dot:nth-child(2) { animation-delay: 0.15s; }
.chat__typing-dot:nth-child(3) { animation-delay: 0.3s; }
@keyframes xy-typing-bounce {
  0%, 60%, 100% { transform: translateY(0); opacity: 0.5; }
  30% { transform: translateY(-3px); opacity: 1; }
}

.chat-answer-card {
  margin-top: 0.6rem;
  padding: var(--space-3);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--white);
  color: var(--text);
  max-width: 420px;
}
.chat-answer-card .field { margin-bottom: var(--space-2); }
.chat-answer-card .field:last-of-type { margin-bottom: 0; }
.chat-answer-card__actions { display: flex; gap: 0.6rem; margin-top: var(--space-3); flex-wrap: wrap; }

.chat-answered-summary {
  margin-top: 0.6rem;
  padding: 0.6rem 0.85rem;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.1);
  font-size: 0.8125rem;
}
.chat-answered-summary div { display: flex; justify-content: space-between; gap: 0.75rem; padding: 0.15rem 0; }
.chat-answered-summary dt { opacity: 0.75; }
.chat-answered-summary dd { font-weight: 600; text-align: right; }

.chat-review-actions { display: flex; gap: 0.6rem; margin-top: var(--space-3); flex-wrap: wrap; }
.chat-review-edit { background: none; border: none; color: var(--accent); font-size: 0.8125rem; font-weight: 600; cursor: pointer; padding: 0; }
.chat-review-edit:hover { text-decoration: underline; }

/* Full-bleed gate: the onboarding chat is the ONLY thing visible on this
   company until intake is confirmed — deliberately not a centered
   .modal-overlay card, it replaces the panel content area outright rather
   than floating over it. */
.app-panel--gate { display: flex; flex-direction: column; }
.app-panel--gate .chat-card { height: 68vh; }

.is-unlocking { animation: xy-unlock-out var(--dur-slow) var(--ease-out) forwards; }
@keyframes xy-unlock-out {
  0% { opacity: 1; transform: scale(1); }
  100% { opacity: 0; transform: scale(0.98); }
}
[data-unlock-reveal] { animation: xy-unlock-in var(--dur-slow) var(--ease-out) both; }
[data-unlock-reveal-group] [data-unlock-reveal]:nth-child(1) { animation-delay: 0ms; }
[data-unlock-reveal-group] [data-unlock-reveal]:nth-child(2) { animation-delay: 80ms; }
[data-unlock-reveal-group] [data-unlock-reveal]:nth-child(3) { animation-delay: 160ms; }
[data-unlock-reveal-group] [data-unlock-reveal]:nth-child(4) { animation-delay: 240ms; }
[data-unlock-reveal-group] [data-unlock-reveal]:nth-child(5) { animation-delay: 320ms; }
[data-unlock-reveal-group] [data-unlock-reveal]:nth-child(6) { animation-delay: 400ms; }
@keyframes xy-unlock-in {
  0% { opacity: 0; transform: translateY(8px); }
  100% { opacity: 1; transform: translateY(0); }
}
@media (prefers-reduced-motion: reduce) {
  .is-unlocking, [data-unlock-reveal] { animation: none; }
}

.contract-card {
  margin-top: 0.6rem;
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-md);
  background: var(--white);
  color: var(--text);
  max-width: 360px;
}
.contract-card__title { font-weight: 700; font-size: 0.875rem; margin-bottom: 0.3rem; }
.contract-card__summary { font-size: 0.8125rem; color: var(--text-muted); margin-bottom: 0.6rem; }
.contract-card__footer { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; flex-wrap: wrap; }

.modal-overlay {
  position: fixed; inset: 0; z-index: 300;
  background: rgba(20, 18, 14, 0.5);
  display: flex; align-items: flex-start; justify-content: center;
  padding: var(--space-4) var(--space-3);
  overflow-y: auto;
}
.modal {
  background: var(--white);
  border-radius: var(--radius-lg);
  max-width: 680px; width: 100%;
  padding: var(--space-4);
  margin: var(--space-4) 0;
}
.modal__header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--space-3); margin-bottom: var(--space-3); }
.modal__close { border: none; background: none; cursor: pointer; font-size: 1.25rem; line-height: 1; color: var(--text-faint); padding: 0.25rem; }
.modal__close:hover { color: var(--ink); }
.contract-doc { font-family: Georgia, "Times New Roman", serif; font-size: 0.875rem; line-height: 1.6; white-space: pre-wrap; max-height: 50vh; overflow-y: auto; border: 1px solid var(--border); border-radius: var(--radius-md); padding: var(--space-3); background: var(--surface-alt); }
.modal__actions { display: flex; gap: var(--space-2); margin-top: var(--space-3); flex-wrap: wrap; }

.btn--danger { background: var(--danger); border-color: var(--danger); color: var(--white); }
.btn--danger:hover { opacity: 0.9; }

.chat-composer {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: flex-end;
  border-top: 1px solid var(--border);
  padding-top: var(--space-3);
  margin-top: var(--space-3);
}
.chat-composer textarea {
  flex: 1 1 160px;
  min-width: 0;
  min-height: 44px;
  max-height: 140px;
  padding: 0.7rem 0.85rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  resize: vertical;
}
.chat-composer__attach-btn {
  width: 44px; height: 44px;
  flex-shrink: 0;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
}
.chat-composer__attach-btn svg { width: 18px; height: 18px; }

/* ---- Page-level composition helpers (replace one-off inline layout) ---- */
.chat-card { display: flex; flex-direction: column; height: 62vh; }
.chat-card__log { flex: 1; overflow-y: auto; padding-right: 0.5rem; }
.chat-card__log.is-empty { display: flex; align-items: center; justify-content: center; }
.attach-preview { display: none; font-size: 0.8125rem; color: var(--text-faint); margin-top: 0.4rem; }
.attach-preview.is-visible { display: block; }

.inbox-layout { display: grid; grid-template-columns: 280px 1fr; gap: var(--space-3); height: 72vh; }
@media (max-width: 760px) { .inbox-layout { grid-template-columns: 1fr; height: auto; } }
.conversation-list { overflow-y: auto; padding: 0.4rem; display: flex; flex-direction: column; gap: 0.1rem; }
.conversation-item {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: 0.65rem 0.6rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: background-color var(--dur-fast) var(--ease-out);
}
.conversation-item:hover { background: var(--surface-alt); }
.conversation-item.is-active { background: var(--surface-alt); }
.conversation-item__body { flex: 1; min-width: 0; }
.conversation-item__name { font-weight: 600; font-size: 0.9375rem; display: flex; align-items: center; gap: 0.4rem; }
.conversation-item__meta { font-size: 0.8125rem; color: var(--text-faint); margin-top: 0.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conversation-pane { display: flex; flex-direction: column; min-height: 0; }
.conversation-pane__placeholder { margin: auto; }

/* ---- Panel section spacing rhythm ---- */
.panel-section { margin-bottom: var(--space-4); }
.panel-section:last-child { margin-bottom: 0; }

.btn-row { display: flex; gap: var(--space-2); flex-wrap: wrap; }

/* A row of related KPIs reads more like a considered report and less like
   a SaaS tile grid as one joined strip with dividers than as N separate
   boxed-and-shadowed cards — same information, one container. */
.grid-cards--4col {
  grid-template-columns: repeat(4, 1fr);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface);
  overflow: hidden;
  gap: 0;
}
.grid-cards--4col > .card {
  border: none;
  border-radius: 0;
  border-right: 1px solid var(--border);
  box-shadow: none !important;
  transform: none !important;
}
.grid-cards--4col > .card:last-child { border-right: none; }
@media (max-width: 900px) {
  .grid-cards--4col { grid-template-columns: 1fr 1fr; }
  .grid-cards--4col > .card:nth-child(2n) { border-right: none; }
  .grid-cards--4col > .card:nth-child(-n+2) { border-bottom: 1px solid var(--border); }
}
@media (max-width: 480px) {
  .grid-cards--4col { grid-template-columns: 1fr; }
  .grid-cards--4col > .card { border-right: none; border-bottom: 1px solid var(--border); }
  .grid-cards--4col > .card:last-child { border-bottom: none; }
}

.card--danger { border-color: rgba(172,43,33,0.35); }
.card--danger .card-head__icon { background: rgba(172,43,33,0.08); }
.card--danger .card-head__icon svg { color: var(--danger); }
