/* Оболочка экрана MateGlobal (флаг nav_shell). Устройство – как у Endless (нижнее меню, круг «Меню» с листом,
   меню слева, точки перелома ≤ 860 / ≥ 861 px, уроки ~/endless-ref/ui/УРОКИ.md), а вид – свой: палитра MateGlobal
   (app.css), свои значки (_shell_icons.html). Владелец 28.11: бренд Endless с проектом не смешивать. */

/* Отступы под меню – по классу shell-on на <body> (base.html: флаг и вход), не :has(): Safari ниже 15.4 его не знает,
   и последняя строка уходила бы под меню (Ревизор 2, 28.11). :has() – только там, где без него просто прежний вид. */

/* ---------- тема MateGlobal: тёмно-синий (#1f3a5f) на светлом, голубой (#8fb3e0) на тёмном – цвета app.css.
   data-theme="dark|light" на <html> (theme.js), без него – как у системы */
html.shell {
  --bg: #f5f7fa; --bg-2: #ffffff; --card: #ffffff; --line: rgba(27,36,48,.12);
  --text: #1b2430; --muted: #5d6b7a; --brand: #1f3a5f; --brand-soft: rgba(31,58,95,.1);
  --primary-bg: #1f3a5f; --primary-fg: #ffffff; --err: #b3261e; --shadow: 0 1px 3px rgba(0,0,0,.08);
  --ink: var(--text); --accent: var(--brand);
  --shell-side: 232px; --shell-bar: 68px;
  color-scheme: light;
}
html.shell[data-theme="dark"] {
  --bg: #11161c; --bg-2: #1a212a; --card: #1a212a; --line: rgba(230,235,241,.12);
  --text: #e6ebf1; --muted: #9aa7b4; --brand: #8fb3e0; --brand-soft: rgba(143,179,224,.16);
  --primary-bg: #8fb3e0; --primary-fg: #11161c; --err: #f2b8b5; --shadow: 0 1px 3px rgba(0,0,0,.4);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  html.shell:not([data-theme="light"]) {
    --bg: #11161c; --bg-2: #1a212a; --card: #1a212a; --line: rgba(230,235,241,.12);
    --text: #e6ebf1; --muted: #9aa7b4; --brand: #8fb3e0; --brand-soft: rgba(143,179,224,.16);
    --primary-bg: #8fb3e0; --primary-fg: #11161c; --err: #f2b8b5; --shadow: 0 1px 3px rgba(0,0,0,.4);
    color-scheme: dark;
  }
}
html.shell body { background: var(--bg); color: var(--text); }
/* у нас --accent – и цвет ссылок, и фон кнопок с белым текстом: заливка кнопок – пара primary-bg/fg (в тёмной теме
   голубой фон и тёмный текст, иначе белое на голубом не читается) */
html.shell button:not(.link):not(.shell-menu):not(.shell-tile):not(.date-pick):not(.cal-nav),
html.shell .btn, html.shell .bubble.me, html.shell .cal-sel { background: var(--primary-bg); color: var(--primary-fg); }
html.shell .date-pick, html.shell .cal-nav { background: none; color: var(--brand); }
html.shell button.link { color: var(--brand); }
html.shell input, html.shell select, html.shell textarea { background: var(--bg-2); color: var(--text); border-color: var(--line); }

.ico { width: 20px; height: 20px; display: block; }
.shell-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

/* ---------- шапка экрана: название и «Настройки» справа */
.shell-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; min-height: 52px;
  background: var(--bg); border-bottom: 1px solid var(--line); z-index: 30; }
.shell-title { font-size: 20px; font-weight: 700; letter-spacing: -.02em; white-space: nowrap; overflow: hidden;
  text-overflow: ellipsis; min-width: 0; }
.shell-settings { width: 44px; height: 44px; flex: 0 0 auto; border-radius: 12px; display: grid; place-items: center;
  color: var(--brand); border: 1px solid var(--line); background: var(--card); }
.shell-settings .ico { width: 22px; height: 22px; }
.shell-settings.active { background: var(--brand-soft); }

/* ---------- боковое меню (≥ 861 px) */
.shell-side { display: none; }
.shell-nav a, .shell-bottom a { color: var(--muted); font-weight: 500; text-decoration: none; }
.shell-nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; min-height: 44px;
  transition: background-color .15s, color .15s; }
.shell-nav a i, .shell-bottom a i { font-style: normal; opacity: .8; }
.shell-nav a:hover { color: var(--text); background: var(--brand-soft); }
.shell-nav a.active, .shell-bottom a.active { color: var(--brand); background: var(--brand-soft); font-weight: 600; }
.shell-nav a.active i, .shell-bottom a.active i { opacity: 1; }
@media (min-width: 861px) {
  html { scrollbar-gutter: stable; }
  body.shell-on { padding-left: calc(var(--shell-side) + env(safe-area-inset-left)); }
  .shell-side { display: flex; flex-direction: column; gap: 18px; position: fixed; top: 0; bottom: 0;
    left: env(safe-area-inset-left); width: var(--shell-side); padding: 22px 16px; overflow-y: auto; z-index: 35;
    border-right: 1px solid var(--line); background: var(--bg-2); }
  .shell-brand { font-weight: 700; font-size: 17px; letter-spacing: -.01em; color: var(--text); text-decoration: none; padding: 0 12px; }
  .shell-nav { display: flex; flex-direction: column; gap: 4px; }
  .shell-side-foot { margin-top: auto; }
  .shell-logout { color: var(--muted); font-size: 14px; }
  .shell-bottom, .shell-sheet { display: none !important; }
}

/* ---------- телефон (≤ 860 px): нижнее меню – два раздела, круг «Меню», два раздела */
.shell-bottom { display: none; }
@media (max-width: 860px) {
  /* последняя строка прокручивается из-под меню (урок 3): высота меню + безопасная зона снизу */
  body.shell-on { padding-bottom: calc(var(--shell-bottom-h, calc(var(--shell-bar) + env(safe-area-inset-bottom))) + 24px); }
  .shell-bottom { display: flex; justify-content: space-around; align-items: flex-start; position: fixed; bottom: 0;
    left: 0; right: 0; z-index: 40; padding: 6px max(6px, env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom))
    max(6px, env(safe-area-inset-left)); border-top: 1px solid var(--line); background: var(--bg-2); }
  /* полупрозрачная с размытием – только где оба есть (iOS 15: color-mix с var() сбрасывал фон в прозрачный).
     Урок 2: у этого элемента нет выносных потомков – WebKit их обрезал бы */
  @supports ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) and (background: color-mix(in srgb, red 50%, transparent)) {
    .shell-bottom { background: color-mix(in srgb, var(--bg-2) 85%, transparent); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); }
  }
  .shell-bottom a, .shell-menu { flex: 0 0 min(78px, calc((100% - 14px) / 5)); width: min(78px, calc((100% - 14px) / 5));
    min-width: 0; display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 3px;
    padding: 5px 0; border-radius: 12px; font-size: min(11px, 3.05vw); line-height: 14px; white-space: nowrap;
    -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
  .shell-bottom a > span, .shell-menu > span { display: block; text-align: center; max-width: 100%; overflow: hidden; text-overflow: ellipsis; }
  .shell-bottom a i { width: 30px; height: 30px; display: grid; place-items: center; }
  .shell-bottom a i .ico { width: 30px; height: 30px; }
  .shell-bottom a.active { background: none; }
  /* круг 58 + обводка 4 цветом экрана: в разметке те же 30 px, что значок соседей, круг выступает над панелью */
  .shell-menu { border: 0; background: none; color: var(--text); font: inherit; font-size: min(11px, 3.05vw);
    font-weight: 600; cursor: pointer; min-height: 0; }
  .shell-menu i { width: 58px; height: 58px; margin-top: -36px; box-sizing: content-box; border: 4px solid var(--bg);
    border-radius: 50%; display: grid; place-items: center; background: var(--primary-bg); color: var(--primary-fg);
    box-shadow: 0 6px 18px rgba(0,0,0,.18); font-style: normal; }
  .shell-menu i .ico { grid-area: 1 / 1; width: 26px; height: 26px; transition: transform .28s cubic-bezier(.2,.8,.2,1), opacity .2s ease; }
  .shell-menu .m-x { opacity: 0; transform: rotate(-90deg); }
  body.shell-menu-open .shell-menu .m-x { opacity: 1; transform: none; }
  body.shell-menu-open .shell-menu .m-dots { opacity: 0; transform: rotate(90deg); }
  .shell-menu .m-close, body.shell-menu-open .shell-menu .m-open { display: none; }
  body.shell-menu-open .shell-menu .m-close { display: block; }
  body.shell-menu-open .shell-bottom { z-index: 61; background: var(--bg-2); -webkit-backdrop-filter: none; backdrop-filter: none; }
  body.shell-menu-open { overflow: hidden; }
  /* печатаешь – меню прячется (урок 8 Endless: ввод не перекрывать): на Android клавиатура поднимала меню над собой
     и оно съедало место у переписки (LT 28.11); поле агента – к низу */
  body.shell-typing .shell-bottom { display: none; }
  body.shell-on.shell-typing { padding-bottom: env(safe-area-inset-bottom); }
  body.shell-on.shell-typing .chat-form { bottom: 0; }
  /* экран агента: поле ввода – над нижним меню, а не под ним (у формы sticky bottom: 0) */
  /* --shell-bottom-h – настоящая высота нижнего меню (shell.js меряет): на iPhone и Galaxy она 71–76 px, а не 68,
     и поле агента заходило под меню на 7–8 px (LT 28.11). Без JS – расчёт по --shell-bar */
  body.shell-on .chat-form { bottom: var(--shell-bottom-h, calc(var(--shell-bar) + env(safe-area-inset-bottom))); }
  body.shell-on .chat-page { margin-bottom: -24px; }   /* у чата поле ввода само над меню – запас 24 px не нужен */
}
/* экран агента: оболочка вложена в его <header> (шаблон агента не трогаем, _agent_nav.html). Липкая шапка – свой слой:
   без z-index поле ввода (sticky, ниже в разметке) рисовалось поверх круга «Меню»; .top nav { gap } из app.css
   раздвигал кнопки нижнего меню и «Финансы» уходили за край */
html.shell header.top { z-index: 45; }
html.shell .top nav.shell-bottom { gap: 0; }
html.shell .top nav.shell-nav { flex-direction: column; align-items: stretch; gap: 4px; }
html.shell .top .brand { display: none; }   /* «MateGlobal» – в боковом меню; на телефоне шапка – название экрана */

/* ---------- лист «Меню»: шторка над нижним меню, сетка плиток */
.shell-sheet { position: fixed; inset: 0; z-index: 60; display: flex; align-items: flex-end; justify-content: center;
  padding-top: max(14px, calc(env(safe-area-inset-top) + 14px)); }
.shell-sheet[hidden] { display: none; }
.shell-sheet-bg { position: absolute; inset: 0; background: rgba(0,0,0,.45); }
.shell-sheet-card { position: relative; width: 100%; max-height: calc(100% - 10px); overflow: auto; background: var(--bg-2);
  border-radius: 20px 20px 0 0; padding: 20px 14px calc(var(--shell-bottom-h, calc(var(--shell-bar) + env(safe-area-inset-bottom))) + 12px);
  animation: shell-up .28s cubic-bezier(.2,.8,.2,1); }
.shell-sheet:not([hidden]) .shell-sheet-bg { animation: shell-fade .28s ease; }
.shell-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); grid-auto-rows: minmax(84px, auto); gap: 8px 6px; }
.shell-tile { display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: 6px; min-width: 0;
  padding: 2px 0 0; border: 0; border-radius: 16px; background: none; color: var(--text); font: inherit; font-size: 12px;
  line-height: 14px; cursor: pointer; text-decoration: none; min-height: 0;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; -webkit-tap-highlight-color: transparent; }
.shell-tile > span { max-width: 100%; overflow: hidden; white-space: normal; text-align: center;
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }   /* «На одобрение» – в две строки, не «…» */
.shell-tile > i { width: 50px; height: 50px; border-radius: 16px; display: grid; place-items: center; font-style: normal;
  background: var(--brand-soft); color: var(--brand); }
.shell-tile > i .ico { width: 26px; height: 26px; }
.shell-tile.active > i { background: var(--brand); color: var(--primary-fg); }
@media (max-width: 359px) { .shell-tile { font-size: 11px; letter-spacing: -.02em; } .shell-grid { column-gap: 4px; } }
/* анимации – только transform/opacity (урок 4); без них лист открывается так же (урок 5: «Уменьшение движения»
   гасит их правилом app.css, а не ломает) */
@keyframes shell-up { from { transform: translateY(100%); } to { transform: none; } }
@keyframes shell-fade { from { opacity: 0; } }

/* ---------- выбор темы (Настройки) */
.shell-theme { display: flex; gap: 6px; flex-wrap: wrap; }
.shell-theme button { flex: 1 1 0; min-width: 90px; background: var(--bg-2) !important; color: var(--text) !important;
  border: 1px solid var(--line); }
.shell-theme button[aria-pressed="true"] { background: var(--primary-bg) !important; color: var(--primary-fg) !important; border-color: transparent; }

/* ---------- один заголовок экрана – в шапке (координатор 28.11): h1 страницы скрыт глазам, но остаётся для чтения
   с экрана и для поиска по странице; шаблоны экранов не меняются */
html.shell .page > h1:first-of-type, html.shell .page > .row-between:first-child > h1 {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0; }
/* «Клиенты»: «+ Клиент» – справа в строке поиска, а не отдельной строкой над ней */
html.shell .page:has(> .row-between:first-child + .search) { display: grid; grid-template-columns: minmax(0, 1fr) auto;
  column-gap: 8px; align-items: center; }
html.shell .page:has(> .row-between:first-child + .search) > * { grid-column: 1 / -1; }
html.shell .page:has(> .row-between:first-child + .search) > .row-between { display: contents; }
html.shell .page:has(> .row-between:first-child + .search) > .row-between > .btn { grid-column: 2; grid-row: 1; margin: 8px 0 12px; }
html.shell .page:has(> .row-between:first-child + .search) > .search { grid-column: 1; grid-row: 1; }
