/* =================================================================
   БАЗА — reset, шрифт, фон, оболочка, адаптив
   Цвета только через токены (см. tokens.css). Локальный шрифт Inter
   подключается ниже относительно этого файла (../vendor/fonts/...).
   ================================================================= */

/* ---- ЛОКАЛЬНЫЙ ШРИФТ Inter (без CDN) ---- */
@font-face{
  font-family:"Inter";
  font-style:normal;
  font-weight:400;
  font-display:swap;
  src:url("../vendor/fonts/inter-regular.woff2") format("woff2");
}
@font-face{
  font-family:"Inter";
  font-style:normal;
  font-weight:500;
  font-display:swap;
  src:url("../vendor/fonts/inter-medium.woff2") format("woff2");
}
@font-face{
  font-family:"Inter";
  font-style:normal;
  font-weight:600;
  font-display:swap;
  src:url("../vendor/fonts/inter-semibold.woff2") format("woff2");
}
@font-face{
  font-family:"Inter";
  font-style:normal;
  font-weight:700;
  font-display:swap;
  src:url("../vendor/fonts/inter-bold.woff2") format("woff2");
}

/* =================================================================
   RESET / БАЗА СТРАНИЦЫ
   ================================================================= */
*{margin:0;padding:0;box-sizing:border-box}
/* min-height по динамической высоте вьюпорта (а не height:100%): иначе на iOS-PWA
   фикс. нижний таб-бар «висит» выше реального края экрана. 100vh — фолбэк для
   старых Safari, 100dvh — корректная высота с учётом адресной строки/полоски «домой». */
html,body{min-height:100vh;min-height:100dvh;overflow-x:clip;max-width:100%;touch-action:manipulation;-webkit-text-size-adjust:100%}
body{
  font-family:-apple-system,BlinkMacSystemFont,"SF Pro Text","Segoe UI",Inter,system-ui,sans-serif;
  background:var(--bg);
  color:var(--text-1);
  -webkit-font-smoothing:antialiased;
  text-rendering:optimizeLegibility;
  font-variant-numeric:tabular-nums lining-nums;
  letter-spacing:-.01em;
  position:relative;
  /* overflow-x:clip (НЕ hidden): hidden по спеке заставляет overflow-y стать auto,
     body становится скролл-контейнером и ломает position:sticky у сайдбара (он «улетал»
     вверх при скролле). clip убирает горизонтальную прокрутку, не трогая вертикаль. */
  overflow-x:clip;
  transition:background .22s ease,color .22s ease;
}
.num{font-variant-numeric:tabular-nums;font-feature-settings:"tnum" 1}
@media (prefers-reduced-motion:reduce){*{transition:none!important}}

/* радиальный фон — только стиль «стекло» */
body::before{content:"";position:fixed;inset:0;pointer-events:none;z-index:0;opacity:0;transition:opacity .22s ease}
html[data-style="glass"] body::before{
  opacity:1;
  background:
    radial-gradient(120% 90% at 50% -10%, var(--radial-1), transparent 60%),
    radial-gradient(80% 60% at 50% -5%, var(--radial-2), transparent 55%);
}

/* что меняется по токенам — у всех элементов плавный переход */
.sidebar,.topbar,.card,.nav-item,.iconbtn,.search,.switch,.badge,.bar,
.style-strip,.style-pill,.kpi,table thead th,tbody td,.avatar{
  transition:background-color .22s ease, color .22s ease, border-color .22s ease,
             box-shadow .22s ease, fill .22s ease;
}

/* =================================================================
   ОБОЛОЧКА
   ================================================================= */
.layout{position:relative;z-index:1;display:grid;grid-template-columns:264px 1fr;min-height:100vh}

/* ---- САЙДБАР ---- */
.sidebar{
  background:var(--surface-1);
  border-right:1px solid var(--hair);
  display:flex;flex-direction:column;
  position:sticky;top:0;height:100vh;
  /* если пунктов больше, чем высота экрана — сайдбар скроллится сам, независимо от контента */
  overflow-y:auto;overscroll-behavior:contain;
  padding:26px 16px 18px;
}
html[data-style="glass"] .sidebar{
  -webkit-backdrop-filter:var(--glass-blur);backdrop-filter:var(--glass-blur);
  background:linear-gradient(180deg,rgba(255,255,255,0.02),transparent 30%), var(--glass-bg);
}

/* ---- Лого, навигация, блок пользователя ---- */
.wordmark{padding:6px 12px 26px;display:flex;flex-direction:column;gap:3px}
.wordmark .mark{font-size:23px;font-weight:700;letter-spacing:.14em;color:var(--text-1)}
.wordmark .sub{font-size:11px;color:var(--text-3);letter-spacing:.04em}
html[data-style="glass"] .wordmark .sub,
html[data-style="sgi"] .wordmark .sub{text-transform:uppercase;letter-spacing:.06em}

.nav{display:flex;flex-direction:column;gap:2px;flex:1}
.nav-section{font-size:10px;font-weight:600;text-transform:uppercase;letter-spacing:.07em;
  color:var(--text-3);padding:16px 12px 6px}
.nav-item{
  position:relative;display:flex;align-items:center;gap:12px;
  padding:10px 12px;border-radius:var(--radius-ctrl);
  color:var(--text-2);font-size:14px;font-weight:450;
  cursor:pointer;text-decoration:none;
}
.nav-item svg{width:18px;height:18px;flex:none;stroke:currentColor;stroke-width:1.6;fill:none;opacity:.9}
.nav-item:hover{background:var(--surface-3);color:var(--text-1)}
.nav-item.active{background:var(--accent-soft);color:var(--text-1);font-weight:550}
.nav-item.active svg{stroke:var(--accent);opacity:1}
/* акцентный индикатор слева (pro / glass) */
.nav-item.active::before{
  content:"";position:absolute;left:-16px;top:50%;transform:translateY(-50%);
  width:3px;height:20px;border-radius:0 3px 3px 0;background:var(--accent);
}
html[data-style="glass"] .nav-item.active::before{box-shadow:0 0 10px var(--accent-glow)}
/* SGI: без полоски, активный текст — петроль */
html[data-style="sgi"] .nav-item.active{color:var(--accent-ink);font-weight:600}
html[data-style="sgi"] .nav-item.active::before{display:none}
html[data-style="sgi"] .nav-item.active svg{opacity:1;stroke:var(--accent-ink)}

.user{
  display:flex;align-items:center;gap:11px;
  padding:11px;margin-top:14px;border-radius:13px;
  border:1px solid var(--hair);background:var(--surface-2);
}
html[data-style="sgi"] .user{border:0;border-top:1px solid var(--hair);border-radius:0;background:transparent;padding:12px 10px 4px}
.avatar{
  width:36px;height:36px;border-radius:50%;flex:none;
  display:grid;place-items:center;font-size:12.5px;font-weight:600;
  color:var(--text-1);background:var(--avatar-grad);
  border:1px solid var(--hair-2);letter-spacing:.02em;
}
html[data-style="sgi"] .avatar{border:0;color:var(--accent-ink)}
.user .meta{display:flex;flex-direction:column;gap:1px;min-width:0}
.user .name{font-size:13px;font-weight:550;color:var(--text-1);white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.user .role{font-size:11px;color:var(--text-3)}
.logout-btn{margin-left:auto;flex:none;width:32px;height:32px;border-radius:var(--radius-ctrl);
  display:grid;place-items:center;cursor:pointer;background:transparent;border:1px solid var(--hair);color:var(--text-3);transition:color .15s ease,border-color .15s ease}
.logout-btn:hover{color:var(--danger);border-color:var(--danger)}
.logout-btn svg{width:16px;height:16px;stroke:currentColor;stroke-width:1.7;fill:none}

/* =================================================================
   ДЕЛОВАЯ ЗАСТАВКА при первом открытии (раз за сессию)
   ================================================================= */
#splash{position:fixed;inset:0;z-index:9999;display:flex;align-items:center;justify-content:center;
  background:var(--bg);transition:opacity .6s ease,visibility .6s ease}
#splash.hide{opacity:0;visibility:hidden;pointer-events:none}
.splash-inner{display:flex;flex-direction:column;align-items:center}
.splash-mark{font-size:clamp(40px,9vw,72px);font-weight:700;letter-spacing:.2em;color:var(--text-1);
  opacity:0;transform:translateY(10px);animation:splashUp .9s cubic-bezier(.2,.8,.2,1) .15s forwards}
.splash-line{height:2px;width:0;background:var(--accent);margin:18px 0 14px;border-radius:2px;
  box-shadow:0 0 12px -2px var(--accent-glow);animation:splashLine .8s cubic-bezier(.2,.8,.2,1) .6s forwards}
.splash-sub{font-size:clamp(11px,2.2vw,14px);letter-spacing:.34em;text-transform:uppercase;color:var(--text-3);
  opacity:0;animation:splashFade .8s ease 1.05s forwards}
@keyframes splashUp{to{opacity:1;transform:translateY(0)}}
@keyframes splashLine{to{width:clamp(120px,22vw,200px)}}
@keyframes splashFade{to{opacity:1}}
@media(prefers-reduced-motion:reduce){
  #splash .splash-mark,#splash .splash-line,#splash .splash-sub{animation:none;opacity:1;transform:none}
  #splash .splash-line{width:clamp(120px,22vw,200px)}
}

/* ---- ОСНОВНОЕ ---- */
.main{display:flex;flex-direction:column;min-width:0}
.topbar{
  position:sticky;top:0;z-index:20;
  display:flex;align-items:center;gap:18px;
  padding:16px 34px;
  background:color-mix(in srgb,var(--bg) 82%,transparent);
  -webkit-backdrop-filter:saturate(140%) blur(14px);
  backdrop-filter:saturate(140%) blur(14px);
  border-bottom:1px solid var(--hair);
}
html[data-style="glass"] .topbar{background:var(--glass-bg)}
.topbar .title{font-size:18px;font-weight:600;letter-spacing:-.01em}
.topbar .spacer{flex:1}
.search{
  display:flex;align-items:center;gap:9px;
  background:var(--surface-2);border:1px solid var(--hair);
  border-radius:var(--radius-ctrl);padding:8px 13px;width:240px;
}
html[data-style="sgi"] .search{border-radius:999px;border-color:var(--border-strong)}
.search svg{width:15px;height:15px;stroke:var(--text-3);stroke-width:1.7;fill:none;flex:none}
.search input{border:0;outline:0;background:transparent;color:var(--text-1);font-size:13.5px;width:100%;font-family:inherit}
.search input::placeholder{color:var(--text-3)}
.search:focus-within{border-color:var(--accent-line);box-shadow:0 0 0 3px var(--accent-soft)}

.iconbtn{
  width:38px;height:38px;border-radius:var(--radius-ctrl);flex:none;
  display:grid;place-items:center;cursor:pointer;
  background:var(--surface-2);border:1px solid var(--hair);color:var(--text-2);
  position:relative;
}
html[data-style="sgi"] .iconbtn{border-radius:999px;border-color:var(--border-strong)}
.iconbtn:hover{background:var(--surface-4);color:var(--text-1)}
html[data-style="sgi"] .iconbtn:hover{border-color:var(--accent);box-shadow:0 0 0 3px var(--accent-soft)}
.iconbtn svg{width:18px;height:18px;stroke:currentColor;stroke-width:1.6;fill:none}
/* колокол со счётчиком */
.bell-dot{
  position:absolute;top:-3px;right:-3px;min-width:16px;height:16px;padding:0 4px;
  border-radius:999px;display:grid;place-items:center;
  background:var(--bell-bg);color:var(--bell-txt);
  font-size:10px;font-weight:700;border:2px solid var(--bg);
}
.topbar .avatar{width:38px;height:38px;border-radius:var(--radius-ctrl)}
html[data-style="sgi"] .topbar .avatar{border-radius:50%}

/* ---- КОНТЕНТ ----
   Занимает ВСЮ ширину справа от сайдбара — без узкой центрированной колонки и
   полей по бокам (пустые поля смотрятся «дёшево»). Правило на весь сайт. */
.content{padding:24px 34px 40px;width:100%;flex:1;min-width:0}

/* Шапка раздела (заголовок + подпись). Воздух между жирным заголовком и подписью,
   чтобы они не «слипались» (правило на весь сайт). */
.greet h1{font-size:25px;font-weight:680;letter-spacing:-.02em;line-height:1.15}
.greet p{margin-top:7px;font-size:13.5px;color:var(--text-3);line-height:1.35}

/* =================================================================
   АВТО-ПОДСТРОЙКА СЕТОК
   ================================================================= */
/* авто-вмещение при любой ширине окна: карточки сами переносятся, без сжатия в «колонну» */
.kpis{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,200px),1fr));gap:11px;margin-bottom:14px}
/* график + таблица: при узком окне аккуратно встают друг под друга, а не сжимаются */
.grid2{display:grid;grid-template-columns:repeat(auto-fit,minmax(min(100%,380px),1fr));gap:11px;margin-bottom:14px;min-width:0}
.grid2>.card{min-width:0}

/* Воздух между отдельными плашками/карточками по всему сайту.
   Внутри сеток (.kpis/.grid2) интервал задаёт gap — у их карточек margin убираем. */
.card{margin-bottom:12px}
.kpis>.card,.kpis>.kpi,.grid2>.card{margin-bottom:0}

/* =================================================================
   АДАПТИВ ~390px
   ================================================================= */
/* Нижний таб-бар — ТОЛЬКО на телефоне. На десктопе скрыт по умолчанию,
   иначе его крупные иконки вылезают чёрными блоками внизу страницы. */
.tabbar{display:none}

@media(max-width:760px){
  .layout{grid-template-columns:1fr}
  .sidebar{display:none}
  /* учитываем «чёлку»/вырез телефона — шапка ниже выреза, контент не улетает наверх */
  .topbar{padding:calc(13px + env(safe-area-inset-top,0px)) 16px 13px;gap:10px}
  .topbar .title{font-size:16px}
  .search{display:none}
  .content{padding:18px 11px 92px}
  .style-strip{flex-direction:column;align-items:stretch;gap:10px;padding:14px}
  .style-pills{overflow-x:auto;justify-content:flex-start}
  .style-pill{white-space:nowrap}
  .greet h1{font-size:21px}
  /* на телефоне — компактно: плашки по 2-3 в ряд, минимум воздуха, максимум инфо на экране */
  .kpis{grid-template-columns:repeat(auto-fit,minmax(148px,1fr));gap:8px}
  /* заголовки панелей и подписи переносятся, селекторы не вылезают за экран */
  .panel-head{flex-wrap:wrap;gap:4px 10px}
  .panel-head .hint,.greet p{overflow-wrap:anywhere}
  /* строки контролов (период/фильтры) — в один ряд с горизонтальным скроллом, а не в столбик */
  .field-row{flex-wrap:nowrap;overflow-x:auto;-webkit-overflow-scrolling:touch;padding-bottom:2px}
  .field-row::-webkit-scrollbar{display:none}
  .field-row>*{flex:0 0 auto}
  select.sel{max-width:100%}
  .kpi{padding:11px 13px}
  .kpi .label{min-height:0;font-size:10.5px}
  .kpi .num{font-size:20px;margin:5px 0 3px}
  .kpi .sub{font-size:11px}
  .grid2{grid-template-columns:1fr;gap:14px}
  .panel-body,.controls{padding:18px 16px}
  /* без боковых отступов у прокручиваемой обёртки — липкий столбец прилипает к самому краю
     карточки, и слева под ним НЕ остаётся полоски, в которую просвечивают соседние колонки */
  .tablewrap{padding:18px 0}
  .panel-head{padding-left:16px;padding-right:16px}
  thead th:first-child,tbody td:first-child{padding-left:16px}
  tbody td:last-child,thead th:last-child{padding-right:16px}
  .chart{gap:9px;height:185px}
  .bar{border-radius:6px 6px 2px 2px}
  .col .val{font-size:10.5px}
  .controls{flex-direction:column;align-items:flex-start;gap:18px}
  .badges{margin-left:0;flex-wrap:wrap}
  table{font-size:12.5px;min-width:512px}
  /* левая «заглушка» того же цвета (-3px) закрывает суб-пиксельный просвет у края карточки
     при инерционной прокрутке iOS; справа — мягкая тень-разделитель */
  thead th:first-child,tbody td:first-child{min-width:138px;
    box-shadow:-3px 0 0 0 var(--col-stick),8px 0 12px -8px rgba(0,0,0,.30)}
  .grid2>.card{overflow:hidden}
  td .name{white-space:normal}
  .chart-wrap{height:190px}
  .tabbar{
    display:flex;position:fixed;left:0;right:0;bottom:0;z-index:50;
    background:color-mix(in srgb,var(--surface-1) 92%,transparent);
    -webkit-backdrop-filter:saturate(150%) blur(16px);backdrop-filter:saturate(150%) blur(16px);
    border-top:1px solid var(--hair);
    /* НЕ резервируем всю нижнюю безопасную зону iPhone (~34px) — иначе под иконками
       большой пустой зазор и бар «задран». Берём зону минус 16px, но не меньше 4px.
       Хочется ещё ниже — увеличить 16 (напр. 22); наезжает на полоску «домой» —
       уменьшить (напр. 10). Менять только это число. */
    padding:4px 6px max(4px, calc(env(safe-area-inset-bottom,0px) - 16px));
  }
  html[data-style="glass"] .tabbar{background:var(--glass-bg)}
  .tab{
    flex:1;display:flex;flex-direction:column;align-items:center;gap:4px;
    color:var(--text-3);font-size:10px;font-weight:500;text-decoration:none;padding:4px 0;border-radius:10px;
  }
  .tab svg{width:21px;height:21px;stroke:currentColor;stroke-width:1.6;fill:none}
  .tab.active{color:var(--accent)}
  html[data-style="sgi"] .tab.active{color:var(--accent-ink)}
}
@media(max-width:400px){
  .kpis{grid-template-columns:repeat(2,minmax(0,1fr))}
}
