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

:root {
    --bg: #f4f6fb;
    --surface: #ffffff;
    --surface2: #f0f2f8;
    --border: #e2e6f0;
    --accent: #5b6ef5;
    --accent-hover: #4a5de0;
    --danger: #e05454;
    --text: #1a1d2e;
    --text-muted: #6b7190;
    --radius: 10px;
    --font: 'Segoe UI', system-ui, sans-serif;
    --shadow: 0 1px 4px rgba(0,0,0,0.07);
}

body {
    background: var(--bg);
    color: var(--text);
    font-family: var(--font);
    font-size: 14px;
    min-height: 100vh;
}

.hidden { display: none !important; }

/* ─── Layout ───────────────────────────────────────────────────────────────────── */

.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 220px;
    background: var(--surface);
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    padding: 20px 16px;
    flex-shrink: 0;
    box-shadow: var(--shadow);
}

.sidebar-logo {
    font-size: 20px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 16px;
    display: flex;
    align-items: center;
    gap: 8px;
}

.sidebar-logo svg {
    width: 28px;
    height: 28px;
    flex-shrink: 0;
}

.user-info {
    background: var(--surface2);
    border-radius: 8px;
    padding: 10px 12px;
    font-size: 12px;
    color: var(--text-muted);
    margin-bottom: 20px;
    border-left: 3px solid var(--accent);
    cursor: pointer;
    transition: all 0.15s;
}

.user-info:hover {
    background: var(--border);
    color: var(--accent);
    font-weight: 500;
}

.nav-btn {
    display: block;
    width: 100%;
    text-align: left;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 14px;
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.15s;
    margin-bottom: 8px;
}

.nav-btn:hover, .nav-btn.active {
    background: var(--surface2);
    color: var(--accent);
    font-weight: 600;
}

.sidebar-footer { margin-top: auto; }

.sidebar-footer button {
    width: 100%;
    background: none;
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 8px 12px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 13px;
    transition: all 0.15s;
}

.sidebar-footer button:hover { border-color: var(--danger); color: var(--danger); }

.content { flex: 1; padding: 32px 40px; overflow-y: auto; }

/* ─── Header ───────────────────────────────────────────────────────────────────── */

.page-header {
    display: flex;
    align-items: center;
    gap: 14px;
    margin-bottom: 28px;
}

.page-header h1 { font-size: 22px; font-weight: 700; flex: 1; }
.header-actions { display: flex; gap: 10px; }

/* ─── Buttons ──────────────────────────────────────────────────────────────────── */

.btn {
    padding: 9px 18px;
    border-radius: 8px;
    border: none;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { border-color: var(--accent); color: var(--accent); }
.btn-ghost { background: none; color: var(--text-muted); border: 1px solid var(--border); }
.btn-ghost:hover { color: var(--text); border-color: var(--text-muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #c03a3a; }
.btn-full { width: 100%; }

/* ─── Tabs ────────────────────────────────────────────────────────────────────── */

.editor-tabs {
    display: flex;
    gap: 8px;
    margin-bottom: 16px;
    border-bottom: 1px solid var(--border);
}

.tab-btn {
    background: none;
    border: none;
    padding: 10px 16px;
    font-size: 13px;
    color: var(--text-muted);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    transition: all 0.15s;
    margin-bottom: -1px;
}

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

/* ─── Catalog Grid ────────────────────────────────────────────────────────────────────── */

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

.catalog-card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.15s, box-shadow 0.15s;
}

.catalog-card:hover {
    transform: translateY(-3px);
    box-shadow: 0 8px 24px rgba(91,110,245,0.1);
}

.catalog-card-thumb {
    height: 110px;
    position: relative;
    display: flex;
    flex-direction: column;
}

.catalog-card-body { padding: 14px 16px; }
.catalog-card-body h3 { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.catalog-card-body p { color: var(--text-muted); font-size: 13px; margin-bottom: 12px; min-height: 18px; }

.catalog-card-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.catalog-card-actions .btn { font-size: 12px; padding: 6px 12px; }

/* ─── Design Picker ───────────────────────────────────────────────────────────────────── */

.theme-picker { display: flex; flex-direction: column; gap: 14px; }

.design-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 10px;
}

.design-card {
    border: 2px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    cursor: pointer;
    transition: border-color 0.15s, box-shadow 0.15s;
    background: var(--surface);
}
.design-card:hover { border-color: var(--accent); }
.design-card.active {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(91,110,245,0.18);
}

.design-preview {
    height: 80px;
    position: relative;
    overflow: hidden;
}
.design-preview > div { width: 100%; height: 100%; }

.theme-preview-btn {
    position: absolute;
    top: 5px;
    right: 5px;
    background: rgba(0,0,0,0.6);
    color: #fff;
    border: none;
    border-radius: 50%;
    width: 24px;
    height: 24px;
    font-size: 12px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s;
    z-index: 10;
    backdrop-filter: blur(4px);
}
.design-card:hover .theme-preview-btn { opacity: 1; }

.design-meta {
    padding: 7px 9px;
    background: var(--surface);
    border-top: 1px solid var(--border);
}
.design-meta strong { font-size: 11px; font-weight: 600; color: var(--text); display: block; }
.design-meta span { font-size: 10px; color: var(--text-muted); line-height: 1.3; }

/* Color palette (shows when Classic is selected) */
.color-palette {
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 12px 14px;
}
.color-palette.hidden { display: none; }
.palette-label {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.06em;
    margin-bottom: 10px;
}
.palette-swatches { display: flex; gap: 8px; flex-wrap: wrap; }
.palette-swatch {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    border: 2px solid transparent;
    cursor: pointer;
    transition: transform 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.palette-swatch:hover { transform: scale(1.15); }
.palette-swatch.active {
    border-color: #fff;
    box-shadow: 0 0 0 2px var(--accent);
    transform: scale(1.15);
}

/* ─── Page Grid ────────────────────────────────────────────────────────────────────── */

.page-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
}

.page-item {
    background: var(--surface);
    border: 2px solid var(--border);
    border-radius: var(--radius);
    overflow: hidden;
    cursor: grab;
    transition: all 0.15s;
}

.page-item:hover { border-color: var(--accent); box-shadow: 0 4px 12px rgba(91,110,245,0.1); }
.page-item:active { cursor: grabbing; }

.page-item img {
    width: 100%;
    aspect-ratio: 3/4;
    object-fit: cover;
    display: block;
}

.page-item-footer {
    padding: 8px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: var(--surface);
    border-top: 1px solid var(--border);
}

.page-item-num { font-size: 12px; color: var(--text-muted); font-weight: 500; }

.page-delete {
    background: var(--danger);
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 5px;
    transition: background 0.15s;
}

.page-delete:hover { background: #c03a3a; }

.sortable-ghost { opacity: 0.3; border: 2px dashed var(--accent); }
.sortable-drag { opacity: 0.9; box-shadow: 0 8px 24px rgba(0,0,0,0.2); }

/* ─── Library Grid ────────────────────────────────────────────────────────────────────── */

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

.library-item {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    box-shadow: var(--shadow);
    transition: transform 0.15s;
}

.library-item:hover { transform: translateY(-2px); }

.library-item img {
    width: 100%;
    aspect-ratio: 3/4;
    object-fit: cover;
    display: block;
}

.library-item-footer {
    padding: 8px 10px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-top: 1px solid var(--border);
}

.library-item-date { font-size: 11px; color: var(--text-muted); }

.library-delete {
    background: var(--danger);
    border: none;
    color: #fff;
    cursor: pointer;
    font-size: 11px;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 4px;
    transition: background 0.15s;
}

.library-delete:hover { background: #c03a3a; }

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

.library-select-item {
    position: relative;
    border-radius: 10px;
    overflow: hidden;
    border: 2px solid var(--border);
    transition: border-color 0.15s;
}

.library-select-item:hover { border-color: var(--accent); }
.library-select-item.selected { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(91,110,245,0.2); }

.library-select-item img {
    width: 100%;
    aspect-ratio: 3/4;
    object-fit: cover;
    display: block;
}

.library-select-overlay {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.3);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: opacity 0.15s;
}

.library-select-item:hover .library-select-overlay { opacity: 1; }

.lib-checkbox {
    width: 20px;
    height: 20px;
    cursor: pointer;
}

/* ─── Modal ────────────────────────────────────────────────────────────────────── */

.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,16,30,0.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    backdrop-filter: blur(4px);
}

.modal {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 28px;
    width: 440px;
    max-width: 94vw;
    box-shadow: 0 20px 60px rgba(0,0,0,0.15);
}

.modal-wide {
    width: 860px;
    max-width: 96vw;
    max-height: 92vh;
    overflow-y: auto;
}

.modal-sm { width: 340px; }

.modal-cols {
    display: flex;
    gap: 28px;
    margin-bottom: 4px;
}

.modal-left { flex: 0 0 260px; }
.modal-right { flex: 1; min-width: 0; }

.modal h2 { font-size: 18px; font-weight: 700; margin-bottom: 20px; }
.modal p { color: var(--text-muted); font-size: 14px; margin-bottom: 20px; line-height: 1.6; }

.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 6px;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.optional { font-size: 11px; font-weight: 400; text-transform: none; }

.form-group input,
.form-group textarea {
    width: 100%;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 14px;
    padding: 10px 12px;
    font-family: var(--font);
    transition: border-color 0.15s;
    resize: vertical;
}

.form-group input:focus,
.form-group textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,110,245,0.1); }

.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; }

/* ─── Upload Progress ──────────────────────────────────────────────────────────────────── */

.upload-progress {
    background: #eef0ff;
    border: 1px solid #c8ccff;
    border-radius: var(--radius);
    padding: 12px 18px;
    margin-bottom: 20px;
    font-size: 13px;
    color: var(--accent);
    font-weight: 500;
}

/* ─── Login ────────────────────────────────────────────────────────────────────── */

.login-body {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: #f4f6fb;
}

.login-box {
    background: #fff;
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 40px;
    width: 360px;
    max-width: 90vw;
    box-shadow: 0 4px 24px rgba(0,0,0,0.08);
}

.login-logo {
    font-size: 24px;
    font-weight: 700;
    color: var(--accent);
    margin-bottom: 6px;
    text-align: center;
}

.login-subtitle {
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
    margin-bottom: 24px;
}

.error-msg { color: var(--danger); font-size: 13px; margin-bottom: 12px; text-align: center; }

.empty-state {
    color: var(--text-muted);
    text-align: center;
    padding: 48px 0;
    font-size: 14px;
}

/* ─── Catalog Preview Modal ──────────────────────────────────────── */

.catalog-preview-wrap {
    width: 90vw;
    height: 90vh;
    background: var(--surface);
    border-radius: 16px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
}

.catalog-preview-topbar {
    background: var(--surface);
    border-bottom: 1px solid var(--border);
    padding: 14px 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
}

.preview-catalog-label {
    font-weight: 700;
    font-size: 16px;
    color: var(--text);
}

.catalog-preview-container {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 20px;
    padding: 20px;
    position: relative;
    background: linear-gradient(135deg, var(--surface2) 0%, var(--bg) 100%);
    overflow: hidden;
}

.catalog-preview-arrow {
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: var(--accent);
    color: #fff;
    border: none;
    font-size: 28px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    transition: all 0.15s;
    font-weight: bold;
}

.catalog-preview-arrow:hover {
    background: var(--accent-hover);
    transform: scale(1.1);
}

.catalog-preview-screen {
    flex: 1;
    max-width: 500px;
    height: 100%;
    background: var(--cp-grad, linear-gradient(135deg, var(--cp-page) 0%, var(--cp-bg) 100%));
    border-radius: 8px;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 10px 40px rgba(0,0,0,0.4);
}

.cps-header {
    background: var(--cp-header);
    border-bottom: 1px solid rgba(255,255,255,0.1);
    height: 48px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 12px;
    flex-shrink: 0;
}

.cps-back { font-size: 12px; color: var(--cp-muted, rgba(255,255,255,0.6)); }
.cps-title { flex: 1; text-align: center; font-weight: 600; font-size: 13px; color: var(--cp-text, #fff); }
.cps-theme { font-size: 10px; color: var(--cp-accent); font-weight: 600; }

.cps-main {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.cps-book {
    display: flex;
    gap: 4px;
    height: 80%;
    max-height: 300px;
    box-shadow: 0 8px 30px rgba(0,0,0,0.4);
    border-radius: 3px;
    overflow: hidden;
}

.cps-page {
    flex: 1;
    background: var(--cp-page);
    min-width: 100px;
}

.cps-footer {
    background: var(--cp-header);
    border-top: 1px solid rgba(255,255,255,0.1);
    height: 40px;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    font-size: 12px;
    color: var(--cp-muted, rgba(255,255,255,0.6));
    padding: 0 16px;
    text-align: center;
}

.catalog-preview-list {
    background: var(--surface2);
    border-top: 1px solid var(--border);
    padding: 12px;
    display: flex;
    gap: 8px;
    overflow-x: auto;
    flex-shrink: 0;
    max-height: 60px;
}

.catalog-preview-item {
    background: var(--surface);
    border: 1px solid var(--border);
    color: var(--text-muted);
    padding: 8px 14px;
    border-radius: 6px;
    cursor: pointer;
    font-size: 12px;
    white-space: nowrap;
    transition: all 0.15s;
    font-family: var(--font);
}

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

.catalog-preview-item.active {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
    font-weight: 600;
}
