/* Application shell layout: sidebar, topbar, content area, page routing.
 *
 * Root layout is CSS Grid, not flex-with-explicit-heights: a flex row
 * where the sidebar had its own `height:100vh` while `.main`'s content
 * could be taller OR shorter than one viewport made the sidebar's dark
 * background visibly end before/after the real page bottom on pages
 * whose content differs a lot from viewport height (e.g. the Campaign
 * Wizard's per-step content). Grid's default `align-items: stretch`
 * makes `.sidebar` and `.main` ALWAYS exactly the same height (the
 * taller of the two, whatever that is) with no manual sync needed — the
 * inner `.sidebar-inner` wrapper is what actually gets `position:sticky`
 * + its own `max-height:100vh` + scroll, independent of the outer grid
 * cell's real height. Fix this at the root only — never re-patch this
 * per-page with local margin/height hacks.
 */
html, body { height: 100%; }
body {
  margin: 0; font-family: var(--font-sans); background: var(--bg); color: var(--text);
  font-size: var(--text-base); line-height: 1.5; -webkit-font-smoothing: antialiased;
}
/* #app-shell wraps sidebar+main (см. index.html) — отдельный login screen
   рендерится ВНЕ этой обёртки (#login-root), до того как известно, кто
   залогинен, поэтому grid здесь, не на body напрямую. */
#app-shell { display: grid; grid-template-columns: var(--shell-sidebar-w) 1fr; min-height: 100vh; }
a { color: inherit; }
svg.icon { width: 17px; height: 17px; flex-shrink: 0; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- sidebar ---------- */
.sidebar {
  background: var(--sidebar-bg); color: var(--sidebar-text); min-width: 0; border-right:1px solid var(--sidebar-border);
  /* deliberately no explicit height here — stretches to match .main via grid */
}
.sidebar-inner {
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; max-height: 100vh; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px; }
.brand-wordmark { color:#0d1b3d; font-size:20px; font-weight:800; letter-spacing:-.045em; line-height:1; }
.brand-wordmark span { color:#ff3366; }
.brand .tag { font-size: 10px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: .08em; margin-top:4px; }

/* context switcher — the 4 top-level UX spaces from the directive */
.context-switch { display: flex; flex-direction: column; gap: 2px; padding: 0 10px 14px; }
.context-btn {
  display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 9px; cursor: pointer;
  font-size: 12.5px; font-weight: 600; color: var(--sidebar-text); transition: background var(--duration-fast);
}
.context-btn svg { width: 16px; height: 16px; opacity: .8; }
.context-btn:hover { background: var(--sidebar-bg-raised); color: var(--sidebar-text-hover); }
.context-btn.active { background: var(--sidebar-active-bg); color: var(--sidebar-text-hover); }
.context-btn.active svg { opacity: 1; color: var(--primary-active); }

.sidebar-section-label {
  font-size: 10px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em;
  color: var(--text-tertiary); padding: 14px 20px 6px;
}
nav.nav-list { display: flex; flex-direction: column; gap: 1px; padding: 0 10px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  font-size: 13px; font-weight: 500; color: var(--sidebar-text); cursor: pointer;
  transition: background var(--duration-fast), color var(--duration-fast); white-space: nowrap;
}
.nav-item:hover { background: var(--sidebar-bg-raised); color: var(--sidebar-text-hover); }
.nav-item.active { background: var(--sidebar-active-bg); color: var(--sidebar-text-hover); font-weight:600; }
.nav-item.active svg { color: var(--primary-active); }
.nav-item svg { width: 16px; height: 16px; opacity: .85; flex-shrink: 0; }

.sidebar-footer { margin-top: auto; padding: 14px 20px; font-size: 11px; color: var(--text-tertiary); border-top: 1px solid var(--sidebar-border); }

/* ---------- main area ---------- */
.main { min-width: 0; min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: 0 28px; height: var(--shell-topbar-h); background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 5; flex-shrink: 0;
}
.topbar-title { display: flex; flex-direction: column; }
.topbar h1 { font-size: var(--text-lg); }
.topbar .crumb { font-size: 11px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.topbar-right { display: flex; align-items: center; gap: var(--sp-3); }
.refresh-indicator { font-size: 11px; color: var(--text-tertiary); white-space: nowrap; }

/* POST-REVIEW CORRECTION PASS п.3: 1240px оставлял ~450px пустого гуттера
   с обеих сторон на 1920px+ экранах — операционные таблицы (NOC/Operators/
   Message Explorer/Billing) выглядели "воткнутыми" в угол огромного
   пустого поля. 1600px даёт таблицам реально использовать пространство;
   формы/wizard не затронуты — у них свой узкий .flow-container (760px),
   намеренно не растягивается "чтобы заполнить" (см. ту же директиву). */
.content { padding: 16px 20px 40px; max-width: 1680px; width: 100%; margin: 0 auto; }
/* FINAL CORRECTION PASS п.7: operational screens (NOC/Operators/Routing/
   Logs/Message Explorer) держат плотные datasets — 1600px их зря обрезает
   на широких мониторах. Business/customer screens (Campaigns/Audience/
   Billing/Pricing и т.п.) сознательно остаются на 1600px — комфортный
   SaaS-layout, не задача "растянуть каждый экран" (директива явно
   предупреждает против обеих крайностей). */
.content.content--operational { max-width: 2000px; }
.page { display: none; }
.page.active { display: block; }
.page-stack { display: flex; flex-direction: column; gap: 12px; }

.page-header { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--sp-4); flex-wrap: wrap; margin-bottom: 4px; }
.page-header h1 { font-size: var(--text-2xl); }
.page-header .sub { font-size: var(--text-sm); color: var(--text-secondary); margin-top: 2px; }
.page-header .actions { display: flex; gap: 8px; flex-shrink: 0; }

/* full-page flows (wizard) replace .content entirely */
.flow-page { display: none; position: fixed; inset: 0; background: var(--bg); z-index: 40; overflow-y: auto; flex-direction: column; }
.flow-page.active { display: flex; }
.flow-topbar { display: flex; align-items: center; justify-content: space-between; padding: 16px 28px; border-bottom: 1px solid var(--border); background: var(--surface); flex-shrink: 0; }
.flow-body { flex: 1; overflow-y: auto; }
.flow-container { max-width: 760px; margin: 0 auto; padding: 32px 28px 80px; }
.flow-footer {
  position: sticky; bottom: 0; background: var(--surface); border-top: 1px solid var(--border);
  padding: 16px 28px; display: flex; align-items: center; justify-content: space-between; flex-shrink: 0;
}

/* ---------- responsive ---------- */
/* ---------- login screen ---------- */
.login-screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: var(--bg); padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow-md); padding: 32px 30px; }
.login-brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.login-wordmark { font-size:26px; }
.login-sub { font-size: 11px; color: var(--text-tertiary); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
.login-heading { font-size: var(--text-xl); margin: 0 0 20px; }
.login-error { font-size: 12.5px; color: var(--danger-strong); background: var(--danger-soft); border-radius: var(--radius-sm); padding: 8px 11px; }
.login-error .login-error-link { display: inline-flex; margin-top: 8px; }
.login-hint { font-size: 11.5px; color: var(--text-tertiary); margin-top: 18px; line-height: 1.5; }
.login-hint code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; font-size: 11px; }

/* ---------- "Acting as" — staff working inside a shared/tenant-scoped
   module from the Admin Platform must pick which customer explicitly
   (директива п.2) rather than silently touching whichever account a page
   happened to fetch first. ---------- */
.acting-as { display: flex; align-items: center; gap: 8px; font-size: 12.5px; }
.acting-as label { color: var(--text-tertiary); font-weight: 600; white-space: nowrap; }
.acting-as select { max-width: 220px; }

@media (max-width: 900px) {
  #app-shell { display: block; } /* stacked: sidebar becomes a normal-flow top bar, no grid row-matching needed */
  .sidebar-inner { position: static; height: auto; max-height: none; overflow: visible; flex-direction: row; align-items: center; overflow-x: auto; padding: 8px 10px; }
  .brand { padding: 4px 10px; }
  .brand .tag { display: none; }
  .context-switch { flex-direction: row; padding: 0 6px; }
  .sidebar-section-label { display: none; }
  nav.nav-list { flex-direction: row; padding: 0 6px; }
  .nav-item { flex-shrink: 0; }
  .sidebar-footer { display: none; }
  .main { min-height: 0; }
  .topbar, .content { padding-left: 16px; padding-right: 16px; }
  .flow-container { padding-left: 16px; padding-right: 16px; }
  th, td { padding: 10px 12px; }
}

@media (max-width: 700px) {
  .topbar { height:auto; min-height:var(--shell-topbar-h); padding-top:10px; padding-bottom:10px; flex-wrap:wrap; align-items:flex-start; }
  .topbar-title, .topbar-right { min-width:0; }
  .topbar-right { width:100%; flex-wrap:wrap; }
  .acting-as { min-width:0; flex-wrap:wrap; }
  .acting-as select { max-width:100%; min-width:0; }
  .content { padding-top:18px; padding-bottom:40px; }
  .page-header .actions { width:100%; flex-wrap:wrap; }
  .page-header .actions .btn { flex:1 1 auto; }
  .drawer-body, .modal-body { padding:16px; }
  .flow-topbar, .flow-footer { padding-left:16px; padding-right:16px; gap:12px; }
  .flow-footer { flex-wrap:wrap; }
  .stepper { display:grid; grid-template-columns:repeat(5,minmax(0,1fr)); gap:var(--sp-2); padding:var(--sp-3) var(--sp-4); overflow:visible; }
  .step { min-width:0; justify-content:center; }
  .step > span, .step-connector { display:none; }

  /* Older screens still express their detail/form grids inline. Collapse
     every such content grid at the shared responsive boundary so labels,
     helper copy and values cannot escape cards or drawers. */
  .page [style*="grid-template-columns:"],
  .drawer-body [style*="grid-template-columns:"],
  .modal-body [style*="grid-template-columns:"],
  .flow-container [style*="grid-template-columns:"] {
    grid-template-columns:minmax(0,1fr) !important;
  }
  .toast-stack { left:12px; right:12px; bottom:12px; align-items:stretch; }
  .toast { max-width:none; overflow-wrap:anywhere; }
}

/* Compact, always available locale choice. */
.language-control select {font:inherit;font-size:12px;border:1px solid var(--border);border-radius:6px;padding:5px 7px;background:var(--surface, #fff);color:var(--text-primary, #17212f);max-width:135px;}
.login-language {display:flex;justify-content:flex-end;margin-bottom:14px;}
.sr-only {position:absolute;width:1px;height:1px;padding:0;margin:-1px;overflow:hidden;clip:rect(0,0,0,0);white-space:nowrap;border:0;}
/* Translated navigation labels may take two lines at the fixed sidebar width. */
@media (min-width: 981px) {
  .nav-item > span, .context-btn > span { min-width:0; white-space:normal; overflow-wrap:anywhere; line-height:1.35; }
  .nav-item > svg, .context-btn > svg { flex-shrink:0; }
}

/* Keep both navigation levels reachable on touch screens. */
.context-btn, .nav-item { border: 0; background: transparent; font-family: inherit; text-align: left; }
.context-btn:focus-visible, .nav-item:focus-visible { outline: 2px solid var(--primary); outline-offset: -2px; }
@media (max-width: 900px) {
  .sidebar-inner { flex-direction: column; align-items: stretch; overflow-x: visible; }
  .context-switch { flex-wrap: wrap; gap: 4px; padding: 6px; }
  nav.nav-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 4px; }
  .context-btn, .nav-item { min-height: 44px; white-space: normal; overflow-wrap: anywhere; }
  .context-btn span, .nav-item span { min-width: 0; }
}

.chart-tooltip { position: fixed; z-index: 10000; pointer-events: none; white-space: pre-line; overflow-wrap: anywhere; max-width: min(320px, calc(100vw - 16px)); padding: 10px 12px; border-radius: 8px; background: #14213d; color: #fff; box-shadow: 0 3px 12px #0003; font-size: 12px; }

#app-shell[hidden] { display: none; }
.card:has(> table) { overflow-x: auto; }

/* Unified navigation: desktop sidebar, mobile drawer, compact account panel. */
#app-shell[hidden] { display:none; }
#app-shell { grid-template-columns: var(--shell-sidebar-w) minmax(0, 1fr); }
.topbar-title { min-width: 0; flex: 1; }
.topbar h1 { overflow-wrap: anywhere; }
.topbar-right { flex: 0 0 auto; width: auto; }
.context-btn, .nav-item { width:100%; min-width:0; white-space:normal; }
.context-btn span, .nav-item span { min-width:0; overflow-wrap:anywhere; }
.shell-icon-button { border:1px solid var(--border); background:var(--surface); border-radius:12px; width:44px; height:44px; display:grid; place-items:center; cursor:pointer; color:var(--text); flex-shrink:0; font-size:26px; }
.shell-icon-button svg { width:22px; height:22px; fill:none; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; }
.navigation-toggle, .navigation-close, .navigation-backdrop { display:none; }
.profile-menu { position:relative; }
.profile-trigger { list-style:none; display:flex; align-items:center; gap:9px; padding:5px 9px 5px 5px; min-height:44px; border:1px solid var(--border); border-radius:999px; cursor:pointer; background:var(--surface); }
.profile-trigger::-webkit-details-marker { display:none; }
.profile-trigger svg { width:16px; height:16px; fill:none; stroke:currentColor; stroke-width:1.6; }
.profile-trigger-name { max-width:180px; overflow:hidden; text-overflow:ellipsis; white-space:nowrap; font-weight:600; font-size:12px; }
.profile-avatar { width:32px; height:32px; border-radius:50%; display:grid; place-items:center; background:#fff0f5; color:#a91346; font-size:12px; font-weight:700; }
.profile-panel { position:absolute; right:0; top:calc(100% + 10px); width:min(320px, calc(100vw - 32px)); padding:16px; background:var(--surface); border:1px solid var(--border); border-radius:16px; box-shadow:0 14px 40px #17213b24; display:flex; flex-direction:column; gap:16px; }
.profile-menu:not([open]) .profile-panel { display:none; }
.profile-identity { display:flex; flex-direction:column; gap:4px; padding-bottom:12px; border-bottom:1px solid var(--border); overflow-wrap:anywhere; }
.profile-identity span { color:var(--text-tertiary); font-size:11px; }
.profile-panel .acting-as { display:flex; align-items:stretch; flex-direction:column; gap:7px; }
.profile-panel .acting-as select { width:100%; max-width:none; }
.profile-language { display:flex; align-items:center; justify-content:space-between; gap:12px; font-size:12px; }
.profile-signout { border:0; border-top:1px solid var(--border); background:transparent; text-align:left; padding:14px 0 0; color:#b42348; cursor:pointer; font:inherit; min-height:44px; }
.profile-trigger:focus-visible, .shell-icon-button:focus-visible, .profile-signout:focus-visible { outline:2px solid var(--primary); outline-offset:3px; }
@media (max-width:900px) {
  .sidebar { position:fixed; inset:0 auto 0 0; width:min(320px, calc(100vw - 48px)); z-index:60; transform:translateX(-105%); visibility:hidden; transition:transform .18s ease, visibility .18s; box-shadow:8px 0 40px #17213b20; }
  .sidebar-inner { height:100dvh; max-height:100dvh; position:relative; display:flex; flex-direction:column; align-items:stretch; overflow-y:auto; overflow-x:hidden; padding:12px 10px; }
  .brand { padding:10px 10px 20px; }
  .brand .tag { display:block; }
  .navigation-close { display:grid; position:absolute; right:12px; top:12px; }
  .context-switch { display:flex; flex-direction:column; padding:0 0 12px; gap:4px; }
  .sidebar-section-label { display:block; padding-left:10px; }
  nav.nav-list { display:flex; flex-direction:column; padding:0; gap:3px; }
  .nav-item, .context-btn { flex-shrink:0; min-height:44px; }
  .sidebar-footer { display:block; margin-top:20px; }
  .navigation-toggle { display:grid; }
  .navigation-open { overflow:hidden; }
  .navigation-open .sidebar { transform:translateX(0); visibility:visible; }
  .navigation-backdrop:not([hidden]) { display:block; position:fixed; inset:0; border:0; background:#10203b66; backdrop-filter:blur(3px); z-index:59; }
  .topbar { height:68px; flex-wrap:nowrap; align-items:center; padding-top:8px; padding-bottom:8px; }
  .topbar-right { width:auto; flex-wrap:nowrap; }
  .profile-trigger-name { display:none; }
  .profile-trigger { padding:4px; gap:3px; }
  .profile-panel { position:fixed; right:12px; top:76px; max-height:calc(100dvh - 92px); overflow-y:auto; }
}
@media (prefers-reduced-motion:reduce) { .sidebar { transition:none; } }

/* Desktop navigation can yield space to content without altering mobile navigation (the rail: see the end of this file). */
@media (min-width:901px) {
  .navigation-toggle { display:grid; }
}

.staff-docs-layout{display:grid;grid-template-columns:minmax(220px,280px) minmax(0,1fr);gap:24px;align-items:start}.staff-docs-layout h2{margin-top:0}.staff-docs-layout .btn[aria-pressed="true"]{border-color:var(--accent,#ff2866);background:#fff1f5}@media(max-width:800px){.staff-docs-layout{grid-template-columns:minmax(0,1fr)}}

/* ---------- fixpack1 (29 Oct): accessibility and mobile layout ---------- */
/* Keyboard-only shortcut past the navigation; visible only when focused. */
.skip-link { position: fixed; top: 8px; left: 8px; z-index: 1000; padding: 10px 14px; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); color: var(--text); font-weight: 600; transform: translateY(-200%); transition: transform .15s ease; }
.skip-link:focus, .skip-link:focus-visible { transform: translateY(0); }
#content:focus { outline: none; }
/* The topbar title is a label, not a second page heading (each page owns its h1). */
.topbar .topbar-heading { margin: 0; font-size: var(--text-lg); font-weight: 700; letter-spacing: -0.01em; line-height: 1.35; overflow-wrap: anywhere; color: var(--text); }
/* Overview: recent campaigns + needs attention side by side on wide screens, stacked on narrow ones. */
.dashboard-split { display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(0, 1fr); gap: 20px; align-items: start; }
@media (max-width: 900px) { .dashboard-split { grid-template-columns: minmax(0, 1fr); } }
/* The hidden attribute always wins over component display rules (.hint-banner,
   .card, .field, .page-stack ... set display:flex/grid/block and used to override it,
   e.g. the billing "suspended" banner stayed visible for every customer). */
[hidden] { display: none !important; }
/* Human-readable load error: sentence first, technical reason second. */
.load-error { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; padding: 12px 14px; border-radius: var(--radius-sm); background: var(--danger-soft); color: var(--danger-strong); }
.load-error-text { margin: 0; font-weight: 600; }
.load-error-detail { margin: 0; font-size: 12px; color: var(--text-secondary); overflow-wrap: anywhere; }
.load-error-detail code { font-size: 12px; }
/* Inside a wide, horizontally scrolling table the message stays in the visible part of the cell. */
.table-wrap td .load-error { position: sticky; left: 0; max-width: min(100%, calc(100vw - 96px)); box-sizing: border-box; }
#db-stats-error:not([hidden]) { margin-bottom: 4px; }

/* Collapsible desktop menu (owner 26.11): the button in the menu header turns the menu into a narrow rail of section icons, names on
   hover (title, set by shellMenus.js); the choice is remembered. Phones and tablets keep the slide-out drawer. Both shells (ZEXTEL, SendSMS). */
.sidebar-collapse { display:none; }
@media (min-width:901px) {
  .brand { position:relative; }
  .sidebar-collapse { display:grid; place-items:center; margin-left:auto; flex:0 0 auto; width:32px; height:32px; border:1px solid transparent; border-radius:8px; background:transparent; color:var(--text-tertiary); cursor:pointer; padding:0; }
  .sidebar-collapse:hover { background:var(--sidebar-bg-raised); color:var(--sidebar-text-hover); border-color:var(--sidebar-border); }
  .sidebar-collapse:focus-visible { outline:2px solid var(--primary); outline-offset:2px; }
  .sidebar-collapse svg { width:18px; height:18px; fill:none; stroke:currentColor; stroke-width:1.8; stroke-linecap:round; stroke-linejoin:round; }
  .navigation-collapsed .sidebar-collapse svg { transform:scaleX(-1); }
  .navigation-collapsed #app-shell { grid-template-columns:72px minmax(0,1fr); }
  .navigation-collapsed .sidebar-inner { padding-left:0; padding-right:0; overflow-x:hidden; }
  .navigation-collapsed .brand { flex-direction:column; align-items:center; justify-content:center; gap:10px; padding:16px 0 12px; }
  .navigation-collapsed .brand .tag, .navigation-collapsed .ss-logo-text, .navigation-collapsed .sidebar-section-label, .navigation-collapsed .sidebar-footer { display:none !important; }
  .navigation-collapsed .brand-wordmark { font-size:0; letter-spacing:0; }
  .navigation-collapsed .brand-wordmark span { font-size:24px; }
  .navigation-collapsed .sidebar-collapse { margin:0; }
  .navigation-collapsed .context-switch, .navigation-collapsed nav.nav-list { padding-left:12px; padding-right:12px; }
  .navigation-collapsed .context-switch { padding-bottom:10px; margin-bottom:8px; border-bottom:1px solid var(--sidebar-border); }
  .navigation-collapsed .nav-item, .navigation-collapsed .context-btn { justify-content:center; gap:0; padding:10px 0; min-height:42px; }
  .navigation-collapsed .nav-item > span, .navigation-collapsed .context-btn > span { display:none; }
  .navigation-collapsed .nav-item svg, .navigation-collapsed .context-btn svg { width:19px; height:19px; }
  .navigation-collapsed .ss-nav-group { font-size:0; height:1px; margin:10px 6px; background:var(--sidebar-border); }
}
