/* ========== 基礎設定 ========== */
:root {
    --safe-area-top: env(safe-area-inset-top, 0px);
    --safe-area-bottom: env(safe-area-inset-bottom, 0px);
    --color-primary: #17a2b8;
    --color-secondary: #28a745;
    --color-danger: #dc3545;
}

* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    padding-top: var(--safe-area-top);
    padding-bottom: calc(70px + var(--safe-area-bottom));
    background: #f5f5f5;
    font-size: 16px;
}

/* ========== 載入遮罩 ========== */
.loading-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(255,255,255,0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 9999;
}

/* ========== 頂部標題列 ========== */
.app-header {
    background: linear-gradient(135deg, var(--color-primary), #138496);
    color: white;
    padding: 12px 16px;
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: 0 2px 8px rgba(0,0,0,0.15);
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.app-header .menu-btn {
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
}

.app-header .menu-btn:active {
    background: rgba(255,255,255,0.3);
}

.app-header .header-center {
    flex: 1;
    text-align: center;
}

.app-header .header-center h1 {
    font-size: 1.2rem;
    margin: 0;
    font-weight: 600;
}

.app-header .header-center .update-info {
    font-size: 0.75rem;
    opacity: 0.9;
    margin-top: 2px;
}

.app-header .header-right {
    width: 40px;
}

/* ========== 搜尋區域 ========== */
.search-section {
    background: white;
    padding: 10px 12px;
    margin: 8px 12px;
    border-radius: 10px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}

.search-input {
    border-radius: 8px;
    border: 2px solid #e0e0e0;
    transition: border-color 0.2s;
}

.search-input:focus {
    border-color: var(--color-primary);
    box-shadow: 0 0 0 2px rgba(23,162,184,0.15);
    outline: none;
}

.search-btn {
    font-weight: 600;
    border-radius: 8px;
}

/* ========== 結果統計 ========== */
.result-stats {
    padding: 12px 16px;
    margin: 0 12px 12px;
    background: #e8f4f8;
    border-radius: 8px;
    font-size: 0.9rem;
    color: #0c5460;
}

/* ========== 內容區域 ========== */
.content-area {
    padding: 0 12px 20px;
    min-height: 200px;
}

/* ========== 書籍卡片 ========== */
.book-card {
    background: white;
    border-radius: 12px;
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: 0 2px 6px rgba(0,0,0,0.06);
    border-left: 4px solid var(--color-primary);
    position: relative;
}

.book-card.library-card {
    border-left-color: var(--color-secondary);
}

.book-card .book-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: #333;
    margin-bottom: 8px;
    line-height: 1.4;
    padding-right: 30px;
}

.book-card .book-title a {
    color: var(--color-primary);
    text-decoration: none;
}

.book-card.library-card .book-title {
    color: #333;
}

.book-card .book-meta {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 8px 12px;
    font-size: 0.9rem;
    color: #666;
}

.book-card .book-meta .label {
    color: #999;
    font-size: 0.8rem;
}

.book-card .book-meta .clickable {
    color: var(--color-primary);
    cursor: pointer;
    text-decoration: underline;
    text-decoration-style: dotted;
    padding: 4px 0;
}

.book-card .book-meta .clickable:active {
    opacity: 0.7;
}

.book-card .book-level {
    display: inline-block;
    background: var(--color-primary);
    color: white;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.8rem;
    font-weight: 600;
    margin-top: 10px;
}

/* ========== 跨書單標籤 ========== */
.cross-tag {
    position: absolute;
    top: 8px;
    right: 8px;
    font-size: 0.7rem;
    padding: 3px 8px;
    border-radius: 10px;
    font-weight: 600;
}

.cross-tag.library-tag {
    background: var(--color-secondary);
    color: white;
}

.cross-tag.planet-tag {
    background: var(--color-primary);
    color: white;
}

/* ========== 愛心按鈕 ========== */
.favorite-btn {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    font-size: 1.3rem;
    color: #ddd;
    cursor: pointer;
    padding: 4px;
    line-height: 1;
    z-index: 10;
}

.favorite-btn.active {
    color: var(--color-danger);
}

.favorite-btn:active {
    transform: scale(1.2);
}

.book-card .cross-tag + .favorite-btn,
.book-card .favorite-btn.has-cross-tag {
    top: 32px;
}

/* ========== 空狀態 / 提示 ========== */
.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: #999;
}

.empty-state .icon {
    font-size: 3rem;
    margin-bottom: 16px;
}

.search-hint {
    text-align: center;
    padding: 60px 20px;
    color: #999;
}

.search-hint .icon {
    font-size: 4rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* ========== 載入更多 ========== */
.loading-more {
    text-align: center;
    padding: 20px;
    color: #666;
    font-size: 0.9rem;
}

.end-of-list {
    text-align: center;
    padding: 20px;
    color: #999;
    font-size: 0.85rem;
}

/* ========== 底部導覽列 ========== */
.bottom-nav {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    background: white;
    display: flex;
    padding-bottom: var(--safe-area-bottom);
    box-shadow: 0 -2px 10px rgba(0,0,0,0.1);
    z-index: 100;
}

.nav-tab {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 12px 8px;
    border: none;
    background: transparent;
    color: #999;
    font-size: 0.75rem;
    font-weight: 600;
    position: relative;
    transition: color 0.2s;
}

.nav-tab.active { color: var(--color-primary); }
.nav-tab.active.library { color: var(--color-secondary); }

.nav-tab .nav-icon {
    font-size: 1.5rem;
    margin-bottom: 4px;
}

.nav-tab .nav-badge {
    position: absolute;
    top: 6px;
    right: 50%;
    transform: translateX(20px);
    background: var(--color-danger);
    color: white;
    font-size: 0.65rem;
    font-weight: 700;
    padding: 2px 6px;
    border-radius: 10px;
    min-width: 18px;
    text-align: center;
}

.nav-tab .nav-badge.planet { background: var(--color-primary); }
.nav-tab .nav-badge.library { background: var(--color-secondary); }

/* ========== Tab 內容 ========== */
.tab-content { display: none; }
.tab-content.active { display: block; }

/* ========== Drawer 側邊選單 ========== */
.offcanvas { max-width: 85%; }

.drawer-menu-item {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid #eee;
    color: #333;
    text-decoration: none;
    font-size: 1rem;
    cursor: pointer;
}

.drawer-menu-item:active { background: #f5f5f5; }

.drawer-menu-item i:first-child {
    font-size: 1.3rem;
    margin-right: 12px;
    color: var(--color-primary);
    width: 24px;
    text-align: center;
}

.drawer-menu-item .badge { margin-left: 8px; }

.drawer-page {
    height: 100%;
    overflow-y: auto;
}

/* ========== 搜尋記錄 ========== */
.history-list { overflow-y: auto; }

.history-item {
    display: flex;
    align-items: center;
    padding: 14px 20px;
    border-bottom: 1px solid #f0f0f0;
}

.history-item .history-text {
    flex: 1;
    cursor: pointer;
    color: var(--color-primary);
}

.history-item .delete-btn {
    color: #999;
    padding: 4px 8px;
    cursor: pointer;
}

.history-item .delete-btn:active { color: var(--color-danger); }

/* ========== 我的最愛列表 (Drawer) ========== */
.favorites-list { overflow-y: auto; }

.favorite-item {
    padding: 12px 16px;
    border-bottom: 1px solid #f0f0f0;
}

.favorite-item .fav-title {
    font-weight: 600;
    color: #333;
    margin-bottom: 4px;
}

.favorite-item .fav-meta {
    font-size: 0.85rem;
    color: #666;
}

/* ========== 版本更新 ========== */
.version-list { padding: 16px 20px; }
.version-item { margin-bottom: 20px; }

.version-item .version-header {
    font-weight: 600;
    color: var(--color-primary);
    margin-bottom: 8px;
}

.version-item ul {
    margin: 0;
    padding-left: 20px;
    color: #666;
    font-size: 0.9rem;
}

/* ========== 關於頁面 ========== */
.about-section { margin-bottom: 20px; }

.about-section h6 {
    color: var(--color-primary);
    font-weight: 600;
    margin-bottom: 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.about-section p,
.about-section ul {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 0;
}

.about-section ul { padding-left: 20px; }

/* ========== 離線提示 ========== */
.offline-notice {
    background: #fff3cd;
    color: #856404;
    padding: 10px 16px;
    margin: 12px;
    border-radius: 8px;
    font-size: 0.9rem;
    display: none;
}
