:root {
    --bg-color: #080710;
    --panel-bg: rgba(17, 24, 39, 0.45);
    --border-color: rgba(255, 255, 255, 0.08);
    --primary-glow: rgba(99, 102, 241, 0.15);
    --secondary-glow: rgba(168, 85, 247, 0.15);
    --text-main: #f3f4f6;
    --text-muted: #9ca3af;
    --accent-purple: #a855f7;
    --accent-indigo: #6366f1;
    --accent-green: #10b981;
    --accent-blue: #3b82f6;
}

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

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

/* Ambient Glow Blobs */
.glow-blob {
    position: absolute;
    width: 600px;
    height: 600px;
    border-radius: 50%;
    pointer-events: none;
    filter: blur(120px);
    z-index: 0;
}
.glow-1 {
    top: -150px;
    left: -150px;
    background: radial-gradient(circle, var(--primary-glow) 0%, rgba(0,0,0,0) 70%);
}
.glow-2 {
    bottom: -150px;
    right: -150px;
    background: radial-gradient(circle, var(--secondary-glow) 0%, rgba(0,0,0,0) 70%);
}

.wrapper {
    position: relative;
    z-index: 10;
    max-width: 1600px;
    width: 100%;
    margin: 0 auto;
    padding: 20px;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.wrapper > .initial-workspace {
    overflow-y: auto;
    flex: 1;
    min-height: 0;
}

/* Header Styling */
header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    margin-bottom: 20px;
    flex-shrink: 0;
}

.brand-title {
    font-family: 'Outfit', sans-serif;
    font-size: 2.0rem;
    font-weight: 700;
    background: linear-gradient(135deg, #ffffff 30%, #a855f7 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    display: flex;
    align-items: center;
    gap: 12px;
    cursor: pointer;
}

.brand-logo-dot {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background-color: var(--accent-purple);
    box-shadow: 0 0 15px var(--accent-purple);
    animation: pulse-glow 2s infinite;
}

@keyframes pulse-glow {
    0% { box-shadow: 0 0 10px rgba(168, 85, 247, 0.5); }
    50% { box-shadow: 0 0 20px rgba(168, 85, 247, 0.9); }
    100% { box-shadow: 0 0 10px rgba(168, 85, 247, 0.5); }
}

.header-controls {
    display: flex;
    align-items: center;
    gap: 16px;
}

.credentials-pill-container {
    display: flex;
    gap: 12px;
}

.cred-pill {
    background: rgba(255, 255, 255, 0.04);
    border: 1px solid var(--border-color);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    display: flex;
    align-items: center;
    gap: 8px;
    color: var(--text-muted);
}

.cred-pill.ok span { color: var(--accent-green); }
.cred-pill.missing span { color: #ef4444; }

.status-indicator {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}
.status-ok {
    background-color: var(--accent-green);
    box-shadow: 0 0 8px var(--accent-green);
}
.status-missing {
    background-color: #ef4444;
    box-shadow: 0 0 8px #ef4444;
}

.run-another-btn {
    background: linear-gradient(135deg, var(--accent-indigo) 0%, var(--accent-purple) 100%);
    border: none;
    color: white;
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.2);
    transition: all 0.2s ease;
    display: none;
    align-items: center;
    gap: 6px;
}

.run-another-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.35);
}

/* Glassmorphic Panel Base */
.glass-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 16px;
    padding: 24px;
    box-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
}

.panel-heading {
    font-family: 'Outfit', sans-serif;
    font-size: 1.25rem;
    font-weight: 600;
    margin-bottom: 20px;
    color: #ffffff;
    border-left: 3px solid var(--accent-purple);
    padding-left: 10px;
}

/* ==========================================
   STATE 1: UPLOAD & CONFIGURATION WORKSPACE
   ========================================== */
.initial-workspace {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 30px;
    align-items: stretch;
}

.upload-zone {
    border: 2px dashed rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 45px 20px;
    text-align: center;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    background: rgba(255, 255, 255, 0.01);
    margin-bottom: 20px;
    position: relative;
    overflow: hidden;
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent-purple);
    background: rgba(168, 85, 247, 0.03);
    box-shadow: inset 0 0 20px rgba(168, 85, 247, 0.05);
}

.upload-icon {
    font-size: 2.5rem;
    margin-bottom: 12px;
    filter: drop-shadow(0 0 8px rgba(168, 85, 247, 0.3));
}

.file-input { display: none; }

/* Configuration Forms */
.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 0.88rem;
    color: var(--text-muted);
    margin-bottom: 8px;
    font-weight: 500;
}

.select-input, .textarea-input {
    width: 100%;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 10px 14px;
    color: white;
    font-size: 0.9rem;
    outline: none;
    transition: all 0.2s;
}

.select-input:focus, .textarea-input:focus {
    border-color: var(--accent-purple);
    box-shadow: 0 0 8px rgba(168, 85, 247, 0.25);
    background: rgba(255, 255, 255, 0.05);
}

.textarea-input {
    height: 140px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    resize: vertical;
}

/* Toggle Enhancer Bar */
.toggle-container {
    display: flex;
    align-items: center;
    justify-content: space-between;
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    padding: 12px 16px;
    border-radius: 10px;
    margin-bottom: 25px;
}

.switch-label-container {
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.switch {
    position: relative;
    display: inline-block;
    width: 44px;
    height: 24px;
}

.switch input { opacity: 0; width: 0; height: 0; }

.slider {
    position: absolute;
    cursor: pointer;
    top: 0; left: 0; right: 0; bottom: 0;
    background-color: rgba(255, 255, 255, 0.1);
    transition: .4s;
    border-radius: 24px;
    border: 1px solid var(--border-color);
}

.slider:before {
    position: absolute;
    content: "";
    height: 16px;
    width: 16px;
    left: 3px;
    bottom: 3px;
    background-color: white;
    transition: .4s;
    border-radius: 50%;
}

input:checked + .slider {
    background-color: var(--accent-indigo);
    box-shadow: 0 0 10px rgba(99, 102, 241, 0.4);
}

input:checked + .slider:before {
    transform: translateX(20px);
}

/* Trigger Button */
.action-btn {
    width: 100%;
    background: linear-gradient(135deg, var(--accent-indigo) 0%, var(--accent-purple) 100%);
    color: white;
    border: none;
    padding: 14px;
    border-radius: 8px;
    font-size: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s;
    box-shadow: 0 4px 15px rgba(99, 102, 241, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.action-btn:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.action-btn:active { transform: translateY(0); }

.btn-disabled {
    background: rgba(255, 255, 255, 0.05) !important;
    color: var(--text-muted) !important;
    border: 1px solid var(--border-color) !important;
    box-shadow: none !important;
    cursor: not-allowed !important;
    transform: none !important;
}

/* Visual Info / Guide Panel */
.guide-panel {
    min-height: 480px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    text-align: center;
    padding: 40px;
    border: 1px dashed rgba(255,255,255,0.06);
    background: rgba(255,255,255,0.01);
}

.guide-art {
    font-size: 4rem;
    margin-bottom: 20px;
    animation: float 4s ease-in-out infinite;
}

@keyframes float {
    0%, 100% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
}

/* ==========================================
   LOADING SKETCH & PROGRESS STATE
   ========================================== */
.loading-overlay {
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 100px 40px;
    flex: 1;
}

.skeleton-loader {
    width: 80px;
    height: 80px;
    position: relative;
    margin-bottom: 30px;
}

.skeleton-circle {
    width: 100%;
    height: 100%;
    border-radius: 50%;
    border: 4px solid transparent;
    border-top-color: var(--accent-purple);
    border-bottom-color: var(--accent-indigo);
    animation: spin 1.5s linear infinite;
}

.skeleton-inner {
    position: absolute;
    top: 15px; left: 15px; right: 15px; bottom: 15px;
    border-radius: 50%;
    border: 4px solid transparent;
    border-left-color: var(--accent-green);
    animation: spin-reverse 1s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

@keyframes spin-reverse {
    0% { transform: rotate(360deg); }
    100% { transform: rotate(0deg); }
}

.progress-text {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 12px;
    text-align: center;
    background: linear-gradient(135deg, #ffffff 40%, var(--accent-indigo) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.progress-subtext {
    color: var(--text-muted);
    font-size: 0.9rem;
    max-width: 400px;
    text-align: center;
    line-height: 1.5;
}

/* ==========================================
   STATE 2: INTERACTIVE VISUAL EXPLORER
   ========================================== */
.explorer-workspace {
    display: none;
    grid-template-columns: 1fr 2.4fr;
    gap: 25px;
    flex: 1;
    min-height: 0;
    height: 100%;
    align-items: stretch;
    overflow: hidden;
}

/* LEFT PANE: PDF Viewer controls & Canvas */
.viewer-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}

.viewer-toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 16px;
    background: rgba(255,255,255,0.03);
    border-bottom: 1px solid var(--border-color);
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    flex-shrink: 0;
}

.toolbar-group {
    display: flex;
    align-items: center;
    gap: 12px;
}

.toolbar-btn {
    background: rgba(255,255,255,0.05);
    border: 1px solid var(--border-color);
    color: var(--text-main);
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.15s;
    display: flex;
    align-items: center;
    justify-content: center;
    min-width: 32px;
    height: 32px;
}

.toolbar-btn:hover {
    background: rgba(255,255,255,0.1);
    border-color: rgba(255,255,255,0.2);
}

.page-indicator-input {
    width: 42px;
    height: 32px;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: white;
    text-align: center;
    font-size: 0.85rem;
    font-family: inherit;
    outline: none;
    transition: all 0.15s;
}

.page-indicator-input:focus {
    border-color: var(--accent-purple);
}

/* Remove input arrows */
.page-indicator-input::-webkit-outer-spin-button,
.page-indicator-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.viewer-body {
    flex: 1;
    overflow: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 24px;
    position: relative;
    background: rgba(0, 0, 0, 0.2);
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 16px;
    scrollbar-width: none; /* Firefox */
    -ms-overflow-style: none;  /* IE and Edge */
}

.viewer-body::-webkit-scrollbar {
    display: none; /* Chrome, Safari and Opera */
}

.page-canvas-wrapper {
    position: relative;
    background: white;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.6);
    transform-origin: top center;
    transition: transform 0.2s ease;
}

.page-canvas {
    position: relative;
}

#pdf-render-canvas {
    display: block;
    max-width: 100%;
}

.box-layer {
    position: absolute;
    top: 0; left: 0; width: 100%; height: 100%;
    pointer-events: none;
    z-index: 5;
}

/* Neon Glowing Visual Bounding Boxes */
.grounding-box {
    position: absolute;
    border: 1.5px solid rgba(99, 102, 241, 0.4); /* Neon Indigo standard */
    background: rgba(99, 102, 241, 0.02);
    pointer-events: auto;
    cursor: pointer;
    transition: all 0.15s ease;
}

.grounding-box:hover, .grounding-box.highlight {
    border-color: var(--accent-purple) !important;
    background: rgba(168, 85, 247, 0.12) !important;
    box-shadow: 0 0 12px rgba(168, 85, 247, 0.5) !important;
    z-index: 10;
}

.grounding-box.is-visual {
    border-color: rgba(16, 185, 129, 0.4); /* Neon Green for figures/tables */
    background: rgba(16, 185, 129, 0.02);
}

.grounding-box.is-visual:hover, .grounding-box.is-visual.highlight {
    border-color: var(--accent-green) !important;
    background: rgba(16, 185, 129, 0.12) !important;
    box-shadow: 0 0 12px rgba(16, 185, 129, 0.5) !important;
}

/* RIGHT PANE: Results Panel & Tabs */
.results-panel {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    height: 100%;
}

.results-header-tabs {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
    background: rgba(255,255,255,0.02);
    padding: 8px 16px;
    border-top-left-radius: 16px;
    border-top-right-radius: 16px;
    flex-shrink: 0;
}

.tab-group {
    display: flex;
    gap: 6px;
    background: rgba(0,0,0,0.25);
    padding: 3px;
    border-radius: 8px;
    border: 1px solid var(--border-color);
}

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

.tab-btn:hover {
    color: white;
    background: rgba(255,255,255,0.03);
}

.tab-btn.active {
    background: rgba(99, 102, 241, 0.15);
    border: 1px solid rgba(99, 102, 241, 0.25);
    color: #c7d2fe;
    box-shadow: 0 2px 8px rgba(99, 102, 241, 0.15);
}

.tab-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

.tab-content-container {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    position: relative;
    background: rgba(255, 255, 255, 0.01);
    border-bottom-left-radius: 16px;
    border-bottom-right-radius: 16px;
}

.tab-pane {
    display: none;
    height: 100%;
    overflow-y: auto;
    padding: 24px;
}

.tab-pane.active {
    display: block;
}

/* ===== TAB 1: EXTRACTION TABLE ===== */
.extraction-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    overflow: hidden;
    font-size: 0.88rem;
}

.extraction-table thead th {
    background: rgba(255,255,255,0.03);
    padding: 12px 16px;
    text-align: left;
    font-size: 0.72rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: var(--text-muted);
    border-bottom: 1px solid var(--border-color);
}

.extraction-table thead th.col-key { width: 220px; }

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

.extraction-table tbody tr td {
    border-bottom: 1px solid var(--border-color);
    padding: 14px 16px;
    vertical-align: top;
}

.extraction-table tbody tr:last-child td {
    border-bottom: none;
}

.extraction-table tbody tr:hover {
    background: rgba(99, 102, 241, 0.04);
}

.extraction-table tbody tr.active {
    background: rgba(168, 85, 247, 0.06);
    box-shadow: inset 3px 0 0 var(--accent-purple);
}

.field-key-name {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.82rem;
    color: #a5b4fc;
    font-weight: 500;
}

.field-icon {
    font-size: 0.9rem;
    margin-right: 6px;
}

.col-value {
    color: var(--text-main);
    line-height: 1.6;
    word-break: break-word;
}

/* Pill styling inside tables */
.pill-list {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
}

.tag-pill {
    display: inline-flex;
    align-items: center;
    padding: 4px 10px;
    border-radius: 12px;
    font-size: 0.76rem;
    font-weight: 500;
    border: 1px solid rgba(255, 255, 255, 0.08);
    background: rgba(255, 255, 255, 0.03);
    color: var(--text-main);
    transition: all 0.15s ease;
}

.tag-pill:hover, .tag-pill.active {
    border-color: var(--accent-indigo);
    background: rgba(99, 102, 241, 0.15);
    color: #c7d2fe;
}

/* ===== TAB 2: GROUNDING SEGMENTS ===== */
.grounding-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.grounding-box-card {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 16px;
    transition: all 0.2s;
}

.grounding-box-card:hover {
    border-color: rgba(255, 255, 255, 0.15);
    background: rgba(255,255,255,0.03);
}

.grounding-box-card.active {
    border-color: var(--accent-purple);
    box-shadow: 0 0 10px rgba(168, 85, 247, 0.15);
    background: rgba(168, 85, 247, 0.02);
}

.grounding-card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 0.85rem;
    margin-bottom: 8px;
}

.grounding-coords-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 10px;
}

.coord-pill {
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-color);
    padding: 3px 8px;
    border-radius: 4px;
    font-size: 0.72rem;
    font-family: 'JetBrains Mono', monospace;
    color: var(--text-muted);
}

.coord-pill span { color: #f3f4f6; }

/* ===== TAB 3: MARKDOWN CHUNKS ===== */
.chunk-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.chunk-item {
    border: 1px solid var(--border-color);
    padding: 14px;
    border-radius: 8px;
    background: rgba(255, 255, 255, 0.01);
    transition: all 0.2s;
    cursor: pointer;
}

.chunk-item:hover {
    border-color: rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.03);
}

.chunk-item.active {
    border-color: var(--accent-green);
    background: rgba(16, 185, 129, 0.03);
}

.chunk-label {
    font-size: 0.74rem;
    color: var(--text-muted);
    margin-bottom: 6px;
    display: block;
    font-weight: 500;
}

.chunk-body {
    font-size: 0.85rem;
    line-height: 1.6;
    color: var(--text-main);
}

.chunk-body table {
    width: 100%;
    border-collapse: collapse;
    margin: 10px 0;
    font-size: 0.78rem;
}

.chunk-body table th, .chunk-body table td {
    border: 1px solid var(--border-color);
    padding: 8px 12px;
    text-align: left;
}

.chunk-body table th {
    background: rgba(255,255,255,0.03);
    font-weight: 600;
}

/* ===== TAB 4: JSON EXPLORER ===== */
.json-pre {
    font-family: 'JetBrains Mono', monospace;
    font-size: 0.8rem;
    color: #f3f4f6;
    white-space: pre-wrap;
    word-wrap: break-word;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--border-color);
    padding: 16px;
    border-radius: 8px;
}

.json-chunk-item {
    cursor: pointer;
    padding: 2px 6px;
    border-radius: 4px;
    transition: all 0.15s;
}

.json-chunk-item:hover {
    background: rgba(255, 255, 255, 0.03);
}

.json-chunk-item.active {
    background: rgba(99, 102, 241, 0.15);
    border-left: 2px solid var(--accent-indigo);
}

/* Accuracy Semantic Metadata block */
.card-meta-section {
    margin-top: 14px;
    padding-top: 12px;
    border-top: 1px dashed rgba(255, 255, 255, 0.05);
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.meta-row {
    font-size: 0.82rem;
    color: var(--text-muted);
    line-height: 1.5;
}

.meta-label {
    font-weight: 600;
    color: #c7d2fe;
    margin-right: 6px;
}

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

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