/* SIAR Organigram Engine — manual test console.
   One light theme, restrained colour, no theme system. */

:root {
  --bg: #f5f6f8;
  --surface: #ffffff;
  --border: #e0e4ea;
  --border-strong: #c8cfda;
  --text: #1b2330;
  --muted: #66707f;
  --accent: #1f5fa8;
  --accent-soft: #eaf1fa;
  --info: #175cd3;
  --info-soft: #eef4ff;
  --warning: #b54708;
  --warning-soft: #fff6ed;
  --error: #b42318;
  --error-soft: #fef3f2;
  --radius: 10px;

  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

* {
  box-sizing: border-box;
}

/* Several panels the script toggles are flex or grid containers, and their
   own `display` would otherwise beat the `hidden` attribute's. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

.wrap {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 1.5rem;
}

/* --- header ------------------------------------------------------------- */

.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1.75rem 0 1.5rem;
  margin-bottom: 2rem;
}

.app-header h1 {
  margin: 0;
  font-size: 1.5rem;
  letter-spacing: -0.01em;
}

.subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

/* --- panels ------------------------------------------------------------- */

.panel,
.results {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  margin-bottom: 1.5rem;
}

.results {
  margin-bottom: 3rem;
}

.panel-title {
  margin: 0 0 1.25rem;
  font-size: 0.8rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

/* --- upload ------------------------------------------------------------- */

.dropzone {
  border: 2px dashed var(--border-strong);
  border-radius: var(--radius);
  padding: 2.75rem 1.5rem;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.dropzone:hover,
.dropzone:focus-visible,
.dropzone.is-dragging {
  border-color: var(--accent);
  background: var(--accent-soft);
  outline: none;
}

.dropzone-main {
  margin: 0;
  font-size: 1.05rem;
  font-weight: 600;
}

.dropzone-hint {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

.file-info {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  margin-top: 1.25rem;
  padding: 0.9rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.file-facts {
  display: flex;
  flex-wrap: wrap;
  gap: 1.75rem;
  margin: 0;
}

.file-fact dt {
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.file-fact dd {
  margin: 0.15rem 0 0;
  font-weight: 500;
  word-break: break-all;
}

.preview {
  margin-top: 1.25rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
}

.preview-image {
  display: block;
  max-width: 100%;
  margin: 0 auto;
}

.preview-pdf {
  display: block;
  width: 100%;
  height: 460px;
  border: 0;
}

/* --- controls ----------------------------------------------------------- */

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 1.25rem;
}

.control {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.control label {
  font-size: 0.85rem;
  color: var(--muted);
}

select {
  font: inherit;
  padding: 0.45rem 0.6rem;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: inherit;
}

.checkbox {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  cursor: pointer;
}

button {
  font: inherit;
  cursor: pointer;
  border-radius: 8px;
}

.primary {
  padding: 0.55rem 1.1rem;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #fff;
  font-weight: 600;
}

.primary:hover:not(:disabled) {
  background: #1a4f8c;
}

.primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.secondary {
  padding: 0.4rem 0.85rem;
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: inherit;
}

.secondary:hover {
  border-color: var(--accent);
  color: var(--accent);
}

.link-button {
  border: 0;
  background: none;
  padding: 0;
  color: var(--accent);
  text-decoration: underline;
}

.model-line {
  margin: 0 0 0 auto;
  color: var(--muted);
  font-size: 0.85rem;
}

.model-name {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text);
}

/* --- in-flight ---------------------------------------------------------- */

.progress {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-top: 1.25rem;
  padding: 0.85rem 1rem;
  background: var(--accent-soft);
  border-radius: var(--radius);
  color: var(--accent);
  font-weight: 500;
}

.spinner {
  width: 1.05rem;
  height: 1.05rem;
  border: 2px solid rgba(31, 95, 168, 0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@media (prefers-reduced-motion: reduce) {
  .spinner {
    animation-duration: 2.4s;
  }
}

.elapsed {
  margin-left: auto;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-variant-numeric: tabular-nums;
}

.error-banner {
  margin: 1.25rem 0 0;
  padding: 0.85rem 1rem;
  background: var(--error-soft);
  border: 1px solid #f3c0bb;
  border-left: 4px solid var(--error);
  border-radius: var(--radius);
  color: var(--error);
  white-space: pre-wrap;
}

/* --- result cards ------------------------------------------------------- */

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.85rem;
}

.card {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
  padding: 0.9rem 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.card-value {
  font-size: 1.5rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.card-label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
}

.run-summary {
  margin: 1rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

/* --- tabs --------------------------------------------------------------- */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0.25rem;
  margin-top: 1.5rem;
  border-bottom: 1px solid var(--border);
}

.tab {
  padding: 0.55rem 0.9rem;
  border: 0;
  border-bottom: 2px solid transparent;
  border-radius: 8px 8px 0 0;
  background: none;
  color: var(--muted);
  font-weight: 500;
}

.tab:hover {
  color: var(--text);
}

.tab.is-active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.tab-panel {
  padding-top: 1.25rem;
}

/* --- graph -------------------------------------------------------------- */

.graph-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}

.graph-zoom,
.graph-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
}

.graph-step {
  min-width: 2.2rem;
  font-variant-numeric: tabular-nums;
}

.graph-zoom-level {
  min-width: 3.5rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.85rem;
  font-variant-numeric: tabular-nums;
}

/* Full width so the message never reflows the buttons beside it. */
.graph-status {
  flex-basis: 100%;
  text-align: right;
  min-height: 1.2em;
}

.graph-canvas {
  overflow: auto;
  max-height: 70vh;
  padding: 1rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: grab;
}

/* While a drag-pan is in flight. Set from JS so the cursor tracks the gesture. */
.graph-canvas.is-panning {
  cursor: grabbing;
  user-select: none;
}

/* The stage carries the zoom, so the SVG keeps its natural size and the
   canvas scrolls. Scaling the wrapper rather than the SVG keeps Mermaid's
   own layout untouched. */
.graph-stage {
  transform-origin: 0 0;
  width: max-content;
}

.graph-stage svg {
  display: block;
  max-width: none;
  height: auto;
}

/* The fallback <pre> lives in the stage too; it must not inherit the
   natural-width rule meant for the diagram. */
.graph-stage .code-block {
  width: 100%;
}

#panel-graph:fullscreen {
  padding: 1.5rem;
  background: var(--surface);
  overflow: auto;
}

#panel-graph:fullscreen .graph-canvas {
  max-height: calc(100vh - 8rem);
}

.notice {
  margin: 0 0 1rem;
  padding: 0.75rem 1rem;
  background: var(--warning-soft);
  border: 1px solid #f3ceac;
  border-left: 4px solid var(--warning);
  border-radius: var(--radius);
  color: var(--warning);
  font-size: 0.9rem;
}

.code-block {
  margin: 0;
  padding: 1rem;
  max-height: 32rem;
  overflow: auto;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  line-height: 1.55;
  white-space: pre;
}

/* --- tables ------------------------------------------------------------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.data-table th,
.data-table td {
  padding: 0.55rem 0.8rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

.data-table thead th {
  background: var(--bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.76rem;
  font-weight: 600;
  color: var(--muted);
}

.data-table tbody tr:last-child td {
  border-bottom: 0;
}

.data-table tbody tr:hover td {
  background: #fafbfc;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
}

.numeric {
  font-variant-numeric: tabular-nums;
}

.entity-name {
  display: block;
  font-weight: 500;
}

.entity-id {
  display: block;
  margin-top: 0.1rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.75rem;
  color: var(--muted);
}

.empty {
  padding: 1.5rem;
  text-align: center;
  color: var(--muted);
}

/* --- issues ------------------------------------------------------------- */

.issue-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.issue {
  padding: 0.8rem 1rem;
  border: 1px solid var(--border);
  border-left: 4px solid var(--muted);
  border-radius: var(--radius);
  background: var(--bg);
}

.issue-error {
  border-left-color: var(--error);
  background: var(--error-soft);
}

.issue-warning {
  border-left-color: var(--warning);
  background: var(--warning-soft);
}

.issue-info {
  border-left-color: var(--info);
  background: var(--info-soft);
}

.issue-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
}

.severity {
  padding: 0.1rem 0.5rem;
  border-radius: 999px;
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff;
  background: var(--muted);
}

.issue-error .severity {
  background: var(--error);
}

.issue-warning .severity {
  background: var(--warning);
}

.issue-info .severity {
  background: var(--info);
}

.issue-code {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.8rem;
  font-weight: 600;
}

.issue-message {
  margin: 0.4rem 0 0;
}

.issue-refs {
  margin: 0.4rem 0 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.76rem;
  color: var(--muted);
  word-break: break-word;
}

/* --- json + debug ------------------------------------------------------- */

.json-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 0.9rem;
}

.copy-status {
  color: var(--muted);
  font-size: 0.85rem;
}

.debug-gallery {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(230px, 1fr));
  gap: 1rem;
}

.debug-item {
  margin: 0;
  padding: 0.6rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.debug-item img {
  display: block;
  width: 100%;
  height: auto;
  border-radius: 6px;
  background: var(--surface);
}

.debug-caption {
  margin-top: 0.5rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.74rem;
  color: var(--muted);
  word-break: break-all;
}

/* Relations, coloured by how settled they are.
 *
 * The three states are the same three the debug overlay draws
 * (`app/debug/connector_overlay.py`), so a reader comparing the table with the
 * picture sees one relation described one way. */
.data-table tr.edge-ambiguous {
  background: var(--warning-soft);
}

.data-table tr.edge-ambiguous td:last-child {
  color: var(--warning);
  font-weight: 600;
}

.data-table tr.edge-inferred td:last-child {
  color: var(--muted);
}

/* Where a code came from. Three origins, three looks, because a number the
 * document printed and one this service proposed are different claims and a
 * table makes them look identical. */
.code-badge {
  display: inline-block;
  margin-left: 0.4em;
  padding: 0 0.35em;
  border-radius: 3px;
  font-size: 0.7em;
  font-weight: 700;
  letter-spacing: 0.03em;
  vertical-align: middle;
}

.code-source {
  background: var(--accent);
  color: #fff;
}

.code-generated,
.code-suggested {
  background: var(--warning-soft);
  color: var(--warning);
  border: 1px solid var(--warning);
}
