﻿body {
    background: #f4f6f8;
    color: #1f2937;
}

:root {
    /* ── Pastel colour palette (24 colours) ── */
    --kvp-color-0:  #fca5a5;  /* rose        */
    --kvp-color-1:  #fdba74;  /* orange      */
    --kvp-color-2:  #fcd34d;  /* amber       */
    --kvp-color-3:  #fde047;  /* yellow      */
    --kvp-color-4:  #bef264;  /* lime        */
    --kvp-color-5:  #86efac;  /* green       */
    --kvp-color-6:  #6ee7b7;  /* emerald     */
    --kvp-color-7:  #5eead4;  /* teal        */
    --kvp-color-8:  #67e8f9;  /* cyan        */
    --kvp-color-9:  #7dd3fc;  /* sky         */
    --kvp-color-10: #93c5fd;  /* blue        */
    --kvp-color-11: #a5b4fc;  /* indigo      */
    --kvp-color-12: #c4b5fd;  /* violet      */
    --kvp-color-13: #d8b4fe;  /* purple      */
    --kvp-color-14: #f0abfc;  /* fuchsia     */
    --kvp-color-15: #f9a8d4;  /* pink        */
    --kvp-color-16: #fecdd3;  /* light rose  */
    --kvp-color-17: #fed7aa;  /* light orange*/
    --kvp-color-18: #d9f99d;  /* light lime  */
    --kvp-color-19: #99f6e4;  /* mint        */
    --kvp-color-20: #bae6fd;  /* light sky   */
    --kvp-color-21: #c7d2fe;  /* light indigo*/
    --kvp-color-22: #f5d0fe;  /* light fuchsia*/
    --kvp-color-23: #fbcfe8;  /* light pink  */
    --preview-divider-width: 12px;
}

.analyzer-page {
    min-height: 100dvh;
    height: 100dvh;
    overflow: hidden;
    box-sizing: border-box;
}

.analyzer-layout {
    --analyzer-sidebar-width: calc((100% - var(--preview-divider-width)) / 2);
    display: flex;
    flex-wrap: nowrap;
    align-items: stretch;
    min-height: 100%;
    height: 100%;
    overflow: hidden;
}

.analyzer-sidebar-column {
    flex: 0 0 var(--analyzer-sidebar-width);
    width: var(--analyzer-sidebar-width);
    max-width: none;
    min-width: 0;
    overflow: auto;
    min-height: 0;
    height: 100%;
}

.analyzer-brand {
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e9eef5;
}

.analyzer-logo {
    height: 45px;
    width: auto;
}

.ui-panel {
    background: #fff;
    border: 1px solid #e8eef5;
    border-radius: 0.9rem;
    padding: 1rem;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
}

.section-heading h2 {
    color: #0f172a;
}

.upload-dropzone {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    min-height: 150px;
    padding: 1.25rem;
    border: 2px dashed #9ec5fe;
    border-radius: 1rem;
    background: linear-gradient(180deg, #f8fbff 0%, #eef6ff 100%);
    text-align: center;
    color: #0d6efd;
    cursor: pointer;
    transition: background-color 0.2s ease, border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}

.upload-dropzone:hover,
.upload-dropzone:focus-visible,
.upload-dropzone.is-dragover {
    border-color: #0d6efd;
    background: #e9f3ff;
    transform: translateY(-1px);
    box-shadow: var(--focus-ring);
    outline: none;
}

.upload-dropzone-icon {
    font-size: 2rem;
    line-height: 1;
}

.upload-dropzone-title {
    font-weight: 600;
    color: #0f172a;
}

.upload-dropzone-subtitle {
    font-size: 0.9rem;
    color: #52607a;
}

.selected-files-summary {
    margin-top: 0.75rem;
}

.selected-files-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.selected-file-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    padding: 0.75rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.85rem;
}

.selected-file-meta {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    min-width: 0;
}

.selected-file-icon {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    border-radius: 0.75rem;
    background: #e8f0ff;
    color: #0d6efd;
    font-size: 1rem;
    flex-shrink: 0;
}

.selected-file-name {
    font-weight: 600;
    color: #0f172a;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.selected-file-details {
    font-size: 0.8rem;
    color: #64748b;
}

.token-editor {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
    min-height: 3rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.85rem;
    background: #fff;
    transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

.token-editor:focus-within {
    border-color: #0d6efd;
    box-shadow: var(--focus-ring);
}

.token-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
}

.token-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    max-width: 100%;
    padding: 0.35rem 0.65rem;
    border-radius: 999px;
    background: #e8f0ff;
    color: #0b5ed7;
    font-size: 0.9rem;
    font-weight: 500;
}

.token-chip-label {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 18rem;
}

.token-chip-remove {
    border: none;
    background: transparent;
    color: inherit;
    padding: 0;
    width: 1.1rem;
    height: 1.1rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border-radius: 999px;
}

.token-chip-remove:hover,
.token-chip-remove:focus-visible {
    background: rgba(11, 94, 215, 0.12);
    outline: none;
}

.token-input {
    flex: 1 1 12rem;
    border: none;
    min-width: 12rem;
    padding: 0.25rem 0;
    outline: none;
    background: transparent;
}

.token-empty {
    color: #94a3b8;
    font-size: 0.9rem;
}

#fieldTemplatesDropdown {
    position: relative;
    width: 100%;
    background: #fff;
    border: 1px solid #cbd5e1;
    border-radius: 0.85rem;
    box-shadow: var(--panel-shadow);
    max-height: 24rem;
    overflow: auto;
    z-index: 2000;
    display: none;
    font-size: 0.9rem;
}

#fieldTemplatesSearch {
    position: sticky;
    top: 0;
    background: #f8fafc;
    border-bottom: 1px solid #e2e8f0;
    padding: 0.75rem;
    z-index: 1;
}

#fieldTemplatesSearch input {
    width: 100%;
    font-size: 0.9rem;
    padding: 0.5rem 0.75rem;
    border: 1px solid #cbd5e1;
    border-radius: 0.65rem;
}

#fieldTemplatesDropdown .tpl-item {
    position: relative;
    padding: 0.85rem 3rem 0.85rem 0.85rem;
    cursor: pointer;
    line-height: 1.3;
    border-bottom: 1px solid #f1f5f9;
    outline: none;
}

#fieldTemplatesDropdown .tpl-item:last-child {
    border-bottom: none;
}

#fieldTemplatesDropdown .tpl-item:hover,
#fieldTemplatesDropdown .tpl-item:focus-visible {
    background: #edf4ff;
}

#fieldTemplatesDropdown .tpl-item.is-active {
    background: #e8f0ff;
}

#fieldTemplatesDropdown .tpl-vendor {
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 0.2rem;
}

#fieldTemplatesDropdown .tpl-meta,
#fieldTemplatesDropdown .tpl-fields {
    color: #475569;
    font-size: 0.8rem;
    margin-top: 0.2rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

#fieldTemplatesDropdown .tpl-delete {
    position: absolute;
    top: 4px;
    right: 4px;
    width: 24px;
    height: 24px;
    border: none;
    background: transparent;
    color: #dc3545;
    font-weight: 700;
    font-size: 18px;
    line-height: 1;
    cursor: pointer;
}

#fieldTemplatesDropdown .tpl-delete:hover {
    color: #a71d2a;
}

#previewToolbar,
#documentNavigator,
#downloadBtn,
#loading-overlay,
#loginModal,
#loginError,
#analyzeProgressStatus,
#uploadError {
    display: none;
}

.results-panel .nav-link {
    font-weight: 600;
}

.results-panel .nav-link:focus-visible {
    box-shadow: var(--focus-ring);
}

.document-preview-column {
    flex: 1 1 auto;
    min-width: 0;
    min-height: 0;
    overflow: auto;
    height: 100%;
    position: relative;
}

.preview-header {
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e2e8f0;
}

.preview-toolbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1rem;
    padding: 0.75rem 1rem;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 0.9rem;
    box-shadow: 0 4px 12px rgba(15, 23, 42, 0.04);
    position: sticky;
    top: 0;
    z-index: 200;
    background: rgba(255, 255, 255, 0.96);
    -webkit-backdrop-filter: blur(8px);
    backdrop-filter: blur(8px);
    border: 1px solid #d9e2ec;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.12);
}

.preview-toolbar-content {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    width: 100%;
    justify-content: space-between;
}

.preview-zoom-label {
    min-width: 4rem;
}

.multi-page-preview {
    display: flex;
    flex-direction: column;
    gap: 1.25rem;
    position: relative;
    z-index: 1;
    align-items: flex-start;
}

.preview-page-container {
    display: flex;
    justify-content: flex-start;
    align-items: flex-start;
    width: 100%;
    position: relative;
    z-index: 1;
    overflow: hidden;
}

.preview-page-wrapper {
    position: relative;
    background: #fff;
    border: 1px solid #dbe4f0;
    border-radius: 0.9rem;
    box-shadow: var(--panel-shadow);
    overflow: hidden;
    transform-origin: top left;
}

.preview-page-wrapper img,
.preview-page-wrapper canvas {
    display: block;
    max-width: 100%;
    height: auto;
}

.preview-resize-divider {
    flex: 0 0 var(--preview-divider-width);
    width: var(--preview-divider-width);
    min-width: var(--preview-divider-width);
    cursor: col-resize;
    background: linear-gradient(180deg, #eef2f6 0%, #dde5ee 100%);
    border-left: 1px solid #d7dee8;
    border-right: 1px solid #d7dee8;
    position: relative;
    user-select: none;
    touch-action: none;
}

.preview-resize-divider::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 4px;
    height: 64px;
    border-radius: 999px;
    background: #93a4b8;
    box-shadow: 0 0 0 4px rgba(255, 255, 255, 0.85);
}

.preview-resize-divider:hover,
.preview-resize-divider.is-resizing,
.preview-resize-divider:focus-visible {
    background: linear-gradient(180deg, #dcecff 0%, #cfe2ff 100%);
    outline: none;
}

body.is-column-resizing {
    cursor: col-resize;
    user-select: none;
}

.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    min-height: 220px;
    padding: 2rem 1.5rem;
    text-align: center;
    background: linear-gradient(180deg, #ffffff 0%, #f8fbff 100%);
    border: 1px dashed #cbd5e1;
    border-radius: 1rem;
    color: #475569;
}

.empty-state-icon {
    font-size: 2rem;
    color: #0d6efd;
}

.empty-state-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: #0f172a;
}

.empty-state-description {
    max-width: 32rem;
}

.empty-state-list {
    margin: 0.25rem 0 0;
    padding-left: 1.25rem;
    text-align: left;
}

.kvp {
    border-radius: 0.8rem;
    margin-bottom: 0.5rem;
    padding: 0.65rem 0.85rem 0.65rem 1rem;
    cursor: pointer;
    font-size: 0.9rem;
    border: 1px solid transparent;
    border-left-width: 4px;
    transition: box-shadow 0.15s ease, filter 0.15s ease;
}

.kvp:hover {
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.09);
    filter: brightness(0.97);
}

.kvp:focus-visible {
    outline: none;
    box-shadow: 0 0 0 3px rgba(13, 110, 253, 0.25);
}

.kvp-label {
    font-weight: 600;
    font-size: 0.8rem;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: #374151;
}

.kvp-value {
    font-size: 0.92rem;
    color: #111827;
    margin-top: 0.2rem;
    word-break: break-word;
    line-height: 1.45;
}

.kvp-confidence {
    display: inline-flex;
    align-items: center;
    gap: 0.2rem;
    font-size: 0.72rem;
    color: #6b7280;
    background: rgba(0, 0, 0, 0.06);
    padding: 0.1rem 0.45rem;
    border-radius: 999px;
    float: right;
    margin-left: 0.5rem;
}

/* ── Pastel field colour classes (24 colours) ── */
.kvp-color-0,  .table-color-0  { border-color: #fca5a5; background: #fff1f2; }
.kvp-color-1,  .table-color-1  { border-color: #fdba74; background: #fff7ed; }
.kvp-color-2,  .table-color-2  { border-color: #fcd34d; background: #fffbeb; }
.kvp-color-3,  .table-color-3  { border-color: #fde047; background: #fefce8; }
.kvp-color-4,  .table-color-4  { border-color: #bef264; background: #f7fee7; }
.kvp-color-5,  .table-color-5  { border-color: #86efac; background: #f0fdf4; }
.kvp-color-6,  .table-color-6  { border-color: #6ee7b7; background: #ecfdf5; }
.kvp-color-7,  .table-color-7  { border-color: #5eead4; background: #f0fdfa; }
.kvp-color-8,  .table-color-8  { border-color: #67e8f9; background: #ecfeff; }
.kvp-color-9,  .table-color-9  { border-color: #7dd3fc; background: #f0f9ff; }
.kvp-color-10, .table-color-10 { border-color: #93c5fd; background: #eff6ff; }
.kvp-color-11, .table-color-11 { border-color: #a5b4fc; background: #eef2ff; }
.kvp-color-12, .table-color-12 { border-color: #c4b5fd; background: #f5f3ff; }
.kvp-color-13, .table-color-13 { border-color: #d8b4fe; background: #faf5ff; }
.kvp-color-14, .table-color-14 { border-color: #f0abfc; background: #fdf4ff; }
.kvp-color-15, .table-color-15 { border-color: #f9a8d4; background: #fdf2f8; }
.kvp-color-16, .table-color-16 { border-color: #fecdd3; background: #fff8f8; }
.kvp-color-17, .table-color-17 { border-color: #fed7aa; background: #fff9f3; }
.kvp-color-18, .table-color-18 { border-color: #d9f99d; background: #f9fff0; }
.kvp-color-19, .table-color-19 { border-color: #99f6e4; background: #f0fffe; }
.kvp-color-20, .table-color-20 { border-color: #bae6fd; background: #f0f9ff; }
.kvp-color-21, .table-color-21 { border-color: #c7d2fe; background: #f1f2ff; }
.kvp-color-22, .table-color-22 { border-color: #f5d0fe; background: #fef6ff; }
.kvp-color-23, .table-color-23 { border-color: #fbcfe8; background: #fef6fa; }

.kvp-box, .table-box {
    position: absolute;
    border: 2px solid;
    border-radius: 3px;
    pointer-events: none;
    z-index: 20;
    box-sizing: border-box;
    opacity: 0.7;
}

.kvp-box.is-focused {
    opacity: 1;
    stroke-width: 2;
    filter: drop-shadow(0 0 12px rgba(0, 0, 0, 0.8));
}

.label-box {
    position: absolute;
    border: 2px dashed #0078d4;
    pointer-events: none;
    z-index: 10;
}

.page-number-overlay {
    position: absolute;
    top: 0;
    left: 0;
    background: #aaa;
    color: #fff;
    padding: 0.35rem 0.55rem;
    font-weight: 700;
    font-size: 0.85rem;
    z-index: 50;
    pointer-events: none;
    border-bottom-right-radius: 0.75rem;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15);
}

/* ── Document info chips ── */
.doc-info-bar {
    display: flex;
    flex-wrap: wrap;
    gap: 0.45rem;
    margin-bottom: 0.85rem;
}

.doc-info-item {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.4rem 0.75rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.65rem;
    min-width: 0;
    max-width: 100%;
}

.doc-info-icon {
    font-size: 0.85rem;
    color: #0d6efd;
    flex-shrink: 0;
}

.doc-info-label {
    display: block;
    font-size: 0.68rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: #64748b;
    line-height: 1;
    margin-bottom: 0.1rem;
    white-space: nowrap;
}

.doc-info-value {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: #0f172a;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 16rem;
    line-height: 1.3;
}

/* ── Combined grid ── */
th.sticky-header.sticky-top {
    position: sticky;
    top: 0;
    background: #f8f9fa;
    color: #212529;
    font-size: 0.85rem;
    letter-spacing: 0.05em;
    white-space: nowrap;
    z-index: 20;
}

.combined-grid-wrapper {
    max-height: 32rem;
    overflow: auto;
    border: 1px solid #e2e8f0;
    border-radius: 0.85rem;
    box-shadow: 0 2px 8px rgba(15, 23, 42, 0.05);
}

.combined-grid-table {
    margin-bottom: 0;
}

.combined-grid-table tbody tr {
    transition: background-color 0.12s ease;
}

.combined-grid-table tbody tr > td:first-child {
    text-align: center;
    color: #6b7280;
    font-size: 0.8rem;
    font-variant-numeric: tabular-nums;
    width: 3rem;
}

.grid-filename-link {
    color: #0d6efd;
    text-decoration: none;
    font-weight: 500;
}

.grid-filename-link:hover {
    text-decoration: underline;
}

.analyze-progress-button {
    position: relative;
    overflow: hidden;
    min-height: 2.85rem;
}

.analyze-progress-fill {
    position: absolute;
    inset: 0 auto 0 0;
    width: 0;
    background: linear-gradient(90deg, rgba(255, 255, 255, 0.15) 0%, rgba(255, 255, 255, 0.35) 100%);
    transition: width 0.2s ease;
}

.analyze-progress-text {
    position: relative;
    z-index: 1;
}

#loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15, 23, 42, 0.18);
    z-index: 9999;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.loading-card {
    width: min(32rem, 100%);
    padding: 1.25rem;
    border-radius: 1rem;
    background: #fff;
}

.loading-progress {
    width: 100%;
    height: 0.65rem;
    background: #e2e8f0;
    border-radius: 999px;
    overflow: hidden;
}

.loading-progress-bar {
    height: 100%;
    width: 0;
    background: linear-gradient(90deg, #0d6efd 0%, #6f42c1 100%);
    border-radius: inherit;
    transition: width 0.2s ease;
}

.progress-bar {
    width: 100%;
    height: 5px;
    background: #eee;
    border-radius: 2px;
    overflow: hidden;
    position: relative;
}

.progress-bar-inner {
    height: 100%;
    width: 40%;
    background: linear-gradient(90deg, #0078d4 0%, #6f42c1 50%, #17a2b8 100%);
    border-radius: 2px;
    position: absolute;
    left: -40%;
    animation: progress-indeterminate 3s linear infinite;
}

@keyframes progress-indeterminate {
    0% {
        left: -50%;
    }

    100% {
        left: 100%;
    }
}

.login-modal {
    position: fixed;
    inset: 0;
    z-index: 99999;
    background: rgba(15, 23, 42, 0.28);
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

.login-modal-dialog {
    min-width: min(26rem, 100%);
    margin: auto;
}

.form-control:focus,
.form-select:focus,
.btn:focus-visible,
.dropdown-item:focus-visible {
    box-shadow: var(--focus-ring);
}

@media (max-width: 991.98px) {
    .analyzer-layout {
        min-height: auto;
    }

    .analyzer-sidebar-column,
    .document-preview-column {
        min-height: auto;
    }
}

@media (max-width: 767.98px) {
    .analyzer-page {
        height: auto;
        min-height: 100dvh;
        overflow: visible;
    }

    .analyzer-layout {
        flex-wrap: wrap;
        min-height: auto;
        height: auto;
        overflow: visible;
    }

    .analyzer-sidebar-column,
    .document-preview-column {
        flex: 1 1 100%;
        width: 100%;
        height: auto;
    }

    .preview-resize-divider {
        display: none;
    }

    .token-chip-label {
        max-width: 12rem;
    }

    .preview-toolbar-content {
        justify-content: flex-start;
    }
}

.token-chip[draggable="true"] {
    cursor: grab;
}

.token-chip.is-dragging {
    opacity: 0.6;
    cursor: grabbing;
}

.token-editor.is-drop-target {
    border-color: #0d6efd;
    box-shadow: 0 0 0 0.2rem rgba(13, 110, 253, 0.15);
    background: rgba(13, 110, 253, 0.04);
}

.token-chip.is-drop-before,
.token-chip.is-drop-after {
    position: relative;
}

.token-chip.is-drop-before::before,
.token-chip.is-drop-after::after {
    content: '';
    position: absolute;
    top: 0.25rem;
    bottom: 0.25rem;
    width: 3px;
    border-radius: 999px;
    background: #0d6efd;
}

.token-chip.is-drop-before::before {
    left: -0.4rem;
}

.token-chip.is-drop-after::after {
    right: -0.4rem;
}