/* 02-layout.css — The app frame: sidebar, main column, top bar, panel, icon buttons; Telegram safe areas.
   Part of the CRM stylesheet: the files load in number order (components/app_styles.html) and later
   rules win, exactly as when this was one file. */

/* ---------- Layout ---------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; inset: 0 auto 0 0;
  width: var(--sidebar-w);
  display: flex; flex-direction: column;
  padding: 18px 12px 12px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  z-index: 30;
}
.brand { display: flex; align-items: center; padding: 6px 10px 18px; }
.brand img { display: block; width: auto; height: 26px; }
.brand .logo-dark, [data-theme=dark] .brand .logo-light { display: none; }
[data-theme=dark] .brand .logo-dark { display: block; }

.sidebar-search { position: relative; margin: 0 2px 14px; }
.sidebar-search input {
  width: 100%; height: 38px; padding: 0 10px 0 34px;
  border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface-2); color: var(--text); font: inherit; font-size: 13.5px;
}
.sidebar-search svg { position: absolute; left: 12px; top: 12px; color: var(--faint); }

.nav-group { margin-bottom: 10px; }
.nav-title { padding: 6px 10px; font-size: 11px; font-weight: 700; letter-spacing: .08em; color: var(--faint); text-transform: uppercase; }
.nav-link {
  position: relative;
  display: flex; align-items: center; gap: 10px;
  height: 38px; padding: 0 12px; margin: 1px 0;
  border-radius: 10px; color: var(--text-2); font-weight: 500; font-size: 14px;
  transition: background .15s, color .15s;
}
.nav-link:hover { background: var(--surface-3); }
.nav-link.active { background: var(--accent-soft); color: var(--accent-strong); font-weight: 600; }
.nav-link.active::before { content: ""; position: absolute; left: -12px; top: 7px; bottom: 7px; width: 3px; border-radius: 0 3px 3px 0; background: var(--accent); }
.nav-link.active svg { color: var(--accent); }
.nav-badge { margin-left: auto; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 9px; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; display: grid; place-items: center; }

.sidebar-user {
  margin-top: auto;
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 10px;
  background: var(--surface-2); border: 1px solid var(--border-soft);
}
.sidebar-user .meta { line-height: 1.2; min-width: 0; }
.sidebar-user .meta b { display: block; font-size: 13.5px; }
.sidebar-user .meta span { font-size: 12.5px; color: var(--muted); }
.sidebar-user form { margin-left: auto; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }
.topbar { height: 56px; display: flex; align-items: center; justify-content: flex-end; gap: 8px; padding: 0 20px; }
/* ---------- Telegram Mini App ----------
   Telegram's header (and in fullscreen the status bar) lies on top of the page. --tg-safe-* hold how far, as Telegram
   reports it (js/app/telegram.js), and are 0 when nothing overlaps — so every screen and overlay simply adds them. */
body.in-telegram .topbar {
  padding-top: var(--tg-safe-top, 0px);
  height: calc(52px + var(--tg-safe-top, 0px));
}
body.in-telegram .tabbar { padding-bottom: calc(6px + max(var(--tg-safe-bottom, 0px), env(safe-area-inset-bottom, 0px))); }
body.in-telegram .panel { padding-bottom: calc(92px + max(var(--tg-safe-bottom, 0px), env(safe-area-inset-bottom, 0px))); }
body.in-telegram .drawer-head { padding-top: calc(16px + var(--tg-safe-top, 0px)); }
body.in-telegram .drawer-body { padding-bottom: calc(20px + var(--tg-safe-bottom, 0px)); }
body.in-telegram .drawer-foot { padding-bottom: calc(12px + var(--tg-safe-bottom, 0px)); }
/* Drawers without a header row (staff card) keep their content below Telegram's buttons too. */
body.in-telegram .drawer > .drawer-body:first-child { padding-top: calc(14px + var(--tg-safe-top, 0px)); }
body.in-telegram .sidebar {
  padding-top: calc(18px + var(--tg-safe-top, 0px));
  padding-bottom: calc(12px + var(--tg-safe-bottom, 0px));
}
body.in-telegram .messages { top: calc(14px + var(--tg-safe-top, 0px)); }
body.in-telegram .lightbox {
  padding-top: var(--tg-safe-top, 0px);
  padding-bottom: var(--tg-safe-bottom, 0px);
}
@media (max-width: 820px) {
  body.in-telegram .selection-bar,
  body.in-telegram .share-panel { bottom: calc(70px + max(var(--tg-safe-bottom, 0px), env(safe-area-inset-bottom, 0px))); }
}
/* Inside Telegram its own Back is the one way back: no ✕ on drawers, no in-page "← Orqaga" links. */
body.in-telegram .drawer [data-drawer-close].btn-ghost,
body.in-telegram a.link[data-back],
body.in-telegram .error-actions a[data-back] { display: none; }
.panel {
  flex: 1;
  margin: 0 0 0 0;
  padding: 26px 28px 40px;
  background: var(--surface);
  border-top-left-radius: 18px;
  border: 1px solid var(--border);
  border-right: 0; border-bottom: 0;
}

.icon-btn {
  position: relative;
  width: 36px; height: 36px; display: grid; place-items: center;
  border-radius: 50%; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-2); cursor: pointer;
}
.icon-btn:hover { background: var(--surface-3); }
.icon-btn .dot { position: absolute; top: -3px; right: -3px; min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px; background: var(--accent); color: #fff; font-size: 10px; font-weight: 700; display: grid; place-items: center; }

