/* Base Reset & Variables */
:root {
    --bg-color: #FFFFFF;
    --text-primary: #37352F;
    --text-secondary: #787774;
    --border-color: #E9E9E7;
    --hover-bg: #F1F1EF;
    --accent-color: #2383E2; /* Notion Blue */
    --accent-hover: #1D6CB9;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: rgba(15, 15, 15, 0.1) 0px 0px 0px 1px, rgba(15, 15, 15, 0.1) 0px 2px 4px;
    --font-sans: 'Inter', 'Noto Sans JP', -apple-system, BlinkMacSystemFont, "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    background-color: var(--bg-color);
    color: var(--text-primary);
    font-family: var(--font-sans);
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
}

/* Utilities */
.hidden {
    display: none !important;
}

/* App Container */
#app {
    max-width: 800px;
    margin: 0 auto;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* Header */
.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border-color);
    position: sticky;
    top: 0;
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(8px);
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 8px;
}

.header-icon {
    color: var(--text-primary);
    width: 24px;
    height: 24px;
}

h1 {
    font-size: 1.25rem;
    font-weight: 600;
}

.header-right {
    display: flex;
    align-items: center;
    gap: 12px;
}

.icon-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 6px;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.2s, color 0.2s;
}

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

.sync-status {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.status-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background-color: #EB5757; /* offline */
}
.status-dot.online {
    background-color: #219653;
}

/* Main Content */
.main-content {
    flex: 1;
    padding: 24px 20px;
    display: flex;
    flex-direction: column;
    gap: 24px;
}

.search-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

/* Row 1: 検索表層5内の主行 */
.search-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* Row 2: アクション行 */
.action-row {
    display: flex;
    align-items: center;
    gap: 8px;
}

/* 検索種剔セレクト */
.search-type-select {
    flex-shrink: 0;
    appearance: none;
    -webkit-appearance: none;
    background-color: var(--hover-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 8px 28px 8px 12px;
    font-family: inherit;
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-primary);
    cursor: pointer;
    outline: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%23787774' stroke-width='2.5' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.search-type-select:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(35, 131, 226, 0.15);
}

/* 検索実行ボタン */
.search-exec-btn {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    font-size: 0.88rem;
    white-space: nowrap;
}

/* スキャン行ボタン */
.scan-btn-row {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 14px;
    font-size: 0.85rem;
    white-space: nowrap;
}


/* Search Bar */
.search-bar {
    flex: 1;
    display: flex;
    align-items: center;
    background-color: var(--hover-bg);
    border-radius: 6px;
    padding: 8px 12px;
    gap: 8px;
}

.search-icon {
    color: var(--text-secondary);
    width: 18px;
    height: 18px;
}

#search-input {
    flex: 1;
    background: none;
    border: none;
    outline: none;
    font-family: inherit;
    font-size: 0.95rem;
    color: var(--text-primary);
}

#search-input::placeholder {
    color: var(--text-secondary);
}

.scan-btn {
    padding: 4px;
}

/* Library Section */
.section-header {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 16px;
}

.section-header h2 {
    font-size: 1rem;
    font-weight: 500;
}

.book-count {
    font-size: 0.85rem;
    color: var(--text-secondary);
    background-color: var(--hover-bg);
    padding: 2px 8px;
    border-radius: 12px;
}

.book-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 20px;
}

.book-card {
    display: flex;
    flex-direction: column;
    cursor: pointer;
    transition: transform 0.2s, box-shadow 0.2s;
    border-radius: 8px;
}

.book-card:hover {
    transform: translateY(-2px);
}

.book-cover {
    width: 100%;
    aspect-ratio: 2/3;
    object-fit: cover;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    box-shadow: var(--shadow-sm);
    margin-bottom: 8px;
}

.book-info {
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.book-title {
    font-size: 0.9rem;
    font-weight: 500;
    line-height: 1.3;
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.book-author {
    font-size: 0.8rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

/* Empty State */
.empty-state {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 20px;
    color: var(--text-secondary);
    text-align: center;
    gap: 12px;
}

.empty-icon {
    width: 32px;
    height: 32px;
    opacity: 0.5;
}

/* Modal */
.modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(15, 15, 15, 0.4);
    backdrop-filter: blur(2px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 100;
    opacity: 1;
    transition: opacity 0.2s;
}

.modal.hidden {
    opacity: 0;
    pointer-events: none;
}

.modal-content {
    background-color: var(--bg-color);
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-md);
    padding: 24px;
}

.scanner-content {
    max-width: 400px;
}

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

.modal-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

.close-modal {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    padding: 4px;
}

#reader {
    width: 100%;
    border-radius: 8px;
    overflow: hidden;
    margin-bottom: 16px;
}

.scanner-guide {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 10px;
    padding: 12px 0 4px;
}

.scanner-guide-icon {
    width: 28px;
    height: 28px;
    color: var(--accent-color);
    opacity: 0.7;
}

.scanner-help {
    font-size: 0.85rem;
    color: var(--text-secondary);
    text-align: center;
    line-height: 1.6;
}

.scanner-help strong {
    color: var(--text-primary);
    font-weight: 600;
}

/* スキャナーモーダル: モバイルでは全幅にする */
@media (max-width: 600px) {
    .scanner-content {
        max-width: 100%;
        width: 95%;
        margin: auto;
    }
}

/* Responsive adjustments */
@media (max-width: 600px) {
    .book-grid {
        grid-template-columns: repeat(auto-fill, minmax(100px, 1fr));
        gap: 16px;
    }
}

/* Authentication Screen */
.auth-container {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background-color: #F7F7F5; /* Notion light gray bg */
    padding: 20px;
}

.auth-card {
    background-color: var(--bg-color);
    width: 100%;
    max-width: 400px;
    padding: 40px;
    border-radius: 8px;
    box-shadow: var(--shadow-md);
    border: 1px solid var(--border-color);
}

.auth-header {
    text-align: center;
    margin-bottom: 32px;
}

.auth-icon {
    width: 32px;
    height: 32px;
    color: var(--accent-color);
    margin-bottom: 12px;
}

.auth-header h2 {
    font-size: 1.5rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.auth-header p {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.form-group {
    margin-bottom: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.form-group label {
    font-size: 0.85rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.form-group input {
    padding: 10px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.95rem;
    outline: none;
    transition: border-color 0.2s, box-shadow 0.2s;
}

.form-group input:focus {
    border-color: var(--accent-color);
    box-shadow: 0 0 0 2px rgba(35, 131, 226, 0.2);
}

.auth-actions {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin-top: 24px;
}

.primary-btn {
    background-color: var(--accent-color);
    color: white;
    border: none;
    border-radius: 6px;
    padding: 10px 16px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: background-color 0.2s;
    font-family: inherit;
}

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

.secondary-btn {
    background-color: transparent;
    color: var(--text-secondary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 10px 16px;
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    font-family: inherit;
}

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

    .auth-error {
        color: #EB5757;
        font-size: 0.85rem;
        margin-top: -8px;
        margin-bottom: 12px;
        text-align: center;
    }

    /* Search Results Modal & Candidates */
    .search-results-content {
        max-width: 600px;
        width: 100%;
        max-height: 85vh;
        display: flex;
        flex-direction: column;
    }

    .candidates-list {
        display: flex;
        flex-direction: column;
        gap: 12px;
        overflow-y: auto;
        padding-right: 4px;
        margin-top: 16px;
    }

    .candidate-card {
        display: flex;
        gap: 16px;
        padding: 12px;
        border: 1px solid var(--border-color);
        border-radius: 8px;
        background-color: var(--bg-color);
        transition: box-shadow 0.2s, border-color 0.2s;
        align-items: center;
        animation: fadeSlideIn 0.2s ease-out;
    }

    .candidate-card:hover {
        box-shadow: var(--shadow-sm);
        border-color: #d0d0d0;
    }

    .candidate-cover {
        width: 60px;
        height: 85px;
        object-fit: cover;
        border-radius: 4px;
        box-shadow: 0 1px 3px rgba(0,0,0,0.1);
        flex-shrink: 0;
    }

    .candidate-info {
        flex: 1;
        display: flex;
        flex-direction: column;
        gap: 4px;
        min-width: 0; /* for text truncation */
    }

    .candidate-title {
        font-size: 1rem;
        font-weight: 600;
        margin: 0;
        color: var(--text-primary);
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .candidate-author {
        font-size: 0.85rem;
        color: var(--text-secondary);
        margin: 0;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    .candidate-details {
        font-size: 0.75rem;
        color: #888;
        margin: 0;
    }

    .add-candidate-btn {
        flex-shrink: 0;
        white-space: nowrap;
        padding: 8px 16px;
    }

/* 検索件数ラベル */
.result-count-label {
    font-size: 0.8rem;
    color: var(--text-secondary);
    flex: 1;
    text-align: center;
}

/* 検索ローディングスピナー */
.search-loading {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 12px;
    padding: 32px 20px;
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.loading-spinner {
    width: 32px;
    height: 32px;
    border: 3px solid var(--border-color);
    border-top-color: var(--accent-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}


@keyframes fadeSlideIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* 続きを見るボタン: アイコン込み */
#load-more-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    font-size: 0.9rem;
    padding: 12px;
    border-radius: 8px;
    transition: all 0.2s;
}

#load-more-btn:hover {
    background-color: var(--hover-bg);
    color: var(--text-primary);
}

/* モバイル対応: 検索UIを縮める */
@media (max-width: 480px) {
    .search-type-select {
        font-size: 0.78rem;
        padding: 8px 22px 8px 8px;
    }
    .search-exec-btn {
        padding: 8px 10px;
        font-size: 0.8rem;
    }
    .search-exec-btn span {
        display: none;
    }
    .scan-btn-row {
        font-size: 0.8rem;
        padding: 8px 10px;
    }
}

