:root {
    --bg: #f6faf7;
    --surface: #ffffff;
    --surface-2: #edf6f1;
    --surface-3: #dceee5;
    --text: #16241f;
    --muted: #5f6f68;
    --primary: #146b58;
    --primary-strong: #0c4f40;
    --accent: #d94f45;
    --warning: #b7791f;
    --border: #bed4ca;
    --danger: #b3261e;
    --ok: #1d7f55;
    --radius: 8px;
}

* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    min-height: 100%;
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    color: var(--text);
    background: var(--bg);
}

body {
    line-height: 1.35;
}

button,
input,
select,
textarea {
    font: inherit;
}

button {
    min-height: 44px;
    border-radius: var(--radius);
    border: 1px solid transparent;
    font-weight: 700;
    cursor: pointer;
    transition: background 0.16s ease, border-color 0.16s ease, transform 0.16s ease;
}

button:active {
    transform: translateY(1px);
}

button:disabled {
    cursor: not-allowed;
    opacity: 0.55;
}

input,
select,
textarea {
    width: 100%;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 10px;
    color: var(--text);
    background: #fff;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible {
    outline: 2px solid rgba(20, 107, 88, 0.28);
    outline-offset: 2px;
}

textarea {
    min-height: 90px;
    resize: vertical;
}

label {
    display: block;
    font-size: 13px;
    font-weight: 700;
    color: var(--muted);
    margin: 10px 0 5px;
}

.type-combobox {
    position: relative;
}

.combobox-dropdown {
    position: absolute;
    left: 0;
    right: 0;
    top: calc(100% + 4px);
    z-index: 15;
    max-height: 238px;
    overflow: auto;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    box-shadow: 0 10px 24px rgba(20, 107, 88, 0.14);
}

.combobox-option {
    width: 100%;
    min-height: 38px;
    display: flex;
    align-items: center;
    padding: 8px 10px;
    border: 0;
    border-radius: 0;
    background: #fff;
    color: var(--text);
    font-weight: 600;
    text-align: left;
}

.combobox-option:hover,
.combobox-option.highlighted {
    background: var(--surface-2);
}

.combobox-option.create {
    color: var(--primary-strong);
    border-top: 1px solid var(--border);
}

.field-hint {
    min-height: 18px;
    margin-top: 4px;
    color: var(--muted);
    font-size: 12px;
}

h1,
h2 {
    margin: 0;
}

.hidden {
    display: none !important;
}

.auth-page {
    min-height: 100vh;
    display: grid;
    place-items: center;
    padding: 18px;
}

.auth-box {
    width: min(420px, 100%);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 20px;
    box-shadow: 0 16px 40px rgba(22, 36, 31, 0.08);
}

.stack {
    display: grid;
    gap: 8px;
}

.brand-mark {
    width: 54px;
    height: 54px;
    display: block;
    margin-bottom: 10px;
    border-radius: var(--radius);
}

.brand-mark.small {
    width: 42px;
    height: 42px;
    margin: 0;
}

.muted,
.meta {
    color: var(--muted);
    font-size: 13px;
}

.app-shell {
    width: min(720px, 100%);
    margin: 0 auto;
    padding: 10px 10px 18px;
}

.topbar {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    box-shadow: 0 8px 26px rgba(22, 36, 31, 0.06);
}

.brand-row {
    display: flex;
    gap: 10px;
    align-items: center;
    min-width: 0;
}

.brand-row h1 {
    font-size: 21px;
}

.tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    margin: 10px 0;
}

.tab {
    background: var(--surface-2);
    border-color: var(--border);
    color: var(--primary-strong);
    min-height: 46px;
}

.tab.is-active {
    background: var(--primary);
    color: #fff;
}

.panel {
    display: none;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 14px;
    box-shadow: 0 12px 34px rgba(22, 36, 31, 0.06);
}

.panel.is-active {
    display: block;
}

.capture-flow {
    display: grid;
    gap: 12px;
}

.capture-actions {
    display: grid;
    gap: 10px;
    justify-items: center;
    padding: 4px 0 2px;
}

.submit-row,
.search-row {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.search-row input {
    flex: 1 1 220px;
}

.search-row select {
    flex: 0 1 170px;
}

.primary {
    background: var(--primary);
    color: #fff;
}

.primary:hover {
    background: var(--primary-strong);
}

.secondary,
.secondary-link {
    border: 1px solid var(--border);
    background: #fff;
    color: var(--primary-strong);
}

.secondary-link {
    display: inline-flex;
    min-height: 42px;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius);
    text-decoration: none;
    font-weight: 700;
}

.danger {
    background: #fff;
    color: var(--danger);
    border-color: #e0aaa5;
}

.wide {
    flex: 1 1 220px;
}

.btn-icon {
    width: 22px;
    height: 22px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    flex: 0 0 auto;
}

.btn-icon svg {
    width: 100%;
    height: 100%;
    display: block;
    fill: currentColor;
}

.capture-primary,
.capture-secondary,
.read-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
}

.capture-primary {
    width: min(340px, 100%);
    min-height: 68px;
    font-size: 18px;
    box-shadow: 0 14px 28px rgba(20, 107, 88, 0.22);
}

.capture-secondary {
    width: min(300px, 100%);
    min-height: 52px;
}

.read-btn {
    min-height: 52px;
}

.page-count-row {
    display: flex;
    justify-content: space-between;
    gap: 10px;
    align-items: center;
}

.page-strip {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    gap: 8px;
    min-height: 0;
}

.page-tile,
.doc-row,
.preview-tile {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
}

.page-tile {
    padding: 6px;
}

.page-tile img {
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    border-radius: 6px;
    display: block;
}

.page-tile footer {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 5px;
    margin-top: 6px;
    font-size: 12px;
}

.tiny {
    min-height: 30px;
    padding: 4px 8px;
}

.document-list {
    display: grid;
    gap: 8px;
    margin-top: 10px;
}

.doc-row {
    width: 100%;
    text-align: left;
    padding: 12px;
    position: relative;
    overflow: hidden;
}

.doc-row.is-processing::before {
    content: "";
    position: absolute;
    inset: 0 auto 0 0;
    width: 4px;
    background: var(--warning);
}

.doc-row.is-processing::after {
    content: "";
    position: absolute;
    left: 0;
    right: 0;
    top: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--primary), transparent);
    animation: scanMove 1.4s linear infinite;
}

.doc-row h3 {
    margin: 0 0 5px;
    font-size: 16px;
}

.doc-meta,
.badge-row {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    min-height: 24px;
    border-radius: 6px;
    padding: 3px 7px;
    font-size: 12px;
    font-weight: 700;
    background: var(--surface-2);
    color: var(--primary-strong);
}

.mini-spinner {
    width: 12px;
    height: 12px;
    border: 2px solid currentColor;
    border-right-color: transparent;
    border-radius: 50%;
    display: inline-block;
    animation: spin 0.8s linear infinite;
}

.badge.warn {
    background: #fff4dd;
    color: var(--warning);
}

.badge.error {
    background: #ffe9e6;
    color: var(--danger);
}

.badge.ok {
    background: #e6f5ee;
    color: var(--ok);
}

.message {
    min-height: 22px;
    font-size: 13px;
    color: var(--ok);
}

.message.error,
.error {
    color: var(--danger);
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(10, 20, 16, 0.58);
    padding: 10px;
    overflow: auto;
    z-index: 20;
}

.detail-box {
    width: min(900px, 100%);
    margin: 0 auto;
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    padding: 12px;
}

.detail-head {
    display: flex;
    justify-content: space-between;
    gap: 8px;
    align-items: center;
}

.grid-2,
.grid-3 {
    display: grid;
    gap: 8px;
}

.grid-2 {
    grid-template-columns: repeat(2, minmax(0, 1fr));
}

.grid-3 {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

.status-line {
    margin: 8px 0;
}

.status-line.is-processing {
    padding: 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface-2);
}

.review-box {
    margin: 10px 0;
    padding: 10px;
    border: 1px solid #e3c079;
    border-radius: var(--radius);
    background: #fff8e8;
    color: #744900;
    font-size: 13px;
}

.detail-pages {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 8px;
    margin: 10px 0;
}

.preview-tile {
    padding: 6px;
}

.preview-tile img {
    width: 100%;
    aspect-ratio: 3 / 4;
    object-fit: cover;
    border-radius: 6px;
    display: block;
}

.install-prompt,
.processing-widget {
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: var(--surface);
    padding: 12px;
    margin: 10px 0;
    box-shadow: 0 10px 28px rgba(22, 36, 31, 0.07);
}

.install-prompt {
    display: flex;
    gap: 10px;
    align-items: center;
    justify-content: space-between;
}

.install-prompt.compact {
    margin: 12px 0;
    box-shadow: none;
}

.install-prompt p,
.processing-widget p {
    margin: 3px 0 0;
    color: var(--muted);
    font-size: 13px;
}

.processing-widget {
    display: grid;
    grid-template-columns: 56px 1fr;
    gap: 12px;
    align-items: center;
}

.processing-widget.is-done {
    border-color: #9dceb7;
    background: #f0faf5;
}

.processing-widget.is-error {
    border-color: #e0aaa5;
    background: #fff5f3;
}

.scan-indicator {
    width: 52px;
    height: 52px;
    border: 1px solid var(--border);
    border-radius: var(--radius);
    background: #fff;
    position: relative;
    overflow: hidden;
}

.scan-indicator::before {
    content: "";
    position: absolute;
    inset: 8px;
    border: 2px solid var(--surface-3);
    border-radius: 5px;
}

.scan-indicator span {
    position: absolute;
    left: 8px;
    right: 8px;
    top: 10px;
    height: 3px;
    border-radius: 3px;
    background: var(--primary);
    animation: scanLine 1.25s ease-in-out infinite alternate;
}

.process-steps {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 6px;
    margin-top: 9px;
}

.process-steps span {
    min-height: 25px;
    border: 1px solid var(--border);
    border-radius: 6px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    background: #fff;
    font-size: 12px;
    font-weight: 700;
}

.process-steps span.is-active,
.process-steps span.is-complete {
    border-color: var(--primary);
    background: var(--surface-2);
    color: var(--primary-strong);
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

@keyframes scanLine {
    from {
        transform: translateY(0);
    }
    to {
        transform: translateY(29px);
    }
}

@keyframes scanMove {
    from {
        transform: translateX(-100%);
    }
    to {
        transform: translateX(100%);
    }
}

@media (max-width: 680px) {
    .grid-2,
    .grid-3 {
        grid-template-columns: 1fr;
    }

    .capture-actions button,
    .submit-row button {
        flex: 1 1 150px;
    }

    .app-shell {
        padding: 8px 8px 16px;
    }

    .topbar {
        padding: 10px;
    }

    .brand-row h1 {
        font-size: 20px;
    }

    .panel {
        padding: 12px;
    }

    .install-prompt {
        align-items: stretch;
        flex-direction: column;
    }

    .processing-widget {
        grid-template-columns: 46px 1fr;
    }

    .scan-indicator {
        width: 46px;
        height: 46px;
    }
}
