:root {
    --bg-primary: hsl(230, 35%, 7%);
    --bg-sidebar: hsla(230, 35%, 9%, 0.85);
    --bg-card: hsla(230, 25%, 14%, 0.45);
    --bg-card-hover: hsla(230, 25%, 18%, 0.6);
    --border-color: hsla(230, 20%, 30%, 0.25);
    --border-glow: hsla(185, 80%, 55%, 0.15);
    --accent-teal: hsl(185, 95%, 48%);
    --accent-teal-hover: hsl(185, 100%, 60%);
    --accent-purple: hsl(265, 80%, 65%);
    --text-primary: hsl(220, 20%, 96%);
    --text-secondary: hsl(220, 15%, 75%);
    --text-muted: hsl(220, 12%, 55%);
    --success-green: hsl(142, 76%, 45%);
    --error-red: hsl(350, 76%, 50%);
    --warning-orange: hsl(35, 85%, 55%);
    --font-family: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body, html {
    height: 100%;
    background: var(--bg-primary);
    color: var(--text-primary);
    font-family: var(--font-family);
    overflow: hidden;
    line-height: 1.5;
}

.app-container {
    display: grid;
    grid-template-columns: 320px 1fr;
    height: 100dvh;
    height: 100vh;
    width: 100vw;
    background-image:
        radial-gradient(circle at 10% 20%, hsla(185, 70%, 40%, 0.08) 0%, transparent 40%),
        radial-gradient(circle at 80% 80%, hsla(265, 70%, 40%, 0.06) 0%, transparent 40%);
}

.sidebar {
    background: var(--bg-sidebar);
    border-right: 1px solid var(--border-color);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    height: 100dvh;
    height: 100vh;
    overflow-y: auto;
    z-index: 10;
}

.brand-section {
    padding: 24px;
    display: flex;
    align-items: center;
    gap: 12px;
    border-bottom: 1px solid var(--border-color);
}

.logo-container {
    width: 40px;
    height: 40px;
    background: linear-gradient(135deg, var(--accent-teal), var(--accent-purple));
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.brand-logo {
    width: 22px;
    height: 22px;
    color: #fff;
}

.brand-section h1 {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.3px;
}

.subtitle {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 400;
}

.status-card {
    margin: 16px;
    padding: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.status-card h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 8px;
    font-size: 13px;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-dot.green { background: var(--success-green); box-shadow: 0 0 6px var(--success-green); }
.status-dot.red { background: var(--error-red); box-shadow: 0 0 6px var(--error-red); }

.api-warning-banner {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    padding: 10px;
    margin-top: 8px;
    background: hsla(35, 85%, 55%, 0.1);
    border: 1px solid hsla(35, 85%, 55%, 0.2);
    border-radius: 8px;
    font-size: 12px;
    color: var(--warning-orange);
    line-height: 1.4;
}

.api-warning-banner .warning-icon { width: 16px; height: 16px; flex-shrink: 0; margin-top: 1px; }
.api-warning-banner code {
    background: hsla(0, 0%, 0%, 0.3);
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 11px;
}

.upload-section {
    padding: 0 16px;
    margin-bottom: 12px;
}

.upload-section h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.dropzone {
    border: 1.5px dashed var(--border-color);
    border-radius: 12px;
    padding: 24px 16px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
}

.dropzone:hover, .dropzone.drag-over {
    border-color: var(--accent-teal);
    background: hsla(185, 80%, 50%, 0.05);
}

.upload-icon { width: 32px; height: 32px; color: var(--text-muted); margin-bottom: 8px; }
.dropzone-text { font-size: 14px; color: var(--text-secondary); }
.dropzone-link { color: var(--accent-teal); font-weight: 500; }
.dropzone-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }

.upload-progress {
    margin-top: 12px;
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
}

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

.progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-teal), var(--accent-purple));
    border-radius: 2px;
    transition: width 0.3s ease;
}

.progress-text { font-size: 12px; color: var(--text-muted); margin-top: 6px; text-align: center; }

.history-section {
    flex: 1;
    padding: 0 16px 16px;
    display: flex;
    flex-direction: column;
    min-height: 0;
}

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

.history-header h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
}

.history-count {
    background: var(--bg-card);
    padding: 2px 8px;
    border-radius: 10px;
    font-size: 12px;
    color: var(--text-secondary);
}

.export-bar {
    display: flex;
    gap: 4px;
    margin-bottom: 8px;
}

.export-btn {
    flex: 1;
    padding: 6px 0;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-family);
    font-size: 11px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.export-btn:hover {
    border-color: var(--accent-teal);
    color: var(--accent-teal);
    background: hsla(185, 80%, 50%, 0.05);
}

.invoice-list {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.invoice-list .empty-state {
    font-size: 13px;
    color: var(--text-muted);
    text-align: center;
    padding: 20px 0;
}

.invoice-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    margin-bottom: 4px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    cursor: pointer;
    transition: var(--transition);
}

.invoice-item:hover {
    background: var(--bg-card-hover);
    border-color: var(--accent-teal);
}

.invoice-item.active {
    border-color: var(--accent-teal);
    box-shadow: 0 0 10px var(--border-glow);
}

.invoice-item-info {
    flex: 1;
    min-width: 0;
}

.invoice-item-name {
    font-size: 13px;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.invoice-item-meta {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: 2px;
}

.invoice-item-total {
    font-size: 14px;
    font-weight: 600;
    color: var(--accent-teal);
    margin-left: 8px;
}

.invoice-item-delete {
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 4px;
    border-radius: 4px;
    margin-left: 4px;
}

.invoice-item-delete:hover { color: var(--error-red); }

/* Main Panel */
.main-panel {
    display: flex;
    flex-direction: column;
    height: 100dvh;
    height: 100vh;
    overflow-y: auto;
    padding: 32px 40px;
}

.welcome-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 100%;
    text-align: center;
}

.welcome-content { max-width: 480px; }

.welcome-icon {
    width: 80px;
    height: 80px;
    color: var(--accent-teal);
    margin-bottom: 24px;
}

.welcome-content h2 {
    font-size: 28px;
    font-weight: 700;
    margin-bottom: 12px;
}

.welcome-content p {
    font-size: 15px;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 24px;
}

.btn-primary {
    padding: 12px 28px;
    border: none;
    border-radius: 10px;
    background: linear-gradient(135deg, var(--accent-teal), var(--accent-purple));
    color: #fff;
    font-family: var(--font-family);
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px hsla(185, 80%, 50%, 0.25);
}

.hidden { display: none !important; }

.result-panel { display: flex; flex-direction: column; height: 100%; }

.result-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 16px;
    margin-bottom: 20px;
    padding-bottom: 16px;
    border-bottom: 1px solid var(--border-color);
}

.result-header h2 { font-size: 22px; font-weight: 700; }
.result-subtitle { font-size: 13px; color: var(--text-muted); margin-top: 4px; }

.result-actions {
    display: flex;
    gap: 6px;
    flex-shrink: 0;
}

.btn-secondary {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    background: transparent;
    color: var(--text-secondary);
    font-family: var(--font-family);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-secondary:hover {
    border-color: var(--accent-teal);
    color: var(--accent-teal);
    background: hsla(185, 80%, 50%, 0.05);
}

.details-wrapper {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.detail-card {
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 20px;
    -webkit-backdrop-filter: blur(10px);
    backdrop-filter: blur(10px);
}

.detail-card h3 {
    font-size: 11px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 12px;
}

.detail-field {}
.detail-field label {
    display: block;
    font-size: 11px;
    color: var(--text-muted);
    margin-bottom: 2px;
}

.detail-field .value {
    font-size: 14px;
    font-weight: 500;
    word-break: break-word;
}

.detail-field input {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    background: hsla(230, 20%, 10%, 0.6);
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 14px;
    outline: none;
    transition: var(--transition);
}

.detail-field input:focus {
    border-color: var(--accent-teal);
    box-shadow: 0 0 8px var(--border-glow);
}

.line-items-table {
    width: 100%;
    border-collapse: collapse;
}

.line-items-table th {
    text-align: left;
    font-size: 11px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 8px 12px;
    border-bottom: 1px solid var(--border-color);
}

.line-items-table td {
    padding: 8px 12px;
    font-size: 13px;
    border-bottom: 1px solid var(--border-color);
}

.line-items-table input {
    width: 100%;
    padding: 4px 6px;
    border: 1px solid transparent;
    border-radius: 4px;
    background: transparent;
    color: var(--text-primary);
    font-family: var(--font-family);
    font-size: 13px;
    outline: none;
    transition: var(--transition);
}

.line-items-table input:focus {
    border-color: var(--accent-teal);
    background: hsla(230, 20%, 10%, 0.6);
}

.confidence-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 500;
}

.confidence-badge.high { background: hsla(142, 76%, 45%, 0.15); color: var(--success-green); }
.confidence-badge.medium { background: hsla(35, 85%, 55%, 0.15); color: var(--warning-orange); }
.confidence-badge.low { background: hsla(350, 76%, 50%, 0.15); color: var(--error-red); }

/* Toast */
.toast-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
    z-index: 100;
}

.toast {
    padding: 12px 18px;
    border-radius: 10px;
    background: var(--bg-card);
    border: 1px solid var(--border-color);
    -webkit-backdrop-filter: blur(20px);
    backdrop-filter: blur(20px);
    font-size: 13px;
    color: var(--text-primary);
    animation: slideIn 0.3s ease;
    max-width: 360px;
}

.toast.error { border-color: var(--error-red); color: var(--error-red); }
.toast.success { border-color: var(--success-green); color: var(--success-green); }

@keyframes slideIn {
    from { opacity: 0; transform: translateX(20px); }
    to { opacity: 1; transform: translateX(0); }
}

@media (max-width: 768px) {
    .app-container { grid-template-columns: 1fr; }
    .sidebar { display: none; }
    .main-panel { padding: 20px; }
}
