/* ==========================================================================
   VIBO DOCTOR DESIGN SYSTEM & VARIABLES
   ========================================================================== */
:root {
    --bg-base: hsl(222, 25%, 6%);
    --bg-surface: hsl(222, 20%, 10%);
    --bg-card: hsla(222, 20%, 14%, 0.6);
    --border-color: hsla(215, 20%, 25%, 0.4);
    --text-primary: hsl(210, 20%, 98%);
    --text-secondary: hsl(210, 10%, 78%);
    --text-muted: hsl(210, 10%, 58%);
    
    /* Clinical / AI Accents */
    --primary: hsl(175, 90%, 45%);       /* Clinical Teal */
    --primary-glow: hsla(175, 90%, 45%, 0.15);
    --secondary: hsl(195, 95%, 50%);     /* Medical Cyan */
    --accent: hsl(40, 95%, 55%);         /* Warning Orange */
    
    /* Pain Level Colors */
    --rate-1: hsl(145, 75%, 45%);        /* Green */
    --rate-2: hsl(175, 75%, 45%);        /* Teal */
    --rate-3: hsl(45, 95%, 50%);         /* Yellow-Orange */
    --rate-4: hsl(18, 95%, 50%);         /* Orange-Red */
    --rate-5: hsl(0, 85%, 55%);          /* Clinical Red */
    
    --font-heading: 'Inter', 'Sarabun', sans-serif;
    --font-body: 'Sarabun', 'Inter', sans-serif;
    --transition-smooth: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ==========================================================================
   GLOBAL RESET & LAYOUT
   ========================================================================== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    background-color: var(--bg-base);
    color: var(--text-secondary);
    font-family: var(--font-body);
    line-height: 1.6;
    overflow-x: hidden;
    padding: 40px 20px;
}

.app-container {
    max-width: 1000px;
    margin: 0 auto;
}

/* Print Elements (Hidden on Web) */
.print-report-header {
    display: none;
}

/* ==========================================================================
   HEADER SECTION
   ========================================================================== */
.app-header {
    text-align: center;
    margin-bottom: 40px;
}

.header-top-nav {
    display: flex;
    justify-content: flex-start;
    margin-bottom: 20px;
}

.back-home-link {
    text-decoration: none;
    color: var(--text-muted);
    font-family: var(--font-heading);
    font-size: 0.85rem;
    font-weight: 600;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    transition: var(--transition-smooth);
}

.back-home-link:hover {
    color: var(--primary);
    transform: translateX(-2px);
}

.logo-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 12px;
    flex-wrap: wrap;
}

.logo-badge {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: hsl(222, 25%, 6%);
    font-family: var(--font-heading);
    font-weight: 800;
    font-size: 0.9rem;
    padding: 5px 12px;
    border-radius: 4px;
    letter-spacing: 1.5px;
    box-shadow: 0 0 15px rgba(0, 150, 136, 0.3);
}

.logo-title {
    font-size: 2.2rem;
    font-weight: 700;
    font-family: var(--font-heading);
    color: var(--text-primary);
}

.header-tagline {
    font-size: 1.05rem;
    color: var(--text-muted);
    max-width: 600px;
    margin: 0 auto;
}

/* ==========================================================================
   DIAGNOSTIC WIZARD STYLING
   ========================================================================== */
.wizard-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 40px;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(15px);
}

/* Progress Step Circles */
.wizard-header {
    margin-bottom: 35px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 25px;
}

.step-indicator {
    display: flex;
    align-items: center;
    justify-content: center;
    margin-bottom: 25px;
}

.step-circle {
    width: 36px;
    height: 36px;
    border-radius: 50%;
    background-color: var(--bg-base);
    border: 2px solid var(--border-color);
    color: var(--text-muted);
    display: flex;
    align-items: center;
    justify-content: center;
    font-family: var(--font-heading);
    font-weight: 700;
    font-size: 0.95rem;
    transition: var(--transition-smooth);
}

.step-circle.active {
    border-color: var(--primary);
    color: var(--primary);
    background-color: var(--primary-glow);
    box-shadow: 0 0 12px var(--primary-glow);
}

.step-circle.completed {
    background-color: var(--primary);
    border-color: var(--primary);
    color: hsl(222, 25%, 6%);
}

.step-line {
    flex-grow: 1;
    max-width: 80px;
    height: 2px;
    background-color: var(--border-color);
    margin: 0 10px;
    transition: var(--transition-smooth);
}

.step-line.completed {
    background-color: var(--primary);
}

.section-title {
    font-size: 1.5rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.section-desc {
    font-size: 0.95rem;
    color: var(--text-muted);
}

/* Question Groups & Rating buttons */
.question-group {
    margin-bottom: 30px;
    animation: fade-slide 0.4s ease-out forwards;
}

@keyframes fade-slide {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

.q-label {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    display: block;
    margin-bottom: 4px;
}

.q-help {
    font-size: 0.85rem;
    color: var(--text-muted);
    display: block;
    margin-bottom: 18px;
}

.rating-scale {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 15px;
    max-width: 650px;
}

.rate-btn {
    background-color: var(--bg-base);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 14px 10px;
    color: var(--text-secondary);
    font-family: var(--font-heading);
    font-size: 1.4rem;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition-smooth);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    position: relative;
    overflow: hidden;
}

.rate-btn span {
    font-size: 0.75rem;
    font-weight: 500;
    font-family: var(--font-body);
    color: var(--text-muted);
}

.rate-btn:hover {
    transform: translateY(-2px);
}

/* Dynamic Active Button Styles based on severity values */
.rating-scale .rate-btn[data-value="1"]:hover, 
.rating-scale .rate-btn[data-value="1"].active {
    border-color: var(--rate-1);
    color: var(--rate-1);
    background-color: hsla(145, 75%, 45%, 0.08);
}
.rating-scale .rate-btn[data-value="1"].active {
    box-shadow: 0 0 15px hsla(145, 75%, 45%, 0.2);
}

.rating-scale .rate-btn[data-value="2"]:hover, 
.rating-scale .rate-btn[data-value="2"].active {
    border-color: var(--rate-2);
    color: var(--rate-2);
    background-color: hsla(175, 75%, 45%, 0.08);
}
.rating-scale .rate-btn[data-value="2"].active {
    box-shadow: 0 0 15px hsla(175, 75%, 45%, 0.2);
}

.rating-scale .rate-btn[data-value="3"]:hover, 
.rating-scale .rate-btn[data-value="3"].active {
    border-color: var(--rate-3);
    color: var(--rate-3);
    background-color: hsla(45, 95%, 50%, 0.08);
}
.rating-scale .rate-btn[data-value="3"].active {
    box-shadow: 0 0 15px hsla(45, 95%, 50%, 0.2);
}

.rating-scale .rate-btn[data-value="4"]:hover, 
.rating-scale .rate-btn[data-value="4"].active {
    border-color: var(--rate-4);
    color: var(--rate-4);
    background-color: hsla(18, 95%, 50%, 0.08);
}
.rating-scale .rate-btn[data-value="4"].active {
    box-shadow: 0 0 15px hsla(18, 95%, 50%, 0.2);
}

.rating-scale .rate-btn[data-value="5"]:hover, 
.rating-scale .rate-btn[data-value="5"].active {
    border-color: var(--rate-5);
    color: var(--rate-5);
    background-color: hsla(0, 85%, 55%, 0.08);
}
.rating-scale .rate-btn[data-value="5"].active {
    box-shadow: 0 0 15px hsla(0, 85%, 55%, 0.25);
}

/* Wizard Steps Visibility */
.wizard-step {
    display: none;
}

.wizard-step.active {
    display: block;
}

/* Wizard Navigation */
.wizard-nav {
    display: flex;
    justify-content: space-between;
    margin-top: 40px;
    padding-top: 25px;
    border-top: 1px solid var(--border-color);
}

.wizard-btn-prev, .wizard-btn-next {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 12px 28px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition-smooth);
    border: none;
}

.wizard-btn-prev {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.wizard-btn-prev:hover {
    background-color: var(--bg-card);
    color: var(--text-primary);
}

.wizard-btn-next {
    background-color: var(--primary);
    color: hsl(222, 25%, 6%);
    font-weight: 700;
}

.wizard-btn-next:hover {
    background-color: hsl(175, 90%, 40%);
    box-shadow: 0 5px 15px rgba(0, 150, 136, 0.3);
}

/* ==========================================================================
   RESULTS DASHBOARD STYLING
   ========================================================================== */
.results-section {
    animation: fade-in-dashboard 0.6s cubic-bezier(0.16, 1, 0.3, 1) forwards;
}

@keyframes fade-in-dashboard {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

.results-grid {
    display: grid;
    grid-template-columns: 1.1fr 0.9fr;
    gap: 30px;
}

.result-card {
    background-color: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 24px;
    padding: 35px;
    box-shadow: 0 15px 35px rgba(0, 0, 0, 0.3);
}

.result-card-title {
    font-size: 1.4rem;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.highlight-title {
    color: var(--primary) !important;
}

.result-card-subtitle {
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 25px;
}

/* Overview report styles */
.result-badge-box {
    margin-bottom: 10px;
}

.result-badge {
    display: inline-block;
    padding: 6px 14px;
    border-radius: 30px;
    font-size: 0.8rem;
    font-weight: 700;
    letter-spacing: 0.5px;
}

.result-badge.risk-low { background: rgba(0, 150, 136, 0.15); border: 1px solid var(--rate-1); color: var(--rate-1); }
.result-badge.risk-med { background: rgba(255, 152, 0, 0.15); border: 1px solid var(--rate-3); color: var(--rate-3); }
.result-badge.risk-high { background: rgba(244, 67, 54, 0.15); border: 1px solid var(--rate-5); color: var(--rate-5); }

.diagnosis-summary-box {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    margin-bottom: 30px;
}

.diagnosis-summary-box h3 {
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 8px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.diagnosis-summary-box p {
    font-size: 0.95rem;
    color: var(--text-secondary);
    line-height: 1.5;
}

/* SVG Chart wrapper */
.chart-container-box h3 {
    font-size: 0.95rem;
    color: var(--text-primary);
    margin-bottom: 15px;
}

.chart-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    background-color: var(--bg-base);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    min-height: 280px;
}

/* Timeline Prescription styles */
.prescription-timeline {
    display: flex;
    flex-direction: column;
    position: relative;
    padding-left: 20px;
    border-left: 2px solid var(--border-color);
    gap: 25px;
    margin-bottom: 35px;
}

.timeline-item {
    position: relative;
    transition: var(--transition-smooth);
}

.timeline-indicator {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background-color: var(--bg-base);
    border: 2px solid var(--border-color);
    position: absolute;
    left: -28px;
    top: 5px;
    transition: var(--transition-smooth);
}

.timeline-item.active .timeline-indicator {
    background-color: var(--primary);
    border-color: var(--primary);
    box-shadow: 0 0 10px var(--primary);
}

.timeline-content {
    background-color: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 20px;
    transition: var(--transition-smooth);
}

/* Highlighting urgent recommended phase based on score */
.timeline-item.recommended .timeline-content {
    border-color: var(--accent);
    background-color: hsla(40, 95%, 55%, 0.03);
    box-shadow: 0 0 15px hsla(40, 95%, 55%, 0.05);
}

.timeline-item.recommended .timeline-indicator {
    border-color: var(--accent);
    background-color: var(--accent);
    box-shadow: 0 0 10px var(--accent);
}

.phase-tag {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 3px 8px;
    border-radius: 4px;
    display: inline-block;
    margin-bottom: 10px;
}

.tag-simple { background-color: rgba(0, 150, 136, 0.15); color: var(--rate-1); }
.tag-medium { background-color: rgba(13, 71, 161, 0.2); color: var(--secondary); }
.tag-serious { background-color: rgba(244, 67, 54, 0.15); color: var(--rate-5); }

.timeline-content h3 {
    font-size: 1.1rem;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.timeline-content p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-bottom: 12px;
}

.timeline-bullets {
    list-style: none;
    padding-top: 10px;
    border-top: 1px dashed var(--border-color);
}

.timeline-bullets li {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    position: relative;
    padding-left: 14px;
}

.timeline-bullets li::before {
    content: "•";
    color: var(--primary);
    font-weight: bold;
    position: absolute;
    left: 0;
    top: -1px;
}

.timeline-item.recommended .timeline-bullets li::before {
    color: var(--accent);
}

/* Result Buttons */
.results-actions {
    display: flex;
    gap: 15px;
}

.action-btn-print, .action-btn-restart {
    font-family: var(--font-heading);
    font-size: 0.95rem;
    font-weight: 600;
    padding: 12px 24px;
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition-smooth);
    border: none;
    flex: 1;
}

.action-btn-print {
    background: linear-gradient(135deg, var(--primary), var(--secondary));
    color: hsl(222, 25%, 6%);
    font-weight: 700;
}

.action-btn-print:hover {
    transform: translateY(-2px);
    box-shadow: 0 5px 15px rgba(0, 150, 136, 0.3);
}

.action-btn-restart {
    background-color: transparent;
    border: 1px solid var(--border-color);
    color: var(--text-secondary);
}

.action-btn-restart:hover {
    background-color: var(--bg-card);
    color: var(--text-primary);
}

/* ==========================================================================
   RESPONSIVE DESIGN (WEB)
   ========================================================================== */
@media (max-width: 900px) {
    .results-grid {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    .rating-scale {
        grid-template-columns: 1fr;
        gap: 8px;
    }
    .rate-btn {
        flex-direction: row;
        justify-content: space-between;
        padding: 10px 20px;
    }
    .rate-btn span {
        text-align: right;
    }
    .wizard-card {
        padding: 25px 20px;
    }
    .results-actions {
        flex-direction: column;
    }
}

/* ==========================================================================
   CSS PRINT MEDIA QUERY (PRINT-TO-PDF OVERRIDES)
   ========================================================================== */
@media print {
    @page {
        size: A4 portrait;
        margin: 10mm; /* Clean print margin */
    }

    body {
        background: #ffffff !important;
        color: #111111 !important;
        font-size: 10pt !important;
        line-height: 1.3 !important;
        padding: 0 !important;
        -webkit-print-color-adjust: exact;
        print-color-adjust: exact;
    }

    .app-container {
        max-width: 100% !important;
        margin: 0 !important;
    }

    /* Hide Wizard during print */
    .wizard-section,
    .app-header {
        display: none !important;
    }

    /* Print Header display */
    .print-report-header {
        display: flex !important;
        justify-content: space-between;
        align-items: center;
        border-bottom: 2px solid #0d47a1;
        padding-bottom: 8pt;
        margin-bottom: 20pt;
    }

    .print-branding {
        display: flex;
        align-items: baseline;
        gap: 8px;
    }

    .logo-vibo {
        font-family: var(--font-heading);
        font-size: 18pt;
        font-weight: bold;
        color: #0d47a1;
    }

    .logo-by {
        font-size: 9pt;
        color: #555555;
    }

    .print-meta-date {
        font-size: 9pt;
        color: #555555;
    }

    /* Split Results into 2 Pages explicitly */
    .results-section {
        display: block !important;
    }

    .results-grid {
        display: block !important; /* Stack items vertically for print */
    }

    /* PAGE 1: DIAGNOSIS & SVG CHART */
    .overview-card {
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        background: transparent !important;
        page-break-after: always;
        break-after: page;
        height: 260mm; /* Fit exactly Page 1 */
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }

    .result-badge-box {
        margin-bottom: 12pt;
    }

    .result-badge {
        font-size: 9pt !important;
        padding: 4pt 10pt !important;
        border: 2px solid #111111 !important;
        background: transparent !important;
    }
    
    .result-badge.risk-low { color: #004d40 !important; border-color: #004d40 !important; }
    .result-badge.risk-med { color: #e65100 !important; border-color: #e65100 !important; }
    .result-badge.risk-high { color: #b71c1c !important; border-color: #b71c1c !important; }

    .result-card-title {
        font-size: 16pt !important;
        color: #0d47a1 !important;
    }

    .result-card-subtitle {
        font-size: 8.5pt !important;
        color: #555555 !important;
        margin-bottom: 15pt !important;
    }

    .diagnosis-summary-box {
        border: 1.5px solid #cccccc !important;
        background: #f9f9f9 !important;
        padding: 12pt !important;
        border-radius: 8px !important;
        margin-bottom: 20pt !important;
    }

    .diagnosis-summary-box h3 {
        color: #0d47a1 !important;
        font-size: 10pt !important;
    }

    .diagnosis-summary-box p {
        color: #222222 !important;
        font-size: 9pt !important;
    }

    .chart-container-box h3 {
        color: #0d47a1 !important;
        font-size: 10pt !important;
        border-bottom: 1.5px solid #0d47a1;
        padding-bottom: 4pt;
        margin-bottom: 10pt !important;
    }

    .chart-wrapper {
        background: transparent !important;
        border: 1.5px solid #cccccc !important;
        border-radius: 8px !important;
        padding: 10pt !important;
        min-height: auto !important;
    }

    .chart-wrapper svg {
        width: 140mm !important;
        height: 140mm !important;
    }

    /* PAGE 2: PRESCRIPTION TIMELINE */
    .prescription-card {
        border: none !important;
        box-shadow: none !important;
        padding: 0 !important;
        background: transparent !important;
        height: 260mm; /* Fit exactly Page 2 */
        display: flex;
        flex-direction: column;
        justify-content: space-between;
    }

    .prescription-card .result-card-title {
        font-size: 16pt !important;
        color: #0d47a1 !important;
        border-bottom: 2px solid #0d47a1;
        padding-bottom: 4pt;
    }

    .prescription-timeline {
        border-left: 2px solid #cccccc !important;
        gap: 15pt !important;
        margin-bottom: 20pt !important;
        padding-left: 15pt !important;
    }

    .timeline-indicator {
        border: 2px solid #555555 !important;
        background: #ffffff !important;
        left: -21pt !important;
    }

    .timeline-item.active .timeline-indicator {
        border-color: #0d47a1 !important;
        background: #0d47a1 !important;
    }

    .timeline-item.recommended .timeline-indicator {
        border-color: #e65100 !important;
        background: #e65100 !important;
    }

    .timeline-content {
        border: 1.5px solid #cccccc !important;
        background: #ffffff !important;
        border-radius: 8px !important;
        padding: 12pt !important;
    }

    .timeline-item.recommended .timeline-content {
        border: 2px solid #e65100 !important;
        background: #fff8f1 !important;
    }

    .phase-tag {
        font-size: 7.5pt !important;
        padding: 2pt 6pt !important;
        border: 1px solid #111111 !important;
    }
    
    .tag-simple { color: #004d40 !important; border-color: #004d40 !important; background: transparent !important; }
    .tag-medium { color: #0d47a1 !important; border-color: #0d47a1 !important; background: transparent !important; }
    .tag-serious { color: #b71c1c !important; border-color: #b71c1c !important; background: transparent !important; }

    .timeline-content h3 {
        font-size: 10.5pt !important;
        color: #111111 !important;
    }

    .timeline-content p {
        font-size: 8pt !important;
        color: #444444 !important;
    }

    .timeline-bullets {
        border-top: 1px dashed #cccccc !important;
        padding-top: 6pt !important;
    }

    .timeline-bullets li {
        font-size: 8pt !important;
        color: #333333 !important;
        margin-bottom: 4pt !important;
    }

    .timeline-bullets li::before {
        color: #0d47a1 !important;
    }

    .timeline-item.recommended .timeline-bullets li::before {
        color: #e65100 !important;
    }

    /* Print Sign-off Lines instead of Interactive buttons */
    .results-actions {
        display: none !important; /* Hide web buttons */
    }

    /* Inject print-only sign-off signature section */
    .prescription-card::after {
        content: "ผลการวิเคราะห์นี้จัดทำขึ้นโดยความร่วมมือระหว่าง IndeVibo & Samong\A\Aลงชื่อแพทย์ผู้ตรวจปฏิบัติการ: __________________________    วันที่ตรวจ: ____/____/________\A\Aสัญญายอมรับความมุ่งมั่นทรานส์ฟอร์ม:  [  ] ยินดีเริ่มเข้าร่วมกู้คืนกำไร Phase 1 ทันที";
        display: block;
        white-space: pre-wrap;
        font-size: 8.5pt;
        line-height: 1.8;
        color: #333333;
        border-top: 1.5px dashed #cccccc;
        padding-top: 15pt;
        margin-top: 10pt;
    }
}
