/* ==========================================================================
   Valuation Identities — tool-specific styles

   Extends the shared design system in ../styles.css (the `landing` repo owns
   that file). Everything here is built from the same custom properties —
   paper/ink, --accent, --warn, --danger, --radius — so the page stays inside
   the suite's palette in both light and dark mode. Nothing is hardcoded
   except the chart ramp, which lives on the fixed-light chart paper.
   ========================================================================== */

:root {
    /* Verdict states. Reuse the suite's accent/ochre/oxblood rather than the
       usual traffic-light green/amber/red, which would break the palette. */
    --ok: var(--accent);
    --ok-soft: var(--accent-soft);
    --check: var(--warn);
    --check-soft: color-mix(in srgb, var(--warn) 11%, transparent);
    --bad: var(--danger);
    --bad-soft: color-mix(in srgb, var(--danger) 11%, transparent);

    /* Chart ramp — sequential, one hue, light→dark, ordered by return on
       capital. Validated for contrast (all >= 3:1) and colour-vision
       separation against the fixed-light chart paper; every line is also
       directly labelled, so identity never rests on colour alone. */
    --ramp-1: #6d8dab;
    --ramp-2: #42627f;
    --ramp-3: #1f3243;
}

@media (prefers-color-scheme: dark) {
    :root {
        /* the muted dark palette needs a touch more tint to read as a wash */
        --check-soft: color-mix(in srgb, var(--warn) 16%, transparent);
        --bad-soft: color-mix(in srgb, var(--danger) 16%, transparent);
    }
}

/* visually hidden but exposed to assistive technology — used by the
   debounced diagnostics announcer (#flag-announce) */
.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    margin: -1px;
    padding: 0;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
    border: 0;
}

/* ==========================================================================
   Panels (inputs, diagnostics, notes)
   ========================================================================== */
.panel {
    margin: clamp(26px, 4vw, 40px) 0;
    padding: clamp(18px, 3vw, 26px);
    background-color: var(--surface-2);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
}

.panel-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 18px;
    flex-wrap: wrap;
}

/* override the global h2 — inside a panel there is no section rule */
.panel-title {
    font-family: var(--font);
    font-weight: 600;
    font-size: clamp(18px, 2.2vw, 22px);
    letter-spacing: -0.02em;
    color: var(--ink);
    margin: 0;
    padding: 0;
    border: none;
}

.panel-sub {
    max-width: 62ch;
    margin-top: 8px;
    color: var(--ink-soft);
    font-size: 14.5px;
    line-height: 1.55;
}

.panel-toggle {
    flex: none;
    font-size: 13.5px;
    padding: 8px 14px;
}

/* ---------- Presets ---------- */
.preset-bar {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 10px 16px;
    margin: 20px 0 4px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.preset-label {
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-soft);
}

.preset-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.preset {
    cursor: pointer;
    font-family: var(--font);
    font-size: 13px;
    font-weight: 500;
    line-height: 1.2;
    padding: 7px 12px;
    border-radius: var(--radius);
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--ink);
    transition: border-color 0.2s, background-color 0.2s, color 0.2s;
}

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

.preset:focus-visible {
    outline: none;
    box-shadow: var(--ring);
}

.preset small {
    display: block;
    font-size: 11px;
    font-weight: 400;
    color: var(--ink-faint);
    margin-top: 2px;
}

/* ---------- Input grid ---------- */
.input-groups {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(232px, 1fr));
    gap: 22px;
    margin-top: 22px;
}

.input-group h3 {
    font-family: var(--font);
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--accent);
    padding-bottom: 7px;
    margin-bottom: 12px;
    border-bottom: 1px solid var(--line);
}

.field {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-bottom: 9px;
}

.field label {
    font-size: 13px;
    line-height: 1.35;
    color: var(--ink-soft);
}

.field .in-wrap {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    flex: none;
}

.field input {
    width: 92px;
    padding: 6px 8px;
    text-align: right;
    border: 1px solid var(--line-strong);
    border-radius: var(--radius);
    background-color: var(--field-bg);
    color: var(--ink);
    font-family: var(--font);
    font-size: 13.5px;
    font-variant-numeric: tabular-nums;
    transition: border-color 0.2s, box-shadow 0.2s;
    -moz-appearance: textfield;
}

.field input::-webkit-outer-spin-button,
.field input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.field input:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: var(--ring);
}

.field .suffix {
    font-size: 12px;
    color: var(--ink-faint);
    width: 12px;
}

.input-actions {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 14px;
    margin-top: 22px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.copy-note {
    font-size: 13px;
    color: var(--accent);
}

/* ==========================================================================
   Diagnostics
   ========================================================================== */
.flag-list {
    list-style: none;
    margin-top: 18px;
    display: grid;
    gap: 9px;
}

.flag {
    display: grid;
    grid-template-columns: auto 1fr;
    align-items: start;
    gap: 11px;
    padding: 11px 14px;
    border-radius: var(--radius);
    border: 1px solid var(--line);
    background: var(--surface);
    font-size: 14px;
    line-height: 1.5;
}

.flag-mark {
    font-size: 12px;
    line-height: 1.45;
}

.flag-check {
    border-color: color-mix(in srgb, var(--check) 40%, var(--line));
    background: var(--check-soft);
}
.flag-check .flag-mark {
    color: var(--check);
}

.flag-bad {
    border-color: color-mix(in srgb, var(--bad) 45%, var(--line));
    background: var(--bad-soft);
}
.flag-bad .flag-mark {
    color: var(--bad);
}

.flag a {
    color: inherit;
    text-decoration: none;
    border-bottom: 1px solid color-mix(in srgb, currentColor 35%, transparent);
}

.flag a:hover {
    border-bottom-color: currentColor;
}

.flag-clean {
    color: var(--ink-soft);
    background: var(--surface);
    border-style: dashed;
}

/* ---------- Jump nav ---------- */
.jump {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px 10px;
    margin-top: 20px;
    padding-top: 18px;
    border-top: 1px solid var(--line);
}

.jump-label {
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-soft);
    margin-right: 4px;
}

.jump a {
    display: inline-flex;
    align-items: baseline;
    gap: 6px;
    padding: 5px 11px;
    border-radius: 999px;
    border: 1px solid var(--line-strong);
    background: var(--surface);
    color: var(--ink-soft);
    text-decoration: none;
    font-size: 12.5px;
    line-height: 1.3;
    transition: border-color 0.2s, color 0.2s;
}

.jump a span {
    font-weight: 600;
    color: var(--accent);
}

.jump a:hover {
    border-color: var(--accent);
    color: var(--ink);
}

/* ==========================================================================
   Identity sections and cards
   ========================================================================== */
.family {
    margin-top: clamp(38px, 5vw, 56px);
}

.family > h2 {
    margin-top: 0;
}

.family-lede {
    max-width: var(--measure);
    margin: -4px 0 22px;
    color: var(--ink-soft);
    font-size: 15px;
    line-height: 1.6;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(440px, 1fr));
    gap: 20px;
    align-items: start;
}

@media (max-width: 980px) {
    .card-grid {
        grid-template-columns: 1fr;
    }
}

.card {
    display: flex;
    flex-direction: column;
    min-width: 0;
    scroll-margin-top: 20px;
    background-color: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.card-head {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 18px;
    background-color: var(--surface-2);
    border-bottom: 1px solid var(--line);
}

.card-no {
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.06em;
    color: var(--ink-faint);
    font-variant-numeric: tabular-nums;
}

.card-title {
    font-family: var(--font);
    font-weight: 600;
    font-size: 16px;
    letter-spacing: -0.01em;
    color: var(--ink);
    margin-top: 2px;
}

.verdict {
    flex: none;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    font-size: 11.5px;
    font-weight: 600;
    letter-spacing: 0.03em;
    white-space: nowrap;
    border: 1px solid transparent;
}

.verdict-ok {
    color: var(--accent-ink);
    background: var(--ok-soft);
    border-color: color-mix(in srgb, var(--accent) 32%, transparent);
}
.verdict-check {
    color: var(--check);
    background: var(--check-soft);
    border-color: color-mix(in srgb, var(--check) 38%, transparent);
}
.verdict-bad {
    color: var(--bad);
    background: var(--bad-soft);
    border-color: color-mix(in srgb, var(--bad) 42%, transparent);
}
.verdict-na {
    color: var(--ink-faint);
    background: transparent;
    border-color: var(--line-strong);
}

.card-body {
    padding: 18px;
    display: flex;
    flex-direction: column;
    gap: 16px;
    flex: 1;
}

/* ---------- Formula ---------- */
.formula {
    padding: 15px 14px;
    border-radius: var(--radius);
    background: color-mix(in srgb, var(--accent-soft) 55%, transparent);
    border: 1px solid color-mix(in srgb, var(--accent) 15%, var(--line));
    text-align: center;
    font-size: 15px;
    line-height: 2.1;
    color: var(--ink);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.formula .v {
    color: var(--accent-ink);
    font-weight: 500;
    white-space: nowrap;
}

.formula .op {
    color: var(--ink-faint);
    margin: 0 0.38em;
}

.formula .eq {
    color: var(--ink-faint);
    margin: 0 0.55em;
}

.formula .lit {
    white-space: nowrap;
}

.formula sub,
.formula sup {
    font-size: 0.68em;
    color: var(--ink-soft);
    font-weight: 400;
}

/* stacked fraction */
.frac {
    display: inline-flex;
    flex-direction: column;
    vertical-align: middle;
    text-align: center;
    line-height: 1.32;
    margin: 0 0.15em;
}

.frac > .num {
    padding: 0 0.4em 0.14em;
    border-bottom: 1px solid var(--ink-faint);
}

.frac > .den {
    padding: 0.14em 0.4em 0;
}

/* alternative formula line ("equivalently, …") */
.formula-alt {
    margin-top: 10px;
    padding-top: 12px;
    border-top: 1px dashed var(--line-strong);
    font-size: 14px;
}

.formula-alt-label {
    display: block;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--ink-faint);
    margin-bottom: 6px;
    line-height: 1.4;
}

/* ---------- "With your numbers" ---------- */
.yours {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 16px;
    align-items: center;
}

.terms {
    display: grid;
    gap: 5px;
    min-width: 0;
}

.term {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    font-size: 13.5px;
    padding-bottom: 4px;
    border-bottom: 1px dotted var(--line);
}

.term:last-child {
    border-bottom: none;
    padding-bottom: 0;
}

.term-label {
    color: var(--ink-soft);
    min-width: 0;
}

.term-value {
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    color: var(--ink);
    white-space: nowrap;
}

.result {
    flex: none;
    text-align: center;
    min-width: 122px;
    padding: 12px 14px;
    border-radius: var(--radius);
    background: var(--surface-2);
    border: 1px solid var(--line-strong);
}

.result-value {
    display: block;
    font-size: clamp(21px, 2.4vw, 26px);
    font-weight: 600;
    letter-spacing: -0.02em;
    line-height: 1.15;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
}

.result-label {
    display: block;
    margin-top: 5px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--ink-soft);
    line-height: 1.35;
}

.result-undef .result-value {
    color: var(--ink-faint);
    font-size: 19px;
}

/* ---------- Explore ---------- */
.explore {
    border: 1px dashed var(--line-strong);
    border-radius: var(--radius);
    padding: 14px;
}

.explore-head {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 12px;
}

.explore-title {
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.explore-reset {
    cursor: pointer;
    border: none;
    background: none;
    padding: 0;
    font-family: var(--font);
    font-size: 12.5px;
    color: var(--accent);
    text-decoration: underline;
    text-underline-offset: 2px;
}

.explore-reset:focus-visible {
    outline: none;
    box-shadow: var(--ring);
    border-radius: 3px;
}

.slider {
    display: grid;
    grid-template-columns: minmax(96px, auto) 1fr auto;
    align-items: center;
    gap: 10px;
    margin-bottom: 9px;
}

.slider label {
    font-size: 12.5px;
    color: var(--ink-soft);
    line-height: 1.3;
}

.slider output {
    font-size: 12.5px;
    font-variant-numeric: tabular-nums;
    font-weight: 500;
    color: var(--ink);
    text-align: right;
    min-width: 54px;
}

input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    width: 100%;
    height: 20px;
    background: transparent;
    cursor: pointer;
}

input[type="range"]::-webkit-slider-runnable-track {
    height: 3px;
    border-radius: 2px;
    background: var(--line-strong);
}

input[type="range"]::-moz-range-track {
    height: 3px;
    border-radius: 2px;
    background: var(--line-strong);
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 14px;
    height: 14px;
    margin-top: -5.5px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
    box-shadow: 0 0 0 1px var(--accent);
}

input[type="range"]::-moz-range-thumb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--accent);
    border: 2px solid var(--surface);
    box-shadow: 0 0 0 1px var(--accent);
}

input[type="range"]:focus-visible {
    outline: none;
}

input[type="range"]:focus-visible::-webkit-slider-thumb {
    box-shadow: 0 0 0 1px var(--accent), var(--ring);
}

input[type="range"]:focus-visible::-moz-range-thumb {
    box-shadow: 0 0 0 1px var(--accent), var(--ring);
}

.explore-out {
    display: flex;
    align-items: baseline;
    justify-content: space-between;
    gap: 10px;
    margin-top: 12px;
    padding-top: 11px;
    border-top: 1px solid var(--line);
    font-size: 13px;
}

.explore-out .label {
    color: var(--ink-soft);
}

.explore-out .value {
    font-size: 16px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
    color: var(--accent-ink);
}

/* ---------- Guidance and reference ---------- */
.guidance {
    font-size: 13.5px;
    line-height: 1.6;
    color: var(--ink-soft);
}

.guidance strong {
    color: var(--ink);
    font-weight: 500;
}

.verdict-msg {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 9px;
    align-items: start;
    font-size: 13.5px;
    line-height: 1.5;
    padding: 10px 12px;
    border-radius: var(--radius);
}

.verdict-msg .flag-mark {
    font-size: 11.5px;
    line-height: 1.5;
}

.msg-ok {
    color: var(--ink-soft);
    background: var(--ok-soft);
}
.msg-ok .flag-mark {
    color: var(--accent);
}
.msg-check {
    color: var(--ink);
    background: var(--check-soft);
}
.msg-check .flag-mark {
    color: var(--check);
}
.msg-bad {
    color: var(--ink);
    background: var(--bad-soft);
}
.msg-bad .flag-mark {
    color: var(--bad);
}
.msg-na {
    color: var(--ink-faint);
    background: var(--surface-2);
}

.ref {
    margin-top: auto;
    padding-top: 13px;
    border-top: 1px solid var(--line);
    font-size: 12.5px;
    line-height: 1.5;
    color: var(--ink-faint);
}

.ref .ref-ch {
    font-weight: 600;
    color: var(--ink-soft);
}

/* ==========================================================================
   View tabs — the identities and the chain are two views of the same inputs
   ========================================================================== */
.tabbar {
    display: flex;
    gap: 4px;
    margin-top: clamp(26px, 4vw, 40px);
    border-bottom: 1px solid var(--line-strong);
}

.tabbar [role="tab"] {
    appearance: none;
    background: none;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -1px;
    padding: 9px 14px 11px;
    font-family: var(--font);
    font-size: 14.5px;
    font-weight: 600;
    line-height: 1.3;
    text-align: left;
    color: var(--ink-soft);
    cursor: pointer;
}

.tabbar [role="tab"] small {
    display: block;
    font-size: 11.5px;
    font-weight: 400;
    color: var(--ink-faint);
}

.tabbar [role="tab"]:hover {
    color: var(--ink);
}

.tabbar [role="tab"][aria-selected="true"] {
    color: var(--accent-ink);
    border-bottom-color: var(--accent);
}

.tabbar [role="tab"]:focus-visible {
    outline: none;
    box-shadow: var(--ring);
    border-radius: var(--radius) var(--radius) 0 0;
}

/* ==========================================================================
   The chain panel — one directed sequence from margins to value per share
   ========================================================================== */
.chain-row {
    display: grid;
    grid-template-columns: minmax(190px, 1.1fr) minmax(230px, 1.5fr) minmax(190px, 1.1fr);
    gap: 10px 26px;
    align-items: center;
    padding: 6px 0;
}

.chain-what h3 {
    font-family: var(--font);
    font-size: 13.5px;
    font-weight: 600;
    color: var(--ink);
    margin-bottom: 5px;
}

/* quieter than a card's formula box: inline, left-aligned, no frame */
.chain-formula {
    padding: 0;
    background: none;
    border: none;
    text-align: left;
    font-size: 13px;
    line-height: 1.9;
}

.chain-controls .slider:last-child {
    margin-bottom: 0;
}

.chain-follows {
    font-size: 12px;
    font-style: italic;
    color: var(--ink-faint);
}

.chain-outs {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    justify-content: flex-end;
    text-align: right;
}

.chain-chip-label {
    display: block;
    font-size: 10.5px;
    font-weight: 600;
    letter-spacing: 0.07em;
    text-transform: uppercase;
    color: var(--ink-faint);
}

.chain-chip-value {
    display: block;
    font-size: 15px;
    font-weight: 500;
    font-variant-numeric: tabular-nums;
    color: var(--ink);
}

.chain-chip-big .chain-chip-value {
    font-size: 19px;
    font-weight: 600;
    color: var(--accent-ink);
}

.chain-link {
    text-align: center;
    color: var(--ink-faint);
    font-size: 13px;
    line-height: 1;
    padding: 2px 0;
}

#ch-msg {
    margin-top: 16px;
}

@media (max-width: 860px) {
    .chain-row {
        grid-template-columns: 1fr;
        gap: 10px;
        padding: 10px 0;
    }
    .chain-outs {
        justify-content: flex-start;
        text-align: left;
    }
}

/* ==========================================================================
   Charts — rendered on the fixed-light chart paper, as elsewhere in the suite
   ========================================================================== */
.card-chart {
    background: var(--chart-paper);
    border: 1px solid var(--chart-axis);
    border-radius: var(--radius);
    padding: 10px 12px 6px;
}

.card-chart svg {
    display: block;
    width: 100%;
    height: auto;
    overflow: visible;
}

.card-chart .ax-line {
    stroke: var(--chart-axis);
    stroke-width: 1;
    shape-rendering: crispEdges;
}

.card-chart .grid-line {
    stroke: var(--chart-grid);
    stroke-width: 1;
    shape-rendering: crispEdges;
}

.card-chart .ax-text {
    font-family: var(--font);
    font-size: 10px;
    fill: var(--chart-axis-ink);
}

.card-chart .ax-title {
    font-family: var(--font);
    font-size: 10.5px;
    font-weight: 500;
    fill: var(--chart-ink);
}

.card-chart .series {
    fill: none;
    stroke-width: 2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.card-chart .series-label {
    font-family: var(--font);
    font-size: 10.5px;
    font-weight: 500;
}

.card-chart .marker-line {
    stroke: var(--chart-axis-ink);
    stroke-width: 1;
    stroke-dasharray: 3 3;
}

.card-chart .marker-dot {
    fill: var(--chart-loss);
    stroke: var(--chart-paper);
    stroke-width: 2;
}

.card-chart .marker-text {
    font-family: var(--font);
    font-size: 10px;
    font-weight: 500;
    fill: var(--chart-loss);
}

.chart-caption {
    margin-top: 8px;
    font-size: 12px;
    line-height: 1.5;
    color: var(--ink-soft);
}

/* ==========================================================================
   Notes panel
   ========================================================================== */
.notes-panel {
    background: var(--surface);
}

.notes {
    max-width: var(--measure);
    margin: 18px 0 0 1.15em;
    display: grid;
    gap: 12px;
    font-size: 14.5px;
    line-height: 1.6;
    color: var(--ink-soft);
}

.notes strong {
    color: var(--ink);
}

.source-note {
    max-width: var(--measure);
    margin-top: 22px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
    font-size: 13px;
    line-height: 1.55;
    color: var(--ink-faint);
}

/* ==========================================================================
   Responsive
   ========================================================================== */
@media (max-width: 620px) {
    .yours {
        grid-template-columns: 1fr;
    }

    .result {
        min-width: 0;
    }

    .slider {
        grid-template-columns: 1fr auto;
    }

    .slider input[type="range"] {
        grid-column: 1 / -1;
    }

    .field input {
        width: 84px;
    }
}
