/* ========== COLOR PALETTE (only change from commit) ========== */
:root {
    --primary-color: #4a90e2;
    --primary-color-light: #dbeaff;
    --slider-color: #4a90e2;
    --bg-page: #dbeaff;
    --bg-shell: #f7f7f7;
    --bg-card: #ffffff;
    --text: #222;
    --text-muted: #5a5a5a;
    --border: rgba(0, 0, 0, 0.12);
    --hover: rgba(0, 0, 0, 0.06);
    --tooltip-bg: #333;
    --tooltip-text: #fff;
}

body.female {
    --primary-color: #ff8ab8;
    --primary-color-light: #ffe4f0;
    --slider-color: #ff8ab8;
}

body.dark {
    --bg-page: #0b0f16;
    --bg-shell: #121826;
    --bg-card: #161f31;
    --text: #e9eef7;
    --text-muted: #a7b4cc;
    --border: rgba(255, 255, 255, 0.1);
    --hover: rgba(255, 255, 255, 0.06);
    --tooltip-bg: #1a2332;
    --tooltip-text: #e9eef7;
}

/* ========== LAYOUT ========== */
* { box-sizing: border-box; }

[hidden] { display: none !important; }

body {
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
    background-color: var(--bg-page);
    color: var(--text);
    margin: 0;
    padding: 24px 20px;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    line-height: 1.45;
}

.container {
    display: grid;
    grid-template-columns: minmax(0, 1fr) 240px;
    grid-template-rows: auto auto;
    align-items: start;
    gap: 14px 16px;
    width: 100%;
    max-width: 1100px;
}

.app-header {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4px 44px 0 0;
}

.content-column {
    grid-column: 1;
    grid-row: 2;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 16px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

body.dark .card {
    box-shadow: 0 2px 16px rgba(0, 0, 0, 0.25);
}

h1 {
    margin: 0 0 4px 0;
    font-size: 1.55em;
    font-weight: 700;
    color: var(--text);
    letter-spacing: -0.02em;
}

.app-subtitle {
    margin: 0;
    font-size: 0.9em;
    color: var(--text-muted);
}

.section-title {
    margin: 0 0 14px 0;
    font-size: 0.8em;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
}

/* ========== SETTINGS TOGGLES ========== */
.settings-card {
    padding: 12px 16px;
}

.toggle-row {
    display: flex;
    flex-wrap: wrap;
    gap: 16px 24px;
    justify-content: center;
}

.toggle-group {
    display: flex;
    align-items: center;
    gap: 10px;
}

.toggle-label {
    font-size: 0.88em;
    font-weight: 600;
    color: var(--text-muted);
}

/* ========== MEASUREMENT FIELDS ========== */
.measurements-card {
    display: flex;
    flex-direction: column;
    gap: 14px;
}

.measure-field {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.measure-field__row {
    display: grid;
    grid-template-columns: 1fr auto auto;
    align-items: center;
    gap: 10px;
}

.measure-field__row label {
    font-weight: 600;
    font-size: 0.92em;
    color: var(--text);
    margin: 0;
}

.unit-hint {
    font-weight: 500;
    color: var(--text-muted);
    font-size: 0.9em;
}

.measure-field__formatted {
    font-size: 0.9em;
    font-weight: 600;
    color: var(--primary-color);
    white-space: nowrap;
}

.measure-field__formatted--secondary {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
}

.measure-input-group {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-shell);
    border: 1.5px solid var(--border);
    border-radius: 8px;
    padding: 4px 10px;
    min-width: 108px;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.measure-input-group:focus-within {
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px var(--primary-color-light);
}

body.dark .measure-input-group:focus-within {
    box-shadow: 0 0 0 3px rgba(74, 144, 226, 0.2);
}

.measure-input-group--solo {
    grid-column: 2 / -1;
    justify-self: end;
}

.measure-input {
    width: 72px;
    border: none;
    background: transparent;
    color: var(--text);
    font-size: 0.95em;
    font-weight: 600;
    padding: 6px 0;
    outline: none;
    text-align: right;
    -moz-appearance: textfield;
}

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

.measure-input:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.measure-input-unit {
    font-size: 0.78em;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: lowercase;
    min-width: 24px;
}

.measure-field--select {
    gap: 8px;
}

.measure-field--select label {
    font-weight: 600;
    font-size: 0.92em;
}

.measure-select,
select {
    width: 100%;
    padding: 10px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background-color: var(--bg-shell);
    color: var(--text);
    font-size: 0.9em;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

.measure-select:focus,
.measure-select:hover,
select:focus,
select:hover {
    border-color: var(--primary-color);
}

.measure-field--select .measure-input-group--solo {
    width: 100%;
    max-width: 160px;
}

#goalWeightInput.measure-input {
    width: 88px;
}

.history-panel {
    grid-column: 2;
    grid-row: 2;
    width: 240px;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    max-height: calc(100vh - 48px);
    margin: 0;
    align-self: start;
    position: sticky;
    top: 24px;
}

.history-title {
    margin-bottom: 4px;
}

.history-hint {
    font-size: 0.78em;
    color: var(--text-muted);
    margin: 0 0 12px 0;
    line-height: 1.4;
}

.history-list {
    overflow-y: auto;
    overflow-x: hidden;
    flex: 1;
    min-height: 80px;
    margin: 0 -4px;
    padding: 0 4px;
}

.history-item {
    display: grid;
    grid-template-columns: 18px 1fr;
    align-items: center;
    gap: 10px;
    padding: 9px 8px;
    margin-bottom: 2px;
    cursor: pointer;
    font-size: 0.875rem;
    border-radius: 8px;
    border-left: 3px solid transparent;
    transition: background 0.15s, border-color 0.15s;
    line-height: 1.3;
}

.history-item:hover {
    background: var(--hover);
}

.history-item.is-selected {
    background: var(--primary-color-light);
    border-left-color: var(--primary-color);
    padding-left: 5px;
}

body.dark .history-item.is-selected {
    background: var(--hover);
}

.history-item__radio {
    margin: 0;
    width: 16px;
    height: 16px;
    cursor: pointer;
    flex-shrink: 0;
    accent-color: var(--primary-color);
    justify-self: center;
}

.history-item__label {
    display: block;
    cursor: pointer;
    font-weight: 500;
    margin: 0;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    min-width: 0;
}

@media (max-width: 640px) {
    .results-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}
@media (max-width: 700px) {
    .container {
        grid-template-columns: 1fr;
        grid-template-rows: auto;
    }

    .app-header {
        grid-column: 1;
    }

    .content-column {
        grid-column: 1;
        grid-row: auto;
    }

    .history-panel {
        grid-column: 1;
        grid-row: auto;
        width: 100%;
        max-height: 240px;
        position: static;
    }
    .measure-field__row {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .measure-input-group,
    .measure-input-group--solo {
        justify-self: stretch;
        width: 100%;
        max-width: none;
    }
    .measure-input {
        flex: 1;
        width: auto;
    }
}

label {
    font-weight: 600;
    font-size: 0.9em;
    color: var(--text);
}

.slider-container {
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
}

/* Pill buttons = circles, 28×28 (commit sizing) */
.slider-btn {
    background-color: transparent;
    color: var(--primary-color);
    border: 1.5px solid var(--primary-color);
    border-radius: 50%;
    width: 28px;
    height: 28px;
    font-size: 18px;
    font-weight: 300;
    line-height: 1;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.2s ease;
    user-select: none;
    padding: 0;
    margin: 0;
}

.slider-btn:hover {
    background-color: var(--primary-color);
    color: white;
    transform: scale(1.05);
}

.slider-btn:active {
    transform: scale(0.95);
    background-color: var(--primary-color);
    color: white;
}

.slider-btn:disabled {
    opacity: 0.3;
    cursor: not-allowed;
    border-color: var(--text-muted);
    color: var(--text-muted);
}

.slider-btn:disabled:hover {
    background-color: transparent;
    transform: none;
}

.slider-container input[type="range"] {
    flex: 1;
    -webkit-appearance: none;
    appearance: none;
    height: 6px;
    border-radius: 5px;
    background: var(--slider-color);
    outline: none;
}

input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 20px;
    height: 20px;
    background: var(--bg-card);
    border-radius: 50%;
    border: 2px solid var(--primary-color);
    cursor: pointer;
}

input[type="range"]::-moz-range-thumb {
    width: 20px;
    height: 20px;
    background: var(--bg-card);
    border-radius: 50%;
    border: 2px solid var(--primary-color);
    cursor: pointer;
}

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

/* Toggle switch */
.switch {
    position: relative;
    display: inline-block;
    width: 45px;
    height: 24px;
}

.switch input {
    opacity: 0;
    width: 0;
    height: 0;
}

.slider.round {
    border-radius: 24px;
}

.switch .slider {
    position: absolute;
    cursor: pointer;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background-color: var(--primary-color);
    transition: 0.4s;
    border-radius: 24px;
}

.switch .slider:before {
    position: absolute;
    content: "";
    height: 20px;
    width: 20px;
    left: 2px;
    bottom: 2px;
    background-color: var(--bg-card);
    transition: 0.4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--primary-color);
}

input:checked + .slider:before {
    transform: translateX(22px);
}

/* ========== Theme toggle + dark checkbox ========== */
.theme-toggle {
    position: fixed;
    top: 12px;
    right: 12px;
    z-index: 1000;
    width: 40px;
    height: 40px;
    padding: 0;
    border: none;
    border-radius: 50%;
    background: var(--bg-card);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.2em;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
}

.theme-toggle:hover {
    color: var(--primary-color);
}

.dark-mode-checkbox {
    position: absolute;
    opacity: 0;
    pointer-events: none;
    width: 0;
    height: 0;
}

body.dark .theme-icon-sun { display: none !important; }
body.dark .theme-icon-moon { display: inline !important; }
body.dark .theme-icon-moon[hidden] { display: inline !important; }
body:not(.dark) .theme-icon-moon { display: none !important; }

/* ========== FFMI scale ========== */
.ffmi-scale {
    position: relative;
    width: 100%;
    padding-top: 14px;
    margin-top: 4px;
}

.ffmi-scale[aria-hidden="true"] {
    display: none;
}

.ffmi-scale[aria-hidden="false"] {
    display: block;
}

.ffmi-scale__track {
    position: relative;
    height: 26px;
    width: 100%;
    background: linear-gradient(to right,
        rgba(211, 211, 211, 0.8),
        rgba(0, 128, 128, 0.8),
        rgba(255, 165, 0, 0.8),
        rgba(218, 165, 32, 0.8),
        rgba(220, 20, 60, 0.8),
        rgba(0, 0, 139, 0.8)
    );
    border-radius: 6px;
    overflow: visible;
}

.ffmi-horizontal {
    margin-bottom: 0;
}

.ffmi-labels-below {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.62em;
    padding: 0 6px;
    pointer-events: none;
}

.ffmi-labels-below span {
    color: white;
    font-weight: 700;
    text-shadow: 0 1px 2px rgba(0, 0, 0, 0.75);
    text-align: center;
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    line-height: 1.2;
}

.ffmi-numbers-below {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 0;
    width: 100%;
    margin-top: 10px;
    padding: 0 1px 2px;
    color: var(--text-muted);
    font-size: 0.72em;
    font-weight: 600;
    line-height: 1.2;
}

.ffmi-numbers-below span {
    flex: 1 1 0;
    min-width: 0;
    text-align: center;
}

/* Downward caret — sits above the bar, tip touches top edge */
.ffmi-indicator {
    position: absolute;
    top: -13px;
    left: 0;
    width: 0;
    height: 0;
    border-left: 9px solid transparent;
    border-right: 9px solid transparent;
    border-top: 13px solid var(--primary-color);
    transform: translateX(-50%);
    filter: drop-shadow(0 1px 2px rgba(0, 0, 0, 0.35));
    z-index: 2;
    pointer-events: none;
    transition: left 0.15s ease;
}

body.dark .ffmi-indicator {
    border-top-color: var(--primary-color);
    filter: drop-shadow(0 1px 3px rgba(0, 0, 0, 0.6));
}

#hipsSlider:disabled,
#hipsInput:disabled {
    opacity: 0.5;
}

.grayed-out {
    opacity: 0.55;
    pointer-events: none;
}

/* ========== RESULTS ========== */
.results-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

.results-card {
    margin: 0;
}

.weeks-to-goal {
    color: var(--text-muted);
    font-size: 0.8em;
    font-style: italic;
    margin-left: 4px;
    display: block;
    margin-top: 2px;
}

.bmr-floor-warning {
    display: block;
    font-size: 0.78em;
    font-weight: 600;
    color: var(--text-muted);
    margin-top: 2px;
}

.bmr-floor-warning--high,
.weight-loss-cal--below-floor {
    color: #dc3545;
}

body.dark .bmr-floor-warning--high,
body.dark .weight-loss-cal--below-floor {
    color: #f87171;
}

.result-group {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.result-item {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 12px;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
    position: relative;
}

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

.result-label {
    font-size: 0.88em;
    color: var(--text-muted);
    font-weight: 500;
}

.result-value {
    font-size: 0.95em;
    font-weight: 700;
    color: var(--text);
    text-align: right;
}

.result-unit {
    font-size: 0.82em;
    font-weight: 500;
    color: var(--text-muted);
}

.tooltip-trigger {
    cursor: help;
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 2px;
}

#bmiCategory.badge {
    font-weight: 700;
    font-size: 0.88em;
    padding: 0 4px;
}
#bmiCategory.badge--good { color: #28a745; }
#bmiCategory.badge--warn { color: #d97706; }
#bmiCategory.badge--bad { color: #dc3545; }

.ffmi-scale-card {
    padding-bottom: 16px;
    overflow: visible;
}

.ffmi-horizontal {
    margin: 0;
}

/* Tooltips */
.tooltip-trigger .tooltip-text {
    display: none;
    position: absolute;
    right: 0;
    top: 100%;
    margin-top: 6px;
    padding: 8px 12px;
    background-color: var(--tooltip-bg);
    color: var(--tooltip-text);
    border-radius: 6px;
    font-size: 0.82em;
    font-weight: normal;
    white-space: normal;
    width: 240px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    line-height: 1.4;
    text-align: left;
    text-decoration: none;
}

.tooltip-trigger .tooltip-text::before {
    content: '';
    position: absolute;
    right: 16px;
    top: -6px;
    width: 0;
    height: 0;
    border-left: 6px solid transparent;
    border-right: 6px solid transparent;
    border-bottom: 6px solid var(--tooltip-bg);
}

.tooltip-trigger:hover .tooltip-text,
.tooltip-trigger:focus .tooltip-text,
.tooltip-trigger:focus-within .tooltip-text {
    display: block;
}

/* ========== MOBILE-SPECIFIC STYLES ========== */
@media (max-width: 600px) {
    body {
        padding: 12px 10px;
        padding-top: max(12px, env(safe-area-inset-top));
        padding-bottom: max(12px, env(safe-area-inset-bottom));
        padding-left: max(10px, env(safe-area-inset-left));
        padding-right: max(10px, env(safe-area-inset-right));
        align-items: flex-start;
        min-height: 100vh;
        min-height: 100dvh;
    }

    .container {
        width: 100%;
        max-width: none;
        padding: 12px;
        padding-bottom: 20px;
        border-radius: 12px;
        transform: none;
    }

    .content-column {
        width: 100%;
    }

    h1 {
        font-size: 1.35em;
        padding-right: 44px;
    }

    .app-subtitle {
        font-size: 0.85em;
    }

    .card {
        padding: 14px;
    }

    .toggle-row {
        gap: 12px 20px;
    }

    /* Touch-friendly slider buttons (min 44px) */
    .slider-btn {
        width: 40px;
        height: 40px;
        font-size: 20px;
    }

    .slider-container input[type="range"] {
        height: 8px;
    }

    input[type="range"]::-webkit-slider-thumb {
        width: 24px;
        height: 24px;
    }

    input[type="range"]::-moz-range-thumb {
        width: 24px;
        height: 24px;
    }

    input[type="number"],
    .measure-input,
    select,
    .measure-select {
        font-size: 16px;
        min-height: 40px;
    }

    .measure-input-group {
        min-height: 44px;
        padding: 6px 12px;
    }

    /* Switches remain easy to tap */
    .switch {
        width: 48px;
        height: 26px;
    }

    .switch .slider:before {
        height: 22px;
        width: 22px;
    }

    input:checked + .slider:before {
        transform: translateX(24px);
    }

    .theme-toggle {
        top: max(10px, env(safe-area-inset-top));
        right: max(10px, env(safe-area-inset-right));
        width: 44px;
        height: 44px;
        font-size: 1.25em;
    }

    .history-panel {
        width: 100%;
        max-height: 240px;
        position: static;
    }

    .history-item {
        padding: 11px 10px;
    }

    .results-grid {
        grid-template-columns: 1fr;
    }

    .result-item {
        flex-direction: column;
        gap: 4px;
    }

    .result-value {
        text-align: left;
    }

    .tooltip-trigger .tooltip-text {
        left: 0;
        right: auto;
        width: 100%;
        max-width: 100%;
    }

    .ffmi-scale {
        padding-top: 12px;
    }

    .ffmi-scale__track {
        height: 28px;
    }

    .ffmi-indicator {
        top: -11px;
        border-left-width: 8px;
        border-right-width: 8px;
        border-top-width: 11px;
    }

    .ffmi-labels-below {
        font-size: 0.58em;
        padding: 0 4px;
    }

    .ffmi-numbers-below {
        font-size: 0.65em;
        margin-top: 8px;
        padding-bottom: 4px;
    }
}

#calculatorPanel {
    display: flex;
    flex-direction: column;
    gap: 14px;
    min-width: 0;
}

.profile-card {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.profile-row {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    align-items: center;
}

.profile-row label {
    margin: 0;
}

.profile-card .measure-select {
    flex: 1;
    min-width: 140px;
}

#unlockRow,
#createRow {
    flex-direction: column;
    align-items: stretch;
}

#unlockRow .profile-input,
#createRow .profile-input,
#unlockRow .profile-btn,
#createRow .profile-btn {
    flex: none;
    width: 100%;
    min-width: 0;
}

.profile-input {
    flex: 1;
    min-width: 120px;
    min-height: 44px;
    padding: 8px 12px;
    border: 1.5px solid var(--border);
    border-radius: 8px;
    background: var(--bg-shell);
    color: var(--text);
    font-size: 16px;
}

.profile-btn {
    min-height: 44px;
    padding: 0 16px;
    border: none;
    border-radius: 8px;
    background: var(--primary-color);
    color: #fff;
    font-weight: 700;
    cursor: pointer;
}

.profile-status {
    margin: 0;
    font-size: 0.85em;
    color: var(--text-muted);
}

.view-tabs {
    display: flex;
    gap: 6px;
    padding: 6px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 2px 12px rgba(0, 0, 0, 0.06);
}

.view-tab {
    flex: 1;
    min-height: 48px;
    border-radius: 10px;
    border: 2px solid transparent;
    background: transparent;
    color: var(--text-muted);
    font: inherit;
    font-weight: 700;
    cursor: pointer;
}

.view-tab.is-active {
    background: var(--primary-color);
    border-color: var(--primary-color);
    color: #fff;
    box-shadow: 0 2px 8px rgba(74, 144, 226, 0.35);
}

.view-tab:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

.view-banner {
    margin: 0;
    padding: 10px 12px;
    border-radius: 10px;
    background: var(--primary-color-light);
    color: var(--text);
    font-size: 0.9em;
    font-weight: 600;
}

body.dark .view-banner {
    background: rgba(74, 144, 226, 0.18);
}

.profile-warning {
    margin: 0;
    padding: 10px 12px;
    border-radius: 10px;
    border: 1px solid #e0a84a;
    background: #fff6e4;
    color: #6b4a10;
    font-size: 0.92em;
    font-weight: 700;
    line-height: 1.4;
}

body.dark .profile-warning {
    background: rgba(224, 168, 74, 0.16);
    border-color: rgba(224, 168, 74, 0.55);
    color: #f3d19a;
}

.profile-local {
    margin: 0;
    color: var(--text-muted);
    font-size: 0.9em;
}

body.is-viewing .measurements-card,
body.is-viewing .settings-card {
    opacity: 0.72;
}

.chart-hint {
    margin: 0 0 10px 0;
    color: var(--text-muted);
    font-size: 0.82em;
    line-height: 1.4;
}

.chart-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 0 0 10px 0;
}

.chart-key {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    min-height: 40px;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1.5px solid var(--border);
    background: var(--bg-shell);
    color: var(--text);
    font: inherit;
    font-size: 0.82em;
    font-weight: 600;
    cursor: pointer;
}

.chart-key::before {
    content: '';
    width: 16px;
    height: 3px;
    border-radius: 2px;
    background: var(--line, var(--primary-color));
    flex-shrink: 0;
}

.chart-key.is-off {
    opacity: 0.45;
}

.chart-key.is-off::before {
    height: 8px;
    background: transparent;
    border: 2px solid var(--line, var(--primary-color));
}

.progress-chart svg {
    width: 100%;
    height: auto;
    display: block;
}

.chart-line {
    fill: none;
    stroke-width: 2.5;
    stroke-linejoin: round;
    stroke-linecap: round;
}

.chart-axis { stroke: var(--border); stroke-width: 1; }
.chart-label { fill: var(--text-muted); font-size: 12px; font-family: system-ui, sans-serif; }

.progress-empty {
    margin: 8px 0 0 0;
    color: var(--text-muted);
    font-size: 0.9em;
}

/* Narrow phones – tighten further */
@media (max-width: 380px) {
    body {
        padding: 10px 8px;
    }

    .container {
        padding: 10px;
    }

    h1 {
        font-size: 1.2em;
    }

    .ffmi-labels-below span {
        font-size: 0.65em;
    }

    .view-tab {
        font-size: 0.88em;
        min-height: 44px;
        padding: 0 4px;
    }
}

/* The page stays inside the window. History scrolls inside its own list. */
html,
body {
    height: 100%;
}

body {
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
    padding: 8px 12px;
    flex-direction: column;
    align-items: center;
}

.container {
    flex: 1 1 auto;
    width: 100%;
    height: auto;
    min-height: 0;
    max-height: 100%;
    overflow: hidden;
    gap: 8px 12px;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto auto minmax(0, 1fr);
    padding: 0;
    transform: none;
}

.app-header { grid-row: 1; }
.history-panel { grid-row: 2; }
.content-column { grid-row: 3; }

.container:has(.history-panel[hidden]) {
    grid-template-rows: auto minmax(0, 1fr);
}

.container:has(.history-panel[hidden]) .content-column {
    grid-row: 2;
}

.app-header {
    padding: 0 40px 0 0;
}

h1 {
    font-size: 1.25em;
    line-height: 1.15;
}

.app-subtitle {
    font-size: 0.78em;
    line-height: 1.2;
}

.content-column {
    min-height: 0;
    height: 100%;
    overflow: hidden;
    gap: 8px;
}

.view-tabs {
    flex-shrink: 0;
    padding: 3px;
}

.view-tab {
    min-height: 36px;
}

.card {
    padding: 8px 10px;
}

.section-title {
    margin: 0 0 6px 0;
    font-size: 0.875rem;
    letter-spacing: 0.02em;
    color: #2c2c2c;
}

body.dark .section-title {
    color: #e6edf7;
}

#calculatorPanel,
#progressPanel {
    flex: 1 1 auto;
    min-height: 0;
    overflow: hidden;
}

#profilePanel {
    flex: 0 1 auto;
    min-height: 0;
    overflow: hidden;
}

#calculatorPanel {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    gap: 8px;
    overflow: auto;
}

.settings-card {
    flex-shrink: 0;
    padding: 6px 10px;
}

.toggle-row {
    gap: 8px 16px;
}

.calc-main {
    flex: 0 0 auto;
    min-height: min-content;
    display: flex;
    flex-direction: column;
    gap: 8px;
    overflow: visible;
}

.calc-side {
    display: contents;
}

.results-grid {
    order: 1;
}

.ffmi-scale-card {
    order: 2;
}

.measurements-card {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    gap: 8px 18px;
    align-content: start;
    height: auto;
    min-height: min-content;
    overflow: visible;
    flex-shrink: 0;
    padding: 10px 12px;
}

.measurements-card > .section-title,
.measurements-card > .measure-field--select {
    grid-column: 1 / -1;
}

.measure-field {
    flex: none;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    min-height: 36px;
    min-width: 0;
    max-width: 100%;
}

.measure-field__row {
    display: contents;
}

.measure-field label {
    flex: 0 0 7.4em;
    width: 7.4em;
    font-size: 0.9375rem;
    line-height: 1.25;
    color: var(--text);
}

.measure-field__formatted {
    flex: 0 0 auto;
    font-size: 0.75em;
}

.measure-input-group {
    flex: 0 0 auto;
    min-width: 0;
    padding: 1px 6px;
}

.measure-input {
    width: 4.6em;
    padding: 2px 0;
    font-size: 1rem;
}

#goalWeightInput.measure-input {
    width: 64px;
}

.slider-container {
    flex: 1 1 8rem;
    min-width: 0;
    max-width: 14rem;
}

.slider-btn {
    width: 22px;
    height: 22px;
    font-size: 15px;
}

.measure-field--select .measure-select {
    flex: 1 1 auto;
    width: auto;
    min-width: 0;
    padding: 4px 8px;
}

.results-grid {
    flex: 0 0 auto;
    height: auto;
    min-height: min-content;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: none;
    grid-auto-rows: min-content;
    align-items: start;
    align-content: start;
    gap: 8px;
}

.results-card {
    min-height: min-content;
    height: auto;
    overflow: visible;
    flex-shrink: 0;
    display: flex;
    flex-direction: column;
    padding: 10px 14px 8px;
}

.results-card .section-title {
    margin-bottom: 2px;
}

.result-group {
    flex: 0 0 auto;
    width: 100%;
    max-width: 26rem;
    min-height: min-content;
    gap: 0;
    justify-content: flex-start;
}

.result-item {
    display: flex;
    flex-direction: column;
    align-items: stretch;
    gap: 2px;
    padding: 7px 0;
    border-bottom: 1px solid var(--border);
    min-height: 0;
}

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

.result-item__main {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    align-items: baseline;
    column-gap: 0.75rem;
    width: 100%;
    min-width: 0;
}

.result-label,
.result-value {
    font-size: 1rem;
    line-height: 1.35;
}

.result-value {
    font-size: 1.0625rem;
}

.result-label {
    min-width: 0;
    color: var(--text);
    font-weight: 600;
    white-space: normal;
}

.result-value {
    font-variant-numeric: tabular-nums;
    font-weight: 700;
    white-space: nowrap;
    text-align: right;
    justify-self: end;
    flex-shrink: 0;
}

.weeks-to-goal,
.bmr-floor-warning {
    display: block;
    margin: 0;
    white-space: normal;
}

.weeks-to-goal:empty,
.bmr-floor-warning:empty {
    display: none;
}

.weeks-to-goal {
    color: var(--text-muted);
    font-size: 0.8125rem;
    font-style: normal;
    font-weight: 500;
}

.bmr-floor-warning--high {
    margin-top: 2px;
    padding: 3px 8px;
    border-radius: 6px;
    border-left: 3px solid #7f1d1d;
    background: #fde8e8;
    color: #6b1212;
    font-size: 0.8125rem;
    font-weight: 700;
    line-height: 1.35;
}

.weight-loss-cal--below-floor {
    color: #7f1d1d;
}

body.dark .weight-loss-cal--below-floor {
    color: #fecaca;
}

body.dark .bmr-floor-warning--high {
    background: #fde8e8;
    color: #6b1212;
}

#bmiCategory.badge:empty {
    display: none;
}

#bmiCategory.badge {
    display: inline-block;
    margin-right: 6px;
    padding: 1px 6px;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 700;
    line-height: 1.4;
    vertical-align: 1px;
}

#bmiCategory.badge--good {
    color: #14532d;
    background: #dcfce7;
}

#bmiCategory.badge--warn {
    color: #7a3e00;
    background: #fef3c7;
}

#bmiCategory.badge--bad {
    color: #7f1d1d;
    background: #fee2e2;
}

.ffmi-scale-card {
    flex-shrink: 0;
    padding: 6px 10px 6px;
}

.ffmi-scale {
    padding-top: 10px;
    margin-top: 0;
}

.ffmi-scale__track {
    height: 20px;
}

.ffmi-indicator {
    top: -10px;
    border-left-width: 7px;
    border-right-width: 7px;
    border-top-width: 10px;
}

.ffmi-numbers-below {
    margin-top: 4px;
    font-size: 0.8125rem;
}

.ffmi-labels-below {
    font-size: 0.75rem;
    padding: 0 2px;
}

.tooltip-trigger {
    text-decoration: none;
}

.tooltip-trigger:hover,
.tooltip-trigger:focus-visible {
    text-decoration: underline;
    text-decoration-style: dotted;
    text-underline-offset: 3px;
}

.history-panel {
    width: 100%;
    height: auto;
    max-height: none;
    min-height: 0;
    align-self: stretch;
    position: static;
    flex-direction: row;
    align-items: center;
    gap: 8px;
    padding: 4px 10px;
}

.history-title {
    margin: 0;
    flex-shrink: 0;
}

.history-hint {
    display: none;
}

.history-list {
    display: flex;
    flex-direction: row;
    align-items: center;
    overflow-x: auto;
    overflow-y: hidden;
    min-height: 0;
    gap: 4px;
    margin: 0;
    padding: 0;
}

.history-item {
    width: auto;
    margin: 0;
    padding: 4px 8px;
    white-space: nowrap;
}

.history-item__label {
    white-space: nowrap;
}

.history-list {
    min-height: 0;
}

.view-banner {
    flex-shrink: 0;
    padding: 6px 10px;
}

#progressPanel {
    display: flex;
    flex-direction: column;
}

.chart-hint {
    flex-shrink: 0;
}

.chart-legend {
    flex-shrink: 0;
    margin-bottom: 6px;
}

.progress-chart {
    flex: 1 1 auto;
    min-height: 0;
}

.progress-chart svg {
    width: 100%;
    height: 100%;
}

@media (max-width: 860px) {
    .container {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: auto auto minmax(0, 1fr);
    }

    .app-header,
    .history-panel,
    .content-column {
        grid-column: 1;
    }

    .app-header { grid-row: 1; }
    .history-panel { grid-row: 2; }
    .content-column { grid-row: 3; }

    .history-panel {
        width: 100%;
        height: auto;
        flex-direction: row;
        align-items: center;
        gap: 8px;
        padding: 4px 8px;
    }

    .history-title {
        margin: 0;
        flex-shrink: 0;
    }

    .history-hint {
        display: none;
    }

    .history-list {
        display: flex;
        flex-direction: row;
        align-items: center;
        overflow-x: auto;
        overflow-y: hidden;
        gap: 4px;
        margin: 0;
        padding: 0;
    }

    .history-item {
        width: auto;
        margin: 0;
        padding: 4px 8px;
        white-space: nowrap;
    }

    .history-item__label {
        white-space: nowrap;
    }

    .measurements-card {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (min-width: 760px) {
    .calc-main {
        display: grid;
        grid-template-columns: minmax(0, 1.25fr) minmax(18.5rem, 0.75fr);
        align-items: start;
        gap: 8px;
    }

    .calc-side {
        display: flex;
        flex-direction: column;
        gap: 8px;
        align-self: start;
        min-width: 0;
    }

    .results-grid,
    .ffmi-scale-card {
        order: 0;
    }

    .measurements-card,
    .results-grid {
        grid-template-columns: minmax(0, 1fr);
    }
}

@media (min-width: 641px) and (max-width: 759px) {
    .results-grid {
        grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    }
}

@media (max-height: 720px) {
    body {
        padding-top: 4px;
        padding-bottom: 4px;
    }

    .app-subtitle {
        display: none;
    }

    h1 {
        font-size: 1.1em;
    }

    .ffmi-scale {
        padding-top: 8px;
    }

    .ffmi-numbers-below {
        margin-top: 2px;
    }
}

@media (max-width: 600px) {
    body {
        padding: 6px 8px;
        min-height: 0;
        overflow: hidden;
    }

    .slider-btn {
        width: 22px;
        height: 22px;
        font-size: 14px;
    }

    .slider-container input[type="range"] {
        height: 6px;
    }

    input[type="range"]::-webkit-slider-thumb,
    input[type="range"]::-moz-range-thumb {
        width: 16px;
        height: 16px;
    }

    .measure-input,
    .measure-select,
    select {
        font-size: 16px;
        min-height: 0;
    }

    .measure-input-group {
        min-height: 0;
        padding: 1px 6px;
    }

    .view-tab {
        min-height: 34px;
        font-size: 0.82em;
    }

    .measure-field {
        flex-wrap: wrap;
        row-gap: 4px;
        align-items: center;
    }

    .measure-input-group {
        width: auto;
        flex: 0 0 auto;
    }

    .measure-input {
        flex: 0 0 auto;
        width: 4.6em;
    }

    .slider-container {
        flex: 1 1 100%;
        max-width: none;
    }

    h1 {
        font-size: 1.05em;
    }

    .app-header {
        padding-right: 44px;
    }
}
