/* ========== 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 (commit structure – one panel) ========== */
* { box-sizing: border-box; }

body {
    font-family: Arial, sans-serif;
    background-color: var(--bg-page);
    color: var(--text);
    margin: 0;
    padding: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 100vh;
}

.container {
    display: flex;
    flex-direction: row;
    background: var(--bg-shell);
    padding: 10px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    width: 95%;
    max-width: 1200px;
    border-radius: 10px;
    overflow: visible;
    padding-bottom: 20px;
}

.main-content {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
}

.history-panel {
    width: 220px;
    flex-shrink: 0;
    border-left: 1px solid var(--border);
    padding-left: 12px;
    margin-left: 12px;
    display: flex;
    flex-direction: column;
    max-height: 85vh;
}

.history-title {
    font-size: 1.1em;
    margin: 0 0 6px 0;
    color: var(--text);
}

.history-hint {
    font-size: 0.75em;
    color: var(--text-muted);
    margin: 0 0 10px 0;
    line-height: 1.3;
}

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

.history-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 4px;
    cursor: pointer;
    font-size: 0.9em;
    border-radius: 4px;
}

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

.history-item.is-selected {
    background: var(--hover);
    border-left: 3px solid var(--primary-color);
    padding-left: 6px;
    margin-left: -2px;
}

.history-item input[type="radio"] {
    cursor: pointer;
    flex-shrink: 0;
}

.history-item label {
    cursor: pointer;
    font-weight: normal;
    margin: 0;
    flex: 1;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

@media (min-width: 701px) and (max-height: 900px) {
    .container { transform: scale(0.95); transform-origin: center center; }
}
@media (min-width: 701px) and (max-height: 800px) {
    .container { transform: scale(0.85); transform-origin: center center; }
}
@media (max-width: 700px) {
    .container { flex-direction: column; }
    .history-panel { width: 100%; border-left: none; border-top: 1px solid var(--border); padding-left: 0; margin-left: 0; padding-top: 12px; margin-top: 12px; max-height: 280px; }
}

/* ========== INPUTS (one block, no extra panels) ========== */
.input-group {
    margin-bottom: 10px;
}

h1 {
    text-align: center;
    margin: 0 0 15px 0;
    font-size: 1.5em;
    color: var(--text);
    font-weight: bold;
}

label {
    font-weight: bold;
    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;
    height: 20px;
    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: 5px;
    margin-top: 10px;
}

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

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

.ffmi-horizontal {
    margin-bottom: 10px;
}

.ffmi-numbers-below {
    display: flex;
    justify-content: space-between;
    font-size: 0.8em;
    margin-top: 8px;
    margin-bottom: 5px;
    width: 100%;
    color: var(--text);
    padding: 0 2px;
}

.ffmi-numbers-below span {
    min-width: 20px;
    text-align: center;
}

.ffmi-labels-below {
    display: flex;
    justify-content: space-between;
    font-size: 0.9em;
    margin-top: 5px;
    padding-left: 10px;
    padding-right: 10px;
}

.ffmi-labels-below span {
    color: white;
    font-weight: bold;
    text-shadow: 1px 1px 2px rgba(0, 0, 0, 0.6);
}

.ffmi-indicator {
    position: absolute;
    width: 12px;
    height: 25px;
    background-color: rgba(255, 255, 255, 0.6);
    border: 2px solid var(--primary-color);
    border-radius: 5px;
    top: -5px;
    box-shadow: 0 0 5px rgba(0, 0, 0, 0.3);
}

#hipsSlider:disabled {
    opacity: 0.5;
}

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

/* ========== Select + number input ========== */
select {
    width: 100%;
    padding: 8px;
    border: 2px solid var(--primary-color);
    border-radius: 5px;
    background-color: var(--bg-card);
    color: var(--text);
    font-size: 0.9em;
    cursor: pointer;
    outline: none;
    transition: border-color 0.2s;
}

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

input[type="number"] {
    width: 100%;
    padding: 8px;
    border: 2px solid var(--primary-color);
    border-radius: 5px;
    background-color: var(--bg-card);
    color: var(--text);
    font-size: 0.9em;
    outline: none;
    transition: border-color 0.2s;
    box-sizing: border-box;
}

input[type="number"]:focus, input[type="number"]:hover {
    border-color: var(--primary-color);
}

input[type="number"]::placeholder {
    color: var(--text-muted);
}

/* ========== Results (single block styling) ========== */
.weeks-to-goal {
    color: var(--text-muted);
    font-size: 0.85em;
    font-style: italic;
    margin-left: 8px;
}

.ffmi-results,
.tdee-results {
    margin-top: 15px;
    padding: 10px;
    background-color: var(--bg-card);
    border-radius: 5px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.ffmi-results h2,
.tdee-results h2 {
    margin-top: 0;
    margin-bottom: 10px;
    font-size: 1.1em;
    color: var(--text);
}

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

.result-group p {
    margin: 0;
    font-size: 0.9em;
    color: var(--text);
    position: relative;
}

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

/* BMI badges (script uses .badge--good / .badge--warn / .badge--bad) */
#bmiCategory.badge {
    font-weight: bold;
    padding: 0 6px;
}
#bmiCategory.badge--good { color: #28a745; }
#bmiCategory.badge--warn { color: #d97706; }
#bmiCategory.badge--bad { color: #dc3545; }

/* Tooltips */
.result-group p strong.tooltip-trigger .tooltip-text {
    display: none;
    position: absolute;
    left: calc(100% + 10px);
    top: 0;
    padding: 8px 12px;
    background-color: var(--tooltip-bg);
    color: var(--tooltip-text);
    border-radius: 4px;
    font-size: 0.85em;
    font-weight: normal;
    white-space: normal;
    width: 250px;
    z-index: 1000;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.3);
    line-height: 1.4;
}

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

.result-group p strong.tooltip-trigger:hover .tooltip-text {
    display: block;
}

/* Focus for keyboard and tap-to-show on mobile */
.result-group p strong.tooltip-trigger:focus .tooltip-text,
.result-group p strong.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;
    }

    .main-content {
        width: 100%;
    }

    .inputs {
        width: 100%;
    }

    h1 {
        font-size: 1.35em;
        margin-bottom: 14px;
        padding-right: 44px; /* avoid overlap with theme toggle */
    }

    .input-group {
        margin-bottom: 14px;
    }

    .input-group > span:first-of-type,
    .input-group > span:last-of-type {
        font-size: 0.9em;
    }

    /* 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;
    }

    /* Prevent iOS zoom on focus – use 16px for inputs */
    input[type="number"],
    select {
        font-size: 16px;
        padding: 10px;
        min-height: 44px;
    }

    /* 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%;
        border-left: none;
        border-top: 1px solid var(--border);
        padding-left: 0;
        margin-left: 0;
        padding-top: 14px;
        margin-top: 14px;
        max-height: 240px;
        min-height: 120px;
    }

    .history-title {
        font-size: 1.05em;
    }

    .history-hint {
        font-size: 0.8em;
    }

    .history-item {
        padding: 10px 6px;
        font-size: 0.9em;
        min-height: 44px;
        box-sizing: border-box;
    }

    .ffmi-results,
    .tdee-results {
        margin-top: 14px;
        padding: 12px;
        border-radius: 8px;
    }

    .ffmi-results h2,
    .tdee-results h2 {
        font-size: 1.05em;
        margin-bottom: 10px;
    }

    .result-group p {
        font-size: 0.95em;
        line-height: 1.45;
    }

    /* Tooltips on mobile: show below, full width, tap to show */
    .result-group p {
        position: relative;
    }

    .result-group p strong.tooltip-trigger .tooltip-text {
        left: 0;
        right: auto;
        top: 100%;
        margin-top: 6px;
        width: 100%;
        max-width: 100%;
        box-sizing: border-box;
    }

    .result-group p strong.tooltip-trigger .tooltip-text::before {
        left: 12px;
        top: -6px;
        width: 0;
        height: 0;
        border-left: 6px solid transparent;
        border-right: 6px solid transparent;
        border-bottom: 6px solid var(--tooltip-bg);
        border-top: none;
    }

    .ffmi-scale {
        height: 18px;
        margin-top: 12px;
        border-radius: 6px;
    }

    .ffmi-indicator {
        width: 10px;
        height: 22px;
        top: -4px;
    }

    .ffmi-labels-below {
        font-size: 0.7em;
        padding-left: 2px;
        padding-right: 2px;
        margin-top: 4px;
    }

    .ffmi-labels-below span {
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
        max-width: 16%;
    }

    .ffmi-numbers-below {
        font-size: 0.7em;
        margin-top: 6px;
    }
}

/* 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;
    }
}
