/* =====================================================================
   Telegram Bot Hosting Platform — Design System v2
   Advanced, icon-driven UI. No emoji anywhere — status and actions are
   communicated with inline SVG icons + color, never pictographs.
   ===================================================================== */

:root {
  /* Color */
  --ink:        #0C1730;
  --ink-soft:   #4A5578;
  --ink-faint:  #8B93AD;
  --paper:      #FFFFFF;
  --paper-tint: #F4F6FB;
  --line:       #E3E8F2;
  --line-soft:  #EEF1F9;

  --signal:      #1D4ED8;
  --signal-dark: #12308F;
  --signal-tint: #EAF0FE;
  --signal-glow: rgba(29, 78, 216, 0.18);

  --live:      #0E9F6E;
  --live-tint: #E7F9F1;
  --wait:      #B8720B;
  --wait-tint: #FCF0DC;
  --stop:      #B42318;
  --stop-tint: #FDECEA;
  --idle:      #667085;
  --idle-tint: #F0F1F5;

  /* Type */
  --font-display: 'Sora', 'Segoe UI', sans-serif;
  --font-body: 'Inter', 'Segoe UI', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, monospace;

  /* Shape */
  --radius-sm: 8px;
  --radius: 12px;
  --radius-lg: 20px;
  --shadow: 0 4px 12px rgba(12, 23, 48, 0.06), 0 16px 40px -20px rgba(12, 23, 48, 0.28);
  --shadow-sm: 0 1px 2px rgba(12, 23, 48, 0.07);

  --page-pad-x: 32px;
  --page-pad-top: 28px;
}

@media (max-width: 640px) {
  :root { --page-pad-x: 16px; --page-pad-top: 16px; }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font-family: var(--font-body);
  color: var(--ink);
  background: var(--paper-tint);
  font-size: 15px;
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  color: var(--ink);
  line-height: 1.18;
  margin: 0 0 0.5em;
  font-weight: 650;
  letter-spacing: -0.01em;
}

h1 { font-size: 2.1rem; }
h2 { font-size: 1.4rem; }
h3 { font-size: 1.05rem; }

@media (max-width: 640px) {
  h1 { font-size: 1.55rem; }
  h2 { font-size: 1.2rem; }
}

p { margin: 0 0 1em; color: var(--ink-soft); max-width: 62ch; }

a { color: var(--signal); text-decoration: none; }
a:hover { text-decoration: underline; }

code, .mono { font-family: var(--font-mono); font-size: 0.9em; }

img, svg { max-width: 100%; display: block; }

button, input, select, textarea { font-family: inherit; font-size: inherit; }

:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 2px;
}

.icon { flex-shrink: 0; vertical-align: -3px; }

/* ---------------------------------------------------------------- */
/* Layout                                                             */
/* ---------------------------------------------------------------- */

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 0 24px;
}
@media (max-width: 640px) { .container { padding: 0 16px; } }

.app-shell {
  display: grid;
  grid-template-columns: 246px 1fr;
  min-height: 100vh;
}

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
}

.sidebar {
  background: var(--ink);
  color: #C7D0EA;
  padding: 22px 16px;
  display: flex;
  flex-direction: column;
  overflow-wrap: break-word;
  min-width: 0;
}

@media (min-width: 901px) {
  .sidebar {
    position: sticky;
    top: 0;
    height: 100vh;
    width: 246px;
    max-width: 246px;
    overflow-y: auto;
    overflow-x: hidden;
    transform: none;
  }
  .sidebar-backdrop { display: none !important; }
}

/* Off-canvas drawer on mobile */
@media (max-width: 900px) {
  .sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(82vw, 300px);
    z-index: 200;
    box-shadow: var(--shadow);
    transform: translateX(-105%);
    transition: transform 0.22s ease;
    overflow-y: auto;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: none;
    position: fixed; inset: 0;
    background: rgba(12, 23, 48, 0.45);
    z-index: 190;
  }
  .sidebar-backdrop.open { display: block; }
}

.sidebar .brand {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  color: #fff;
  font-family: var(--font-display);
  font-weight: 650;
  font-size: 1.02rem;
  padding: 0 6px 20px;
}
.sidebar .brand-left { display: flex; align-items: center; gap: 10px; }

.sidebar-close-btn {
  display: none;
  align-items: center; justify-content: center;
  width: 34px; height: 34px;
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.06);
  color: #C7D0EA;
  border: none;
  cursor: pointer;
}
@media (max-width: 900px) { .sidebar-close-btn { display: inline-flex; } }
.sidebar-close-btn:hover { background: rgba(255,255,255,0.12); color: #fff; }

.brand-mark {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--signal), #4B7BFF);
  display: flex; align-items: center; justify-content: center;
  font-size: 15px; font-weight: 700; color: #fff;
  flex-shrink: 0;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: #C7D0EA;
  font-size: 0.92rem;
  font-weight: 500;
  margin-bottom: 2px;
}
.nav-link .icon { color: #8C97BD; }
.nav-link:hover { background: rgba(255,255,255,0.06); text-decoration: none; }
.nav-link.active { background: var(--signal); color: #fff; }
.nav-link.active .icon { color: #fff; }

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.sidebar-user { font-size: 0.8rem; color: #8B93AD; padding: 0 12px 6px; display: flex; align-items: center; gap: 8px; }

.sidebar-support {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: #9FB0E8;
  font-size: 0.88rem;
  font-weight: 500;
  background: rgba(29, 78, 216, 0.16);
  margin-top: 4px;
}
.sidebar-support:hover { background: rgba(29, 78, 216, 0.26); text-decoration: none; color: #C9D8FF; }

.main {
  padding: var(--page-pad-top) var(--page-pad-x) 56px;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 22px;
  flex-wrap: wrap;
}

.mobile-menu-btn {
  display: none;
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius-sm);
  width: 40px; height: 40px; align-items: center; justify-content: center; cursor: pointer;
  color: var(--ink);
  flex-shrink: 0;
}
@media (max-width: 900px) { .mobile-menu-btn { display: flex; } }

/* ---------------------------------------------------------------- */
/* Components                                                         */
/* ---------------------------------------------------------------- */

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow-sm);
}
@media (max-width: 640px) { .card { padding: 16px; } }

.card-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }

.grid {
  display: grid;
  gap: 14px;
}
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }
@media (max-width: 760px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: repeat(2, 1fr); }
}
@media (max-width: 480px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 18px;
  box-shadow: var(--shadow-sm);
}
.stat .value { font-family: var(--font-display); font-size: 1.55rem; font-weight: 700; color: var(--ink); }
.stat .label { color: var(--ink-soft); font-size: 0.82rem; margin-top: 2px; display: flex; align-items: center; gap: 6px; }
.stat .label .icon { color: var(--ink-faint); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-weight: 600;
  font-size: 0.9rem;
  cursor: pointer;
  transition: transform 0.05s ease, opacity 0.15s ease, background 0.15s ease;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--signal); color: #fff; box-shadow: 0 1px 2px rgba(0,0,0,0.05), 0 0 0 0 var(--signal-glow); }
.btn-primary:hover { background: var(--signal-dark); }
.btn-outline { background: var(--paper); color: var(--ink); border-color: var(--line); }
.btn-outline:hover { border-color: var(--signal); color: var(--signal); }
.btn-danger { background: var(--stop-tint); color: var(--stop); }
.btn-danger:hover { background: #FBD9D6; }
.btn-ghost { background: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--line-soft); }
.btn-sm { padding: 7px 13px; font-size: 0.82rem; }
.btn-icon { padding: 9px; width: 38px; }
.btn-block { width: 100%; }

.field { margin-bottom: 16px; }
.field label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--ink);
  margin-bottom: 6px;
}
.field .hint { font-size: 0.8rem; color: var(--ink-faint); margin-top: 4px; line-height: 1.5; }
.field input, .field select, .field textarea {
  width: 100%;
  padding: 11px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
}
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--signal);
  outline: none;
  box-shadow: 0 0 0 3px var(--signal-tint);
}
.field.error input { border-color: var(--stop); }
.field .error-text { color: var(--stop); font-size: 0.82rem; margin-top: 4px; }

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px 3px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge-live { background: var(--live-tint); color: var(--live); }
.badge-wait { background: var(--wait-tint); color: var(--wait); }
.badge-stop { background: var(--stop-tint); color: var(--stop); }
.badge-idle { background: var(--idle-tint); color: var(--idle); }
.badge .icon { width: 12px; height: 12px; }

.toast-stack {
  position: fixed;
  top: 16px;
  right: 16px;
  left: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  pointer-events: none;
}
@media (min-width: 640px) { .toast-stack { left: auto; max-width: 340px; } }
.toast {
  background: var(--ink);
  color: #fff;
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  font-size: 0.87rem;
  box-shadow: var(--shadow);
  animation: toast-in 0.2s ease;
  display: flex; align-items: center; gap: 8px;
  pointer-events: auto;
  max-width: 100%;
}
.toast.error { background: var(--stop); }
.toast.success { background: var(--live); }
@keyframes toast-in { from { opacity: 0; transform: translateY(-6px); } to { opacity: 1; transform: translateY(0); } }

.modal-backdrop {
  position: fixed; inset: 0; background: rgba(12, 23, 48, 0.5);
  display: flex; align-items: center; justify-content: center; z-index: 900; padding: 20px;
}
.modal {
  background: var(--paper); border-radius: var(--radius-lg); padding: 24px;
  max-width: 420px; width: 100%; box-shadow: var(--shadow);
}

.skeleton {
  background: linear-gradient(90deg, var(--line-soft) 25%, var(--line) 37%, var(--line-soft) 63%);
  background-size: 400% 100%;
  animation: skeleton-wave 1.4s ease infinite;
  border-radius: var(--radius-sm);
}
@keyframes skeleton-wave { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

.empty-state {
  text-align: center;
  padding: 48px 20px;
  color: var(--ink-soft);
}
.empty-state .icon { color: var(--ink-faint); margin: 0 auto 12px; }

.progress-bar {
  height: 6px; border-radius: 999px; background: var(--line-soft); overflow: hidden;
}
.progress-bar > div {
  height: 100%; background: var(--signal); border-radius: 999px; transition: width 0.2s ease;
}

table.data-table { width: 100%; border-collapse: collapse; font-size: 0.86rem; }
.data-table th {
  text-align: left; color: var(--ink-soft); font-weight: 600; font-size: 0.76rem;
  padding: 10px 12px; border-bottom: 1px solid var(--line); white-space: nowrap;
}
.data-table td { padding: 12px; border-bottom: 1px solid var(--line-soft); }
.data-table tr:last-child td { border-bottom: none; }
.table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--paper-tint);
  padding: 20px;
}
.auth-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 32px;
  max-width: 400px;
  width: 100%;
  box-shadow: var(--shadow);
}
@media (max-width: 480px) { .auth-card { padding: 24px 20px; } }

/* Scrollable tab row — critical mobile fix: tabs no longer clip/overflow,
   they scroll horizontally with a lightweight snap instead. A soft fade
   + chevron hint on the right edge (mobile only) signals there's more
   to scroll, since the cut-off tab itself isn't a strong enough cue. */
.tab-scroll-wrap {
  position: relative;
  margin-bottom: 20px;
}
@media (max-width: 640px) {
  .tab-scroll-wrap::after {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 2px;
    width: 28px;
    background: linear-gradient(90deg, rgba(244,246,251,0) 0%, var(--paper-tint) 78%);
    pointer-events: none;
  }
  .tab-scroll-wrap.at-end::after { opacity: 0; }
}
.tab-row {
  display: flex;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
}
.tab-row::-webkit-scrollbar { display: none; }
.tab-btn {
  display: flex; align-items: center; gap: 7px;
  padding: 10px 14px;
  border: none; background: none; cursor: pointer;
  font-weight: 600; font-size: 0.88rem;
  color: var(--ink-soft);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  flex-shrink: 0;
}
.tab-btn .icon { color: var(--ink-faint); }
.tab-btn.active { color: var(--signal); border-color: var(--signal); }
.tab-btn.active .icon { color: var(--signal); }

.text-sm { font-size: 0.85rem; }
.text-muted { color: var(--ink-soft); }
.mt-0 { margin-top: 0; } .mt-1 { margin-top: 8px; } .mt-2 { margin-top: 16px; } .mt-3 { margin-top: 24px; }
.mb-0 { margin-bottom: 0; } .mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 16px; } .mb-3 { margin-bottom: 24px; }
.flex { display: flex; } .items-center { align-items: center; } .justify-between { justify-content: space-between; }
.gap-1 { gap: 8px; } .gap-2 { gap: 16px; }
.flex-wrap { flex-wrap: wrap; }
