/* ============================================================
   EKSER KATALOG - STYLE
   Modern, responsive flipbook e-catalog styles
   ============================================================ */

/* ---- CSS Variables (Easy to customize) ---- */
:root {
    --brand-color: #222222;
    --brand-color-light: #333333;
    --brand-color-dark: #111111;
    --accent-color: #4a90d9;
    --accent-hover: #357abd;

    --bg-color: #f2f2f2;
    --bg-secondary: #e8e8e8;
    --surface-color: #ffffff;

    --text-primary: #222222;
    --text-secondary: #666666;
    --text-light: #999999;
    --text-on-brand: #ffffff;

    --control-bar-bg: rgba(34, 34, 34, 0.95);
    --control-bar-height: 56px;
    --header-height: 56px;

    --shadow-soft: 0 2px 20px rgba(0, 0, 0, 0.08);
    --shadow-medium: 0 4px 30px rgba(0, 0, 0, 0.12);
    --shadow-strong: 0 8px 40px rgba(0, 0, 0, 0.18);

    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 16px;
    --radius-round: 50%;

    --transition-fast: 0.15s ease;
    --transition-normal: 0.25s ease;
    --transition-smooth: 0.35s cubic-bezier(0.4, 0, 0.2, 1);

    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Arial, sans-serif;
    --z-header: 100;
    --z-control-bar: 100;
    --z-pages-panel: 200;
    --z-pages-overlay: 190;
    --z-modal: 500;
    --z-toast: 600;
    --z-loading: 1000;
}

/* ---- Reset & Base ---- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: var(--font-family);
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    position: relative;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

img {
    max-width: 100%;
    display: block;
}

button {
    cursor: pointer;
    border: none;
    background: none;
    font-family: inherit;
    outline: none;
    -webkit-tap-highlight-color: transparent;
}

input {
    font-family: inherit;
    outline: none;
    border: none;
}

/* ---- Loading Screen ---- */
#loading-screen {
    position: fixed;
    inset: 0;
    background: var(--bg-color);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-loading);
    transition: opacity 0.5s ease, visibility 0.5s ease;
}

#loading-screen.hidden {
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
}

.loading-content {
    text-align: center;
}

.loading-spinner {
    width: 48px;
    height: 48px;
    border: 3px solid var(--bg-secondary);
    border-top-color: var(--brand-color);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
    margin: 0 auto 20px;
}

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

.loading-text {
    font-size: 0.95rem;
    color: var(--text-secondary);
    font-weight: 500;
    margin-bottom: 16px;
}

.loading-progress {
    width: 200px;
    height: 4px;
    background: var(--bg-secondary);
    border-radius: 2px;
    overflow: hidden;
    margin: 0 auto;
}

.loading-progress-bar {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--brand-color), var(--accent-color));
    border-radius: 2px;
    transition: width 0.3s ease;
}

/* ---- App Container ---- */
#app-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    width: 100vw;
    overflow: hidden;
    position: relative;
}

/* ---- Header ---- */
#header {
    height: var(--header-height);
    background: var(--surface-color);
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    box-shadow: 0 1px 8px rgba(0, 0, 0, 0.04);
    z-index: var(--z-header);
    flex-shrink: 0;
    display: flex;
    align-items: center;
}

.header-inner {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.logo-area {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
}

.header-logo {
    max-width: 220px;
    height: 40px;
    object-fit: contain;
    display: block;
}

.logo-area h1 {
    font-size: 1.15rem;
    font-weight: 700;
    letter-spacing: 2px;
    color: var(--brand-color);
    white-space: nowrap;
}

/* ---- Catalog Wrapper (Catalog Area) ---- */
#catalog-wrapper {
    flex: 1;
    min-height: 0;
    width: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    position: relative;
    background: #f2f2f2;
}

/* ---- Book Wrapper (Flipbook Outer) ---- */
.book-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    max-width: 96vw;
    max-height: 100%;
    overflow: visible;
    transform-origin: center center;
    transition: transform 0.25s ease-out;
}

#flipbook {
    position: relative;
    background: transparent;
    max-width: 100%;
    max-height: 100%;
    display: block;
    opacity: 1;
    visibility: visible;
}

/* StPageFlip overrides */
.stf__parent {
    margin: 0 auto;
}

/* Page styling */
.page-wrapper {
    background-color: #fff;
    overflow: hidden;
}

.page-wrapper img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    image-rendering: -webkit-optimize-contrast;
    image-rendering: crisp-edges;
}

.page-loading {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: #fafafa;
}

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

.page-error {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    width: 100%;
    height: 100%;
    background: #fafafa;
    color: var(--text-light);
    font-size: 0.85rem;
    gap: 8px;
}

.page-error i {
    font-size: 1.5rem;
    color: #ccc;
}

/* ---- Control Bar ---- */
#control-bar {
    height: var(--control-bar-height);
    background: var(--control-bar-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-top: 1px solid rgba(255, 255, 255, 0.06);
    z-index: var(--z-control-bar);
    flex-shrink: 0;
    display: flex;
    align-items: center;
    user-select: none;
}

.control-bar-inner {
    width: 100%;
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 8px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 4px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 2px;
}

.control-group-left {
    gap: 2px;
}

.control-group-center {
    gap: 2px;
}

.control-group-right {
    gap: 2px;
}

/* Control Button */
.ctrl-btn {
    width: 40px;
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    color: var(--text-on-brand);
    font-size: 0.9rem;
    transition: all var(--transition-fast);
    position: relative;
    flex-shrink: 0;
}

.ctrl-btn:hover {
    background: rgba(255, 255, 255, 0.12);
}

.ctrl-btn:active {
    background: rgba(255, 255, 255, 0.2);
    transform: scale(0.93);
}

.ctrl-btn.active {
    background: rgba(255, 255, 255, 0.15);
    color: var(--accent-color);
}

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

.ctrl-btn:disabled:hover {
    background: transparent;
    transform: none;
}

/* Page Indicator */
.page-indicator {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 0 6px;
    height: 34px;
    background: rgba(255, 255, 255, 0.1);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.page-input {
    width: 36px;
    height: 28px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 4px;
    color: var(--text-on-brand);
    font-size: 0.8rem;
    font-weight: 600;
    text-align: center;
    padding: 0 2px;
    -moz-appearance: textfield;
}

.page-input::-webkit-outer-spin-button,
.page-input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.page-input:focus {
    border-color: var(--accent-color);
    background: rgba(255, 255, 255, 0.2);
}

.page-separator {
    color: rgba(255, 255, 255, 0.4);
    font-size: 0.8rem;
    font-weight: 500;
}

.page-total {
    color: rgba(255, 255, 255, 0.7);
    font-size: 0.8rem;
    font-weight: 500;
}

/* ---- Pages Panel ---- */
#pages-panel {
    width: 240px;
    background: var(--surface-color);
    border-right: 1px solid rgba(0, 0, 0, 0.06);
    display: flex;
    flex-direction: column;
    z-index: var(--z-pages-panel);
    flex-shrink: 0;
    margin-left: -240px; /* Hidden by default */
    transition: margin-left var(--transition-smooth), transform var(--transition-smooth), opacity var(--transition-smooth);
    box-shadow: 2px 0 20px rgba(0, 0, 0, 0.06);
    overflow: hidden;
    opacity: 0;
    pointer-events: none;
}

#pages-panel.is-open {
    margin-left: 0;
    opacity: 1;
    pointer-events: auto;
}

.pages-panel-header {
    height: 48px;
    padding: 0 16px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
    font-weight: 600;
    font-size: 0.9rem;
    color: var(--text-primary);
    flex-shrink: 0;
}

.panel-close-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-round);
    color: var(--text-secondary);
    font-size: 0.8rem;
    transition: all var(--transition-fast);
}

.panel-close-btn:hover {
    background: rgba(0, 0, 0, 0.06);
    color: var(--text-primary);
}

.pages-panel-grid {
    flex: 1;
    overflow-y: auto;
    padding: 12px;
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
    align-content: start;
    scrollbar-width: thin;
    scrollbar-color: rgba(0, 0, 0, 0.15) transparent;
}

.pages-panel-grid::-webkit-scrollbar {
    width: 4px;
}

.pages-panel-grid::-webkit-scrollbar-thumb {
    background: rgba(0, 0, 0, 0.15);
    border-radius: 2px;
}

/* Thumbnail Card */
.thumb-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    gap: 6px;
    cursor: pointer;
    border-radius: var(--radius-sm);
    padding: 6px;
    transition: all var(--transition-fast);
    border: 2px solid transparent;
}

.thumb-card:hover {
    background: rgba(0, 0, 0, 0.04);
}

.thumb-card.active {
    border-color: var(--brand-color);
    background: rgba(0, 0, 0, 0.02);
}

.thumb-image-wrap {
    width: 100%;
    aspect-ratio: 0.707;
    background: #f3f3f3;
    border: 1px solid #ddd;
    overflow: hidden;
    border-radius: 4px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.thumb-image-wrap.spread {
    aspect-ratio: 1.414;
}

.thumb-image-wrap img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    display: block;
    background: #fff;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.thumb-image-wrap img.loaded {
    opacity: 1;
}

.thumb-image-wrap.spread img {
    width: 50%;
}

.thumb-error {
    font-size: 0.7rem;
    color: var(--text-light);
    text-align: center;
    padding: 0 4px;
}

.thumb-label {
    font-size: 13px;
    line-height: 1.2;
    color: var(--text-primary);
    text-align: center;
    font-weight: 500;
}

/* ---- Pages Panel Overlay (mobile) ---- */
.pages-panel-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: var(--z-pages-overlay);
    transition: opacity var(--transition-normal);
    backdrop-filter: blur(2px);
}

/* ---- Search Modal ---- */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: var(--z-modal);
    padding: 20px;
    backdrop-filter: blur(4px);
    animation: fadeIn 0.2s ease;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: var(--surface-color);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 440px;
    box-shadow: var(--shadow-strong);
    overflow: hidden;
    animation: slideUp 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid rgba(0, 0, 0, 0.06);
}

.modal-header h3 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--text-primary);
}

.modal-close-btn {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-round);
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.modal-close-btn:hover {
    background: rgba(0, 0, 0, 0.06);
}

.modal-body {
    padding: 20px;
}

.search-input-wrapper {
    position: relative;
    margin-bottom: 12px;
}

.search-input-wrapper .search-icon {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: var(--text-light);
    font-size: 0.85rem;
}

.search-input-wrapper input {
    width: 100%;
    height: 44px;
    padding: 0 16px 0 42px;
    background: var(--bg-color);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    font-size: 0.9rem;
    color: var(--text-primary);
    transition: border-color var(--transition-fast);
}

.search-input-wrapper input::placeholder {
    color: var(--text-light);
}

.search-input-wrapper input:focus {
    border-color: var(--accent-color);
    background: var(--surface-color);
}

.search-results {
    max-height: 250px;
    overflow-y: auto;
}

.search-result-item {
    padding: 10px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background var(--transition-fast);
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 10px;
}

.search-result-item:hover {
    background: var(--bg-color);
    color: var(--text-primary);
}

.search-result-item i {
    color: var(--accent-color);
    font-size: 0.8rem;
    flex-shrink: 0;
}

.search-no-result {
    padding: 16px;
    text-align: center;
    color: var(--text-light);
    font-size: 0.85rem;
}

/* ---- Toast Notification ---- */
.toast {
    position: fixed;
    bottom: 80px;
    left: 50%;
    transform: translateX(-50%);
    background: var(--brand-color);
    color: var(--text-on-brand);
    padding: 12px 24px;
    border-radius: var(--radius-md);
    font-size: 0.85rem;
    font-weight: 500;
    z-index: var(--z-toast);
    box-shadow: var(--shadow-medium);
    animation: toastIn 0.3s ease;
    white-space: nowrap;
    max-width: 90vw;
    overflow: hidden;
    text-overflow: ellipsis;
}

@keyframes toastIn {
    from { transform: translateX(-50%) translateY(16px); opacity: 0; }
    to { transform: translateX(-50%) translateY(0); opacity: 1; }
}

/* ---- Share Modal & QR Modal ---- */
.share-modal-content {
    max-width: 400px;
}

.share-options-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 16px;
    padding: 8px 0;
}

.share-opt-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 12px 8px;
    border-radius: var(--radius-md);
    transition: background 0.2s ease;
    text-decoration: none;
    color: var(--text-color);
}

.share-opt-btn:hover {
    background: rgba(0,0,0,0.05);
}

.share-opt-icon {
    width: 48px;
    height: 48px;
    background: var(--brand-color);
    color: var(--text-on-brand);
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    font-size: 1.25rem;
    box-shadow: 0 4px 10px rgba(var(--brand-color-rgb), 0.3);
}

.share-opt-btn span {
    font-size: 0.75rem;
    font-weight: 500;
    text-align: center;
}

.qr-modal-content {
    max-width: 320px;
    text-align: center;
}

.qr-modal-body {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 16px;
    padding: 24px;
}

#qrcode-container img {
    margin: 0 auto;
}

.qr-link-text {
    font-size: 0.75rem;
    color: var(--text-muted);
    word-break: break-all;
    max-width: 100%;
}

/* ---- Mobile Landscape Fixes ---- */
@media (max-height: 500px) and (orientation: landscape) {
    #header {
        height: 44px;
        min-height: 44px;
    }

    .header-logo {
        max-height: 34px;
    }

    #control-bar {
        height: 48px;
        min-height: 48px;
        padding: 0 8px;
    }

    .ctrl-btn {
        width: 36px;
        height: 36px;
        font-size: 0.9rem;
    }

    .page-nav {
        gap: 4px;
    }

    #page-input {
        width: 36px;
        height: 30px;
        font-size: 0.85rem;
    }

    #flipbook-outer {
        padding: 4px;
    }
}

/* Mobile share bottom sheet */
@media (max-width: 768px) {
    #share-modal .modal-content {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        max-width: 100%;
        border-radius: 20px 20px 0 0;
        margin: 0;
        transform: translateY(100%);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    #share-modal.modal-overlay[style*="display: flex"] .modal-content {
        transform: translateY(0);
    }

    .share-options-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }
}

@media (max-width: 900px) {
    .stf__parent {
        /* Force visibility on mobile */
        opacity: 1 !important;
        visibility: visible !important;
    }
}

/* ---- Fullscreen styles removed ---- */

/* ---- Responsive ---- */

/* Large screens */
@media (min-width: 1024px) {
    .ctrl-btn {
        width: 42px;
        height: 42px;
        font-size: 0.95rem;
        border-radius: var(--radius-md);
    }

    .control-group {
        gap: 4px;
    }

    .page-input {
        width: 42px;
    }
}

/* Tablet */
@media (max-width: 1023px) {
    .control-group-center {
        display: none;
    }

    .ctrl-btn {
        width: 38px;
        height: 38px;
        font-size: 0.85rem;
    }
}

/* Mobile */
@media (max-width: 768px) {
    :root {
        --header-height: 48px;
        --control-bar-height: 52px;
    }

    .logo-area h1 {
        font-size: 0.95rem;
        letter-spacing: 1px;
    }

    .header-logo {
        max-width: 160px;
        height: 32px;
    }

    #flipbook-outer {
        padding: 8px;
    }

    .ctrl-btn {
        width: 36px;
        height: 36px;
        font-size: 0.8rem;
    }

    .control-bar-inner {
        padding: 0 4px;
    }

    /* Hide less important buttons on mobile */
    #btn-zoom-in,
    #btn-zoom-out {
        display: none;
    }

    /* Pages panel - bottom drawer on mobile */
    #pages-panel {
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        width: 100%;
        height: 60vh;
        border-right: none;
        border-top: 1px solid rgba(0, 0, 0, 0.08);
        border-radius: var(--radius-lg) var(--radius-lg) 0 0;
        margin-left: 0 !important;
        transform: translateY(100%); /* Hidden by default on mobile */
        box-shadow: 0 -4px 30px rgba(0, 0, 0, 0.15);
        z-index: var(--z-pages-panel);
        transition: transform var(--transition-smooth), opacity var(--transition-smooth);
        opacity: 0;
        pointer-events: none;
    }

    #pages-panel.is-open {
        transform: translateY(0);
        opacity: 1;
        pointer-events: auto;
    }

    .pages-panel-grid {
        grid-template-columns: repeat(3, 1fr);
        gap: 8px;
    }

    .page-input {
        width: 32px;
        font-size: 0.75rem;
    }

    .page-separator,
    .page-total {
        font-size: 0.75rem;
    }

    /* Fix mobile flipbook sizing and visibility */
    #catalog-wrapper {
        height: calc(100vh - var(--header-height) - var(--control-bar-height));
        padding: 8px;
    }

    #flipbook-outer {
        width: 100%;
        max-width: 100vw;
        height: 100%;
        display: flex;
        align-items: center;
        justify-content: center;
        padding: 0;
    }

    #flipbook {
        display: block;
        visibility: visible;
        opacity: 1;
    }

    .page-wrapper {
        background: white;
        overflow: hidden;
    }

    .page-wrapper img {
        width: 100%;
        height: 100%;
        object-fit: contain;
        display: block;
        opacity: 1;
        visibility: visible;
    }
}

/* Very small mobile */
@media (max-width: 400px) {
    .ctrl-btn {
        width: 32px;
        height: 32px;
        font-size: 0.75rem;
    }

    #btn-sound,
    #btn-autoplay {
        display: none;
    }

    .page-indicator {
        padding: 0 4px;
    }

    .page-input {
        width: 28px;
        height: 24px;
        font-size: 0.7rem;
    }
}

/* Landscape mobile optimized above */

/* ---- Print ---- */
@media print {
    #control-bar,
    #header,
    #pages-panel,
    #loading-screen,
    .modal-overlay,
    .toast {
        display: none !important;
    }
}


/* ---- Izgara Görünümü Sol Panel Kaydırma Çubuğu ---- */
#pages-panel {
    max-height: calc(100vh - (var(--header-height) + var(--control-bar-height))); /* Panel yüksekliğini ayarlar */
    overflow-y: auto !important; /* Dikey kaydırmayı aktif eder */
    scrollbar-width: thin; /* Firefox için ince çubuk */
    scrollbar-color: var(--text-light) transparent;
}

/* Chrome, Edge ve Safari için kaydırma çubuğu tasarımı */
#pages-panel::-webkit-scrollbar {
    width: 6px;
}

#pages-panel::-webkit-scrollbar-thumb {
    background-color: var(--text-light);
    border-radius: 10px;
}

#pages-panel::-webkit-scrollbar-track {
    background: transparent;
}
