/* ===== CSS VARIABLES ===== */
:root {
    --green:        #00966b;
    --green-hover:  #007d58;
    --teal:         #084c61;
    --text:         #4a5568;
    --muted:        #64748b;
    --bg:           #f7fafc;
    --white:        #ffffff;
    --red:          #e53e3e;
    --red-bg:       #fff5f5;
    --green-bg:     #f0fff4;
    --border:       #e2e8f0;
    --shadow:       0 8px 24px rgba(0,0,0,0.06);
    --radius:       14px;
    --radius-sm:    10px;
    --ease:         cubic-bezier(0.4, 0, 0.2, 1);

    /* Shake vars */
    --shake-distance:  6px;
    --shake-overshoot: 4px;
    --shake-dur-a:     80ms;
    --shake-dur-b:     60ms;
    --shake-ease:      cubic-bezier(0.22, 1, 0.36, 1);
    --revert-dur:      280ms;
}

/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html {
    min-height: 100%;
}
body {
    font-family: 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    padding: 120px 0 0;
}

/* ===== LAYOUT ===== */
.calculator-container {
    max-width: 900px;
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 24px;
    flex: 1;
    margin-bottom: 0;
    margin-top: 32px;
}
@media (max-width: 720px) {
    .calculator-container { grid-template-columns: 1fr; }
}

footer.footer {
    width: 100%;
    margin-top: 40px;
    flex-shrink: 0;
}

/* ===== CARDS ===== */
section {
    background: var(--white);
    border-radius: var(--radius);
    padding: 28px;
    box-shadow: var(--shadow);
    /* Subtle entrance animation */
    animation: cardIn 0.4s var(--ease) both;
}
section.calculator-card { animation-delay: 0.08s; }

@keyframes cardIn {
    from { opacity: 0; transform: translateY(12px); }
    to   { opacity: 1; transform: translateY(0); }
}

h2 {
    color: var(--teal);
    font-size: 1.45rem;
    font-weight: 700;
    margin-bottom: 12px;
    line-height: 1.3;
}

.subtitle {
    font-size: 0.9rem;
    color: var(--muted);
    margin-bottom: 22px;
}

/* ===== EDUCATION PANEL SWITCHING ===== */
.edu-panel {
    display: none;
    animation: eduFadeIn 0.35s var(--ease);
}
.edu-panel.active {
    display: block;
}
@keyframes eduFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ===== EDUCATION CARD ===== */
.education-card p {
    font-size: 0.92rem;
    line-height: 1.65;
    color: var(--text);
    margin-bottom: 16px;
}

.formula-box {
    background: #f7fafc;
    border-left: 4px solid var(--green);
    border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
    padding: 14px 16px;
    margin-bottom: 14px;
}

.formula-title {
    font-size: 0.82rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--green);
    margin-bottom: 10px;
}

.formula-box ul { list-style: none; display: flex; flex-direction: column; gap: 7px; }
.formula-box li {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    font-size: 0.88rem;
    gap: 8px;
}
.formula-label { color: var(--teal); font-weight: 600; flex-shrink: 0; }
.formula-value { color: var(--muted); text-align: right; }
.formula-value em { font-style: normal; font-size: 0.8rem; color: #94a3b8; }

.disclaimer { font-size: 0.76rem; color: #b0bec5; font-style: italic; }

/* ===== TABS ===== */
.form-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 24px;
    border-bottom: 2px solid var(--border);
}

.tab-btn {
    flex: 1;
    padding: 11px 12px;
    background: transparent;
    border: none;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    font-size: 0.88rem;
    font-weight: 600;
    color: var(--muted);
    cursor: pointer;
    transition: color 0.2s var(--ease), border-color 0.2s var(--ease);
}
.tab-btn:hover { color: var(--green); }
.tab-btn.active { color: var(--green); border-bottom-color: var(--green); }

.tab-content { display: none; flex-direction: column; gap: 0; }
.tab-content.active {
    display: flex;
    animation: fadeSlideIn 0.25s var(--ease);
}
@keyframes fadeSlideIn {
    from { opacity: 0; transform: translateY(5px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* ===== FORM ===== */
.form-group {
    display: flex;
    flex-direction: column;
    margin-bottom: 16px;
}
.form-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 14px;
}

label {
    font-size: 0.82rem;
    font-weight: 700;
    color: var(--teal);
    margin-bottom: 7px;
    letter-spacing: 0.01em;
}
.unit-label {
    font-weight: 500;
    font-size: 0.78rem;
    color: var(--muted);
    margin-left: 4px;
}

input[type="number"],
input[type="text"],
select {
    height: 46px;
    padding: 0 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.92rem;
    color: var(--text);
    background: #fafafa;
    width: 100%;
    outline: none;
    transition: border-color 0.18s var(--ease), box-shadow 0.18s var(--ease), background 0.18s var(--ease);
}
input:focus, select:focus {
    border-color: var(--green);
    background: var(--white);
    box-shadow: 0 0 0 3px rgba(0,150,107,0.1);
}

/* Select custom arrow */
.select-wrapper { position: relative; width: 100%; }
.select-wrapper::after {
    content: "▼";
    font-size: 0.6rem;
    color: #b0bec5;
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}
select { appearance: none; padding-right: 36px; cursor: pointer; }

/* ===== SHAKE ERROR (transitions.dev) ===== */
.t-input-wrap { position: relative; width: 100%; }
.t-input {
    transition: border-color 150ms ease-out;
    will-change: transform;
    display: block;
    width: 100%;
}
.t-input.select-wrapper::after {
    content: "▼";
    font-size: 0.6rem;
    color: #b0bec5;
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    pointer-events: none;
}
input.t-input { display: block; }

.t-input.is-error select,
.t-input.is-error input,
input.t-input.is-error {
    border-color: var(--red) !important;
    box-shadow: 0 0 0 3px rgba(229,62,62,0.12) !important;
}
.t-input.is-error { transition: border-color var(--revert-dur) ease-out; }

.t-error-msg {
    opacity: 0;
    visibility: hidden;
    font-size: 0.75rem;
    color: var(--red);
    margin-top: 5px;
    display: block;
    transition: opacity var(--revert-dur) ease-out, visibility 0s linear var(--revert-dur);
}
.t-input-wrap.is-error .t-error-msg {
    opacity: 1;
    visibility: visible;
    transition: opacity var(--revert-dur) ease-out, visibility 0s;
}

.t-input.is-shaking {
    animation: t-input-shake calc(var(--shake-dur-a)*2 + var(--shake-dur-b)*2) linear;
}
@keyframes t-input-shake {
    0%     { transform: translateX(0);                                 animation-timing-function: var(--shake-ease); }
    28.57% { transform: translateX(var(--shake-distance));             animation-timing-function: var(--shake-ease); }
    57.14% { transform: translateX(calc(var(--shake-distance) * -1)); animation-timing-function: var(--shake-ease); }
    78.57% { transform: translateX(var(--shake-overshoot));            animation-timing-function: var(--shake-ease); }
    100%   { transform: translateX(0); }
}
@media (prefers-reduced-motion: reduce) {
    .t-input { animation: none !important; transform: none !important; }
}

/* ===== BUTTON ===== */
.btn-calculate {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    margin-top: 6px;
    padding: 13px 20px;
    background: var(--green);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.18s var(--ease), transform 0.12s var(--ease), box-shadow 0.18s var(--ease);
}
.btn-calculate:hover {
    background: var(--green-hover);
    box-shadow: 0 4px 14px rgba(0,150,107,0.25);
}
.btn-calculate:active { transform: scale(0.97); }
.btn-icon {
    width: 17px; height: 17px;
    transition: transform 0.18s var(--ease);
    flex-shrink: 0;
}
.btn-calculate:hover .btn-icon { transform: translateX(4px); }

/* ===== RESULT CARD ===== */
.result-card {
    grid-column: span 2;
    border-top: 4px solid var(--green);
}
@media (max-width: 720px) { .result-card { grid-column: span 1; } }

.hidden { display: none !important; }

.result-card:not(.hidden) {
    animation: resultIn 0.45s cubic-bezier(0.16,1,0.3,1) both;
}
@keyframes resultIn {
    from { opacity: 0; transform: translateY(18px); }
    to   { opacity: 1; transform: translateY(0); }
}

/* Status badge */
.result-status {
    padding: 14px 18px;
    border-radius: var(--radius-sm);
    text-align: center;
    font-weight: 700;
    font-size: 1.1rem;
    margin-bottom: 20px;
    /* Pop-in animation */
    animation: statusPop 0.35s cubic-bezier(0.34,1.56,0.64,1) both;
    animation-delay: 0.15s;
}
@keyframes statusPop {
    from { opacity: 0; transform: scale(0.93); }
    to   { opacity: 1; transform: scale(1); }
}
.status-safe    { background: var(--green-bg); color: var(--green);  border: 1px solid rgba(0,150,107,0.18); }
.status-low     { background: #fffbeb;          color: #92400e;       border: 1px solid rgba(251,191,36,0.3); }
.status-over    { background: var(--red-bg);    color: var(--red);    border: 1px solid rgba(229,62,62,0.18); }
.status-warning { background: #fffaf0;          color: #c05621;       border: 1px solid rgba(192,86,33,0.2); }

/* ===== GAUGE ===== */
.sugar-gauge-panel {
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 18px 18px 12px;
    margin-bottom: 20px;
    text-align: center;
    transition: border-color 0.4s ease, background 0.4s ease;
}
.gauge-title {
    font-size: 0.88rem;
    font-weight: 700;
    color: var(--teal);
    margin-bottom: 8px;
    letter-spacing: 0.01em;
}
.semicircle-gauge {
    display: flex;
    flex-direction: column;
    align-items: center;
    max-width: 240px;
    margin: 0 auto;
}
.semicircle-gauge svg {
    width: 100%;
    height: auto;
    filter: drop-shadow(0 3px 8px rgba(0,0,0,0.1));
}
.gauge-center-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-top: 6px;
    gap: 2px;
}
.gauge-level-text {
    font-size: 1.05rem;
    font-weight: 800;
    letter-spacing: 0.07em;
    transition: color 0.4s ease;
}
.gauge-value-text {
    font-size: 0.78rem;
    color: var(--muted);
    font-weight: 600;
}

/* ===== COMPARISON BOX ===== */
.comparison-box {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    background: #f8fafc;
    border-radius: var(--radius-sm);
    padding: 16px 20px;
    margin-bottom: 20px;
}
.comparison-item { text-align: center; flex: 1; }
.comparison-item span {
    display: block;
    font-size: 0.78rem;
    color: var(--muted);
    margin-bottom: 4px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}
.comparison-item strong {
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--teal);
}
.arrow-container { color: var(--muted); flex-shrink: 0; }

/* ===== TIPS BOX ===== */
.tips-box {
    background: #fffbf0;
    border: 1px solid #fde9c0;
    border-radius: var(--radius-sm);
    padding: 16px 18px;
    margin-bottom: 14px;
    font-size: 0.9rem;
    line-height: 1.65;
}
.tips-header {
    display: flex;
    align-items: center;
    gap: 7px;
    margin-bottom: 8px;
}
.tips-header h4 {
    font-size: 0.88rem;
    font-weight: 700;
    color: #b45309;
}

/* ===== DISCLAIMER ===== */
.medical-disclaimer {
    font-size: 0.73rem;
    color: #b0bec5;
    text-align: center;
    line-height: 1.5;
}

/* ===== RESPONSIVE STYLE FOR MOBILE ===== */
@media (max-width: 576px) {
    body {
        padding: 120px 12px 40px;
    }
    
    .calculator-container {
        gap: 16px;
    }
    
    section {
        padding: 20px;
    }
    
    .form-row {
        grid-template-columns: 1fr;
        gap: 16px;
    }
    
    .comparison-box {
        flex-direction: column;
        gap: 12px;
        padding: 16px;
    }
    
    .arrow-container {
        transform: rotate(90deg);
        margin: 4px 0;
        display: flex;
        justify-content: center;
    }
}