/* Restaurant AI — оформление управленческого продукта.
 *
 * Три решения определяют вид.
 *
 * Спокойный фон и один акцент. Интерфейс, где всё выделено, не
 * выделяет ничего; владелец должен за секунду находить то, что
 * требует внимания, а не разбирать палитру.
 *
 * Цвет только семантический. Красный означает «требует внимания»,
 * зелёный — «выше обычного», и больше нигде они не появляются.
 * Поэтому красная строка в списке действительно что-то значит.
 *
 * Тёмная тема наравне со светлой. Telegram открывается в обеих, и
 * приложение, светящееся белым внутри тёмного клиента, выглядит
 * чужим. Цвета заданы переменными и переключаются целиком.
 */

:root {
  color-scheme: light dark;

  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e3e6ea;
  --text: #14171a;
  --text-dim: #5b6472;
  --text-faint: #8b95a3;

  /* Акцент — глубокий сине-зелёный: деловой, не «корпоративно-синий». */
  --accent: #1f6f6b;
  --accent-soft: #e6f2f1;

  /* Семантика. Используются ТОЛЬКО по назначению. */
  --critical: #b3261e;
  --critical-soft: #fceceb;
  --warning: #8a5a00;
  --warning-soft: #fdf3e2;
  --positive: #1f6b3a;
  --positive-soft: #e9f4ed;

  --radius: 14px;
  --radius-sm: 9px;
  --gap: 16px;
  --shadow: 0 1px 2px rgba(20, 23, 26, .04), 0 8px 24px rgba(20, 23, 26, .06);

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
          "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1216;
    --surface: #171b21;
    --surface-2: #1f242c;
    --border: #272d36;
    --text: #eef1f5;
    --text-dim: #9aa5b4;
    --text-faint: #6b7684;
    --accent: #4fb3ac;
    --accent-soft: #16302f;
    --critical: #ef6a61;
    --critical-soft: #2a1817;
    --warning: #dda63a;
    --warning-soft: #2a2317;
    --positive: #5fbd84;
    --positive-soft: #16261c;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .35);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* Safe area: в Telegram снизу «шторка», и кнопки не должны под неё уезжать. */
body {
  padding-bottom: env(safe-area-inset-bottom);
}

.app { min-height: 100vh; }

/* ============================================================ НАВИГАЦИЯ
 * Мобильно — снизу, как в приложении. На широком экране — слева
 * колонкой: на десктопе горизонтальная полоса внизу выглядит
 * чужеродно, а место по бокам есть. */
.nav {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  display: flex;
  justify-content: space-around;
  background: var(--surface);
  border-top: 1px solid var(--border);
  padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
  z-index: 20;
}

.nav__item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 6px 2px;
  border: 0;
  background: none;
  color: var(--text-faint);
  font: inherit;
  font-size: 11px;
  cursor: pointer;
  border-radius: var(--radius-sm);
  /* 44px — минимальная площадь касания, ниже промахиваются пальцем. */
  min-height: 44px;
}

.nav__item[aria-current="page"] { color: var(--accent); }
.nav__icon { font-size: 18px; line-height: 1; }
.nav__badge {
  position: absolute;
  transform: translate(14px, -6px);
  background: var(--critical);
  color: #fff;
  font-size: 10px;
  font-weight: 600;
  min-width: 16px;
  height: 16px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  padding: 0 4px;
}

.main {
  padding: 16px 16px 88px;
  max-width: 760px;
  margin: 0 auto;
}

@media (min-width: 900px) {
  .app { display: grid; grid-template-columns: 232px 1fr; }
  .nav {
    position: sticky;
    top: 0;
    height: 100vh;
    flex-direction: column;
    justify-content: flex-start;
    gap: 2px;
    padding: 20px 12px;
    border-top: 0;
    border-right: 1px solid var(--border);
  }
  .nav__item {
    flex: 0 0 auto;
    flex-direction: row;
    justify-content: flex-start;
    gap: 12px;
    font-size: 15px;
    padding: 10px 12px;
    width: 100%;
  }
  .nav__item[aria-current="page"] { background: var(--accent-soft); }
  .nav__icon { font-size: 17px; }
  .nav__badge { position: static; transform: none; margin-left: auto; }
  .main { padding: 28px 32px 40px; max-width: 1080px; margin: 0; }
}

/* ================================================================ ШАПКА */
.header { margin-bottom: 20px; }
.header__row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.header h1 { margin: 0; font-size: 22px; font-weight: 650; letter-spacing: -.01em; }
.header__sub { color: var(--text-dim); font-size: 14px; margin-top: 2px; }

/* Переключатель периода. Сегментный контрол читается быстрее
 * выпадающего списка: все варианты видны сразу. */
.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 3px;
  gap: 2px;
}
.segmented button {
  border: 0;
  background: none;
  font: inherit;
  font-size: 14px;
  color: var(--text-dim);
  padding: 7px 14px;
  border-radius: 7px;
  cursor: pointer;
  min-height: 38px;
}
.segmented button[aria-pressed="true"] {
  background: var(--surface);
  color: var(--text);
  font-weight: 550;
  box-shadow: 0 1px 2px rgba(0,0,0,.06);
}

.select {
  font: inherit;
  font-size: 14px;
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-height: 40px;
}

/* ================================================================ КАРТЫ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: var(--gap);
  box-shadow: var(--shadow);
}
.card__title {
  font-size: 13px;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
  color: var(--text-faint);
  margin: 0 0 12px;
}

.metrics { display: grid; gap: 10px; grid-template-columns: 1fr 1fr; }
@media (min-width: 720px) { .metrics { grid-template-columns: repeat(4, 1fr); } }

.metric {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
}
.metric__title { font-size: 13px; color: var(--text-dim); }
.metric__value {
  font-size: 24px;
  font-weight: 650;
  letter-spacing: -.02em;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
}
@media (min-width: 720px) { .metric__value { font-size: 27px; } }
.metric__change { font-size: 13px; margin-top: 4px; font-variant-numeric: tabular-nums; }
.metric__expected { font-size: 12px; color: var(--text-faint); margin-top: 6px; }

.up { color: var(--positive); }
.down { color: var(--critical); }
.flat { color: var(--text-faint); }

/* ============================================================= СТАТУСЫ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  font-weight: 550;
  padding: 3px 9px;
  border-radius: 20px;
  background: var(--surface-2);
  color: var(--text-dim);
  white-space: nowrap;
}
.badge--critical { background: var(--critical-soft); color: var(--critical); }
.badge--warning  { background: var(--warning-soft);  color: var(--warning); }
.badge--positive { background: var(--positive-soft); color: var(--positive); }
.badge--accent   { background: var(--accent-soft);   color: var(--accent); }

.freshness {
  font-size: 13px;
  color: var(--text-faint);
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
}
.freshness--stale { color: var(--warning); }

/* ============================================================== СПИСКИ */
.list { display: flex; flex-direction: column; gap: 10px; }

.row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  width: 100%;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  font: inherit;
  color: inherit;
  cursor: pointer;
  min-height: 44px;
}
.row:hover { border-color: var(--accent); }
.row__body { flex: 1; min-width: 0; }
.row__title { font-weight: 550; }
.row__meta {
  font-size: 13px;
  color: var(--text-dim);
  margin-top: 3px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}
/* Полоса слева — не декор: она кодирует важность и видна боковым
 * зрением при пролистывании списка. */
.row--critical { border-left: 3px solid var(--critical); }
.row--warning  { border-left: 3px solid var(--warning); }
.row--positive { border-left: 3px solid var(--positive); }

/* ============================================================= КНОПКИ */
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

.btn {
  font: inherit;
  font-size: 15px;
  padding: 10px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  min-height: 44px;
}
.btn:hover { border-color: var(--accent); }
.btn--primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
  font-weight: 550;
}
.btn--ghost { background: none; border-color: transparent; color: var(--accent); }
.btn:disabled { opacity: .5; cursor: default; }

/* =============================================================== БЛОКИ */
.section { margin-bottom: 24px; }
.section__head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section__head h2 { font-size: 17px; font-weight: 600; margin: 0; }

.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 14px; font-size: 15px; }
.kv dt { color: var(--text-dim); }
.kv dd { margin: 0; font-variant-numeric: tabular-nums; }

.prose { font-size: 15px; line-height: 1.6; }
.prose p { margin: 0 0 10px; }
.prose ul { margin: 0 0 10px; padding-left: 20px; }
.prose li { margin-bottom: 4px; }

/* Блок ответа AI. Отделён рамкой намеренно: читатель должен видеть,
 * где кончается измеренное системой и начинается объяснение модели. */
.ai {
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 14px;
  background: var(--surface);
}
.ai__label {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--accent);
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  gap: 8px;
  align-items: center;
}
.ai__group { margin-top: 12px; }
.ai__group h4 {
  font-size: 13px;
  color: var(--text-dim);
  margin: 0 0 5px;
  font-weight: 600;
}

/* =========================================================== СОСТОЯНИЯ
 * Пять состояний экрана, и ни одно не является белым пустым полем:
 * пустой экран читается как поломка. */
.state {
  padding: 32px 16px;
  text-align: center;
  color: var(--text-dim);
  font-size: 15px;
}
.state--error { color: var(--critical); }
.state--empty { color: var(--text-faint); }

.skeleton {
  background: linear-gradient(90deg, var(--surface-2) 25%,
                              var(--border) 37%, var(--surface-2) 63%);
  background-size: 400% 100%;
  animation: shimmer 1.4s ease infinite;
  border-radius: var(--radius);
  height: 78px;
  margin-bottom: 10px;
}
@keyframes shimmer {
  0% { background-position: 100% 50%; }
  100% { background-position: 0 50%; }
}
@media (prefers-reduced-motion: reduce) {
  .skeleton { animation: none; }
}

/* ============================================================ ГРАФИКИ */
.chart { width: 100%; overflow-x: auto; }
.chart svg { display: block; width: 100%; height: auto; }
.chart__legend {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 8px;
  flex-wrap: wrap;
}
.chart__key { display: inline-flex; align-items: center; gap: 5px; }
.chart__swatch { width: 11px; height: 11px; border-radius: 3px; }

/* ============================================================ АССИСТЕНТ */
.chat { display: flex; flex-direction: column; gap: 12px; margin-bottom: 16px; }
.msg { max-width: 88%; padding: 11px 14px; border-radius: var(--radius); font-size: 15px; }
.msg--user {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg--assistant {
  align-self: flex-start;
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

.composer { display: flex; gap: 8px; align-items: flex-end; }
.composer textarea {
  flex: 1;
  font: inherit;
  font-size: 16px;   /* меньше 16px — iOS зумит страницу при фокусе */
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  resize: none;
  min-height: 44px;
  max-height: 140px;
}
.suggestions { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px; }
.suggestion {
  font: inherit;
  font-size: 14px;
  padding: 8px 13px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-dim);
  cursor: pointer;
  min-height: 40px;
}
.suggestion:hover { border-color: var(--accent); color: var(--accent); }

.thinking { display: flex; align-items: center; gap: 9px; color: var(--text-dim); font-size: 15px; }
.thinking__dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent);
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { opacity: .3; } 50% { opacity: 1; } }
@media (prefers-reduced-motion: reduce) {
  .thinking__dot { animation: none; opacity: .7; }
}

.hint { font-size: 13px; color: var(--text-faint); margin-top: 8px; }
.mono { font-family: var(--mono); font-size: 13px; }

/* ==================================================== ДОБАВЛЕНО В MVP (B)
 * Пять вкладок, произвольный период, экраны прибыли, ресторанов и
 * управления доступом. Ни одного нового цвета: палитра та же, иначе
 * «красное» перестанет означать одно и то же по всему приложению.
 */

/* Подпись вкладки. На узких экранах названия из двух слов ломались бы
 * в две строки и разъезжались по высоте — поэтому одна строка. */
.nav__label {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* ------------------------------------------------------------- ПЕРИОД */
.periods { display: flex; flex-direction: column; gap: 10px; }

/* Поля дат скрыты, пока не выбран «Свой»: четыре кнопки и два
 * календаря одновременно — это шум на каждом экране ради операции,
 * которую делают редко. */
.periods__range { display: none; align-items: center; gap: 8px; flex-wrap: wrap; }
.periods--open .periods__range { display: flex; }

.segmented--wrap { display: flex; flex-wrap: wrap; }

/* --------------------------------------------------------------- ПОЛЯ */
.input {
  font: inherit;
  font-size: 15px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  min-height: 40px;
  min-width: 0;
}
.input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.input--date { flex: 1 1 130px; }

.form__row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.form__row .input { flex: 1 1 160px; }

/* -------------------------------------------------------------- КНОПКИ */
.btn--small { padding: 7px 12px; font-size: 14px; min-height: 38px; }

/* Удаление доступа — единственное необратимое действие в интерфейсе,
 * и выглядеть оно должно соответственно. Подтверждение — вторым
 * нажатием той же кнопки, а не модальным окном: окно в Telegram
 * WebView перекрывает половину экрана. */
.btn--danger { color: var(--critical); border-color: var(--critical); }

/* Быстрые переходы под четырьмя числами главной. */
.quick { display: flex; gap: 8px; flex-wrap: wrap; margin: 4px 0 4px; }

/* -------------------------------------------------------------- СТРОКИ */
/* Выбранное — акцентом слева, а не заливкой: заливка конкурирует с
 * семантическими цветами строк «требует внимания». */
.row--selected { border-left: 3px solid var(--accent); }

/* Приглушённая строка — раздел без источника или приостановленный
 * доступ. Не спрятана: пропавшая строка читается как «этого нет». */
.row--muted { opacity: .62; }

/* --------------------------------------------------- ПАРЫ КЛЮЧ-ЗНАЧЕНИЕ */
.kv__key { color: var(--text-dim); }
.kv__value { font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- СНОСКИ */
.hint--boxed {
  background: var(--surface-2);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-top: 12px;
}
.hint--error { color: var(--critical); }
