/* ============================================
   Snapi - App Styles
   Mobile-first SPA layout
   ============================================ */

/* App Shell */
.app-shell {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    max-width: 480px;
    margin: 0 auto;
    position: relative;
    background: var(--bg);
}

/* Header */
.app-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 0 16px;
    height: var(--header-height);
    background: var(--bg-card);
    border-bottom: 1px solid var(--border);
    position: sticky;
    top: 0;
    z-index: 50;
}
.app-header-title {
    font-size: 18px;
    font-weight: 700;
    flex: 1;
}
.app-header-back {
    background: none;
    border: none;
    color: var(--text);
    font-size: 20px;
    cursor: pointer;
    padding: 4px;
    display: none;
}
.app-header-actions {
    display: flex;
    align-items: center;
    gap: 8px;
}
.header-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 2px solid var(--border);
    cursor: pointer;
    object-fit: cover;
}

/* Profile selector in header */
.profile-selector {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 4px 12px;
    background: var(--bg-input);
    border-radius: 20px;
    border: 1px solid var(--border);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-secondary);
}
.profile-selector:hover { border-color: var(--accent); }
.profile-selector-icon { font-size: 16px; }

/* Content area */
.app-content {
    flex: 1;
    padding: 16px;
    padding-bottom: calc(var(--tab-bar-height) + 24px); /* space for tab bar + Pix-style FAB */
    overflow-y: auto;
}

/* Tab Bar */
.tab-bar {
    position: fixed;
    bottom: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 100%;
    max-width: 480px;
    height: var(--tab-bar-height);
    background: var(--bg-card);
    border-top: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-around;
    z-index: 50;
    padding: 0 8px;
}
.tab-bar-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 6px 12px;
    border: none;
    background: none;
    color: var(--text-muted);
    font-family: inherit;
    font-size: 10px;
    font-weight: 500;
    cursor: pointer;
    transition: color 0.15s;
    min-width: 56px;
}
.tab-bar-item.active { color: var(--accent); }
.tab-bar-item:hover { color: var(--text); }
.tab-bar-icon { font-size: 22px; line-height: 1; }

/* Camera FAB — Pix style (integrated in tab bar, elevated) */
.tab-bar-fab-wrapper {
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    width: 60px;
    align-self: flex-end;
    margin-bottom: 4px;
}
.camera-fab {
    width: 54px;
    height: 54px;
    border-radius: 50%;
    background: linear-gradient(135deg, #1D2B4E, #0F4C5C);
    color: #fff;
    border: 4px solid var(--bg-card);
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 16px rgba(15,76,92,0.4);
    transition: transform 0.15s, box-shadow 0.15s;
    margin-top: -28px;
    z-index: 2;
}
.camera-fab:hover { transform: scale(1.05); box-shadow: 0 6px 24px rgba(15,76,92,0.5); }
.camera-fab:active { transform: scale(0.95); }

/* Pages */
.page { display: none; }
.page.active { display: block; }

/* Books Grid */
.books-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 12px;
}
.book-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 20px 16px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
}
.book-card:hover { border-color: var(--accent); box-shadow: var(--shadow-md); }
.book-icon { font-size: 32px; margin-bottom: 8px; display: block; }
.book-name { font-size: 14px; font-weight: 600; color: var(--text); margin-bottom: 4px; }
.book-count { font-size: 12px; color: var(--text-muted); }

/* Items List */
.items-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.item-card {
    display: flex;
    align-items: center;
    gap: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 12px;
    cursor: pointer;
    transition: all 0.15s;
}
.item-card:hover { border-color: var(--accent); }
.item-thumb {
    width: 48px;
    height: 48px;
    border-radius: var(--radius-sm);
    object-fit: cover;
    background: var(--bg-input);
    flex-shrink: 0;
}
.item-info { flex: 1; min-width: 0; }
.item-title {
    font-size: 14px;
    font-weight: 600;
    color: var(--text);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.item-subtitle {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.item-date { font-size: 11px; color: var(--text-muted); flex-shrink: 0; }

/* Item Detail */
.item-detail-photo {
    width: 100%;
    max-height: 300px;
    object-fit: contain;
    border-radius: var(--radius);
    background: var(--bg-input);
    margin-bottom: 16px;
}
.item-detail-fields {
    display: flex;
    flex-direction: column;
    gap: 12px;
}
.item-field {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    padding: 12px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
}
.item-field-label {
    font-size: 12px;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    font-weight: 600;
}
.item-field-value {
    font-size: 14px;
    color: var(--text);
    text-align: right;
    word-break: break-word;
    max-width: 60%;
}

/* Capture Overlay */
.capture-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 200;
    display: none;
    flex-direction: column;
}
.capture-overlay.active { display: flex; }

.capture-header {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.capture-close {
    background: none;
    border: none;
    color: var(--text);
    font-size: 24px;
    cursor: pointer;
    padding: 4px;
}
.capture-title { font-size: 16px; font-weight: 600; flex: 1; }

.capture-body {
    flex: 1;
    padding: 16px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.capture-preview {
    width: 100%;
    max-height: 250px;
    object-fit: contain;
    border-radius: var(--radius);
    background: var(--bg-input);
}

.capture-result {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
}
.capture-classification {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-bottom: 12px;
}
.capture-classification-icon { font-size: 20px; }
.capture-classification-text { font-size: 14px; font-weight: 600; }
.capture-confidence {
    font-size: 12px;
    color: var(--text-muted);
    margin-left: auto;
}

.capture-fields {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.capture-book-selector {
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.capture-book-option {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 12px;
    background: var(--bg-input);
    border: 2px solid transparent;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: border-color 0.15s;
}
.capture-book-option.selected { border-color: var(--accent); background: var(--accent-light); }
.capture-book-option:hover { border-color: var(--accent); }
.capture-book-icon { font-size: 20px; }
.capture-book-name { font-size: 14px; font-weight: 600; }

.capture-footer {
    padding: 16px;
    border-top: 1px solid var(--border);
    display: flex;
    gap: 12px;
}

/* Loading state for capture */
.capture-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 40px;
    text-align: center;
}
.capture-loading-text {
    font-size: 14px;
    color: var(--text-secondary);
}

/* Onboarding */
.onboarding-overlay {
    position: fixed;
    inset: 0;
    background: var(--bg);
    z-index: 300;
    display: none;
    flex-direction: column;
    align-items: center;
    padding: 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
.onboarding-overlay.active { display: flex; }
.onboarding-title {
    font-size: 22px;
    font-weight: 800;
    text-align: center;
    margin-bottom: 4px;
}
.onboarding-subtitle {
    font-size: 13px;
    color: var(--text-secondary);
    text-align: center;
    margin-bottom: 16px;
}
.onboarding-profiles {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    width: 100%;
    max-width: 380px;
}
.onboarding-profile {
    background: var(--bg-card);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    padding: 12px 10px;
    text-align: center;
    cursor: pointer;
    transition: all 0.15s;
}
.onboarding-profile:hover { border-color: var(--accent); }
.onboarding-profile.selected { border-color: var(--accent); background: var(--accent-light); }
.onboarding-profile-icon { font-size: 26px; margin-bottom: 4px; display: block; }
.onboarding-profile-name { font-size: 13px; font-weight: 700; margin-bottom: 2px; }
.onboarding-profile-desc { font-size: 11px; color: var(--text-muted); line-height: 1.3; }
.onboarding-actions {
    margin-top: 16px;
    text-align: center;
    width: 100%;
    max-width: 380px;
    padding-bottom: 24px;
}

/* Search */
.search-bar {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 8px 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 16px;
}
.search-bar input {
    flex: 1;
    border: none;
    background: none;
    font-family: inherit;
    font-size: 14px;
    color: var(--text);
    outline: none;
}
.search-bar input::placeholder { color: var(--text-muted); }
.search-icon { font-size: 18px; color: var(--text-muted); }

/* Settings */
.settings-section {
    margin-bottom: 24px;
}
.settings-section-title {
    font-size: 12px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    margin-bottom: 12px;
}
.settings-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    margin-bottom: 8px;
    cursor: pointer;
    transition: border-color 0.15s;
}
.settings-item:hover { border-color: var(--accent); }
.settings-item-icon { font-size: 20px; flex-shrink: 0; }
.settings-item-text { flex: 1; }
.settings-item-label { font-size: 14px; font-weight: 500; }
.settings-item-desc { font-size: 12px; color: var(--text-muted); }
.settings-item-value { font-size: 14px; color: var(--text-secondary); }

/* Usage bar */
.usage-bar {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 16px;
}
.usage-bar-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 8px;
}
.usage-bar-label { font-size: 13px; font-weight: 500; }
.usage-bar-count { font-size: 13px; color: var(--text-muted); }

/* Auth page (login in app) */
.auth-page {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 24px;
    text-align: center;
}
.auth-logo { font-size: 48px; margin-bottom: 16px; }
.auth-title { font-size: 24px; font-weight: 800; margin-bottom: 8px; }
.auth-subtitle { font-size: 14px; color: var(--text-secondary); margin-bottom: 32px; }
.auth-form {
    width: 100%;
    max-width: 340px;
}
.auth-divider {
    display: flex;
    align-items: center;
    gap: 12px;
    margin: 20px 0;
    color: var(--text-muted);
    font-size: 12px;
}
.auth-divider::before,
.auth-divider::after {
    content: '';
    flex: 1;
    height: 1px;
    background: var(--border);
}
.auth-toggle {
    font-size: 13px;
    color: var(--text-muted);
    margin-top: 16px;
}
.auth-toggle a { color: var(--accent); font-weight: 600; cursor: pointer; }

/* User dropdown in app */
.user-dropdown {
    position: absolute;
    top: calc(var(--header-height) + 4px);
    right: 16px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow-lg);
    min-width: 200px;
    z-index: 100;
    display: none;
    overflow: hidden;
}
.user-dropdown.active { display: block; }
.user-dropdown-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}
.user-dropdown-email { font-size: 12px; color: var(--text-muted); }
.user-dropdown-plan { font-size: 11px; color: var(--accent); font-weight: 600; text-transform: uppercase; margin-top: 2px; }
.user-dropdown-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 16px;
    color: var(--text-secondary);
    font-size: 14px;
    cursor: pointer;
    border: none;
    background: none;
    width: 100%;
    text-align: left;
    font-family: inherit;
    transition: background 0.15s;
}
.user-dropdown-item:hover { background: var(--bg-hover); color: var(--text); }
.user-dropdown-item.danger { color: var(--red); }
.user-dropdown-item.danger:hover { background: rgba(239, 68, 68, 0.06); }

/* Hidden file inputs */
#camera-input, #gallery-input { display: none; }

/* Chat widget — push above tab bar */
#axiom-chat-widget { bottom: calc(var(--tab-bar-height) + 12px) !important; }

/* Subcategory Chips (book detail filter) */
.subcategory-chips {
    display: flex;
    gap: 6px;
    overflow-x: auto;
    padding: 4px 0 12px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.subcategory-chips::-webkit-scrollbar { display: none; }

.subcategory-chip {
    flex-shrink: 0;
    padding: 5px 14px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    font-family: inherit;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}
.subcategory-chip:hover { border-color: var(--accent); }
.subcategory-chip.active {
    background: var(--accent);
    color: #fff;
    border-color: var(--accent);
}

/* Subcategory Badge (on items) */
.subcategory-badge {
    display: inline-flex;
    align-items: center;
    padding: 1px 8px;
    border-radius: 10px;
    background: rgba(15, 76, 92, 0.08);
    color: var(--color-accent);
    font-size: 11px;
    font-weight: 500;
    white-space: nowrap;
    vertical-align: middle;
}

/* Subcategory Autocomplete (capture overlay) */
.subcategory-autocomplete {
    position: relative;
}
.subcategory-dropdown {
    position: absolute;
    top: 100%;
    left: 0;
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-top: none;
    border-radius: 0 0 var(--radius-sm) var(--radius-sm);
    box-shadow: var(--shadow-md);
    z-index: 10;
    max-height: 160px;
    overflow-y: auto;
    display: none;
}
.subcategory-option {
    padding: 10px 14px;
    font-size: 14px;
    color: var(--text);
    cursor: pointer;
    transition: background 0.1s;
}
.subcategory-option:hover {
    background: var(--bg-hover);
}

/* Responsive: wider screens */
@media (min-width: 481px) {
    .app-shell {
        border-left: 1px solid var(--border);
        border-right: 1px solid var(--border);
    }
}
