:root {
    --ink: #17212b;
    --ink-soft: #5a6b7b;
    --line: #dfe5ec;
    --bg: #f4f6f9;
    --surface: #ffffff;
    --brand: #123a5e;
    --brand-accent: #2e8bc0;
    --ok: #1f7a4d;
    --ok-bg: #e5f4ec;
    --error: #a32c2c;
    --error-bg: #fbeaea;
    --warn: #8a6100;
    --warn-bg: #fdf3dc;
    --radius: 8px;
    --header-h: 56px;
    --footer-h: 40px;
    --nav-w: 208px;
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
    margin: 0;
    font-family: "Segoe UI", Roboto, system-ui, -apple-system, sans-serif;
    font-size: 14px;
    color: var(--ink);
    background: var(--bg);
}

/* ---------------------------------------------------------------- header */

.app-header {
    height: var(--header-h);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 20px;
    background: var(--brand);
    color: #fff;
}

.brand { display: flex; align-items: baseline; gap: 8px; }

.brand-mark {
    font-size: 19px;
    font-weight: 700;
    letter-spacing: 1.5px;
}

.brand-mark.alt { color: var(--brand-accent); }

.brand-sub {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    opacity: .65;
}

.session { display: flex; align-items: center; gap: 14px; }
.session-user { display: flex; align-items: center; gap: 8px; }
.session-name { font-weight: 600; }
.logout-form { margin: 0; }

/* ------------------------------------------------------------------ body */

.app-body {
    display: flex;
    min-height: calc(100vh - var(--header-h) - var(--footer-h));
}

.app-nav {
    width: var(--nav-w);
    flex: 0 0 var(--nav-w);
    background: var(--surface);
    border-right: 1px solid var(--line);
    padding: 16px 0;
}

.nav-item {
    display: block;
    padding: 10px 20px;
    color: var(--ink);
    text-decoration: none;
    border-left: 3px solid transparent;
}

.nav-item:hover { background: var(--bg); }

.nav-item.active {
    border-left-color: var(--brand-accent);
    background: var(--bg);
    font-weight: 600;
}

.nav-group {
    margin: 18px 0 6px;
    padding: 0 20px;
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--ink-soft);
}

.app-main { flex: 1; padding: 24px 28px; min-width: 0; }

.page-title { margin: 0 0 20px; font-size: 22px; font-weight: 600; }

/* ---------------------------------------------------------------- footer */

.app-footer {
    height: var(--footer-h);
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 0 20px;
    background: var(--surface);
    border-top: 1px solid var(--line);
    color: var(--ink-soft);
    font-size: 12px;
}

.sep { opacity: .4; }
.footer-product { font-weight: 600; letter-spacing: 1px; color: var(--brand); }

/* --------------------------------------------------------------- pieces */

.panel {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px;
    margin-bottom: 20px;
}

.panel h2 { margin: 0 0 12px; font-size: 15px; }

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
    margin-bottom: 22px;
}

.card {
    display: block;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    padding: 18px 20px;
    text-decoration: none;
    color: inherit;
}

.card:hover { border-color: var(--brand-accent); }
.card h2 { margin: 0 0 6px; font-size: 15px; color: var(--brand); }
.card p { margin: 0; color: var(--ink-soft); }

.detail { display: grid; grid-template-columns: 120px 1fr; gap: 6px 12px; margin: 0; }
.detail dt { color: var(--ink-soft); }
.detail dd { margin: 0; }

.grid {
    width: 100%;
    border-collapse: collapse;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius);
    overflow: hidden;
}

.grid th, .grid td {
    padding: 10px 14px;
    text-align: left;
    border-bottom: 1px solid var(--line);
}

.grid th {
    background: #eef2f6;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: .5px;
    color: var(--ink-soft);
}

.grid tbody tr:last-child td { border-bottom: none; }
.grid .num { text-align: right; font-variant-numeric: tabular-nums; }
.grid .actions { text-align: right; }
.row-muted td { opacity: .55; }
.muted { color: var(--ink-soft); }
.empty { color: var(--ink-soft); font-style: italic; }

.badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    background: #eef2f6;
    color: var(--ink-soft);
}

.badge-role { background: rgba(46, 139, 192, .15); color: var(--brand); }
.badge-ok { background: var(--ok-bg); color: var(--ok); }
.badge-error { background: var(--error-bg); color: var(--error); }
.badge-warn { background: var(--warn-bg); color: var(--warn); }

.alert {
    padding: 10px 14px;
    border-radius: var(--radius);
    margin-bottom: 16px;
}

.alert-ok { background: var(--ok-bg); color: var(--ok); }
.alert-error { background: var(--error-bg); color: var(--error); }
.alert ul { margin: 0; padding-left: 18px; }
.validation:empty { display: none; }
.validation ul { list-style: none; padding: 0; }

.btn {
    display: inline-block;
    padding: 8px 14px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    background: var(--surface);
    color: var(--ink);
    font-size: 13px;
    cursor: pointer;
}

.btn:hover { border-color: var(--brand-accent); }
.btn-small { padding: 4px 10px; font-size: 12px; }
.btn-block { width: 100%; }

.btn-primary {
    background: var(--brand);
    border-color: var(--brand);
    color: #fff;
    font-weight: 600;
}

.btn-primary:hover { background: #17486f; }

.btn-ghost {
    background: transparent;
    border-color: rgba(255, 255, 255, .35);
    color: #fff;
}

.btn-ghost:hover { background: rgba(255, 255, 255, .12); }

/* ---------------------------------------------------------------- login */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(160deg, #123a5e 0%, #0d283f 100%);
}

.login-shell { width: 100%; max-width: 380px; padding: 20px; }

.login-card {
    background: var(--surface);
    border-radius: 12px;
    padding: 28px 26px;
    box-shadow: 0 18px 40px rgba(0, 0, 0, .25);
}

.login-brand { text-align: center; }
.login-brand .brand-mark { color: var(--brand); font-size: 26px; }
.login-brand .brand-mark.alt { color: var(--brand-accent); }

.login-sub {
    margin: 4px 0 22px;
    text-align: center;
    color: var(--ink-soft);
    font-size: 12px;
}

.login-note { color: var(--ink-soft); margin: 0 0 18px; }

.login-footer {
    margin-top: 18px;
    text-align: center;
    color: rgba(255, 255, 255, .6);
    font-size: 12px;
}

.stack { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field span { font-size: 12px; font-weight: 600; color: var(--ink-soft); }

.field input {
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
}

.field input:focus {
    outline: none;
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px rgba(46, 139, 192, .15);
}

.link-muted { text-align: center; color: var(--ink-soft); font-size: 13px; }

@media (max-width: 720px) {
    .app-body { flex-direction: column; }
    .app-nav { width: 100%; flex: none; display: flex; flex-wrap: wrap; padding: 8px; }
    .nav-item { border-left: none; border-bottom: 3px solid transparent; }
    .nav-item.active { border-left: none; border-bottom-color: var(--brand-accent); }
    .nav-group { width: 100%; margin: 6px 0 0; }
    .app-main { padding: 18px 16px; }
}

/* ------------------------------------------------------------ forms/toolbar */

.toolbar {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-bottom: 14px;
}

.form-panel { max-width: 720px; }

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 14px 18px;
}

.form-grid .span-2 { grid-column: 1 / -1; }

.field select {
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    background: var(--surface);
}

.field select:focus {
    outline: none;
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px rgba(46, 139, 192, .15);
}

.field-error {
    font-size: 12px;
    font-weight: 400;
    color: var(--error);
}

.field-error:empty { display: none; }

.check-row {
    display: flex;
    flex-wrap: wrap;
    gap: 18px;
    padding-top: 4px;
}

.check {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 13px;
    color: var(--ink);
}

.check input { width: 16px; height: 16px; accent-color: var(--brand-accent); }

.form-actions {
    display: flex;
    gap: 10px;
    padding-top: 6px;
    border-top: 1px solid var(--line);
    margin-top: 4px;
}

@media (max-width: 640px) {
    .form-grid { grid-template-columns: 1fr; }
}

/* ------------------------------------------------------------ documents toolbar */

.toolbar form { margin: 0; }
.toolbar-info { margin-right: auto; align-self: center; font-size: 12px; }

.upload-form {
    display: flex;
    align-items: center;
    gap: 8px;
}

.upload-form input[type="file"] { font-size: 12px; max-width: 260px; }

/* ------------------------------------------------------------ settings */

.field textarea {
    padding: 9px 11px;
    border: 1px solid var(--line);
    border-radius: var(--radius);
    font-size: 14px;
    font-family: inherit;
    line-height: 1.45;
    resize: vertical;
    min-height: 44px;
}

.field textarea:focus {
    outline: none;
    border-color: var(--brand-accent);
    box-shadow: 0 0 0 3px rgba(46, 139, 192, .15);
}

.field .hint { font-weight: 400; font-style: normal; opacity: .8; margin-left: 4px; }

.form-panel-wide { max-width: 960px; }

.filter-form { display: flex; align-items: center; gap: 8px; margin-right: auto; }
.field-inline { flex-direction: row; align-items: center; gap: 8px; }
.field-inline select { padding: 6px 10px; font-size: 13px; }

.field-group { margin-bottom: 18px; }
.field-group-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.field-group-head h2 { margin: 0; display: flex; align-items: center; gap: 8px; }

.grid .tags { white-space: normal; }
.grid .tags .badge { margin: 1px 2px 1px 0; }
.grid .clip { max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.settings-panel { margin-bottom: 18px; }
.settings-panel .col-label { width: 220px; }
.settings-panel .col-key { width: 280px; }
.setting-value code { word-break: break-all; }
.setting-value .badge { margin-left: 6px; }
code { font-family: Consolas, "Cascadia Mono", monospace; font-size: 12px; }

/* ------------------------------------------------------------ documents: selection */

.grid .col-check { width: 36px; text-align: center; }
.grid .col-check input { width: 16px; height: 16px; accent-color: var(--brand-accent); cursor: pointer; vertical-align: middle; }
#documents-grid tbody tr { cursor: default; }
.grid tr.row-selected td { background: rgba(46, 139, 192, .08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary:disabled:hover { background: var(--brand); }

/* ------------------------------------------------------------ modal dialogs */

dialog.modal {
    width: min(560px, calc(100vw - 32px));
    max-height: calc(100vh - 48px);
    padding: 0;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--ink);
    box-shadow: 0 24px 60px rgba(18, 58, 94, .25);
}

dialog.modal::backdrop { background: rgba(23, 33, 43, .45); }

.modal-body { display: flex; flex-direction: column; gap: 14px; padding: 20px 22px; margin: 0; }
.modal-head { display: flex; align-items: center; justify-content: space-between; }
.modal-head h2 { margin: 0; font-size: 17px; font-weight: 600; }
.modal-close {
    border: none; background: none; font-size: 22px; line-height: 1; cursor: pointer;
    color: var(--ink-soft); padding: 2px 6px; border-radius: 6px;
}
.modal-close:hover { background: var(--bg); color: var(--ink); }
.modal-note { margin: 0; font-size: 12px; }
.modal-actions {
    display: flex; align-items: center; justify-content: flex-end; gap: 10px;
    padding-top: 12px; border-top: 1px solid var(--line);
}
.modal-actions .muted { margin-right: auto; font-size: 12px; }

/* process */
.process-summary { background: var(--bg); border-radius: var(--radius); padding: 12px 14px; }
.summary-count { font-size: 14px; }
.summary-count strong { font-size: 20px; color: var(--brand); margin-right: 4px; }
.summary-list { margin: 8px 0 0; padding-left: 18px; color: var(--ink-soft); font-size: 13px; max-height: 150px; overflow: auto; }
.summary-warn { margin: 8px 0 0; padding: 6px 10px; border-radius: 6px; background: var(--warn-bg); color: var(--warn); font-size: 12px; }

.processor-list { border: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.processor-list legend { font-size: 12px; font-weight: 600; color: var(--ink-soft); margin-bottom: 6px; padding: 0; }
.processor-option {
    display: flex; gap: 10px; align-items: flex-start; padding: 10px 12px;
    border: 1px solid var(--line); border-radius: var(--radius); cursor: pointer;
}
.processor-option:hover { border-color: var(--brand-accent); }
.processor-option:has(input:checked) { border-color: var(--brand-accent); background: rgba(46, 139, 192, .07); }
.processor-option.is-disabled { opacity: .6; cursor: not-allowed; }
.processor-option input { margin-top: 3px; accent-color: var(--brand-accent); }
.processor-text { display: flex; flex-direction: column; gap: 3px; }
.processor-name { font-weight: 600; display: flex; gap: 6px; align-items: center; }
.processor-desc { font-size: 12px; color: var(--ink-soft); }

/* upload */
.dropzone {
    position: relative;
    display: flex; flex-direction: column; align-items: center; gap: 4px;
    padding: 28px 16px; text-align: center; cursor: pointer;
    border: 2px dashed var(--line); border-radius: 10px; background: var(--bg);
    transition: border-color .15s, background .15s;
}
.dropzone:hover, .dropzone.is-over { border-color: var(--brand-accent); background: rgba(46, 139, 192, .07); }
.dropzone input[type="file"] { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dropzone-icon { font-size: 28px; color: var(--brand-accent); line-height: 1; }
.dropzone-title { font-size: 15px; font-weight: 600; }
.dropzone-title u { color: var(--brand-accent); }
.dropzone-hint { font-size: 12px; color: var(--ink-soft); }

.instructions { margin: 0; padding-left: 18px; font-size: 12px; color: var(--ink-soft); display: flex; flex-direction: column; gap: 3px; }

.file-list { list-style: none; margin: 0; padding: 0; max-height: 200px; overflow: auto; display: flex; flex-direction: column; gap: 4px; }
.file-list:empty { display: none; }
.file-list li {
    display: flex; align-items: center; gap: 10px; padding: 6px 10px;
    border: 1px solid var(--line); border-radius: 6px; font-size: 13px;
}
.file-list li.is-invalid { border-color: var(--error); background: var(--error-bg); }
.file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-meta { font-size: 12px; color: var(--ink-soft); white-space: nowrap; }
.file-list li.is-invalid .file-meta { color: var(--error); }
.file-remove { border: none; background: none; cursor: pointer; font-size: 16px; color: var(--ink-soft); padding: 0 4px; }
.file-remove:hover { color: var(--error); }

.progress { height: 6px; border-radius: 3px; background: var(--bg); overflow: hidden; }
.progress-bar { height: 100%; width: 0; background: var(--brand-accent); transition: width .2s; }

/* ------------------------------------------------------------ settings: processors */

.detail-wide { grid-template-columns: 160px 1fr; }
.processor-card h2 { gap: 8px; }
.processor-card-desc { margin: 0 0 10px; }
.processor-card .col-label { width: 180px; color: var(--ink-soft); }

/* ------------------------------------------------------------ document details */

.details-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; margin-bottom: 16px; }
.details-grid .panel { margin: 0; }
@media (max-width: 960px) { .details-grid { grid-template-columns: 1fr; } }

.panel-actions { display: flex; align-items: center; gap: 10px; margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.panel-actions select { padding: 5px 9px; border: 1px solid var(--line); border-radius: var(--radius); font-family: inherit; background: var(--surface); }
.panel-actions .muted { font-size: 12px; }

code.wrap { word-break: break-all; }
pre.json, .log pre {
    margin: 0; padding: 10px 12px; background: var(--bg); border-radius: var(--radius);
    font-family: Consolas, "Cascadia Mono", monospace; font-size: 12px;
    white-space: pre-wrap; word-break: break-word; max-height: 320px; overflow: auto;
}
.log { margin-top: 12px; }
.log summary { cursor: pointer; font-size: 12px; color: var(--ink-soft); margin-bottom: 6px; }
.progress-inline { margin-top: 10px; }

.btn-ghost-dark { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-ghost-dark:hover { color: var(--brand); border-color: var(--line); }

.doc-link { color: var(--brand); font-weight: 600; text-decoration: none; }
.doc-link:hover { text-decoration: underline; }
.grid .checksum code { color: var(--ink-soft); cursor: help; }
