/* Flange-analysis styles, scoped for the merged piping-iso-app shell.
 *
 * Two changes from the standalone flange app.css:
 *
 *  1. Every rule is prefixed `.flange-scope ` so the handful of class names the
 *     two apps share (.active, .app-shell, .empty, .error, .spacer) can never
 *     touch piping's own chrome.  The flange UI is mounted inside a
 *     <div class="flange-host flange-scope"> in piping's workspace.
 *
 *  2. The theme variable blocks (:root / [data-theme=dark]) are gone.  piping
 *     already defines --bg/--panel-bg/--text/--muted/--border/--accent/… on
 *     html[data-theme=…] for all four of its themes, with the same names and
 *     the same light/dark values, so the flange UI tracks the piping theme with
 *     no JS sync.  Only the utilisation-band colours are unique to flange, so
 *     they are re-homed on .flange-scope below (light) with a dark override for
 *     the two dark themes.
 */

/* Utilisation bands. Same thresholds as the workbooks -- a colour that means
   one thing on screen and another in the download is worse than no colour. */
.flange-scope {
  --ok-bg: #e6f4ea;      --ok-text: #12683a;
  --warn-bg: #fef4e2;    --warn-text: #8a5300;
  --fail-bg: #fdecec;    --fail-text: #b3261e;
  --na-bg: #f0f1f3;      --na-text: #6b7280;
  --caveat-bg: #fff8e6;  --caveat-text: #8a5300;
}
html[data-theme="dark"] .flange-scope,
html[data-theme="modern"] .flange-scope {
  --ok-bg: #16301f;      --ok-text: #7ee2a8;
  --warn-bg: #33280f;    --warn-text: #f5cd7a;
  --fail-bg: #3a1f1f;    --fail-text: #ff8a80;
  --na-bg: #22252c;      --na-text: #8b929e;
  --caveat-bg: #2e2712;  --caveat-text: #f5cd7a;
}

/* ── Host ────────────────────────────────────────────────────────────────
   Fills piping's workspace slot the way .preview does, but scrolls its form
   content and sits on the panel background rather than the white canvas. */
.flange-host {
  flex: 1; min-width: 0; min-height: 0; overflow: auto;
  background: var(--bg); color: var(--text); font-size: 14px;
}

/* ── Sub-tab nav (the flange group: analysis / quick / data / codes) ───── */

.flange-scope .tabs {
  display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin: 0;
}
.flange-scope .tabs button {
  background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--muted); padding: 8px 14px; cursor: pointer; font-size: .88rem;
}
.flange-scope .tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Shell ───────────────────────────────────────────────────────────── */

.flange-scope .app-shell {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 14px 18px 28px;
  gap: 12px;
  max-width: 1500px;
  margin: 0 auto;
}

/* ── Panels ──────────────────────────────────────────────────────────── */

.flange-scope .panel {
  background: var(--panel-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius, 8px);
  padding: 12px 14px;
}
.flange-scope .panel > h2 { margin: 0 0 4px; font-size: .95rem; }
.flange-scope .panel .hint { margin: 0 0 10px; color: var(--muted); font-size: .78rem; }

.flange-scope .columns { display: grid; grid-template-columns: 420px 1fr; gap: 12px; align-items: start; }
@media (max-width: 1100px) { .flange-scope .columns { grid-template-columns: 1fr; } }

/* ── Forms ───────────────────────────────────────────────────────────── */

.flange-scope .field-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.flange-scope .field { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.flange-scope .field label { font-size: .72rem; color: var(--muted); }
.flange-scope .field input, .flange-scope .field select {
  background: var(--input-bg, var(--bg)); color: var(--text);
  border: 1px solid var(--border); border-radius: 5px;
  padding: 5px 7px; font-size: .84rem; width: 100%;
}
.flange-scope .field input:focus, .flange-scope .field select:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.flange-scope .field.wide { grid-column: 1 / -1; }

.flange-scope fieldset {
  border: 1px solid var(--border); border-radius: 6px;
  margin: 0 0 10px; padding: 8px 10px 10px;
}
.flange-scope legend { font-size: .76rem; color: var(--muted); padding: 0 4px; }

.flange-scope button.primary {
  background: var(--accent); color: #fff; border: none; border-radius: 6px;
  padding: 8px 16px; cursor: pointer; font-size: .88rem;
}
.flange-scope button.primary:hover { background: var(--accent-hover); }
.flange-scope button.primary:disabled { opacity: .5; cursor: default; }

.flange-scope button.ghost {
  background: none; color: var(--accent); border: 1px solid var(--border);
  border-radius: 6px; padding: 5px 11px; cursor: pointer; font-size: .8rem;
}
.flange-scope button.ghost:hover { border-color: var(--accent); }
.flange-scope button.link {
  background: none; border: none; color: var(--accent);
  cursor: pointer; font-size: .78rem; padding: 0;
}

.flange-scope .row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.flange-scope .row.end { justify-content: flex-end; }

/* ── Tables ──────────────────────────────────────────────────────────── */

.flange-scope .grid-wrap { overflow-x: auto; }
.flange-scope table.grid { border-collapse: collapse; width: 100%; font-size: .82rem; }
.flange-scope table.grid th, .flange-scope table.grid td {
  border: 1px solid var(--border); padding: 5px 8px; text-align: left;
  white-space: nowrap;
}
.flange-scope table.grid th { background: var(--bg); font-weight: 600; font-size: .76rem; }
.flange-scope table.grid td.num { text-align: right; font-variant-numeric: tabular-nums; }
.flange-scope table.grid tr.selected > td { outline: 1px solid var(--accent); outline-offset: -1px; }

/* The two rows the rating is read between. Tinted rather than outlined, because
   the pair has to read as one bracket and two outlines read as two selections. */
.flange-scope table.grid tr.pt-bracket > td {
  background: var(--caveat-bg); color: var(--caveat-text); font-weight: 600;
}

/* ── Status chips ────────────────────────────────────────────────────── */

.flange-scope .chip {
  display: inline-block; border-radius: 4px; padding: 1px 7px;
  font-size: .75rem; font-variant-numeric: tabular-nums; cursor: pointer;
  border: 1px solid transparent;
}
.flange-scope .chip.ok     { background: var(--ok-bg);     color: var(--ok-text); }
.flange-scope .chip.warn   { background: var(--warn-bg);   color: var(--warn-text); }
.flange-scope .chip.fail   { background: var(--fail-bg);   color: var(--fail-text); font-weight: 600; }
.flange-scope .chip.na     { background: var(--na-bg);     color: var(--na-text); }
.flange-scope .chip.caveat { background: var(--caveat-bg); color: var(--caveat-text); }
.flange-scope .chip:hover { border-color: currentColor; }

/* The unverified stamp. Deliberately loud: a result built on an unchecked
   reference row is usable but not quotable, and a subtle badge gets missed. */
.flange-scope .stamp {
  background: var(--fail-bg); color: var(--fail-text);
  border: 1px solid var(--fail-text); border-radius: 6px;
  padding: 8px 12px; font-size: .8rem; margin-bottom: 10px;
}
.flange-scope .stamp strong { letter-spacing: .04em; }

.flange-scope .error {
  background: var(--error-bg); color: var(--error-text);
  border-radius: 6px; padding: 9px 12px; font-size: .84rem;
}

.flange-scope .muted { color: var(--muted); font-size: .78rem; }
.flange-scope .mono { font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: .78rem; }

/* ── Reasons ─────────────────────────────────────────────────────────── */

/* The reason list is the point of the app, so it gets room to breathe rather
   than being crushed into a tooltip. */
.flange-scope .reasons { list-style: none; margin: 8px 0 0; padding: 0; display: grid; gap: 6px; }
.flange-scope .reasons li {
  border-left: 3px solid var(--border); padding: 4px 0 4px 10px;
  font-size: .82rem; line-height: 1.45;
}
.flange-scope .reasons li.na { border-left-color: var(--na-text); }
.flange-scope .reasons li.caveat { border-left-color: var(--caveat-text); }
.flange-scope .reasons .clause {
  display: block; font-family: ui-monospace, Consolas, monospace;
  font-size: .72rem; color: var(--muted);
}

.flange-scope .detail-head { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.flange-scope .detail-head h3 { margin: 0; font-size: .92rem; }

.flange-scope details.intermediates { margin-top: 10px; }
.flange-scope details.intermediates > summary { cursor: pointer; font-size: .8rem; color: var(--accent); }
.flange-scope details.intermediates table { margin-top: 8px; }

.flange-scope .sources { margin: 8px 0 0; padding-left: 18px; }
.flange-scope .sources li { font-size: .74rem; color: var(--muted); }

.flange-scope .empty { color: var(--muted); font-size: .84rem; padding: 20px 4px; text-align: center; }

/* ── Mode switcher (Manual / CAESAR on the full-analysis tab) ─────────────── */

.flange-scope .mode-switcher {
  display: flex;
  border: 1px solid var(--border);
  border-radius: 7px;
  overflow: hidden;
  width: fit-content;
  margin-bottom: 12px;
}
.flange-scope .mode-btn {
  background: none; border: none; padding: 7px 20px;
  cursor: pointer; font-size: .84rem; color: var(--muted);
  transition: background .12s, color .12s;
}
.flange-scope .mode-btn:hover { background: var(--bg); }
.flange-scope .mode-btn.active { background: var(--accent); color: #fff; font-weight: 500; }

/* ── CAESAR upload panel ─────────────────────────────────────────────────── */

.flange-scope .caesar-upload { display: grid; gap: 10px; }
.flange-scope .caesar-upload .field input[type=file] {
  padding: 4px; font-size: .8rem; cursor: pointer;
}
.flange-scope .caesar-note {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; padding: 10px 12px;
  font-size: .78rem; color: var(--muted); line-height: 1.55;
}

/* ── Quick check layout ──────────────────────────────────────────────────── */

.flange-scope .quick-layout {
  display: grid;
  grid-template-columns: 420px 1fr;
  gap: 12px;
  align-items: start;
}
.flange-scope .quick-left, .flange-scope .quick-right { display: flex; flex-direction: column; gap: 12px; }
@media (max-width: 1100px) { .flange-scope .quick-layout { grid-template-columns: 1fr; } }
