:root {
    --brand-blue: #0F206C;
    --brand-blue-dark: #0A174E;
    --brand-blue-soft: #EEF3FF;
    --brand-pink: #E55496;
    --brand-pink-soft: #FDF0F6;
    --bg: #F6F8FF;
    --surface: #FFFFFF;
    --surface-soft: #FAFBFF;
    --text: #17203F;
    --muted: #64708D;
    --line: rgba(15, 32, 108, 0.14);
    --line-strong: rgba(15, 32, 108, 0.22);
    --shadow: 0 8px 24px rgba(15, 32, 108, 0.08);
    --danger: #C9435B;
    --success: #1F8A63;
}

* {
    box-sizing: border-box;
}

html,
body {
    min-height: 100%;
}

body {
    margin: 0;
    font-family: Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
}

.topbar {
    height: 56px;
    background: var(--brand-blue);
    color: #ffffff;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 22px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
}

.topbar-left {
    font-size: 18px;
    letter-spacing: -0.01em;
}

.topbar-status {
    display: inline-flex;
    align-items: center;
    min-height: 28px;
    padding: 5px 12px;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.18);
    font-size: 14px;
    color: rgba(255, 255, 255, 0.94);
    text-decoration: none;
}

.topbar-status:hover {
    background: rgba(255, 255, 255, 0.18);
    border-color: rgba(255, 255, 255, 0.28);
}


.layout {
    display: flex;
    min-height: calc(100vh - 56px);
}

.sidebar {
    width: 220px;
    background: #ffffff;
    color: var(--text);
    padding: 20px;
    border-right: 1px solid var(--line);
    box-sizing: border-box;
}

.menu-title {
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    margin-bottom: 12px;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.menu-item {
    display: block;
    color: var(--brand-blue);
    text-decoration: none;
    padding: 10px 12px;
    background: var(--brand-blue-soft);
    border: 1px solid transparent;
    border-radius: 8px;
    font-weight: 700;
}

.menu-item:hover {
    border-color: var(--line-strong);
}

.menu-item.active {
    color: #ffffff;
    background: var(--brand-blue);
    border-color: var(--brand-blue);
}

.sidebar-actions {
    margin-top: 18px;
    padding-top: 16px;
    border-top: 1px solid var(--line);
}

.sidebar-export-btn {
    width: 100%;
    min-height: 42px;
    padding: 10px 12px;
    background: var(--brand-pink);
    border-color: var(--brand-pink);
    text-align: center;
}

.sidebar-export-btn:hover {
    background: #cf3f82;
    border-color: #cf3f82;
}

.sidebar-export-btn:disabled {
    opacity: 0.72;
    cursor: wait;
}

.sidebar-export-status {
    margin-top: 10px;
    padding: 9px 10px;
    border: 1px solid rgba(15, 32, 108, 0.16);
    border-radius: 8px;
    background: var(--brand-blue-soft);
    color: var(--brand-blue);
    font-size: 12px;
    line-height: 1.35;
}

.sidebar-export-status.is-warning {
    border-color: rgba(15, 32, 108, 0.16);
    background: var(--brand-blue-soft);
    color: var(--muted);
}

.sidebar-export-status.is-success {
    border-color: rgba(31, 138, 99, 0.24);
    background: #EEF9F4;
    color: var(--success);
}

.sidebar-export-status.is-error {
    border-color: rgba(201, 67, 91, 0.22);
    background: #FFF1F4;
    color: var(--danger);
}

.content {
    flex: 1;
    padding: 24px;
    box-sizing: border-box;
}

.page-header {
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--line);
}

.page-header h1 {
    margin: 0 0 8px 0;
    color: var(--brand-blue);
    font-size: 28px;
    line-height: 1.2;
}

.page-header p {
    margin: 0;
    color: var(--muted);
    line-height: 1.45;
}

.grid-2 {
    display: grid;
    grid-template-columns: minmax(520px, 1.15fr) minmax(420px, 0.85fr);
    gap: 20px;
    align-items: start;
}

.card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 20px;
    box-shadow: var(--shadow);
}

.card h2 {
    margin-top: 0;
    margin-bottom: 16px;
    color: var(--brand-blue);
    font-size: 20px;
    line-height: 1.25;
}

.form-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 8px;
}

input[type="text"],
input[type="file"],
textarea {
    width: 100%;
    box-sizing: border-box;
    padding: 9px 10px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    margin-bottom: 6px;
    background: #ffffff;
    color: var(--text);
    font: inherit;
    outline: none;
}

input[type="text"]:focus,
input[type="file"]:focus,
textarea:focus {
    border-color: var(--brand-pink);
    box-shadow: 0 0 0 3px rgba(229, 84, 150, 0.12);
}

input[type="text"]::placeholder,
textarea::placeholder {
    color: #99A2B8;
}

button {
    padding: 10px 16px;
    border: 1px solid var(--brand-blue);
    background: var(--brand-blue);
    color: #ffffff;
    border-radius: 8px;
    cursor: pointer;
    font: inherit;
    font-weight: 700;
}

button:hover {
    background: var(--brand-blue-dark);
    border-color: var(--brand-blue-dark);
}

button:focus-visible {
    outline: 3px solid rgba(229, 84, 150, 0.22);
    outline-offset: 2px;
}

.hint {
    margin-top: 12px;
    font-size: 14px;
    color: var(--muted);
    line-height: 1.45;
}

.hint-message {
    margin-bottom: 16px;
    padding: 10px 12px;
    color: var(--text);
    background: var(--brand-pink-soft);
    border: 1px solid rgba(229, 84, 150, 0.20);
    border-radius: 8px;
}

.empty-box {
    margin-top: 16px;
    border: 1px dashed rgba(15, 32, 108, 0.28);
    border-radius: 8px;
    padding: 40px 20px;
    text-align: center;
    color: var(--muted);
    background: var(--surface-soft);
}

.meta {
    margin-top: 12px;
    padding: 9px 10px;
    border-left: 3px solid var(--brand-blue);
    border-radius: 6px;
    background: var(--brand-blue-soft);
    color: var(--muted);
    font-size: 14px;
}

.meta strong {
    color: var(--brand-blue);
}

.preview-tools {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-top: 14px;
    margin-bottom: 10px;
    flex-wrap: nowrap;
}

.preview-tools-left,
.preview-tools-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.preview-tools-right {
    margin-left: auto;
    gap: 12px;
}

.preview-tool-btn {
    padding: 8px 12px;
    min-width: 42px;
    font-size: 14px;
    color: var(--brand-blue);
    background: #ffffff;
    border-color: var(--line-strong);
}

.preview-tool-btn:hover {
    color: #ffffff;
    background: var(--brand-blue);
    border-color: var(--brand-blue);
}

.preview-zoom-value {
    min-width: 58px;
    text-align: center;
    font-size: 14px;
    color: var(--brand-blue);
    font-weight: 700;
}

.preview-box {
    margin-top: 10px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: #ffffff;
    overflow: hidden;
}

.preview-viewport {
    width: 100%;
    height: 620px;
    overflow: auto;
    background: #F0F3FA;
    cursor: default;
}

.preview-viewport.is-dragging {
    cursor: grabbing;
}

.preview-stage {
    min-width: 100%;
    min-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 12px;
    box-sizing: border-box;
}

.preview-stage.is-zoomed {
    align-items: flex-start;
    justify-content: flex-start;
}

.preview-image {
    display: block;
    user-select: none;
    -webkit-user-drag: none;
    box-shadow: 0 2px 8px rgba(15, 32, 108, 0.12);
}

.compact-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px 14px;
    align-items: start;
}

.field {
    display: flex;
    flex-direction: column;
}

.field label {
    margin-bottom: 4px;
    color: #394461;
    font-size: 14px;
    font-weight: 700;
}

.field-wide {
    grid-column: 1 / -1;
}

textarea {
    resize: vertical;
    min-height: 42px;
}

.inline-form {
    margin: 0;
    display: flex;
    align-items: center;
}

#recognize-btn.is-loading {
    opacity: 0.85;
    cursor: wait;
}

#recognize-btn .btn-loader {
    font-weight: 700;
}

.btn-secondary {
    background: var(--success);
    border-color: var(--success);
}

.btn-secondary:hover {
    background: #176D4F;
    border-color: #176D4F;
}

@media (max-width: 1180px) {
    .grid-2 {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 760px) {
    .topbar {
        height: auto;
        min-height: 56px;
        align-items: flex-start;
        flex-direction: column;
        gap: 8px;
        padding: 12px 16px;
    }

    .layout {
        display: block;
        min-height: auto;
    }

    .sidebar {
        width: 100%;
        border-right: none;
        border-bottom: 1px solid var(--line);
        padding: 14px 16px;
    }

    .content {
        padding: 16px;
    }

    .compact-grid {
        grid-template-columns: 1fr;
    }

    .preview-tools {
        align-items: flex-start;
        flex-direction: column;
    }

    .preview-tools-right {
        width: 100%;
        margin-left: 0;
        flex-wrap: wrap;
    }

    .preview-viewport {
        height: 460px;
    }
}

/* Страница авторизации */
.auth-body {
    min-height: 100vh;
    background:
        linear-gradient(135deg, #ffffff 0%, var(--bg) 48%, #fbf3f8 100%);
    overflow: hidden;
}

.auth-neural-canvas {
    position: fixed;
    inset: 0;
    z-index: 0;
    width: 100vw;
    height: 100vh;
    opacity: 0.85;
    pointer-events: none;
}

.auth-page {
    position: relative;
    z-index: 1;
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 24px;
}

.auth-card {
    width: min(420px, 100%);
    border: 1px solid var(--line);
    border-radius: 14px;
    padding: 24px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: var(--shadow);
}

.auth-brand {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 26px;
    padding-bottom: 18px;
    border-bottom: 1px solid var(--line);
}

.auth-brand-mark {
    display: grid;
    place-items: center;
    flex: 0 0 46px;
    width: 46px;
    height: 46px;
    border-radius: 10px;
    color: #ffffff;
    background: var(--brand-blue);
    font-size: 14px;
    font-weight: 800;
    letter-spacing: 0.03em;
}

.auth-brand-title {
    color: var(--brand-blue);
    font-size: 18px;
    font-weight: 800;
    line-height: 1.2;
}

.auth-brand-subtitle {
    margin-top: 3px;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.3;
}

.auth-header {
    margin-bottom: 20px;
}

.auth-header h1 {
    margin: 0 0 8px;
    color: var(--brand-blue);
    font-size: 26px;
    line-height: 1.2;
}

.auth-header p {
    margin: 0;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

.auth-form {
    display: grid;
    gap: 14px;
}

.auth-field {
    display: grid;
    gap: 6px;
}

.auth-field label {
    color: #394461;
    font-size: 14px;
    font-weight: 700;
}

.auth-field input {
    width: 100%;
    margin: 0;
}

.auth-field input[type="password"] {
    box-sizing: border-box;
    padding: 9px 10px;
    border: 1px solid var(--line-strong);
    border-radius: 8px;
    background: #ffffff;
    color: var(--text);
    font: inherit;
    outline: none;
}

.auth-field input[type="password"]:focus {
    border-color: var(--brand-pink);
    box-shadow: 0 0 0 3px rgba(229, 84, 150, 0.12);
}

.auth-field input[type="password"]::placeholder {
    color: #99A2B8;
}

.auth-submit {
    width: 100%;
    min-height: 42px;
    margin-top: 4px;
}

.auth-note {
    margin: 16px 0 0;
    color: var(--muted);
    font-size: 13px;
    line-height: 1.4;
    text-align: center;
}

.auth-message {
    margin-bottom: 16px;
    padding: 10px 12px;
    border: 1px solid rgba(15, 32, 108, 0.18);
    border-radius: 8px;
    background: var(--brand-blue-soft);
    color: var(--brand-blue);
    font-size: 14px;
    line-height: 1.4;
}

.auth-message-error {
    border-color: rgba(201, 67, 91, 0.22);
    background: #FFF1F4;
    color: var(--danger);
}

@media (max-width: 520px) {
    .auth-page {
        padding: 16px;
    }

    .auth-card {
        padding: 20px;
    }

    .auth-brand {
        align-items: flex-start;
    }
}

/* Modal export result */
body.is-export-modal-open {
    overflow: hidden;
}

.export-modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 1000;
    display: grid;
    place-items: center;
    padding: 20px;
    background: rgba(15, 32, 108, 0.22);
}

.export-modal-overlay[hidden] {
    display: none !important;
}

.export-modal-card {
    position: relative;
    width: min(420px, 100%);
    border: 1px solid rgba(15, 32, 108, 0.14);
    border-radius: 16px;
    padding: 24px;
    background: #ffffff;
    box-shadow: 0 22px 70px rgba(15, 32, 108, 0.20);
}

.export-modal-x {
    position: absolute;
    top: 12px;
    right: 12px;
    width: 32px;
    height: 32px;
    padding: 0;
    border-radius: 999px;
    color: var(--brand-blue);
    background: var(--bg-soft);
    font-size: 22px;
    line-height: 1;
}

.export-modal-x:hover {
    background: #e8efff;
}

.export-modal-icon {
    display: grid;
    place-items: center;
    width: 42px;
    height: 42px;
    margin-bottom: 14px;
    border-radius: 999px;
    color: #ffffff;
    background: var(--brand-blue);
    font-size: 20px;
    font-weight: 800;
}

.export-modal-card h2 {
    margin: 0 36px 8px 0;
    color: var(--brand-blue);
    font-size: 22px;
    line-height: 1.25;
}

.export-modal-text {
    margin: 0 0 12px;
    color: var(--muted);
    font-size: 14px;
    line-height: 1.45;
}

.export-modal-list {
    margin: 0 0 20px;
    padding-left: 20px;
    color: var(--text);
    font-size: 14px;
    line-height: 1.45;
}

.export-modal-list li {
    margin: 7px 0;
}

.export-modal-list li::marker {
    color: var(--brand-pink);
    font-weight: 800;
}

.export-modal-close {
    width: 100%;
}



/* Export modal v5: strict internal portal style, without success icon or close cross */
.export-modal-card {
    width: min(440px, 100%);
    padding: 24px;
}

.export-modal-x,
.export-modal-icon {
    display: none !important;
}

.export-modal-card h2 {
    margin: 0 0 10px 0;
    color: var(--brand-blue);
    font-size: 21px;
    line-height: 1.25;
}

.export-modal-text {
    margin: 0 0 12px;
}

.export-modal-list[hidden] {
    display: none !important;
}

.export-modal-close {
    margin-top: 2px;
}
