/* ========== Reset & Base ========== */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

[hidden] {
    display: none !important;
}

:root {
    --bg: #080808;
    --bg-surface: #131313;
    --bg-raised: #1e1e1e;
    --bg-inset: #0a0a0a;
    --text-primary: #d9d9d9;
    --text-secondary: #908d88;
    --text-muted: #58595b;
    --accent: #ff470c;
    --accent-glow: rgba(255, 71, 12, 0.25);
    --error: #dc3545;
    --shadow-dark: rgba(0, 0, 0, 0.7);
    --shadow-light: rgba(50, 50, 50, 0.12);
    --radius: 20px;
    --radius-sm: 12px;
    --transition: 0.25s ease;
}

html, body {
    height: 100%;
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

/* ========== Page Layout ========== */
.page {
    min-height: 100vh;
}

/* ========== Neo-Skeuomorphic Card ========== */
.card {
    background: var(--bg-surface);
    border-radius: var(--radius);
    box-shadow:
        8px 8px 20px var(--shadow-dark),
        -8px -8px 20px var(--shadow-light),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.card-inner {
    padding: 40px;
}

/* ========== Login Page ========== */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 20px;
    background:
        radial-gradient(ellipse at 30% 20%, rgba(255, 71, 12, 0.06) 0%, transparent 60%),
        radial-gradient(ellipse at 70% 80%, rgba(255, 71, 12, 0.03) 0%, transparent 50%),
        var(--bg);
}

.login-container .card {
    width: 100%;
    max-width: 420px;
}

.login-container h1 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 4px;
    letter-spacing: -0.5px;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 14px;
    margin-bottom: 32px;
}

/* ========== Form Elements ========== */
.input-group {
    margin-bottom: 20px;
}

.input-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 8px;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.input-wrapper {
    background: var(--bg-inset);
    border-radius: var(--radius-sm);
    box-shadow:
        inset 4px 4px 8px rgba(0, 0, 0, 0.4),
        inset -2px -2px 6px rgba(50, 50, 50, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.03);
    transition: box-shadow var(--transition), border-color var(--transition);
}

.input-wrapper:focus-within {
    border-color: var(--accent);
    box-shadow:
        inset 4px 4px 8px rgba(0, 0, 0, 0.4),
        inset -2px -2px 6px rgba(50, 50, 50, 0.08),
        0 0 0 3px var(--accent-glow);
}

.input-wrapper input {
    width: 100%;
    padding: 14px 16px;
    background: transparent;
    border: none;
    outline: none;
    color: var(--text-primary);
    font-size: 15px;
    font-family: inherit;
}

.input-wrapper input::placeholder {
    color: var(--text-muted);
}

/* ========== Buttons ========== */
.btn-primary {
    width: 100%;
    padding: 14px 24px;
    margin-top: 12px;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 15px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    position: relative;
    overflow: hidden;
    box-shadow:
        4px 4px 12px rgba(0, 0, 0, 0.4),
        -2px -2px 8px rgba(255, 71, 12, 0.15),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
    transition: transform var(--transition), box-shadow var(--transition);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow:
        6px 6px 16px rgba(0, 0, 0, 0.5),
        -3px -3px 10px rgba(255, 71, 12, 0.2),
        inset 0 1px 0 rgba(255, 255, 255, 0.15);
}

.btn-primary:active {
    transform: translateY(1px);
    box-shadow:
        2px 2px 6px rgba(0, 0, 0, 0.4),
        inset 0 2px 4px rgba(0, 0, 0, 0.2);
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    transform: none;
}

.btn-secondary {
    padding: 10px 20px;
    background: var(--bg-raised);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    box-shadow:
        3px 3px 8px var(--shadow-dark),
        -2px -2px 6px var(--shadow-light);
    transition: transform var(--transition), box-shadow var(--transition);
}

.btn-secondary:hover {
    transform: translateY(-1px);
    box-shadow:
        4px 4px 12px var(--shadow-dark),
        -3px -3px 8px var(--shadow-light);
}

.btn-secondary:active {
    transform: translateY(1px);
    box-shadow:
        1px 1px 3px var(--shadow-dark),
        inset 0 1px 3px rgba(0, 0, 0, 0.2);
}

/* ========== Loader ========== */
.btn-loader {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

/* ========== Processing Overlay ========== */
.processing-overlay {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: rgba(10, 10, 10, 0.85);
    backdrop-filter: blur(6px);
    z-index: 9999;
    gap: 24px;
}

.processing-spinner {
    width: 80px;
    height: 80px;
    border: 5px solid rgba(255, 255, 255, 0.1);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.processing-text {
    color: var(--text-secondary);
    font-size: 16px;
    font-weight: 500;
    letter-spacing: 0.3px;
    animation: pulse-text 1.5s ease-in-out infinite;
}

@keyframes pulse-text {
    0%, 100% { opacity: 0.6; }
    50% { opacity: 1; }
}

/* ========== Error Message ========== */
.error-message {
    color: var(--error);
    font-size: 13px;
    padding: 10px 14px;
    margin-top: 4px;
    background: rgba(255, 107, 107, 0.08);
    border-radius: 8px;
    border: 1px solid rgba(255, 107, 107, 0.15);
}

/* ========== Dashboard ========== */
.dashboard-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    background: #111111;
}

.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
    padding: 6px 12px;
    background: linear-gradient(180deg, #2b2b2b 0%, #1f1f1f 100%);
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    box-shadow: none;
}

.topbar h2 {
    font-size: 13px;
    font-weight: 600;
    letter-spacing: 0;
    color: #d5d5d5;
}

.topbar-logo {
    height: 18px;
    width: auto;
    display: block;
}

.topbar-left {
    display: flex;
    align-items: center;
    gap: 10px;
}

.topbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.provider-select {
    background: var(--bg-raised);
    color: var(--text-primary);
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: var(--radius-sm);
    padding: 6px 12px;
    font-size: 0.8rem;
    cursor: pointer;
    outline: none;
    transition: border-color var(--transition);
}

.provider-select:hover,
.provider-select:focus {
    border-color: var(--accent);
}

.provider-select option {
    background: var(--bg-raised);
    color: var(--text-primary);
}

.traffic-lights {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-right: 2px;
}

.traffic-light {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    box-shadow: inset 0 1px 1px rgba(255, 255, 255, 0.25), 0 0 0 1px rgba(0, 0, 0, 0.3);
}

.traffic-light-close {
    background: #ff5f57;
}

.traffic-light-minimize {
    background: #febc2e;
}

.traffic-light-zoom {
    background: #28c840;
}

.user-badge {
    font-size: 11px;
    color: var(--text-secondary);
    padding: 4px 8px;
    background: rgba(255, 255, 255, 0.04);
    border-radius: 6px;
    box-shadow: none;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.dashboard-content {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 8px;
    gap: 8px;
}

/* ========== Two-Panel Layout (diff-tool style) ========== */
.panels {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 8px;
    flex: 1;
    min-height: 0;
}

.panels > .card {
    display: flex;
    flex-direction: column;
    overflow: hidden;
    min-width: 0;
}

.panels > .card > .card-inner {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    padding: 8px;
    overflow: hidden;
}

.card {
    border-radius: 10px;
    background: #1b1b1b;
    box-shadow: none;
    border: 1px solid rgba(255, 255, 255, 0.07);
}

.panel-title {
    font-size: 12px;
    font-weight: 600;
    margin-bottom: 0;
}

.panel-desc {
    font-size: 11px;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.panel-header-compact {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    padding: 2px 2px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.06);
    margin-bottom: 8px;
}

.panel-meta {
    font-size: 10px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.4px;
}

/* ========== Upload Panel ========== */
.panel-upload .card-inner {
    gap: 0;
}

/* File Preview */
.file-preview {
    flex: 1;
    min-height: 0;
    overflow: hidden;
    border-radius: 8px;
    background: #141414;
    box-shadow: none;
    border: 1px solid rgba(255, 255, 255, 0.06);
}

.file-preview-empty {
    height: 100%;
    display: flex;
    flex-direction: column;
    gap: 10px;
    align-items: center;
    justify-content: center;
    color: var(--text-muted);
    font-size: 13px;
    cursor: pointer;
}

.file-preview.drag-over {
    border-color: rgba(255, 71, 12, 0.45);
    background: rgba(255, 71, 12, 0.05);
}

.file-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 6px 8px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    min-height: 32px;
}

.file-preview-meta {
    display: flex;
    flex-direction: column;
    min-width: 0;
}

.file-preview-name {
    font-size: 11px;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.file-preview-size {
    font-size: 10px;
    color: var(--text-muted);
}

.file-preview-body {
    height: calc(100% - 42px);
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: auto;
}

.file-preview-image {
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
}

.file-preview-pdf {
    width: 100%;
    height: 100%;
    border: none;
    background: #fff;
}

.file-preview-unsupported {
    color: var(--text-muted);
    font-size: 12px;
    padding: 10px;
    text-align: center;
}

/* ========== Form Panel ========== */
.ocr-form-area {
    position: relative;
    flex: 1;
    min-height: 0;
    overflow-y: auto;
    border-radius: 8px;
    background: #141414;
    border: 1px solid rgba(255, 255, 255, 0.06);
    padding: 8px;
}

.form-placeholder {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 100%;
    color: var(--text-muted);
    text-align: center;
    gap: 12px;
}

.form-placeholder span {
    font-size: 12px;
    max-width: 200px;
    line-height: 1.5;
}

.ocr-result-form {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.ocr-section {
    background: var(--bg-surface);
    border-radius: 8px;
    padding: 10px 10px 8px;
    margin: 0;
    border: 1px solid rgba(255, 255, 255, 0.04);
    box-shadow:
        4px 4px 10px var(--shadow-dark),
        -3px -3px 8px var(--shadow-light),
        inset 0 1px 0 rgba(255, 255, 255, 0.04);
}

.ocr-section-title {
    font-size: 10px;
    font-weight: 600;
    color: var(--accent);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 0 4px;
}

.ocr-row {
    display: grid;
    gap: 6px;
}

.ocr-cols-1 { grid-template-columns: 1fr; }
.ocr-cols-2 { grid-template-columns: 1fr 1fr; }
.ocr-cols-3 { grid-template-columns: 1fr 1fr 1fr; }
.ocr-cols-4 { grid-template-columns: 1fr 1fr 1fr 1fr; }

.ocr-field {
    display: flex;
    flex-direction: column;
    gap: 2px;
    min-width: 0;
}

.ocr-form-row {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.ocr-form-label {
    font-size: 9px;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.4px;
    padding-left: 2px;
}

.ocr-form-input {
    width: 100%;
    padding: 5px 8px;
    background: var(--bg-inset);
    border: 1px dashed rgba(255, 255, 255, 0.12);
    border-radius: 6px;
    outline: none;
    color: var(--text-primary);
    font-size: 12px;
    font-family: inherit;
    cursor: text;
    resize: vertical;
    box-shadow:
        inset 3px 3px 6px rgba(0, 0, 0, 0.4),
        inset -2px -2px 4px rgba(50, 50, 50, 0.08);
    transition: box-shadow var(--transition), border-color var(--transition), background var(--transition);
}

.ocr-form-input:hover {
    border-color: rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.03);
}

.ocr-form-input:focus {
    border-style: solid;
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.04);
    box-shadow:
        inset 3px 3px 6px rgba(0, 0, 0, 0.4),
        inset -2px -2px 4px rgba(50, 50, 50, 0.08),
        0 0 0 2px var(--accent-glow);
}

/* Line Items Table */
.ocr-table-wrap {
    overflow: hidden;
    background: var(--bg-inset);
    border-radius: 6px;
    box-shadow:
        inset 3px 3px 6px rgba(0, 0, 0, 0.35),
        inset -2px -2px 4px rgba(50, 50, 50, 0.06);
    border: 1px solid rgba(255, 255, 255, 0.03);
    padding: 4px;
}

.ocr-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 11px;
    table-layout: fixed;
}

.ocr-table th {
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    color: var(--text-secondary);
    font-weight: 600;
    padding: 4px 8px 4px 3px;
    text-align: left;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
    white-space: nowrap;
    position: relative;
}

.ocr-table th .col-resizer {
    position: absolute;
    right: -3px;
    top: 0;
    width: 7px;
    height: 100%;
    cursor: col-resize;
    z-index: 2;
    background: transparent;
}

.ocr-table th .col-resizer::after {
    content: '';
    position: absolute;
    right: 3px;
    top: 20%;
    width: 1px;
    height: 60%;
    background: rgba(255, 255, 255, 0.15);
    border-radius: 1px;
    transition: background 0.15s, width 0.15s;
}

.ocr-table th .col-resizer:hover::after,
.ocr-table th .col-resizer.resizing::after {
    width: 3px;
    right: 2px;
    background: var(--accent);
    top: 10%;
    height: 80%;
    border-radius: 2px;
}

.ocr-table td {
    padding: 2px 2px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.ocr-table-input {
    width: 100%;
    padding: 4px 5px;
    background: var(--bg-inset);
    border: 1px dashed rgba(255, 255, 255, 0.12);
    border-radius: 4px;
    color: var(--text-primary);
    font-size: 11px;
    font-family: inherit;
    outline: none;
    cursor: text;
    resize: none;
    overflow: hidden;
    box-shadow:
        inset 2px 2px 4px rgba(0, 0, 0, 0.35),
        inset -1px -1px 3px rgba(50, 50, 50, 0.06);
    transition: box-shadow var(--transition), border-color var(--transition), background var(--transition);
}

.ocr-table-input:hover {
    border-color: rgba(255, 255, 255, 0.25);
    background: rgba(255, 255, 255, 0.03);
}

.ocr-table-input:focus {
    border-style: solid;
    border-color: var(--accent);
    background: rgba(255, 255, 255, 0.04);
    box-shadow:
        inset 2px 2px 4px rgba(0, 0, 0, 0.35),
        inset -1px -1px 3px rgba(50, 50, 50, 0.06),
        0 0 0 2px var(--accent-glow);
}

.ocr-ti-xs { min-width: 36px; }
.ocr-ti-sm { min-width: 60px; }
.ocr-ti-md { min-width: 90px; }
.ocr-ti-lg { min-width: 120px; }

/* ========== Debug Panel ========== */
.panel-debug {
    flex-shrink: 0;
}

.panel-debug .card-inner {
    padding: 8px;
}

.debug-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.debug-header .panel-title {
    margin-bottom: 0;
}

.btn-icon {
    background: #2a2a2a;
    border: 1px solid rgba(255, 255, 255, 0.08);
    border-radius: 6px;
    padding: 4px;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    box-shadow: none;
    transition: color var(--transition), transform var(--transition);
}

.btn-icon:hover {
    color: var(--text-primary);
    transform: translateY(-1px);
}

.btn-icon:active {
    transform: translateY(1px);
}

.debug-actions {
    display: flex;
    gap: 4px;
}

.debug-output {
    display: block;
    width: 100%;
    background: #121212;
    border-radius: 8px;
    padding: 8px 10px;
    height: 120px;
    max-height: 160px;
    overflow-y: auto;
    resize: vertical;
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace;
    font-size: 11px;
    line-height: 1.5;
    box-shadow: none;
    border: 1px solid rgba(255, 255, 255, 0.06);
    white-space: pre-wrap;
    word-break: break-word;
    color: var(--text-muted);
    outline: none;
}

.btn-secondary,
.btn-top {
    width: auto;
    min-width: 0;
    margin-top: 0;
    padding: 6px 10px;
    font-size: 11px;
    line-height: 1.2;
    border-radius: 6px;
    box-shadow: none;
}

.btn-secondary {
    background: #2a2a2a;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-primary.btn-top {
    background: #3a3a3a;
    border: 1px solid rgba(255, 255, 255, 0.08);
}

.btn-primary.btn-top:hover,
.btn-secondary:hover,
.btn-icon:hover {
    transform: none;
}

.debug-output::-webkit-scrollbar {
    width: 6px;
}

.debug-output::-webkit-scrollbar-track {
    background: transparent;
}

.debug-output::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 3px;
}

/* ========== Animations ========== */
.page {
    animation: fadeIn 0.35s ease;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ========== Responsive ========== */
@media (max-width: 768px) {
    .dashboard-container {
        height: auto;
        overflow: auto;
    }
    .panels {
        grid-template-columns: 1fr;
    }
    .panels > .card {
        min-height: 350px;
    }
}

@media (max-width: 480px) {
    .panels > .card > .card-inner {
        padding: 20px 16px;
    }
    .dashboard-content {
        padding: 12px;
    }
    .topbar {
        padding: 12px 16px;
    }
}

/* ========== Pricing Panel ========== */
.bottom-panels {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.bottom-panels .panel-debug {
    flex: 1;
    min-width: 0;
}

.bottom-panels .panel-pricing {
    flex: 0 0 280px;
    min-width: 220px;
}

.panel-pricing {
    flex-shrink: 0;
}

.panel-pricing .card-inner {
    padding: 8px;
}

.pricing-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 8px;
}

.pricing-header .panel-title {
    margin-bottom: 0;
    display: flex;
    align-items: center;
}

.pricing-content {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.pricing-card {
    min-width: 0;
    background: #141414;
    border: 1px solid rgba(255, 255, 255, 0.06);
    border-radius: 8px;
    padding: 10px 12px;
}

.pricing-card-title {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.4px;
    color: var(--text-muted);
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.pricing-provider-badge {
    display: inline-block;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: 0.3px;
    padding: 2px 6px;
    border-radius: 4px;
    text-transform: uppercase;
}

.pricing-provider-badge.azure {
    background: rgba(0, 120, 212, 0.15);
    color: #4db8ff;
    border: 1px solid rgba(0, 120, 212, 0.25);
}

.pricing-provider-badge.openai {
    background: rgba(16, 163, 127, 0.15);
    color: #10a37f;
    border: 1px solid rgba(16, 163, 127, 0.25);
}

.pricing-rows {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.pricing-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 11px;
}

.pricing-row-label {
    color: var(--text-secondary);
}

.pricing-row-value {
    color: var(--text-primary);
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', Menlo, Consolas, monospace;
    font-size: 11px;
}

.pricing-divider {
    height: 1px;
    background: rgba(255, 255, 255, 0.06);
    margin: 4px 0;
}

.pricing-total-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    font-size: 12px;
    font-weight: 600;
    padding-top: 2px;
}

.pricing-total-row .pricing-row-label {
    color: var(--text-primary);
}

.pricing-total-row .pricing-row-value {
    color: var(--accent);
    font-size: 13px;
    font-weight: 700;
}

.pricing-empty {
    color: var(--text-muted);
    font-size: 11px;
    padding: 4px 0;
}
