/* ===== База ===== */
* { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: system-ui, 'Segoe UI', sans-serif; background: var(--bg); color: var(--text); min-height: 100vh; }

/* ===== Темы ===== */
body[data-theme="wagtail"] { --accent: #007d7e; --accent-dark: #005b5c; --sidebar: #2b2b2b; --bg: #f6f6f6; --card: #ffffff; --border: #e1e1e1; --text: #26251f; --radius: 3px; }
body[data-theme="modern"] { --accent: #4f46e5; --accent-dark: #3730a3; --sidebar: #1e1b4b; --bg: #eef0f4; --card: #ffffff; --border: #dde1e8; --text: #18181b; --radius: 10px; }
body[data-theme="warm"]   { --accent: #b4552d; --accent-dark: #8f3f1e; --sidebar: #4a2c1a; --bg: #faf3ea; --card: #fffdf8; --border: #e8dccb; --text: #3b2a1e; --radius: 12px; }

/* ===== Верхняя панель (рамка демо) ===== */
.topbar { display: flex; align-items: center; gap: 24px; padding: 10px 20px; background: var(--sidebar); color: #fff; }
.topbar-brand { font-weight: 600; }
.mode-switch { display: flex; gap: 4px; margin-left: auto; }
.mode-tab { padding: 8px 18px; border: none; border-radius: var(--radius); background: transparent; color: #ffffffaa; cursor: pointer; font-size: 0.95rem; }
.mode-tab.active { background: #ffffff22; color: #fff; font-weight: 600; }
.theme-switch { display: flex; gap: 8px; }
.theme-dot { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; }
.theme-dot.active { border-color: #fff; }
.theme-wagtail { background: #007d7e; }
.theme-modern { background: #4f46e5; }
.theme-warm { background: #b4552d; }

.view { min-height: calc(100vh - 49px); }
.hidden { display: none !important; }

/* ===== Сайт ===== */
.site-hero { background: var(--accent); color: #fff; text-align: center; padding: 56px 20px; }
.site-body { max-width: 640px; margin: 0 auto; padding: 32px 20px 64px; }
.site-body h2 { margin-bottom: 20px; }
.site-dish { display: flex; align-items: baseline; gap: 10px; padding: 12px 4px; border-bottom: 1px dashed var(--border); flex-wrap: wrap; }
.site-dish .dish-ico { display: inline-flex; color: var(--accent); }
.site-dish .dish-ico svg { width: 22px; height: 22px; }
.site-dish .name { font-weight: 600; }
.site-dish .dots { flex: 1; border-bottom: 2px dotted var(--border); min-width: 30px; }
.site-dish .price { font-weight: 700; color: var(--accent); white-space: nowrap; }
.site-dish .desc { flex-basis: 100%; color: #777; font-size: 0.9rem; }

/* ===== Админка: узкий сайдбар как у Wagtail ===== */
.view-admin { display: flex; }
.admin-sidebar { width: 56px; background: var(--sidebar); color: #ffffffbb; flex-shrink: 0; display: flex; flex-direction: column; justify-content: space-between; overflow: hidden; transition: width 0.15s ease; padding: 8px 0; }
.admin-sidebar:hover { width: 210px; }
.admin-sidebar ul { list-style: none; }
.admin-sidebar li { display: flex; align-items: center; gap: 14px; padding: 12px 0 12px 17px; cursor: pointer; white-space: nowrap; font-size: 0.95rem; }
.admin-sidebar li:hover { background: #ffffff14; color: #fff; }
.admin-sidebar li.active { background: var(--accent); color: #fff; }
.admin-sidebar li svg { width: 21px; height: 21px; flex-shrink: 0; }
.admin-sidebar .label { opacity: 0; transition: opacity 0.15s ease; }
.admin-sidebar:hover .label { opacity: 1; }

.admin-content { flex: 1; display: flex; flex-direction: column; }

/* Белая шапка раздела */
.admin-titlebar { background: var(--card); border-bottom: 1px solid var(--border); padding: 16px 28px; }
.admin-titlebar h2 { font-size: 1.25rem; }
.admin-titlebar .subtitle { color: #777; font-size: 0.88rem; margin-top: 3px; }

/* Таблица страниц */
.pages-wrap { padding: 24px 28px; }
.pages-table { width: 100%; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); border-collapse: collapse; }
.pages-table th { text-align: left; font-size: 0.8rem; text-transform: uppercase; letter-spacing: 0.4px; color: #888; padding: 10px 16px; border-bottom: 1px solid var(--border); }
.pages-table td { padding: 12px 16px; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
.pages-table tr:last-child td { border-bottom: none; }
.pages-table tbody tr { cursor: pointer; }
.pages-table tbody tr:hover { background: #00000006; }
.page-title { font-weight: 600; }
.page-title .chevron { color: #999; margin-right: 8px; }
.chip { display: inline-block; padding: 3px 10px; border-radius: 999px; font-size: 0.78rem; font-weight: 600; }
.chip-live { background: #e2f4e8; color: #1c7a3d; }
.chip-draft { background: #eee; color: #777; }

/* Экран редактирования страницы */
.edit-header { background: var(--card); border-bottom: 1px solid var(--border); padding: 14px 28px; display: flex; align-items: center; gap: 16px; }
.breadcrumbs { color: #777; font-size: 0.9rem; }
.breadcrumbs b { color: var(--text); }
.edit-header-actions { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.tabs { background: var(--card); padding: 0 28px; display: flex; gap: 4px; border-bottom: 1px solid var(--border); }
.tab { padding: 10px 16px; border: none; background: none; cursor: pointer; font-size: 0.95rem; color: #666; border-bottom: 3px solid transparent; }
.tab.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: 600; }

.edit-body { padding: 24px 28px; flex: 1; }
.edit-columns { display: grid; grid-template-columns: 1fr 1.4fr; gap: 24px; align-items: start; }

.dish-list { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.dish-item { display: flex; align-items: center; gap: 10px; padding: 12px 16px; cursor: pointer; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
.dish-item:last-child { border-bottom: none; }
.dish-item:hover { background: #00000006; }
.dish-item.selected { background: var(--accent); color: #fff; }
.dish-item svg { width: 18px; height: 18px; flex-shrink: 0; }
.dish-item .price { margin-left: auto; font-weight: 600; }

.dish-form { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 24px; }
.dish-form h3 { margin-bottom: 18px; font-size: 1.05rem; }
.dish-form label { display: block; margin-bottom: 14px; font-size: 0.9rem; color: #555; }
.dish-form input, .dish-form textarea { display: block; width: 100%; margin-top: 6px; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius); font: inherit; background: var(--bg); color: var(--text); }
.dish-form input:focus, .dish-form textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

/* Нижняя панель действий как у Wagtail */
.action-bar { position: sticky; bottom: 0; background: var(--card); border-top: 1px solid var(--border); padding: 12px 28px; display: flex; justify-content: flex-end; gap: 12px; }

/* Таб с настройками/продвижением */
.tab-note { background: var(--card); border: 1px dashed var(--border); border-radius: var(--radius); padding: 24px; color: #777; }
.meta-row { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); font-size: 0.95rem; }
.meta-row:last-child { border-bottom: none; }
.meta-row .k { color: #888; min-width: 170px; }

/* Кнопки */
.btn { padding: 9px 18px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card); color: var(--text); cursor: pointer; font-size: 0.92rem; }
.btn:hover { background: #00000008; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); }

/* Тост */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(80px); background: var(--accent); color: #fff; padding: 12px 24px; border-radius: var(--radius); opacity: 0; transition: all 0.3s ease; pointer-events: none; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* Плашка «это демо» */
.demo-modal { position: fixed; inset: 0; background: #00000066; display: flex; align-items: center; justify-content: center; z-index: 10; }
.demo-modal-box { background: var(--card); max-width: 420px; margin: 20px; padding: 28px; border-radius: var(--radius); }
.demo-modal-box h2 { margin-bottom: 12px; }
.demo-modal-box p { margin-bottom: 20px; line-height: 1.5; color: #555; }

.placeholder { padding: 60px 20px; text-align: center; color: #888; }

/* ===== Счётчик в сайдбаре ===== */
.badge { margin-left: auto; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent); color: #fff; font-size: 0.75rem; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.admin-sidebar li.active .badge { background: #ffffff33; }
.admin-sidebar:not(:hover) .badge { margin-left: 0; }

/* ===== Статусы ===== */
.chip-new { background: #fef3c7; color: #92400e; }
.chip-inwork { background: #dbeafe; color: #1d4ed8; }
.chip-closed { background: #eee; color: #777; }

/* ===== Форма на сайте ===== */
.site-booking-title { margin: 44px 0 18px; }
.site-form { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.site-form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.site-form label { font-size: 0.9rem; color: #555; }
.site-form input { display: block; width: 100%; margin-top: 6px; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius); font: inherit; background: var(--bg); color: var(--text); }
.site-form-note { margin-top: 14px; color: var(--accent); font-size: 0.9rem; min-height: 1.2em; }

/* ===== Карточка заявки ===== */
.request-card h3 { margin: 20px 0 12px; font-size: 1rem; }
.req-text { margin: 16px 0 4px; padding: 14px 16px; background: var(--bg); border-radius: var(--radius); line-height: 1.5; }
.status-buttons { display: flex; gap: 10px; flex-wrap: wrap; }
.cell-clip { max-width: 320px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #666; }
.form-hint { color: #888; font-size: 0.85rem; margin-top: 4px; }

/* ===== Дашборд ===== */
.dash-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; margin-bottom: 26px; }
.dash-card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px; }
.dash-num { font-size: 2.2rem; font-weight: 700; color: var(--accent); }
.dash-label { color: #777; font-size: 0.9rem; margin-top: 4px; }
.dash-panel { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.dash-panel h3 { margin-bottom: 14px; font-size: 1rem; }
.dash-panel .pages-table { border: none; }

/* Кнопка сброса на тёмной верхней панели */
.topbar .btn-reset { background: transparent; border-color: #ffffff33; color: #ffffffaa; margin-right: 4px; }
.topbar .btn-reset:hover { color: #fff; border-color: #ffffff66; background: #ffffff14; }

/* ===== Дашборд: график и топ блюд ===== */
.dash-grid { display: grid; grid-template-columns: 1.2fr 1fr; gap: 18px; margin-bottom: 26px; }
.week-chart { width: 100%; max-width: 420px; }
.topdish { display: flex; align-items: center; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--border); }
.topdish:last-child { border-bottom: none; }
.td-ico { display: inline-flex; color: var(--accent); }
.td-ico svg { width: 20px; height: 20px; }
.td-name { min-width: 110px; font-weight: 600; font-size: 0.95rem; }
.td-bar { flex: 1; height: 8px; background: var(--border); border-radius: 999px; overflow: hidden; }
.td-bar span { display: block; height: 100%; background: var(--accent); border-radius: 999px; }
.td-num { font-weight: 700; color: var(--accent); min-width: 28px; text-align: right; }
/* ===== АДАПТИВ ДЛЯ МОБИЛЬНЫХ (до 768px) ===== */
@media (max-width: 768px) {
    .demo-modal-box { max-width: 95vw; }
    .topbar { flex-wrap: wrap; justify-content: center; }
    .mode-switch { margin: 0; }
}
/* ===== Адаптив админки ===== */
@media (max-width: 768px) {
    /* Ключ: разрешаем контенту сжиматься */
    .admin-content { min-width: 0; }

    /* Таблицы скроллятся внутри контейнера, а не раздвигают страницу */
    .pages-wrap { padding: 16px; overflow-x: auto; }
    .dash-panel { overflow-x: auto; }
    .pages-table { min-width: 560px; }

    /* Гриды в одну колонку */
    .dash-cards { grid-template-columns: 1fr; }
    .dash-grid { grid-template-columns: 1fr; }
    .edit-columns { grid-template-columns: 1fr; }
    .site-form-row { grid-template-columns: 1fr; }

    /* Компактные отступы */
    .admin-titlebar, .edit-header, .tabs, .edit-body, .action-bar { padding-left: 16px; padding-right: 16px; }
    .dash-card { padding: 16px; }
    .dash-num { font-size: 1.8rem; }

    /* Мета-строки друг под другом */
    .meta-row { flex-direction: column; gap: 2px; }
    .meta-row .k { min-width: 0; }
    .cell-clip { max-width: 200px; }
}

/* На сенсорных экранах сайдбар не разворачивается по тапу */
@media (max-width: 768px) and (hover: none) {
    .admin-sidebar:hover { width: 56px; }
    .admin-sidebar:hover .label { opacity: 0; }
}
/* ===== Мобильные таблицы: ужимаем в экран вместо скролла ===== */
@media (max-width: 768px) {
    .pages-table { min-width: 0; width: 100%; font-size: 0.8rem; }
    .pages-table th, .pages-table td { padding: 7px 6px; white-space: normal; }

    /* «Страницы» (4 колонки): прячем «Тип» и «Обновлено» */
    .pages-wrap .pages-table:has(th:last-child:nth-child(4)) :is(th, td):nth-child(2),
    .pages-wrap .pages-table:has(th:last-child:nth-child(4)) :is(th, td):nth-child(3) { display: none; }

    /* «Заявки» и «Бронирования» (5 колонок): прячем 3-ю («Телефон» / «Гостей») */
    .pages-wrap .pages-table:has(th:last-child:nth-child(5)) :is(th, td):nth-child(3) { display: none; }

    /* «Сообщение» — обрезаем многоточием */
    .cell-clip { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
    .dash-panel .pages-table td:nth-child(3) { max-width: 110px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* ===== Таблицы: все колонки на месте + видимый скролл ===== */
@media (max-width: 768px) {
    /* отменяем скрытие колонок из прошлого блока */
    .pages-wrap .pages-table:has(th:last-child:nth-child(4)) :is(th, td):nth-child(2),
    .pages-wrap .pages-table:has(th:last-child:nth-child(4)) :is(th, td):nth-child(3),
    .pages-wrap .pages-table:has(th:last-child:nth-child(5)) :is(th, td):nth-child(3) { display: table-cell; }

    /* скролл всегда внутри контейнера */
    .pages-wrap, .dash-panel { overflow-x: auto; -webkit-overflow-scrolling: touch; }

    /* тени по краям — сигнал «таблицу можно листать» */
    .pages-wrap, .dash-panel {
        background-image:
            linear-gradient(to right, rgba(90, 90, 90, 0.35), rgba(90, 90, 90, 0)),
            linear-gradient(to left, rgba(90, 90, 90, 0.35), rgba(90, 90, 90, 0));
        background-position: 0 0, 100% 0;
        background-repeat: no-repeat;
        background-size: 14px 100%;
    }

    /* тонкий скроллбар в цвет акцента */
    .pages-wrap::-webkit-scrollbar, .dash-panel::-webkit-scrollbar { height: 5px; }
    .pages-wrap::-webkit-scrollbar-thumb, .dash-panel::-webkit-scrollbar-thumb { background: var(--accent); border-radius: 3px; }
    .pages-wrap::-webkit-scrollbar-track, .dash-panel::-webkit-scrollbar-track { background: transparent; }
}

/* ===== Мобильная правка: формы и вкладки помещаются в экран ===== */
@media (max-width: 768px) {
    /* вкладки переносятся, а не уезжают за край */
    .tabs { flex-wrap: wrap; overflow-x: auto; }
    .tab { white-space: nowrap; }

    /* хлебные крошки переносятся */
    .breadcrumbs { flex-wrap: wrap; }

    /* контейнеры форм не шире экрана */
    .edit-body, .action-bar, .dish-form, .site-form, .request-card { min-width: 0; max-width: 100%; }

    /* поля ввода — во всю ширину карточки */
    .dish-form input, .dish-form textarea, .dish-form select,
    .site-form input, .site-form textarea, .site-form select,
    .request-card input, .request-card textarea, .request-card select { width: 100%; max-width: 100%; box-sizing: border-box; }

    /* нижняя панель с кнопками: скроллится, если кнопок много */
    .action-bar { overflow-x: auto; justify-content: flex-start; }

    /* кнопки статусов заявки переносятся */
    .status-buttons { flex-wrap: wrap; }
}

/* ===== Мобильная правка: нижняя панель кнопок в столбик ===== */
@media (max-width: 768px) {
    .action-bar { flex-direction: column; align-items: stretch; gap: 10px; overflow-x: visible; }
    .action-bar .btn { width: 100%; box-sizing: border-box; }
    .action-bar .demo-note { width: 100%; box-sizing: border-box; }
}

/* ===== Мобильная правка: шапка редактирования и кнопки ===== */
@media (max-width: 768px) {
    /* шапка редактирования — столбиком: крошки / статус / вкладки */
    .edit-header { flex-direction: column !important; align-items: stretch !important; gap: 10px; }
    .edit-header-actions { display: flex; flex-wrap: wrap; gap: 8px; }

    /* вкладки — явный флекс с переносом, не уезжают за край */
    .tabs { display: flex; flex-wrap: wrap; gap: 4px; overflow-x: visible; }
    .tab { white-space: nowrap; }

    /* панель внизу: примечание сверху, кнопки друг под другом на всю ширину */
    .action-bar { display: flex !important; flex-direction: column !important; align-items: stretch !important; gap: 10px; overflow-x: visible; }
    .action-bar .btn { width: 100% !important; flex: 1 1 100%; box-sizing: border-box; }
    .action-bar .demo-note { width: 100%; box-sizing: border-box; }
}

