:root {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    background-color: #f5f6f8;
    color: #1c1f23;
}

body {
    margin: 0;
    padding: 0 1.5rem 2rem;
}

main {
    max-width: 1200px;
    margin: 0 auto;
}

.site-header {
    background: #0f172a;
    color: #e5e7eb;
    padding: 0.6rem 1.2rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    box-shadow: 0 1px 3px rgba(15, 23, 42, 0.25);
    font-size: 0.9rem;
}

.site-header h1 {
    font-size: 1rem;
    margin: 0;
    display: flex;
    gap: 0.8rem;
    align-items: center;
}

.site-header h1 a {
    color: #f8fafc;
    text-decoration: none;
}

.site-header nav a {
    color: #cbd5f5;
    text-decoration: none;
    margin-left: 1rem;
    font-weight: 500;
}

.site-header nav a:hover {
    color: white;
}

.user-pill {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.15);
    margin-left: 1rem;
}

.presence-banner {
    background: #e0e7ff;
    color: #1e1b4b;
    padding: 0.5rem 1rem;
    display: flex;
    gap: 0.6rem;
    flex-wrap: wrap;
    align-items: center;
    border-bottom: 1px solid #c7d2fe;
}

.presence-pill {
    background: white;
    border-radius: 999px;
    padding: 0.25rem 0.8rem;
    box-shadow: 0 1px 2px rgba(15, 23, 42, 0.15);
    font-size: 0.85rem;
    display: inline-flex;
    gap: 0.3rem;
    align-items: center;
}

.presence-pill strong {
    color: #312e81;
}

.presence-pill-conflict {
    border: 2px solid #dc2626;
    color: #991b1b;
}

.presence-alert {
    background: #fef2f2;
    color: #991b1b;
    padding: 0.6rem 1rem;
    display: flex;
    gap: 0.3rem;
    align-items: center;
    border-bottom: 1px solid #fecaca;
    font-weight: 600;
}

section {
    background: white;
    border-radius: 8px;
    padding: 1.2rem;
    margin-top: 1.2rem;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.07);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 0.4rem 0.6rem;
    border-bottom: 1px solid #e3e6eb;
}

th {
    text-align: left;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #5b6470;
}

.status-badge {
    padding: 0.15rem 0.5rem;
    border-radius: 999px;
    font-size: 0.8rem;
    font-weight: 600;
    display: inline-block;
}

.status-ok {
    background: #d6f5e3;
    color: #0b8355;
}

.status-missing {
    background: #fde2e1;
    color: #bb2d3e;
}

.progress-row {
    display: flex;
    align-items: center;
    gap: 0.6rem;
}

.progress-bar {
    flex: 1;
    background: #e2e8f0;
    border-radius: 999px;
    height: 10px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #3b82f6, #0ea5e9);
    border-radius: 999px;
}

.progress-count {
    font-size: 0.85rem;
    color: #475569;
}

.forms-row {
    display: flex;
    flex-wrap: wrap;
    gap: 1rem;
}

.forms-row form {
    flex: 1;
    min-width: 250px;
}

.grid.two-columns {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
    gap: 1.2rem;
}

.login-box {
    max-width: 360px;
    margin: 2rem auto;
}

.login-box form {
    display: flex;
    flex-direction: column;
    gap: 0.8rem;
}

.password-wrapper {
    position: relative;
    display: flex;
    align-items: center;
}

.password-wrapper input {
    width: 100%;
    padding-right: 2.5rem;
}

.password-toggle {
    position: absolute;
    right: 0.4rem;
    background: rgba(15, 23, 42, 0.08);
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.75rem;
    line-height: 1;
    padding: 0.2rem 0.4rem;
    color: #0f172a;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: 0.5rem;
    border-radius: 6px;
    border: 1px solid #c5ccd6;
    margin-top: 0.3rem;
    box-sizing: border-box;
}

textarea {
    min-height: 280px;
    font-family: ui-monospace, SFMono-Regular, SFMono-Regular, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

button {
    margin-top: 0.6rem;
    padding: 0.5rem 1.2rem;
    border: none;
    background: #114bda;
    color: white;
    border-radius: 6px;
    cursor: pointer;
}

button.secondary {
    background: #546177;
}

.flash-container {
    max-width: 1200px;
    margin: 1rem auto;
    background: transparent;
    box-shadow: none;
    padding: 0;
}

.flash {
    border-radius: 6px;
    padding: 0.75rem 1rem;
    margin-bottom: 0.6rem;
}

.flash-success {
    background: #d5f3e6;
    color: #0f7147;
}

.flash-error {
    background: #fde4e1;
    color: #981b1f;
}

.flash-log pre {
    white-space: pre-wrap;
    font-size: 0.8rem;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.8rem;
}

.card {
    background: #f8fafc;
    border-radius: 6px;
    padding: 0.8rem;
    border: 1px solid #e1e5ec;
    min-height: 100px;
    word-break: break-all;
}

.card.pending {
    background: #fffdf5;
    border-color: #f3e7c1;
}

.card.ok {
    background: #f2fbf4;
    border-color: #bae4c7;
}
.flex {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.flex > * {
    flex: 1;
    min-width: 260px;
}

.actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.6rem;
}

.filter-input {
    margin-bottom: 0.8rem;
}

.nav-buttons {
    display: flex;
    justify-content: space-between;
    gap: 0.5rem;
    margin: 0.8rem 0 1.2rem;
}

.button {
    display: inline-block;
    padding: 0.45rem 1rem;
    border-radius: 6px;
    text-decoration: none;
    background: #114bda;
    color: white;
}

.button.secondary {
    background: #546177;
}

.button-success {
    background: #15803d !important;
    color: #f8fafc;
}

.action-extra {
    border: none;
    background: transparent;
    color: #0f172a;
    font-size: 0.85rem;
    margin: 0 0 0 0.3rem;
    cursor: pointer;
    padding: 0;
    text-decoration: underline;
    display: inline;
    line-height: inherit;
    vertical-align: baseline;
}

.action-extra:hover {
    color: #1d4ed8;
}

.button.secondary.ghost.active {
    background: #1e3a8a;
    color: #f8fafc;
}

.snippet-wrapper {
    position: relative;
}

.snippet-menu {
    position: absolute;
    bottom: calc(100% + 0.25rem);
    left: 0;
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    background: #ffffff;
    border: 1px solid #c5ccd6;
    border-radius: 6px;
    box-shadow: 0 6px 18px rgba(15, 23, 42, 0.2);
    padding: 0.4rem;
    z-index: 1500;
    min-width: 140px;
}

.snippet-menu.hidden {
    display: none;
}

.snippet-menu button {
    text-align: left;
    width: 100%;
    padding: 0.3rem 0.5rem;
    border: none;
    background: transparent;
    cursor: pointer;
    border-radius: 4px;
}

.snippet-menu button:hover {
    background: #e2e8f0;
}

.compare-section.dark-mode .snippet-menu {
    background: #1f2937;
    border-color: #4b5563;
    color: #f3f4f6;
}

.compare-section.dark-mode .snippet-menu button {
    color: #f3f4f6;
}

.compare-section.dark-mode .snippet-menu button:hover {
    background: #374151;
}
.button.primary {
    background: #114bda;
    color: white;
}

.button.loading {
    pointer-events: none;
    opacity: 0.8;
    position: relative;
    padding-right: 2.5rem;
}

.button.loading::after {
    content: "";
    position: absolute;
    right: 0.7rem;
    top: 50%;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.6);
    border-top-color: white;
    animation: spin 0.6s linear infinite;
    transform: translateY(-50%);
}

@keyframes spin {
    from { transform: translateY(-50%) rotate(0deg); }
    to { transform: translateY(-50%) rotate(360deg); }
}

.button.compact {
    padding: 0.35rem 0.65rem;
    font-size: 0.85rem;
    line-height: 1.2;
}

.button.disabled {
    background: #c5ccd6;
    color: #5b6470;
    cursor: default;
}

.button.ghost {
    background: transparent;
    color: #546177;
    border: 1px solid #546177;
}

.button.ghost:hover {
    background: rgba(84, 97, 119, 0.1);
}

.decision-form {
    display: block;
}

.decision-form textarea {
    min-height: 120px;
}

.decision-row {
    display: flex;
    gap: 0.6rem;
    align-items: flex-end;
    flex-wrap: wrap;
}

.decision-row label {
    flex: 1;
    min-width: 220px;
}

.decision-row .notes-field.hidden {
    display: none;
}

.decision-row button {
    align-self: flex-end;
}

.doc-row-skip td,
.doc-row-skip a {
    text-decoration: line-through;
    color: #8b949e;
}

.doc-row-skip {
    background: #f2f4f6;
}

.doc-row-later {
    background: #fff6cc;
}

.doc-row-later td {
    border-bottom-color: #f1e3a6;
}

.compare-grid {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.compare-grid > .pdf-pane,
.compare-grid > .html-pane {
    flex: 1;
    min-width: 320px;
}

.pdf-frame {
    width: 100%;
    min-height: 600px;
    border: 1px solid #c5ccd6;
    border-radius: 6px;
    background: #fff;
}

.editor-actions {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 0.8rem;
}

.editor-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.html-pane textarea {
    min-height: 600px;
}

.html-pane .CodeMirror {
    border: 1px solid #c5ccd6;
    border-radius: 6px;
    min-height: 600px;
    font-size: 0.9rem;
}

.html-pane .CodeMirror-selected {
    background: #ffe58f !important;
    color: #1c1f23 !important;
}

.compare-section {
    position: relative;
}

.compare-section.dark-mode {
    background: #111827;
    color: #f3f4f6;
    border-radius: 8px;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
}

.compare-section.dark-mode h3 {
    color: #f9fafb;
}

.compare-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 0.6rem;
}

.icon-toggle {
    width: auto;
    min-width: 42px;
    padding: 0.4rem 0.75rem;
    font-size: 1.2rem;
    line-height: 1;
    text-align: center;
}

.compare-fullscreen {
    position: fixed;
    inset: 0;
    background: #fff;
    z-index: 999;
    margin: 0;
    padding: 1rem 1.5rem 1.5rem;
    overflow: auto;
}

.compare-section.dark-mode.compare-fullscreen {
    background: #0f172a;
}

.compare-fullscreen .compare-grid {
    flex-wrap: nowrap;
}

.compare-fullscreen .pdf-frame,
.compare-fullscreen .html-pane textarea,
.compare-fullscreen .html-pane .CodeMirror {
    min-height: calc(100vh - 200px);
}

.compare-section.dark-mode .pdf-frame {
    border-color: #374151;
    background: #1f2937;
}

.compare-section.dark-mode .html-pane .CodeMirror {
    border-color: #374151;
    background: #111827;
}

.compare-section.dark-mode .html-pane .CodeMirror-selected {
    background: #facc15 !important;
    color: #111827 !important;
}

.compare-section.dark-mode .button.ghost {
    border-color: #9ca3af;
    color: #e5e7eb;
}

.compare-section.dark-mode .button.ghost:hover {
    background: rgba(148, 163, 184, 0.2);
}

.action-buttons {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    align-items: center;
    margin-left: auto;
    justify-content: flex-end;
}

.actions label {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.inline-field {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
    min-width: 220px;
}

.quad-row {
    align-items: stretch;
    gap: 0.8rem;
}

.adjust-field {
    flex: 1.3;
    min-width: 240px;
}

.short-field {
    flex: 1;
    min-width: 180px;
}

.ocr-adjust-display {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.modal {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1200;
}

.modal.hidden {
    display: none;
}

.modal-dialog {
    background: white;
    border-radius: 8px;
    width: min(900px, 95vw);
    max-height: 90vh;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 50px rgba(15, 23, 42, 0.35);
}

.modal-header,
.modal-footer {
    padding: 0.9rem 1.2rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.modal-body {
    padding: 0 1.2rem 1.2rem;
    overflow: auto;
}

.modal-body ul {
    margin: 0;
    padding-left: 1.2rem;
}

.crop-instructions {
    margin-bottom: 0.6rem;
    font-size: 0.9rem;
    color: #546177;
}

.crop-stage {
    position: relative;
    border: 1px solid #c5ccd6;
    border-radius: 6px;
    overflow: hidden;
    background: #f8fafc;
    display: inline-block;
    max-width: 100%;
}

#crop-image {
    display: block;
    width: auto;
    height: auto;
    max-width: 100%;
    max-height: 65vh;
    background: #ffffff;
}

#crop-overlay {
    position: absolute;
    border: 2px solid #2563eb;
    background: rgba(37, 99, 235, 0.2);
    pointer-events: none;
    display: none;
}

.modal-footer {
    justify-content: flex-end;
    gap: 0.5rem;
}

.ocr-modal-body label {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    margin-bottom: 0.8rem;
}

.ocr-modal-body input[type="range"] {
    width: 100%;
}

.ocr-preview {
    border: 1px solid #c5ccd6;
    border-radius: 6px;
    overflow: hidden;
    background: #0f172a;
    margin-top: 0.8rem;
}

.ocr-preview img {
    width: 100%;
    max-height: 320px;
    object-fit: contain;
    display: block;
}

.search-panel {
    position: fixed;
    left: 50%;
    top: 50%;
    transform: translate(-50%, -50%);
    width: 320px;
    background: #ffffff;
    border: 1px solid #c5ccd6;
    border-radius: 8px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    z-index: 1200;
}

.compare-section.dark-mode ~ .search-panel {
    background: #111827;
    border-color: #374151;
    color: #f3f4f6;
}

.search-panel.hidden {
    display: none;
}

.search-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.5rem 0.75rem;
    cursor: move;
}

.search-panel-body {
    padding: 0.75rem;
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.search-panel-body label {
    display: flex;
    flex-direction: column;
    font-size: 0.9rem;
    gap: 0.2rem;
}

.search-actions {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
    justify-content: flex-end;
}

.compare-section.dark-mode ~ .search-panel .button.ghost {
    border-color: #9ca3af;
    color: #e5e7eb;
}

.compare-section.dark-mode ~ .search-panel {
    box-shadow: 0 4px 16px rgba(15, 23, 42, 0.7);
}
