/**
 * Calculators — redesign to match Figma "rulr-team-library / Calculators &
 * Decision Support". Loaded after style.css so it can override the older
 * calculator control styles (.unit-*, .calculator-*-tab, .result*).
 *
 * Design tokens (from Figma variables):
 *   font           Inter Tight
 *   primary        #312e81  (indigo-900)  — links / "Open →" / active
 *   text           #020617  (slate-950)
 *   muted          #64748b / #4a5565
 *   card border    #f5f5f9
 *   card shadow    0 8px 24px rgba(33,33,97,.05)
 *   radius         16px (card), 12px (controls), 10.4px (icon tile)
 */
@import url('https://fonts.googleapis.com/css2?family=Inter+Tight:wght@400;500;600;700&display=swap');

.calc-scope,
.calc-scope * {
    font-family: 'Inter Tight', ui-sans-serif, system-ui, -apple-system, sans-serif;
}

/* Override the theme's global `section { margin: 2rem 0 4rem }` — the Tailwind
   `my-*` utilities on the section were purged from style.css, so it otherwise
   inherits that large default. A class beats the element selector. */
.calc-scope {
    margin-top: 1.5rem;
    margin-bottom: 2rem;
}

.calc-container {
    width: 100%;
    max-width: 1472px;
    margin: 0 auto;
    padding: 0 1rem;
}

/* ============================ LIST PAGE ============================ */
.calc-page-head {
    max-width: 720px;
    margin: 0 0 2rem;
}
.calc-page-title {
    font-size: 36px;
    line-height: 40px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: #020617;
    margin: 0 0 0.75rem;
}
.calc-page-intro {
    font-size: 16px;
    line-height: 24px;
    color: #64748b;
    margin: 0;
}

/* Full-width gray band behind the card grid + FAQ (white title sits above it). */
.calc-gray {
    padding-top: 2.5rem;
    padding-bottom: 3.5rem;
}
.calc-faq {
    max-width: 960px;
    margin: 5rem auto 0;
}

.calc-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(0, 1fr));
    gap: 20px;
}
@media (max-width: 1279px) { .calc-grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 900px)  { .calc-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px)  { .calc-grid { grid-template-columns: 1fr; } }

.calc-card {
    display: flex;
    flex-direction: column;
    gap: 16px;
    padding: 24px;
    border-radius: 16px;
    background: #ffffff;
    border: 1px solid #f5f5f9;
    text-decoration: none;
    height: 100%;
    transition: background-color 0.15s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}
.calc-card:hover {
    background: var(--calc-hover, #f8f8fa);
    box-shadow: 0 8px 24px rgba(33, 33, 97, 0.05);
}

.calc-card__icon {
    width: 64px;
    height: 64px;
    border-radius: 10.4px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--calc-tile, #f1f5f9);
    color: #343330;
    flex: none;
}
.calc-card__icon svg { width: 32px; height: 32px; display: block; }

.calc-card__body { display: flex; flex-direction: column; gap: 12px; flex: 1 0 auto; }
.calc-card__title {
    font-size: 24px;
    line-height: 32px;
    font-weight: 700;
    color: #020617;
    margin: 0;
    word-break: break-word;
}
.calc-card__desc {
    font-size: 16px;
    line-height: 24px;
    font-weight: 400;
    color: #4a5565;
    margin: 0;
    flex: 1 0 auto;
}
.calc-card__open {
    font-size: 16px;
    line-height: 22px;
    font-weight: 600;
    color: #312e81;
    margin: 0;
}

/* "Suggest a new calculator" dashed card */
.calc-card--suggest {
    border: 1px dashed rgba(49, 46, 129, 0.3);
    background: rgba(231, 240, 252, 0.3);
    align-items: center;
    justify-content: center;
    text-align: center;
}
.calc-card--suggest:hover { box-shadow: none; }
.calc-card--suggest .calc-card__icon {
    width: 72px;
    height: 72px;
    background: #312e81;
    color: #ffffff;
}
.calc-card--suggest .calc-card__icon svg { width: 40px; height: 40px; }
.calc-card--suggest .calc-card__desc { text-align: center; flex: 0 0 auto; }
.calc-card--suggest .calc-card__open { color: #312e81; }

/* ========================= SINGLE PAGE ========================= */
.calc-single {
    display: grid;
    grid-template-columns: 331px minmax(0, 1fr);
    gap: 20px;
    align-items: start;
    /* Extra breathing room above the sidebar tiles + "← CALCULATORS" back link. */
    padding-top: 1.5rem;
}
@media (min-width: 1024px) { .calc-single { padding-top: 2rem; } }
/* minmax(0,1fr) (not plain 1fr) so the column can shrink below its content's
   intrinsic width — otherwise wide inner rows push the page wider than the
   viewport and everything scrolls sideways. */
@media (max-width: 1023px) { .calc-single { grid-template-columns: minmax(0, 1fr); } }
.calc-aside,
.calc-main { min-width: 0; }
/* Never let a control overflow its column. */
.calc-card-panel { max-width: 100%; }
.calc-card-panel .unit-input { max-width: 100%; }

.calc-breadcrumb {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 12px;
    font-weight: 600;
    color: #94a3b8;
    margin: 0 0 1rem;
}

/* "Back to Calculators" link (main column) — replaces the old breadcrumb. */
.calc-back {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 12px;
    font-weight: 600;
    color: #94a3b8;
    text-decoration: none;
    margin: 0 0 1rem;
    transition: color 0.15s ease;
}
.calc-back:hover { color: #312e81; }
.calc-breadcrumb::before {
    content: "";
    width: 20px;
    height: 2px;
    background: #cbd5e1;
    display: inline-block;
}

/* ---- Sidebar nav: 2-col grid of icon tiles ---- */
.calc-nav {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.calc-nav__item {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    text-align: center;
    gap: 12px;
    padding: 16px 12px;
    border-radius: 16px;
    background: #f8f8fa;
    border: none;
    text-decoration: none;
    transition: background-color 0.15s ease;
}
.calc-nav__item:hover { background: var(--calc-hover, #f1f1f5); }
.calc-nav__item.is-active {
    background: var(--calc-hover, #eef7f0);
}
.calc-nav__icon {
    width: 64px;
    height: 64px;
    border-radius: 10.4px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--calc-tile, #f1f5f9);
    color: #343330;
    flex: none;
}
.calc-nav__icon svg { width: 32px; height: 32px; display: block; }
.calc-nav__label {
    font-size: 13px;
    line-height: 18px;
    font-weight: 600;
    color: #334155;
    margin: 0;
}
.calc-nav__item.is-active .calc-nav__label { color: #020617; }

.calc-nav__item--suggest .calc-nav__label { color: #312e81; }

/* Desktop shows the grid; the mobile quick-bar + overlay + FAB are hidden. */
.calc-mobilebar { display: none; }
.calc-overlay { display: none; }
.calc-fab { display: none; }

@media (max-width: 1023px) {
    .calc-aside__desktop { display: none; }

    /* Drop the aside box so the sticky quick-bar's containing block is the whole
       .calc-single column — otherwise it would unstick right after the (short)
       aside scrolls out of view. */
    .calc-aside { display: contents; }

    /* "Last Used" bar: a label + the three most-recent calculators. Not sticky —
       it sits BELOW the calculator (order:2 after the main column, order:1). */
    .calc-main { order: 1; }
    .calc-mobilebar {
        display: block;
        order: 2;
        background: #ffffff;
        padding: 10px 0 0;
        margin-top: 1.5rem;
    }
    .calc-mobilebar__title {
        margin: 0 0 8px;
        font-size: 11px;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        font-weight: 700;
        color: #94a3b8;
    }
    .calc-mobilebar__recent {
        display: grid;
        grid-template-columns: 1fr 1fr 1fr;
        gap: 10px;
    }
    .calc-mobilebar .calc-nav__item {
        padding: 12px 8px;
        gap: 8px;
    }
    .calc-mobilebar .calc-nav__icon { width: 44px; height: 44px; border-radius: 9px; }
    .calc-mobilebar .calc-nav__icon svg { width: 24px; height: 24px; }
    .calc-mobilebar .calc-nav__label {
        font-size: 11px;
        line-height: 14px;
        display: -webkit-box;
        -webkit-line-clamp: 2;
        -webkit-box-orient: vertical;
        overflow: hidden;
    }

    /* Floating "Show All Calculators" tab, pinned to the right edge, centered.
       Collapses (slides mostly off-screen, leaving a clickable edge) on scroll-down
       and expands on scroll-up — toggled via .is-collapsed by JS. */
    .calc-fab {
        display: inline-flex;
        align-items: center;
        gap: 8px;
        position: fixed;
        right: 0;
        top: 50%;
        transform: translateY(-50%);
        z-index: 90;
        appearance: none;
        cursor: pointer;
        border: none;
        background: #312e81;
        color: #ffffff;
        writing-mode: vertical-rl;
        padding: 16px 8px;
        border-radius: 12px 0 0 12px;
        font-size: 12px;
        font-weight: 700;
        letter-spacing: 0.04em;
        box-shadow: -3px 0 14px rgba(2, 6, 23, 0.22);
        transition: transform 0.3s cubic-bezier(0.22, 1, 0.36, 1);
    }
    /* Leave ~18px peeking so it stays visible and tappable. */
    .calc-fab.is-collapsed {
        transform: translateY(-50%) translateX(calc(100% - 18px));
    }
    .calc-fab__icon {
        writing-mode: horizontal-tb; /* keep the icon upright */
        display: inline-flex;
    }
    .calc-fab__icon svg { width: 18px; height: 18px; display: block; }
}

/* Overlay of all calculators (two columns, vertically scrollable). */
.calc-overlay {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: #ffffff;
}
.calc-overlay[hidden] { display: none; }
@media (max-width: 1023px) {
    .calc-overlay:not([hidden]) { display: flex; }
}
.calc-overlay__panel {
    width: 100%;
    height: 100%;
    max-height: none;
    display: flex;
    flex-direction: column;
    background: #ffffff;
    border-radius: 0;
    overflow: hidden;
}
.calc-overlay__head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: calc(16px + env(safe-area-inset-top)) 18px 16px;
    border-bottom: 1px solid #f1f5f9;
    position: sticky;
    top: 0;
    background: #ffffff;
}
.calc-overlay__title { margin: 0; font-size: 18px; font-weight: 800; color: #020617; }
.calc-overlay__close {
    appearance: none;
    cursor: pointer;
    border: none;
    background: #f1f5f9;
    color: #334155;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.calc-overlay__grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    padding: 16px 18px calc(18px + env(safe-area-inset-bottom));
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

/* ---- Main column ---- */
.calc-title {
    font-size: 30px;
    line-height: 1.15;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: #020617;
    margin: 0 0 1.25rem;
    overflow-wrap: anywhere;
}
@media (min-width: 768px)  { .calc-title { font-size: 32px; } }
@media (min-width: 1280px) { .calc-title { font-size: 36px; } }
.calc-lede {
    font-size: 16px;
    line-height: 24px;
    color: #64748b;
    margin: 0 0 2.5rem;
    max-width: 720px;
}

/* Calculator Page WYSIWYG body — rendered after the calculator, in its own panel
   (a lighter grey than the calculator panel) using the same paddings. */
.calc-body {
    margin-top: 3.5rem;
    background: #fcfcfd;
    border-radius: 16px;
    padding: 1.5rem;
}
@media (min-width: 768px)  { .calc-body { padding: 2rem; } }
@media (min-width: 1280px) { .calc-body { padding: 2.5rem; } }
.calc-body.prose { max-width: none; }

/* Form card */
.calc-card-panel {
    background: #f8f8fa;
    border: none;
    border-radius: 16px;
    box-shadow: none;
    padding: 1.5rem;
}
@media (min-width: 768px)  { .calc-card-panel { padding: 2rem; } }
@media (min-width: 1280px) { .calc-card-panel { padding: 2.5rem; } }

/* Groups (toggles + inputs) */
.calc-controls { display: flex; flex-direction: column; gap: 28px; }
.calc-row { display: flex; flex-wrap: wrap; gap: 20px; }
.calc-row--inputs > .unit-wrapper { flex: 1 1 150px; min-width: 120px; }

/* Field label */
.unit-title,
.calc-label {
    display: block;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    font-size: 12px;
    font-weight: 600;
    color: #94a3b8;
    margin: 0 0 8px;
}

/* Segmented toggle (Unit System / Patient Sex) */
.unit-btn-wrapper {
    display: inline-flex;
    gap: 4px;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 14px;
}
.unit-btn {
    appearance: none;
    border: none;
    cursor: pointer;
    background: transparent;
    color: #475569;
    font-size: 14px;
    font-weight: 600;
    line-height: 1;
    padding: 10px 20px;
    border-radius: 11px;
    white-space: nowrap;
    transition: background-color 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
}
.unit-btn sup { font-weight: 500; opacity: 0.7; margin-left: 2px; }
.unit-btn-selected {
    background: #ffffff;
    color: #020617;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

/* Numeric inputs */
.unit-input {
    width: 100%;
    height: 56px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 0 20px;
    font-size: 16px;
    font-weight: 500;
    color: #020617;
    outline: none;
    transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.unit-input::placeholder { color: #94a3b8; font-weight: 400; }
.unit-input:focus {
    border-color: #312e81;
    box-shadow: 0 0 0 3px rgba(49, 46, 129, 0.12);
}
.unit-wrapper .unit-title { position: static; }
.unit-wrapper label.unit-title { text-transform: uppercase; }

/* Divider before the result */
.calc-controls + .notification { margin-top: 12px; }
.result {
    margin-top: 32px;
    padding-top: 32px;
    border-top: 1px solid #eef0f3;
}

/* ---- Compatibility with the existing per-calculator control markup ---- */
/* The old pages wrap controls in `.mt-9`; kill that top margin inside the card. */
.calc-card-panel > *:first-child { margin-top: 0 !important; }

/* Vertical option lists (Child-Pugh, ECOG …) — a vertical segmented control that
   matches the horizontal Unit/Sex toggles: a light track with pill options. */
.unit-btn-wrapper.flex-col {
    display: flex;
    flex-direction: column;
    gap: 4px;
    background: #f1f5f9;
    padding: 4px;
    border-radius: 14px;
    width: 100%;
}
.unit-btn-wrapper.flex-col .unit-btn {
    width: 100%;
    text-align: left;
    white-space: normal;
    background: transparent;
    border: none;
    border-radius: 11px;
    padding: 10px 14px;
    box-shadow: none;
    color: #475569;
}
.unit-btn-wrapper.flex-col .unit-btn.unit-btn-selected {
    background: #ffffff;
    color: #020617;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.08);
}

/* Checkbox / sentence labels must stay normal-case (not the uppercase caption). */
input[type="checkbox"] + .unit-title,
input[type="checkbox"] ~ .unit-title,
label.flex .unit-title {
    text-transform: none;
    letter-spacing: normal;
    font-size: 14px;
    font-weight: 500;
    color: #334155;
    margin: 0;
}
.calc-card-panel input[type="checkbox"] {
    width: 20px;
    height: 20px;
    accent-color: #312e81;
    flex: none;
}

/* Nested helper / info boxes — no border; differentiated from the grey panel by
   a white background. */
.calc-card-panel .bg-white:not(.unit-btn-wrapper) {
    background: #ffffff !important;
    border: none !important;
}
/* Drop the theme's grey borders on nested boxes/cycle rows inside the panel. */
.calc-card-panel [class*="border-gray"],
.calc-card-panel .cycle-row {
    border-color: transparent !important;
}

/* Native selects share the numeric-input box; keep the browser's native arrow
   (the theme's `.select-wrapper` already supplies one where used). */
.calc-card-panel select.unit-input {
    padding-right: 40px;
    cursor: pointer;
}

/* Give any remaining raw inputs/selects in the card the same field styling as
   `.unit-input` (e.g. the Cisplatin "Dosing History" cycle rows, which are
   injected from a <template> without the .unit-input class). */
.calc-card-panel .cycle-row input,
.calc-card-panel .cycle-row select {
    width: 100%;
    height: 48px;
    background: #ffffff;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    padding: 0 14px;
    font-size: 15px;
    font-weight: 500;
    color: #020617;
    outline: none;
}
.calc-card-panel .cycle-row input:focus,
.calc-card-panel .cycle-row select:focus {
    border-color: #312e81;
    box-shadow: 0 0 0 3px rgba(49, 46, 129, 0.12);
}
/* "+ Add Cycle" button — was black text on indigo. */
.calc-card-panel #add-cycle {
    background: #312e81;
    color: #ffffff;
    border-radius: 12px;
    font-weight: 600;
}
.calc-card-panel #add-cycle:hover { background: #272460; }

/* Keep nested boxes (dosing history, info panels) from overflowing on mobile. */
.calc-card-panel .grid { min-width: 0; }
.calc-card-panel .cycle-row .grid > div { min-width: 0; }
