/* ─── Бренд: синий #1678ff + белый текст, шрифт Mulish ─────────────── */
:root {
    --brand: #1678ff;
    --brand-deep: #0e5ec4;
    --bg: #1678ff;
    --text: #ffffff;
    --hint: rgba(255, 255, 255, 0.78);
    --separator: rgba(255, 255, 255, 0.14);
    --button: #ffffff;
    --button-text: #1678ff;
    --ghost: rgba(255, 255, 255, 0.85);
    --sheet-bg: #ffffff;
    --sheet-text: #15233a;
    --sheet-hint: #6b7a90;
    --sheet-border: rgba(0, 0, 0, 0.06);
    --good: #34c759;
    --bad: #ff453a;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: 'Mulish', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    font-weight: 500;
    font-size: 16px;
    overflow: hidden;
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
    overscroll-behavior: none;
}

button { font-family: inherit; }

/* ─── Экраны ────────────────────────────────────────────────────────── */

.screen {
    position: fixed;
    inset: 0;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 24px;
    text-align: center;
}
.screen.visible { display: flex; }

/* ─── Сканер ────────────────────────────────────────────────────────── */

#screen-scanner {
    padding: 0;
    background: #000;
    overflow: hidden;
}
#cam {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    background: #000;
}

.scanner-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* top: место под подсказку; bottom: место под фонарик + кнопки */
    padding: 70px 0 calc(200px + env(safe-area-inset-bottom));
    pointer-events: none;
}

/* Затемнение по бокам через box-shadow трюк — окно «вырезает» в тёмном слое */
.scanner-frame {
    position: relative;
    width: min(72vw, 300px);
    aspect-ratio: 1 / 1;
    border-radius: 18px;
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.62);
    transition: transform .25s ease, box-shadow .25s ease;
}
.scanner-frame.found {
    transform: scale(1.04);
    box-shadow: 0 0 0 9999px rgba(22, 120, 255, 0.55);
}

.corner {
    position: absolute;
    width: 28px;
    height: 28px;
    border: 3px solid #ffffff;
    transition: border-color .25s ease;
}
.corner.tl { top: -3px; left: -3px; border-right: none; border-bottom: none; border-top-left-radius: 18px; }
.corner.tr { top: -3px; right: -3px; border-left: none; border-bottom: none; border-top-right-radius: 18px; }
.corner.bl { bottom: -3px; left: -3px; border-right: none; border-top: none; border-bottom-left-radius: 18px; }
.corner.br { bottom: -3px; right: -3px; border-left: none; border-top: none; border-bottom-right-radius: 18px; }
.scanner-frame.found .corner { border-color: #ffffff; }

.hint {
    position: absolute;
    top: calc(20px + env(safe-area-inset-top));
    left: 0;
    right: 0;
    width: 100%;
    text-align: center;
    color: #ffffff;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: 0.2px;
    text-shadow: 0 1px 4px rgba(0, 0, 0, 0.55);
    margin: 0;
    pointer-events: none;
}

/* ─── Фонарик ───────────────────────────────────────────────────────── */

.flash-btn {
    position: absolute;
    bottom: calc(120px + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%);
    width: 56px;
    height: 56px;
    border-radius: 50%;
    border: none;
    background: rgba(255, 255, 255, 0.16);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: background .2s, transform .1s;
    z-index: 5;
}
.flash-btn:active { transform: translateX(-50%) scale(0.95); }
.flash-btn.on {
    background: #ffffff;
    color: var(--brand);
}
.flash-btn svg { width: 26px; height: 26px; }

/* ─── Нижние кнопки «Файл / Ссылка» ─────────────────────────────────── */

.bottom-actions {
    position: absolute;
    left: 0;
    right: 0;
    bottom: calc(20px + env(safe-area-inset-bottom));
    display: flex;
    gap: 12px;
    padding: 0 20px;
    z-index: 5;
}
.action-btn {
    flex: 1;
    background: rgba(255, 255, 255, 0.14);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.22);
    border-radius: 14px;
    padding: 14px 12px;
    color: #ffffff;
    font-family: inherit;
    font-weight: 600;
    font-size: 15px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    cursor: pointer;
    transition: background .15s, transform .1s;
}
.action-btn:active { transform: scale(0.97); background: rgba(255, 255, 255, 0.26); }
.action-btn svg { width: 20px; height: 20px; }

/* ─── Модалка вставки ссылки ────────────────────────────────────────── */

.modal {
    position: fixed;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 100;
    padding: 24px;
}
.modal.visible { display: flex; }

.modal-card {
    width: 100%;
    max-width: 360px;
    background: #ffffff;
    color: var(--sheet-text);
    border-radius: 18px;
    padding: 22px;
    text-align: left;
}
.modal-card h3 {
    margin: 0 0 14px;
    font-size: 18px;
    font-weight: 700;
}
.modal-card input {
    width: 100%;
    padding: 14px 16px;
    border: 1px solid var(--sheet-border);
    border-radius: 12px;
    font-family: inherit;
    font-size: 15px;
    color: var(--sheet-text);
    margin-bottom: 14px;
    -webkit-appearance: none;
    background: #f6f7fb;
    outline: none;
}
.modal-card input:focus {
    border-color: var(--brand);
    background: #ffffff;
}
.modal-card .btn-primary { background: var(--brand); color: #ffffff; }
.modal-card .btn-ghost { color: var(--sheet-hint); }

/* ─── Спиннер / загрузка ────────────────────────────────────────────── */

.spinner {
    width: 56px;
    height: 56px;
    border: 4px solid rgba(255, 255, 255, 0.25);
    border-top-color: #ffffff;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin-bottom: 18px;
}
@keyframes spin { to { transform: rotate(360deg); } }
#loading-text { color: var(--hint); font-weight: 600; }

/* ─── Превью / bottom-sheet ─────────────────────────────────────────── */

.sheet-host {
    justify-content: flex-end;
    padding: 0;
    background: rgba(0, 0, 0, 0.4);
}
.sheet {
    width: 100%;
    background: var(--sheet-bg);
    color: var(--sheet-text);
    border-top-left-radius: 24px;
    border-top-right-radius: 24px;
    padding: 14px 22px calc(22px + env(safe-area-inset-bottom));
    transform: translateY(100%);
    transition: transform .35s cubic-bezier(0.32, 0.72, 0, 1);
    box-shadow: 0 -8px 32px rgba(0, 0, 0, 0.35);
}
.screen.visible .sheet { transform: translateY(0); }

.sheet-handle {
    width: 40px;
    height: 4px;
    background: var(--sheet-border);
    border-radius: 2px;
    margin: 0 auto 18px;
}
.sheet h2 {
    margin: 0 0 16px;
    font-size: 20px;
    font-weight: 800;
    text-align: left;
    color: var(--sheet-text);
}

.row {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    padding: 12px 0;
    border-top: 1px solid var(--sheet-border);
    text-align: left;
}
.row:first-of-type { border-top: none; }
.row-label { color: var(--sheet-hint); font-size: 14px; font-weight: 600; }
.row-value { font-size: 15px; font-weight: 600; max-width: 60%; text-align: right; word-break: break-word; color: var(--sheet-text); }
.row.total .row-value { font-size: 24px; font-weight: 800; color: var(--brand); }
.row.balance { border-top-style: dashed; }

/* ─── Кнопки ────────────────────────────────────────────────────────── */

.btn {
    width: 100%;
    border: none;
    border-radius: 14px;
    padding: 16px;
    font-family: inherit;
    font-size: 17px;
    font-weight: 700;
    margin-top: 10px;
    cursor: pointer;
    transition: transform .1s, opacity .15s;
    -webkit-appearance: none;
}
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #ffffff; }
.btn-ghost { background: transparent; color: var(--sheet-hint); }

/* На синем фоне (success/error/loading) у нас белые кнопки */
#screen-loading .btn-primary,
#screen-success .btn-primary,
#screen-error .btn-primary {
    background: #ffffff;
    color: var(--brand);
}
#screen-loading .btn-ghost,
#screen-success .btn-ghost,
#screen-error .btn-ghost {
    color: rgba(255, 255, 255, 0.78);
}

/* ─── Финальные экраны ──────────────────────────────────────────────── */

.result-icon {
    width: 120px;
    height: 120px;
    margin-bottom: 22px;
}
.result-icon svg { width: 100%; height: 100%; overflow: visible; }
.result-icon .circle {
    stroke: currentColor;
    stroke-width: 4;
    stroke-dasharray: 226;
    stroke-dashoffset: 226;
    animation: draw-circle 0.5s ease forwards;
}
.result-icon .check, .result-icon .cross {
    stroke: currentColor;
    stroke-width: 6;
    stroke-linecap: round;
    stroke-linejoin: round;
    fill: none;
}
.result-icon .check { stroke-dasharray: 70; stroke-dashoffset: 70; animation: draw-stroke 0.4s 0.4s ease forwards; }
.result-icon .cross { stroke-dasharray: 40; stroke-dashoffset: 40; animation: draw-stroke 0.3s 0.4s ease forwards; }
.result-icon.success { color: #ffffff; }
.result-icon.error   { color: #ffffff; }
@keyframes draw-circle { to { stroke-dashoffset: 0; } }
@keyframes draw-stroke { to { stroke-dashoffset: 0; } }

#screen-success h2,
#screen-error h2 {
    margin: 0 0 8px;
    font-size: 26px;
    font-weight: 800;
}
.muted {
    color: var(--hint);
    margin: 0 0 24px;
    max-width: 320px;
    line-height: 1.4;
    white-space: pre-line;
}
#screen-success .btn,
#screen-error .btn { max-width: 320px; }

.desktop-icon {
    width: 96px;
    height: 144px;
    margin: 0 auto 24px;
    display: block;
    color: rgba(255, 255, 255, 0.92);
}

/* Build-id маркер в правом нижнем углу — для проверки что свежий JS загрузился */
#build-tag {
    position: fixed;
    right: 6px;
    bottom: calc(4px + env(safe-area-inset-bottom));
    font-size: 10px;
    color: rgba(255, 255, 255, 0.45);
    letter-spacing: 0.2px;
    pointer-events: none;
    z-index: 9999;
    font-family: monospace;
}
