/* Heart Disease Prediction Web App — Artistic Redesign v2 */

:root {
    --primary: #1e3a5f;
    --primary-light: #2d5a8e;
    --primary-glow: rgba(30, 58, 95, 0.15);
    --accent: #e74c3c;
    --bg-gradient-start: #0f2027;
    --bg-gradient-mid: #203a43;
    --bg-gradient-end: #2c5364;
    --card-bg: rgba(255, 255, 255, 0.95);
    --card-border: rgba(255, 255, 255, 0.2);
    --text: #2d3748;
    --text-light: #718096;
    --border: #e2e8f0;
    --success: #27ae60;
    --warning: #f39c12;
    --danger: #e74c3c;
    --radius: 16px;
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.12);
    --shadow-hover: 0 12px 40px rgba(0, 0, 0, 0.18);
}

* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "PingFang SC",
                 "Microsoft YaHei", sans-serif;
    background: linear-gradient(135deg, var(--bg-gradient-start) 0%, var(--bg-gradient-mid) 50%, var(--bg-gradient-end) 100%);
    min-height: 100vh;
    color: var(--text);
    line-height: 1.6;
    position: relative;
    overflow-x: hidden;
}
body::before {
    content: '';
    position: fixed; top: 0; left: 0; right: 0; bottom: 0;
    background-image:
        radial-gradient(circle at 20% 20%, rgba(255,255,255,0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(255,255,255,0.04) 0%, transparent 50%);
    pointer-events: none; z-index: 0;
}

.app-container {
    max-width: 680px; margin: 0 auto;
    padding: 24px 16px 48px;
    position: relative; z-index: 1;
}

/* Header */
.app-header {
    text-align: center; padding: 40px 24px 32px;
    background: var(--card-bg); border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 16px;
    backdrop-filter: blur(20px); border: 1px solid var(--card-border);
    position: relative; overflow: hidden;
}
.app-header::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
    background: linear-gradient(90deg, #667eea, #764ba2, #e74c3c);
}
.header-icon {
    font-size: 68px; margin-bottom: 12px;
    filter: drop-shadow(0 4px 8px rgba(0,0,0,0.1));
    animation: heartbeat 2s ease-in-out infinite;
}
@keyframes heartbeat {
    0%,100% { transform: scale(1); } 15% { transform: scale(1.08); }
    30% { transform: scale(1); } 45% { transform: scale(1.05); } 60% { transform: scale(1); }
}
.app-header h1 {
    font-size: 38px; font-weight: 800; letter-spacing: 0.5px;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.subtitle {
    color: var(--text-light); font-size: 8px; margin-top: 6px;
    text-transform: uppercase; letter-spacing: 3px; font-weight: 500;
}

/* Disclaimer & Warning */
.disclaimer {
    background: linear-gradient(135deg, #fff8e1, #fff3cd); color: #856404;
    padding: 14px 18px; border-radius: 12px; font-size: 13px;
    margin-bottom: 16px; border-left: 4px solid #ffc107;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.age-warning {
    background: linear-gradient(135deg, #e3f2fd, #bbdefb); color: #1565c0;
    padding: 14px 18px; border-radius: 12px; font-size: 13px;
    margin-bottom: 16px; border-left: 4px solid #42a5f5;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06); display: none;
}

/* Form Sections */
.form-section {
    background: var(--card-bg); border-radius: var(--radius);
    box-shadow: var(--shadow); padding: 28px 24px; margin-bottom: 16px;
    transition: box-shadow 0.3s, transform 0.3s;
    backdrop-filter: blur(20px); border: 1px solid var(--card-border);
}
.form-section:hover { box-shadow: var(--shadow-hover); transform: translateY(-1px); }

.section-header { display: flex; align-items: center; gap: 12px; margin-bottom: 22px; flex-wrap: wrap; }
.section-header.optional { flex-direction: column; align-items: flex-start; }
.section-icon {
    font-size: 28px; width: 44px; height: 44px;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary-glow); border-radius: 12px;
}
.section-header h2 { font-size: 18px; color: var(--primary); font-weight: 700; display: flex; align-items: center; gap: 8px; }
.section-note { font-size: 12px; color: var(--text-light); margin-top: 4px; }

.badge { font-size: 10px; padding: 3px 10px; border-radius: 20px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.5px; }
.required-badge { background: linear-gradient(135deg, #fed7d7, #feb2b2); color: #c53030; }
.optional-badge { background: linear-gradient(135deg, #c6f6d5, #9ae6b4); color: #276749; }
.required-mark { color: var(--accent); font-weight: bold; }

/* Grid */
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
@media (max-width: 560px) { .form-grid { grid-template-columns: 1fr; } }

.form-field { display: flex; flex-direction: column; gap: 5px; }
.form-field label { font-size: 13px; font-weight: 600; color: var(--text); }
.field-help { font-size: 11px; color: var(--text-light); }

/* Inputs */
input[type="number"], select {
    padding: 10px 12px; border: 1.5px solid var(--border); border-radius: 10px;
    font-size: 14px; color: var(--text); background: #fff;
    transition: all 0.25s; width: 100%; appearance: none; -webkit-appearance: none;
}
select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%23718096' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
    background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px;
}
input[type="number"]:focus, select:focus {
    outline: none; border-color: var(--primary-light); box-shadow: 0 0 0 3px var(--primary-glow);
}
/* Fix 3: small elegant placeholders */
input::placeholder { color: #b0bec5; font-size: 12px; opacity: 0.7; }

/* Slider + Number */
.slider-input-group { display: flex; align-items: center; gap: 10px; }
.slider-input-group .range-slider {
    flex: 1; -webkit-appearance: none; appearance: none;
    height: 6px; border-radius: 3px;
    background: linear-gradient(90deg, #c6f6d5 0%, #fefcbf 50%, #fed7d7 100%);
    outline: none; cursor: pointer; transition: opacity 0.2s;
}
.slider-input-group .range-slider:disabled { opacity: 0.25; cursor: not-allowed; background: #e2e8f0; }
.slider-input-group .range-slider::-webkit-slider-thumb {
    -webkit-appearance: none; width: 22px; height: 22px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border: 3px solid white; box-shadow: 0 2px 8px rgba(0,0,0,0.25);
    cursor: pointer; transition: transform 0.15s;
}
.slider-input-group .range-slider::-webkit-slider-thumb:hover { transform: scale(1.2); }
.slider-input-group .range-slider::-moz-range-thumb {
    width: 22px; height: 22px; border-radius: 50%;
    background: linear-gradient(135deg, var(--primary), var(--primary-light));
    border: 3px solid white; box-shadow: 0 2px 8px rgba(0,0,0,0.25); cursor: pointer;
}
.slider-input-group input[type="number"] {
    width: 68px; flex-shrink: 0; text-align: center; font-weight: 700; font-size: 13px; padding: 8px 4px;
}

/* BMI computed bar (compact, inline with form) */
.bmi-bar {
    display: flex; align-items: center; gap: 10px;
    padding: 10px 16px; margin-top: 14px;
    background: linear-gradient(135deg, #f7fafc, #edf2f7);
    border-radius: 10px; border: 1.5px solid var(--border);
    font-size: 14px; transition: all 0.3s;
}
.bmi-bar-label {
    font-weight: 700; color: var(--text-light); font-size: 12px;
    text-transform: uppercase; letter-spacing: 1px;
}
.bmi-bar-value {
    font-size: 20px; font-weight: 800; color: var(--primary);
    min-width: 48px; text-align: center;
}
.bmi-bar-tag {
    font-size: 12px; font-weight: 600; padding: 2px 10px;
    border-radius: 12px; margin-left: auto;
}
.bmi-bar.bmi-normal { border-color: var(--success); }
.bmi-bar.bmi-normal .bmi-bar-tag { background: #c6f6d5; color: #22543d; }
.bmi-bar.bmi-overweight { border-color: var(--warning); }
.bmi-bar.bmi-overweight .bmi-bar-tag { background: #fefcbf; color: #744210; }
.bmi-bar.bmi-obese { border-color: var(--danger); }
.bmi-bar.bmi-obese .bmi-bar-tag { background: #fed7d7; color: #9b2c2c; }

/* Submit */
.submit-btn {
    width: 100%; padding: 18px;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 50%, #667eea 100%);
    color: white; border: none; border-radius: var(--radius);
    font-size: 18px; font-weight: 800; cursor: pointer;
    transition: all 0.3s; box-shadow: 0 6px 20px rgba(30,58,95,0.35);
    margin-bottom: 16px; letter-spacing: 1px; position: relative; overflow: hidden;
}
.submit-btn::after {
    content: ''; position: absolute; top: 0; left: -100%; width: 100%; height: 100%;
    background: linear-gradient(90deg, transparent, rgba(255,255,255,0.15), transparent);
    transition: left 0.5s;
}
.submit-btn:hover:not(:disabled)::after { left: 100%; }
.submit-btn:hover:not(:disabled) { transform: translateY(-3px); box-shadow: 0 10px 30px rgba(30,58,95,0.45); }
.submit-btn:active:not(:disabled) { transform: translateY(-1px); }
.submit-btn:disabled { opacity: 0.6; cursor: not-allowed; }
.btn-loading { display: inline-flex; align-items: center; gap: 10px; }
.spinner {
    width: 22px; height: 22px; border: 3px solid rgba(255,255,255,0.3);
    border-top-color: white; border-radius: 50%; animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Results */
.results-panel { animation: slideUp 0.6s cubic-bezier(0.16,1,0.3,1); }
@keyframes slideUp { from { opacity:0; transform:translateY(40px) scale(0.98); } to { opacity:1; transform:translateY(0) scale(1); } }
.result-card {
    background: var(--card-bg); border-radius: var(--radius);
    box-shadow: var(--shadow-hover); padding: 36px 28px; text-align: center;
    margin-bottom: 16px; backdrop-filter: blur(20px);
    border: 1px solid var(--card-border); position: relative; overflow: hidden;
}
.result-card::before {
    content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
    background: var(--success); transition: background 0.5s;
}
.gauge-svg { width: 240px; height: 144px; filter: drop-shadow(0 4px 12px rgba(0,0,0,0.08)); }
.risk-level { font-size: 28px; font-weight: 900; margin-bottom: 14px; letter-spacing: 1px; }
.advice-text { font-size: 15px; color: var(--text); line-height: 1.8; margin-bottom: 24px; padding: 0 8px; }

.doctor-rec {
    display: flex; align-items: flex-start; gap: 14px;
    background: linear-gradient(135deg, #fff5f5, #fed7d7);
    border: 1px solid #feb2b2; border-radius: 14px; padding: 18px;
    margin-bottom: 18px; text-align: left; animation: pulse 2.5s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { box-shadow: 0 0 0 0 rgba(229,62,62,0.25); } 50% { box-shadow: 0 0 0 10px rgba(229,62,62,0); } }
.rec-icon { font-size: 32px; flex-shrink: 0; }
.rec-text strong { display: block; color: #c53030; font-size: 16px; margin-bottom: 4px; font-weight: 800; }
.rec-text span { font-size: 13px; color: #742a2a; line-height: 1.5; }

.result-meta { font-size: 12px; color: var(--text-light); margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--border); }
.model-info { margin-bottom: 6px; }
.confidence-note { font-size: 12px; margin-top: 8px; padding: 10px 14px; border-radius: 10px; line-height: 1.6; font-weight: 500; }
.conf-high { background: linear-gradient(135deg, #c6f6d5, #9ae6b4); color: #22543d; }
.conf-moderate { background: linear-gradient(135deg, #fefcbf, #fefce8); color: #744210; }
.conf-low { background: linear-gradient(135deg, #fed7d7, #feebc8); color: #9b2c2c; }
.conf-basic { background: linear-gradient(135deg, #e2e8f0, #edf2f7); color: #4a5568; }

.reset-btn {
    width: 100%; padding: 16px; background: transparent;
    color: rgba(255,255,255,0.9); border: 2px solid rgba(255,255,255,0.4);
    border-radius: var(--radius); font-size: 16px; font-weight: 700;
    cursor: pointer; transition: all 0.3s; letter-spacing: 0.5px;
}
.reset-btn:hover { background: rgba(255,255,255,0.15); border-color: rgba(255,255,255,0.7); color: white; }

.error-panel {
    background: var(--card-bg); border: 1px solid #feb2b2;
    border-radius: var(--radius); padding: 28px; text-align: center;
    margin-bottom: 16px; box-shadow: var(--shadow);
}
.error-icon { font-size: 40px; margin-bottom: 10px; }
#error-message { color: #c53030; font-size: 15px; margin-bottom: 18px; line-height: 1.6; }

.app-footer { text-align: center; padding: 24px; color: rgba(255,255,255,0.6); font-size: 11px; }
.footer-note { margin-top: 6px; opacity: 0.5; font-size: 10px; }

@media (max-width: 480px) {
    .app-container { padding: 12px 10px 36px; }
    .app-header { padding: 28px 18px 24px; }
    .app-header h1 { font-size: 28px; }
    .header-icon { font-size: 56px; }
    .form-section { padding: 20px 16px; }
    .result-card { padding: 28px 18px; }
    .risk-level { font-size: 24px; }
}

/* Individual factors explainability panel */
.factors-panel { text-align: left; margin: 20px 0 12px; padding: 16px 18px;
    background: linear-gradient(135deg,#f7fafc,#edf2f7); border-radius: 12px;
    border: 1px solid var(--border); }
.factors-title { font-size: 14px; font-weight: 800; color: var(--primary); margin-bottom: 12px; }
.factor-row { display: flex; align-items: center; gap: 10px; margin: 7px 0; font-size: 12.5px; }
.factor-name { width: 130px; flex-shrink: 0; font-weight: 600; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.factor-bar { flex: 1; height: 9px; background: #e2e8f0; border-radius: 5px; overflow: hidden; }
.factor-fill { display: block; height: 100%; border-radius: 5px; transition: width .6s ease; }
.fill-up { background: linear-gradient(90deg,#e74c3c,#c0392b); }
.fill-down { background: linear-gradient(90deg,#27ae60,#229954); }
.factor-val { width: 130px; flex-shrink: 0; text-align: right; font-weight: 700; font-size: 11.5px; }
.txt-up { color: #c0392b; } .txt-down { color: #229954; }
.factors-foot { font-size: 11px; color: var(--text-light); margin-top: 10px; line-height: 1.5; }
.imputed-note { background: #e3f2fd; color: #1565c0; border-radius: 10px; padding: 10px 14px;
    font-size: 12px; margin: 10px 0; text-align: left; }

/* Optional sliders: slightly faded until user interacts */
.slider-optional { opacity: 0.45; transition: opacity 0.3s ease; }
.slider-optional:hover { opacity: 0.7; }
input.touched { border-color: var(--primary) !important; }

/* Normal range hint below clinical/wearable fields */
.normal-range-hint {
    display: block;
    margin-top: 4px;
    padding: 4px 8px;
    background: linear-gradient(135deg, #e8f5e9, #f1f8e9);
    border-left: 3px solid #66bb6a;
    border-radius: 0 6px 6px 0;
    font-size: 11px;
    color: #2e7d32;
    line-height: 1.4;
}

/* Age-band threshold disclosure */
.band-note { background: #fff8e1; color: #8d6e00; border-left: 4px solid #f0b400;
    border-radius: 8px; padding: 11px 14px; font-size: 12.5px; line-height: 1.6;
    margin: 10px 0; text-align: left; }
.band-note .bn-sub { font-size: 11.5px; color: #a8842a; display: inline-block; margin-top: 4px; }

/* Clinical stance selector */
.stance-section { background: linear-gradient(135deg,#f8f6ff,#f0edfa); }
.stance-options { display: grid; grid-template-columns: repeat(auto-fit,minmax(190px,1fr));
    gap: 12px; margin-top: 6px; }
.stance-opt { cursor: pointer; }
.stance-opt input { position: absolute; opacity: 0; pointer-events: none; }
.stance-card { display: block; padding: 13px 15px; border-radius: 11px;
    border: 2px solid #ddd6f3; background: #fff; transition: all .22s ease; height: 100%; }
.stance-card b { display: block; font-size: 13.5px; color: #4a3b78; margin-bottom: 6px; }
.stance-card small { display: block; font-size: 11.5px; color: #7a719a; line-height: 1.55; }
.stance-opt input:checked + .stance-card {
    border-color: #764ba2; background: linear-gradient(135deg,#faf7ff,#f2ecfd);
    box-shadow: 0 4px 14px rgba(118,75,162,.18); transform: translateY(-2px); }
.stance-opt:hover .stance-card { border-color: #b8a6e0; }
