/* ===== CSS Reset & Variables ===== */
*,
*::before,
*::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    /* Color Palette - Modern Dark Theme */
    --bg-primary: #0a0a0f;
    --bg-secondary: #12121a;
    --bg-card: rgba(255, 255, 255, 0.05);
    --bg-glass: rgba(255, 255, 255, 0.08);

    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.7);
    --text-muted: rgba(255, 255, 255, 0.4);

    --accent-primary: #6366f1;
    --accent-secondary: #8b5cf6;
    --accent-gradient: linear-gradient(135deg, #6366f1 0%, #a855f7 50%, #ec4899 100%);

    --success: #10b981;
    --warning: #f59e0b;
    --error: #ef4444;

    /* Glassmorphism */
    --glass-bg: rgba(255, 255, 255, 0.06);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-blur: 20px;

    /* Spacing */
    --spacing-xs: 4px;
    --spacing-sm: 8px;
    --spacing-md: 16px;
    --spacing-lg: 24px;
    --spacing-xl: 32px;

    /* Border Radius */
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 20px;
    --radius-full: 9999px;

    /* Shadows */
    --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
    --shadow-md: 0 4px 20px rgba(0, 0, 0, 0.3);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.4);
    --shadow-glow: 0 0 40px rgba(99, 102, 241, 0.3);

    /* Transitions */
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
    --transition-slow: 400ms cubic-bezier(0.4, 0, 0.2, 1);
}

/* ===== Base Styles ===== */
html,
body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    overflow-x: hidden;
    -webkit-font-smoothing: antialiased;
}

body {
    background:
        radial-gradient(ellipse at 20% 0%, rgba(99, 102, 241, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 100%, rgba(168, 85, 247, 0.1) 0%, transparent 50%),
        var(--bg-primary);
}

/* ===== App Container ===== */
.app-container {
    min-height: 100%;
    max-width: 100%;
    display: flex;
    flex-direction: column;
    padding: var(--spacing-md);
    padding-bottom: calc(var(--spacing-xl) + env(safe-area-inset-bottom));
}

/* ===== Header ===== */
.app-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-md) 0;
    margin-bottom: var(--spacing-md);
}

.logo {
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.logo-icon {
    font-size: 28px;
    filter: drop-shadow(0 0 10px rgba(99, 102, 241, 0.5));
}

.logo h1 {
    font-size: 20px;
    font-weight: 600;
    background: var(--accent-gradient);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.settings-btn {
    width: 44px;
    height: 44px;
    border: none;
    background: var(--glass-bg);
    border-radius: var(--radius-md);
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-normal);
    border: 1px solid var(--glass-border);
}

.settings-btn:hover {
    background: var(--bg-glass);
    color: var(--text-primary);
    transform: rotate(45deg);
}

/* ===== Camera Section ===== */
.camera-section {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.camera-container {
    position: relative;
    width: 100%;
    aspect-ratio: 4/3;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-lg);
}

#videoPreview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: none;
}

#videoPreview.active {
    display: block;
}

.camera-overlay {
    position: absolute;
    inset: 0;
    display: none;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.camera-overlay.active {
    display: flex;
}

.camera-frame {
    width: 85%;
    height: 85%;
    border: 2px dashed rgba(255, 255, 255, 0.3);
    border-radius: var(--radius-lg);
    position: relative;
}

.camera-frame::before,
.camera-frame::after {
    content: '';
    position: absolute;
    width: 40px;
    height: 40px;
    border: 3px solid var(--accent-primary);
}

.camera-frame::before {
    top: -2px;
    left: -2px;
    border-right: none;
    border-bottom: none;
    border-top-left-radius: var(--radius-md);
}

.camera-frame::after {
    bottom: -2px;
    right: -2px;
    border-left: none;
    border-top: none;
    border-bottom-right-radius: var(--radius-md);
}

.camera-hint {
    position: absolute;
    bottom: var(--spacing-lg);
    left: 50%;
    transform: translateX(-50%);
    font-size: 14px;
    color: var(--text-secondary);
    background: rgba(0, 0, 0, 0.6);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-full);
    backdrop-filter: blur(10px);
    white-space: nowrap;
}

.camera-placeholder {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: var(--spacing-md);
    cursor: pointer;
    transition: var(--transition-normal);
}

.camera-placeholder:hover {
    background: rgba(255, 255, 255, 0.02);
}

.camera-placeholder.hidden {
    display: none;
}

.placeholder-icon {
    font-size: 64px;
    opacity: 0.5;
    animation: pulse 2s ease-in-out infinite;
}

.camera-placeholder p {
    color: var(--text-muted);
    font-size: 14px;
}

@keyframes pulse {

    0%,
    100% {
        transform: scale(1);
        opacity: 0.5;
    }

    50% {
        transform: scale(1.05);
        opacity: 0.7;
    }
}

/* ===== Capture Controls ===== */
.capture-controls {
    display: flex;
    justify-content: center;
    padding: var(--spacing-md) 0;
}

.capture-btn {
    position: relative;
    width: 72px;
    height: 72px;
    border: none;
    background: transparent;
    cursor: pointer;
    transition: var(--transition-normal);
}

.capture-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.capture-ring {
    position: absolute;
    inset: 0;
    border: 4px solid var(--text-primary);
    border-radius: 50%;
    transition: var(--transition-normal);
}

.capture-btn:not(:disabled):hover .capture-ring {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
}

.capture-inner {
    position: absolute;
    inset: 8px;
    background: var(--text-primary);
    border-radius: 50%;
    transition: var(--transition-normal);
}

.capture-btn:not(:disabled):hover .capture-inner {
    background: var(--accent-primary);
    transform: scale(0.9);
}

.capture-btn:not(:disabled):active .capture-inner {
    transform: scale(0.8);
}

/* ===== Results Section ===== */
.results-section {
    display: none;
    flex-direction: column;
    gap: var(--spacing-lg);
    animation: slideUp 0.4s ease;
}

.results-section.active {
    display: flex;
}

@keyframes slideUp {
    from {
        opacity: 0;
        transform: translateY(30px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.results-header h2 {
    font-size: 20px;
    font-weight: 600;
}

.new-scan-btn {
    padding: var(--spacing-sm) var(--spacing-md);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-full);
    color: var(--text-secondary);
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition-normal);
}

.new-scan-btn:hover {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
    color: white;
}

.captured-image-container {
    width: 100%;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-md);
}

.captured-image-container img {
    width: 100%;
    display: block;
}

.suggestions-container {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-lg);
    padding: var(--spacing-lg);
    backdrop-filter: blur(var(--glass-blur));
}

/* ===== Loading State ===== */
.loading-state {
    display: none;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-md);
    padding: var(--spacing-xl);
}

.loading-state.active {
    display: flex;
}

.loading-spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--glass-border);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

.loading-state p {
    color: var(--text-secondary);
    font-size: 14px;
}

/* ===== Suggestions Content ===== */
.suggestions-content {
    display: none;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.suggestions-content.active {
    display: flex;
}

.suggestions-content h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--accent-primary);
    margin-bottom: var(--spacing-sm);
    display: flex;
    align-items: center;
    gap: var(--spacing-sm);
}

.suggestions-content p,
.suggestions-content li {
    font-size: 15px;
    line-height: 1.6;
    color: var(--text-secondary);
}

.suggestions-content ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.suggestions-content li {
    padding-left: var(--spacing-lg);
    position: relative;
}

.suggestions-content li::before {
    content: '✦';
    position: absolute;
    left: 0;
    color: var(--accent-secondary);
}

.suggestion-section {
    padding-bottom: var(--spacing-lg);
    border-bottom: 1px solid var(--glass-border);
}

.suggestion-section:last-child {
    padding-bottom: 0;
    border-bottom: none;
}

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.8);
    backdrop-filter: blur(8px);
    display: none;
    align-items: center;
    justify-content: center;
    padding: var(--spacing-md);
    z-index: 1000;
    opacity: 0;
    transition: opacity var(--transition-normal);
}

.modal-overlay.active {
    display: flex;
    opacity: 1;
}

.modal-content {
    width: 100%;
    max-width: 400px;
    background: var(--bg-secondary);
    border-radius: var(--radius-lg);
    border: 1px solid var(--glass-border);
    overflow: hidden;
    transform: scale(0.95);
    transition: transform var(--transition-normal);
}

.modal-overlay.active .modal-content {
    transform: scale(1);
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: var(--spacing-lg);
    border-bottom: 1px solid var(--glass-border);
}

.modal-header h2 {
    font-size: 18px;
    font-weight: 600;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--glass-bg);
    border-radius: var(--radius-sm);
    color: var(--text-secondary);
    font-size: 24px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition-fast);
}

.modal-close:hover {
    background: var(--error);
    color: white;
}

.modal-body {
    padding: var(--spacing-lg);
    display: flex;
    flex-direction: column;
    gap: var(--spacing-lg);
}

.setting-group {
    display: flex;
    flex-direction: column;
    gap: var(--spacing-sm);
}

.setting-group label {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
}

.setting-group input {
    width: 100%;
    padding: var(--spacing-md);
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-md);
    color: var(--text-primary);
    font-size: 15px;
    transition: var(--transition-fast);
}

.setting-group input:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.setting-group input::placeholder {
    color: var(--text-muted);
}

.setting-hint {
    font-size: 12px;
    color: var(--text-muted);
}

.setting-hint a {
    color: var(--accent-primary);
    text-decoration: none;
}

.setting-hint a:hover {
    text-decoration: underline;
}

.save-settings-btn {
    width: 100%;
    padding: var(--spacing-md);
    background: var(--accent-gradient);
    border: none;
    border-radius: var(--radius-md);
    color: white;
    font-size: 15px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition-normal);
}

.save-settings-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-glow);
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: calc(var(--spacing-xl) + env(safe-area-inset-bottom));
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--bg-secondary);
    border: 1px solid var(--glass-border);
    border-radius: var(--radius-full);
    padding: var(--spacing-md) var(--spacing-lg);
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 500;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all var(--transition-slow);
    z-index: 1001;
    max-width: calc(100% - var(--spacing-xl));
    text-align: center;
}

.toast.active {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.success {
    border-color: var(--success);
    background: rgba(16, 185, 129, 0.1);
}

.toast.error {
    border-color: var(--error);
    background: rgba(239, 68, 68, 0.1);
}

/* ===== Responsive ===== */
@media (min-width: 768px) {
    .app-container {
        max-width: 600px;
        margin: 0 auto;
        padding: var(--spacing-xl);
    }

    .camera-container {
        aspect-ratio: 16/10;
    }
}

/* ===== Scrollbar ===== */
::-webkit-scrollbar {
    width: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: var(--glass-border);
    border-radius: var(--radius-full);
}

::-webkit-scrollbar-thumb:hover {
    background: var(--text-muted);
}

/* ===== Recording Indicator ===== */
.recording-indicator {
    position: absolute;
    top: var(--spacing-md);
    left: var(--spacing-md);
    display: none;
    align-items: center;
    gap: var(--spacing-sm);
    background: rgba(0, 0, 0, 0.7);
    padding: var(--spacing-sm) var(--spacing-md);
    border-radius: var(--radius-full);
    backdrop-filter: blur(10px);
    z-index: 10;
}

.recording-indicator.active {
    display: flex;
}

.rec-dot {
    width: 10px;
    height: 10px;
    background: var(--error);
    border-radius: 50%;
    animation: recPulse 1s ease-in-out infinite;
}

@keyframes recPulse {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.5;
        transform: scale(0.9);
    }
}

.rec-text {
    color: var(--error);
    font-size: 12px;
    font-weight: 700;
    letter-spacing: 1px;
}

.rec-timer {
    color: var(--text-primary);
    font-size: 14px;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

/* ===== Capture Button Recording State ===== */
.capture-btn.recording .capture-ring {
    border-color: var(--error);
    animation: ringPulse 1.5s ease-in-out infinite;
}

.capture-btn.recording .capture-inner {
    background: var(--error);
    border-radius: var(--radius-sm);
    transform: scale(0.5);
}

@keyframes ringPulse {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.4);
    }

    50% {
        box-shadow: 0 0 0 15px rgba(239, 68, 68, 0);
    }
}

/* ===== Capture Controls Enhancement ===== */
.capture-controls {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--spacing-sm);
    padding: var(--spacing-md) 0;
}

.capture-hint {
    font-size: 12px;
    color: var(--text-muted);
}

/* ===== Placeholder Subtitle ===== */
.placeholder-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    text-align: center;
    max-width: 200px;
}

/* ===== Captured Media Container ===== */
.captured-media-container {
    width: 100%;
    border-radius: var(--radius-lg);
    overflow: hidden;
    border: 1px solid var(--glass-border);
    box-shadow: var(--shadow-md);
    background: var(--bg-secondary);
}

.captured-media-container img,
.captured-media-container video {
    width: 100%;
    display: block;
}

.captured-media-container video {
    max-height: 300px;
    object-fit: contain;
    background: #000;
}

/* ===== Loading State Enhancement ===== */
.loading-hint {
    font-size: 11px;
    color: var(--text-muted);
    margin-top: var(--spacing-xs);
}