/* ========================================
   Clinical Trial Eligibility Screening
   styles.css
   ======================================== */

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

:root {
    /* Color System */
    --primary: #1a5276;
    --primary-light: #2980b9;
    --primary-pale: #d6eaf8;
    --primary-bg: #eaf2f8;
    --accent: #e74c3c;
    --accent-soft: #fadbd8;
    --success: #1e8449;
    --success-bg: #d5f5e3;
    --warning: #d4ac0d;
    --warning-bg: #fef9e7;
    --caution: #e67e22;

    /* Neutrals */
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-alt: #f8f9fb;
    --border: #dce1e7;
    --border-light: #ecf0f3;
    --text: #1c2833;
    --text-secondary: #5d6d7e;
    --text-muted: #95a5a6;

    /* Spacing */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 36px;
    --space-2xl: 48px;

    /* Typography */
    --font-main: 'Noto Sans JP', 'IBM Plex Sans', -apple-system, sans-serif;
    --font-mono: 'IBM Plex Mono', 'SF Mono', monospace;

    /* Radii */
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;

    /* Shadows */
    --shadow-sm: 0 1px 3px rgba(0,0,0,0.06);
    --shadow-md: 0 4px 12px rgba(0,0,0,0.08);
    --shadow-lg: 0 8px 30px rgba(0,0,0,0.12);
    --shadow-xl: 0 20px 60px rgba(0,0,0,0.15);
}

html {
    font-size: 15px;
    scroll-behavior: smooth;
}

body {
    font-family: var(--font-main);
    background: var(--bg);
    color: var(--text);
    line-height: 1.65;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
}

/* --- Subtle background pattern --- */
body::before {
    content: '';
    position: fixed;
    inset: 0;
    background:
        radial-gradient(circle at 20% 20%, rgba(26,82,118,0.03) 0%, transparent 50%),
        radial-gradient(circle at 80% 80%, rgba(41,128,185,0.03) 0%, transparent 50%);
    pointer-events: none;
    z-index: 0;
}

/* --- App Container --- */
.app-container {
    position: relative;
    z-index: 1;
    max-width: 860px;
    margin: 0 auto;
    padding: 0 var(--space-md);
}

/* --- Header --- */
.app-header {
    padding: var(--space-lg) 0 var(--space-md);
    border-bottom: 1px solid var(--border-light);
    margin-bottom: var(--space-md);
}

.header-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: var(--space-md);
}

.logo-area {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.logo-icon {
    width: 48px;
    height: 48px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary);
    color: white;
    border-radius: var(--radius-md);
    flex-shrink: 0;
}

.app-title {
    font-size: 1.35rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: var(--text);
}

.app-subtitle {
    font-size: 0.75rem;
    color: var(--text-muted);
    font-weight: 400;
    letter-spacing: 0.04em;
    text-transform: uppercase;
}

.header-badge {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    font-size: 0.75rem;
    color: var(--caution);
    background: #fef5e7;
    padding: 6px 14px;
    border-radius: 20px;
    font-weight: 500;
    border: 1px solid #f9e2b3;
}

.badge-dot {
    width: 7px;
    height: 7px;
    background: var(--caution);
    border-radius: 50%;
    animation: pulse-dot 2s ease-in-out infinite;
}

@keyframes pulse-dot {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

/* --- Progress Bar --- */
.progress-container {
    margin-bottom: var(--space-lg);
}

.progress-bar {
    height: 4px;
    background: var(--border-light);
    border-radius: 2px;
    overflow: hidden;
    margin-bottom: var(--space-sm);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, var(--primary), var(--primary-light));
    border-radius: 2px;
    transition: width 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    width: 16.67%;
}

.progress-steps {
    display: flex;
    justify-content: space-between;
    gap: var(--space-xs);
}

.progress-step-label {
    font-size: 0.65rem;
    color: var(--text-muted);
    text-align: center;
    flex: 1;
    transition: color 0.3s;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.progress-step-label.active {
    color: var(--primary);
    font-weight: 600;
}

.progress-step-label.completed {
    color: var(--success);
}

/* --- Steps --- */
.step {
    display: none;
    animation: fadeSlideIn 0.4s ease-out;
}

.step.active {
    display: block;
}

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

.step-header {
    display: flex;
    align-items: flex-start;
    gap: var(--space-md);
    margin-bottom: var(--space-xl);
    padding-bottom: var(--space-md);
    border-bottom: 2px solid var(--primary-pale);
}

.step-number {
    font-size: 2rem;
    font-weight: 700;
    color: var(--primary-light);
    opacity: 0.3;
    line-height: 1;
    font-family: var(--font-mono), monospace;
    flex-shrink: 0;
}

.step-title {
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 2px;
}

.step-desc {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

/* --- Question Cards --- */
.questions-grid {
    display: flex;
    flex-direction: column;
    gap: var(--space-md);
}

.question-card {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    transition: border-color 0.2s, box-shadow 0.2s;
}

.question-card:hover {
    border-color: var(--border);
    box-shadow: var(--shadow-sm);
}

.question-label {
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--text);
    margin-bottom: var(--space-xs);
}

.question-detail {
    font-size: 0.82rem;
    color: var(--text-secondary);
    margin-bottom: var(--space-md);
    line-height: 1.7;
}

/* --- Radio Buttons --- */
.radio-group {
    display: flex;
    gap: var(--space-md);
    flex-wrap: wrap;
}

.radio-group.inline {
    margin-top: var(--space-sm);
}

.radio-option {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
    font-size: 0.88rem;
    padding: 8px 18px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    transition: all 0.2s;
    user-select: none;
    background: var(--surface);
}

.radio-option:hover {
    border-color: var(--primary-light);
    background: var(--primary-bg);
}

.radio-option input[type="radio"] {
    display: none;
}

.radio-custom {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    border: 2px solid var(--border);
    position: relative;
    flex-shrink: 0;
    transition: border-color 0.2s;
}

.radio-custom::after {
    content: '';
    position: absolute;
    inset: 3px;
    border-radius: 50%;
    background: var(--primary);
    transform: scale(0);
    transition: transform 0.2s;
}

.radio-option input[type="radio"]:checked ~ .radio-custom {
    border-color: var(--primary);
}

.radio-option input[type="radio"]:checked ~ .radio-custom::after {
    transform: scale(1);
}

.radio-option:has(input:checked) {
    border-color: var(--primary);
    background: var(--primary-bg);
}

/* --- Select --- */
.select-wrapper {
    position: relative;
}

.select-wrapper select {
    width: 100%;
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-family: var(--font-main);
    background: var(--surface);
    color: var(--text);
    appearance: none;
    cursor: pointer;
    transition: border-color 0.2s;
}

.select-wrapper select:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(41,128,185,0.12);
}

.select-wrapper::after {
    content: '▾';
    position: absolute;
    right: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-muted);
    pointer-events: none;
    font-size: 0.9rem;
}

/* --- Input Fields --- */
.input-row {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: var(--space-md);
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
}

.input-group label {
    font-size: 0.78rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.criteria-hint {
    color: var(--primary-light);
    font-weight: 600;
    font-size: 0.72rem;
}

.input-group input[type="number"] {
    padding: 10px 14px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: var(--font-main);
    background: var(--surface);
    color: var(--text);
    transition: border-color 0.2s;
    -moz-appearance: textfield;
}

.input-group input[type="number"]::-webkit-outer-spin-button,
.input-group input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
}

.input-group input[type="number"]:focus {
    outline: none;
    border-color: var(--primary-light);
    box-shadow: 0 0 0 3px rgba(41,128,185,0.12);
}

.input-group input.invalid {
    border-color: var(--accent);
    background: #fef5f5;
}

.input-group input.valid {
    border-color: var(--success);
    background: #f3faf6;
}

/* --- Lab Card --- */
.lab-card {
    border-left: 3px solid var(--primary-light);
}

.lab-header {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-bottom: var(--space-md);
}

.lab-icon {
    font-size: 1.2rem;
}

.lab-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: var(--space-md);
    margin-bottom: var(--space-sm);
}

/* --- Checkbox --- */
.checkbox-inline {
    margin-top: var(--space-sm);
    padding-top: var(--space-sm);
    border-top: 1px dashed var(--border-light);
}

.checkbox-option {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.checkbox-option input[type="checkbox"] {
    display: none;
}

.checkbox-custom {
    width: 16px;
    height: 16px;
    border: 1.5px solid var(--border);
    border-radius: 3px;
    flex-shrink: 0;
    position: relative;
    transition: all 0.2s;
}

.checkbox-option input:checked ~ .checkbox-custom {
    background: var(--primary);
    border-color: var(--primary);
}

.checkbox-option input:checked ~ .checkbox-custom::after {
    content: '✓';
    position: absolute;
    inset: 0;
    color: white;
    font-size: 0.65rem;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
}

/* --- Exclusion List --- */
.exclusion-list {
    display: flex;
    flex-direction: column;
    gap: var(--space-sm);
}

.exclusion-item {
    background: var(--surface);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: var(--space-md) var(--space-lg);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: var(--space-lg);
    transition: all 0.2s;
}

.exclusion-item:hover {
    border-color: var(--border);
}

.exclusion-item:has(input[value="yes"]:checked) {
    border-color: var(--accent);
    background: var(--accent-soft);
    border-left: 3px solid var(--accent);
}

.exclusion-q {
    font-size: 0.85rem;
    color: var(--text);
    flex: 1;
    line-height: 1.65;
}

.exclusion-q .note {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-top: 3px;
    font-style: italic;
}

/* --- Navigation --- */
.nav-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-lg) 0;
    margin-top: var(--space-md);
    border-top: 1px solid var(--border-light);
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: var(--space-sm);
    padding: 10px 24px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.88rem;
    font-family: var(--font-main);
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
}

.btn:disabled {
    opacity: 0.35;
    cursor: not-allowed;
}

.btn-back {
    background: var(--surface);
    color: var(--text-secondary);
    border: 1.5px solid var(--border);
}

.btn-back:hover:not(:disabled) {
    background: var(--surface-alt);
    color: var(--text);
}

.btn-next {
    background: var(--primary);
    color: white;
}

.btn-next:hover:not(:disabled) {
    background: var(--primary-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-next.submit {
    background: var(--success);
}

.btn-next.submit:hover:not(:disabled) {
    background: #27ae60;
}

.step-indicator {
    font-size: 0.8rem;
    color: var(--text-muted);
    font-weight: 500;
    font-family: var(--font-mono), monospace;
}

/* --- Results Overlay --- */
.results-overlay {
    position: fixed;
    inset: 0;
    background: rgba(28, 40, 51, 0.5);
    backdrop-filter: blur(6px);
    z-index: 1000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--space-md);
    animation: fadeIn 0.3s ease;
}

.results-overlay.visible {
    display: flex;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.results-panel {
    background: var(--surface);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    max-width: 720px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
    padding: var(--space-2xl);
    position: relative;
    animation: slideUp 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

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

.results-close {
    position: absolute;
    top: var(--space-md);
    right: var(--space-md);
    width: 36px;
    height: 36px;
    border: none;
    background: var(--surface-alt);
    border-radius: 50%;
    font-size: 1.3rem;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.results-close:hover {
    background: var(--border-light);
    color: var(--text);
}

/* Results content */
.result-verdict {
    text-align: center;
    margin-bottom: var(--space-xl);
}

.verdict-icon {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 2rem;
    margin-bottom: var(--space-md);
}

.verdict-icon.eligible {
    background: var(--success-bg);
    color: var(--success);
}

.verdict-icon.ineligible {
    background: var(--accent-soft);
    color: var(--accent);
}

.verdict-icon.caution {
    background: var(--warning-bg);
    color: var(--warning);
}

.verdict-title {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: var(--space-xs);
}

.verdict-title.eligible { color: var(--success); }
.verdict-title.ineligible { color: var(--accent); }
.verdict-title.caution { color: var(--caution); }

.verdict-subtitle {
    font-size: 0.88rem;
    color: var(--text-secondary);
}

.result-section {
    margin-bottom: var(--space-lg);
}

.result-section-title {
    font-size: 0.78rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    margin-bottom: var(--space-sm);
    padding-bottom: var(--space-xs);
    border-bottom: 1px solid var(--border-light);
}

.result-item {
    display: flex;
    align-items: flex-start;
    gap: var(--space-sm);
    padding: var(--space-sm) 0;
    font-size: 0.85rem;
    line-height: 1.6;
}

.result-item .icon-pass {
    color: var(--success);
    flex-shrink: 0;
    font-weight: 700;
}

.result-item .icon-fail {
    color: var(--accent);
    flex-shrink: 0;
    font-weight: 700;
}

.result-item .icon-warn {
    color: var(--caution);
    flex-shrink: 0;
    font-weight: 700;
}

.result-summary {
    background: var(--surface-alt);
    border: 1px solid var(--border-light);
    border-radius: var(--radius-md);
    padding: var(--space-lg);
    margin-top: var(--space-lg);
}

.result-summary p {
    font-size: 0.82rem;
    color: var(--text-secondary);
    line-height: 1.7;
}

.result-stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: var(--space-md);
    margin-bottom: var(--space-lg);
}

.stat-box {
    text-align: center;
    padding: var(--space-md);
    border-radius: var(--radius-md);
    border: 1px solid var(--border-light);
}

.stat-number {
    font-size: 1.6rem;
    font-weight: 700;
    font-family: var(--font-mono), monospace;
}

.stat-number.green { color: var(--success); }
.stat-number.red { color: var(--accent); }
.stat-number.yellow { color: var(--caution); }

.stat-label {
    font-size: 0.7rem;
    color: var(--text-muted);
    margin-top: 2px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.btn-reset {
    display: block;
    width: 100%;
    margin-top: var(--space-lg);
    padding: 12px;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 0.9rem;
    font-family: var(--font-main);
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s;
}

.btn-reset:hover {
    background: var(--primary-light);
}

/* --- Footer --- */
.app-footer {
    text-align: center;
    padding: var(--space-lg) 0 var(--space-2xl);
    border-top: 1px solid var(--border-light);
    margin-top: var(--space-md);
}

.app-footer p {
    font-size: 0.75rem;
    color: var(--text-muted);
    line-height: 1.6;
}

/* --- Validation shake --- */
@keyframes shake {
    0%, 100% { transform: translateX(0); }
    25% { transform: translateX(-4px); }
    75% { transform: translateX(4px); }
}

.shake {
    animation: shake 0.3s ease-in-out;
}

/* --- Toast --- */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-size: 0.85rem;
    z-index: 2000;
    opacity: 0;
    transition: all 0.3s;
    white-space: nowrap;
}

.toast.visible {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

/* --- Responsive --- */
@media (max-width: 640px) {
    html { font-size: 14px; }

    .header-inner {
        flex-direction: column;
        align-items: flex-start;
    }

    .exclusion-item {
        flex-direction: column;
        align-items: flex-start;
        gap: var(--space-sm);
    }

    .input-row {
        grid-template-columns: 1fr;
    }

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

    .result-stats {
        grid-template-columns: 1fr;
    }

    .results-panel {
        padding: var(--space-lg);
    }
}
