:root {
  color-scheme: dark;
  --bg: #07101c;
  --panel: #0d1a2a;
  --panel-soft: #101f31;
  --text: #f3f8fa;
  --muted: #8fa4b3;
  --cyan: #55d6e8;
  --cyan-strong: #85e7f1;
  --border: rgba(85, 214, 232, 0.18);
  --danger: #ff8c8c;
  --radius-card: 24px;
  --radius-bubble: 18px;
  --shadow: 0 28px 80px rgba(0, 0, 0, 0.38), 0 2px 12px rgba(85, 214, 232, 0.06);
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background:
    radial-gradient(circle at 15% 10%, rgba(24, 166, 185, 0.16), transparent 32rem),
    radial-gradient(circle at 85% 90%, rgba(85, 214, 232, 0.08), transparent 28rem),
    var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
  touch-action: manipulation;
}

button, textarea { font: inherit; }
button { cursor: pointer; }

.skip-link {
  position: fixed;
  left: 12px;
  top: 12px;
  z-index: 10;
  transform: translateY(-180%);
  border-radius: 8px;
  background: var(--cyan-strong);
  color: var(--bg);
  padding: 10px 14px;
}
.skip-link:focus { transform: translateY(0); }

.shell {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
}

.chat-card {
  width: min(100%, 760px);
  min-height: min(780px, calc(100dvh - 32px));
  max-height: calc(100dvh - 32px);
  display: grid;
  grid-template-rows: auto minmax(180px, 1fr) auto auto auto;
  overflow: hidden;
  background: linear-gradient(180deg, rgba(16, 31, 49, 0.98), rgba(11, 22, 37, 0.98));
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(7, 16, 28, 0.56);
}

.brand-mark, .avatar {
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  color: var(--bg);
  background: linear-gradient(145deg, var(--cyan-strong), #18a6b9);
  font-weight: 800;
  letter-spacing: -0.04em;
}
.brand-mark { width: 48px; height: 48px; border-radius: 15px; }
.avatar { width: 32px; height: 32px; border-radius: 10px; font-size: 11px; }

.brand-copy { min-width: 0; }
.eyebrow { margin: 0 0 4px; color: var(--cyan); font-size: 11px; font-weight: 800; letter-spacing: 0.16em; }
h1 { margin: 0; font-size: clamp(18px, 3vw, 23px); line-height: 1.2; text-wrap: balance; }
.presence { margin: 5px 0 0; color: var(--muted); font-size: 13px; }
.presence-dot { display: inline-block; width: 8px; height: 8px; margin-right: 5px; border-radius: 50%; background: #70d8aa; box-shadow: 0 0 0 3px rgba(112, 216, 170, 0.12); }

.messages {
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 24px;
  scroll-behavior: smooth;
}
.message { display: flex; gap: 10px; align-items: flex-end; margin-bottom: 20px; }
.message-agent { align-items: flex-start; }
.message-agent > .avatar { margin-top: 2px; }
.message-user { justify-content: flex-end; }
.message-content { display: grid; gap: 10px; width: min(90%, 600px); min-width: 0; }
.message-user .message-content { width: auto; max-width: min(84%, 560px); }
.bubble { max-width: min(84%, 560px); padding: 14px 16px; border-radius: var(--radius-bubble); overflow-wrap: anywhere; line-height: 1.55; }
.message-content .bubble { max-width: 100%; }
.bubble p { margin: 0; }
.bubble p + p { margin-top: 8px; }
.message-agent .bubble { background: var(--panel-soft); border: 1px solid rgba(255, 255, 255, 0.06); border-bottom-left-radius: 5px; }
.message-user .bubble { background: var(--cyan-strong); color: var(--bg); border-bottom-right-radius: 5px; }
.message-error .bubble { border-color: rgba(255, 140, 140, 0.4); color: #ffd0d0; }

.capabilities { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.capabilities span { padding: 5px 8px; border: 1px solid var(--border); border-radius: 999px; color: var(--cyan-strong); background: rgba(85, 214, 232, 0.06); font-size: 10px; font-weight: 700; letter-spacing: 0.02em; }

.artifact-list { display: grid; gap: 10px; min-width: 0; }
.academy-sources { display: grid; gap: 8px; margin-top: 10px; padding: 12px; border: 1px solid var(--border); border-radius: 14px; background: var(--panel-soft); }
.academy-sources-kicker { margin: 0; color: var(--cyan-strong); font-size: 10px; font-weight: 850; letter-spacing: 0.1em; }
.academy-source { display: grid; gap: 3px; min-width: 0; padding-top: 8px; border-top: 1px solid var(--border); }
.academy-source-course, .academy-source-title { margin: 0; overflow-wrap: anywhere; }
.academy-source-course { color: var(--muted); font-size: 11px; font-weight: 700; }
.academy-source-title { color: var(--text); font-size: 13px; font-weight: 800; line-height: 1.35; }
.academy-source-evidence { width: fit-content; margin-top: 3px; padding: 4px 7px; border-radius: 999px; background: var(--subtle); color: var(--cyan-strong); font-size: 10px; font-weight: 750; }
.artifact { min-width: 0; overflow: hidden; border: 1px solid rgba(133, 231, 241, 0.18); border-radius: 16px; background: rgba(7, 16, 28, 0.72); box-shadow: 0 12px 30px rgba(0, 0, 0, 0.16); }
.artifact-title { margin: 0; color: var(--text); font-size: 15px; line-height: 1.3; text-wrap: balance; }
.artifact-body { margin: 7px 0 0; color: #bed0db; font-size: 13px; line-height: 1.5; overflow-wrap: anywhere; }
.artifact-kicker { display: block; margin-bottom: 7px; color: var(--cyan); font-size: 10px; font-weight: 800; letter-spacing: 0.12em; text-transform: uppercase; }

.artifact-action { position: relative; padding: 17px; background: linear-gradient(145deg, rgba(22, 71, 92, 0.78), rgba(7, 16, 28, 0.88)); }
.artifact-action::before { content: ""; position: absolute; inset: 0 0 auto; height: 2px; background: linear-gradient(90deg, var(--cyan-strong), transparent 78%); }
.artifact-button { min-height: 44px; width: 100%; margin-top: 14px; padding: 10px 14px; border: 1px solid rgba(255, 255, 255, 0.18); border-radius: 12px; background: var(--cyan-strong); color: var(--bg); font-weight: 800; transition: transform 160ms ease, background-color 160ms ease; }
.artifact-button:hover { transform: translateY(-1px); background: #a7eff5; }
.artifact-footer { display: flex; justify-content: flex-end; padding: 9px 14px; border-top: 1px solid rgba(255, 255, 255, 0.07); background: rgba(255, 255, 255, 0.018); }
.artifact-action .artifact-footer { margin: 14px -17px -17px; }
.artifact-callout .artifact-footer { grid-column: 1 / -1; margin: 4px -15px -14px; }
.artifact-download { min-height: 44px; padding: 9px 12px; border: 1px solid var(--border); border-radius: 11px; background: rgba(85, 214, 232, 0.06); color: var(--cyan-strong); font-size: 12px; font-weight: 800; transition: background-color 160ms ease, border-color 160ms ease; }
.artifact-download:hover { border-color: rgba(85, 214, 232, 0.42); background: rgba(85, 214, 232, 0.13); }

.artifact-heading { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 15px 16px 11px; }
.artifact-progress { flex: 0 0 auto; min-width: 42px; padding: 5px 8px; border-radius: 999px; background: rgba(85, 214, 232, 0.1); color: var(--cyan-strong); text-align: center; font-size: 11px; font-weight: 800; font-variant-numeric: tabular-nums; }
.checklist { display: grid; margin: 0; padding: 0 10px 10px; list-style: none; }
.checklist-item + .checklist-item { border-top: 1px solid rgba(255, 255, 255, 0.06); }
.checklist-label { display: grid; grid-template-columns: 26px minmax(0, 1fr); align-items: center; gap: 9px; min-height: 48px; padding: 7px 6px; cursor: pointer; }
.checklist-label input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.checklist-marker { grid-column: 1; grid-row: 1; display: grid; place-items: center; width: 22px; height: 22px; border: 2px solid #668091; border-radius: 7px; background: rgba(255, 255, 255, 0.03); }
.checklist-marker::after { content: ""; width: 9px; height: 5px; border: solid var(--bg); border-width: 0 0 2px 2px; opacity: 0; transform: rotate(-45deg) translateY(-1px); }
.checklist-copy { grid-column: 2; grid-row: 1; color: #dce8ee; font-size: 13px; line-height: 1.4; overflow-wrap: anywhere; }
.checklist-label input:focus-visible + .checklist-marker { outline: 3px solid var(--cyan-strong); outline-offset: 3px; }
.checklist-label input:checked + .checklist-marker { border-color: var(--cyan-strong); background: var(--cyan-strong); }
.checklist-label input:checked + .checklist-marker::after { opacity: 1; }
.checklist-label input:checked ~ .checklist-copy { color: var(--muted); text-decoration: line-through; }
.checklist-description { margin: -3px 16px 10px; color: var(--muted); font-size: 12px; line-height: 1.5; }
.checklist-label-capture { cursor: default; }
.checklist-prompt { display: block; margin: 0 6px 7px 41px; color: #eef7fa; font-size: 13px; font-weight: 750; line-height: 1.45; }
.checklist-response { display: block; width: calc(100% - 47px); min-height: 48px; max-height: 176px; margin: 0 6px 0 41px; padding: 11px 12px; resize: vertical; border: 1px solid #668091; border-radius: 11px; outline: 0; background: rgba(1, 12, 22, 0.64); color: var(--text); font: inherit; font-size: 14px; line-height: 1.45; }
textarea.checklist-response { min-height: 96px; }
.checklist-response::placeholder { color: #718796; }
.checklist-response:focus { border-color: var(--cyan-strong); box-shadow: 0 0 0 3px rgba(85, 214, 232, 0.12); }
.checklist-response[aria-invalid="true"] { border-color: var(--danger); box-shadow: 0 0 0 3px rgba(255, 119, 119, 0.1); }
.checklist-feedback { display: block; min-height: 18px; margin: 6px 6px 10px 41px; color: var(--muted); font-size: 11px; line-height: 1.4; }
.checklist-feedback-success { color: #8ce7bd; }
.checklist-feedback-error { color: #ffaaaa; }
.checklist-privacy { margin: 0; padding: 2px 16px 12px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.checklist-review { min-height: 46px; width: calc(100% - 28px); margin: 0 14px 13px; padding: 10px 14px; border: 1px solid rgba(85, 214, 232, 0.32); border-radius: 12px; background: rgba(85, 214, 232, 0.09); color: var(--cyan-strong); font-weight: 850; }
.checklist-review:hover, .checklist-review-ready { background: var(--cyan-strong); color: var(--bg); }
.artifact-complete { border-color: rgba(112, 216, 170, 0.42); }
.artifact-complete .artifact-progress { background: rgba(112, 216, 170, 0.14); color: #8ce7bd; }

.artifact-comparison { padding-top: 15px; }
.artifact-comparison > .artifact-title { padding: 0 16px 12px; }
.comparison-scroll { overflow-x: auto; overscroll-behavior-inline: contain; outline: none; }
.comparison-scroll:focus-visible { box-shadow: inset 0 0 0 3px var(--cyan-strong); }
.comparison-table { width: 100%; min-width: 440px; border-collapse: collapse; font-size: 12px; line-height: 1.4; }
.comparison-table th, .comparison-table td { padding: 11px 12px; border-top: 1px solid rgba(255, 255, 255, 0.07); text-align: left; vertical-align: top; overflow-wrap: anywhere; }
.comparison-column { color: var(--cyan-strong); background: rgba(85, 214, 232, 0.06); font-weight: 800; }
.comparison-corner, .comparison-label { color: var(--muted); font-weight: 750; }
.comparison-label { width: 28%; }
.comparison-value { color: #dce8ee; }

.artifact-callout { display: grid; grid-template-columns: 30px minmax(0, 1fr); gap: 10px; padding: 14px 15px; }
.callout-icon { display: grid; place-items: center; width: 28px; height: 28px; border-radius: 9px; background: rgba(85, 214, 232, 0.12); color: var(--cyan-strong); font-weight: 900; }
.artifact-success { border-color: rgba(112, 216, 170, 0.34); }
.artifact-success .callout-icon { background: rgba(112, 216, 170, 0.14); color: #8ce7bd; }
.artifact-warning { border-color: rgba(253, 177, 43, 0.38); }
.artifact-warning .callout-icon { background: rgba(253, 177, 43, 0.14); color: #ffd07a; }
.callout-copy { min-width: 0; }

.artifact-video { background: linear-gradient(145deg, rgba(8, 33, 54, 0.88), rgba(7, 16, 28, 0.92)); border-color: rgba(133, 231, 241, 0.26); }
.video-card { display: grid; grid-template-columns: 132px minmax(0, 1fr); gap: 13px; align-items: stretch; padding: 11px; color: inherit; text-decoration: none; }
.video-card:hover .video-open { color: #ffffff; transform: translateX(2px); }
.video-thumb { width: 132px; height: 84px; object-fit: cover; border-radius: 13px; border: 1px solid rgba(255, 255, 255, 0.12); background: rgba(255, 255, 255, 0.04); }
.video-thumb-missing { display: block; background: linear-gradient(135deg, rgba(85, 214, 232, 0.18), rgba(253, 177, 43, 0.14)); }
.video-copy { min-width: 0; display: grid; align-content: start; gap: 5px; }
.video-copy .artifact-body { margin-top: 0; }
.video-next { margin: 0; color: #dce8ee; font-size: 12px; line-height: 1.4; overflow-wrap: anywhere; }
.video-open { display: inline-flex; width: fit-content; margin-top: 3px; color: var(--cyan-strong); font-size: 12px; font-weight: 850; transition: transform 160ms ease, color 160ms ease; }
.video-actions { display: flex; justify-content: flex-end; padding: 0 11px 9px; }
.video-copy-link { min-height: 44px; padding: 8px 11px; border: 1px solid var(--border); border-radius: 10px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 800; }
.video-copy-link:hover { border-color: rgba(85, 214, 232, 0.42); color: var(--cyan-strong); }

.suggestions { display: flex; flex-wrap: wrap; gap: 8px; overflow-x: visible; padding: 0 24px 14px; }
.suggestion { min-height: 44px; flex: 1 1 150px; border: 1px solid var(--border); border-radius: 999px; padding: 9px 14px; color: var(--cyan-strong); background: rgba(85, 214, 232, 0.06); line-height: 1.25; white-space: normal; }
.suggestion:hover { background: rgba(85, 214, 232, 0.12); border-color: rgba(85, 214, 232, 0.38); }

.composer { display: flex; align-items: flex-end; gap: 10px; margin: 0 16px; padding: 10px; background: rgba(7, 16, 28, 0.84); border: 1px solid var(--border); border-radius: 18px; }
textarea { min-height: 44px; max-height: 144px; width: 100%; resize: none; border: 0; outline: 0; padding: 11px 10px; color: var(--text); background: transparent; font-size: 16px; line-height: 1.4; }
textarea::placeholder { color: #718796; }
.send-button { width: 44px; height: 44px; flex: 0 0 auto; display: grid; place-items: center; border: 0; border-radius: 13px; background: var(--cyan-strong); color: var(--bg); transition: transform 160ms ease, background-color 160ms ease, opacity 160ms ease; }
.send-button:hover { background: #a7eff5; transform: translateY(-1px); }
.send-button:active { transform: translateY(0); }
.send-button:disabled { cursor: wait; opacity: 0.55; transform: none; }
.send-button svg { width: 22px; height: 22px; fill: currentColor; }

.status-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 8px; padding: 0 16px max(8px, env(safe-area-inset-bottom)); }
.status { min-height: 36px; margin: 0; padding: 8px 0; color: var(--muted); text-align: center; font-size: 11px; line-height: 1.4; }
.status-error { color: var(--danger); }
.clear-local-data { min-height: 44px; padding: 8px 10px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-size: 11px; font-weight: 750; text-decoration: underline; text-underline-offset: 3px; }
.clear-local-data:hover { color: var(--text); background: rgba(255, 255, 255, 0.05); }

button:focus-visible, input:focus-visible, textarea:focus-visible, a:focus-visible, .skip-link:focus-visible { outline: 3px solid var(--cyan-strong); outline-offset: 3px; }
.composer:focus-within { border-color: rgba(85, 214, 232, 0.62); box-shadow: 0 0 0 3px rgba(85, 214, 232, 0.1); }

.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; }

.typing { display: inline-flex; gap: 5px; align-items: center; min-height: 20px; }
.typing span { width: 6px; height: 6px; border-radius: 50%; background: var(--muted); animation: pulse 1.2s infinite ease-in-out; }
.typing span:nth-child(2) { animation-delay: 140ms; }
.typing span:nth-child(3) { animation-delay: 280ms; }
@keyframes pulse { 0%, 60%, 100% { opacity: 0.35; transform: translateY(0); } 30% { opacity: 1; transform: translateY(-3px); } }

@media (max-width: 640px) {
  .shell { padding: 0; }
  .chat-card { min-height: 100dvh; max-height: 100dvh; border: 0; border-radius: 0; }
  .chat-header { padding: max(16px, env(safe-area-inset-top)) 16px 14px; }
  .messages { padding: 18px 16px; }
  .suggestions { padding: 0 16px 12px; }
  .status-row { padding-right: 10px; padding-bottom: max(8px, env(safe-area-inset-bottom)); padding-left: 16px; }
  .status { text-align: left; }
  .bubble { max-width: 88%; }
  .video-card { grid-template-columns: 104px minmax(0, 1fr); gap: 10px; padding: 10px; }
  .video-thumb { width: 104px; height: 68px; border-radius: 11px; }
  .video-next { font-size: 11px; }
}

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