/* Flipbook Viewer — Modern CSS, Flipbook Express benzeri deneyim */

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

:root {
    --bg-primary: #1a1d23;
    --bg-secondary: #252a33;
    --bg-toolbar: #2d333f;
    --text-primary: #e8eaed;
    --text-secondary: #9aa0a6;
    --accent: #4f8bf9;
    --accent-hover: #6ba0ff;
    --border: #3a404d;
    --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
    --highlight: #ffc107;
}

html, body {
    height: 100%;
    overflow: hidden;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    -webkit-font-smoothing: antialiased;
}

#app {
    display: grid;
    grid-template-rows: 56px 1fr 48px;
    grid-template-columns: auto 1fr;
    grid-template-areas:
        "toolbar toolbar"
        "sidebar main"
        "status status";
    height: 100vh;
    width: 100vw;
}

/* ===== Toolbar ===== */
.toolbar {
    grid-area: toolbar;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 16px;
    background: var(--bg-toolbar);
    border-bottom: 1px solid var(--border);
    gap: 16px;
}

.toolbar-left, .toolbar-right {
    display: flex;
    align-items: center;
    gap: 8px;
}

.toolbar-logo {
    height: 32px;
    width: auto;
    display: block;
    flex-shrink: 0;
    object-fit: contain;
}

.toolbar-center {
    flex: 1;
    max-width: 500px;
}

#book-title {
    font-size: 15px;
    font-weight: 500;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 240px;
}

.toolbar button {
    background: transparent;
    border: none;
    color: var(--text-primary);
    cursor: pointer;
    padding: 8px;
    border-radius: 6px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: background 0.15s;
    font-size: 18px;
    min-width: 36px;
    height: 36px;
}

.toolbar button:hover {
    background: rgba(255, 255, 255, 0.08);
}

.toolbar button:active {
    background: rgba(255, 255, 255, 0.12);
}

#zoom-level {
    font-size: 13px;
    color: var(--text-secondary);
    min-width: 48px;
    text-align: center;
}

/* ===== Search box ===== */
.search-box {
    position: relative;
    width: 100%;
}

#search-input {
    width: 100%;
    height: 36px;
    padding: 0 36px 0 14px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 18px;
    color: var(--text-primary);
    font-size: 14px;
    outline: none;
    transition: border-color 0.15s;
}

#search-input:focus {
    border-color: var(--accent);
}

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

#btn-search-clear {
    position: absolute;
    right: 4px;
    top: 50%;
    transform: translateY(-50%);
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    border-radius: 50%;
    font-size: 18px;
}

#btn-search-clear:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

/* ===== Sidebar ===== */
.sidebar {
    grid-area: sidebar;
    width: 280px;
    background: var(--bg-secondary);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: width 0.2s;
}

.sidebar.hidden {
    width: 0;
    border-right: none;
}

.sidebar-tabs {
    display: flex;
    border-bottom: 1px solid var(--border);
}

.tab {
    flex: 1;
    padding: 12px;
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 13px;
    font-weight: 500;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
}

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

.tab.active {
    color: var(--accent);
    border-bottom-color: var(--accent);
}

.sidebar-content {
    flex: 1;
    overflow-y: auto;
    padding: 8px;
}

.panel {
    display: none;
}

.panel.active {
    display: block;
}

.toc-item {
    padding: 8px 12px;
    cursor: pointer;
    border-radius: 4px;
    font-size: 13px;
    color: var(--text-primary);
    margin-bottom: 2px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 8px;
    transition: background 0.15s;
}

.toc-item:hover {
    background: rgba(255, 255, 255, 0.06);
}

.toc-item .toc-page {
    color: var(--text-secondary);
    font-size: 11px;
    white-space: nowrap;
}

.toc-item[data-level="2"] { padding-left: 24px; }
.toc-item[data-level="3"] { padding-left: 36px; }

.thumbs-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
}

.thumb-item {
    cursor: pointer;
    border: 2px solid transparent;
    border-radius: 4px;
    overflow: hidden;
    transition: border-color 0.15s;
    position: relative;
}

.thumb-item:hover {
    border-color: var(--accent);
}

.thumb-item.active {
    border-color: var(--accent);
}

.thumb-item img {
    width: 100%;
    display: block;
}

.thumb-item .thumb-num {
    position: absolute;
    bottom: 2px;
    right: 2px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 1px 6px;
    border-radius: 3px;
    font-size: 10px;
}

/* ===== Book container ===== */
.book-container {
    grid-area: main;
    display: flex;
    align-items: center;
    justify-content: center;
    position: relative;
    overflow: hidden;
    background: var(--bg-primary);
    padding: 20px;
}

#flipbook-wrapper {
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: transform 0.25s ease-out;
    transform-origin: center center;
}

#flipbook {
    box-shadow: var(--shadow);
}

#flipbook .page {
    background: white;
    overflow: hidden;
}

#flipbook .page img {
    width: 100%;
    height: 100%;
    display: block;
    pointer-events: none;
    user-select: none;
}

/* ===== Nav buttons ===== */
.nav-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    width: 48px;
    height: 48px;
    background: rgba(45, 51, 63, 0.85);
    border: 1px solid var(--border);
    color: var(--text-primary);
    cursor: pointer;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
    transition: all 0.15s;
    backdrop-filter: blur(8px);
}

.nav-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: white;
}

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

.nav-prev { left: 16px; }
.nav-next { right: 16px; }

/* ===== Status bar ===== */
.status-bar {
    grid-area: status;
    display: flex;
    align-items: center;
    gap: 16px;
    padding: 0 16px;
    background: var(--bg-toolbar);
    border-top: 1px solid var(--border);
}

.page-indicator {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 13px;
    color: var(--text-primary);
}

#page-input {
    width: 50px;
    height: 28px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 4px;
    color: var(--text-primary);
    text-align: center;
    font-size: 13px;
    outline: none;
}

#page-input:focus {
    border-color: var(--accent);
}

.progress-bar {
    flex: 1;
    height: 4px;
    background: var(--bg-secondary);
    border-radius: 2px;
    overflow: hidden;
}

#progress-fill {
    height: 100%;
    background: var(--accent);
    width: 0%;
    transition: width 0.3s;
}

/* ===== Search results ===== */
.search-results {
    position: absolute;
    top: 56px;
    left: 50%;
    transform: translateX(-50%);
    width: 480px;
    max-height: 400px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 8px;
    box-shadow: var(--shadow);
    z-index: 100;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.search-results.hidden {
    display: none;
}

.search-results-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 13px;
    color: var(--text-secondary);
}

#btn-search-close {
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 18px;
    padding: 0;
    width: 24px;
    height: 24px;
    border-radius: 4px;
}

#btn-search-close:hover {
    background: rgba(255, 255, 255, 0.08);
    color: var(--text-primary);
}

#search-results-list {
    overflow-y: auto;
    flex: 1;
}

.search-result {
    padding: 12px 14px;
    cursor: pointer;
    border-bottom: 1px solid var(--border);
    transition: background 0.15s;
}

.search-result:hover {
    background: rgba(255, 255, 255, 0.04);
}

.search-result:last-child {
    border-bottom: none;
}

.search-result-page {
    font-size: 11px;
    color: var(--accent);
    font-weight: 600;
    margin-bottom: 4px;
}

.search-result-snippet {
    font-size: 13px;
    color: var(--text-primary);
    line-height: 1.5;
}

.search-result-snippet mark {
    background: var(--highlight);
    color: #000;
    padding: 0 2px;
    border-radius: 2px;
}

/* ===== Loading ===== */
.loading {
    position: fixed;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: var(--bg-primary);
    z-index: 1000;
    gap: 16px;
}

.loading.hidden {
    display: none;
}

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

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

/* ===== Mobile ===== */
@media (max-width: 768px) {
    #app {
        grid-template-columns: minmax(0, 1fr);
        grid-template-areas:
            "toolbar"
            "main"
            "status";
    }

    .toolbar {
        overflow: hidden;
    }

    .toolbar-logo {
        display: none;
    }

    #book-title {
        max-width: 120px;
    }

    .sidebar {
        position: fixed;
        top: 56px;
        left: 0;
        height: calc(100vh - 56px);
        z-index: 50;
        width: 100%;
        max-width: 320px;
    }

    .toolbar-center {
        display: none;
    }

    #book-title {
        max-width: 160px;
        font-size: 13px;
    }

    .nav-btn {
        width: 40px;
        height: 40px;
    }

    .search-results {
        width: 90%;
    }

    .book-container {
        padding: 0;
    }

    #flipbook-wrapper {
        padding: 0;
    }

    #flipbook {
        margin: 0 auto;
    }

    .nav-prev { left: 4px; }
    .nav-next { right: 4px; }

    .nav-btn {
        background: rgba(0, 0, 0, 0.35);
        border-color: transparent;
    }
}
