/* SelfHostTCO — FinOps audit terminal: warm ledger paper, carbon ink, forest
   green fillets, monospaced money. Flat surfaces, 5px corners, no gradients and
   no webfonts. Light and dark are both first-class. */

:root {
  color-scheme: light dark;
  --bg: #f6f5f1;
  --surface: #ffffff;
  --panel: #efede7;
  --ink: #14171a;
  --ink-soft: #3a4148;
  --muted: #5c656e;
  --line: #d5d2c8;
  --line-soft: #e5e2d9;
  --slate: #161d1b;
  --slate-2: #202a27;
  --on-slate: #edf1ef;
  --on-slate-soft: #9aa8a2;
  --accent: #0d6e4f;
  --accent-ink: #0a583f;
  --accent-bg: #e7f4ef;
  --warn-ink: #b42318;
  --warn-bg: #fef3f2;
  --err: #b42318;
  --radius: 5px;
  --mono: ui-monospace, "SF Mono", "Cascadia Mono", Consolas, "Liberation Mono", monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

/* Theme: follows the OS until the visitor presses the header toggle, which sets
   <html data-theme="light|dark"> (stored in localStorage, applied in <head>
   before first paint). */
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0e1211;
  --surface: #151b19;
  --panel: #1b2320;
  --line: #2a3531;
  --line-soft: #212a27;
  --ink: #e7ecea;
  --ink-soft: #b2bdb8;
  --muted: #86948e;
  --slate: #0a0e0c;
  --slate-2: #131b18;
  --on-slate: #e7ecea;
  --on-slate-soft: #8d9c96;
  --accent: #22c58b;
  --accent-ink: #34d399;
  --accent-bg: #102a22;
  --warn-ink: #f97066;
  --warn-bg: #2a1512;
  --err: #fca5a5;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0e1211;
    --surface: #151b19;
    --panel: #1b2320;
    --line: #2a3531;
    --line-soft: #212a27;
    --ink: #e7ecea;
    --ink-soft: #b2bdb8;
    --muted: #86948e;
    --slate: #0a0e0c;
    --slate-2: #131b18;
    --on-slate: #e7ecea;
    --on-slate-soft: #8d9c96;
    --accent: #22c58b;
    --accent-ink: #34d399;
    --accent-bg: #102a22;
    --warn-ink: #f97066;
    --warn-bg: #2a1512;
    --err: #fca5a5;
  }
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 1.0625rem;
  line-height: 1.68;
  -webkit-font-smoothing: antialiased;
}

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

a {
  color: var(--ink); text-decoration: underline;
  text-decoration-color: var(--accent); text-decoration-thickness: 2px;
  text-underline-offset: 0.2em;
}
a:hover { color: var(--accent-ink); }

.skip {
  position: absolute; left: 0.75rem; top: -10rem; z-index: 30;
  background: var(--surface); color: var(--ink); padding: 0.5rem 0.9rem;
  border: 2px solid var(--accent); border-radius: var(--radius);
}
.skip:focus { top: 0.75rem; }

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

/* ---------- header ---------- */
.site-header {
  position: sticky; top: 0; z-index: 10;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.site-header .wrap {
  display: flex; align-items: center; justify-content: space-between;
  gap: 0.5rem 1.5rem; padding-top: 0.65rem; padding-bottom: 0.65rem;
  flex-wrap: wrap;
}
.brand {
  display: inline-flex; align-items: center; gap: 0.6rem;
  color: var(--ink); text-decoration: none;
  font-size: 1.05rem; font-weight: 700; letter-spacing: -0.02em;
}
.brand svg { border-radius: 4px; flex: none; }
.brand b { color: var(--accent-ink); font-weight: 700; }
.site-header nav { display: flex; gap: 0.2rem; flex-wrap: wrap; font-size: 0.93rem; }
.site-header nav a {
  color: var(--ink-soft); text-decoration: none;
  padding: 0.4rem 0.75rem; border-radius: var(--radius); font-weight: 500;
  border: 1px solid transparent;
}
.site-header nav a:hover { color: var(--ink); background: var(--panel); }
.site-header nav a[aria-current] {
  color: var(--ink); font-weight: 650;
  border-color: var(--line); background: var(--panel);
  box-shadow: inset 0 -2px 0 var(--accent);
}

.theme-toggle {
  display: inline-flex; align-items: center; justify-content: center;
  width: 2.25rem; height: 2.25rem; margin-left: 0.25rem; padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--ink-soft); cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.theme-toggle:hover { border-color: var(--accent); color: var(--ink); }
.theme-toggle svg { width: 1.05rem; height: 1.05rem; }
.theme-toggle .i-sun { display: none; }
:root[data-theme="dark"] .theme-toggle .i-sun { display: block; }
:root[data-theme="dark"] .theme-toggle .i-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .theme-toggle .i-sun { display: block; }
  :root:not([data-theme="light"]) .theme-toggle .i-moon { display: none; }
}
.site-header .nav-row { display: flex; align-items: center; gap: 0.2rem; flex-wrap: wrap; }

/* ---------- page head: the dark audit band ---------- */
main { padding-top: 1.5rem; padding-bottom: 2rem; }

.page-head {
  position: relative; overflow: hidden;
  margin: 0 0 1.75rem; padding: 2.4rem 2.25rem 2.1rem;
  border-radius: var(--radius);
  background-color: var(--slate);
  color: var(--on-slate);
  background-image:
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 300 150'%3E%3Cpath d='M0 118h300' stroke='%2336413b' stroke-width='1'/%3E%3Cpath d='M20 118V74h26v44M58 118V52h26v66M96 118V86h26v32M134 118V38h26v80M172 118V64h26v54M210 118V90h26v28M248 118V44h26v74' fill='none' stroke='%230d6e4f' stroke-width='3'/%3E%3Cpath d='M0 132h300' stroke='%2336413b' stroke-width='1' stroke-dasharray='2 5'/%3E%3C/svg%3E"),
    linear-gradient(rgba(237, 241, 239, 0.05) 1px, transparent 1px),
    linear-gradient(90deg, rgba(237, 241, 239, 0.05) 1px, transparent 1px);
  background-repeat: no-repeat, repeat, repeat;
  background-size: 280px auto, 26px 26px, 26px 26px;
  background-position: right 1.75rem bottom 1.2rem, 0 0, 0 0;
}
.page-head h1 {
  margin: 0 0 0.8rem; max-width: 24ch;
  font-size: clamp(1.85rem, 1.15rem + 2.5vw, 2.75rem); line-height: 1.08;
  letter-spacing: -0.035em; font-weight: 750; color: var(--on-slate);
}
.page-head .lead {
  margin: 0; max-width: 62ch; color: var(--on-slate-soft); font-size: 1.04rem;
}
.page-head .lead a { color: var(--on-slate); }

h2 {
  margin: 2.6rem 0 0.75rem; font-size: 1.5rem; line-height: 1.25;
  letter-spacing: -0.025em; font-weight: 720;
}
h3 { margin: 1.4rem 0 0.35rem; font-size: 1.08rem; font-weight: 680; letter-spacing: -0.01em; }

.prose { max-width: 74ch; }
.prose > h2:first-child { margin-top: 2.2rem; }
.prose h2 { padding-top: 0.9rem; border-top: 1px solid var(--line); }
.prose h2::before {
  content: ""; display: block; width: 2.25rem; height: 3px;
  margin: -0.95rem 0 0.8rem; background: var(--accent);
}
.prose p { margin: 0 0 1rem; }
.prose ul, .prose ol { margin: 0 0 1.15rem; padding-left: 1.35rem; }
.prose li { margin: 0.35rem 0; }
.prose li::marker { color: var(--accent-ink); }
.prose b { font-weight: 680; }
.prose .table-scroll { max-width: none; }
.prose code {
  font: 0.9em/1.4 var(--mono); background: var(--panel);
  padding: 0.1em 0.35em; border-radius: 3px; border: 1px solid var(--line-soft);
}

.disclaimer {
  margin: 2.2rem 0 0; padding: 1rem 1.15rem;
  border: 1px solid var(--line); border-left: 3px solid var(--warn-ink);
  background: var(--surface); border-radius: var(--radius);
  font-size: 0.94rem; color: var(--ink-soft);
}

/* ---------- calculator ---------- */
.card {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius);
}
.calc { margin: 0 0 2rem; padding: 1.5rem 1.6rem 1.35rem; }
.calc h2 {
  margin: 0 0 1.15rem; font-size: 0.8rem; font-weight: 700;
  font-family: var(--mono); letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--muted); display: flex; align-items: center; gap: 0.6rem;
}
.calc h2::before {
  content: ""; width: 0.6rem; height: 0.6rem; flex: none;
  background: var(--accent); border-radius: 1px;
}
.calc-grid {
  display: grid; gap: 1rem 1.1rem;
  grid-template-columns: repeat(auto-fit, minmax(215px, 1fr));
}
.calc-grid label {
  display: flex; flex-direction: column; gap: 0.35rem;
  font-size: 0.9rem; font-weight: 600; color: var(--ink);
}
.calc-grid .field {
  display: flex; align-items: stretch; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--panel); overflow: hidden;
  transition: border-color 0.15s, box-shadow 0.15s, background-color 0.15s;
}
.calc-grid .field:hover { border-color: var(--muted); }
.calc-grid .field:focus-within {
  border-color: var(--accent); background: var(--surface);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent);
}
.calc-grid input,
.calc-grid select {
  flex: 1; min-width: 0; border: 0; background: transparent; color: var(--ink);
  font: 600 1.1rem/1.2 var(--mono); padding: 0.75rem 0.8rem;
  font-variant-numeric: tabular-nums;
}
.calc-grid select {
  font-size: 0.86rem; font-weight: 600; cursor: pointer;
  -webkit-appearance: none; appearance: none;
  padding-right: 1.7rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5 6 6.5 11 1.5' fill='none' stroke='%235c656e' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.6rem center;
  background-size: 0.62rem auto;
}
.calc-grid input:focus, .calc-grid select:focus { outline: none; }
.calc-grid .unit {
  display: flex; align-items: center; padding: 0 0.75rem;
  font: 500 0.78rem/1 var(--mono); color: var(--muted);
  border-left: 1px solid var(--line);
}
.calc-grid .hint {
  font-size: 0.78rem; font-weight: 400; color: var(--muted); line-height: 1.45;
}

.calc-result {
  display: grid; gap: 0;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  margin: 1.5rem 0 0; padding: 0;
  border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); overflow: hidden;
}
/* hairlines drawn by each cell (right + bottom), clipped at the outer edge,
   so an unfilled last row stays plain surface instead of a grey block */
.out {
  display: flex; flex-direction: column; gap: 0.2rem;
  padding: 0.75rem 0.9rem; background: var(--surface);
  box-shadow: 1px 0 0 var(--line), 0 1px 0 var(--line);
}
.out-primary {
  grid-column: span 2; background: var(--slate); color: var(--on-slate);
  box-shadow: inset 4px 0 0 var(--accent), 1px 0 0 var(--line), 0 1px 0 var(--line);
}
.out-label {
  font: 600 0.7rem/1.3 var(--mono); letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted);
}
.out-primary .out-label { color: var(--on-slate-soft); }
.out-value { display: flex; align-items: baseline; gap: 0.35rem; }
.out-value b {
  font: 650 1.3rem/1.2 var(--mono); color: var(--ink);
  letter-spacing: -0.03em; font-variant-numeric: tabular-nums;
}
.out-primary .out-value b { font-size: 2.2rem; color: var(--on-slate); }
.out-value i { font: 500 0.78rem/1 var(--mono); color: var(--muted); font-style: normal; }
.out-primary .out-value i { color: var(--accent); }
.out-primary.out-negative {
  box-shadow: inset 4px 0 0 var(--warn-ink), 1px 0 0 var(--line), 0 1px 0 var(--line);
}
.out-primary.out-negative .out-value b,
.out-primary.out-negative .out-value i { color: #fbbf24; }

.calc-error {
  margin: 0.9rem 0 0; padding: 0.65rem 0.8rem; border-radius: var(--radius);
  background: var(--warn-bg);
  border-left: 3px solid var(--err);
  color: var(--err); font-size: 0.9rem; font-weight: 600;
}
.calc-note {
  margin: 1rem 0 0; font-size: 0.86rem; line-height: 1.55; color: var(--muted);
  max-width: 82ch;
}

/* ---------- tables ---------- */
.table-scroll {
  margin: 1.3rem 0; overflow-x: auto; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--surface);
}
table { width: 100%; border-collapse: collapse; font-size: 0.94rem; }
caption {
  caption-side: top; text-align: left; padding: 0.8rem 0.95rem;
  font-size: 0.86rem; line-height: 1.5; color: var(--ink-soft);
  border-bottom: 1px solid var(--line);
}
th, td {
  padding: 0.55rem 0.95rem; text-align: right;
  border-bottom: 1px solid var(--line-soft);
  font-variant-numeric: tabular-nums; font-family: var(--mono); font-size: 0.9rem;
}
thead th {
  background: var(--slate); color: var(--on-slate-soft);
  font-size: 0.7rem; font-weight: 600; letter-spacing: 0.08em;
  text-transform: uppercase; white-space: nowrap; border-bottom: 0;
}
thead th:first-child, tbody th { text-align: left; }
tbody th { font-weight: 650; color: var(--ink); }
tbody tr:last-child th, tbody tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: var(--accent-bg); }

/* the plain compatibility tables inside the prose */
.prose table td, .prose table th { text-align: left; white-space: normal; }
.prose table td:first-child { font-family: var(--sans); font-weight: 600; }
.prose table tbody td:first-child { white-space: nowrap; }
.prose thead th:first-child { text-align: left; }

/* ---------- faq ---------- */
.faq { margin: 3rem 0 0; max-width: 74ch; }
.faq details { border-bottom: 1px solid var(--line); padding: 0.9rem 0; }
.faq details:first-of-type { border-top: 1px solid var(--line); }
.faq summary {
  cursor: pointer; font-weight: 650; font-size: 1.02rem;
  list-style: none; display: flex; gap: 0.75rem; align-items: baseline;
}
.faq summary:hover { color: var(--accent-ink); }
.faq summary::-webkit-details-marker { display: none; }
.faq summary::before {
  content: "+"; font-family: var(--mono); font-weight: 700;
  color: var(--accent-ink); flex: none; width: 1ch;
}
.faq details[open] summary::before { content: "\2212"; }
.faq-body { padding: 0.55rem 0 0.2rem 1.75ch; color: var(--ink-soft); }

/* ---------- index cards ---------- */
.tool-grid {
  list-style: none; padding: 0; margin: 1rem 0 2rem;
  display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}
.tool-card {
  display: flex; flex-direction: column; gap: 0.45rem; height: 100%;
  padding: 1.3rem 1.35rem; border-radius: var(--radius); text-decoration: none;
  color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-top: 3px solid var(--slate);
  transition: border-color 0.15s;
}
.tool-card:hover { border-color: var(--accent); color: var(--ink); }
.tool-kind {
  font: 600 0.7rem/1 var(--mono); letter-spacing: 0.1em; text-transform: uppercase;
  color: var(--accent-ink);
}
.tool-card h3 { margin: 0.15rem 0 0.15rem; font-size: 1.18rem; letter-spacing: -0.02em; }
.tool-card p { margin: 0; font-size: 0.93rem; color: var(--ink-soft); flex: 1; }
.tool-go { font: 600 0.82rem/1 var(--mono); color: var(--ink); margin-top: 0.4rem; }
.tool-card:hover .tool-go { color: var(--accent-ink); }

/* ---------- sizing sheet ---------- */
.visually-hidden {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}
.sheet {
  margin: 0 0 2rem; padding: 1.5rem 1.6rem 1.35rem;
  background: var(--surface); border: 1px solid var(--line);
  border-left: 3px solid var(--accent); border-radius: var(--radius);
}
.sheet-head {
  display: flex; flex-wrap: wrap; gap: 1rem 1.5rem;
  align-items: flex-start; justify-content: space-between;
}
.sheet-head > div:first-child { min-width: 0; }
.sheet-kicker {
  margin: 0 0 0.35rem; font: 600 0.7rem/1 var(--mono);
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--accent-ink);
}
.sheet h2 { margin: 0; font-size: 1.3rem; letter-spacing: -0.02em; }
.sheet-actions { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.btn {
  font: 600 0.82rem/1 var(--mono); letter-spacing: 0.02em;
  padding: 0.62rem 0.95rem; border-radius: var(--radius);
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  cursor: pointer; transition: border-color 0.12s ease, color 0.12s ease;
}
.btn:hover { border-color: var(--accent); color: var(--accent-ink); }
.btn-solid { background: var(--slate); border-color: var(--slate); color: var(--on-slate); }
.btn-solid:hover { background: var(--slate-2); border-color: var(--accent); color: var(--on-slate); }
.sheet-meta {
  margin: 0.9rem 0 1rem; padding-bottom: 0.75rem;
  border-bottom: 1px solid var(--line-soft);
  font: 500 0.82rem/1.5 var(--mono); color: var(--muted);
}
.sheet .table-scroll { margin: 0 0 0.9rem; }
.sheet-table td.sheet-note-cell {
  text-align: left; font-family: var(--sans); font-size: 0.82rem;
  color: var(--muted); white-space: normal;
}
.sheet-note {
  margin: 0; max-width: 82ch; font-size: 0.85rem; line-height: 1.6; color: var(--ink-soft);
}

/* Printing is the point of the sheet: on paper only the sheet exists, with the
   site name as its letterhead, and it has to fit one A4/Letter page. */
@page { margin: 12mm; }

@media print {
  :root {
    --bg: #fff; --surface: #fff; --panel: #fff;
    --ink: #000; --ink-soft: #222; --muted: #444;
    --line: #999; --line-soft: #ccc; --slate: #000; --on-slate: #fff;
    --on-slate-soft: #333; --accent: #000; --accent-ink: #000;
    --accent-bg: #fff; --warn-ink: #000; --warn-bg: #fff;
  }
  .site-header, .site-footer, .page-head, .calc, .prose, .faq, .skip,
  .tool-grid, .sheet-actions, .disclaimer { display: none !important; }
  body { background: #fff; font-size: 10pt; }
  .wrap { max-width: none; padding: 0; }
  main { padding: 0; }
  .sheet { border: 0; border-radius: 0; padding: 0; margin: 0; }
  .sheet::before {
    content: "SelfHostTCO · selfhosttco.com";
    display: block; margin-bottom: 0.8rem; padding-bottom: 0.4rem;
    border-bottom: 2px solid #000;
    font: 700 8pt/1 var(--mono); letter-spacing: 0.08em; text-transform: uppercase;
  }
  .sheet h2 { font-size: 12pt; }
  .sheet-meta { color: #222; font-size: 7.5pt; }
  .table-scroll { border: 0; overflow: visible; }
  .sheet-table { font-size: 8.5pt; }
  .sheet-table thead th { background: #fff; color: #000; border-bottom: 1px solid #000; }
  .sheet-table th, .sheet-table td { border-bottom: 1px solid #ccc; padding: 0.28rem 0.4rem; }
  .sheet-table tbody tr:hover { background: transparent; }
  .sheet-note { color: #333; font-size: 7.5pt; }
  a[href]::after { content: ""; }
}

/* ---------- footer ---------- */
.site-footer {
  margin-top: 4rem; padding: 2.2rem 0 2.4rem;
  background: var(--slate); color: var(--on-slate-soft);
  border-top: 3px solid var(--accent);
  font-size: 0.9rem;
}
.site-footer p { margin: 0 0 0.75rem; max-width: 78ch; }
.site-footer .footer-brand { color: var(--on-slate); }
.site-footer nav { display: flex; flex-wrap: wrap; gap: 0.3rem 1.5rem; margin: 0 0 1rem; }
.site-footer nav a { color: var(--on-slate); text-decoration: none; }
.site-footer nav a:hover { color: var(--accent); text-decoration: underline; }
.site-footer .footer-note { font-size: 0.82rem; line-height: 1.6; }

@media (max-width: 760px) {
  .page-head { background-size: 190px auto, 24px 24px, 24px 24px; background-position: right 1rem bottom 1rem, 0 0, 0 0; padding-bottom: 6.5rem; }
}
@media (max-width: 640px) {
  .site-header .wrap { position: relative; }
  .theme-toggle { position: absolute; right: 1rem; top: 0.6rem; margin: 0; }
  body { font-size: 1rem; }
  .wrap { padding: 0 1rem; }
  .page-head { padding: 1.6rem 1.25rem 6rem; }
  .calc { padding: 1.2rem 1.1rem 1.1rem; }
  .calc-grid { grid-template-columns: 1fr; }
  .calc-result { grid-template-columns: 1fr 1fr; }
  .out-primary { grid-column: 1 / -1; }
  .out-primary .out-value b { font-size: 2rem; }
  .site-header nav { font-size: 0.88rem; }
  .site-header nav a { padding: 0.35rem 0.55rem; }
  th, td { padding: 0.5rem 0.6rem; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
