/* CSS Variables for theming */
:root {
    --primary-color: #6366f1;
    --primary-hover: #4f46e5;
    --primary-light: #e0e7ff;
    --secondary-color: #64748b;
    --secondary-hover: #475569;
    --success-color: #10b981;
    --error-color: #ef4444;
    --warning-color: #f59e0b;
    --background: #f8fafc;
    --surface: #ffffff;
    --surface-hover: #f1f5f9;
    --text-primary: #1e293b;
    --text-secondary: #64748b;
    --text-muted: #94a3b8;
    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --transition: all 0.2s ease;
}

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

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: var(--background);
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
}

/* App Container */
.app-container {
    max-width: 600px;
    margin: 0 auto;
    padding: 20px;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
header {
    text-align: center;
    padding: 20px 0 30px;
}

.logo-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 8px;
}

.logo {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

h1 {
    font-size: 2rem;
    font-weight: 700;
    color: var(--text-primary);
    letter-spacing: -0.02em;
}

.tagline {
    color: var(--text-secondary);
    font-size: 1rem;
}

/* Main Content */
main {
    flex: 1;
}

/* Mode Tabs */
.mode-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 24px;
    background: var(--surface);
    padding: 6px;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

.tab-btn {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 16px;
    border: none;
    background: transparent;
    color: var(--text-secondary);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    border-radius: var(--radius-md);
    transition: var(--transition);
}

.tab-btn:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

.tab-btn.active {
    background: var(--primary-color);
    color: white;
}

.tab-btn svg {
    flex-shrink: 0;
}

/* Scanner Sections */
.scanner-section {
    display: none;
}

.scanner-section.active {
    display: block;
}

/* Camera Section */
.camera-container {
    position: relative;
    background: #000;
    border-radius: var(--radius-lg);
    overflow: hidden;
    aspect-ratio: 4/3;
    margin-bottom: 16px;
}

#camera-preview {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
}

.scan-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.scan-frame {
    width: 65%;
    max-width: 250px;
    aspect-ratio: 1;
    border: 3px solid rgba(255, 255, 255, 0.8);
    border-radius: var(--radius-md);
    box-shadow: 0 0 0 9999px rgba(0, 0, 0, 0.4);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {
    0%, 100% { border-color: rgba(255, 255, 255, 0.8); }
    50% { border-color: var(--primary-color); }
}

.camera-controls {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.camera-select {
    padding: 12px 16px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-md);
    background: var(--surface);
    color: var(--text-primary);
    font-size: 0.95rem;
    cursor: pointer;
    min-width: 150px;
}

.status-message {
    text-align: center;
    margin-top: 12px;
    font-size: 0.9rem;
    color: var(--text-secondary);
}

.status-message.error {
    color: var(--error-color);
}

.status-message.success {
    color: var(--success-color);
}

/* Upload Section */
.upload-container {
    margin-bottom: 16px;
}

.upload-area {
    border: 2px dashed var(--border-color);
    border-radius: var(--radius-lg);
    padding: 48px 24px;
    text-align: center;
    cursor: pointer;
    transition: var(--transition);
    background: var(--surface);
}

.upload-area:hover,
.upload-area.dragover {
    border-color: var(--primary-color);
    background: var(--primary-light);
}

.upload-area svg {
    color: var(--text-muted);
    margin-bottom: 16px;
}

.upload-area p {
    color: var(--text-secondary);
    margin-bottom: 4px;
}

.upload-hint {
    font-size: 0.85rem;
    color: var(--text-muted) !important;
}

.image-preview-container {
    position: relative;
    background: var(--surface);
    border-radius: var(--radius-lg);
    overflow: hidden;
    box-shadow: var(--shadow-md);
}

#uploaded-image {
    width: 100%;
    max-height: 400px;
    object-fit: contain;
    display: block;
}

#clear-image {
    position: absolute;
    top: 12px;
    right: 12px;
    background: rgba(0, 0, 0, 0.6);
    color: white;
    border: none;
    width: 36px;
    height: 36px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
}

#clear-image:hover {
    background: rgba(0, 0, 0, 0.8);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 12px 24px;
    border: none;
    border-radius: var(--radius-md);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
}

.btn-primary {
    background: var(--primary-color);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

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

.btn-secondary:hover {
    background: var(--surface-hover);
}

.btn-outline {
    background: transparent;
    color: var(--primary-color);
    border: 1px solid var(--primary-color);
}

.btn-outline:hover {
    background: var(--primary-light);
}

.btn-text {
    background: transparent;
    color: var(--text-secondary);
    padding: 8px 12px;
}

.btn-text:hover {
    color: var(--text-primary);
}

.btn-icon {
    padding: 8px;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* Result Section */
.result-section {
    background: var(--surface);
    border-radius: var(--radius-lg);
    padding: 24px;
    margin-top: 24px;
    box-shadow: var(--shadow-md);
}

.result-section h2 {
    font-size: 1.1rem;
    color: var(--text-secondary);
    margin-bottom: 16px;
    font-weight: 500;
}

.result-container {
    background: var(--background);
    border-radius: var(--radius-md);
    padding: 16px;
    margin-bottom: 16px;
}

.result-content {
    word-break: break-all;
    font-family: 'SF Mono', Monaco, 'Cascadia Code', monospace;
    font-size: 0.95rem;
    line-height: 1.6;
    color: var(--text-primary);
    margin-bottom: 16px;
    max-height: 200px;
    overflow-y: auto;
}

.result-actions {
    display: flex;
    gap: 12px;
    flex-wrap: wrap;
}

#scan-again {
    width: 100%;
}

/* History Section */
.history-section {
    margin-top: 32px;
    padding-top: 24px;
    border-top: 1px solid var(--border-color);
}

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

.history-header h2 {
    font-size: 1.1rem;
    color: var(--text-secondary);
    font-weight: 500;
}

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

.no-history {
    text-align: center;
    color: var(--text-muted);
    padding: 24px;
    font-size: 0.9rem;
}

.history-item {
    background: var(--surface);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    display: flex;
    align-items: center;
    gap: 12px;
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: var(--transition);
}

.history-item:hover {
    box-shadow: var(--shadow-md);
}

.history-icon {
    width: 36px;
    height: 36px;
    border-radius: var(--radius-sm);
    background: var(--primary-light);
    color: var(--primary-color);
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
}

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

.history-text {
    font-size: 0.9rem;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-time {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.history-actions {
    display: flex;
    gap: 4px;
}

.history-actions button {
    background: transparent;
    border: none;
    color: var(--text-muted);
    padding: 6px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    transition: var(--transition);
}

.history-actions button:hover {
    color: var(--text-primary);
    background: var(--surface-hover);
}

/* Footer */
footer {
    text-align: center;
    padding: 24px 0;
    margin-top: auto;
    border-top: 1px solid var(--border-color);
}

footer p {
    color: var(--text-muted);
    font-size: 0.85rem;
}

footer a {
    color: var(--primary-color);
    text-decoration: none;
    font-weight: 500;
    transition: var(--transition);
}

footer a:hover {
    color: var(--primary-hover);
    text-decoration: underline;
}

/* Toast Notification */
.toast {
    position: fixed;
    bottom: 24px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--text-primary);
    color: white;
    padding: 12px 24px;
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-lg);
    z-index: 1000;
    opacity: 0;
    transition: all 0.3s ease;
}

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

.toast.success {
    background: var(--success-color);
}

.toast.error {
    background: var(--error-color);
}

/* Responsive Design */
@media (max-width: 480px) {
    .app-container {
        padding: 16px;
    }

    h1 {
        font-size: 1.5rem;
    }

    .logo {
        width: 40px;
        height: 40px;
    }

    .tab-btn {
        padding: 10px 12px;
        font-size: 0.9rem;
    }

    .tab-btn span {
        display: none;
    }

    .upload-area {
        padding: 32px 16px;
    }

    .result-section {
        padding: 16px;
    }

    .btn {
        padding: 10px 16px;
        font-size: 0.9rem;
    }

    .camera-controls {
        flex-direction: column;
    }

    .camera-select {
        width: 100%;
    }
}

/* Dark mode support */
@media (prefers-color-scheme: dark) {
    :root {
        --background: #0f172a;
        --surface: #1e293b;
        --surface-hover: #334155;
        --text-primary: #f1f5f9;
        --text-secondary: #94a3b8;
        --text-muted: #64748b;
        --border-color: #334155;
        --primary-light: #312e81;
    }

    .upload-area:hover,
    .upload-area.dragover {
        background: var(--primary-light);
    }

    .camera-select {
        color-scheme: dark;
    }
}

/* Accessibility */
@media (prefers-reduced-motion: reduce) {
    * {
        animation: none !important;
        transition: none !important;
    }
}

/* Focus styles */
button:focus-visible,
input:focus-visible,
select:focus-visible {
    outline: 2px solid var(--primary-color);
    outline-offset: 2px;
}

/* Print styles */
@media print {
    .camera-container,
    .upload-container,
    .mode-tabs,
    footer,
    .history-section,
    .result-actions,
    #scan-again {
        display: none !important;
    }

    .result-section {
        box-shadow: none;
        border: 1px solid #000;
    }
}
