:root {
    --bg: var(--tg-theme-bg-color, #ffffff);
    --text: var(--tg-theme-text-color, #1a1a1a);
    --hint: var(--tg-theme-hint-color, #888888);
    --link: var(--tg-theme-link-color, #2678b6);
    --btn: var(--tg-theme-button-color, #2678b6);
    --btn-text: var(--tg-theme-button-text-color, #ffffff);
    --secondary-bg: var(--tg-theme-secondary-bg-color, #f4f4f5);
    --destructive: var(--tg-theme-destructive-text-color, #e53935);
    --radius: 12px;
    --shadow: 0 1px 4px rgba(0,0,0,.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg);
    color: var(--text);
    font-size: 15px;
    line-height: 1.5;
    min-height: 100vh;
    overflow-x: hidden;
}

/* ── Screens ─────────────────────────────────── */
.screen { display: none; flex-direction: column; min-height: 100vh; padding: 16px; }
.screen.active { display: flex; }

/* ── Top bar ─────────────────────────────────── */
.topbar {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}
.topbar h2 { font-size: 18px; font-weight: 700; flex: 1; }
.topbar .subtitle { font-size: 13px; color: var(--hint); }

/* ── Cards ───────────────────────────────────── */
.card {
    background: var(--secondary-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
}

/* ── Buttons ─────────────────────────────────── */
.btn {
    display: block;
    width: 100%;
    padding: 14px 16px;
    border: none;
    border-radius: var(--radius);
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    text-align: center;
    transition: opacity .15s;
}
.btn:disabled { opacity: .5; cursor: default; }
.btn:active:not(:disabled) { opacity: .8; }

.btn-primary { background: var(--btn); color: var(--btn-text); }
.btn-secondary {
    background: var(--secondary-bg);
    color: var(--text);
    border: 1.5px solid rgba(0,0,0,.08);
}
.btn-danger { background: var(--destructive); color: #fff; }
.btn + .btn { margin-top: 10px; }

/* ── Home action buttons ─────────────────────── */
.action-btn {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 16px;
    background: var(--secondary-bg);
    border: none;
    border-radius: var(--radius);
    width: 100%;
    font-size: 15px;
    font-weight: 600;
    color: var(--text);
    cursor: pointer;
    margin-bottom: 10px;
    text-align: left;
    box-shadow: var(--shadow);
    transition: opacity .15s;
}
.action-btn:active { opacity: .7; }
.action-btn .icon { font-size: 28px; }
.action-btn .label { flex: 1; }
.action-btn .chevron { color: var(--hint); font-size: 18px; }

/* ── Forms ───────────────────────────────────── */
.form-group { margin-bottom: 14px; }
.form-group label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--hint);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 6px;
}
.form-group input,
.form-group textarea,
.form-group select {
    width: 100%;
    padding: 11px 13px;
    border: 1.5px solid rgba(0,0,0,.1);
    border-radius: 8px;
    font-size: 15px;
    background: var(--bg);
    color: var(--text);
    outline: none;
}
.form-group input:focus,
.form-group textarea:focus { border-color: var(--btn); }
.form-group textarea { resize: vertical; min-height: 72px; }

/* ── File input ──────────────────────────────── */
.file-input-wrapper {
    position: relative;
    border: 2px dashed rgba(0,0,0,.12);
    border-radius: var(--radius);
    padding: 28px 16px;
    text-align: center;
    margin-bottom: 16px;
    cursor: pointer;
    background: var(--secondary-bg);
}
.file-input-wrapper input[type="file"] {
    position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%;
}
.file-input-wrapper .file-icon { font-size: 36px; margin-bottom: 8px; }
.file-input-wrapper p { color: var(--hint); font-size: 14px; }

/* ── Image preview ───────────────────────────── */
#image-preview {
    width: 100%;
    max-height: 260px;
    object-fit: contain;
    border-radius: var(--radius);
    margin-bottom: 12px;
    display: none;
    background: var(--secondary-bg);
}

/* ── Badges ──────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 3px 9px;
    border-radius: 20px;
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .4px;
}
.badge-confirmed, .badge-success  { background: #d4edda; color: #1a7f37; }
.badge-extracted, .badge-uploaded { background: #cfe2ff; color: #0a58ca; }
.badge-processing, .badge-started { background: #fff3cd; color: #856404; }
.badge-pending                    { background: #e2e3e5; color: #41464b; }
.badge-failed                     { background: #f8d7da; color: #842029; }
.badge-draft                      { background: #e2e3e5; color: #41464b; }
.badge-rejected                   { background: #f8d7da; color: #842029; }

/* ── Document cards ──────────────────────────── */
.doc-card {
    background: var(--secondary-bg);
    border-radius: var(--radius);
    padding: 14px;
    margin-bottom: 10px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: opacity .15s;
}
.doc-card:active { opacity: .7; }
.doc-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
}
.doc-type { font-weight: 600; font-size: 14px; }
.doc-card-info { display: flex; justify-content: space-between; font-size: 13px; color: var(--hint); }
.doc-filename { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 65%; }
.doc-verification { margin-top: 8px; }
.doc-user { font-weight: 500; }

/* ── Log entries ─────────────────────────────── */
.log-entry {
    border-left: 3px solid #ddd;
    padding: 10px 12px;
    margin-bottom: 10px;
    border-radius: 0 8px 8px 0;
    background: var(--secondary-bg);
}
.log-success  { border-color: #1a7f37; }
.log-failed   { border-color: #842029; }
.log-started  { border-color: #856404; }
.log-header   { display: flex; justify-content: space-between; align-items: center; margin-bottom: 4px; }
.log-step     { font-weight: 600; font-size: 14px; }
.log-message  { font-size: 13px; color: var(--hint); margin-top: 4px; }
.log-time     { font-size: 11px; color: var(--hint); margin-top: 4px; display: block; }

/* ── Filters ─────────────────────────────────── */
.filters {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.filters select {
    flex: 1;
    min-width: 120px;
    padding: 8px 10px;
    border: 1.5px solid rgba(0,0,0,.1);
    border-radius: 8px;
    font-size: 13px;
    background: var(--bg);
    color: var(--text);
}
.filters .btn { width: auto; padding: 8px 16px; flex-shrink: 0; }

/* ── Utility ─────────────────────────────────── */
.loading-text, .empty-text { text-align: center; color: var(--hint); padding: 32px 0; }
.error-text   { text-align: center; color: var(--destructive); padding: 32px 0; }

.spinner {
    width: 36px; height: 36px;
    border: 3px solid rgba(0,0,0,.1);
    border-top-color: var(--btn);
    border-radius: 50%;
    animation: spin .7s linear infinite;
    margin: 40px auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.qr-hint { font-size: 13px; color: var(--hint); margin-bottom: 12px; min-height: 18px; }

/* ── Toast ───────────────────────────────────── */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(80px);
    background: #1a1a1a;
    color: #fff;
    padding: 11px 20px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 500;
    white-space: nowrap;
    opacity: 0;
    transition: all .25s ease;
    z-index: 9999;
    max-width: calc(100vw - 32px);
    text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.success { background: #1a7f37; }
.toast.error   { background: #842029; }

/* ── Loading splash ──────────────────────────── */
#screen-loading {
    justify-content: center;
    align-items: center;
    gap: 16px;
}
#screen-loading h2 { font-size: 20px; }

/* ── Home greeting ───────────────────────────── */
.greeting { margin-bottom: 24px; }
.greeting h1 { font-size: 22px; font-weight: 700; }
.greeting p  { color: var(--hint); font-size: 14px; margin-top: 2px; }

/* ── Section titles ──────────────────────────── */
.section-title {
    font-size: 12px;
    font-weight: 700;
    color: var(--hint);
    text-transform: uppercase;
    letter-spacing: .6px;
    margin-bottom: 10px;
    margin-top: 6px;
}

/* ── Page wrapper ────────────────────────────── */
.page {
    width: 100%;
    max-width: 480px;
    margin: 0 auto;
    padding-bottom: 32px;
}

/* ── Screen header ───────────────────────────── */
.screen-header {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 20px;
}
.screen-header h2 { font-size: 20px; font-weight: 700; }
.screen-icon { font-size: 28px; line-height: 1; }

.page-title { font-size: 18px; font-weight: 700; margin-bottom: 16px; }

/* ── Home hero ───────────────────────────────── */
.home-hero {
    padding: 24px 0 20px;
}
.home-greeting { font-size: 24px; font-weight: 700; }
.home-role { font-size: 14px; color: var(--hint); margin-top: 4px; }

/* ── Action grid (home) ──────────────────────── */
.action-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}
.action-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 20px 12px;
    background: var(--secondary-bg);
    border: none;
    border-radius: var(--radius);
    cursor: pointer;
    box-shadow: var(--shadow);
    transition: opacity .15s;
    color: var(--text);
    text-align: center;
}
.action-card:active { opacity: .7; }
.action-icon { font-size: 32px; line-height: 1; }
.action-label { font-size: 14px; font-weight: 600; }
.action-card-admin { grid-column: 1 / -1; }

/* ── File drop zone ──────────────────────────── */
.file-drop-zone {
    display: block;
    position: relative;
    border: 2px dashed rgba(0,0,0,.15);
    border-radius: var(--radius);
    padding: 0;
    text-align: center;
    margin-bottom: 14px;
    cursor: pointer;
    background: var(--secondary-bg);
    overflow: hidden;
    min-height: 160px;
    display: flex;
    align-items: center;
    justify-content: center;
}
.file-drop-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 32px 16px;
    color: var(--hint);
    font-size: 14px;
}
.file-drop-icon { font-size: 40px; margin-bottom: 4px; }
.file-drop-hint { font-size: 12px; opacity: .7; }

.image-preview {
    width: 100%;
    max-height: 260px;
    object-fit: contain;
    border-radius: var(--radius);
    display: none;
}

.visually-hidden {
    position: absolute;
    width: 1px; height: 1px;
    overflow: hidden;
    clip: rect(0 0 0 0);
    white-space: nowrap;
}

/* ── QR scan status ──────────────────────────── */
.qr-scan-hint {
    font-size: 13px;
    color: var(--hint);
    margin-bottom: 8px;
    display: none;
}
.qr-scan-status {
    font-size: 13px;
    min-height: 20px;
    margin-bottom: 14px;
    color: var(--hint);
}

/* ── Button full ─────────────────────────────── */
.btn-full { width: 100%; margin-top: 8px; }

/* ── Review hint ─────────────────────────────── */
.review-hint {
    font-size: 13px;
    color: var(--hint);
    margin-bottom: 20px;
    line-height: 1.5;
}

/* ── Form helpers ────────────────────────────── */
.form-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--hint);
    text-transform: uppercase;
    letter-spacing: .5px;
    margin-bottom: 6px;
}
.form-input {
    width: 100%;
    padding: 11px 13px;
    border: 1.5px solid rgba(0,0,0,.1);
    border-radius: 8px;
    font-size: 15px;
    background: var(--bg);
    color: var(--text);
    outline: none;
    font-family: inherit;
}
.form-input:focus { border-color: var(--btn); }
.form-textarea { resize: vertical; min-height: 72px; }

/* ── Card list ───────────────────────────────── */
.card-list { padding-top: 4px; }

/* ── Filter bar ──────────────────────────────── */
.filter-bar {
    display: flex;
    gap: 8px;
    margin-bottom: 14px;
    flex-wrap: wrap;
}
.filter-select {
    flex: 1;
    min-width: 120px;
    padding: 8px 10px;
    border: 1.5px solid rgba(0,0,0,.1);
    border-radius: 8px;
    font-size: 13px;
    background: var(--bg);
    color: var(--text);
    outline: none;
    font-family: inherit;
}
.filter-select:focus { border-color: var(--btn); }

/* ── Log list ────────────────────────────────── */
.log-list { padding-top: 4px; }

/* ── Loading container ───────────────────────── */
.loading-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    color: var(--hint);
    font-size: 14px;
}
.loading-container .spinner { margin: 0; }
