/* ============================================================
   Libro.az — design tokens + component classes
   Единая система для панели, админки и лендинга.
   Светлая тема = :root, тёмная = .dark (класс на <html>).
   ============================================================ */

:root {
    color-scheme: light;

    --bg: #f8fafc;             /* фон страницы */
    --surface: #ffffff;        /* карточки / панели */
    --surface-2: #f1f5f9;      /* hover / вторичная поверхность */
    --text: #0f172a;           /* основной текст */
    --muted: #64748b;          /* приглушённый текст */
    --border: #e2e8f0;         /* границы */
    --primary: #6366f1;        /* индиго */
    --primary-hover: #4f46e5;
    --primary-soft: #eef2ff;
    --ring: rgba(99, 102, 241, 0.12);

    --danger: #dc2626;
    --danger-soft: #fee2e2;
    --success: #16a34a;
    --success-soft: #dcfce7;
    --warning: #ca8a04;
    --warning-soft: #fef9c3;
    --info: #2563eb;
    --info-soft: #dbeafe;
    --purple: #9333ea;
    --purple-soft: #f3e8ff;

    --header-bg: rgba(255, 255, 255, 0.85);
}

.dark {
    color-scheme: dark;

    --bg: #0b1220;
    --surface: #111827;
    --surface-2: #1f2937;
    --text: #f1f5f9;
    --muted: #94a3b8;
    --border: #1f2937;
    --primary: #818cf8;
    --primary-hover: #6366f1;
    --primary-soft: rgba(99, 102, 241, 0.16);
    --ring: rgba(129, 140, 248, 0.25);

    --danger: #f87171;
    --danger-soft: rgba(248, 113, 113, 0.14);
    --success: #4ade80;
    --success-soft: rgba(74, 222, 128, 0.14);
    --warning: #fbbf24;
    --warning-soft: rgba(251, 191, 36, 0.14);
    --info: #60a5fa;
    --info-soft: rgba(96, 165, 250, 0.14);
    --purple: #c084fc;
    --purple-soft: rgba(192, 132, 252, 0.14);

    --header-bg: rgba(11, 18, 32, 0.85);
}

/* ---------- Базовые утилиты ---------- */

.container {
    margin: 0 auto;
    width: 100%;
    max-width: 1200px;
    padding: 0 16px;
    box-sizing: border-box;
}

/* ---------- Кнопки ---------- */

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 16px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    line-height: 1.2;
    cursor: pointer;
    border: none;
    text-decoration: none;
    transition: all 0.15s;
    white-space: nowrap;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--border); }

.btn-danger { background: var(--danger-soft); color: var(--danger); }
.btn-danger:hover { background: var(--danger); color: #fff; }

.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }

.btn-icon { padding: 0; width: 40px; height: 40px; }

/* ---------- Карточки ---------- */

.card {
    background: var(--surface);
    border-radius: 16px;
    padding: 20px;
    border: 1px solid var(--border);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.04);
}

.card-sm {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px 14px;
}

/* ---------- Формы ---------- */

.input {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 14px;
    box-sizing: border-box;
    background: var(--surface);
    color: var(--text);
    font-family: inherit;
}
.input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--ring);
}
.input::placeholder { color: var(--muted); }

.label {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 4px;
}

/* ---------- Бейджи ---------- */

.badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 20px;
    font-weight: 500;
    line-height: 1.5;
    white-space: nowrap;
}
.badge-green  { background: var(--success-soft); color: var(--success); }
.badge-yellow { background: var(--warning-soft); color: var(--warning); }
.badge-red    { background: var(--danger-soft);  color: var(--danger); }
.badge-blue   { background: var(--info-soft);    color: var(--info); }
.badge-purple { background: var(--purple-soft);  color: var(--purple); }

/* ---------- Модалки ---------- */

.modal-overlay {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.4);
    padding: 16px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}
/* Прямой дочерний блок модалки: центрируется, когда помещается,
   и прокручивается вместе с оверлеем, когда контент выше экрана. */
.modal-overlay > * {
    margin: auto;
    flex-shrink: 0;
}
.modal-box {
    background: var(--surface);
    border-radius: 20px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.15);
    padding: 24px;
    max-width: 420px;
    width: 100%;
    max-height: 90vh;
    overflow-y: auto;
}

@media (max-width: 640px) {
    .modal-overlay {
        padding: 12px;
    }
    .modal-box {
        border-radius: 16px;
        padding: 20px;
    }
}

/* ---------- Таблицы ---------- */

.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th {
    text-align: left;
    padding: 10px 12px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.03em;
    border-bottom: 1px solid var(--border);
}
.table td { padding: 12px; border-bottom: 1px solid var(--border); color: var(--text); }
.table tbody tr:hover { background: var(--surface-2); }

/* ---------- Верхняя шапка ---------- */

.app-header {
    position: sticky;
    top: 0;
    z-index: 40;
    padding-top: env(safe-area-inset-top);
    background: var(--header-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

/* ---------- Навигация (top-nav) ---------- */

.nav-link {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 12px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    color: var(--muted);
    text-decoration: none;
    white-space: nowrap;
    transition: color 0.15s, background 0.15s;
}
.nav-link:hover { color: var(--text); background: var(--surface-2); }
.nav-link.active { color: var(--primary); background: var(--primary-soft); }

/* ---------- Мобильный drawer ---------- */

.app-drawer {
    position: fixed;
    top: 0;
    left: 0;
    height: 100%;
    width: 280px;
    max-width: 85vw;
    background: var(--surface);
    z-index: 60;
    transform: translateX(-100%);
    transition: transform 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    box-shadow: 0 0 40px rgba(0, 0, 0, 0.2);
    overflow-y: auto;
    padding-top: env(safe-area-inset-top);
}
.app-drawer.open { transform: translateX(0); }

.app-drawer-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    z-index: 55;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.25s;
}
.app-drawer-backdrop.open { opacity: 1; pointer-events: auto; }

.drawer-link {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border-radius: 10px;
    font-size: 15px;
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
}
.drawer-link:hover { background: var(--surface-2); }
.drawer-link.active { color: var(--primary); background: var(--primary-soft); }

/* ---------- Бургер-кнопка (мобильная) ---------- */

.burger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 40px;
    height: 40px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    cursor: pointer;
    font-size: 18px;
    line-height: 1;
}
.burger:hover { background: var(--surface-2); }

/* ---------- Выпадающее меню «Ещё» ---------- */

.more-menu {
    position: absolute;
    top: calc(100% + 8px);
    right: 0;
    min-width: 210px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 14px;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.14);
    padding: 6px;
    z-index: 55;
    opacity: 0;
    pointer-events: none;
    transform: translateY(-6px);
    transition: opacity 0.15s, transform 0.15s;
}
.more-menu.open { opacity: 1; pointer-events: auto; transform: translateY(0); }

/* ---------- Шапка и секции drawer ---------- */

.app-drawer-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px;
    border-bottom: 1px solid var(--border);
}
.app-drawer-section {
    padding: 14px 16px 6px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.05em;
    text-transform: uppercase;
    color: var(--muted);
}

/* ---------- Тумблер темы ---------- */

.theme-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    cursor: pointer;
    font-size: 16px;
    line-height: 1;
}
.theme-toggle:hover { background: var(--surface-2); color: var(--text); }

/* ---------- Flash-сообщения ---------- */

.flash {
    padding: 12px 16px;
    border-radius: 12px;
    font-size: 14px;
    border: 1px solid var(--border);
}
.flash-success { background: var(--success-soft); color: var(--success); border-color: transparent; }
.flash-error   { background: var(--danger-soft);  color: var(--danger);  border-color: transparent; }

/* ---------- Брендовые градиенты / фон ---------- */

.def-gradient {
    background-image: linear-gradient(120deg, #8ec5fc 0%, #e0c3fc 100%);
}
.def-color {
    background-color: #6366f1;
}
.bg_gradient {
    background: linear-gradient(135deg, #6366f1, #8b5cf6);
}

/* ---------- Мастер создания страницы ---------- */

.wizard-type-card {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 10px;
    text-align: center;
    width: 100%;
    min-height: 190px;
    padding: 24px 16px;
    border-radius: 20px;
    border: 2px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease, background .18s ease;
}
.wizard-type-card:hover {
    border-color: var(--primary);
    transform: translateY(-3px);
    box-shadow: 0 12px 28px rgba(99, 102, 241, .14);
}
.wizard-type-card.selected {
    border-color: var(--primary);
    background: var(--primary-soft);
    box-shadow: 0 12px 28px rgba(99, 102, 241, .16);
}
.wizard-type-card.locked { cursor: not-allowed; opacity: .55; }
.wizard-type-card.locked:hover { border-color: var(--border); transform: none; box-shadow: none; }

.wizard-type-icon {
    width: 62px;
    height: 62px;
    border-radius: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--primary-soft);
    color: var(--primary);
    transition: background .18s ease, color .18s ease;
}
.wizard-type-card.selected .wizard-type-icon { background: var(--primary); color: #fff; }
.wizard-type-card.locked .wizard-type-icon { background: var(--surface-2); color: var(--muted); }

.wizard-check {
    display: none;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border-radius: 9999px;
    background: var(--primary);
    color: #fff;
    box-shadow: 0 2px 8px rgba(0, 0, 0, .18);
}
.wizard-type-card.selected .wizard-check,
.wizard-tpl-card.selected .wizard-check { display: flex; }

/* Панель фильтров */
.wizard-filterbar {
    border: 1px solid var(--border);
    background: var(--surface);
    border-radius: 16px;
    padding: 14px 16px;
    margin-bottom: 18px;
}
.wizard-filter-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: var(--muted);
    letter-spacing: .02em;
    white-space: nowrap;
}

.wizard-chip {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 7px 14px;
    border-radius: 9999px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--muted);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    white-space: nowrap;
    transition: border-color .15s ease, color .15s ease, background .15s ease;
}
.wizard-chip:hover { border-color: var(--primary); color: var(--text); }
.wizard-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.wizard-color {
    width: 30px;
    height: 30px;
    border-radius: 9999px;
    border: 2px solid var(--surface);
    box-shadow: 0 0 0 1px var(--border);
    cursor: pointer;
    flex-shrink: 0;
    transition: transform .15s ease, box-shadow .15s ease;
}
.wizard-color:hover { transform: scale(1.12); }
.wizard-color.active {
    box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary);
    transform: scale(1.08);
}

/* Карточка шаблона */
.wizard-tpl-card {
    position: relative;
    border-radius: 18px;
    border: 2px solid var(--border);
    background: var(--surface);
    overflow: hidden;
    cursor: pointer;
    transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease;
}
.wizard-tpl-card:hover { transform: translateY(-3px); box-shadow: 0 12px 30px rgba(0, 0, 0, .10); }
.wizard-tpl-card.selected {
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--ring), 0 12px 30px rgba(0, 0, 0, .10);
}
.wizard-tpl-thumb {
    position: relative;
    aspect-ratio: 3 / 4;
    background: var(--surface-2);
    overflow: hidden;
}
.wizard-tpl-overlay {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    background: rgba(11, 18, 32, .45);
    opacity: 0;
    transition: opacity .18s ease;
}
.wizard-tpl-card:hover .wizard-tpl-overlay { opacity: 1; }
.wizard-tpl-lock {
    position: absolute;
    inset: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    background: rgba(11, 18, 32, .55);
    color: #fff;
}
.wizard-tpl-info { padding: 12px 14px; }

.wizard-empty {
    grid-column: 1 / -1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
    padding: 64px 20px;
    text-align: center;
}

/* Нижняя панель навигации мастера */
.wizard-footer {
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    z-index: 30;
    background: var(--surface);
    border-top: 1px solid var(--border);
    box-shadow: 0 -8px 30px rgba(0, 0, 0, .06);
}
.wizard-footer-inner {
    max-width: 1152px;
    margin: 0 auto;
    padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
    display: flex;
    gap: 10px;
}
