:root {
    --primary: #8b5a2b;
    --primary-hover: #6d4620;
    --bg: #f5f0e6;
    --card: #fffbf5;
    --text: #3d3229;
    --text-muted: #8b7355;
    --border: #e8e0d0;
    --success: #6b8e4e;
    --warning: #c9a227;
    --error: #b85450;
    --shadow: 0 1px 3px rgba(61,50,41,0.1);
    --input-bg: #fffbf5;
    --table-header-bg: #fffbf5;
    --drop-zone-hover: #eff6ff;
    --modal-overlay: rgba(0,0,0,0.5);
}

/* Dark Mode */
body.dark-mode {
    --primary: #c9a86c;
    --primary-hover: #d4b87d;
    --bg: #1a1814;
    --card: #2d2924;
    --text: #e8e0d0;
    --text-muted: #a09075;
    --border: #3d3829;
    --success: #7fb069;
    --warning: #e0c060;
    --error: #d6736f;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --input-bg: #3d3829;
    --table-header-bg: #2d2924;
    --drop-zone-hover: #3d3829;
    --modal-overlay: rgba(0,0,0,0.7);
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
    margin: 0;
    padding: 0;
}

html, body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    touch-action: manipulation;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
}

body {
    padding: 10px;
    padding-bottom: 100px;
}

/* Header & Tabs */
.app-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.app-header h1 {
    font-size: 1.75rem;
    margin-bottom: 1rem;
}

.view-tabs {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    max-width: 400px;
    margin: 0 auto;
}

.tab-btn {
    flex: 1;
    padding: 12px 20px;
    font-size: 16px;
    background: var(--card);
    color: var(--text-muted);
    border: 2px solid var(--border);
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
    transition: all 0.2s;
}

.tab-btn.active {
    background: var(--primary);
    color: white;
    border-color: var(--primary);
}

.tab-count {
    display: inline-block;
    background: rgba(255,255,255,0.2);
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    margin-left: 4px;
}

/* Theme Toggle */
.theme-toggle {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 44px;
    height: 44px;
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 100;
}

.theme-toggle:hover {
    background: var(--border);
    transform: scale(1.05);
}

body.dark-mode .theme-toggle {
    background: var(--card);
}

/* Responsive for theme toggle */
@media (max-width: 768px) {
    .theme-toggle {
        top: 5px;
        right: 5px;
        width: 36px;
        height: 36px;
        font-size: 16px;
    }
}

/* Views */
.view {
    display: none;
    max-width: 1200px;
    margin: 0 auto;
}

.view.active {
    display: block;
}

/* Scan View Styles */
#camera-container {
    width: 100%;
    max-width: 500px;
    margin: 0 auto 15px;
}

#reader {
    width: 100%;
    height: 300px;
    background: #222;
    border-radius: 12px;
    overflow: hidden;
    display: none;
    position: relative;
}

#reader video {
    width: 100% !important;
    height: 100% !important;
    object-fit: cover;
}

/* Scanner UI overrides */
#reader__dashboard_section_csr span {
    display: none !important;
}

.camera-wrapper {
    position: relative;
    width: 100%;
    max-width: 500px;
    margin: 0 auto;
}

/* Tap-to-focus overlay */
.focus-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 50;
    cursor: pointer;
}

.focus-indicator {
    position: absolute;
    width: 60px;
    height: 60px;
    border: 2px solid #4CAF50;
    border-radius: 50%;
    pointer-events: none;
    transform: translate(-50%, -50%) scale(0);
    transition: transform 0.2s ease-out;
    z-index: 60;
}

.focus-indicator.active {
    transform: translate(-50%, -50%) scale(1);
}

.focus-indicator::before {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    width: 4px;
    height: 4px;
    background: #4CAF50;
    border-radius: 50%;
    transform: translate(-50%, -50%);
}

/* Barcode guide overlay */
.barcode-guide {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 300px;
    height: 150px;
    border: 3px dashed #4CAF50;
    border-radius: 8px;
    pointer-events: none;
    z-index: 100;
    display: none;
}

.barcode-guide.active { display: block !important; }
.barcode-guide::before {
    content: "ALIGN BARCODE HERE";
    position: absolute;
    top: -25px;
    left: 50%;
    transform: translateX(-50%);
    color: #4CAF50;
    font-size: 12px;
    font-weight: bold;
    background: rgba(0,0,0,0.7);
    padding: 4px 8px;
    border-radius: 4px;
}

/* Camera button */
.camera-btn {
    width: 100%;
    padding: 20px;
    font-size: 18px;
    background: #2196F3;
    color: white;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: 600;
}

.camera-btn:active { background: #1976D2; }
.camera-btn.stop { background: #f44336; }
.camera-btn.stop:active { background: #d32f2f; }

.scan-debug {
    text-align: center;
    font-size: 12px;
    color: var(--text-muted);
    margin-top: 5px;
    min-height: 18px;
}

.scan-hint {
    text-align: center;
    font-size: 13px;
    color: #888;
    margin-top: 5px;
}

/* Photo scan button */
.photo-scan {
    margin-top: 10px;
    text-align: center;
}

.photo-btn {
    display: inline-block;
    padding: 10px 20px;
    font-size: 14px;
    background: #9C27B0;
    color: white;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 500;
}

.photo-btn:active { background: #7B1FA2; }

#photoInput { display: none; }

/* Manual entry */
.manual-entry { 
    display: flex; 
    gap: 8px; 
    margin-bottom: 15px;
    max-width: 500px;
    margin-left: auto;
    margin-right: auto;
}

.manual-entry input { 
    flex: 1; 
    padding: 15px; 
    font-size: 18px;
    border: 2px solid var(--border);
    border-radius: 10px;
    -webkit-appearance: none;
    background: var(--input-bg);
    color: var(--text);
}

.manual-entry input:focus {
    outline: none;
    border-color: var(--primary);
}

.manual-entry button { 
    padding: 15px 25px;
    font-size: 18px;
    background: var(--success);
    color: white;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
}

.manual-entry button:active { background: #5a7a40; }

/* Scan actions */
.scan-actions {
    display: flex;
    gap: 10px;
    max-width: 500px;
    margin: 0 auto 15px;
}

.scan-actions button {
    flex: 1;
    padding: 15px;
    font-size: 16px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    font-weight: 600;
}

.btn-export {
    background: #FF9800;
    color: white;
}

.btn-export:active { background: #F57C00; }

.btn-danger-outline {
    background: transparent;
    color: var(--error);
    border: 2px solid var(--error) !important;
}

.btn-danger-outline:active { background: #ffebee; }

.stats { 
    text-align: center;
    font-size: 14px; 
    color: var(--text-muted);
    margin-bottom: 20px;
}

.stats span { font-weight: bold; color: var(--text); }

/* Recent scans */
.recent-scans {
    max-width: 500px;
    margin: 0 auto;
}

.recent-scans h3 {
    font-size: 16px;
    color: var(--text-muted);
    margin-bottom: 10px;
    padding-left: 5px;
}

.book-list {
    background: var(--card);
    border-radius: 12px;
    overflow: hidden;
}

.book { 
    padding: 15px; 
    border-bottom: 1px solid var(--border); 
    font-size: 16px;
}

.book:last-child { border-bottom: none; }

.book.new { 
    background: #f0e6d6;
    border-left: 4px solid var(--primary);
}

.book-title { font-weight: 600; margin-bottom: 4px; }
.book-author { color: var(--text-muted); font-size: 14px; }
.book-isbn { color: var(--text-muted); font-size: 12px; font-family: monospace; }

.book-actions { 
    margin-top: 10px; 
    display: flex; 
    gap: 8px; 
}

.book-actions button {
    padding: 6px 12px;
    font-size: 13px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 500;
}

.btn-edit {
    background: var(--bg);
    color: var(--primary);
}

.btn-edit:active { background: var(--border); }

.btn-delete {
    background: #ffebee;
    color: var(--error);
}

.btn-delete:active { background: #ffcdd2; }

/* Empty state */
.empty-state {
    max-width: 600px;
    margin: 0 auto;
}

.empty {
    text-align: center;
    color: var(--text-muted);
    padding: 40px;
    font-size: 16px;
}

/* Scan feedback */
.scan-flash {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(76, 175, 80, 0.3);
    pointer-events: none;
    opacity: 0;
    transition: opacity 0.2s;
    z-index: 1000;
}

.scan-flash.active { opacity: 1; }

/* Library View Styles */
.file-drop-zone {
    border: 3px dashed var(--border);
    border-radius: 12px;
    padding: 3rem 2rem;
    text-align: center;
    transition: all 0.2s;
    cursor: pointer;
    background: var(--card);
}

.file-drop-zone:hover, .file-drop-zone.drag-over {
    border-color: var(--primary);
    background: var(--drop-zone-hover);
}

.drop-content .icon {
    font-size: 3rem;
    display: block;
    margin-bottom: 1rem;
}

.drop-content p {
    color: var(--text-muted);
    margin-bottom: 0.5rem;
}

.hint {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 1rem;
}

/* Buttons */
button {
    padding: 0.625rem 1.25rem;
    border: none;
    border-radius: 8px;
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
}

.btn-primary {
    background: var(--primary);
    color: white;
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    background: var(--bg);
    color: var(--text);
    border: 1px solid var(--border);
}

.btn-secondary:hover {
    background: var(--border);
}

.btn-danger {
    background: var(--error);
    color: white;
}

.btn-danger:hover {
    background: #a04542;
}

/* Toolbar */
.toolbar {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
    margin-bottom: 1rem;
    align-items: center;
    background: var(--card);
    padding: 1rem;
    border-radius: 12px;
}

.search-box {
    flex: 1;
    min-width: 250px;
    position: relative;
}

.search-box input {
    width: 100%;
    padding: 0.625rem 2.5rem 0.625rem 1rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 0.875rem;
    background: var(--input-bg);
    color: var(--text);
}

.search-box input:focus {
    outline: none;
    border-color: var(--primary);
}

#clearSearch {
    position: absolute;
    right: 0.5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.25rem 0.5rem;
    display: none;
}

.filters {
    display: flex;
    gap: 0.5rem;
}

.filters select {
    padding: 0.625rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    background: var(--input-bg);
    color: var(--text);
    font-size: 0.875rem;
    min-width: 150px;
}

/* Stats Bar */
.stats-bar {
    padding: 0.75rem 0;
    color: var(--text-muted);
    font-size: 0.875rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 1rem;
}

.divider {
    margin: 0 0.5rem;
}

/* Table */
.table-container {
    overflow-x: auto;
    margin-bottom: 1rem;
    background: var(--card);
    border-radius: 12px;
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.875rem;
}

th {
    text-align: left;
    padding: 0.75rem;
    border-bottom: 2px solid var(--border);
    font-weight: 600;
    cursor: pointer;
    user-select: none;
    white-space: nowrap;
    background: var(--table-header-bg);
}

th:hover {
    background: var(--bg);
}

.sort-icon {
    color: var(--text-muted);
    margin-left: 0.25rem;
}

th.asc .sort-icon::after { content: "↑"; }
th.desc .sort-icon::after { content: "↓"; }

td {
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
}

tr:hover {
    background: var(--bg);
}

td:last-child {
    white-space: nowrap;
}

/* Action Buttons */
.action-btn {
    padding: 0.25rem 0.5rem;
    margin-right: 0.25rem;
    font-size: 0.75rem;
    background: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    cursor: pointer;
}

.action-btn:hover {
    background: var(--bg);
}

.action-btn.edit { color: var(--primary); }
.action-btn.delete { color: var(--error); }

/* Read Toggle Button */
.read-toggle {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: white;
    cursor: pointer;
    font-size: 1rem;
    line-height: 1;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    color: var(--text-muted);
}

.read-toggle:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.read-toggle.read {
    background: var(--success);
    border-color: var(--success);
    color: white;
}

.read-toggle.read:hover {
    background: var(--error);
    border-color: var(--error);
}

/* Read book row styling */
tr.book-read {
    opacity: 0.6;
}

tr.book-read .book-title {
    text-decoration: line-through;
    color: var(--text-muted);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 1rem;
    padding: 1rem 0;
    border-top: 1px solid var(--border);
}

#pageInfo {
    color: var(--text-muted);
    font-size: 0.875rem;
}

#perPage {
    margin-left: auto;
    padding: 0.375rem;
    border: 1px solid var(--border);
    border-radius: 4px;
    background: var(--input-bg);
    color: var(--text);
}

/* Export Bar */
.export-bar {
    display: flex;
    gap: 0.5rem;
    justify-content: center;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

/* Data Management Bar */
.data-bar {
    display: flex;
    justify-content: center;
    padding-top: 1rem;
    margin-top: 1rem;
}

/* Import Stats */
.import-stats {
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.5rem 1rem;
    margin-bottom: 1rem;
    font-size: 0.875rem;
    text-align: center;
}

.stat-added {
    color: var(--success);
    font-weight: 600;
    margin-right: 1rem;
}

.stat-dup {
    color: var(--text-muted);
}

/* Backup Reminder */
.backup-reminder {
    background: #fff3cd;
    border: 1px solid #ffc107;
    border-radius: 8px;
    padding: 0.75rem 1rem;
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    font-size: 0.875rem;
    animation: slideDown 0.3s ease;
}

@keyframes slideDown {
    from {
        opacity: 0;
        transform: translateY(-10px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.reminder-icon {
    font-size: 1.25rem;
}

.reminder-text {
    flex: 1;
    color: #856404;
}

.reminder-close {
    background: none;
    border: none;
    color: #856404;
    cursor: pointer;
    padding: 0.25rem;
    font-size: 1rem;
    line-height: 1;
}

.reminder-close:hover {
    color: #5a3d03;
}

/* Modal (shared) */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: var(--modal-overlay);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
}

.modal-content {
    background: var(--card);
    padding: 2rem;
    border-radius: 12px;
    width: 90%;
    max-width: 400px;
    box-shadow: 0 20px 25px -5px rgba(0,0,0,0.1);
}

.modal-content h3 {
    margin-bottom: 1rem;
}

.modal-content label {
    display: block;
    margin: 1rem 0 0.25rem;
    font-size: 0.875rem;
    font-weight: 500;
}

.modal-content input {
    width: 100%;
    padding: 0.75rem;
    border: 1px solid var(--border);
    border-radius: 8px;
    font-size: 1rem;
    background: var(--input-bg);
    color: var(--text);
}

.modal-content input:focus {
    outline: none;
    border-color: var(--primary);
}

.manual-isbn-display {
    background: var(--bg);
    padding: 10px 15px;
    border-radius: 8px;
    margin-bottom: 12px;
    font-size: 14px;
    color: var(--text-muted);
    font-family: monospace;
}

.manual-isbn-display span {
    color: var(--text);
    font-weight: 600;
}

.modal-actions {
    display: flex;
    gap: 0.5rem;
    justify-content: flex-end;
    margin-top: 1.5rem;
}

/* Footer */
footer {
    text-align: center;
    color: var(--text-muted);
    font-size: 0.875rem;
    margin-top: 2rem;
    padding: 1rem;
}

/* Responsive */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    
    .view-tabs {
        padding: 0 10px;
    }
    
    .tab-btn {
        padding: 10px 15px;
        font-size: 14px;
    }
    
    .toolbar {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filters {
        flex-direction: column;
    }
    
    .filters select {
        width: 100%;
    }
    
    th, td {
        padding: 0.5rem;
    }
    
    .book-isbn {
        display: none;
    }
    
    .scan-actions {
        flex-direction: column;
    }
}
