:root {
    --bg: #f5f7fb;
    --card: #ffffff;
    --border: #e1e6f0;
    --fg: #0e1116;
    --muted: #6b7280;
    --brand: #003DA5;
    --primary: #1e56c6;
    --primary-hover: #003DA5;
    --brand-soft: #e6ecf7;
    --ok: #1f9e4b;
    --bad: #d12e2e;
}
* { box-sizing: border-box; }
body {
    margin: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Inter", system-ui, sans-serif;
    background: var(--bg); color: var(--fg);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}
.container { max-width: 1200px; margin: 0 auto; padding: 2rem; }
h1, h2, h3 { margin-top: 0; color: var(--fg); }

/* Header */
header {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 1.5rem; padding-bottom: 1.25rem;
    border-bottom: 1px solid var(--border);
    gap: 1rem;
}
header .brand {
    display: flex; align-items: center; gap: .9rem;
    text-decoration: none; color: inherit;
}
header .logo { height: 32px; width: auto; border-radius: 4px; display: block; }
header h1 {
    font-size: 1.1rem; margin: 0;
    font-weight: 600; letter-spacing: -0.01em;
}
header h1 .sub {
    display: block; font-size: .8rem; font-weight: 400;
    color: var(--muted); margin-top: .1rem;
}
.doc-counter { font-size: .85rem; color: var(--muted); }
.doc-counter b { color: var(--brand); font-weight: 600; }

a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Tabs */
.tabs {
    display: flex; gap: .25rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1.5rem;
}
.tab {
    padding: .75rem 1.25rem; cursor: pointer;
    font-size: .95rem; font-weight: 500; color: var(--muted);
    border-bottom: 2px solid transparent;
    transition: all .15s ease;
    background: none; border-top: none; border-left: none; border-right: none;
    font-family: inherit;
    box-shadow: none;
    border-radius: 0;
}
.tab:hover { color: var(--fg); background: none; box-shadow: none; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); }

/* Buttons */
.btn, button.btn-primary {
    display: inline-flex; align-items: center; justify-content: center; gap: .4rem;
    padding: .55rem 1.1rem; border-radius: 7px;
    background: var(--primary); color: white; border: 1px solid var(--primary);
    cursor: pointer; font-size: .95rem; font-family: inherit; font-weight: 500;
    transition: all .14s ease;
    box-shadow: 0 1px 2px rgba(0, 61, 165, .18);
}
.btn:hover, button.btn-primary:hover {
    background: var(--primary-hover); border-color: var(--primary-hover);
    text-decoration: none; color: white;
    box-shadow: 0 2px 6px rgba(0, 61, 165, .28);
}
.btn:disabled, button.btn-primary:disabled {
    background: #9aa7bf; border-color: #9aa7bf; cursor: not-allowed;
    box-shadow: none;
}
.btn.secondary, button.btn-secondary {
    background: white; color: var(--brand);
    border: 1px solid var(--border); box-shadow: none;
}
.btn.secondary:hover, button.btn-secondary:hover {
    background: var(--brand-soft); border-color: var(--brand);
    color: var(--brand);
    box-shadow: none;
}
.btn.secondary:disabled, button.btn-secondary:disabled {
    color: var(--muted); cursor: not-allowed; background: white;
}

/* Cards */
.card {
    background: var(--card); border: 1px solid var(--border);
    border-radius: 10px; padding: 1.5rem; margin-bottom: 1rem;
    box-shadow: 0 1px 2px rgba(14, 17, 22, .04);
}
.card h3 { font-size: 1rem; margin-bottom: 1rem; }

/* Forms */
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 1rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.grid-1 { display: grid; grid-template-columns: 1fr; gap: 1rem; margin-top: 1rem; }
label {
    display: block; font-size: .85rem; color: var(--muted);
    margin-bottom: .3rem; font-weight: 500;
}
input[type=text], input[type=date], input[type=number],
input[type=password], input[type=email],
textarea, select {
    width: 100%; padding: .55rem .75rem; border-radius: 6px;
    border: 1px solid var(--border); background: white; color: var(--fg);
    font-family: inherit; font-size: .95rem;
}
textarea { min-height: 60px; resize: vertical; }
input:focus, textarea:focus, select:focus {
    border-color: var(--brand); outline: none;
    box-shadow: 0 0 0 3px rgba(0, 61, 165, .12);
}

/* File drop zone */
.file-drop {
    position: relative;
    display: flex; flex-direction: column;
    align-items: center; justify-content: center;
    padding: 2rem 1rem;
    border: 1.5px dashed var(--border); border-radius: 10px;
    background: #fafbff;
    cursor: pointer;
    transition: all .15s ease;
    text-align: center;
}
.file-drop:hover, .file-drop.is-dragging {
    border-color: var(--brand);
    background: var(--brand-soft);
}
.file-drop input[type=file] {
    position: absolute; inset: 0; opacity: 0; cursor: pointer;
}
.file-drop .icon {
    width: 34px; height: 34px; color: var(--brand);
    margin-bottom: .5rem;
}
.file-drop .title { font-weight: 500; font-size: .95rem; color: var(--fg); }
.file-drop .hint-line { font-size: .8rem; color: var(--muted); margin-top: .25rem; }

/* URL input */
.url-row {
    display: flex; align-items: center; gap: .75rem;
    margin-top: .75rem;
}
.url-row input { flex: 1; }
.url-row .divider {
    color: var(--muted); font-size: .78rem;
    text-transform: uppercase; letter-spacing: .05em;
    padding: 0 .25rem;
}

/* File list */
.file-list { margin-top: .75rem; display: flex; flex-direction: column; gap: .4rem; }
.file-item {
    display: flex; align-items: center; gap: .6rem;
    padding: .5rem .75rem;
    background: var(--brand-soft); border-radius: 6px;
    border: 1px solid var(--border);
}
.file-item .icon { font-size: 1.1rem; }
.file-item .name { flex: 1; font-size: .9rem; color: var(--fg); word-break: break-all; }
.file-item .remove {
    cursor: pointer; color: var(--bad); font-size: 1rem;
    border: none; background: none; padding: .15rem .5rem;
    box-shadow: none; border-radius: 4px;
}
.file-item .remove:hover { background: rgba(209, 46, 46, .1); color: var(--bad); box-shadow: none; }

/* Recognize bar */
.recognize-bar {
    margin-top: 1rem; display: flex; gap: .75rem; align-items: center;
}

/* Status message */
.status-msg {
    margin-top: .75rem; padding: .75rem 1rem; border-radius: 7px;
    font-size: .9rem; display: flex; align-items: center; gap: .5rem;
}
.status-msg.processing { background: #fff8e1; color: #8a5a00; border: 1px solid #f4dfa8; }
.status-msg.success { background: #e8f6ed; color: #1b6e38; border: 1px solid #c7e5d1; }
.status-msg.error { background: #fbe7e7; color: #a02525; border: 1px solid #f3c2c2; }

/* Spinner */
.spinner {
    display: inline-block; width: 16px; height: 16px;
    border: 2px solid rgba(0, 61, 165, .2);
    border-top-color: var(--brand);
    border-radius: 50%;
    animation: spin .8s linear infinite;
    vertical-align: middle;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Actions */
.actions { margin-top: 1.25rem; display: flex; gap: .75rem; }

/* Filters */
.filters {
    display: flex; flex-direction: column; gap: .85rem;
    margin-bottom: 1rem;
    padding: 1rem 1.1rem; background: var(--card);
    border: 1px solid var(--border); border-radius: 12px;
}
.filter-row {
    display: flex; gap: .75rem; flex-wrap: wrap;
    align-items: flex-end;
}
.filter-group { display: flex; flex-direction: column; min-width: 120px; }
.filter-group.flex-1 { flex: 1 1 260px; }
.filter-group label {
    font-size: .7rem; text-transform: uppercase;
    letter-spacing: .04em; color: var(--muted);
    margin-bottom: .3rem; font-weight: 500;
}
.filter-group input, .filter-group select {
    padding: .45rem .7rem; font-size: .9rem;
    border: 1px solid var(--border); border-radius: 8px;
    background: #fff; color: var(--fg);
    transition: border-color .15s, box-shadow .15s;
    font-family: inherit;
}
.filter-group input:focus, .filter-group select:focus {
    outline: none; border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}
.filter-group input[type=date] { min-width: 140px; }
.filter-group select {
    appearance: none; -webkit-appearance: none; -moz-appearance: none;
    padding-right: 1.8rem; cursor: pointer;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none'><path d='M1 1.5L6 6.5L11 1.5' stroke='%23003DA5' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'/></svg>");
    background-repeat: no-repeat;
    background-position: right .6rem center;
}

.btn-reset {
    align-self: flex-end; margin-left: auto;
    background: transparent; border: 1px solid var(--border);
    color: var(--muted); padding: .45rem .85rem;
    border-radius: 8px; font-size: .85rem; cursor: pointer;
    transition: all .15s;
}
.btn-reset:hover {
    color: var(--brand); border-color: var(--brand);
    background: var(--brand-soft);
}

/* Table */
.docs-table {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: 0 1px 2px rgba(14, 17, 22, .04);
}
.docs-table .scroll { overflow-x: auto; }
.docs-table table { width: 100%; border-collapse: collapse; min-width: 900px; }
.docs-table th {
    text-align: left; padding: .75rem .9rem;
    color: var(--muted); font-weight: 500;
    font-size: .75rem; text-transform: uppercase;
    letter-spacing: .03em;
    background: #fafbff;
    border-bottom: 1px solid var(--border);
    white-space: nowrap;
}
.docs-table td {
    padding: .6rem .9rem;
    border-bottom: 1px solid var(--border);
    font-size: .82rem;
    vertical-align: top;
}
.docs-table tr:last-child td { border-bottom: none; }
.docs-table tr:hover td { background: var(--brand-soft); }
.docs-table .amount { font-weight: 600; white-space: nowrap; text-align: right; }
.docs-table .date { white-space: nowrap; color: var(--muted); }
.docs-table .sender { color: var(--muted); }
.docs-table .comment { color: var(--muted); }
.badge {
    display: inline-block; padding: .15rem .55rem; border-radius: 4px;
    background: var(--brand-soft); color: var(--brand);
    font-size: .78rem; font-weight: 500;
    white-space: nowrap;
}
.act-cell {
    white-space: nowrap; text-align: right;
}
.act-cell .icon-btn + .icon-btn { margin-left: .2rem; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 30px; height: 30px; padding: 0;
    border: 1px solid var(--border); border-radius: 7px;
    background: #fff; color: var(--brand);
    cursor: pointer; text-decoration: none;
    transition: all .15s;
    box-shadow: none;
}
.icon-btn svg { width: 16px; height: 16px; display: block; }
.icon-btn:hover {
    background: var(--brand-soft); border-color: var(--brand);
    color: var(--brand); text-decoration: none;
}
.icon-btn.icon-delete { color: var(--bad); }
.icon-btn.icon-delete:hover {
    background: rgba(209, 46, 46, .08);
    border-color: var(--bad); color: var(--bad);
}
.icon-btn.is-disabled {
    opacity: .3; cursor: default; pointer-events: none;
    background: #fafbff;
}
.total-row td {
    background: #fafbff !important;
    font-weight: 600;
    border-top: 2px solid var(--border);
}
.empty { text-align: center; padding: 3rem; color: var(--muted); }

/* Login box */
.login-box {
    max-width: 400px; margin: 3rem auto;
}
.login-box .error {
    color: var(--bad); font-size: .85rem;
    margin-bottom: .5rem; display: none;
}
.login-box input { margin-bottom: .75rem; }

/* User select overlay */
.user-overlay {
    position: fixed; inset: 0;
    background: rgba(14, 17, 22, .5);
    display: flex; align-items: center; justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(2px);
}
.user-box {
    background: var(--card); border-radius: 12px;
    padding: 2rem; width: 380px; max-width: 92vw;
    box-shadow: 0 12px 40px rgba(0, 61, 165, .18);
    border: 1px solid var(--border);
}
.user-box h2 { font-size: 1.15rem; margin-bottom: .35rem; }
.user-box .hint {
    font-size: .85rem; color: var(--muted);
    margin-bottom: 1.25rem;
}
.user-list {
    display: flex; flex-direction: column; gap: .4rem;
    margin-bottom: 1rem;
}
.user-btn {
    width: 100%;
    padding: .7rem 1rem;
    background: #fafbff;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: .95rem; text-align: left;
    color: var(--fg);
    cursor: pointer;
    transition: all .15s ease;
    box-shadow: none;
}
.user-btn:hover {
    background: var(--brand-soft);
    border-color: var(--brand);
    color: var(--brand);
    box-shadow: none;
}
.or-divider {
    display: flex; align-items: center; gap: .75rem;
    color: var(--muted); font-size: .78rem;
    text-transform: uppercase; letter-spacing: .05em;
    margin: .75rem 0;
}
.or-divider::before, .or-divider::after {
    content: ""; flex: 1; height: 1px; background: var(--border);
}
.new-user-form { display: none; }
.new-user-form.visible { display: block; }
.new-user-form .row-inline {
    display: flex; gap: .5rem; margin-bottom: .75rem;
}
.new-user-form .row-inline input { flex: 1; }

.w-full { width: 100%; }

@media (max-width: 700px) {
    .container { padding: 1rem; }
    .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .filter-row { flex-direction: column; align-items: stretch; }
    .filter-group input[type=text] { min-width: 0; }
    .btn-reset { align-self: stretch; margin-left: 0; }
    header { flex-direction: column; align-items: flex-start; gap: .5rem; }
    .tab { padding: .6rem .85rem; font-size: .88rem; }
}
