:root {
  --bg: #ffffff;
  --text: #000000;
  --hint: #707579;
  --button: #3390ec;
  --button-text: #ffffff;
  --link: #3390ec;
  --secondary: #f0f0f0;
  --card: #f7f7f8;
  --border: #e1e1e1;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 15px;
  line-height: 1.35;
  -webkit-tap-highlight-color: transparent;
}

.app-header {
  padding: 14px 16px 8px;
}
.app-header h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
}

.tabs {
  display: flex;
  gap: 4px;
  padding: 0 12px 10px;
  overflow-x: auto;
}
.tab-btn {
  flex: 1;
  min-width: 0;
  padding: 8px 6px;
  border: none;
  border-radius: 10px;
  background: var(--secondary);
  color: var(--text);
  font-size: 19px;
  font-weight: 500;
  cursor: pointer;
  white-space: nowrap;
}
.tab-btn.active {
  background: var(--button);
  color: var(--button-text);
}

main {
  padding: 0 12px 12px;
}

.tab { display: none; }
.tab.active { display: block; }

.datebar {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}
.date-input-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}
.datebar input[type="date"] {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: transparent;
  -webkit-text-fill-color: transparent;
  font-size: 15px;
}
.date-display {
  position: absolute;
  left: 9px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text);
  font-size: 15px;
  pointer-events: none;
  white-space: nowrap;
}
.icon-btn {
  width: 36px;
  height: 36px;
  border: none;
  border-radius: 10px;
  background: var(--secondary);
  color: var(--text);
  font-size: 20px;
  cursor: pointer;
}
.btn {
  padding: 9px 14px;
  border: none;
  border-radius: 10px;
  background: var(--button);
  color: var(--button-text);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
}
.btn.small { padding: 8px 10px; }
.mode-btn { background: var(--secondary); color: var(--text); }
.btn.active, .mode-btn.active { background: var(--button); color: var(--button-text); }

.period-bar { display: flex; align-items: center; gap: 6px; }
.period-label { flex: 1; text-align: center; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.month-input {
  flex: 1;
  min-width: 0;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--card);
  color: var(--text);
  font-size: 15px;
}

.toolbar { margin-bottom: 10px; }

/* Подразделы внутри раздела (например, «Цифры» / «Столы» в «Еде»). */
.sub-tabs { display: flex; gap: 6px; margin-bottom: 10px; }
.sub-tabs .mode-btn { flex: 1; }
/* Логотип Ziamo (белый) в кнопке подраздела: в светлой теме инвертируем. */
.zi-logo {
  max-height: 18px;
  max-width: 100%;
  width: auto;
  height: auto;
  vertical-align: middle;
}
body:not(.dark) .zi-logo { filter: invert(1); }

/* Блоки сводки «Ziamo»: 4 части (выручка / чеки-гости / вино / коктейли). */
.zi-block { margin-bottom: 8px; }
.zi-title {
  color: var(--text);
  font-weight: 700;
  font-size: 14px;
}
/* Ziamo: выделенные заголовки карточек (как шапки таблиц «Загрузки»:
   свой цвет + горизонтальная линия). */
#foodContent .zi-block thead th {
  background: #f1e9fb;
  color: #5b2d90;
  border-bottom: 2px solid #a97fe0;
}
/* Строка «Общая выручка»: первая, крупнее и жирным. */
#foodContent .zi-block tr.zi-total td {
  font-weight: 700;
  font-size: 16px;
}

/* Текст-заглушка (например, пустая страница «Статистика»). */
.hint { color: var(--hint); text-align: center; padding: 28px 0; font-size: 14px; }

.content { min-height: 60px; }

.loading {
  color: var(--hint);
  text-align: center;
  padding: 24px 0;
}
.error {
  color: #e5484d;
  text-align: center;
  padding: 24px 0;
}

.card {
  background: var(--card);
  border-radius: 12px;
  padding: 4px 6px;
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}
th, td {
  padding: 8px 6px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th {
  color: var(--hint);
  font-weight: 500;
  font-size: 13px;
}
td.num { text-align: right; }
th.num { text-align: right; }
tr:last-child td { border-bottom: none; }

/* Итоговая строка таблиц «Подробно» */
.total-row td {
  font-weight: 700;
  border-top: 2px solid var(--border);
  border-bottom: none;
  background: var(--secondary);
  color: var(--text);
}

.actuality {
  margin-top: 10px;
  color: var(--hint);
  font-size: 13px;
  text-align: center;
}

.section-title { font-weight: 700; margin: 2px 0 6px; }
.section-sub { color: var(--hint); font-size: 13px; margin-bottom: 8px; }

/* Заголовок раздела над кнопками управления (с отступом от меню вкладок). */
.tab-title { margin: 16px 4px 0; font-size: 17px; font-weight: 700; }
.tab-title .section-sub { margin-bottom: 0; }

.chart-box { margin-top: 8px; background: var(--card); border-radius: 12px; padding: 8px 4px; }
.chart-box svg { width: 100%; height: auto; display: block; }
.chart-title { color: var(--hint); font-size: 13px; margin: 14px 0 4px; text-align: center; }

/* Полноэкранный просмотр графика (тап по графику) */
.chart-zoomable { cursor: pointer; }
.chart-hint { margin: 3px 0 8px; color: var(--hint); font-size: 11px; text-align: center; }
.chart-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(0, 0, 0, 0.88);
  display: flex; align-items: center; justify-content: center;
  padding: 52px 8px 24px;
}
.chart-overlay-inner {
  width: 100%; max-width: 760px;
  touch-action: none;
  transform-origin: 0 0;
  will-change: transform;
  user-select: none;
  -webkit-user-select: none;
  cursor: grab;
}
.chart-overlay .chart-box {
  width: 100%;
  background: var(--bg);
  border-radius: 12px;
  padding: 10px;
  pointer-events: none;
}
.chart-overlay-controls {
  position: fixed; top: 8px; left: 0; right: 0;
  display: flex; justify-content: center; gap: 10px; z-index: 101;
}
.chart-overlay-controls button {
  border: none; border-radius: 10px; min-width: 44px; height: 36px;
  background: rgba(255, 255, 255, 0.16);
  color: #fff; font-size: 17px; cursor: pointer; padding: 0 12px;
}
.chart-overlay-controls button[disabled] { opacity: 0.7; font-size: 13px; }
.chart-overlay-tip {
  position: fixed; bottom: 8px; left: 0; right: 0; z-index: 101;
  text-align: center; color: rgba(255, 255, 255, 0.6);
  font-size: 12px; pointer-events: none;
}

.stats-line { margin-top: 8px; font-size: 13px; color: var(--hint); text-align: center; }

.food-hint {
  margin-top: 4px;
  color: var(--hint);
  font-size: 12px;
  text-align: center;
}

/* Раздел «Столы» (Restoplace): сетка столов, сводка и карточки броней */
.tables-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(46px, 1fr));
  gap: 6px;
  margin: 0 0 14px;
}
.tbl-chip {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 40px;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
}
/* Три состояния стола: свободен (зелёный) / резерв (жёлтый) / занят (красный). */
.tbl-chip.tbl-free {
  background: #e6f7ec;
  color: #18794e;
  border: 1px solid #b5e2c7;
}
.tbl-chip.tbl-reserved {
  background: #fff3cd;
  color: #8a6d00;
  border: 1px solid #e7cf7a;
}
.tbl-chip.tbl-occupied {
  background: #e5484d;
  color: #ffffff;
  border: 1px solid #c93a3f;
  font-weight: 700;
}
.tbl-summary {
  margin: 2px 0 12px;
  text-align: center;
  font-size: 14px;
  font-weight: 600;
}
.tbl-summary .free { color: #18794e; }
.tbl-summary .reserved { color: #b07d00; }
.tbl-summary .occupied { color: #e5484d; }

.rsv-card {
  background: var(--card);
  border-radius: 10px;
  padding: 8px 10px;
  margin-bottom: 8px;
}
.rsv-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}
.rsv-time { font-weight: 700; font-variant-numeric: tabular-nums; }
.rsv-table { color: var(--hint); font-size: 13px; }
.rsv-guest { margin-top: 3px; font-size: 13px; }
.rsv-badge {
  display: inline-block;
  padding: 1px 8px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
}
.rsv-badge.rsv-occupied { background: #fdeaea; color: #c53030; }
.rsv-badge.rsv-reserved { background: #fff3cd; color: #8a6d00; }

/* Тост-уведомление (тап по занятому столу) */
.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%) translateY(16px);
  max-width: 86%;
  padding: 10px 16px;
  border-radius: 12px;
  background: rgba(30, 30, 30, 0.92);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease, transform 0.2s ease;
  z-index: 200;
}
.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

/* Неактивная кнопка навигации (например «‹» на сегодняшней дате) */
.icon-btn:disabled {
  opacity: 0.35;
  cursor: default;
}

.total {
  margin-top: 10px;
  font-weight: 700;
  text-align: right;
}

/* Статусы номеров (таблица «Номера» в разделе «День») */
.status-занят { color: #e5484d; font-weight: 600; }
.status-свободен { color: #2aab6e; font-weight: 600; }
.status-забронирован { color: #3390ec; font-weight: 600; }
.status-ремонт { color: #8e8e93; }
.status-удержание { color: #f5a623; }

/* Раздел «Загрузка»: метка прогноза и таблицы прогнозных дней */
.forecast-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 8px;
  border-radius: 8px;
  background: #fff3cd;
  color: #8a6d00;
  font-size: 12px;
  font-weight: 600;
  vertical-align: middle;
}
.forecast-title { color: #8a6d00; font-weight: 700; }
/* Единый дизайн ВСЕХ таблиц раздела «Загрузка» — как у «Прогноз по дням»:
   тёплый фон, золотистая пунктирная рамка, выделенная шапка. */
#loadContent .card,
.forecast-card {
  background: #fffdf2;
  border: 1.5px dashed #d9b94a;
}
#loadContent .card thead th,
.forecast-card thead th {
  background: #f3e3a3;
  color: #6b5200;
  font-weight: 700;
  border-bottom: 2px solid #d9b94a;
}
#loadContent .card td,
.forecast-card td { color: #4a3800; }
#loadContent .card tr:last-child td,
.forecast-card tr:last-child td { border-bottom: none; }
#loadContent .total-row td,
.forecast-card .total-row td {
  background: #f3e3a3;
  color: #4a3800;
  border-top: 2px solid #d9b94a;
}
/* Строки «Итого» и «ADR» в модуле «Доход»: жирнее и крупнее. */
#loadContent .card tr.row-emph td {
  font-weight: 700;
  font-size: 16px;
}

/* Раздел «СПА»: единый дизайн таблиц — как у «Загрузки», но в бирюзовой гамме. */
#spaContent .card {
  background: #f2fbfa;
  border: 1.5px dashed #34bfb3;
}
#spaContent .card thead th {
  background: #d2efec;
  color: #0c5e57;
  font-weight: 700;
  border-bottom: 2px solid #34bfb3;
}
#spaContent .card td { color: #12423e; }
#spaContent .card tr:last-child td { border-bottom: none; }
#spaContent .total-row td {
  background: #d2efec;
  color: #12423e;
  border-top: 2px solid #34bfb3;
}

/* Вторичные таблицы СПА («По типу оплаты», «Мастера», «Выручка по дням») —
   на строку ниже относительно таблицы/графиков выше. */
#spaContent .section-title { margin: 16px 0 6px; }

/* Вложенные строки под «Оплаты» (Выручка / Продажа по сертификатам). */
#spaContent tr.sub td:first-child { padding-left: 18px; }

/* Баннер «открыто не из Telegram» */
/* -------------------------------------------------------------------------
   Проверка доступа при запуске: пока доступ не подтверждён, приложение
   (шапка, меню, разделы, футер) не показывается вообще — только экран
   проверки/ошибки.
   ------------------------------------------------------------------------- */
body.access-checking .app-header,
body.access-checking .tabs,
body.access-checking main,
body.access-checking .app-footer {
  display: none !important;
}

#access-screen {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg);
}

.access-card {
  max-width: 340px;
  text-align: center;
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
}

.access-card .btn {
  margin-top: 16px;
}

.hidden { display: none !important; }

/* «Выбор зала» (раздел «Еда → Столы»): оверлей + список залов с галками. */
.halls-overlay {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding: 12px;
  background: rgba(0, 0, 0, 0.45);
}
.halls-panel {
  width: 100%;
  max-width: 420px;
  max-height: 80vh;
  display: flex;
  flex-direction: column;
  padding: 12px;
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
}
.halls-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
  font-size: 15px;
  font-weight: 600;
}
.halls-list {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 2px 0;
}
.hall-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 4px;
  border-bottom: 1px solid var(--border);
  font-size: 15px;
  cursor: pointer;
}
.hall-item:last-child { border-bottom: none; }
.hall-item input[type="checkbox"] {
  width: 20px;
  height: 20px;
  margin: 0;
  accent-color: var(--button);
  flex: none;
}
.halls-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}
.halls-actions .btn { flex: 1; }

/* Предупреждение о неполных данных периода (раздел «Загрузка») */
.load-warn {
  margin: 4px 0 8px;
  padding: 6px 10px;
  border-radius: 8px;
  background: #fff3cd;
  color: #8a6d00;
  font-size: 13px;
}

.app-footer {
  padding: 16px 12px 24px;
  color: var(--text);
  font-size: 12px;
  text-align: center;
}
.app-version {
  color: var(--hint);
}
.app-devby {
  opacity: 0.05;
}
