/* ============================================================
   TelegramBot Platform – Admin Theme
   ============================================================ */

:root {
  /* Brand */
  --primary:       #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #dbeafe;
  --secondary:     #64748b;
  --accent:        #7c3aed;

  /* Status */
  --success:  #16a34a;
  --warning:  #d97706;
  --danger:   #dc2626;
  --info:     #0891b2;

  /* Neutrals */
  --bg:       #f1f5f9;
  --surface:  #ffffff;
  --border:   #e2e8f0;
  --text:     #0f172a;
  --text-muted: #64748b;
  --text-light: #94a3b8;

  /* Sidebar */
  --sidebar-bg:      #0f172a;
  --sidebar-text:    #cbd5e1;
  --sidebar-hover:   rgba(255,255,255,.07);
  --sidebar-active:  rgba(37,99,235,.4);
  --sidebar-active-border: #2563eb;
  --sidebar-width:   240px;
  --sidebar-icon:    #94a3b8;

  /* Misc */
  --radius:    8px;
  --radius-lg: 12px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow:    0 4px 12px rgba(0,0,0,.1);
  --shadow-lg: 0 10px 32px rgba(0,0,0,.12);
  --transition: all .18s ease;
  --topbar-h:  58px;
}

/* Dark mode */
@media (prefers-color-scheme: dark) {
  :root {
    --bg:       #0d1117;
    --surface:  #161b22;
    --border:   #21262d;
    --text:     #f0f6fc;
    --text-muted: #8b949e;
    --text-light: #6e7681;
  }
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; -webkit-font-smoothing: antialiased; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
ul { list-style: none; }

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

/* ── Sidebar ── */
.sidebar {
  width: var(--sidebar-width);
  background: var(--sidebar-bg);
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  transition: transform .25s ease;
}
.sidebar-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 20px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  text-decoration: none;
}
.sidebar-logo-icon {
  width: 32px; height: 32px;
  background: var(--primary);
  border-radius: 8px;
  display: flex; align-items: center; justify-content: center;
}
.sidebar-logo-icon svg { width: 18px; height: 18px; fill: #fff; }
.sidebar-logo-text { color: #f1f5f9; font-weight: 700; font-size: 15px; }

.sidebar-nav { flex: 1; padding: 12px 0; }
.nav-group-label {
  color: var(--sidebar-icon);
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .08em;
  padding: 16px 20px 6px;
}
.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 20px;
  color: var(--sidebar-text);
  border-left: 3px solid transparent;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 450;
}
.nav-item:hover {
  background: var(--sidebar-hover);
  color: #fff;
  text-decoration: none;
}
.nav-item.active {
  background: var(--sidebar-active);
  border-left-color: var(--sidebar-active-border);
  color: #fff;
}
.nav-item .nav-icon {
  width: 18px; height: 18px;
  color: var(--sidebar-icon);
  flex-shrink: 0;
}
.nav-item.active .nav-icon,
.nav-item:hover .nav-icon { color: var(--primary-light); }

.sidebar-footer {
  padding: 12px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.sidebar-user {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: pointer;
  transition: var(--transition);
}
.sidebar-user:hover { background: var(--sidebar-hover); }
.sidebar-avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 600; font-size: 13px;
  flex-shrink: 0;
}
.sidebar-user-info { flex: 1; min-width: 0; }
.sidebar-user-name { color: #f1f5f9; font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user-role { color: var(--sidebar-icon); font-size: 11px; }

/* ── Main content ── */
.main {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* ── Topbar ── */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky; top: 0; z-index: 90;
}
.topbar-title {
  flex: 1;
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
}
.topbar-actions { display: flex; align-items: center; gap: 10px; }
.topbar-menu-btn {
  display: none;
  background: none; border: none;
  cursor: pointer; padding: 6px;
  color: var(--text-muted);
}

/* ── Page content ── */
.page-content {
  flex: 1;
  padding: 24px;
  max-width: 1400px;
  width: 100%;
}
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
}
.page-header-left h1 {
  font-size: 22px;
  font-weight: 700;
  color: var(--text);
}
.page-header-left p {
  color: var(--text-muted);
  font-size: 13px;
  margin-top: 2px;
}
.page-header-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Cards ── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.card-title {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}
.card-body { padding: 20px; }
.card-footer {
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: rgba(0,0,0,.02);
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ── Stats grid ── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.stat-card:hover { box-shadow: var(--shadow); transform: translateY(-1px); }
.stat-card-label { font-size: 12px; color: var(--text-muted); font-weight: 500; text-transform: uppercase; letter-spacing: .04em; }
.stat-card-value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1; }
.stat-card-icon {
  width: 40px; height: 40px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  margin-bottom: 4px;
}
.stat-card-icon.blue   { background: #dbeafe; color: #2563eb; }
.stat-card-icon.green  { background: #dcfce7; color: #16a34a; }
.stat-card-icon.purple { background: #f3e8ff; color: #7c3aed; }
.stat-card-icon.orange { background: #fff7ed; color: #d97706; }
.stat-card-icon.red    { background: #fee2e2; color: #dc2626; }
.stat-card-icon.cyan   { background: #cffafe; color: #0891b2; }
.stat-card-icon svg    { width: 20px; height: 20px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  white-space: nowrap;
  line-height: 1.4;
}
.btn:hover { text-decoration: none; }
.btn svg { width: 15px; height: 15px; flex-shrink: 0; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-lg { padding: 10px 20px; font-size: 15px; }
.btn-icon { padding: 7px; }
.btn-icon.btn-sm { padding: 5px; }

.btn-primary   { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn-secondary { background: transparent; color: var(--text-muted); border-color: var(--border); }
.btn-secondary:hover { background: var(--bg); border-color: var(--text-light); color: var(--text); }
.btn-success   { background: var(--success); color: #fff; border-color: var(--success); }
.btn-danger    { background: var(--danger);  color: #fff; border-color: var(--danger); }
.btn-warning   { background: var(--warning); color: #fff; border-color: var(--warning); }
.btn-ghost     { background: transparent; color: var(--text-muted); border-color: transparent; }
.btn-ghost:hover { background: var(--bg); }
.btn-outline-primary { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn-outline-primary:hover { background: var(--primary-light); }
.btn-outline-danger  { background: transparent; color: var(--danger); border-color: var(--danger); }
.btn-outline-danger:hover  { background: #fee2e2; }

/* ── Forms ── */
.form-group { margin-bottom: 16px; }
.form-label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text);
  margin-bottom: 6px;
}
.form-label .required { color: var(--danger); margin-left: 2px; }
.form-hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.form-control {
  width: 100%;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  font-size: 13px;
  transition: var(--transition);
  outline: none;
  font-family: inherit;
}
.form-control:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.12); }
.form-control::placeholder { color: var(--text-light); }
.form-control:disabled { background: var(--bg); opacity: .7; cursor: not-allowed; }
textarea.form-control { resize: vertical; min-height: 90px; }
select.form-control { cursor: pointer; }

.form-check { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.form-check-input { width: 16px; height: 16px; cursor: pointer; accent-color: var(--primary); }
.form-check-label { font-size: 13px; color: var(--text); }

.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-row-3 { grid-template-columns: 1fr 1fr 1fr; }

/* ── Tables ── */
.table-wrapper { overflow-x: auto; border-radius: var(--radius-lg); }
.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.table th {
  background: var(--bg);
  padding: 10px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 12px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  white-space: nowrap;
  border-bottom: 1px solid var(--border);
}
.table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  vertical-align: middle;
}
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: rgba(37,99,235,.03); }
.table-actions { display: flex; gap: 6px; align-items: center; }

/* ── Badges ── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  line-height: 1.6;
  white-space: nowrap;
}
.badge-success  { background: #dcfce7; color: #16a34a; }
.badge-danger   { background: #fee2e2; color: #dc2626; }
.badge-warning  { background: #fef3c7; color: #d97706; }
.badge-info     { background: #cffafe; color: #0891b2; }
.badge-primary  { background: #dbeafe; color: #2563eb; }
.badge-secondary{ background: var(--bg); color: var(--text-muted); }
.badge-purple   { background: #f3e8ff; color: #7c3aed; }

/* ── Alerts / Flash ── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 12px 16px;
  border-radius: var(--radius);
  border: 1px solid;
  margin-bottom: 16px;
  font-size: 13px;
}
.alert-success { background: #f0fdf4; border-color: #bbf7d0; color: #166534; }
.alert-danger  { background: #fef2f2; border-color: #fecaca; color: #991b1b; }
.alert-warning { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.alert-info    { background: #eff6ff; border-color: #bfdbfe; color: #1e40af; }
.alert svg { width: 16px; height: 16px; flex-shrink: 0; margin-top: 2px; }
.alert-close { margin-left: auto; cursor: pointer; opacity: .6; }
.alert-close:hover { opacity: 1; }

/* ── Pagination ── */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  flex-wrap: wrap;
}
.page-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 32px;
  height: 32px;
  padding: 0 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  color: var(--text-muted);
  text-decoration: none;
  transition: var(--transition);
  background: var(--surface);
}
.page-link:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-light); text-decoration: none; }
.page-link.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.page-link.disabled { opacity: .4; pointer-events: none; }

/* ── Search & Filters bar ── */
.filters-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 14px 20px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  margin-bottom: 16px;
}
.filter-group { display: flex; align-items: center; gap: 6px; }
.filter-label { font-size: 12px; color: var(--text-muted); white-space: nowrap; font-weight: 500; }
.search-input-wrap { position: relative; }
.search-input-wrap svg {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--text-light); pointer-events: none;
}
.search-input { padding-left: 32px; }

/* ── Tabs ── */
.tab-nav {
  display: flex;
  gap: 0;
  border-bottom: 2px solid var(--border);
  margin-bottom: 20px;
}
.tab-btn {
  padding: 10px 18px;
  border: none;
  background: transparent;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  transition: var(--transition);
}
.tab-btn:hover { color: var(--primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }
.tab-content > div { display: none; }
.tab-content > div.active { display: block; }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.55);
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  transform: scale(.96);
  transition: transform .2s;
}
.modal-overlay.open .modal { transform: scale(1); }
.modal-lg { max-width: 760px; }
.modal-xl { max-width: 1100px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}
.modal-title { font-size: 16px; font-weight: 600; }
.modal-close { background: none; border: none; cursor: pointer; padding: 4px; color: var(--text-muted); transition: var(--transition); }
.modal-close:hover { color: var(--danger); }
.modal-body { padding: 20px; }
.modal-footer {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ── Dropdown ── */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute;
  right: 0; top: calc(100% + 6px);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 160px;
  z-index: 500;
  display: none;
  overflow: hidden;
}
.dropdown-menu.open { display: block; }
.dropdown-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  font-size: 13px;
  color: var(--text);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  border: none;
  background: none;
  width: 100%;
  text-align: left;
}
.dropdown-item:hover { background: var(--bg); text-decoration: none; }
.dropdown-item.danger { color: var(--danger); }
.dropdown-item.danger:hover { background: #fee2e2; }
.dropdown-divider { border: none; border-top: 1px solid var(--border); margin: 4px 0; }

/* ── Code / JSON ── */
.code-block {
  background: #0d1117;
  color: #c9d1d9;
  padding: 14px 16px;
  border-radius: var(--radius);
  font-family: 'JetBrains Mono', 'Fira Code', monospace;
  font-size: 12.5px;
  overflow-x: auto;
  line-height: 1.7;
}

/* ── Avatar initials ── */
.avatar {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 700;
  font-size: 12px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

/* ── Empty state ── */
.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 48px; margin-bottom: 12px; }
.empty-state h3 { font-size: 17px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
.empty-state p { font-size: 13px; margin-bottom: 20px; }

/* ── Spinner ── */
.spinner {
  width: 20px; height: 20px;
  border: 2.5px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin .65s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-overlay {
  position: absolute; inset: 0;
  background: rgba(255,255,255,.7);
  display: flex; align-items: center; justify-content: center;
  border-radius: inherit;
  z-index: 10;
}

/* ── Toast notifications ── */
#toast-container {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 13px;
  max-width: 340px;
  animation: slideIn .25s ease;
}
.toast.hide { animation: slideOut .2s ease forwards; }
.toast-success { border-left: 4px solid var(--success); }
.toast-error   { border-left: 4px solid var(--danger); }
.toast-warning { border-left: 4px solid var(--warning); }
.toast-info    { border-left: 4px solid var(--info); }
@keyframes slideIn  { from { opacity:0; transform: translateX(20px); } to { opacity:1; transform: translateX(0); } }
@keyframes slideOut { to   { opacity:0; transform: translateX(20px); } }

/* ── Scenario Builder ── */
#scenario-canvas-wrap {
  position: relative;
  background: #f8fafc;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  cursor: grab;
}
#scenario-canvas-wrap:active { cursor: grabbing; }
#scenario-canvas { display: block; }
.block-palette {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px;
  max-height: 70vh;
  overflow-y: auto;
}
.block-palette-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  cursor: grab;
  transition: var(--transition);
  font-size: 13px;
  font-weight: 450;
  color: var(--text);
  margin-bottom: 4px;
}
.block-palette-item:hover { background: var(--bg); }
.block-palette-item:active { cursor: grabbing; }
.block-palette-dot {
  width: 12px; height: 12px;
  border-radius: 3px;
  flex-shrink: 0;
}

/* ── Chat/Message thread ── */
.message-thread { display: flex; flex-direction: column; gap: 12px; }
.message-bubble {
  display: flex;
  gap: 10px;
  max-width: 78%;
}
.message-bubble.outgoing { flex-direction: row-reverse; align-self: flex-end; }
.message-content {
  background: var(--bg);
  border-radius: 12px 12px 12px 4px;
  padding: 10px 14px;
  font-size: 13.5px;
  line-height: 1.55;
  word-break: break-word;
}
.message-bubble.outgoing .message-content {
  background: var(--primary);
  color: #fff;
  border-radius: 12px 12px 4px 12px;
}
.message-meta {
  font-size: 11px;
  color: var(--text-light);
  margin-top: 3px;
}
.message-bubble.outgoing .message-meta { text-align: right; color: rgba(255,255,255,.65); }

/* ── Utilities ── */
.text-muted    { color: var(--text-muted) !important; }
.text-danger   { color: var(--danger) !important; }
.text-success  { color: var(--success) !important; }
.text-primary  { color: var(--primary) !important; }
.text-center   { text-align: center; }
.text-right    { text-align: right; }
.text-sm       { font-size: 12px; }
.text-xs       { font-size: 11px; }
.font-mono     { font-family: 'JetBrains Mono', monospace; }
.font-bold     { font-weight: 700; }
.font-semibold { font-weight: 600; }
.d-flex        { display: flex; }
.align-items-center { align-items: center; }
.justify-between    { justify-content: space-between; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mb-1  { margin-bottom: 4px; }
.mb-2  { margin-bottom: 8px; }
.mb-3  { margin-bottom: 16px; }
.mb-4  { margin-bottom: 24px; }
.mt-2  { margin-top: 8px; }
.mt-3  { margin-top: 16px; }
.mt-4  { margin-top: 24px; }
.p-2   { padding: 8px; }
.p-3   { padding: 16px; }
.w-100 { width: 100%; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }

/* ── Message bubbles ── */
.message-in,
.message-out {
  display: inline-block;
  padding: 8px 12px;
  border-radius: 12px;
  font-size: 13px;
  line-height: 1.5;
}
.message-in {
  background: var(--surface);
  border: 1px solid var(--border);
  border-bottom-left-radius: 2px;
  color: var(--text);
}
.message-out {
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 2px;
}

/* ── Responsive ── */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main { margin-left: 0; }
  .topbar-menu-btn { display: flex; }
  .page-content { padding: 16px; }
  .form-row { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .page-header { flex-direction: column; }
  .page-header-actions { width: 100%; }
  .filters-bar { flex-direction: column; align-items: stretch; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
}

/* ── Mobile adaptation (core + every plugin page) ── */
.main, .page-content { min-width: 0; }
.page-content, .card, .card-body { overflow-wrap: anywhere; }
.sidebar-backdrop {
  display: none; position: fixed; inset: 0; background: rgba(15,23,42,.5); z-index: 99;
}
@media (max-width: 768px) {
  body.sidebar-open { overflow: hidden; }
  body.sidebar-open .sidebar-backdrop { display: block; }
  .sidebar { z-index: 100; width: min(82vw, 300px); transition: transform .2s ease; box-shadow: none; }
  .sidebar.open { box-shadow: 0 0 40px rgba(0,0,0,.35); }
  .nav-item { min-height: 44px; }
  .topbar { padding: 0 12px; gap: 8px; }
  .topbar-menu-btn { padding: 10px; margin-left: -6px; }
  .topbar-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
  .page-content { padding: 12px; }
  .page-header { gap: 10px; margin-bottom: 14px; }
  .page-header-actions .btn { flex: 1 1 auto; justify-content: center; }
  .card-header { flex-wrap: wrap; gap: 8px; padding: 12px; }
  .card-body { padding: 12px; }
  /* any table scrolls inside its card instead of stretching the page */
  table.table { display: block; max-width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .table th, .table td { padding: 10px 12px; }
  .table-wrapper { -webkit-overflow-scrolling: touch; }
  .form-control, select.form-control, textarea.form-control, input.form-control { font-size: 16px; min-height: 42px; }
  .btn { min-height: 40px; }
  .btn-sm { min-height: 36px; }
  .form-row, .form-grid, .grid-2, .grid-3 { grid-template-columns: 1fr !important; }
  .filters-bar > * { width: 100%; }
  .filters-bar .form-control, .filters-bar select { min-width: 0; width: 100%; }
  .modal-overlay { padding: 8px; align-items: flex-end; }
  .modal, .modal-lg, .modal-xl { width: 100%; max-width: 100%; max-height: 92vh; overflow-y: auto; }
  .modal-body { padding: 14px; }
  .tabs, .tab-list { overflow-x: auto; flex-wrap: nowrap; scrollbar-width: none; }
  .tabs > *, .tab-list > * { flex: 0 0 auto; white-space: nowrap; }
  pre, code { white-space: pre-wrap; word-break: break-word; }
  .dropdown-menu { max-width: calc(100vw - 24px); }
  .alert { padding-right: 36px; }
  .message { max-width: 90%; }
}
@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .page-header-left h1 { font-size: 20px; }
  .login-card, .auth-card { width: 100%; max-width: 100%; border-radius: 0; }
}
@media (max-width: 900px) {
  /* inline fixed-column grids used by core pages collapse to one column */
  [style*="grid-template-columns"]:not([style*="auto-fill"]):not(.stats-grid):not([style*="repeat(2"]) { grid-template-columns: minmax(0, 1fr) !important; }
  [style*="grid-template-columns"] > * { min-width: 0; }
}
@media (max-width: 768px) {
  .table td, .table th { overflow-wrap: normal; word-break: normal; }
  .table td { min-width: 64px; }
}

/* ── Sidebar: plugin folders ── */
.nav-folder-head { width: 100%; background: none; border: 0; border-left: 3px solid transparent; font: inherit; text-align: left; }
.nav-folder-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav-chevron { width: 14px; height: 14px; color: var(--sidebar-icon); transition: transform .15s ease; flex-shrink: 0; }
.nav-folder.open > .nav-folder-head .nav-chevron { transform: rotate(90deg); }
.nav-folder.open > .nav-folder-head { color: #fff; }
.nav-sub { display: none; margin: 0 0 4px 0; }
.nav-folder.open > .nav-sub { display: block; }
.nav-sub-item { padding: 7px 20px 7px 49px; font-size: 13px; position: relative; }
.nav-sub-item::before { content: ''; position: absolute; left: 29px; top: 0; bottom: 0; width: 1px; background: rgba(255,255,255,.10); }
.nav-sub-item.active::before { background: var(--sidebar-active-border); }
