/* AChA Team AI, chat-only shell.
 * Tokens follow Australian-Christian-Arts/acha-brand tokens/tokens.css and
 * system/tokens-extended.css: Off-White canvas, white cards, black text,
 * Dusty Teal accent with BLACK text on teal, Olive Yellow accent only.
 * Crimson is not part of this palette (removed 2026-10-26).
 * The second block maps the names team-ai-chat-cards.js reads (var(--border),
 * var(--dusty), var(--fs-3) ...) onto the brand tokens so the shared card
 * runtime renders on brand without its old design-system bundle. */

@font-face { font-family: "Neue Regrade"; src: url("/fonts/NeueRegrade-Variable.ttf") format("truetype"); font-weight: 100 500; font-display: swap; }
@font-face { font-family: "Neue Regrade"; src: url("/fonts/NeueRegrade-Semibold.otf") format("opentype"); font-weight: 600 900; font-display: swap; }
@font-face { font-family: "Helvetica Neue"; src: local("Helvetica Neue"), url("/fonts/woff2/helvetica-light.woff2") format("woff2"); font-weight: 300; font-display: swap; }
@font-face { font-family: "Helvetica Neue"; src: local("Helvetica Neue"), url("/fonts/woff2/helvetica-regular.woff2") format("woff2"); font-weight: 400 600; font-display: swap; }
@font-face { font-family: "Helvetica Neue"; src: local("Helvetica Neue Bold"), url("/fonts/woff2/helvetica-bold.woff2") format("woff2"); font-weight: 700 900; font-display: swap; }

:root {
  /* Brand primitives (acha-brand tokens/tokens.css) */
  --color-white: #FFFFFF; /* acha-token: color-white */
  --color-offwhite: #F7F6F3; /* acha-token: color-offwhite */
  --color-black: #0D0D0C; /* acha-token: color-black */
  --color-teal: #6E9C9C; /* acha-token: color-teal */
  --color-taupe: #C5BDA2; /* acha-token: color-taupe */
  --color-olive: #C9CE55; /* acha-token: color-olive */
  --color-gray: #E2E2E2; /* acha-token: color-gray */
  --font-heading: "Neue Regrade", "Helvetica Neue", Arial, sans-serif;
  --font-body: "Helvetica Neue", Helvetica, Arial, sans-serif;

  /* Brand semantics (acha-brand system/tokens-extended.css) */
  --bg-canvas: var(--color-offwhite);
  --bg-surface: var(--color-white);
  --bg-brand: var(--color-teal);
  --text-primary: var(--color-black);
  --text-secondary: rgb(0 0 0 / .72);
  --text-on-brand: var(--color-black);
  --text-link: var(--color-black);
  --text-link-decoration: var(--color-teal);
  --highlight-bg: var(--color-olive);
  --border-subtle: var(--color-gray);
  --border-strong: rgb(0 0 0 / .55);
  --focus-ring-color: var(--color-black);
  --radius-control: .25rem;
  --radius-card: .5rem;
  --radius-bubble: 1rem;
  --shadow-1: 0 1px 2px rgb(0 0 0 / .06);
  --shadow-3: 0 8px 24px rgb(0 0 0 / .10);
  --duration-base: 200ms;
  --ease-standard: cubic-bezier(.2, 0, 0, 1);
  --tap: 44px;
  --composer-max: 46rem;

  /* Names read by team-ai-chat-cards.js, mapped onto the brand */
  --white: var(--color-white);
  --text: var(--color-black);
  --border: var(--color-gray);
  --muted: rgb(0 0 0 / .72);
  --teal: var(--color-teal);
  --teal-text: var(--color-black);
  --dusty: rgb(110 156 156 / .10);
  --dusty-deep: rgb(110 156 156 / .22);
  --taupe: var(--color-taupe);
  --taupe-soft: rgb(197 189 162 / .28);
  --olive: var(--color-black);
  --success: var(--color-black);
  --success-bg: rgb(110 156 156 / .16);
  --warning: var(--color-black);
  --warning-bg: rgb(201 206 85 / .35);
  --fs-1: 12px; --fs-2: 13px; --fs-3: 14px; --fs-4: 15px; --fs-5: 16px; --fs-6: 17px; --fs-7: 22px; --fs-8: 28px;
  --kicker-size: 12px; --kicker-weight: 600; --kicker-track: .08em;
  --sp-2: 8px; --sp-3: 12px; --sp-4: 16px;
  --shadow-lg: var(--shadow-3);
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg-canvas);
  color: var(--text-primary);
  font: 400 16px/1.6 var(--font-body);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  min-height: 100dvh;
}
[hidden] { display: none !important; }
h1, h2, h3 { font-family: var(--font-heading); font-weight: 700; line-height: 1.2; margin: 0; letter-spacing: -.01em; }
a { color: var(--text-link); text-decoration: underline; text-decoration-color: var(--text-link-decoration); text-decoration-thickness: 2px; text-underline-offset: 3px; }
button { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus-ring-color); outline-offset: 2px; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0; }

.mark { display: block; color: var(--color-black); }

/* Buttons shared with the card runtime */
.btn-primary, .btn-secondary, .btn-quiet, .btn-signin {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: var(--radius-control);
  font: 600 15px/1 var(--font-body); cursor: pointer; text-decoration: none;
  transition: background var(--duration-base) var(--ease-standard), border-color var(--duration-base) var(--ease-standard);
}
.btn-primary, .btn-signin { background: var(--bg-brand); color: var(--text-on-brand); border: 1px solid var(--bg-brand); }
.btn-primary:hover, .btn-signin:hover { background: rgb(110 156 156 / .85); }
.btn-secondary { background: var(--bg-surface); color: var(--text-primary); border: 1px solid var(--border-strong); }
.btn-secondary:hover { background: var(--dusty); }
.btn-quiet { background: transparent; color: var(--text-primary); border: 1px solid transparent; }
.btn-quiet:hover { background: var(--dusty); }
.btn-primary:disabled, .btn-secondary:disabled, .btn-quiet:disabled, .pill-action:disabled { opacity: .55; cursor: not-allowed; }

.pill-action {
  display: inline-flex; align-items: center; gap: 6px; min-height: var(--tap); padding: 8px 16px;
  border-radius: 999px; border: 1px solid var(--border-strong); background: var(--bg-surface);
  color: var(--text-primary); font: 500 15px/1.35 var(--font-body); cursor: pointer; text-align: left;
}
.pill-action:hover { border-color: var(--color-teal); background: var(--dusty-deep); }
.pill-state, .tag-meta {
  display: inline-flex; align-items: center; min-height: 24px; padding: 2px 10px; border-radius: 999px;
  background: var(--dusty-deep); color: var(--text-primary); font: 600 12px/1.3 var(--font-body);
}
.tag-meta { border-radius: 4px; background: var(--taupe-soft); }
.pill-state.is-urgent { background: var(--highlight-bg); }
.card-index { font-size: var(--kicker-size); font-weight: var(--kicker-weight); letter-spacing: var(--kicker-track); text-transform: uppercase; color: var(--text-primary); }
.progress { height: 6px; border-radius: 999px; background: var(--color-gray); overflow: hidden; }
.progress-fill { height: 100%; background: var(--color-teal); }
.menu { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow-3); padding: 6px; }
.menu-item { display: flex; align-items: center; width: 100%; min-height: var(--tap); padding: 0 12px; border: 0; background: none; border-radius: 6px; cursor: pointer; text-align: left; }
.menu-item:hover { background: var(--dusty); }
.chip-person { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px 4px 4px; border: 1px solid var(--border); border-radius: 999px; background: var(--bg-surface); font-size: 14px; }
.chip-avatar { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--dusty-deep); font-size: 12px; font-weight: 700; }
.card { background: var(--bg-surface); border: 1px solid var(--border); border-radius: var(--radius-card); padding: 16px; }

/* ---------- Status and sign-in screens ---------- */
.screen {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid; place-items: center;
  padding: max(24px, env(safe-area-inset-top)) 16px max(24px, env(safe-area-inset-bottom));
}
.signin-card {
  width: min(420px, 100%); background: var(--bg-surface); border: 1px solid var(--border);
  border-radius: 12px; padding: 40px 32px 32px; box-shadow: var(--shadow-1); text-align: center;
}
.signin-card .mark { width: 72px; height: auto; margin: 0 auto 24px; }
.signin-card h1 { font-size: 28px; margin-bottom: 8px; }
.signin-card p { margin: 0 0 28px; color: var(--text-secondary); }
.btn-signin { width: 100%; min-height: 52px; font-size: 16px; }
.btn-signin svg { width: 18px; height: 18px; flex: none; }
.signin-foot { margin: 20px 0 0 !important; font-size: 13px; color: var(--text-secondary); }
.brand-line { height: 4px; border-radius: 2px; margin: 28px auto 0; width: 64px; background: linear-gradient(270deg, #C5BDA2 8%, #C9CE55 49%, #6E9C9C 90%); }
.status-card { width: min(420px, 100%); text-align: center; }
.status-card .mark { width: 56px; height: auto; margin: 0 auto 20px; }
.status-card p { color: var(--text-secondary); margin: 8px 0 20px; }

/* ---------- Chat app ---------- */
.app {
  display: grid; grid-template-columns: 280px 1fr; grid-template-rows: auto 1fr;
  height: 100vh;
  height: 100dvh;
}
.topbar {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 8px;
  padding: max(8px, env(safe-area-inset-top)) 16px 8px; min-height: 60px;
  background: var(--bg-canvas); border-bottom: 1px solid var(--border);
}
.topbar .brand { display: flex; align-items: center; gap: 10px; margin-right: auto; min-width: 0; }
.topbar .mark { width: 34px; height: auto; flex: none; }
.topbar h1 { font-size: 18px; white-space: nowrap; }
.icon-btn {
  display: inline-grid; place-items: center; width: var(--tap); height: var(--tap); flex: none;
  border: 1px solid transparent; border-radius: 10px; background: transparent; cursor: pointer;
}
.icon-btn:hover { background: var(--dusty); }
.icon-btn svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; background: var(--bg-brand); color: var(--text-on-brand); font: 700 14px/1 var(--font-body); overflow: hidden; }
.avatar img { width: 100%; height: 100%; object-fit: cover; }
#history-toggle { display: none; }

.account { position: relative; }
.account .menu { position: absolute; right: 0; top: calc(100% + 6px); min-width: 240px; z-index: 50; }
.account .who { padding: 10px 12px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; font-size: 14px; }
.account .who strong { display: block; font-size: 15px; }
.account .who span { color: var(--text-secondary); word-break: break-all; }

.history {
  grid-row: 2; display: flex; flex-direction: column; min-height: 0;
  background: var(--bg-canvas); border-right: 1px solid var(--border);
}
.history-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 16px 8px; }
.history-head h2 { font-size: 13px; font-family: var(--font-body); font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-secondary); }
.history-list { list-style: none; margin: 0; padding: 0 8px 16px; overflow-y: auto; flex: 1; }
.history-item { display: flex; align-items: stretch; border-radius: 8px; }
.history-item:hover, .history-item.is-current { background: var(--bg-surface); }
.history-item.is-current { box-shadow: inset 3px 0 0 var(--color-teal); }
.history-open {
  flex: 1; min-width: 0; min-height: var(--tap); padding: 8px 10px; border: 0; background: none;
  text-align: left; cursor: pointer; display: flex; flex-direction: column; justify-content: center;
}
.history-title { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.history-meta { font-size: 12px; color: var(--text-secondary); display: flex; align-items: center; gap: 6px; }
.history-meta .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--color-teal); }
.history-delete { opacity: 0; }
.history-item:hover .history-delete, .history-item:focus-within .history-delete { opacity: 1; }
.history-empty { padding: 8px 16px; color: var(--text-secondary); font-size: 14px; }
.scrim { display: none; }

.main { grid-row: 2; display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.thread { flex: 1; overflow-y: auto; padding: 24px 16px 8px; scroll-behavior: smooth; overscroll-behavior: contain; }
.thread-inner { max-width: var(--composer-max); margin: 0 auto; display: flex; flex-direction: column; gap: 16px; }

.welcome { max-width: var(--composer-max); margin: 6vh auto 0; text-align: left; }
.welcome h2 { font-size: 32px; margin-bottom: 6px; }
.welcome .lede { color: var(--text-secondary); margin: 0 0 24px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.chip-label { display: block; font-size: 12px; font-weight: 600; letter-spacing: .08em; text-transform: uppercase; color: var(--text-secondary); margin: 0 0 10px; }
.category-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr)); gap: 8px; margin-bottom: 16px; }
.category {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; min-height: 64px;
  padding: 12px 14px; border: 1px solid var(--border); border-radius: var(--radius-card);
  background: var(--bg-surface); cursor: pointer; text-align: left;
}
.category:hover { border-color: var(--color-teal); }
.category[aria-expanded="true"] { border-color: var(--color-teal); background: var(--dusty); }
.category strong { font-family: var(--font-heading); font-size: 16px; font-weight: 600; }
.category span { font-size: 13px; color: var(--text-secondary); }

.msg { display: flex; flex-direction: column; gap: 8px; }
.msg-user { align-items: flex-end; }
.bubble { max-width: min(85%, 40rem); padding: 12px 16px; border-radius: var(--radius-bubble); overflow-wrap: anywhere; }
.msg-user .bubble { background: var(--bg-brand); color: var(--text-on-brand); border-bottom-right-radius: 6px; white-space: pre-wrap; }
.msg-assistant .bubble { background: var(--bg-surface); border: 1px solid var(--border); border-bottom-left-radius: 6px; max-width: 100%; }
.msg-assistant.is-streaming .bubble { border-color: var(--color-teal); }
.bubble p { margin: 0 0 .7em; }
.bubble p:last-child, .bubble ul:last-child, .bubble ol:last-child { margin-bottom: 0; }
.bubble ul, .bubble ol { margin: 0 0 .7em; padding-left: 1.3em; }
.bubble li { margin: .2em 0; }
.bubble code { font-family: ui-monospace, Menlo, monospace; font-size: .9em; background: var(--taupe-soft); padding: 1px 5px; border-radius: 4px; }
.bubble .h { font-family: var(--font-heading); font-weight: 600; font-size: 17px; margin: .4em 0 .3em; }
.cards { display: flex; flex-direction: column; gap: 10px; }
.cards:empty { display: none; }
.cards .pill-action { width: 100%; }
.msg-time { font-size: 12px; color: var(--text-secondary); padding: 0 4px; }
.msg-tools { display: flex; gap: 4px; }
.msg-tools .icon-btn { width: var(--tap); height: var(--tap); }
.msg-tools .icon-btn svg { width: 18px; height: 18px; }

.working { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; font-size: 14px; color: var(--text-secondary); padding: 4px 2px; }
.working-steps { flex-basis: 100%; list-style: none; margin: 2px 0 0 20px; padding: 0; display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 13px; color: var(--text-secondary); }
.working .pulse { width: 10px; height: 10px; border-radius: 50%; background: var(--color-teal); animation: pulse 1.2s var(--ease-standard) infinite; flex: none; }
@keyframes pulse { 0%, 100% { opacity: .35; transform: scale(.85); } 50% { opacity: 1; transform: scale(1); } }
.stages { display: flex; flex-wrap: wrap; gap: 6px; }
.notice { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; padding: 12px 14px; border-radius: var(--radius-card); background: var(--bg-surface); border: 1px solid var(--border-strong); border-left: 4px solid var(--color-black); font-size: 15px; }
.notice.is-warning { border-left-color: var(--color-olive); }

.composer-wrap { padding: 8px 16px max(12px, env(safe-area-inset-bottom)); background: var(--bg-canvas); }
.composer {
  max-width: var(--composer-max); margin: 0 auto; display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 8px 8px 16px; background: var(--bg-surface); border: 1px solid var(--border-strong);
  border-radius: 16px; box-shadow: var(--shadow-1);
}
.composer:focus-within { border-color: var(--color-black); }
.composer textarea {
  flex: 1; min-height: var(--tap); max-height: 40vh; resize: none; border: 0; outline: none;
  padding: 10px 0; background: transparent; color: var(--text-primary);
  font: 400 16px/1.5 var(--font-body);
}
.composer textarea::placeholder { color: rgb(0 0 0 / .55); }
.send-btn {
  display: inline-grid; place-items: center; width: var(--tap); height: var(--tap); flex: none;
  border-radius: 12px; border: 1px solid var(--bg-brand); background: var(--bg-brand); color: var(--text-on-brand); cursor: pointer;
}
.send-btn svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.send-btn.is-stop { background: var(--color-black); border-color: var(--color-black); color: var(--color-white); }
.send-btn:disabled { opacity: .5; cursor: not-allowed; }
.composer-note { max-width: var(--composer-max); margin: 6px auto 0; font-size: 12px; color: var(--text-secondary); text-align: center; }

.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: min(430px, calc(100vw - 32px)); padding: 12px 16px; border-radius: 10px;
  background: var(--color-black); color: var(--color-white); font-size: 15px; z-index: 1200; box-shadow: var(--shadow-3);
}

@media (max-width: 768px) {
  .app { grid-template-columns: 1fr; }
  #history-toggle { display: inline-grid; }
  .topbar { padding-left: 8px; padding-right: 8px; }
  .topbar h1 { font-size: 17px; }
  .history {
    position: fixed; top: 0; bottom: 0; left: 0; width: min(86vw, 320px); z-index: 60;
    padding-top: env(safe-area-inset-top); background: var(--bg-canvas);
    transform: translateX(-100%); transition: transform var(--duration-base) var(--ease-standard);
  }
  .app.history-open .history { transform: none; box-shadow: var(--shadow-3); }
  .app.history-open .scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgb(0 0 0 / .4); border: 0; }
  .history-delete { opacity: 1; }
  .main { grid-row: 2; }
  .thread { padding: 16px 12px 8px; }
  .welcome { margin-top: 2vh; }
  .welcome h2 { font-size: 26px; }
  .bubble { max-width: 92%; }
  .composer-wrap { padding-left: 8px; padding-right: 8px; }
  .signin-card { padding: 32px 20px 24px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; }
}

/* Tables and tappable items (2026-10-27: "everything interactive") */
.table-wrap { overflow-x: auto; margin: 8px 0 12px; border: 1px solid var(--color-gray, #E2E2E2); border-radius: 12px; background: #FFFFFF; }
.md-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.md-table th { text-align: left; font-weight: 600; padding: 10px 12px; background: var(--color-offwhite, #F7F6F3); border-bottom: 1px solid var(--color-gray, #E2E2E2); white-space: nowrap; }
.md-table td { padding: 10px 12px; border-bottom: 1px solid var(--color-gray, #E2E2E2); vertical-align: top; }
.md-table tbody tr:last-child td { border-bottom: 0; }
.is-tappable { cursor: pointer; }
.md-table tr.is-tappable:hover td, .md-table tr.is-tappable:focus-visible td { background: rgba(110, 156, 156, 0.12); }
li.is-tappable { border-radius: 8px; padding: 2px 6px; margin-left: -6px; }
li.is-tappable:hover, li.is-tappable:focus-visible { background: rgba(110, 156, 156, 0.12); }
.table-note { margin: 0; padding: 8px 12px; font-size: 13px; color: var(--text-secondary); border-top: 1px solid var(--color-gray, #E2E2E2); }
blockquote { margin: 8px 0; padding: 10px 14px; background: var(--color-offwhite, #F7F6F3); border-radius: 8px; font-style: italic; }
