@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
    --bg-gradient: radial-gradient(circle at top right, #1a103c 0%, #0c081e 50%, #05030a 100%);
    --panel-bg: rgba(20, 15, 45, 0.45);
    --panel-border: rgba(255, 255, 255, 0.08);
    --text-primary: #f3f0ff;
    --text-secondary: #a59fc4;
    --accent-purple: #9d4edd;
    --accent-neon: #00f5d4;
    --accent-neon-glow: rgba(0, 245, 212, 0.35);
    --accent-purple-glow: rgba(157, 78, 221, 0.35);
    --error: #ff5a5f;
    --success: #2ec4b6;
    
    --font-sans: 'Outfit', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    
    --shadow-glow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --blur-strength: 16px;
}

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

body {
    font-family: var(--font-sans);
    background: var(--bg-gradient);
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    overflow-x: hidden;
    padding: 16px;
    -webkit-font-smoothing: antialiased;
}

/* Scrollbars */
::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}
::-webkit-scrollbar-track {
    background: rgba(0, 0, 0, 0.1);
}
::-webkit-scrollbar-thumb {
    background: var(--panel-border);
    border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover {
    background: var(--accent-purple);
}

/* Layout Containers */
.container {
    max-width: 600px;
    width: 100%;
    margin: 0 auto;
    display: flex;
    flex-direction: column;
    gap: 20px;
    flex-grow: 1;
}

header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    background: var(--panel-bg);
    backdrop-filter: blur(var(--blur-strength));
    -webkit-backdrop-filter: blur(var(--blur-strength));
    border: 1px solid var(--panel-border);
    border-radius: 20px;
    box-shadow: var(--shadow-glow);
}

.logo-container {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 32px;
    height: 32px;
    background: linear-gradient(135deg, var(--accent-purple) 0%, var(--accent-neon) 100%);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: 700;
    color: #05030a;
    font-size: 1.1rem;
    box-shadow: 0 0 15px rgba(157, 78, 221, 0.5);
}

h1 {
    font-size: 1.4rem;
    font-weight: 600;
    letter-spacing: -0.5px;
    background: linear-gradient(to right, #ffffff, #d3c7ff);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}

.api-status {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.8rem;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.25);
    padding: 6px 12px;
    border-radius: 20px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

.api-status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: var(--error);
    box-shadow: 0 0 8px var(--error);
}

.api-status-dot.active {
    background-color: var(--success);
    box-shadow: 0 0 8px var(--success);
}

/* Glass Card Base */
.card {
    background: var(--panel-bg);
    backdrop-filter: blur(var(--blur-strength));
    -webkit-backdrop-filter: blur(var(--blur-strength));
    border: 1px solid var(--panel-border);
    border-radius: 24px;
    padding: 24px;
    box-shadow: var(--shadow-glow);
    display: flex;
    flex-direction: column;
    gap: 16px;
    transition: transform 0.3s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.3s ease;
}

/* Upload Panel */
.upload-zone {
    border: 2px dashed rgba(255, 255, 255, 0.15);
    border-radius: 20px;
    padding: 40px 20px;
    text-align: center;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    transition: all 0.3s ease;
    background: rgba(0, 0, 0, 0.15);
}

.upload-zone:hover, .upload-zone.dragover {
    border-color: var(--accent-neon);
    background: rgba(0, 245, 212, 0.03);
    box-shadow: 0 0 20px rgba(0, 245, 212, 0.1);
}

.upload-icon {
    width: 64px;
    height: 64px;
    border-radius: 50%;
    background: rgba(157, 78, 221, 0.1);
    border: 1px solid rgba(157, 78, 221, 0.2);
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--accent-purple);
    font-size: 1.8rem;
    transition: all 0.3s ease;
}

.upload-zone:hover .upload-icon {
    transform: scale(1.1);
    background: rgba(0, 245, 212, 0.1);
    border-color: rgba(0, 245, 212, 0.3);
    color: var(--accent-neon);
    box-shadow: 0 0 15px var(--accent-neon-glow);
}

.upload-title {
    font-size: 1.15rem;
    font-weight: 500;
}

.upload-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
    max-width: 250px;
    line-height: 1.4;
}

#fileInput {
    display: none;
}

/* Camera Toggle and Live View */
.btn-secondary-link {
    background: none;
    border: none;
    color: var(--accent-neon);
    font-family: var(--font-sans);
    font-size: 0.9rem;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 6px;
    align-self: center;
    padding: 8px 16px;
    border-radius: 12px;
    transition: all 0.2s ease;
}

.btn-secondary-link:hover {
    background: rgba(0, 245, 212, 0.08);
}

.live-camera-container {
    display: none;
    position: relative;
    border-radius: 20px;
    overflow: hidden;
    border: 1px solid var(--panel-border);
    background: #000;
    aspect-ratio: 3/4;
    width: 100%;
}

#cameraVideo {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    border: 20px solid rgba(0, 0, 0, 0.4);
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
}

.camera-guide-box {
    border: 2px dashed var(--accent-neon);
    width: 80%;
    height: 80%;
    border-radius: 12px;
    box-shadow: 0 0 15px rgba(0, 245, 212, 0.2);
}

.camera-controls {
    position: absolute;
    bottom: 20px;
    left: 0;
    right: 0;
    display: flex;
    justify-content: center;
    gap: 20px;
    pointer-events: auto;
}

/* Buttons */
.btn {
    background: linear-gradient(135deg, var(--accent-purple) 0%, #7b2cbf 100%);
    color: white;
    border: none;
    padding: 14px 28px;
    border-radius: 16px;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    box-shadow: 0 4px 15px rgba(157, 78, 221, 0.4);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(157, 78, 221, 0.6);
}

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

.btn-success {
    background: linear-gradient(135deg, var(--accent-neon) 0%, #00bb9b 100%);
    color: #05030a;
    box-shadow: 0 4px 15px rgba(0, 245, 212, 0.4);
}

.btn-success:hover {
    box-shadow: 0 6px 20px rgba(0, 245, 212, 0.6);
}

.btn-circle {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    padding: 0;
    font-size: 1.4rem;
}

.btn-close {
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(5px);
    box-shadow: none;
    border: 1px solid rgba(255,255,255,0.1);
}
.btn-close:hover {
    background: rgba(255, 255, 255, 0.1);
    box-shadow: none;
}

/* Scanning Screen Overlay */
.scanning-container {
    display: none;
    position: relative;
    border-radius: 20px;
    overflow: hidden;
    aspect-ratio: 4/5;
    background: #110d29;
    border: 1px solid var(--panel-border);
}

#previewImage {
    width: 100%;
    height: 100%;
    object-fit: contain;
    opacity: 0.65;
}

.laser-line {
    position: absolute;
    width: 100%;
    height: 4px;
    background: linear-gradient(90deg, transparent 0%, var(--accent-neon) 50%, transparent 100%);
    box-shadow: 0 0 15px var(--accent-neon), 0 0 25px var(--accent-neon);
    top: 0;
    left: 0;
    z-index: 10;
    animation: scanAnim 2.2s infinite ease-in-out;
}

.scanning-spinner-box {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(5, 3, 10, 0.8);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 24px;
    border-radius: 20px;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    text-align: center;
    width: 80%;
    max-width: 280px;
    box-shadow: 0 10px 40px rgba(0,0,0,0.6);
}

.spinner {
    width: 40px;
    height: 40px;
    border: 3px solid rgba(0, 245, 212, 0.1);
    border-radius: 50%;
    border-top-color: var(--accent-neon);
    animation: spin 1s linear infinite;
    box-shadow: 0 0 8px var(--accent-neon-glow);
}

.scanning-text {
    font-size: 0.95rem;
    font-weight: 500;
    letter-spacing: 0.2px;
}

.scanning-subtext {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

@keyframes scanAnim {
    0% { top: 0%; }
    50% { top: 98%; }
    100% { top: 0%; }
}

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

/* Results Section */
.results-container {
    display: none;
    flex-direction: column;
    gap: 16px;
}

/* Tabs Navigation */
.tabs {
    display: flex;
    background: rgba(0, 0, 0, 0.2);
    border: 1px solid var(--panel-border);
    padding: 4px;
    border-radius: 16px;
    gap: 4px;
}

.tab {
    flex: 1;
    background: none;
    border: none;
    color: var(--text-secondary);
    padding: 12px 6px;
    border-radius: 12px;
    font-family: var(--font-sans);
    font-weight: 600;
    font-size: 0.85rem;
    cursor: pointer;
    transition: all 0.25s ease;
    text-align: center;
}

.tab.active {
    background: var(--panel-bg);
    color: var(--accent-neon);
    border: 1px solid rgba(255, 255, 255, 0.05);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

/* Tab Panels */
.tab-content {
    display: none;
}

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

/* Structured Dashboard Styles */
.meta-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}

.meta-item {
    background: rgba(0, 0, 0, 0.15);
    padding: 12px 16px;
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.03);
}

.meta-item.full-width {
    grid-column: span 2;
}

.meta-label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 4px;
}

.meta-value {
    font-weight: 600;
    font-size: 0.95rem;
    word-break: break-all;
}

/* Finance totals cards */
.totals-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
}

.total-card {
    background: rgba(0, 0, 0, 0.25);
    border-radius: 16px;
    padding: 12px 8px;
    text-align: center;
    border: 1px solid rgba(255,255,255,0.03);
}

.total-card.gross {
    background: linear-gradient(135deg, rgba(157, 78, 221, 0.15) 0%, rgba(0, 245, 212, 0.08) 100%);
    border: 1px solid rgba(0, 245, 212, 0.2);
    box-shadow: 0 4px 15px rgba(0, 245, 212, 0.05);
}

.total-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 2px;
}

.total-val {
    font-size: 1.15rem;
    font-weight: 700;
    color: var(--text-primary);
}

.total-card.gross .total-val {
    color: var(--accent-neon);
}

/* Items Table */
.table-container {
    overflow-x: auto;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    border: 1px solid rgba(255, 255, 255, 0.05);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    text-align: left;
}

th {
    background: rgba(255, 255, 255, 0.03);
    padding: 10px 12px;
    font-weight: 600;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    text-transform: uppercase;
    font-size: 0.7rem;
}

td {
    padding: 10px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.03);
    color: var(--text-primary);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

.col-qty {
    text-align: center;
    color: var(--text-secondary);
}

.col-price {
    text-align: right;
}

.col-vat {
    text-align: center;
}

/* Raw Output views (Markdown / JSON) */
.output-actions {
    display: flex;
    gap: 10px;
    margin-bottom: 12px;
}

.btn-action {
    flex: 1;
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
    padding: 10px 16px;
    border-radius: 12px;
    font-family: var(--font-sans);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    transition: all 0.2s ease;
}

.btn-action:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: var(--accent-neon);
    color: var(--accent-neon);
}

.code-area {
    width: 100%;
    height: 320px;
    background: rgba(0, 0, 0, 0.4);
    border: 1px solid var(--panel-border);
    border-radius: 16px;
    padding: 16px;
    color: #e2e0ff;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.85rem;
    line-height: 1.5;
    resize: none;
    outline: none;
}

.markdown-rendered-view {
    max-height: 320px;
    overflow-y: auto;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 16px;
    padding: 16px;
    border: 1px solid rgba(255,255,255,0.03);
    font-size: 0.9rem;
    line-height: 1.6;
}

.markdown-rendered-view h1, .markdown-rendered-view h2, .markdown-rendered-view h3 {
    margin-top: 14px;
    margin-bottom: 8px;
    color: #ffffff;
}

.markdown-rendered-view p {
    margin-bottom: 10px;
    color: var(--text-secondary);
}

.markdown-rendered-view table {
    margin: 12px 0;
}

/* History List Panel */
.history-section {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.section-title {
    font-size: 0.9rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    background: rgba(0, 0, 0, 0.15);
    border: 1px solid rgba(255, 255, 255, 0.03);
    border-radius: 16px;
    padding: 12px 16px;
    cursor: pointer;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: all 0.2s ease;
}

.history-item:hover {
    background: rgba(157, 78, 221, 0.06);
    border-color: rgba(157, 78, 221, 0.2);
    transform: translateX(2px);
}

.history-vendor {
    font-weight: 600;
    font-size: 0.95rem;
    margin-bottom: 2px;
}

.history-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.history-gross {
    font-weight: 700;
    color: var(--accent-neon);
    font-size: 1.05rem;
}

.empty-history {
    text-align: center;
    font-size: 0.85rem;
    color: var(--text-secondary);
    padding: 16px;
    border-radius: 16px;
    border: 1px dashed rgba(255,255,255,0.05);
    background: rgba(0,0,0,0.1);
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: rgba(10, 5, 25, 0.9);
    border: 1px solid var(--accent-neon);
    box-shadow: 0 0 15px rgba(0, 245, 212, 0.25);
    color: var(--accent-neon);
    padding: 12px 24px;
    border-radius: 30px;
    font-weight: 600;
    font-size: 0.9rem;
    z-index: 999;
    pointer-events: none;
    transition: transform 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.toast.show {
    transform: translateX(-50%) translateY(0);
}

/* Footer style */
footer {
    text-align: center;
    font-size: 0.75rem;
    color: rgba(255, 255, 255, 0.15);
    margin-top: auto;
    padding: 24px 0 8px 0;
}
