/* Ported from demo-itg-tender-ui/styles.css. The root variable block and the generic
   primitives are unchanged; the ADE-domain rules (grounding boxes and markdown
   chunks) are gone, and the rules this domain needs are
   appended at the bottom. */

:root {
    --bg-main: #ffffff;
    --bg-secondary: #f8fafc;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
    --accent-green: #22c55e;
    --accent-hover: #16a34a;
    --accent-tint: #f0fdf4;
    --accent-ring: rgba(34, 197, 94, 0.12);
    --active-tab-bg: #f1f5f9;
    --header-height: 56px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg-main);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* Header */
.app-header {
    min-height: var(--header-height);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    /* Wraps rather than pushing the upload button off the right edge on a
       narrow window — body is overflow:hidden, so it would be hard to reach. */
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 8px 16px;
    background: white;
    z-index: 100;
    flex-shrink: 0;
}

.header-left, .header-right, .header-center {
    display: flex;
    align-items: center;
    gap: 16px;
}

.breadcrumbs {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.separator { color: var(--border-color); }
.filename { font-weight: 500; color: var(--text-primary); }

.page-nav-top {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-secondary);
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    font-size: 0.85rem;
}

.page-number-input {
    width: 44px;
    background: #f1f5f9;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    padding: 2px;
    text-align: center;
    font-size: 0.82rem;
    font-family: inherit;
    font-weight: 500;
    color: var(--text-primary);
    outline: none;
    transition: border-color 0.15s, background 0.15s;
}

.page-number-input:focus {
    border-color: var(--accent-green);
    background: white;
}

.page-number-input::-webkit-outer-spin-button,
.page-number-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.page-number-input {
    -moz-appearance: textfield;
}

.nav-arrow {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: var(--text-secondary);
}

.nav-arrow:disabled { opacity: 0.35; cursor: default; }

/* Buttons */
.btn {
    padding: 6px 16px;
    border-radius: 6px;
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    font-family: inherit;
}

/* `display: flex` above outranks the user agent's [hidden] rule, so Clear
   stayed on screen after it had nothing left to clear. */
.btn[hidden] { display: none; }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
    background-color: var(--accent-tint);
    border: 1px solid var(--accent-green);
    color: var(--accent-green);
}

.btn-primary:hover:not(:disabled) {
    background-color: #dcfce7;
    color: var(--accent-hover);
}

.btn-outline {
    background: white;
    border: 1px solid var(--border-color);
    color: var(--text-primary);
}

.btn-danger {
    background: white;
    border: 1px solid #fecaca;
    color: #b91c1c;
}

.btn-danger:hover:not(:disabled) {
    background: #fef2f2;
    border-color: #fca5a5;
}

/* Case deletion confirmation */
.delete-case-dialog {
    width: min(400px, calc(100vw - 32px));
    margin: auto;
    padding: 0;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    color: var(--text-primary);
    background: white;
    box-shadow: 0 20px 48px rgba(15, 23, 42, 0.2);
}

.delete-case-dialog::backdrop {
    background: rgba(15, 23, 42, 0.28);
}

.delete-case-dialog-content {
    padding: 22px;
}

.delete-case-dialog h2 {
    font-size: 1rem;
    font-weight: 600;
    line-height: 1.4;
}

.delete-case-dialog-description {
    margin-top: 8px;
    color: var(--text-secondary);
    font-size: 0.85rem;
    line-height: 1.5;
    overflow-wrap: anywhere;
}

.delete-case-dialog-warning {
    margin-top: 14px;
    padding: 8px 10px;
    border: 1px solid #fecaca;
    border-radius: 6px;
    color: #991b1b;
    background: #fef2f2;
    font-size: 0.8rem;
    line-height: 1.4;
}

.delete-case-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 8px;
    margin-top: 20px;
}

.delete-case-confirm {
    border: 1px solid #b91c1c;
    color: white;
    background: #b91c1c;
}

.delete-case-confirm:hover:not(:disabled) {
    border-color: #991b1b;
    background: #991b1b;
}

.btn-text {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-weight: 500;
    cursor: pointer;
}

.icon-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    color: var(--text-secondary);
    padding: 4px;
}

/* Main Container */
.app-container {
    display: grid;
    /* minmax(0, …) rather than a bare percentage: a percentage track refuses to
       shrink below its content's min-content width, so the wide Documents table
       set a floor of ~977px and pushed the header's upload button off-screen. */
    grid-template-columns: minmax(0, 35%) minmax(0, 65%);
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

/* Left Column */
.left-column {
    display: grid;
    border-right: 1px solid var(--border-color);
    background: var(--bg-secondary);
    overflow: hidden;
    min-height: 0;
}

.viewer-section {
    display: flex;
    flex-direction: column;
    align-items: center;
    padding: 20px;
    overflow: auto;
    position: relative;
    min-height: 0;
}

.viewer-section.viewer-empty {
    justify-content: center;
}

.viewer-section.viewer-empty .page-canvas-wrapper {
    display: none;
}

.viewer-drop-target {
    align-items: center;
    background: var(--bg-primary);
    border: 2px dashed var(--border-color);
    border-radius: 12px;
    box-sizing: border-box;
    color: var(--text-secondary);
    display: flex;
    flex-direction: column;
    gap: 8px;
    justify-content: center;
    max-width: 400px;
    min-height: 180px;
    padding: 24px;
    pointer-events: none;
    text-align: center;
    width: 100%;
}

.viewer-drop-target[hidden] {
    display: none;
}

.viewer-drop-target-glyph {
    color: var(--accent-green);
    font-size: 2rem;
}

.viewer-drop-target strong {
    color: var(--text-primary);
    font-size: 0.95rem;
    font-weight: 600;
}

.viewer-drop-target span:not(.viewer-drop-target-glyph) {
    font-size: 0.8rem;
}

.page-canvas-wrapper {
    background: white;
    box-shadow: 0 4px 20px rgba(0,0,0,0.05);
    margin-bottom: 20px;
}

.page-canvas {
    position: relative;
    transform-origin: top center;
}

.page-image {
    display: block;
    max-width: 100%;
    height: auto;
}

/* `display: block` above outranks the user agent's [hidden] rule, so hiding a
   broken image needs saying explicitly. */
.page-image[hidden] { display: none; }

/* Stands in for a page image that failed to load, in the same visual slot. */
.page-missing {
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 320px;
    min-height: 420px;
    padding: 24px;
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    background: white;
    border: 1px dashed var(--border-color);
}

.page-missing[hidden] { display: none; }

/* Right Column */
.right-column {
    display: flex;
    flex-direction: column;
    background: white;
    overflow: hidden;
    min-height: 0;
}

.results-header {
    padding: 12px 20px;
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-shrink: 0;
}

.tab-group {
    display: flex;
    background: var(--bg-secondary);
    padding: 2px;
    border-radius: 8px;
}

.tab-btn {
    padding: 6px 16px;
    border: none;
    background: none;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 6px;
    display: flex;
    align-items: center;
    gap: 6px;
    transition: all 0.15s;
    font-family: inherit;
}

.tab-btn.active {
    background: white;
    color: var(--text-primary);
    box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}

/* Tab Content */
.tab-content {
    display: none;
    flex: 1;
    overflow: hidden;
    min-height: 0;
}

.tab-content.active {
    display: flex;
    flex-direction: column;
}

.panel {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
    min-height: 0;
}

/* ===== TABLES (Documents + Pages tabs) ===== */
.extraction-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid var(--border-color);
    border-radius: 10px;
    overflow: hidden;
    font-size: 0.88rem;
}

.extraction-table thead th {
    background: var(--bg-secondary);
    padding: 10px 16px;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-secondary);
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    z-index: 1;
}

.extraction-table tbody tr {
    transition: background 0.15s;
    cursor: pointer;
}

.extraction-table tbody tr:not(:last-child) td {
    border-bottom: 1px solid var(--border-color);
}

.extraction-table tbody tr:hover {
    background: var(--accent-tint);
}

.extraction-table tbody tr.active {
    background: var(--accent-tint);
    box-shadow: inset 3px 0 0 var(--accent-green);
}

.extraction-table td {
    padding: 12px 16px;
    vertical-align: top;
}

/* Column width helpers */
.col-num { width: 48px; }
.col-pages { width: 110px; white-space: nowrap; }
.col-count { width: 70px; }
.col-conf { width: 100px; }
.col-action { width: 90px; }

.mono {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
}

.muted { color: var(--text-secondary); }

/* ===== Category tint ===== */
.cat-cell {
    display: inline-flex;
    align-items: center;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 0.78rem;
    font-weight: 500;
    background: var(--cat-bg, #f3f4f6);
    color: var(--cat-fg, #374151);
    white-space: nowrap;
}

/* ===== CONFIDENCE BADGE ===== */
.confidence-badge {
    font-size: 0.65rem;
    font-weight: 600;
    padding: 1px 6px;
    border-radius: 8px;
    margin-left: 6px;
    white-space: nowrap;
}

.confidence-high {
    background: #dcfce7;
    color: #166534;
}

.confidence-medium {
    background: #fef9c3;
    color: #854d0e;
}

.confidence-low {
    background: #fee2e2;
    color: #991b1b;
}

/* ===== METADATA FOOTER ===== */
.metadata-footer {
    padding: 8px 20px;
    border-top: 1px solid var(--border-color);
    background: var(--bg-secondary);
    font-size: 0.72rem;
    color: var(--text-secondary);
    display: flex;
    gap: 16px;
    align-items: center;
    flex-shrink: 0;
    flex-wrap: wrap;
}

.metadata-footer span {
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

/* =========================================================================
   New for this domain — no counterpart in the ported design.
   ========================================================================= */

/* Case picker: native select wearing the outline-button skin. */
.case-select {
    appearance: none;
    padding-right: 28px;
    background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%2364748b' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 10px center;
    max-width: 320px;
}

/* Empty state */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    padding: 48px 24px;
    text-align: center;
    color: var(--text-secondary);
    flex: 1;
    min-height: 0;
}

.empty-state .empty-glyph { font-size: 2rem; opacity: 0.5; }
.empty-state .empty-title { font-size: 0.95rem; font-weight: 500; color: var(--text-primary); }
.empty-state .empty-hint { font-size: 0.8rem; line-height: 1.6; max-width: 460px; }

/* Run bar */
.run-bar {
    padding: 10px 20px;
    border-bottom: 1px solid var(--border-color);
    background: var(--bg-secondary);
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex-shrink: 0;
}

.run-bar[hidden] { display: none; }

.run-bar-top {
    display: flex;
    align-items: center;
    justify-content: space-between;
    font-size: 0.78rem;
    color: var(--text-secondary);
    gap: 12px;
}

.run-bar-detail {
    display: flex;
    align-items: center;
    gap: 12px;
    white-space: nowrap;
}

.progress-track {
    height: 4px;
    border-radius: 20px;
    background: var(--border-color);
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent-green);
    border-radius: 20px;
    transition: width 0.3s;
}

.progress-fill.indeterminate {
    width: 35%;
    animation: slide 1.2s ease-in-out infinite;
}

@keyframes slide {
    0%   { margin-left: 0; }
    50%  { margin-left: 65%; }
    100% { margin-left: 0; }
}

/* Error banner — reuses the confidence-low palette. */
.error-banner {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    margin: 12px 20px 0;
    padding: 10px 14px;
    border-radius: 8px;
    background: #fee2e2;
    color: #991b1b;
    border: 1px solid #fecaca;
    font-size: 0.8rem;
    line-height: 1.5;
    flex-shrink: 0;
}

.error-banner[hidden] { display: none; }
.error-banner .error-text { flex: 1; }
.error-banner .error-glyph { flex-shrink: 0; }

/* Spinner */
.spinner {
    width: 10px;
    height: 10px;
    border: 1.5px solid var(--border-color);
    border-top-color: var(--accent-green);
    border-radius: 50%;
    display: inline-block;
    animation: spin 0.7s linear infinite;
}

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

/* Viewer drop target */
.viewer-section.drag-over {
    outline: 2px dashed var(--accent-green);
    outline-offset: -8px;
    background: var(--accent-tint);
}

.viewer-section.drag-over .viewer-drop-target {
    background: var(--accent-tint);
    border-color: var(--accent-green);
}
