/* ========================================
   CardScan AI — Premium Dark Theme
   ======================================== */

:root {
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: rgba(18, 18, 26, 0.8);
    --bg-card-hover: rgba(25, 25, 38, 0.9);
    --bg-glass: rgba(255, 255, 255, 0.03);
    --border-subtle: rgba(255, 255, 255, 0.06);
    --border-glow: rgba(255, 140, 50, 0.3);

    --text-primary: #f0f0f5;
    --text-secondary: #8888a0;
    --text-muted: #555570;

    --accent: #ff8c32;
    --accent-light: #ffb06a;
    --accent-dark: #e06a10;
    --accent-glow: rgba(255, 140, 50, 0.15);
    --accent-glow-strong: rgba(255, 140, 50, 0.35);

    --success: #2dd4a8;
    --error: #ff5c5c;
    --warning: #fbbf24;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --radius-xl: 28px;

    --shadow-card: 0 4px 24px rgba(0, 0, 0, 0.3), 0 1px 4px rgba(0, 0, 0, 0.2);
    --shadow-glow: 0 0 30px rgba(255, 140, 50, 0.1), 0 0 60px rgba(255, 140, 50, 0.05);

    --transition: 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-fast: 0.15s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    min-height: 100dvh;
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Animated Background */
.bg-gradient {
    position: fixed;
    inset: 0;
    background: 
        radial-gradient(ellipse 80% 60% at 50% 0%, rgba(255, 140, 50, 0.08) 0%, transparent 60%),
        radial-gradient(ellipse 60% 50% at 80% 100%, rgba(120, 80, 255, 0.05) 0%, transparent 50%),
        radial-gradient(ellipse 50% 40% at 10% 80%, rgba(255, 100, 50, 0.04) 0%, transparent 50%);
    z-index: -2;
    pointer-events: none;
}

.bg-grid {
    position: fixed;
    inset: 0;
    background-image: 
        linear-gradient(rgba(255,255,255,0.015) 1px, transparent 1px),
        linear-gradient(90deg, rgba(255,255,255,0.015) 1px, transparent 1px);
    background-size: 60px 60px;
    z-index: -1;
    pointer-events: none;
}

/* App Container */
.app-container {
    max-width: 480px;
    margin: 0 auto;
    padding: 0 16px;
    min-height: 100dvh;
    display: flex;
    flex-direction: column;
    position: relative;
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 0;
    position: sticky;
    top: 0;
    z-index: 100;
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    background: rgba(10, 10, 15, 0.7);
    margin: 0 -16px;
    padding: 16px;
}

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

.logo-icon {
    width: 44px;
    height: 44px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    display: flex;
    align-items: center;
    justify-content: center;
    color: white;
    box-shadow: 0 4px 16px rgba(255, 140, 50, 0.3);
}

.logo h1 {
    font-size: 1.25rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    background: linear-gradient(135deg, var(--text-primary), var(--accent-light));
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.tagline {
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    font-weight: 500;
}

.settings-btn {
    width: 40px;
    height: 40px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: var(--bg-glass);
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.settings-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

/* Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    opacity: 0;
    pointer-events: none;
    transition: var(--transition);
    padding: 20px;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: auto;
}

.modal {
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 400px;
    transform: translateY(20px) scale(0.95);
    transition: var(--transition);
    overflow: hidden;
}

.modal-overlay.active .modal {
    transform: translateY(0) scale(1);
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border-subtle);
}

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: var(--text-secondary);
    font-size: 1.4rem;
    cursor: pointer;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.modal-close:hover {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
}

.modal-body {
    padding: 24px;
}

.modal-body label {
    display: block;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
    margin-bottom: 8px;
}

.input-wrapper {
    position: relative;
    margin-bottom: 8px;
}

.input-wrapper input {
    width: 100%;
    padding: 12px 44px 12px 16px;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
    background: var(--bg-glass);
    color: var(--text-primary);
    font-family: 'Inter', monospace;
    font-size: 0.9rem;
    outline: none;
    transition: var(--transition);
}

.input-wrapper input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.toggle-visibility {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    width: 32px;
    height: 32px;
    border: none;
    background: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;
    transition: var(--transition-fast);
}

.toggle-visibility:hover {
    color: var(--text-secondary);
}

.api-hint {
    font-size: 0.78rem;
    color: var(--text-muted);
    margin-bottom: 20px;
}

.api-hint a {
    color: var(--accent);
    text-decoration: none;
}

.api-hint a:hover {
    text-decoration: underline;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 10px 20px;
    border-radius: var(--radius-sm);
    font-family: 'Inter', sans-serif;
    font-size: 0.9rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    white-space: nowrap;
}

.btn-primary {
    background: linear-gradient(135deg, var(--accent), var(--accent-dark));
    color: white;
    box-shadow: 0 4px 16px rgba(255, 140, 50, 0.25);
}

.btn-primary:hover {
    box-shadow: 0 6px 24px rgba(255, 140, 50, 0.35);
    transform: translateY(-1px);
}

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

.btn-secondary {
    background: var(--bg-glass);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
}

.btn-secondary:hover {
    border-color: rgba(255, 255, 255, 0.15);
    background: rgba(255, 255, 255, 0.06);
}

.btn-ghost {
    background: none;
    color: var(--text-secondary);
    padding: 8px 12px;
    font-size: 0.82rem;
}

.btn-ghost:hover {
    color: var(--accent);
}

.btn-large {
    padding: 14px 28px;
    font-size: 1rem;
    border-radius: var(--radius-md);
}

.btn-glow {
    box-shadow: 0 4px 20px rgba(255, 140, 50, 0.3), var(--shadow-glow);
    animation: pulseGlow 3s ease-in-out infinite;
}

@keyframes pulseGlow {
    0%, 100% { box-shadow: 0 4px 20px rgba(255, 140, 50, 0.3); }
    50% { box-shadow: 0 4px 30px rgba(255, 140, 50, 0.5), 0 0 50px rgba(255, 140, 50, 0.15); }
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 8px 0 32px;
}

/* Scan Section */
.scan-section {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100dvh - 120px);
}

.scan-card {
    text-align: center;
    padding: 40px 24px;
}

.scan-illustration {
    margin-bottom: 32px;
    display: flex;
    justify-content: center;
}

.card-mockup {
    width: 140px;
    height: 90px;
    border-radius: var(--radius-md);
    border: 2px solid rgba(255, 140, 50, 0.2);
    background: rgba(255, 140, 50, 0.04);
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    color: var(--accent);
}

.scan-line {
    position: absolute;
    left: 0;
    right: 0;
    height: 2px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    animation: scanLine 2.5s ease-in-out infinite;
    box-shadow: 0 0 15px var(--accent);
}

@keyframes scanLine {
    0% { top: 0; opacity: 0; }
    10% { opacity: 1; }
    90% { opacity: 1; }
    100% { top: 100%; opacity: 0; }
}

.scan-card h2 {
    font-size: 1.6rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    margin-bottom: 8px;
}

.scan-card p {
    color: var(--text-secondary);
    font-size: 0.9rem;
    line-height: 1.5;
    margin-bottom: 32px;
    max-width: 280px;
    margin-left: auto;
    margin-right: auto;
}

.capture-buttons {
    display: flex;
    flex-direction: column;
    gap: 12px;
    align-items: center;
}

.capture-buttons .btn {
    width: 100%;
    max-width: 260px;
}

/* Camera Interface Section */
.camera-section {
    position: fixed;
    inset: 0;
    z-index: 2000;
    background: #000;
    display: flex;
    flex-direction: column;
}

.camera-section.hidden {
    display: none;
}

.camera-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
}

#cameraFeed {
    position: absolute;
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.camera-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.5);
}

.camera-guide {
    position: relative;
    width: 85%;
    max-width: 400px;
    aspect-ratio: 1 / 1.5; /* Portrait orientation for card */
    box-shadow: 0 0 0 4000px rgba(0, 0, 0, 0.6);
    background: transparent;
    border-radius: var(--radius-md);
}

@media (min-aspect-ratio: 1/1) {
    .camera-guide {
        aspect-ratio: 1.5 / 1; /* Landscape orientation */
        width: 70%;
        max-width: 600px;
    }
}

.guide-corner {
    position: absolute;
    width: 30px;
    height: 30px;
    border: 3px solid var(--accent);
}

.guide-corner.top-left {
    top: -3px; left: -3px;
    border-right: none; border-bottom: none;
    border-top-left-radius: var(--radius-md);
}

.guide-corner.top-right {
    top: -3px; right: -3px;
    border-left: none; border-bottom: none;
    border-top-right-radius: var(--radius-md);
}

.guide-corner.bottom-left {
    bottom: -3px; left: -3px;
    border-right: none; border-top: none;
    border-bottom-left-radius: var(--radius-md);
}

.guide-corner.bottom-right {
    bottom: -3px; right: -3px;
    border-left: none; border-top: none;
    border-bottom-right-radius: var(--radius-md);
}

.guide-text {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    color: rgba(255, 255, 255, 0.5);
    font-size: 0.9rem;
    font-weight: 500;
    text-align: center;
    width: 100%;
    pointer-events: none;
}

.camera-controls {
    position: absolute;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 30px 40px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: linear-gradient(to top, rgba(0,0,0,0.8) 0%, transparent 100%);
    z-index: 10;
}

.icon-btn {
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: var(--transition);
}

.icon-btn:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(1.05);
}

.shutter-btn {
    width: 72px;
    height: 72px;
    border-radius: 50%;
    background: transparent;
    border: 4px solid white;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    padding: 0;
    transition: var(--transition-fast);
}

.shutter-inner {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: white;
    transition: var(--transition-fast);
}

.shutter-btn:active .shutter-inner {
    transform: scale(0.9);
    background: var(--accent);
}

/* Processing Section */
.processing-section {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: calc(100dvh - 120px);
}

.process-card {
    width: 100%;
}

.image-preview-container {
    position: relative;
    border-radius: var(--radius-lg);
    overflow: hidden;
    margin-bottom: 28px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
}

.image-preview-container img {
    width: 100%;
    display: block;
    max-height: 300px;
    object-fit: contain;
    background: var(--bg-secondary);
}

.scan-overlay {
    position: absolute;
    inset: 0;
    pointer-events: none;
}

.scan-beam {
    position: absolute;
    left: 0;
    right: 0;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--accent), transparent);
    box-shadow: 0 0 20px var(--accent), 0 0 60px rgba(255, 140, 50, 0.3);
    animation: scanBeam 2s ease-in-out infinite;
}

@keyframes scanBeam {
    0% { top: 0%; }
    100% { top: 100%; }
}

.process-steps {
    display: flex;
    flex-direction: column;
    gap: 16px;
    margin-bottom: 24px;
}

.step {
    display: flex;
    align-items: center;
    gap: 14px;
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    background: var(--bg-glass);
    border: 1px solid var(--border-subtle);
    opacity: 0.4;
    transition: var(--transition);
}

.step.active {
    opacity: 1;
    border-color: var(--accent);
    background: var(--accent-glow);
}

.step.done {
    opacity: 1;
    border-color: var(--success);
    background: rgba(45, 212, 168, 0.08);
}

.step-indicator {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

.step-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
}

.step.done .step-dot {
    background: var(--success);
    width: 24px;
    height: 24px;
    border-radius: 50%;
    position: relative;
}

.step.done .step-dot::after {
    content: '✓';
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--bg-primary);
    font-size: 0.7rem;
    font-weight: 700;
}

.spinner {
    width: 22px;
    height: 22px;
    border: 2.5px solid rgba(255, 140, 50, 0.2);
    border-top-color: var(--accent);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.step span {
    font-size: 0.9rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.step.active span {
    color: var(--text-primary);
}

.step.done span {
    color: var(--success);
}

.ocr-progress {
    display: flex;
    align-items: center;
    gap: 12px;
}

.progress-bar {
    flex: 1;
    height: 4px;
    border-radius: 2px;
    background: rgba(255, 255, 255, 0.06);
    overflow: hidden;
}

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

.progress-text {
    font-size: 0.78rem;
    color: var(--text-muted);
    font-weight: 600;
    min-width: 36px;
    text-align: right;
    font-variant-numeric: tabular-nums;
}

/* Results Section */
.results-section {
    animation: fadeInUp 0.5s ease;
}

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

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

.results-header h2 {
    font-size: 1.3rem;
    font-weight: 700;
}

.preview-thumb-container {
    border-radius: var(--radius-md);
    overflow: hidden;
    margin-bottom: 24px;
    border: 1px solid var(--border-subtle);
    background: var(--bg-secondary);
}

.preview-thumb {
    width: 100%;
    max-height: 200px;
    object-fit: contain;
    display: block;
}

/* Entity Cards */
.entity-cards {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 28px;
}

.entity-card {
    display: flex;
    align-items: flex-start;
    gap: 14px;
    padding: 14px 16px;
    border-radius: var(--radius-md);
    background: var(--bg-card);
    border: 1px solid var(--border-subtle);
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    transition: var(--transition);
}

.entity-card:hover {
    border-color: rgba(255, 255, 255, 0.1);
    background: var(--bg-card-hover);
}

.entity-icon {
    width: 38px;
    height: 38px;
    border-radius: var(--radius-sm);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 1.1rem;
}

.entity-icon.name { background: rgba(255, 140, 50, 0.12); color: var(--accent); }
.entity-icon.org { background: rgba(120, 80, 255, 0.12); color: #9070ff; }
.entity-icon.des { background: rgba(45, 212, 168, 0.12); color: var(--success); }
.entity-icon.phone { background: rgba(50, 140, 255, 0.12); color: #5090ff; }
.entity-icon.email { background: rgba(255, 90, 120, 0.12); color: #ff6080; }
.entity-icon.web { background: rgba(0, 200, 200, 0.12); color: #30d0d0; }

.entity-content {
    flex: 1;
    min-width: 0;
}

.entity-label {
    font-size: 0.72rem;
    text-transform: uppercase;
    letter-spacing: 0.08em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 4px;
}

.entity-value {
    width: 100%;
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: 'Inter', sans-serif;
    font-size: 0.95rem;
    font-weight: 500;
    outline: none;
    padding: 2px 0;
    border-bottom: 1px solid transparent;
    transition: var(--transition-fast);
}

.entity-value:focus {
    border-bottom-color: var(--accent);
}

.entity-value::placeholder {
    color: var(--text-muted);
    font-style: italic;
}

/* Action Buttons */
.action-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.action-buttons .btn {
    width: 100%;
}

/* Toast */
.toast {
    position: fixed;
    bottom: 30px;
    left: 50%;
    transform: translateX(-50%) translateY(20px);
    background: var(--bg-secondary);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 0.88rem;
    font-weight: 500;
    box-shadow: var(--shadow-card);
    z-index: 2000;
    opacity: 0;
    transition: var(--transition);
    pointer-events: none;
}

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

/* Utility */
.hidden {
    display: none !important;
}

/* Scrollbar */
::-webkit-scrollbar {
    width: 4px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.1);
    border-radius: 2px;
}

/* Error state for no API key */
.api-missing-banner {
    background: rgba(255, 92, 92, 0.1);
    border: 1px solid rgba(255, 92, 92, 0.2);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 0.85rem;
    color: var(--error);
    cursor: pointer;
    transition: var(--transition);
}

.api-missing-banner:hover {
    background: rgba(255, 92, 92, 0.15);
}

/* Responsive */
@media (min-width: 600px) {
    .app-container {
        padding: 0 24px;
    }
    
    .capture-buttons {
        flex-direction: row;
        justify-content: center;
    }
    
    .capture-buttons .btn {
        width: auto;
        max-width: none;
    }

    .action-buttons {
        flex-direction: row;
    }
}
