/* Terraform Clinic — theme via [data-theme] on <html>, set by theme.js before paint.
 * Accent is the Kubernetes blue family (#326ce5) in both themes. */

:root[data-theme="light"] {
  --bg: #f4f7fc; --panel: #ffffff; --ink: #151d2c; --muted: #57627a;
  --line: #dbe2ee; --accent: #326ce5; --accent-ink: #ffffff;
  --red: #c02b2b; --red-bg: #fdf1f1; --yellow: #a06a00; --yellow-bg: #fdf7ea;
  --warn: #a06a00; --warn-bg: #fdf7ea; --ok: #1d7a4a; --ok-bg: #eef8f1;
  --code-bg: #eef1f6; --shadow: 0 1px 3px rgba(18, 30, 50, 0.08);
}
:root[data-theme="dark"] {
  --bg: #0d131f; --panel: #161e2d; --ink: #e5ecf7; --muted: #93a1b8;
  --line: #27334a; --accent: #7aa8f5; --accent-ink: #0b1220;
  --red: #f08080; --red-bg: #2a1c1e; --yellow: #e0b45c; --yellow-bg: #282215;
  --warn: #e0b45c; --warn-bg: #282215; --ok: #6fce9e; --ok-bg: #14261d;
  --code-bg: #202b3c; --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }
html { font-size: 16px; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.55;
}
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 0.82em; }
.muted { color: var(--muted); }
.small { font-size: 0.85rem; }
.hidden { display: none !important; }

/* --- Header ------------------------------------------------------------ */
header {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: 0.9rem 1.4rem; border-bottom: 1px solid var(--line); background: var(--panel);
  flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 0.75rem; }
.brand .mark { width: 34px; height: 34px; color: var(--accent); flex: none; }
.brand h1 { font-size: 1.15rem; margin: 0; }
.tagline { margin: 0; font-size: 0.82rem; color: var(--muted); }
.session { display: flex; align-items: center; gap: 0.6rem; flex-wrap: wrap; }
.home-link { display: inline-flex; align-items: center; gap: 0.3rem; color: var(--muted); text-decoration: none; font-size: 0.85rem; }
.home-link svg { width: 14px; height: 14px; }
.home-link:hover { color: var(--ink); }
.credits { color: var(--ok); font-weight: 600; }
.topup { color: var(--accent); font-size: 0.85rem; }

button { font: inherit; cursor: pointer; border-radius: 8px; }
.ghost {
  background: transparent; border: 1px solid var(--line); color: var(--ink);
  padding: 0.35rem 0.8rem; font-size: 0.85rem;
}
.ghost:hover { border-color: var(--accent); }
.ghost.theme-toggle { width: 2.1rem; height: 2.1rem; padding: 0; position: relative; }
.ghost.theme-toggle::after { content: "\2600"; font-size: 1rem; position: absolute; inset: 0; display: grid; place-items: center; }
:root[data-theme="dark"] .ghost.theme-toggle::after { content: "\263D"; }
.primary {
  background: var(--accent); color: var(--accent-ink); border: 1px solid var(--accent);
  padding: 0.45rem 1.1rem; font-weight: 600;
}
.primary:hover { filter: brightness(1.08); }
.primary:disabled { opacity: 0.55; cursor: default; }
.big { padding: 0.65rem 1.5rem; font-size: 1rem; border-radius: 10px; }
button.big:not(.primary) { background: var(--panel); border: 1px solid var(--line); color: var(--ink); }
.linkish { background: none; border: none; padding: 0; color: var(--accent); text-decoration: underline; font-size: inherit; }

/* --- Layout ------------------------------------------------------------ */
main { max-width: 980px; margin: 0 auto; padding: 1.5rem 1.2rem 3rem; }
.klabel {
  display: inline-block; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
}
.label-row { display: flex; align-items: baseline; justify-content: space-between; gap: 1rem; margin-bottom: 0.4rem; flex-wrap: wrap; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
textarea, input[type="text"], select {
  width: 100%; font: inherit; color: var(--ink); background: transparent;
  border: none; outline: none; padding: 0.8rem 0.9rem;
}
textarea { resize: vertical; min-height: 10rem; display: block; }
.card.dragging { outline: 2px dashed var(--accent); outline-offset: 3px; }
input[type="file"] { font-size: 0.85rem; color: inherit; max-width: 46%; }

.options { margin-top: 1rem; }
.options summary { cursor: pointer; }
.options textarea {
  border: 1px solid var(--line); border-radius: 10px; background: var(--panel);
  min-height: 6rem; margin-top: 0.4rem; font-size: 0.92rem;
}
.row.four { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.9rem; margin-top: 1rem; }
.row.four label { display: block; font-size: 0.85rem; margin-bottom: 0.25rem; color: var(--muted); }
.row.four select, .row.four input { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 0.5rem 0.6rem; }
@media (max-width: 820px) { .row.four { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .row.four { grid-template-columns: 1fr; } }
.row.two { display: grid; grid-template-columns: repeat(2, 1fr); gap: 0.9rem; margin-top: 1rem; }
.row.two label { display: block; font-size: 0.85rem; margin-bottom: 0.25rem; color: var(--muted); }
.row.two select, .row.two input { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 0.5rem 0.6rem; width: 100%; box-sizing: border-box; }
@media (max-width: 620px) { .row.two { grid-template-columns: 1fr; } }
.row.three { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.9rem; margin-top: 1rem; }
.row.three label { display: block; font-size: 0.85rem; margin-bottom: 0.25rem; color: var(--muted); }
.row.three select, .row.three input { border: 1px solid var(--line); border-radius: 8px; background: var(--panel); padding: 0.5rem 0.6rem; width: 100%; box-sizing: border-box; }
@media (max-width: 520px) { .row.three { grid-template-columns: 1fr; } }
.actions { display: flex; align-items: center; gap: 0.9rem; margin-top: 1.2rem; flex-wrap: wrap; }
.meter { font-size: 0.8rem; color: var(--muted); }

/* --- Instant prescan ---------------------------------------------------- */
.prescan { margin-top: 1.1rem; }
.prescan-body { display: grid; gap: 0.55rem; margin-top: 0.3rem; }
.ps-item { border: 1px solid var(--line); border-left-width: 4px; border-radius: 8px; padding: 0.55rem 0.8rem; background: var(--panel); }
.ps-item.warn { border-left-color: var(--warn); background: var(--warn-bg); }
.ps-item.kind-resource { border-left-color: var(--accent); background: var(--panel); }
.ps-item.kind-flag { border-left-color: var(--warn); }
.ps-item.kind-warn { border-left-color: var(--red); background: var(--red-bg); }
.ps-label { font-weight: 700; font-size: 0.9rem; }
.ps-chips { display: flex; flex-wrap: wrap; gap: 0.35rem; margin: 0.4rem 0 0.3rem; }
.chip {
  border: 1px solid var(--line); background: var(--panel); border-radius: 999px;
  padding: 0.1rem 0.6rem; font-size: 0.76rem; white-space: nowrap;
}
.ps-why { font-size: 0.85rem; color: var(--muted); }

/* --- Progress ------------------------------------------------------------ */
.progress-panel { margin-top: 1.4rem; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.2rem; }
.pp-top { display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.steps { list-style: none; margin: 0.8rem 0 0; padding: 0; display: grid; gap: 0.45rem; }
.step { display: flex; align-items: center; gap: 0.6rem; font-size: 0.92rem; color: var(--muted); }
.step-ic { width: 0.85rem; height: 0.85rem; border-radius: 50%; border: 2px solid var(--line); flex: none; }
.step.live { color: var(--ink); }
.step.live .step-ic { border-color: var(--accent); animation: pulse 1.2s infinite; }
.step.done { color: var(--ink); }
.step.done .step-ic { background: var(--ok); border-color: var(--ok); }
@keyframes pulse { 50% { transform: scale(1.25); } }

/* --- Result ------------------------------------------------------------ */
.result { margin-top: 1.6rem; display: grid; gap: 1.3rem; }
.res-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 1rem; flex-wrap: wrap; }
.res-head h2 { margin: 0.15rem 0 0.3rem; font-size: 1.35rem; }
.verdict { margin: 0.3rem 0 0; color: var(--muted); font-style: italic; max-width: 46rem; }
.dl-actions { display: flex; gap: 0.5rem; flex-wrap: wrap; }
#partialNote:not(.hidden) { display: block; padding: 10px 14px; border: 1px solid var(--warn); border-radius: 10px; background: var(--warn-bg); }

.summary-card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.2rem; box-shadow: var(--shadow); }
.summary-card p { margin: 0.5rem 0 0; }
.arch-text p { margin: 0.5rem 0 0; }

/* --- Tables (resources, network segments) ------------------------------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 12px; background: var(--panel); box-shadow: var(--shadow); }
.data-table { width: 100%; border-collapse: collapse; min-width: 40rem; font-size: 0.9rem; }
.data-table thead th {
  text-align: left; font-size: 0.72rem; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--muted); padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
.data-table td { padding: 0.55rem 0.85rem; border-bottom: 1px solid var(--line); vertical-align: top; }
.data-table tbody tr:last-child td { border-bottom: none; }
.data-table tbody tr:hover td { background: var(--code-bg); }
.net-zone .table-wrap .data-table { min-width: 28rem; }
.topo-tag { border: 1px solid var(--accent); color: var(--accent); border-radius: 999px; padding: 0.1rem 0.65rem; }
.net-desc { margin: 0.2rem 0 0.7rem; }

/* --- Identity ----------------------------------------------------------- */
.ident-list { margin: 0.5rem 0 0; padding-left: 1.2rem; display: grid; gap: 0.35rem; }
.ident-list li { font-size: 0.93rem; }

/* --- WAF pillars -------------------------------------------------------- */
.waf-row { display: grid; grid-template-columns: repeat(5, 1fr); gap: 0.7rem; margin-top: 0.5rem; }
@media (max-width: 900px) { .waf-row { grid-template-columns: 1fr 1fr; } }
@media (max-width: 520px) { .waf-row { grid-template-columns: 1fr; } }
.waf-card { background: var(--panel); border: 1px solid var(--line); border-top-width: 4px; border-radius: 10px; padding: 0.7rem 0.85rem; box-shadow: var(--shadow); }
.waf-card.st-aligned { border-top-color: var(--ok); }
.waf-card.st-risk { border-top-color: var(--yellow); }
.waf-card.st-gap { border-top-color: var(--red); }
.waf-head { display: flex; align-items: baseline; justify-content: space-between; gap: 0.4rem; flex-wrap: wrap; }
.waf-pillar { font-weight: 700; font-size: 0.88rem; }
.waf-badge {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  border-radius: 999px; padding: 0.1rem 0.5rem;
}
.waf-badge.aligned { background: var(--ok-bg); color: var(--ok); }
.waf-badge.risk { background: var(--yellow-bg); color: var(--yellow); }
.waf-badge.gap { background: var(--red-bg); color: var(--red); }
.waf-note { margin: 0.4rem 0 0; font-size: 0.83rem; color: var(--muted); }

/* --- Risks -------------------------------------------------------------- */
.flag-head { display: flex; align-items: center; gap: 0.55rem; margin-bottom: 0.6rem; }
.flag-head h3 { margin: 0; font-size: 1.02rem; }
.flag-dot { width: 0.75rem; height: 0.75rem; border-radius: 50%; flex: none; }
.flag-head.red .flag-dot { background: var(--red); }
.count { color: var(--muted); }
.flag-list { display: grid; gap: 0.7rem; }
.flag-card { background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 0.8rem 1rem; box-shadow: var(--shadow); }
.flag-card.sev-high { border-left: 4px solid var(--red); background: var(--red-bg); }
.flag-card.sev-medium { border-left: 4px solid var(--yellow); background: var(--yellow-bg); }
.flag-card.sev-low { border-left: 4px solid var(--line); }
.fc-head { display: flex; gap: 0.8rem; align-items: baseline; flex-wrap: wrap; }
.fc-sev { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; border-radius: 999px; padding: 0.1rem 0.55rem; }
.fc-sev.high { background: var(--red-bg); color: var(--red); }
.fc-sev.medium { background: var(--yellow-bg); color: var(--yellow); }
.fc-sev.low { background: var(--code-bg); color: var(--muted); }
.fc-cat { font-weight: 700; font-size: 0.9rem; }
.fc-copy { margin-left: auto; font-size: 0.75rem; padding: 2px 8px; }
.fc-problem { margin: 0.4rem 0 0; font-size: 0.93rem; }
.fc-fix { margin: 0.6rem 0 0; padding: 0.6rem 0.75rem; font-size: 0.78rem; }

/* --- Next steps & IaC ---------------------------------------------------- */
.fix-list { margin: 0.5rem 0 0; padding-left: 1.3rem; display: grid; gap: 0.4rem; }
.fix-list li { background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 0.5rem 0.8rem; font-size: 0.92rem; }
.fc-snippet {
  margin: 0.6rem 0 0; background: var(--code-bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 0.6rem 0.8rem; overflow-x: auto; max-height: 24rem;
  font: 12.5px/1.55 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre;
}
.run-meta { color: var(--muted); font-size: 0.8rem; }

.raw-result { margin-top: 1.4rem; }
.raw-output { background: var(--code-bg); border: 1px solid var(--line); border-radius: 10px; padding: 1rem; overflow-x: auto; font-size: 0.82rem; white-space: pre-wrap; }

/* --- How it works ------------------------------------------------------- */
.how { margin-top: 2.2rem; }
.how-lead { color: var(--muted); }
.how-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1rem; margin-top: 0.8rem; }
@media (max-width: 720px) { .how-grid { grid-template-columns: 1fr; } }
.how-step { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1rem 1.1rem; }
.step-n { display: inline-grid; place-items: center; width: 1.7rem; height: 1.7rem; border-radius: 50%; background: var(--accent); color: var(--accent-ink); font-weight: 700; font-size: 0.9rem; }
.how-step h3 { margin: 0.6rem 0 0.3rem; font-size: 0.98rem; }
.how-step p { margin: 0; font-size: 0.88rem; color: var(--muted); }
.how-credit { margin-top: 1rem; font-size: 0.82rem; color: var(--muted); }
.how-credit a { color: var(--accent); }
#historyList li { margin-bottom: 6px; }
#historyList .linkish { margin-left: 6px; }

/* --- Footer & toasts ------------------------------------------------------ */
footer { border-top: 1px solid var(--line); padding: 1rem 1.4rem; text-align: center; font-size: 0.85rem; color: var(--muted); }
footer a { color: var(--muted); }
.foot-sep { margin: 0 0.5rem; }
.toasts { position: fixed; bottom: 1rem; right: 1rem; display: grid; gap: 0.5rem; z-index: 50; max-width: min(420px, 90vw); }
.toast {
  background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--ok);
  border-radius: 10px; padding: 0.6rem 0.9rem; font-size: 0.88rem; box-shadow: var(--shadow);
  transition: opacity 0.5s;
}
.toast.err { border-left-color: var(--red); }
.toast.gone { opacity: 0; }
.toast a { color: var(--accent); margin-left: 0.4rem; }

/* --- Print: just the plan -------------------------------------------------- */
@media print {
  header, footer, form, .prescan, .how, .toasts, .dl-actions, .progress-panel { display: none !important; }
  body { background: #fff; color: #000; }
  .result { display: grid !important; }
  .flag-card, .summary-card, .waf-card, .table-wrap { break-inside: avoid; box-shadow: none; }
  .fc-snippet { max-height: none; white-space: pre-wrap; }
}

/* Terraform Clinic additions: posture verdict tint + status cells */
.verdict.lv-block { color: var(--red); font-style: normal; font-weight: 600; }
.verdict.lv-fix-first { color: var(--yellow); font-style: normal; font-weight: 600; }
.verdict.lv-ship { color: var(--ok); font-style: normal; font-weight: 600; }
.ck-pass { color: var(--ok); font-weight: 600; }
.ck-fail { color: var(--red); font-weight: 600; }

/* --- Run-button notice: why the model run is unavailable, at the button ---- */
.run-notice {
  margin-top: 0.6rem; border: 1px solid var(--line); border-left: 4px solid var(--accent);
  border-radius: 8px; padding: 0.6rem 0.85rem; background: var(--panel);
  font-size: 0.88rem; color: var(--muted); display: flex; flex-wrap: wrap;
  gap: 0.5rem; align-items: baseline;
}
.run-notice.warn { border-left-color: var(--yellow); background: var(--yellow-bg); }
.run-notice .linkish { font-weight: 600; white-space: nowrap; }

/* --- Follow-up request list ----------------------------------------------- */
.req-list li { padding: 0.45rem 0.7rem; }
.req-item { display: flex; gap: 0.5rem; align-items: baseline; cursor: pointer; }
.req-item.done > span { text-decoration: line-through; opacity: 0.6; }
#requestZone .dl-actions { display: inline-flex; gap: 0.4rem; align-items: center; }
#mailRequests { text-decoration: none; }

/* --- Baseline diff --------------------------------------------------------- */
#diffZone { border-left: 4px solid var(--accent); }
#diffBody .fc-problem { margin: 0.3rem 0; font-size: 0.9rem; }

/* --- Finding anchor highlight when reached from a focus area --------------- */
.flag-card.targeted { outline: 2px solid var(--accent); outline-offset: 2px; }

@media print {
  .run-notice, #diffZone { display: none !important; }
}
.ck-na { color: var(--muted); }
