/* ============================================================
   Expert interface — mobile-first, large touch targets, readable.
   Optimized for older users in clinical settings.
   ============================================================ */

:root {
    --expert-bg: #f4f6fa;
    --expert-card: #ffffff;
    --expert-text: #1a1d24;
    --expert-muted: #4a4f5c;
    --expert-primary: #2563eb;
    --expert-primary-dark: #1e4fc4;
    --expert-yes: #16a34a;
    --expert-yes-dark: #128140;
    --expert-no: #dc2626;
    --expert-no-dark: #b91c1c;
    --expert-border: #d8dde6;
    --expert-radius: 12px;
    --expert-radius-lg: 16px;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    background: var(--expert-bg);
    color: var(--expert-text);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Roboto", "Helvetica Neue", Arial, sans-serif;
    font-size: 17px;
    line-height: 1.45;
    -webkit-text-size-adjust: 100%;
    overscroll-behavior-y: none;
}

body {
    min-height: 100vh;
    min-height: 100dvh;
}

/* --- Cards --- */
.expert-card {
    background: var(--expert-card);
    margin: 12px;
    padding: 1.25rem;
    border-radius: var(--expert-radius-lg);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.05);
}

.expert-card--center {
    text-align: center;
    padding: 2rem 1.5rem;
    max-width: 480px;
    margin: 24px auto;
}

.expert-card h1 {
    font-size: 1.4rem;
    margin: 0 0 0.5rem;
    line-height: 1.3;
}

.muted {
    color: var(--expert-muted);
}

/* --- Top bar --- */
.expert-top {
    background: var(--expert-card);
    padding: 0.85rem 1rem 1rem;
    position: sticky;
    top: 0;
    z-index: 10;
    box-shadow: 0 1px 0 rgba(0, 0, 0, 0.05);
}

.expert-top__meta {
    display: flex;
    gap: 1.25rem;
    margin-bottom: 0.6rem;
    font-size: 0.95rem;
    flex-wrap: wrap;
}

.expert-top__progress {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.progress-text {
    font-weight: 600;
    font-size: 0.95rem;
    min-width: 5.5rem;
    color: var(--expert-muted);
}

.progress-bar {
    flex: 1;
    height: 10px;
    background: #e7eaf0;
    border-radius: 999px;
    overflow: hidden;
}

.progress-bar__fill {
    height: 100%;
    background: var(--expert-primary);
    transition: width 0.25s ease;
}

/* --- Start form --- */
.start-form {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    margin-top: 1rem;
}

.expert-field {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    border: none;
    padding: 0;
    margin: 0;
}

.expert-field__label {
    font-size: 1rem;
    font-weight: 600;
    color: var(--expert-text);
}

.expert-field__error {
    color: var(--expert-no);
    font-size: 0.95rem;
    font-weight: 500;
}

.expert-input {
    font-size: 1.4rem;
    padding: 0.95rem 1rem;
    border: 2px solid var(--expert-border);
    border-radius: var(--expert-radius);
    background: #fff;
    color: var(--expert-text);
    min-height: 56px;
    width: 100%;
    font-family: inherit;
    -webkit-appearance: none;
    appearance: none;
}

.expert-input:focus {
    outline: 3px solid var(--expert-primary);
    outline-offset: 1px;
    border-color: var(--expert-primary);
}

.expert-field input[type="text"],
.expert-field input[type="number"],
.expert-field input:not([type]) {
    font-size: 1.4rem;
    padding: 0.95rem 1rem;
    border: 2px solid var(--expert-border);
    border-radius: var(--expert-radius);
    background: #fff;
    color: var(--expert-text);
    min-height: 56px;
    width: 100%;
}

.expert-field input:focus {
    outline: 3px solid var(--expert-primary);
    outline-offset: 1px;
    border-color: var(--expert-primary);
}

.variant-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.6rem;
}

.variant-btn {
    font-size: 1.5rem;
    font-weight: 700;
    padding: 1.1rem 0;
    border: 2px solid var(--expert-border);
    border-radius: var(--expert-radius);
    background: #fff;
    color: var(--expert-text);
    cursor: pointer;
    min-height: 72px;
    transition: background 0.1s, border-color 0.1s, color 0.1s;
}

.variant-btn:hover {
    background: #f0f3fa;
}

.variant-btn--active,
.variant-btn--active:hover {
    background-color: var(--expert-primary);
    background-image: none;
    border-color: var(--expert-primary);
    color: #fff;
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.25);
    -webkit-text-fill-color: #fff;
}

/* --- Big buttons --- */
.big-btn {
    font-size: 1.2rem;
    font-weight: 700;
    padding: 1.1rem 1.5rem;
    border: none;
    border-radius: var(--expert-radius);
    cursor: pointer;
    min-height: 64px;
    width: 100%;
    transition: background 0.1s, transform 0.05s;
    box-sizing: border-box;
}
.big-btn:active:not(:disabled) {
    transform: translateY(1px);
}

.big-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.big-btn--primary {
    background: var(--expert-primary);
    color: #fff;
}

.big-btn--primary:hover:not(:disabled) {
    background: var(--expert-primary-dark);
}

/* --- Questions list --- */
.expert-questions {
    padding: 0.75rem 0.75rem 7rem;    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.q-global {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--expert-primary-dark);
    margin: 0.5rem 0.25rem 0.25rem;
    padding-bottom: 0.35rem;
    border-bottom: 2px solid var(--expert-primary);
}

.q-local {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--expert-muted);
    margin: 0.25rem 0.25rem 0;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.q-item {
    background: var(--expert-card);
    border-radius: var(--expert-radius);
    padding: 0.9rem 0.9rem 0.8rem;
    display: flex;
    flex-direction: column;
    gap: 0.7rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}
.q-item__num {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--expert-muted);
}

.q-item__text {
    font-size: 1.05rem;
    line-height: 1.4;
    overflow-wrap: break-word;
    word-break: break-word;
    hyphens: auto;
}

.q-item__buttons {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
}

.ans-btn {
    font-size: 1.25rem;
    font-weight: 700;
    padding: 0.95rem 0;
    border: 2px solid var(--expert-border);
    border-radius: var(--expert-radius);
    background: #fff;
    color: var(--expert-text);
    cursor: pointer;
    min-height: 60px;
    transition: background 0.1s, color 0.1s, border-color 0.1s;
}

.ans-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.ans-btn--yes.ans-btn--selected,
.ans-btn--yes:active:not(:disabled) {
    background: var(--expert-yes);
    border-color: var(--expert-yes);
    color: #fff;
}

.ans-btn--no.ans-btn--selected,
.ans-btn--no:active:not(:disabled) {
    background: var(--expert-no);
    border-color: var(--expert-no);
    color: #fff;
}

/* Persistent selected state wins over the brief :active feedback */
.ans-btn--yes.ans-btn--selected:active:not(:disabled) {
    background: var(--expert-yes-dark);
    border-color: var(--expert-yes-dark);
}

.ans-btn--no.ans-btn--selected:active:not(:disabled) {
    background: var(--expert-no-dark);
    border-color: var(--expert-no-dark);
}

/* --- Bottom action bar --- */
.expert-bottom {
    position: fixed;
    left: 0;
    right: 0;
    bottom: 0;
    padding: 0.85rem 0.85rem calc(0.85rem + env(safe-area-inset-bottom));
    background: linear-gradient(to top, var(--expert-bg) 70%, rgba(244, 246, 250, 0));
    z-index: 20;
}

.expert-bottom .big-btn {
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.25);
}

.finish-error {
    background: #fef2f2;
    border: 2px solid var(--expert-no);
    color: #7f1d1d;
    padding: 0.75rem 0.9rem;
    border-radius: var(--expert-radius);
    margin-bottom: 0.6rem;
    font-size: 0.95rem;
    font-weight: 600;
    line-height: 1.35;
    text-align: center;
    box-sizing: border-box;
    width: 100%;
}
/* Highlight + pulse for the question that blocked a "Завершить" tap. */
.q-item--pulse {
    background: #fee2e2;
    box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.2);
    animation: q-pulse 1.4s ease-in-out 0s 3;
}
@keyframes q-pulse {
    0%, 100% { background: var(--expert-card); }
    50% { background: #fee2e2; }
}

@media (prefers-reduced-motion: reduce) {
    .q-item--pulse { animation: none; }
}

.done-banner {
    background: #ecfdf3;
    border: 2px solid #16a34a;
    color: #14532d;
    padding: 1rem 1.1rem;
    border-radius: var(--expert-radius);
    text-align: center;
}

.done-banner p {
    margin: 0.25rem 0 0;
    color: #166534;
}

/* --- Code input auto-complete suggestions --- */
.code-input-wrap {
    position: relative;
}

.code-suggestions {
    position: absolute;
    left: 0;
    right: 0;
    top: 100%;
    z-index: 30;
    background: var(--expert-card);
    border: 2px solid var(--expert-border);
    border-top: none;
    border-radius: 0 0 var(--expert-radius) var(--expert-radius);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
    max-height: 280px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.code-suggestions__item {
    display: block;
    width: 100%;
    padding: 0.85rem 1rem;
    border: none;
    background: transparent;
    color: var(--expert-text);
    font-size: 1.15rem;
    font-family: inherit;
    text-align: left;
    cursor: pointer;
    min-height: 48px;
    transition: background 0.1s;
}

.code-suggestions__item:hover,
.code-suggestions__item:focus {
    background: #f0f3fa;
    outline: none;
}

.code-suggestions__item + .code-suggestions__item {
    border-top: 1px solid #f0f2f7;
}
/* --- Tablet / small desktop: cap the width for readability --- */
@media (min-width: 600px) {
    .expert-card { margin: 20px auto; max-width: 560px; }
    .expert-top { max-width: 700px; margin: 0 auto; }
    .expert-questions { max-width: 700px; margin: 0 auto; }
    /* Footer stays full-width (gradient seamless); only children are capped. */
    .expert-bottom { left: 0; right: 0; transform: none; }
    .expert-bottom > * { max-width: 700px; margin-left: auto; margin-right: auto; box-sizing: border-box; }
}