/* Minimal design system for an academic tool: one neutral palette, small type
   scale, generous spacing, no decoration. Server-rendered; no build step. */

/* --- MicroPolymerIF brand identity (IFSP -- Campus Itapetininga) -----
   Primary accent: institutional green #1E855C. Secondary: warm terracotta
   #9C4A38. Text: deep graphite #181818. Crisp white page, light-grey cards. */
:root {
  --bg: #ffffff;            /* crisp white page */
  --surface: #f8f9fa;       /* cards, sidebar */
  --surface-2: #ffffff;     /* inputs and elevated bits on a grey card */
  --border: #e5e7eb;
  --text: #181818;
  /* >= 5.3:1 on both --bg and --surface, so still AA at the 12px .hint size */
  --text-muted: #5b636e;
  --accent: #1e855c;
  --accent-strong: #14663f;
  --accent-weak: #e8f2ed;
  --accent-2: #9c4a38;
  --accent-2-strong: #7c3a2c;
  --accent-2-weak: #f3e8e5;
  --danger: #b3261e;
  --danger-weak: #f7e8e7;
  --warn: #9c4a38;
  --ok: #1e855c;
  --focus: #0b5c3b;         /* dark green, ~6.5:1 -- a clearly visible focus ring */
  --radius: 8px;
  --space: 8px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-contrast: more) {
  :root {
    --text: #000000;
    --text-muted: #2f2f2f;
    --border: #7a7a72;
    --accent: #0d5138;
    --accent-2: #6e3427;
  }
}

* { box-sizing: border-box; }
body { margin: 0; font-family: var(--font); font-size: 14px; line-height: 1.5; color: var(--text); background: var(--bg); }
a { color: var(--accent); }

/* --- accessibility primitives ---------------------------------------- */
.sr-only {
  position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: var(--surface); color: var(--text); border: 2px solid var(--focus);
  padding: 8px 14px; border-radius: var(--radius); transition: top 0.15s;
}
.skip-link:focus { top: 8px; }
:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
  border-radius: 3px;
}
a:focus-visible, button:focus-visible, .btn:focus-visible,
input:focus-visible, select:focus-visible, textarea:focus-visible, summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}
.swatch {
  display: inline-block; width: 10px; height: 10px; border-radius: 2px;
  border: 1px solid var(--border); vertical-align: middle; margin-left: 4px;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.001ms !important; transition-duration: 0.001ms !important; }
}
h1 { font-size: 20px; font-weight: 600; margin: 0 0 calc(var(--space) * 2); }
h2 { font-size: 16px; font-weight: 600; margin: calc(var(--space) * 3) 0 var(--space); }
h3 { font-size: 14px; font-weight: 600; margin: calc(var(--space) * 2) 0 var(--space); }

.app { display: flex; min-height: 100vh; }
.sidebar { width: 224px; flex-shrink: 0; border-right: 1px solid var(--border); padding: calc(var(--space) * 2); background: var(--surface); }

/* Brand lock-up: the vector mark + wordmark, shared by every page (fragment
   common :: brand). Never a raster -- it scales crisply at any size. */
.brand { display: flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand .mark { flex: none; width: 34px; height: 34px; display: block; }
.brand .wm { display: inline-flex; flex-direction: column; line-height: 1; }
.brand .wm b { font-weight: 700; font-size: 16px; letter-spacing: -0.01em; }
.brand .wm b i { font-style: normal; color: var(--accent); }
.brand .wm .rule { margin-top: 4px; height: 2px; border-radius: 2px;
  background: linear-gradient(90deg, var(--accent-2) 0 55%, var(--accent) 55% 100%); }

.sidebar nav { margin-top: calc(var(--space) * 3); display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { padding: 10px 10px; border-radius: var(--radius); text-decoration: none; color: var(--text); font-weight: 500; }
.sidebar nav a:hover { background: var(--bg); }
.sidebar nav a.active { background: var(--accent-weak); color: var(--accent-strong); font-weight: 600; }
.sidebar .who { margin-top: calc(var(--space) * 3); display: flex; flex-direction: column; align-items: flex-start; gap: 6px; font-size: 12px; color: var(--text-muted); }
.sidebar .who .who-email { word-break: break-word; }
.sidebar .who form { margin: 4px 0 0; }

.main { flex: 1; padding: calc(var(--space) * 4); max-width: 1040px; min-width: 0; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: calc(var(--space) * 2); margin-bottom: calc(var(--space) * 2); }

label { display: block; font-size: 12px; color: var(--text-muted); margin-bottom: 2px; }
input, select, textarea { width: 100%; padding: 7px 10px; border: 1px solid var(--border); border-radius: var(--radius); font: inherit; background: var(--surface-2); color: var(--text); min-height: 40px; }
textarea { min-height: 72px; }
input[type="checkbox"], input[type="radio"] { width: auto; min-height: 0; }
.field { margin-bottom: calc(var(--space) * 1.5); }
.row { display: flex; gap: calc(var(--space) * 2); flex-wrap: wrap; }
.row > * { flex: 1; min-width: 180px; }

button, .btn { font: inherit; font-weight: 600; padding: 9px 16px; min-height: 40px; border: 1px solid var(--accent); background: var(--accent); color: #fff; border-radius: var(--radius); cursor: pointer; text-decoration: none; display: inline-flex; align-items: center; gap: 6px; }
button:hover, .btn:hover { background: var(--accent-strong); border-color: var(--accent-strong); text-decoration: none; }
button.secondary, .btn.secondary { background: var(--surface-2); color: var(--accent-strong); border-color: var(--border); }
button.secondary:hover, .btn.secondary:hover { background: var(--surface); border-color: var(--text-muted); color: var(--accent-strong); }
button:disabled, .btn:disabled { opacity: 0.5; cursor: not-allowed; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--border); vertical-align: top; }
th { color: var(--text-muted); font-weight: 600; }
td.num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11px; font-weight: 600; border: 1px solid var(--border); }
.badge.QUEUED, .badge.RUNNING { color: var(--accent-2-strong); background: var(--accent-2-weak); border-color: #e7d3cd; }
.badge.DONE, .badge.CACHED, .badge.STABLE { color: var(--accent-strong); background: var(--accent-weak); border-color: #bfe0d0; }
.badge.FAILED, .badge.DEPRECATED { color: var(--danger); background: var(--danger-weak); border-color: #ebcbc8; }
.badge.BETA { color: var(--accent-2-strong); background: var(--accent-2-weak); border-color: #e7d3cd; }

.muted { color: var(--text-muted); }
.error { color: var(--danger); font-size: 13px; margin: var(--space) 0; }
.notice { color: var(--accent-strong); font-size: 13px; margin: var(--space) 0; }
.hint { color: var(--text-muted); font-size: 12px; }
.mono { font-family: var(--mono); font-size: 12px; word-break: break-all; white-space: pre-wrap; }
.scroll-x { overflow-x: auto; }

.metric-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: calc(var(--space) * 1.5); }
.metric { border: 1px solid var(--border); border-radius: var(--radius); padding: var(--space) 12px; }
.metric .v { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; }
.metric .k { font-size: 11px; color: var(--text-muted); }
.metric .d { font-size: 11px; color: var(--text-muted); margin-top: 4px; }

.login-wrap { max-width: 360px; margin: 12vh auto; padding: 0 var(--space); }

.autorefresh {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--space);
  background: var(--accent-2-weak); border: 1px solid #e7d3cd; color: var(--accent-2-strong);
  padding: 8px 12px; border-radius: var(--radius); margin: calc(var(--space) * 2) 0; font-size: 13px;
}
.cta-panel {
  display: block;
  background: var(--accent-weak); border: 1px solid var(--accent);
  color: var(--text); border-radius: var(--radius);
  padding: 10px 14px; margin: calc(var(--space) * 2) 0; font-size: 13px; line-height: 1.55;
}
table caption { text-align: left; }

.bars { display: flex; align-items: flex-end; gap: 3px; height: 160px; border-bottom: 1px solid var(--border); padding-top: 8px; }
.bars .bar { flex: 1; background: var(--accent); min-width: 3px; }
.bars-labels { display: flex; gap: 3px; font-size: 9px; color: var(--text-muted); }
.bars-labels span { flex: 1; text-align: center; overflow: hidden; }
figure { margin: 0; }
figure img { max-width: 100%; border: 1px solid var(--border); display: block; }
figure figcaption { margin-top: 6px; }
.viz-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: calc(var(--space) * 2); align-items: start; }
.viz-grid figure.card { margin-bottom: 0; }

/* Node-link similarity graph: a square, aspect-preserved figure. Capped so it
   does not dominate the page; the layout keeps its shape (see fit_unit_box). */
.graph-svg { display: block; width: 100%; max-width: 440px; height: auto; aspect-ratio: 1 / 1;
  border: 1px solid var(--border); border-radius: 8px; background: var(--surface); }

/* One module's results, on the single-job page and (repeated) on the combined
   page. Each carries a soft, module-specific hue (--mod-h) so it is always clear
   which module a block of numbers belongs to. */
.result-block {
  --mod-h: 205;
  border-left: 4px solid hsl(var(--mod-h) 48% 42%);
  padding: 4px 0 8px 16px;
  margin-top: calc(var(--space) * 4);
}
.result-block:first-of-type { margin-top: calc(var(--space) * 2); }
.result-block > h2 {
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--space);
  background: hsl(var(--mod-h) 48% 50% / 0.12);
  border: 1px solid hsl(var(--mod-h) 40% 45% / 0.35);
  border-radius: var(--radius);
  padding: 8px 12px; margin: 0 0 var(--space) -16px;
}
.mod-chip {
  display: inline-block; width: 12px; height: 12px; border-radius: 3px;
  background: hsl(var(--mod-h) 55% 40%); flex: none;
}
@media (prefers-contrast: more) {
  .result-block { border-left-color: hsl(var(--mod-h) 55% 30%); }
  .result-block > h2 { background: hsl(var(--mod-h) 48% 50% / 0.2); }
}

details.prov, details.how-to-read { margin: calc(var(--space) * 2) 0; }
details.prov > summary { cursor: pointer; font-size: 12px; color: var(--text-muted); }
details.prov[open] > summary { margin-bottom: var(--space); }
details.how-to-read > summary {
  cursor: pointer; font-weight: 600; font-size: 13px; color: var(--accent-strong);
  padding: 6px 0;
}
details.how-to-read > p { margin: 8px 0; max-width: 62ch; }
details.how-to-read > p > strong { color: var(--text); }

.mini-report {
  border-left: 3px solid hsl(var(--mod-h, 205) 45% 45%);
  background: hsl(var(--mod-h, 205) 45% 50% / 0.07);
  border-radius: 0 var(--radius) var(--radius) 0;
  padding: 8px 12px; margin: calc(var(--space) * 2) 0;
}
.mini-report-label {
  display: block; font-size: 11px; font-weight: 700; letter-spacing: 0.06em;
  text-transform: uppercase; color: var(--text-muted); margin-bottom: 2px;
}
.mini-report p { margin: 0; max-width: 68ch; white-space: pre-line; }

/* ========================================================================
   Responsive layout -- desktop, notebook, tablet and phone.
   Wide screens: a flex row (sidebar + main). At <= 900px the sidebar becomes a
   sticky top bar whose nav simply WRAPS onto as many rows as it needs -- every
   link stays visible, no horizontal scroll, no disclosure widget, no
   JavaScript. Plain and hard to break.
   ==================================================================== */

img, svg, canvas, video { max-width: 100%; height: auto; }
.viz-grid { grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
pre.mono, .mono { overflow-x: auto; }
th, td { overflow-wrap: anywhere; }   /* never let one long token burst a cell */

@media (max-width: 1100px) {
  .main { max-width: none; }
}

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar {
    width: auto; border-right: 0; border-bottom: 1px solid var(--border);
    padding: 10px 14px 12px; display: flex; flex-wrap: wrap; align-items: center;
    gap: 8px 14px; position: sticky; top: 0; z-index: 40; background: var(--surface);
  }
  .sidebar .skip-link { position: absolute; }
  .brand { margin-right: auto; }
  .brand .mark { width: 30px; height: 30px; }
  .brand .wm b { font-size: 15px; }

  .sidebar nav {
    margin-top: 0; order: 3; flex-basis: 100%;
    flex-direction: row; flex-wrap: wrap; gap: 6px;
  }
  .sidebar nav a {
    padding: 9px 14px; border: 1px solid var(--border); background: var(--surface-2);
    font-weight: 600; white-space: nowrap;
  }
  .sidebar nav a.active { border-color: #bfe0d0; }

  .sidebar .who {
    margin-top: 0; flex-direction: row; align-items: center; flex-wrap: wrap; gap: 6px 10px;
  }
  .sidebar .who form { margin: 0; }

  .main { padding: 20px 16px 40px; }
}

@media (max-width: 520px) {
  .sidebar .who .who-email { display: none; } /* keep the role badge + Sign out */
}

@media (max-width: 560px) {
  h1 { font-size: 18px; }
  .main { padding: 16px 12px 32px; }
  .row > * { flex-basis: 100%; min-width: 0; }
  .metric-grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); }
  .viz-grid { grid-template-columns: 1fr; }
  /* keep the module hue bar but stop the negative-margin header from pushing
     past the viewport edge on a narrow phone */
  .result-block { padding-left: 12px; }
  .result-block > h2 { margin-left: -12px; }
  /* any table not already in a horizontal-scroll wrapper stays contained */
  .main :not(.scroll-x) > table { display: block; overflow-x: auto; }
  .autorefresh { font-size: 12px; }
}

@media (max-width: 400px) {
  .brand .wm { display: none; }        /* mark only on the smallest phones */
  .sidebar nav a { padding: 9px 11px; }
}

/* /modules -- a responsive card grid (no wide table; long summaries wrap
   naturally and never overflow the viewport). */
.module-list { list-style: none; margin: calc(var(--space) * 2) 0 0; padding: 0;
  display: grid; gap: calc(var(--space) * 2);
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
.module-card { margin: 0; display: flex; flex-direction: column; gap: 6px; }
.module-card-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.module-card-head h2 { margin: 0; font-size: 15px; overflow-wrap: anywhere; }
.module-card-meta { margin: 0; }
.module-card-summary { margin: 4px 0 10px; font-size: 13px; color: var(--text); max-width: 60ch; }
.module-card .btn { align-self: flex-start; margin-top: auto; }

/* In-app home: a quiet welcome screen (no history table), shown at / for a
   signed-in user and when the logo is clicked. */
.home { max-width: 34rem; margin: 8vh auto 0; text-align: center; }
.home-mark { display: block; margin: 0 auto calc(var(--space) * 2); }
.home-title { font-size: 24px; margin: 0 0 var(--space); }
.home-lead { color: var(--text-muted); font-size: 14px; margin: 0 auto calc(var(--space) * 3);
  max-width: 30rem; line-height: 1.6; }
.home-actions { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; align-items: center; }
.home-quiet { flex-basis: 100%; margin-top: 6px; font-size: 13px; color: var(--text-muted); }
@media (max-width: 560px) {
  .home { margin-top: 5vh; }
  .home-actions .btn { flex: 1 1 100%; justify-content: center; }
}
