/* --- Reset & Base --- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --bg: #f5f5f0;
    --bg-card: #ffffff;
    --text: #1a1a1a;
    --text-light: #555555;
    --primary: #2563eb;
    --primary-hover: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --border: #e0e0e0;
    --radius: 12px;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    --font-size-base: 18px;
    --font-size-lg: 22px;
    --font-size-xl: 28px;
    --font-size-sm: 15px;
}

/* High contrast mode */
.high-contrast {
    --bg: #000000;
    --bg-card: #1a1a1a;
    --text: #ffffff;
    --text-light: #cccccc;
    --border: #444444;
    --primary: #60a5fa;
    --primary-hover: #93bbfd;
    --primary-light: #1e3a5f;
}

html {
    font-size: var(--font-size-base);
}

body {
    font-family: var(--font);
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

/* --- Layout --- */
.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 1rem;
}

/* --- Accessibility bar --- */
.a11y-bar {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
}

.a11y-btn {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: 0.3rem 0.6rem;
    font-size: var(--font-size-sm);
    cursor: pointer;
    color: var(--text);
    min-width: 44px;
    min-height: 44px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.a11y-btn:hover, .a11y-btn:focus {
    background: var(--primary-light);
    outline: 2px solid var(--primary);
}

/* --- Step navigation bar --- */
.step-nav-bar {
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}

.nav-toggle {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    padding: 0.8rem 1rem;
    background: none;
    border: none;
    font-size: var(--font-size-base);
    font-weight: 600;
    cursor: pointer;
    color: var(--text);
    min-height: 44px;
}

.nav-toggle:hover,
.nav-toggle:focus {
    background: var(--primary-light);
}

.nav-arrow {
    font-size: 12px;
    transition: transform 0.2s;
}

.nav-menu.open + .nav-arrow,
.step-nav-bar:has(.nav-menu:not(.hidden)) .nav-arrow {
    transform: rotate(180deg);
}

.nav-menu {
    max-height: 60vh;
    overflow-y: auto;
    border-top: 1px solid var(--border);
}

.nav-item {
    padding: 0.7rem 1rem;
    cursor: pointer;
    font-size: var(--font-size-sm);
    border-bottom: 1px solid var(--border);
    min-height: 44px;
    display: flex;
    align-items: center;
    color: var(--text-light);
}

.nav-item:hover,
.nav-item:focus {
    background: var(--primary-light);
    color: var(--text);
}

.nav-item.active {
    background: var(--primary-light);
    color: var(--primary);
    font-weight: 600;
    border-left: 3px solid var(--primary);
}

.nav-item.completed {
    color: var(--success);
}

.nav-item.completed::after {
    content: " \2713";
    margin-left: auto;
    font-weight: bold;
}

/* --- Cards --- */
.card {
    background: var(--bg-card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 2rem;
    margin-bottom: 1.5rem;
}

/* --- Buttons --- */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.8rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: var(--font-size-base);
    font-weight: 600;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
    transition: background 0.2s, transform 0.1s;
    text-decoration: none;
}

.btn:active {
    transform: scale(0.98);
}

.btn-primary {
    background: var(--primary);
    color: #ffffff;
}

.btn-primary:hover, .btn-primary:focus {
    background: var(--primary-hover);
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 2px solid var(--border);
}

.btn-secondary:hover, .btn-secondary:focus {
    background: var(--primary-light);
    border-color: var(--primary);
}

.btn-large {
    padding: 1rem 2rem;
    font-size: var(--font-size-lg);
    width: 100%;
    margin-bottom: 0.75rem;
}

.btn-danger {
    background: var(--danger);
    color: #ffffff;
}

.btn-danger:hover {
    background: #b91c1c;
}

/* --- Landing page --- */
.landing {
    text-align: center;
    padding: 3rem 1rem;
}

.landing h1 {
    font-size: var(--font-size-xl);
    margin-bottom: 1rem;
}

.landing p {
    font-size: var(--font-size-base);
    color: var(--text-light);
    margin-bottom: 2rem;
    max-width: 600px;
    margin-left: auto;
    margin-right: auto;
}

.privacy-note {
    background: var(--success-light);
    border: 1px solid var(--success);
    border-radius: 8px;
    padding: 1rem;
    margin: 1.5rem auto;
    max-width: 500px;
    font-size: var(--font-size-sm);
}

/* --- Resume code input --- */
.resume-section {
    margin-top: 2rem;
    padding-top: 1.5rem;
    border-top: 1px solid var(--border);
}

.resume-input-group {
    display: flex;
    gap: 0.5rem;
    max-width: 400px;
    margin: 0.75rem auto;
}

.resume-input-group input {
    flex: 1;
    padding: 0.8rem;
    font-size: var(--font-size-base);
    border: 2px solid var(--border);
    border-radius: 8px;
    text-align: center;
    letter-spacing: 0.2em;
    text-transform: uppercase;
}

.resume-input-group input:focus {
    outline: 2px solid var(--primary);
    border-color: var(--primary);
}

/* --- Progress bar --- */
.progress-container {
    margin-bottom: 1.5rem;
}

.progress-bar-bg {
    height: 8px;
    background: var(--border);
    border-radius: 4px;
    overflow: hidden;
}

.progress-bar-fill {
    height: 100%;
    background: var(--primary);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-text {
    display: flex;
    justify-content: space-between;
    font-size: var(--font-size-sm);
    color: var(--text-light);
    margin-top: 0.3rem;
}

/* --- Step header --- */
.step-header {
    margin-bottom: 1.5rem;
}

.step-header h2 {
    font-size: var(--font-size-lg);
    margin-bottom: 0.5rem;
}

.step-explanation {
    color: var(--text-light);
    font-size: var(--font-size-base);
    line-height: 1.5;
}

/* --- Chat area --- */
.chat-area {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    margin-bottom: 1.5rem;
    max-height: 400px;
    overflow-y: auto;
    padding: 1rem;
    background: var(--bg);
}

.chat-message {
    margin-bottom: 1rem;
    display: flex;
    flex-direction: column;
}

.chat-message.assistant {
    align-items: flex-start;
}

.chat-message.user {
    align-items: flex-end;
}

.chat-bubble {
    max-width: 85%;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    font-size: var(--font-size-base);
    line-height: 1.5;
    word-wrap: break-word;
}

.chat-message.assistant .chat-bubble {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-bottom-left-radius: 4px;
}

.chat-message.user .chat-bubble {
    background: var(--primary);
    color: #ffffff;
    border-bottom-right-radius: 4px;
}

.chat-label {
    font-size: 12px;
    color: var(--text-light);
    margin-bottom: 0.2rem;
    font-weight: 600;
}

/* --- Chat input --- */
.chat-input-area {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1.5rem;
}

.chat-input-area textarea {
    flex: 1;
    padding: 0.8rem;
    font-size: var(--font-size-base);
    font-family: var(--font);
    border: 2px solid var(--border);
    border-radius: 8px;
    resize: none;
    min-height: 50px;
    max-height: 150px;
}

.chat-input-area textarea:focus {
    outline: 2px solid var(--primary);
    border-color: var(--primary);
}

/* --- Score display --- */
.score-panel {
    background: var(--primary-light);
    border: 1px solid var(--primary);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 1rem;
}

.score-panel h3 {
    font-size: var(--font-size-base);
    margin-bottom: 0.5rem;
}

.score-value {
    font-size: var(--font-size-xl);
    font-weight: 700;
    color: var(--primary);
}

.score-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

/* --- Assessment result --- */
.assessment-result {
    background: var(--success-light);
    border: 1px solid var(--success);
    border-radius: var(--radius);
    padding: 1.2rem;
}

.assessment-result h3 {
    margin-bottom: 0.5rem;
    font-size: var(--font-size-base);
}

.assessment-score {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: var(--font-size-base);
    font-weight: 600;
}

/* --- Descriptor selection --- */
.descriptor-list {
    list-style: none;
    margin: 1rem 0;
}

.descriptor-item {
    padding: 0.8rem 1rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0.5rem;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    min-height: 44px;
    transition: border-color 0.2s, background 0.2s;
}

.descriptor-item:hover, .descriptor-item:focus {
    border-color: var(--primary);
    background: var(--primary-light);
}

.descriptor-item.selected {
    border-color: var(--primary);
    background: var(--primary-light);
    font-weight: 600;
}

.descriptor-points {
    background: var(--primary);
    color: #fff;
    border-radius: 20px;
    padding: 0.2rem 0.6rem;
    font-size: var(--font-size-sm);
    font-weight: 700;
    min-width: 40px;
    text-align: center;
    flex-shrink: 0;
    margin-left: 0.5rem;
}

/* --- Navigation buttons --- */
.step-nav {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1.5rem;
}

.step-nav .btn {
    flex: 1;
}

/* --- Review page --- */
.review-activity {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem 1.5rem;
    margin-bottom: 1rem;
}

.review-activity-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.5rem;
}

.review-activity-title {
    font-weight: 600;
    font-size: var(--font-size-base);
}

.review-answer {
    color: var(--text-light);
    font-size: var(--font-size-sm);
    margin-top: 0.5rem;
    display: none;
}

.review-activity.expanded .review-answer {
    display: block;
}

/* --- Warning box --- */
.warning-box {
    background: var(--warning-light);
    border: 1px solid var(--warning);
    border-radius: 8px;
    padding: 1rem;
    margin: 1rem 0;
}

.danger-box {
    background: var(--danger-light);
    border: 1px solid var(--danger);
    border-radius: 8px;
    padding: 1rem;
    margin: 1rem 0;
}

/* --- Resume code display --- */
.resume-code-display {
    background: var(--warning-light);
    border: 2px solid var(--warning);
    border-radius: var(--radius);
    padding: 1.5rem;
    text-align: center;
    margin: 1.5rem 0;
}

.resume-code-value {
    font-size: var(--font-size-xl);
    font-weight: 700;
    letter-spacing: 0.3em;
    margin: 0.5rem 0;
    font-family: monospace;
}

/* --- Loading --- */
.loading {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    color: var(--text-light);
    font-size: var(--font-size-sm);
    padding: 0.5rem;
}

.loading-dot {
    width: 8px;
    height: 8px;
    background: var(--text-light);
    border-radius: 50%;
    animation: pulse 1.4s ease-in-out infinite;
}

.loading-dot:nth-child(2) { animation-delay: 0.2s; }
.loading-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes pulse {
    0%, 80%, 100% { transform: scale(0.6); opacity: 0.5; }
    40% { transform: scale(1); opacity: 1; }
}

/* --- Error message --- */
.error-msg {
    background: var(--danger-light);
    color: var(--danger);
    padding: 0.8rem;
    border-radius: 8px;
    margin: 0.5rem 0;
    font-size: var(--font-size-sm);
}

/* --- Disclaimer --- */
.disclaimer {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 1rem;
    font-size: var(--font-size-sm);
    color: var(--text-light);
    margin: 1rem 0;
}

/* --- Medication autocomplete --- */
.med-input-area {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.5rem;
    align-items: flex-start;
}

.med-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 2px solid var(--primary);
    border-top: none;
    border-radius: 0 0 8px 8px;
    max-height: 200px;
    overflow-y: auto;
    z-index: 100;
    box-shadow: var(--shadow);
}

.med-suggestion-item {
    padding: 0.6rem 0.8rem;
    cursor: pointer;
    font-size: var(--font-size-base);
    min-height: 44px;
    display: flex;
    align-items: center;
}

.med-suggestion-item:hover,
.med-suggestion-item.active {
    background: var(--primary-light);
}

.med-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 0.4rem;
    margin-bottom: 1rem;
    min-height: 1rem;
}

.med-tag {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    background: var(--primary-light);
    border: 1px solid var(--primary);
    border-radius: 20px;
    padding: 0.4rem 0.8rem;
    font-size: var(--font-size-sm);
}

.med-tag-remove {
    background: none;
    border: none;
    color: var(--danger);
    cursor: pointer;
    font-size: 16px;
    font-weight: bold;
    padding: 0 0.2rem;
    min-width: 24px;
    min-height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
}

.med-tag-remove:hover {
    background: var(--danger-light);
}

.dose-suggestions {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 2px solid var(--primary);
    border-top: none;
    border-radius: 0 0 8px 8px;
    z-index: 100;
    box-shadow: var(--shadow);
}

.dose-suggestion-item {
    padding: 0.5rem 0.8rem;
    cursor: pointer;
    font-size: var(--font-size-base);
    min-height: 40px;
    display: flex;
    align-items: center;
}

.dose-suggestion-item:hover {
    background: var(--primary-light);
}

@media (max-width: 600px) {
    .med-input-area {
        flex-direction: column;
    }

    .med-input-area input[type="text"]#med-dose,
    .med-input-area > div {
        width: 100%;
    }

    #med-dose {
        width: 100% !important;
    }
}

/* --- Conditions checkboxes --- */
.conditions-group {
    margin-bottom: 1rem;
}

.conditions-group-label {
    font-weight: 600;
    font-size: var(--font-size-sm);
    color: var(--text-light);
    margin-bottom: 0.4rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.conditions-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.4rem;
}

.condition-checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 0.8rem;
    border: 2px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    font-size: var(--font-size-base);
    min-height: 44px;
    transition: background 0.2s, border-color 0.2s;
    font-weight: normal;
}

.condition-checkbox:hover,
.condition-checkbox:focus-within {
    border-color: var(--primary);
    background: var(--primary-light);
}

.condition-checkbox input[type="checkbox"] {
    width: 20px;
    height: 20px;
    cursor: pointer;
    flex-shrink: 0;
}

.condition-checkbox input[type="checkbox"]:checked + span,
.condition-checkbox:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-light);
    font-weight: 600;
}

@media (max-width: 600px) {
    .conditions-grid {
        grid-template-columns: 1fr;
    }
}

/* --- Professional card --- */
.professional-card {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 1rem;
    margin-bottom: 1rem;
    position: relative;
}

.professional-card label {
    font-weight: 600;
    display: block;
    margin-bottom: 0.3rem;
    font-size: var(--font-size-sm);
}

.professional-card input {
    width: 100%;
    padding: 0.6rem;
    font-size: var(--font-size-base);
    font-family: var(--font);
    border: 2px solid var(--border);
    border-radius: 8px;
    margin-bottom: 0.8rem;
}

.professional-card input:focus {
    outline: 2px solid var(--primary);
    border-color: var(--primary);
}

.professional-remove {
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    background: var(--danger-light);
    color: var(--danger);
    border: none;
    border-radius: 6px;
    padding: 0.3rem 0.6rem;
    cursor: pointer;
    font-size: var(--font-size-sm);
    min-width: 44px;
    min-height: 44px;
}

.professional-remove:hover {
    background: var(--danger);
    color: #fff;
}

/* --- Hidden --- */
.hidden {
    display: none !important;
}

/* --- Responsive --- */
@media (max-width: 600px) {
    :root {
        --font-size-base: 16px;
        --font-size-lg: 20px;
        --font-size-xl: 24px;
    }

    .card {
        padding: 1.2rem;
    }

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

    .step-nav {
        flex-direction: column;
    }

    .chat-bubble {
        max-width: 95%;
    }
}
