* {
  box-sizing: border-box;
}

html {
  scroll-behavior: smooth;
}

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

a {
  color: var(--accent);
  text-decoration: none;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

/* ── App shell ── */

.app-shell {
  display: grid;
  grid-template-columns: 216px 1fr;
  min-height: 100vh;
}

.side {
  background: var(--panel);
  border-right: 1px solid var(--hair);
  padding: 18px 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 0;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.side-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.wh-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 10px 18px;
  margin-bottom: 2px;
}

.wh-mark {
  width: 30px;
  height: 30px;
  flex: none;
}

.wh-mark circle {
  fill: none;
  stroke: var(--brand);
  stroke-width: 2.6;
}

.wh-mark text {
  fill: var(--brand);
  font-family: var(--font-ui);
  font-size: 12.5px;
  font-weight: 600;
  letter-spacing: 0.4px;
}

.app-name {
  font-weight: 600;
  font-size: 15.5px;
  letter-spacing: -0.01em;
  color: var(--brand);
}

.side-link {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 8px 10px 8px 12px;
  margin-left: 0;
  border-radius: 0 8px 8px 0;
  color: var(--muted);
  text-decoration: none;
  font-size: 13px;
  font-weight: 500;
  line-height: 1.3;
  transition: background 0.15s, color 0.15s;
  border: none;
  background: transparent;
  width: 100%;
  text-align: left;
  cursor: pointer;
  font-family: inherit;
}

.side-link:hover {
  background: var(--paper);
  color: var(--brand);
  text-decoration: none;
}

.side-link.on {
  background: var(--accent-soft);
  color: var(--brand);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}

.side-link.on .side-icon {
  color: var(--brand);
}

.side-icon {
  width: 16px;
  height: 16px;
  flex: none;
  color: var(--muted);
}

.side-link:hover .side-icon {
  color: var(--brand);
}

.sep {
  margin: 14px 10px 8px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  font-weight: 600;
}

.side-foot {
  margin-top: auto;
  padding: 12px 10px 4px;
  border-top: 1px solid var(--hair);
  font-size: 11.5px;
  color: var(--faint);
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.side-foot b {
  color: var(--muted);
  font-weight: 600;
}

.side-foot-row {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 8px;
}

.side-profile {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.side-profile-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 8px 8px;
  border: 1px solid var(--hair);
  border-radius: 10px;
  background: var(--surface, #fff);
  color: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.side-profile-btn:hover {
  border-color: var(--muted);
  background: var(--surface-2, #f4f6f8);
}

.side-profile-avatar {
  flex: 0 0 auto;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--surface-2, #f4f6f8);
  color: var(--muted);
  border: 1px solid var(--hair);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.side-profile-avatar.is-user {
  background: var(--brand, #1e3a5f);
  color: #fff;
  border-color: transparent;
}

.side-profile-icon {
  width: 16px;
  height: 16px;
  display: block;
}

.side-profile-meta {
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.side-profile-meta strong {
  font-size: 12px;
  color: var(--ink, #0f172a);
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.side-profile-meta span {
  font-size: 11px;
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.side-profile-logout {
  align-self: stretch;
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 11px;
  cursor: pointer;
  padding: 2px 8px;
  text-align: left;
}

.side-profile-logout:hover {
  color: #b91c1c;
}

.login-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-bottom: 4px;
}

.login-tab {
  border: none;
  background: transparent;
  padding: 8px 10px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  cursor: pointer;
}

.login-tab.on {
  background: var(--surface-2, #f4f6f8);
  color: var(--ink, #0f172a);
}

.login-close {
  position: absolute;
  top: 10px;
  right: 12px;
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  color: var(--muted);
  cursor: pointer;
}

.main {
  padding: 22px 26px 48px;
  min-width: 0;
  max-width: 1200px;
}

/* ── Page head ── */

.pagehead {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
  flex-wrap: wrap;
}

.pagehead-lead {
  min-width: 0;
  flex: 1;
}

.pagehead h3 {
  font-size: 18px;
  font-weight: 700;
  margin: 0;
  letter-spacing: -0.015em;
  color: var(--brand);
}

.pagehead h3[hidden] {
  display: none !important;
}

.back-to-chat-btn {
  flex-shrink: 0;
  order: -1;
}

.crumb {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--faint);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.pagehead-actions {
  margin-left: auto;
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.pagehead-actions-group {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.pagehead-actions-group[hidden] {
  display: none !important;
}

/* ── Buttons ── */

.btn,
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 12.5px;
  font-weight: 600;
  padding: 8px 16px;
  border-radius: var(--radius-input);
  text-decoration: none;
  cursor: pointer;
  font-family: inherit;
  border: none;
}

.btn.primary,
.pill-cta {
  background: var(--accent);
  color: #fff;
}

.btn.primary:hover,
.pill-cta:hover {
  background: var(--brand);
}

.btn.ghost,
.pill:not(.pill-cta) {
  background: var(--panel);
  border: 1px solid var(--hair-strong);
  color: var(--muted);
}

.btn.ghost:hover,
.pill:not(.pill-cta):hover {
  border-color: var(--accent);
  color: var(--brand);
}

button:disabled,
.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.pill-cta b {
  display: none;
}

/* ── Flow bar ── */

.flowbar {
  display: flex;
  align-items: center;
  gap: 18px;
  margin: 4px 0 18px;
  flex-wrap: wrap;
}

.steps {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  row-gap: 6px;
}

.stp {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 600;
  color: var(--faint);
  white-space: nowrap;
  border: none;
  background: transparent;
  padding: 4px 6px;
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
}

.stp:hover {
  background: var(--accent-soft);
  color: var(--brand);
}

.stp .i {
  width: 20px;
  height: 20px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10.5px;
  font-weight: 700;
  border: 1.5px solid var(--hair-strong);
  color: var(--faint);
  background: var(--panel);
}

.stp.done {
  color: var(--good);
}

.stp.done .i {
  background: var(--good-bg);
  border-color: transparent;
  color: var(--good);
}

.stp.act {
  color: var(--brand);
}

.stp.act .i {
  background: var(--accent);
  border-color: transparent;
  color: #fff;
  box-shadow: 0 2px 8px rgba(3, 69, 117, 0.28);
}

.sepln {
  width: 20px;
  height: 1.5px;
  background: var(--hair-strong);
  margin: 0 9px;
}

.flowbar .hint {
  margin-left: auto;
  padding-left: 14px;
  border-left: 2px solid var(--accent);
  font-size: 11.5px;
  color: var(--muted);
  line-height: 1.45;
  max-width: 48ch;
}

/* ── Grid & cards ── */

.grid2 {
  display: grid;
  grid-template-columns: 1.55fr 1fr;
  gap: 16px;
}

.aside-stack {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.aside-stack .panel-tabs {
  margin-bottom: 0;
}

.card {
  background: var(--panel);
  border: 1px solid var(--hair);
  border-radius: var(--radius-card);
  padding: 16px 18px;
}

.card-wide {
  margin-top: 16px;
}

.card h5 {
  font-size: 13px;
  font-weight: 700;
  margin: 0 0 10px;
  color: var(--brand);
}

.card h5 small {
  font-weight: 500;
  color: var(--faint);
  font-size: 11px;
  margin-left: 6px;
}

/* ── Chat ── */

.chat-card {
  display: flex;
  flex-direction: column;
  min-height: 420px;
}

.chat-log {
  flex: 1;
  min-height: 280px;
  overflow: auto;
  margin-bottom: 4px;
}

.chat-status {
  margin-bottom: 10px;
  padding: 10px 13px;
  border-radius: var(--radius-input);
  background: var(--accent-soft);
  border: 1px solid var(--hair);
  font-size: 12.5px;
  color: var(--muted);
}

.chat-status[hidden] {
  display: none !important;
}

.bubble,
.msg {
  max-width: 88%;
  margin: 0 0 10px;
  padding: 10px 13px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
}

.bubble.user,
.msg.user {
  margin-left: auto;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}

.bubble.ai,
.msg.assistant {
  background: var(--ai-bg);
  border: 1px solid #ddd5ef;
  border-bottom-left-radius: 4px;
  color: var(--ink);
}

.bubble .who,
.msg .who {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  opacity: 0.85;
  display: block;
  margin-bottom: 2px;
}

.bubble.ai .who,
.msg.assistant .who {
  color: var(--ai);
}

.bubble.user .who,
.msg.user .who {
  color: rgba(255, 255, 255, 0.85);
}

.composer,
.chat-input-row {
  display: flex;
  gap: 8px;
  margin-top: 12px;
}

.composer .field,
.chat-form input[type="text"] {
  flex: 1;
  border: 1px solid var(--hair-strong);
  border-radius: var(--radius-input);
  padding: 9px 14px;
  color: var(--ink);
  font-size: 13px;
  background: var(--panel);
}

.composer .send,
.chat-form button[type="submit"] {
  width: 36px;
  height: 36px;
  min-height: 36px;
  padding: 0;
  border-radius: var(--radius-input);
  background: var(--accent);
  color: #fff;
  border: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  cursor: pointer;
  flex: none;
}

/* ── Brief kv ── */

.brief-kv {
  margin-bottom: 8px;
}

.kv {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--hair);
  font-size: 12.5px;
}

.kv:last-child {
  border-bottom: none;
}

.kv .k {
  color: var(--faint);
  font-weight: 500;
}

.kv .v {
  font-weight: 600;
  text-align: right;
  max-width: 58%;
  word-break: break-word;
}

.brief-edit {
  margin-top: 8px;
  font-size: 12.5px;
}

.brief-edit summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 8px;
}

.brief-edit[open] summary {
  margin-bottom: 12px;
}

/* ── Sources ── */

.srcrow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--hair);
  font-size: 13px;
}

.srcrow:last-of-type {
  border-bottom: none;
}

.local-docs-controls {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 12px;
  padding: 12px;
  border: 1px solid var(--hair);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel, #fff) 92%, var(--accent-soft, #e8eef8));
}

.local-docs-controls label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
}

.local-docs-controls input[type="file"] {
  width: 100%;
}

.local-upload {
  font-weight: 500;
}

.connections-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  margin-top: 12px;
}

.conn-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 14px 2px;
  border-bottom: 1px solid var(--hair);
  font-size: 13px;
}

.conn-row:last-child {
  border-bottom: none;
}

.conn-row strong {
  display: block;
  font-weight: 600;
}

.conn-row small {
  display: block;
  margin-top: 2px;
  color: var(--muted, #6b7280);
  font-size: 12px;
  max-width: 42ch;
  line-height: 1.35;
}

.conn-row.ok strong {
  color: var(--good, #1f7a4c);
}

.conn-toggle {
  flex: none;
  min-width: 110px;
}

.cbx {
  width: 18px;
  height: 18px;
  border-radius: 5px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 800;
}

.cbx.on {
  background: var(--good);
  color: #fff;
}

.cbx.off {
  border: 1.5px solid var(--hair-strong);
  background: var(--panel);
}

.src-label {
  margin: 0 !important;
  flex: 1;
}

.src-label.check {
  display: flex;
  align-items: center;
  gap: 8px;
}

.src-label input[type="checkbox"] {
  position: absolute;
  opacity: 0;
  width: 0;
  height: 0;
}

.src-extra {
  margin-top: 8px !important;
  font-size: 12.5px;
}

.priv {
  margin-top: 10px;
  background: var(--warn-bg);
  border-radius: var(--radius-input);
  padding: 10px 13px;
  font-size: 12px;
  color: var(--warn);
  line-height: 1.5;
}

/* ── Forms ── */

label {
  display: block;
  margin: 10px 0;
  font-size: 13px;
}

label > span {
  display: block;
  margin-bottom: 4px;
  font-family: var(--font-mono);
  font-size: 9.5px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--faint);
}

.check {
  display: flex;
  gap: 8px;
  align-items: flex-start;
}

.check > span {
  margin: 0;
  text-transform: none;
  letter-spacing: 0;
  font-size: 13px;
  font-family: var(--font-ui);
  color: var(--ink);
}

input:not([type="checkbox"]),
textarea,
select {
  width: 100%;
  border-radius: var(--radius-input);
  border: 1px solid var(--hair-strong);
  padding: 9px 12px;
  background: var(--panel);
  color: var(--ink);
  font: inherit;
  font-size: 13px;
}

input:focus,
textarea:focus,
select:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(3, 69, 117, 0.1);
}

input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
}

textarea {
  resize: vertical;
  min-height: 56px;
}

.two-cols {
  display: flex;
  gap: 10px;
}

.two-cols > label {
  flex: 1;
}

.hint {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 12.5px;
  line-height: 1.5;
}

.hint.warn {
  color: var(--warn);
  font-weight: 600;
  padding: 8px 10px;
  border-radius: var(--radius-input);
  background: var(--warn-bg);
}


/* ── Run progress ── */

.run-progress {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--hair);
}

.run-progress[hidden] {
  display: none !important;
}

.sub {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--hair);
  font-size: 13px;
}

.sub:last-child {
  border-bottom: none;
}

.sub .st {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  font-weight: 700;
}

.sub.done .st {
  background: var(--good-bg);
  color: var(--good);
}

.sub.act .st {
  background: var(--accent);
  color: #fff;
}

.sub.todo .st {
  background: var(--paper);
  color: var(--faint);
}

.sub .lbl b {
  display: block;
  font-weight: 600;
}

.sub .lbl span {
  font-size: 11.5px;
  color: var(--muted);
}

.sub .tail {
  margin-left: auto;
  font-size: 11px;
  color: var(--faint);
  font-family: var(--font-mono);
}

.run-status {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--hair);
  font-size: 12.5px;
  color: var(--muted);
}

#run-timer {
  display: block;
  margin-top: 4px;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  font-weight: 600;
}

/* ── Plan output ── */

.output,
.report-output {
  min-height: 120px;
  overflow: auto;
  white-space: pre-wrap;
  border: 1px solid var(--hair);
  border-radius: var(--radius-input);
  padding: 12px 14px;
  background: var(--code);
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.55;
  color: #26364b;
}

.config-panel {
  margin-top: 12px;
}

.config-panel summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--brand);
  margin-bottom: 8px;
}

/* ── Report block (P5 Studio Marca) ── */

.report-block {
  margin-top: 4px;
}

.banner {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--good-bg);
  border: 1px solid #cbe2d4;
  color: var(--good);
  border-radius: 10px;
  padding: 11px 15px;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 16px;
}

.banner.warn {
  background: var(--warn-bg);
  border-color: rgba(138, 90, 22, 0.25);
  color: var(--warn);
}

.banner[hidden] {
  display: none !important;
}

.banner small {
  margin-left: auto;
  color: var(--muted);
  font-weight: 500;
  font-family: var(--font-mono);
  font-size: 10.5px;
}

.report-layout {
  align-items: start;
}

.rep h1 {
  font-size: 21px;
  font-weight: 700;
  letter-spacing: -0.015em;
  margin: 0.1rem 0 0.3rem;
  line-height: 1.25;
  color: var(--brand);
}

.rep .std {
  font-family: var(--font-mono);
  font-size: 10.5px;
  color: var(--faint);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.report-html h1:first-child {
  display: none;
}

.report-html h2,
.report-html h3 {
  font-size: 14px;
  font-weight: 700;
  margin: 16px 0 4px;
  color: var(--accent);
}

.report-html p,
.report-html li {
  font-size: 13.5px;
  margin: 0.25rem 0 0.6rem;
  color: var(--ink);
  line-height: 1.55;
}

.report-html ul,
.report-html ol {
  padding-left: 1.2rem;
  margin: 0.4rem 0 0.8rem;
}

.cite {
  display: inline-block;
  font-size: 10px;
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  border-radius: 4px;
  padding: 1px 5px;
  cursor: pointer;
  text-decoration: none;
  margin: 0 1px;
  vertical-align: super;
  line-height: 1;
}

.cite:hover {
  background: var(--accent);
  color: #fff;
}

.evidence-panel h5 {
  margin-bottom: 4px;
}

.evidence-list {
  max-height: min(70vh, 720px);
  overflow: auto;
}

.ev {
  border: 1px solid var(--hair);
  border-radius: 10px;
  padding: 10px 13px;
  margin: 8px 0;
  font-size: 12.5px;
  background: var(--panel);
}

.ev .s {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--good);
}

.ev .d {
  float: right;
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--faint);
}

.ev p {
  margin: 0.35rem 0 0;
  color: var(--muted);
  line-height: 1.45;
  font-size: 12.5px;
  clear: both;
}

.ev p b {
  color: var(--brand);
}

.ev.is-active {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.card.rep .report-output {
  min-height: 120px;
  background: var(--panel);
  color: var(--ink);
  margin-top: 12px;
}

.report-link a {
  color: var(--accent);
  font-weight: 600;
}

.report-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin: 0 0 12px;
}

.report-actions[hidden] {
  display: none !important;
}

.report-actions a,
.report-actions button {
  display: inline-flex;
  align-items: center;
  min-height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-input);
  border: 1px solid var(--hair-strong);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
  font-size: 12.5px;
  text-decoration: none;
}

.report-actions a.secondary {
  background: var(--panel);
  color: var(--muted);
}

.report-actions .map-links {
  width: 100%;
  font-size: 12px;
  color: var(--muted);
}

.report-actions .map-links a {
  background: none;
  border: none;
  color: var(--accent);
  padding: 0;
  min-height: auto;
  margin-right: 12px;
}

/* ── Quality ── */

.quality-output {
  margin: 0 0 12px;
  border: 1px solid var(--hair);
  border-radius: var(--radius-input);
  padding: 12px 14px;
  background: var(--paper);
  font-size: 13px;
}

.quality-output:empty {
  display: none;
}

.quality-output.approved {
  border-color: #cbe2d4;
  background: var(--good-bg);
}

.quality-output.rejected {
  border-color: rgba(96, 14, 44, 0.25);
  background: var(--danger-bg);
}

.quality-output.warn {
  border-color: rgba(138, 90, 22, 0.25);
  background: var(--warn-bg);
}

.quality-output .quality-headline {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 6px;
}

.quality-output .quality-pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 2px 8px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
}

.quality-output.approved .quality-pill {
  background: var(--good-bg);
  color: var(--good);
}

.quality-badge {
  margin-top: 8px;
  border-radius: 999px;
  padding: 4px 10px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  display: inline-block;
}

.quality-badge.hidden {
  display: none;
}

.quality-badge.approved {
  background: var(--good-bg);
  color: var(--good);
}

.quality-badge.rejected {
  background: var(--danger-bg);
  color: var(--danger);
}

/* ── Storage banner ── */

.storage-banner {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 14px;
  padding: 11px 15px;
  border-radius: 10px;
  background: var(--warn-bg);
  border: 1px solid rgba(138, 90, 22, 0.2);
  font-size: 12.5px;
  color: var(--warn);
}

.storage-banner[hidden] {
  display: none !important;
}

/* ── Lang switch ── */

.lang-switch {
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  color: var(--faint);
}

.lang-switch select {
  width: auto;
  min-width: 52px;
  padding: 4px 8px;
  font-size: 11px;
}

.side-lang select {
  width: 100%;
}

.chat-lang-switch {
  font-size: 10px;
}

/* ── Toast ── */

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: 360px;
  border: 1px solid var(--hair);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-card);
  background: var(--panel);
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 500;
  z-index: 50;
  box-shadow: 0 12px 32px rgba(16, 29, 43, 0.12);
}

.toast[hidden] {
  display: none !important;
}

/* ── Background runs (continue while starting a new chat) ── */

.bg-runs {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin: 0 0 12px;
}

.bg-runs[hidden] {
  display: none !important;
}

.bg-run-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 14px;
  border: 1px solid var(--hair);
  border-left: 4px solid var(--accent);
  border-radius: var(--radius-card);
  background: color-mix(in srgb, var(--panel) 88%, var(--accent) 12%);
  font-size: 13px;
}

.bg-run-chip.is-done {
  border-left-color: #2f9e44;
}

.bg-run-chip.is-failed {
  border-left-color: #e03131;
}

.bg-run-chip .meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.bg-run-chip .meta strong {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.bg-run-chip .meta span {
  color: var(--muted);
  font-size: 12px;
}

.bg-run-chip .actions .btn {
  padding: 6px 10px;
  font-size: 12px;
}

/* ── Responsive ── */

@media (max-width: 960px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .side {
    position: relative;
    height: auto;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 12px;
  }

  .wh-logo {
    padding-bottom: 0;
  }

  .side-foot {
    display: none;
  }

  .grid2 {
    grid-template-columns: 1fr;
  }

  .flowbar .hint {
    border-left: none;
    margin-left: 0;
    padding-left: 0;
    flex-basis: 100%;
  }

  .pagehead-actions {
    width: 100%;
    margin-left: 0;
  }
}

@media (max-width: 600px) {
  .main {
    padding: 16px;
  }

  .two-cols {
    flex-direction: column;
  }

  .composer {
    flex-direction: column;
  }

  .composer .send {
    width: 100%;
  }
}

/* ── Views, tabs, drawer, utilities ── */

.main-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  gap: 12px;
}

.menu-toggle {
  display: none;
  border: 1px solid var(--hair-strong);
  background: var(--panel);
  border-radius: var(--radius-input);
  padding: 6px 10px;
  cursor: pointer;
  font-size: 16px;
}

.status-chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-left: auto;
}

.chip {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  padding: 4px 10px;
  border-radius: 999px;
  border: 1px solid var(--hair);
  background: var(--panel);
  color: var(--faint);
}

.chip.ok {
  background: var(--good-bg);
  color: var(--good);
  border-color: #cbe2d4;
}

.chip.warn {
  background: var(--warn-bg);
  color: var(--warn);
  border-color: rgba(138, 90, 22, 0.25);
}

.view-panel[hidden] {
  display: none !important;
}

.view-panel.is-active {
  animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.panel-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 0;
  padding: 4px;
  background: var(--paper);
  border: 1px solid var(--hair);
  border-radius: var(--radius-input);
}

.panel-tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 10px;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  border-radius: 6px;
  cursor: pointer;
  font-family: inherit;
}

.panel-tab.on {
  background: var(--panel);
  color: var(--brand);
  box-shadow: 0 1px 3px rgba(16, 29, 43, 0.08);
}

.tab-panel[hidden] {
  display: none !important;
}

.card-head-inline {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.card-head-inline h5 {
  margin: 0;
}

.badge-pill {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 3px 8px;
  border-radius: 999px;
}

.badge-pill.warn {
  background: var(--warn-bg);
  color: var(--warn);
}

.badge-pill.ok {
  background: var(--good-bg);
  color: var(--good);
}

.srcrow.clickable {
  cursor: pointer;
  user-select: none;
  border-radius: 6px;
  padding-left: 6px;
  padding-right: 6px;
  transition: background 0.12s;
}

.srcrow.clickable:hover {
  background: var(--paper);
}

.empty-state {
  padding: 28px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  border: 1px dashed var(--hair-strong);
  border-radius: var(--radius-card);
  background: var(--paper);
  margin-bottom: 10px;
}

.chat-typing {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--ai);
  padding: 6px 4px;
}

.chat-typing[hidden] {
  display: none !important;
}

.chat-typing .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ai);
  animation: bounce 1.2s infinite ease-in-out;
}

.chat-typing .dot:nth-child(2) { animation-delay: 0.15s; }
.chat-typing .dot:nth-child(3) { animation-delay: 0.3s; }

@keyframes bounce {
  0%, 80%, 100% { transform: translateY(0); opacity: 0.4; }
  40% { transform: translateY(-4px); opacity: 1; }
}

.plan-table-wrap {
  overflow: auto;
  margin-bottom: 12px;
}

.plan-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  background: var(--panel);
}

.plan-table th {
  font-family: var(--font-mono);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--faint);
  text-align: left;
  padding: 10px 12px;
  border-bottom: 1px solid var(--hair-strong);
}

.plan-table td {
  padding: 10px 12px;
  border-bottom: 1px solid var(--hair);
  vertical-align: top;
}

.plan-table tr:hover td {
  background: var(--paper);
}

.output-compact {
  min-height: 80px;
  max-height: 200px;
  font-size: 11px;
}

.drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 29, 43, 0.35);
  z-index: 60;
}

.drawer-backdrop[hidden] {
  display: none !important;
}

.drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: min(320px, 90vw);
  height: 100vh;
  background: var(--panel);
  border-right: 1px solid var(--hair);
  z-index: 70;
  display: flex;
  flex-direction: column;
  box-shadow: 8px 0 32px rgba(16, 29, 43, 0.12);
}

.drawer[hidden] {
  display: none !important;
}

.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  border-bottom: 1px solid var(--hair);
}

.drawer-head h4 {
  margin: 0;
  font-size: 15px;
  color: var(--brand);
}

.drawer-close {
  border: none;
  background: transparent;
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  color: var(--muted);
  padding: 4px 8px;
}

.history-list {
  flex: 1;
  overflow: auto;
  padding: 8px;
}

.history-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 1px solid var(--hair);
  border-radius: var(--radius-input);
  background: var(--panel);
  padding: 10px 12px;
  margin-bottom: 8px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s, background 0.15s;
}

.history-item:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
}

.history-item.is-disabled,
.history-item:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.history-item.is-disabled:hover,
.history-item:disabled:hover {
  border-color: var(--hair);
  background: var(--panel);
}

.report-markdown-details {
  margin-top: 16px;
  border-top: 1px solid var(--hair);
  padding-top: 10px;
}

.report-markdown-details summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  color: var(--muted);
  margin-bottom: 8px;
}

#actions-report .btn.primary {
  text-decoration: none;
}

.history-item b {
  display: block;
  font-size: 13px;
  color: var(--brand);
  margin-bottom: 4px;
}

.history-item small {
  font-family: var(--font-mono);
  font-size: 10px;
  color: var(--faint);
}

@media (max-width: 960px) {
  .menu-toggle {
    display: inline-block;
  }

  .side {
    position: fixed;
    left: 0;
    top: 0;
    z-index: 55;
    width: 240px;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
    flex-direction: column;
    height: 100vh;
    box-shadow: 8px 0 32px rgba(16, 29, 43, 0.15);
  }

  .side.is-open {
    transform: translateX(0);
  }

  .side-foot {
    display: flex;
  }
}

/* Compare pane */
.compare-pane {
  margin: 1rem 0;
  padding: 1rem;
}
.compare-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.compare-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.compare-md {
  max-height: 28rem;
  overflow: auto;
  font-size: 13px;
  line-height: 1.45;
  background: var(--surface-2, #f4f6f8);
  padding: 0.75rem;
  border-radius: 6px;
}
.compare-md h3,
.compare-md h4 {
  margin: 0.4rem 0 0.35rem;
  font-size: 14px;
}
.compare-md p {
  margin: 0 0 0.55rem;
}
.src-policy {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px solid var(--hair);
}
.src-policy h6 {
  margin: 0 0 4px;
  font-size: 12px;
}
.src-policy-list {
  font-size: 11px;
  margin-top: 4px;
  word-break: break-word;
}
.drawer-hint {
  padding: 8px 12px 0;
  font-size: 12px;
  line-height: 1.4;
}
.template-preview {
  font-size: 11px;
}
.compare-diff {
  margin: 0.75rem 0 0;
  padding-left: 1.2rem;
}
.compare-pickers {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: end;
  margin-bottom: 1rem;
}
.compare-pickers label {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  font-size: 12px;
}
.compare-pickers select {
  min-width: 12rem;
}
.login-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  display: grid;
  place-items: center;
  z-index: 80;
}
.login-overlay[hidden] {
  display: none !important;
}
.login-card {
  width: min(380px, 92vw);
  background: var(--surface, #fff);
  border-radius: 12px;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.18);
  position: relative;
}
.refine-card {
  width: min(520px, 92vw);
  text-align: left;
}
.refine-card h4 {
  margin: 0;
  font-size: 18px;
}
.refine-card .field-label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 12px;
  font-weight: 600;
}
.refine-card .field {
  width: 100%;
  resize: vertical;
}
.refine-brief-edit {
  border-top: 1px solid var(--hair, #e2e8f0);
  padding-top: 10px;
}
.refine-brief-edit summary {
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 8px;
}
.refine-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 4px;
}
.login-error {
  color: #b91c1c;
  font-size: 13px;
  margin: 0;
}
.stack-form {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.75rem 1rem 1rem;
  border-bottom: 1px solid var(--border, #e2e8f0);
}
.drawer-body {
  overflow: auto;
  max-height: calc(100vh - 4rem);
}
.row-actions {
  display: flex;
  gap: 0.35rem;
}
@media (max-width: 900px) {
  .compare-grid {
    grid-template-columns: 1fr;
  }
}
