/* ===== DESIGN TOKENS ===== */
:root {
    --bg-primary: #0f0a1e;
    --bg-secondary: #1a1232;
    --bg-card: rgba(30, 22, 56, 0.85);
    --bg-card-hover: rgba(40, 30, 70, 0.95);
    --bg-input: rgba(255, 255, 255, 0.06);
    --bg-input-focus: rgba(255, 255, 255, 0.1);

    --text-primary: #f0ecf9;
    --text-secondary: #a69bbf;
    --text-muted: #6b5f82;

    --accent-1: #7c5cfc;
    --accent-2: #b44cfa;
    --accent-3: #e040fb;
    --accent-gradient: linear-gradient(135deg, var(--accent-1), var(--accent-2), var(--accent-3));

    --success: #4cdf90;
    --warning: #ffc245;
    --danger: #ff5577;
    --info: #50b5ff;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.25);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.35);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 30px rgba(124, 92, 252, 0.3);

    --font: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== RESET & BASE ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
    font-size: 16px;
    scroll-behavior: smooth;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font);
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    line-height: 1.6;
    overflow-x: hidden;
    background-image:
        radial-gradient(ellipse at 20% 0%, rgba(124, 92, 252, 0.12) 0%, transparent 60%),
        radial-gradient(ellipse at 80% 100%, rgba(180, 76, 250, 0.08) 0%, transparent 60%);
}

/* ===== HEADER ===== */
#app-header {
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    background: rgba(15, 10, 30, 0.75);
    border-bottom: 1px solid rgba(124, 92, 252, 0.15);
}

.header-inner {
    max-width: 1100px;
    margin: 0 auto;
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.logo {
    display: flex;
    align-items: center;
    gap: 10px;
}

.logo-icon {
    width: 28px;
    height: 28px;
    color: var(--accent-2);
    filter: drop-shadow(0 0 6px rgba(180, 76, 250, 0.5));
}

.logo-text {
    font-size: 1.25rem;
    font-weight: 700;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    letter-spacing: -0.02em;
}

.badge-btn {
    display: flex;
    align-items: center;
    gap: 6px;
    background: var(--bg-card);
    border: 1px solid rgba(124, 92, 252, 0.25);
    color: var(--text-primary);
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
}

.badge-btn svg { width: 16px; height: 16px; }
.badge-btn:hover { background: var(--bg-card-hover); border-color: var(--accent-1); }

/* ===== VIEWS ===== */
.view { display: none; padding: 20px; max-width: 1100px; margin: 0 auto; }
.view.active { display: block; animation: fadeIn 0.4s ease; }

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(12px); }
    to { opacity: 1; transform: translateY(0); }
}

/* ===== VIEW 1: UPLOAD ===== */
.upload-hero {
    text-align: center;
    padding: 40px 0 30px;
    position: relative;
}

.hero-glow {
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 340px;
    height: 340px;
    background: radial-gradient(circle, rgba(124, 92, 252, 0.2), transparent 70%);
    pointer-events: none;
    animation: pulse 4s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { opacity: 0.5; transform: translateX(-50%) scale(1); }
    50% { opacity: 1; transform: translateX(-50%) scale(1.15); }
}

.upload-hero h1 {
    font-size: clamp(1.8rem, 5vw, 2.8rem);
    font-weight: 800;
    letter-spacing: -0.03em;
    line-height: 1.2;
    position: relative;
}

.gradient-text {
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.subtitle {
    color: var(--text-secondary);
    font-size: 1.05rem;
    margin-top: 10px;
    font-weight: 400;
}

/* Upload Method Cards */
.upload-methods {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    margin-bottom: 20px;
}

.upload-card {
    position: relative;
    background: var(--bg-card);
    border: 1px solid rgba(124, 92, 252, 0.15);
    border-radius: var(--radius-lg);
    padding: 32px 20px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    overflow: hidden;
}

.upload-card::before {
    content: '';
    position: absolute;
    inset: 0;
    background: var(--accent-gradient);
    opacity: 0;
    transition: opacity 0.4s;
    border-radius: inherit;
}

.upload-card:hover, .upload-card:active {
    border-color: var(--accent-1);
    transform: translateY(-3px);
    box-shadow: var(--shadow-glow);
}

.upload-card:hover::before, .upload-card:active::before { opacity: 0.06; }

.upload-card-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 16px;
    position: relative;
}

.camera-icon { background: rgba(124, 92, 252, 0.15); color: var(--accent-1); }
.gallery-icon { background: rgba(180, 76, 250, 0.15); color: var(--accent-2); }

.upload-card-icon svg { width: 28px; height: 28px; }

.upload-card h3 {
    font-size: 1.1rem;
    font-weight: 600;
    margin-bottom: 4px;
    position: relative;
}

.upload-card p {
    font-size: 0.85rem;
    color: var(--text-secondary);
    position: relative;
}

.file-input-hidden {
    position: absolute;
    opacity: 0;
    width: 0;
    height: 0;
    pointer-events: none;
}

.upload-card-overlay {
    position: absolute;
    inset: 0;
    cursor: pointer;
    z-index: 2;
}

/* Drag & Drop Zone */
.drop-zone {
    border: 2px dashed rgba(124, 92, 252, 0.25);
    border-radius: var(--radius-lg);
    padding: 40px 20px;
    text-align: center;
    transition: var(--transition);
    margin-bottom: 24px;
}

.drop-zone.drag-over {
    border-color: var(--accent-1);
    background: rgba(124, 92, 252, 0.08);
    box-shadow: var(--shadow-glow);
}

.drop-zone-content svg {
    width: 40px;
    height: 40px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

.drop-zone-content p {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
}

.drop-hint {
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 6px;
    display: block;
}

/* Invoice Queue */
.invoice-queue {
    margin-top: 10px;
}

.queue-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 14px;
    flex-wrap: wrap;
    gap: 10px;
}

.queue-header h3 { font-size: 1.1rem; font-weight: 600; }

.queue-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.queue-item {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    background: var(--bg-card);
    border: 1px solid rgba(124, 92, 252, 0.1);
    border-radius: var(--radius-md);
    transition: var(--transition);
    cursor: pointer;
}

.queue-item:hover {
    border-color: var(--accent-1);
    background: var(--bg-card-hover);
}

.queue-item-thumb {
    width: 44px;
    height: 44px;
    border-radius: 10px;
    object-fit: cover;
    flex-shrink: 0;
}

.queue-item-info { flex: 1; min-width: 0; }
.queue-item-info strong { font-size: 0.9rem; display: block; }
.queue-item-info span { font-size: 0.78rem; color: var(--text-secondary); }

.queue-item-actions { display: flex; gap: 8px; }

.queue-item-btn {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    border: none;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.queue-item-btn svg { width: 16px; height: 16px; }
.queue-item-btn.edit { background: rgba(124, 92, 252, 0.15); color: var(--accent-1); }
.queue-item-btn.delete { background: rgba(255, 85, 119, 0.12); color: var(--danger); }
.queue-item-btn:hover { transform: scale(1.1); }

/* ===== VIEW 2: PROCESSING ===== */
.processing-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 30px;
    padding: 30px 0;
}

.processing-preview {
    width: 100%;
    max-width: 340px;
    border-radius: var(--radius-lg);
    overflow: hidden;
    position: relative;
    box-shadow: var(--shadow-lg);
    border: 1px solid rgba(124, 92, 252, 0.2);
}

.processing-preview img {
    width: 100%;
    display: block;
}

.scanner-animation {
    position: absolute;
    inset: 0;
    pointer-events: none;
    overflow: hidden;
    border-radius: var(--radius-lg);
}

.scan-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 3px;
    background: var(--accent-gradient);
    box-shadow: 0 0 20px rgba(124, 92, 252, 0.6), 0 0 60px rgba(180, 76, 250, 0.3);
    animation: scanMove 2s ease-in-out infinite;
}

@keyframes scanMove {
    0% { top: 0; }
    50% { top: 100%; }
    100% { top: 0; }
}

.processing-status {
    text-align: center;
    position: relative;
}

.processing-status h2 {
    font-size: 1.4rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.processing-status p {
    color: var(--text-secondary);
    font-size: 0.95rem;
    margin-bottom: 20px;
}

.progress-bar-container {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 24px;
}

.progress-bar {
    flex: 1;
    height: 8px;
    background: var(--bg-input);
    border-radius: 4px;
    overflow: hidden;
    min-width: 200px;
}

.progress-fill {
    height: 100%;
    width: 0%;
    background: var(--accent-gradient);
    border-radius: 4px;
    transition: width 0.3s ease;
}

.progress-text {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--accent-2);
    min-width: 40px;
}

.processing-steps {
    display: flex;
    flex-direction: column;
    gap: 10px;
    text-align: left;
}

.step {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.9rem;
    color: var(--text-muted);
    transition: color 0.3s;
}

.step.active { color: var(--text-primary); }
.step.done { color: var(--success); }

.step-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--text-muted);
    flex-shrink: 0;
    transition: var(--transition);
}

.step.active .step-dot {
    background: var(--accent-1);
    box-shadow: 0 0 8px rgba(124, 92, 252, 0.6);
    animation: dotPulse 1s ease-in-out infinite;
}

.step.done .step-dot { background: var(--success); }

@keyframes dotPulse {
    0%, 100% { transform: scale(1); }
    50% { transform: scale(1.4); }
}

/* ===== VIEW 3: REVIEW ===== */
.review-container {
    display: flex;
    flex-direction: column;
    gap: 20px;
    padding-bottom: 30px;
}

.review-card {
    background: var(--bg-card);
    border: 1px solid rgba(124, 92, 252, 0.12);
    border-radius: var(--radius-lg);
    padding: 24px;
    backdrop-filter: blur(10px);
}

.review-card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 20px;
    flex-wrap: wrap;
    gap: 10px;
}

.review-card-header h2 {
    font-size: 1.15rem;
    font-weight: 700;
}

.confidence-badge {
    padding: 4px 14px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
}

.confidence-high { background: rgba(76, 223, 144, 0.15); color: var(--success); }
.confidence-mid { background: rgba(255, 194, 69, 0.15); color: var(--warning); }
.confidence-low { background: rgba(255, 85, 119, 0.15); color: var(--danger); }

/* Detail Grid */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 14px;
}

.detail-field {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.detail-field label {
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
}

.detail-field input,
.detail-field select {
    background: var(--bg-input);
    border: 1px solid rgba(124, 92, 252, 0.12);
    border-radius: var(--radius-sm);
    padding: 10px 14px;
    font-size: 0.95rem;
    color: var(--text-primary);
    font-family: var(--font);
    transition: var(--transition);
    width: 100%;
}

.detail-field input:focus,
.detail-field select:focus {
    outline: none;
    border-color: var(--accent-1);
    background: var(--bg-input-focus);
    box-shadow: 0 0 0 3px rgba(124, 92, 252, 0.15);
}

/* Items Table */
.table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    border-radius: var(--radius-md);
}

.items-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 860px;
    font-size: 0.88rem;
}

.items-table thead th {
    background: rgba(124, 92, 252, 0.1);
    padding: 12px 10px;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    white-space: nowrap;
    border-bottom: 1px solid rgba(124, 92, 252, 0.1);
}

.items-table tbody td {
    padding: 6px 4px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
    vertical-align: middle;
}

.items-table tbody tr:hover {
    background: rgba(124, 92, 252, 0.04);
}

.items-table tbody td input {
    width: 100%;
    background: transparent;
    border: 1px solid transparent;
    padding: 8px 8px;
    font-size: 0.88rem;
    color: var(--text-primary);
    font-family: var(--font);
    border-radius: 6px;
    transition: var(--transition);
}

.items-table tbody td input:focus {
    outline: none;
    background: var(--bg-input);
    border-color: var(--accent-1);
}

.items-table tbody td input::placeholder { color: var(--text-muted); }

.row-delete-btn {
    width: 30px;
    height: 30px;
    border: none;
    background: rgba(255, 85, 119, 0.1);
    color: var(--danger);
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

.row-delete-btn:hover { background: rgba(255, 85, 119, 0.25); transform: scale(1.1); }
.row-delete-btn svg { width: 16px; height: 16px; }

/* Raw Text */
.raw-text-card summary {
    cursor: pointer;
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-secondary);
    padding: 4px 0;
}

.raw-text-card summary:hover { color: var(--text-primary); }

.raw-text {
    margin-top: 12px;
    padding: 16px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: var(--radius-md);
    font-size: 0.82rem;
    line-height: 1.7;
    color: var(--text-secondary);
    white-space: pre-wrap;
    word-break: break-word;
    max-height: 300px;
    overflow-y: auto;
}

/* ===== ACTION BUTTONS ===== */
.review-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
    padding-top: 6px;
}

.btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 600;
    font-family: var(--font);
    cursor: pointer;
    border: none;
    transition: var(--transition);
    white-space: nowrap;
}

.btn svg { width: 18px; height: 18px; flex-shrink: 0; }
.btn:active { transform: scale(0.97); }

.btn-primary {
    background: var(--accent-gradient);
    color: #fff;
    box-shadow: 0 4px 20px rgba(124, 92, 252, 0.35);
}
.btn-primary:hover { box-shadow: 0 6px 30px rgba(124, 92, 252, 0.5); transform: translateY(-1px); }

.btn-secondary {
    background: rgba(124, 92, 252, 0.15);
    color: var(--accent-1);
    border: 1px solid rgba(124, 92, 252, 0.2);
}
.btn-secondary:hover { background: rgba(124, 92, 252, 0.25); }

.btn-outline {
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid rgba(255, 255, 255, 0.12);
}
.btn-outline:hover { background: var(--bg-card); border-color: var(--accent-1); color: var(--text-primary); }

.btn-sm { padding: 8px 16px; font-size: 0.85rem; border-radius: var(--radius-sm); }
.btn-sm svg { width: 15px; height: 15px; }

/* ===== TOAST ===== */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 14px 24px;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    border: 1px solid rgba(124, 92, 252, 0.2);
    color: var(--text-primary);
    font-size: 0.9rem;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    z-index: 200;
    opacity: 0;
    transition: all 0.4s cubic-bezier(0.4, 0, 0.2, 1);
    backdrop-filter: blur(16px);
    pointer-events: none;
}

.toast.visible {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

.toast.success { border-color: var(--success); }
.toast.error { border-color: var(--danger); }

/* ===== RESPONSIVE ===== */
@media (max-width: 600px) {
    .view { padding: 14px; }
    .upload-hero { padding: 24px 0 20px; }
    .upload-methods { gap: 12px; }
    .upload-card { padding: 24px 14px; }
    .review-card { padding: 16px; }
    .detail-grid { grid-template-columns: 1fr; }
    .review-actions { flex-direction: column; }
    .review-actions .btn { width: 100%; justify-content: center; }
    .drop-zone { display: none; }
    .queue-header { flex-direction: column; align-items: flex-start; }
}

@media (min-width: 768px) {
    .processing-container {
        flex-direction: row;
        align-items: flex-start;
    }
    .processing-preview { max-width: 300px; }
    .processing-status { text-align: left; flex: 1; }
}

/* ===== SCROLLBAR ===== */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(124, 92, 252, 0.25); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(124, 92, 252, 0.4); }

/* ===== SELECTION ===== */
::selection { background: rgba(124, 92, 252, 0.35); color: #fff; }
