/**
 * tg-shell.css
 *
 * Shared design tokens + layout primitives for /design/tg/ — every page in the
 * TG Mini App mockup tree links this stylesheet. Brand colour is BLUE only
 * (#1e40af → #3b82f6 gradient); no purple, green, or orange accents.
 *
 * Layout shape per page:
 *   ┌─────────────────────────────┐
 *   │ ☰  Page title               │  ← .tg-header (sticky, 56px)
 *   ├─────────────────────────────┤
 *   │  Scrollable content          │  ← <main>, padding 16px
 *   └─────────────────────────────┘
 *   [ TG MainButton (native) ]      ← Telegram chrome (per-page text)
 *
 * Hamburger drawer (.tg-drawer) opens from the left with a backdrop.
 * Width target: 390-430px (iPhone 12-15 Pro). Cards collapse to 1 column.
 */

/* ─── Reset + base ──────────────────────────────────────────────────────── */
* { box-sizing: border-box; }
html {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
body {
  margin: 0;
  background: linear-gradient(180deg, #0f172a 0%, #1e3a5f 100%);
  background-attachment: fixed;
  min-height: 100vh;
  color: #f1f5f9;
  font-size: 15px;
  line-height: 1.5;
  /* Respect TG's bottom MainButton + iOS home indicator. */
  padding-bottom: calc(env(safe-area-inset-bottom, 0px) + 80px);
}
a { color: #93c5fd; text-decoration: none; }
a:hover { color: #bfdbfe; }
button { font: inherit; cursor: pointer; }

/* ─── Brand logo + colour tokens ────────────────────────────────────────── */
:root {
  --tg-blue-700: #1e40af;
  --tg-blue-500: #3b82f6;
  --tg-blue-300: #93c5fd;
  --tg-slate-900: #0f172a;
  --tg-slate-800: #1e293b;
  --tg-slate-700: #334155;
  --tg-slate-600: #475569;
  --tg-slate-400: #94a3b8;
  --tg-slate-300: #cbd5e1;
  --tg-slate-100: #f1f5f9;
}
.tg-logo {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--tg-blue-700), var(--tg-blue-500));
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-weight: 800;
  font-size: 14px;
  flex-shrink: 0;
}

/* ─── Header (sticky, 56px, hamburger + title) ──────────────────────────── */
.tg-header {
  position: sticky;
  top: 0;
  left: 0;
  right: 0;
  height: 56px;
  background: rgba(15, 23, 42, 0.92);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border-bottom: 1px solid var(--tg-slate-700);
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 0 16px;
  padding-top: env(safe-area-inset-top, 0);
  height: calc(56px + env(safe-area-inset-top, 0));
  z-index: 30;
}
.tg-hamburger {
  width: 44px;
  height: 44px;
  border-radius: 10px;
  background: transparent;
  border: none;
  color: var(--tg-slate-100);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  margin-left: -10px;
  flex-shrink: 0;
}
.tg-hamburger:active { background: rgba(255,255,255,0.06); }
.tg-hamburger svg { display: block; }
.tg-header-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--tg-slate-100);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── i18n language switcher (UZ/RU/EN) ─────────────────────────────────── */
/* Drop `<div class="tg-lang-switch">...</div>` into any header — see web parity. */
.tg-lang-switch {
  display: inline-flex;
  gap: 2px;
  margin-left: auto;
  background: rgba(15, 23, 42, 0.5);
  border: 1px solid var(--tg-slate-700);
  border-radius: 8px;
  padding: 2px;
  flex-shrink: 0;
}
.tg-lang-switch button {
  background: transparent;
  border: none;
  color: var(--tg-slate-400);
  font-size: 11px;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  min-height: 28px;
  letter-spacing: .03em;
}
.tg-lang-switch button.active {
  background: linear-gradient(135deg, var(--tg-blue-700), var(--tg-blue-500));
  color: white;
}
.tg-lang-switch button:not(.active):active { background: rgba(59,130,246,0.08); }

/* ─── Hamburger drawer (left-slide) ─────────────────────────────────────── */
.tg-drawer-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  opacity: 0;
  visibility: hidden;
  transition: opacity .2s ease, visibility .2s ease;
  z-index: 40;
}
.tg-drawer-backdrop.is-open {
  opacity: 1;
  visibility: visible;
}
.tg-drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  width: min(82vw, 320px);
  background: linear-gradient(180deg, #0f172a 0%, #1e3a5f 100%);
  border-right: 1px solid var(--tg-slate-700);
  transform: translateX(-100%);
  transition: transform .25s cubic-bezier(.16,1,.3,1);
  z-index: 50;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top, 0);
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
.tg-drawer.is-open { transform: translateX(0); }
.tg-drawer-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--tg-slate-700);
}
.tg-drawer-header .tg-logo { width: 36px; height: 36px; font-size: 15px; }
.tg-drawer-header strong { color: var(--tg-slate-100); font-size: 15px; }
.tg-drawer-header small { color: var(--tg-slate-400); font-size: 11px; display: block; }
.tg-drawer-section {
  padding: 14px 16px 6px;
  font-size: 11px;
  font-weight: 600;
  color: var(--tg-slate-400);
  text-transform: uppercase;
  letter-spacing: .04em;
}
.tg-drawer-link {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  color: var(--tg-slate-300);
  font-size: 14px;
  min-height: 44px;
  border-left: 3px solid transparent;
}
.tg-drawer-link:active { background: rgba(59,130,246,0.08); }
.tg-drawer-link.is-active {
  color: var(--tg-blue-300);
  background: rgba(59,130,246,0.10);
  border-left-color: var(--tg-blue-500);
}
.tg-drawer-link .icon { font-size: 18px; flex-shrink: 0; width: 22px; text-align: center; }

/* ─── Main content area ─────────────────────────────────────────────────── */
.tg-main {
  padding: 16px;
  max-width: 480px;
  margin: 0 auto;
}
.tg-main h1 {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 4px;
  color: var(--tg-slate-100);
}
.tg-main h2 {
  font-size: 17px;
  font-weight: 600;
  margin: 24px 0 12px;
  color: var(--tg-slate-100);
}
.tg-main p { margin: 0 0 12px; color: var(--tg-slate-300); }
.tg-subtitle { color: var(--tg-slate-400); font-size: 13px; margin: 0 0 16px; }

/* ─── Cards ─────────────────────────────────────────────────────────────── */
.tg-card {
  background: var(--tg-slate-800);
  border: 1px solid var(--tg-slate-700);
  border-radius: 12px;
  padding: 16px;
  margin-bottom: 12px;
}
.tg-card-title {
  font-size: 13px;
  font-weight: 600;
  color: var(--tg-slate-400);
  margin: 0 0 4px;
  text-transform: uppercase;
  letter-spacing: .03em;
}
.tg-card-value {
  font-size: 24px;
  font-weight: 700;
  color: var(--tg-slate-100);
}
.tg-card-meta {
  font-size: 12px;
  color: var(--tg-blue-300);
  margin-top: 4px;
}

/* ─── KPI grid (2 columns max on mobile) ────────────────────────────────── */
.tg-kpi-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-bottom: 16px;
}
.tg-kpi-grid .tg-card { padding: 14px; margin: 0; }

/* ─── List rows (leads, products, etc.) ─────────────────────────────────── */
.tg-list { background: var(--tg-slate-800); border: 1px solid var(--tg-slate-700); border-radius: 12px; overflow: hidden; }
.tg-list-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 16px;
  border-bottom: 1px solid var(--tg-slate-700);
  min-height: 60px;
  color: var(--tg-slate-100);
  text-decoration: none;
}
.tg-list-row:last-child { border-bottom: none; }
.tg-list-row:active { background: rgba(59,130,246,0.06); }
.tg-list-avatar {
  width: 40px; height: 40px; border-radius: 50%;
  background: linear-gradient(135deg, var(--tg-blue-700), var(--tg-blue-500));
  display: flex; align-items: center; justify-content: center;
  color: white; font-weight: 700; font-size: 14px;
  flex-shrink: 0;
}
.tg-list-body { flex: 1; min-width: 0; }
.tg-list-title { font-size: 15px; font-weight: 500; color: var(--tg-slate-100); margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-list-meta { font-size: 12px; color: var(--tg-slate-400); margin-top: 2px; }
.tg-list-trailing { color: var(--tg-slate-400); font-size: 12px; flex-shrink: 0; }

/* ─── Status pills ──────────────────────────────────────────────────────── */
.tg-pill {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  font-size: 11px;
  border-radius: 999px;
  font-weight: 500;
  background: rgba(59, 130, 246, 0.15);
  color: var(--tg-blue-300);
}
.tg-pill.muted { background: rgba(148, 163, 184, 0.15); color: var(--tg-slate-300); }

/* ─── Form fields ───────────────────────────────────────────────────────── */
.tg-field { margin-bottom: 14px; }
.tg-label { display: block; font-size: 13px; font-weight: 500; color: var(--tg-slate-300); margin-bottom: 6px; }
.tg-input,
.tg-textarea,
.tg-select {
  width: 100%;
  background: var(--tg-slate-800);
  border: 1px solid var(--tg-slate-700);
  color: var(--tg-slate-100);
  font: inherit;
  font-size: 15px;
  padding: 12px 14px;
  border-radius: 8px;
  min-height: 44px;
  outline: none;
}
.tg-input:focus,
.tg-textarea:focus,
.tg-select:focus { border-color: var(--tg-blue-500); }
.tg-textarea { min-height: 88px; resize: vertical; }
.tg-help { font-size: 12px; color: var(--tg-slate-400); margin-top: 4px; }

/* ─── Buttons (in-content; MainButton is TG-native) ─────────────────────── */
.tg-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 0 16px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  border: 1px solid transparent;
  background: linear-gradient(135deg, var(--tg-blue-700), var(--tg-blue-500));
  color: white;
}
.tg-btn:active { transform: translateY(1px); }
.tg-btn.secondary {
  background: var(--tg-slate-800);
  color: var(--tg-slate-100);
  border-color: var(--tg-slate-700);
}
.tg-btn.full { width: 100%; }
.tg-btn-row { display: flex; gap: 10px; }
.tg-btn-row .tg-btn { flex: 1; }

/* ─── FAB (floating action button) ──────────────────────────────────────── */
.tg-fab {
  position: fixed;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 84px);
  width: 56px;
  height: 56px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--tg-blue-700), var(--tg-blue-500));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  font-size: 26px;
  box-shadow: 0 8px 24px rgba(30, 64, 175, 0.5);
  z-index: 20;
}

/* ─── Section divider / labels ──────────────────────────────────────────── */
.tg-section-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .05em;
  color: var(--tg-slate-400);
  font-weight: 600;
  margin: 20px 0 8px;
  padding: 0 4px;
}

/* ─── Empty state ───────────────────────────────────────────────────────── */
.tg-empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--tg-slate-400);
}
.tg-empty .icon { font-size: 48px; margin-bottom: 12px; }

/* ─── Misc utilities ────────────────────────────────────────────────────── */
.tg-row-split { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.tg-mt-0 { margin-top: 0; }
.tg-mt-16 { margin-top: 16px; }
.tg-mb-0 { margin-bottom: 0; }
.tg-text-muted { color: var(--tg-slate-400); }
.tg-text-blue { color: var(--tg-blue-300); }
.tg-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tg-stack-12 > * + * { margin-top: 12px; }
.tg-stack-16 > * + * { margin-top: 16px; }
