/* =====================================================================
   UNIFIED ADMIN DESIGN SYSTEM
   Compact, professional, data-dense interface (Grafana/Proxmox inspired).
   Loaded AFTER base + mobile-responsive, so these rules win on equal
   specificity. Targets shared Bootstrap classes used across all pages.
   ===================================================================== */

:root {
  --bg:            #0d1117;
  --bg-elev:       #161b22;
  --bg-elev-2:     #1c2128;
  --bg-elev-3:     #1b1f24;
  --bg-elev-4:     #2b3035;
  --border:        #30363d;
  --border-soft:   #21262d;
  --text:          #c9d1d9;
  --text-bright:   #e6edf3;
  --text-dim:      #8b949e;
  --text-faint:    #6e7681;
  --accent:        #58a6ff;
  --accent-green:  #238636;
  --accent-green-h:#2ea043;
  --danger:        #f85149;
  --warn:          #d29922;
  --white:         #ffffff;
  --green:         #3fb950;
  --amber:         #e3b341;
  --discord:       #5865f2;
  --navy:          #131c2e;
  --slate:         #4a5568;
  --slate-bright:  #e2e8f0;
  --grad-1:        #667eea;
  --grad-2:        #764ba2;
  --blue-soft:     #3390ec;
  --gap:           0.625rem;     /* unified spacing unit */
  --radius:        6px;
}

* { box-sizing: border-box; }

html, body { max-width: 100%; overflow-x: hidden; }

body {
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;          /* 14px base */
  line-height: 1.4;
}

/* ----- Headings: tighter, consistent ----- */
h1, .h1 { font-size: 1.4rem; font-weight: 600; margin: 0 0 .5rem; }
h2, .h2 { font-size: 1.2rem; font-weight: 600; margin: 0 0 .4rem; }
h3, .h3 { font-size: 1.05rem; font-weight: 600; margin: 0 0 .35rem; }
h4, .h4, h5, .h5 { font-size: .95rem; font-weight: 600; margin: 0 0 .3rem; }
h6, .h6 { font-size: .875rem; font-weight: 600; margin: 0 0 .3rem; }
p { margin-bottom: .5rem; }

.text-muted { color: var(--text-dim) !important; }
small, .small { font-size: .8rem; }

/* =====================================================================
   SIDEBAR
   Desktop:  260px expanded, 60px collapsed
   Mobile:   overlay drawer ≤992px, no collapsed state
   ===================================================================== */

:root {
  --sb-w:           260px;
  --sb-w-collapsed: 60px;
  --sb-w-mobile:    min(280px, 85vw);
  --sb-transition:  .22s cubic-bezier(.4,0,.2,1);
}

/* ── Base ───────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  width: var(--sb-w);
  display: flex;
  flex-direction: column;
  background: var(--bg-elev);
  border-right: 1px solid var(--border);
  z-index: 1040;
  transition: width var(--sb-transition), transform var(--sb-transition);
  will-change: width, transform;
}

/* ── Header ─────────────────────────────────────────────────────── */
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: .5rem .6rem;
  min-height: 48px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar-brand {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .88rem;
  font-weight: 700;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  flex: 1 1 auto;
  min-width: 0;
}
.sidebar-brand i { color: var(--accent); font-size: 1rem; flex: 0 0 auto; }
.sidebar-toggle {
  flex: 0 0 auto;
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer; font-size: .8rem;
  transition: color .15s, border-color .15s, transform var(--sb-transition), background .15s;
}
.sidebar-toggle:hover { color: var(--accent); border-color: var(--accent); }
.sidebar-close {
  flex: 0 0 auto;
  width: 28px; height: 28px;
  display: none; align-items: center; justify-content: center;
  background: var(--bg-elev-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text-dim);
  cursor: pointer; font-size: .8rem;
  transition: color .15s, background .15s;
}
.sidebar-close:hover { color: var(--accent); }

/* ── Nav sections ───────────────────────────────────────────────── */
.sidebar-nav {
  flex: 1 1 0;
  min-height: 0;
  padding: .25rem .4rem;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.sidebar-section {
  padding: .45rem .5rem .12rem;
  font-size: .58rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-faint);
  user-select: none;
}

/* ── Nav links ──────────────────────────────────────────────────── */
.sidebar .nav-link {
  position: relative;
  display: flex;
  align-items: center;
  gap: .55rem;
  min-height: 34px;
  padding: 0 .5rem;
  margin-bottom: .04rem;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: .82rem;
  font-weight: 500;
  white-space: nowrap;
  text-decoration: none;
  transition: background .15s, color .15s, box-shadow .15s;
}
.sidebar .nav-link > i:first-child {
  width: 1.1rem;
  text-align: center;
  font-size: .86rem;
  flex: 0 0 auto;
  transition: color .15s;
}
.sidebar .nav-link span {
  flex: 1 1 auto;
  overflow: hidden;
  text-overflow: ellipsis;
}
.sidebar .nav-link:hover {
  background: var(--bg-elev-2);
  color: var(--text);
}
.sidebar .nav-link.active {
  color: var(--accent);
  background: rgba(88,166,255,.10);
  font-weight: 600;
  box-shadow: inset 3px 0 0 var(--accent);
}
.sidebar .nav-link.active > i:first-child { color: var(--accent); }

/* OCR branded */
.sidebar .nav-link-feature > i:first-child { color: #79c0ff; }
.sidebar .nav-link-feature.active > i:first-child { color: #58a6ff; }

/* ── Submenu ────────────────────────────────────────────────────── */
.sub-caret {
  margin-left: auto; font-size: .6rem;
  transition: transform var(--sb-transition);
  opacity: .5;
}
.sidebar .nav-link[aria-expanded="true"] .sub-caret { transform: rotate(180deg); opacity: 1; }
.sidebar .collapse .nav-link.sub-link {
  min-height: 30px; padding-left: 2.2rem; font-size: .78rem;
}
.sidebar .collapse .nav-link.sub-link > i:first-child { font-size: .72rem; }

/* ── Footer ─────────────────────────────────────────────────────── */
.sidebar-footer {
  padding: .35rem .45rem;
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: .3rem;
  flex-shrink: 0;
}
.profile-block {
  display: flex; align-items: center; gap: .4rem; min-width: 0;
}
.profile-avatar {
  flex: 0 0 auto;
  width: 28px; height: 28px;
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--accent), #1f6feb);
  color: #fff;
  font-weight: 700; font-size: .72rem;
}
.profile-meta { min-width: 0; line-height: 1.1; overflow: hidden; }
.profile-name {
  font-size: .74rem; font-weight: 600; color: var(--text);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.profile-role { font-size: .62rem; color: var(--text-faint); }

.sidebar-tools {
  display: flex; align-items: center; gap: .25rem;
}
.workmode-toggle {
  flex: 0 0 auto;
  width: 28px; height: 28px;
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--bg-elev-2); border: 1px solid var(--border);
  color: var(--text-dim); border-radius: var(--radius);
  cursor: pointer; font-size: .8rem;
  transition: color .15s, border-color .15s;
}
.workmode-toggle:hover { color: var(--accent); border-color: var(--accent); }
body.work-mode .workmode-toggle { color: var(--accent-green); border-color: var(--accent-green); }
.seg-lang {
  display: inline-flex;
  border: 1px solid var(--border); border-radius: var(--radius);
  overflow: hidden; flex: 1 1 auto;
}
.seg-lang .seg-btn {
  flex: 1 1 auto;
  background: transparent; border: none;
  color: var(--text-dim);
  font-size: .7rem; font-weight: 600;
  padding: .2rem .12rem; cursor: pointer;
  transition: background .15s, color .15s;
}
.seg-lang .seg-btn:hover { color: var(--text); }
.seg-lang .seg-btn.active { background: var(--accent); color: #fff; }

.sidebar-logout {
  min-height: 30px !important;
  text-decoration: none;
}
.sidebar-logout:hover {
  background: rgba(248,81,73,.10) !important;
  color: #f85149 !important;
}

/* =====================================================================
   DESKTOP COLLAPSED (body.sidebar-collapsed)
   Width → 60px. Only icons, avatar, logout icon, lang icon visible.
   ===================================================================== */
body.sidebar-collapsed .sidebar {
  width: var(--sb-w-collapsed);
}
body.sidebar-collapsed main {
  margin-left: var(--sb-w-collapsed) !important;
}
body.sidebar-collapsed .sidebar-header {
  justify-content: center;
  padding: .5rem 0;
}
body.sidebar-collapsed .sidebar-brand,
body.sidebar-collapsed .sidebar-close { display: none; }
body.sidebar-collapsed .sidebar-toggle i { transform: rotate(180deg); }

/* Nav: only icons, centered */
body.sidebar-collapsed .sidebar .nav-link {
  justify-content: center;
  padding: 0;
  gap: 0;
  min-height: 34px;
}
body.sidebar-collapsed .sidebar .nav-link > i:first-child {
  width: auto; font-size: .92rem;
}
body.sidebar-collapsed .sidebar .nav-link span,
body.sidebar-collapsed .sidebar .sub-caret { display: none; }
body.sidebar-collapsed .sidebar-section { display: none; }

/* Footer: avatar + lang icon + logout icon, centered */
body.sidebar-collapsed .sidebar-footer {
  align-items: center;
  gap: .35rem;
}
body.sidebar-collapsed .profile-meta { display: none; }
body.sidebar-collapsed .seg-lang { display: none; }
body.sidebar-collapsed .workmode-toggle { display: none; }
body.sidebar-collapsed .sidebar-tools { justify-content: center; }
body.sidebar-collapsed .sidebar-logout {
  justify-content: center; padding: 0; gap: 0;
}
body.sidebar-collapsed .sidebar-logout span { display: none; }

/* Tooltips on hover */
body.sidebar-collapsed .sidebar .nav-link::after,
body.sidebar-collapsed .sidebar-logout::after {
  content: attr(data-label);
  position: absolute;
  left: calc(100% + 8px);
  top: 50%;
  transform: translateY(-50%) translateX(-4px);
  background: var(--bg-elev-2); color: var(--text);
  padding: .25rem .45rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  white-space: nowrap;
  font-size: .74rem; font-weight: 500;
  z-index: 1100;
  opacity: 0; pointer-events: none;
  transition: opacity .15s, transform .15s;
  box-shadow: 0 4px 12px rgba(0,0,0,.35);
}
body.sidebar-collapsed .sidebar .nav-link:hover::after,
body.sidebar-collapsed .sidebar-logout:hover::after {
  opacity: 1;
  transform: translateY(-50%) translateX(0);
}

/* Flyout submenu */
body.sidebar-collapsed .sidebar .has-submenu { position: relative; }
body.sidebar-collapsed .sidebar .has-submenu .collapse {
  position: absolute;
  left: calc(100% + 8px); top: 0;
  width: 200px;
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: .3rem;
  box-shadow: 0 8px 22px rgba(0,0,0,.4);
  display: none !important;
  z-index: 1200;
}
body.sidebar-collapsed .sidebar .has-submenu:hover .collapse { display: block !important; }
body.sidebar-collapsed .sidebar .has-submenu .collapse .nav-link.sub-link { padding-left: .6rem; }
body.sidebar-collapsed .sidebar .has-submenu .collapse .nav-link.sub-link span { display: inline !important; }

/* =====================================================================
   DESKTOP (≥993px): sidebar always visible, main offset
   ===================================================================== */
@media (min-width: 993px) {
  main {
    margin-left: var(--sb-w) !important;
    padding: .85rem 1.1rem !important;
    transition: margin-left var(--sb-transition);
  }
  .sidebar {
    width: var(--sb-w) !important;
    transform: translateX(0) !important;
  }
  body.sidebar-collapsed .sidebar {
    width: var(--sb-w-collapsed) !important;
  }
  body.sidebar-collapsed main {
    margin-left: var(--sb-w-collapsed) !important;
  }
  .mobile-topbar,
  .mobile-hamburger,
  .sidebar-overlay,
  .sidebar-close { display: none !important; }
}

/* =====================================================================
   MOBILE TOPBAR (≤992px)
   ===================================================================== */
.mobile-topbar { display: none; }
@media (max-width: 992px) {
  :root { --topbar-h: 50px; }
  .mobile-topbar {
    display: flex; align-items: center; gap: .55rem;
    position: fixed; top: 0; left: 0; right: 0;
    height: var(--topbar-h);
    padding: 0 .65rem;
    padding-top: env(safe-area-inset-top, 0px);
    background: var(--bg-elev);
    border-bottom: 1px solid var(--border);
    z-index: 1030;
  }
  .mobile-hamburger {
    flex: 0 0 auto;
    width: 36px; height: 36px;
    display: inline-flex; align-items: center; justify-content: center;
    background: var(--bg-elev-2); border: 1px solid var(--border);
    color: var(--text); border-radius: var(--radius);
    cursor: pointer; font-size: .9rem;
    transition: background .15s;
    -webkit-tap-highlight-color: transparent;
  }
  .mobile-hamburger:active { background: var(--border); }
  .mobile-page-title {
    flex: 1 1 auto;
    font-size: .9rem; font-weight: 700; color: var(--text);
    overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  }
  main {
    margin-left: 0 !important;
    padding: calc(var(--topbar-h) + env(safe-area-inset-top, 0px) + .5rem) .65rem .65rem !important;
    width: 100%;
  }
}

/* =====================================================================
   MOBILE DRAWER (≤992px)
   Overlay + slide-in from left. No collapsed state on mobile.
   ===================================================================== */
.sidebar-overlay {
  display: none;
  position: fixed; inset: 0;
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  z-index: 1035;
  opacity: 0;
  transition: opacity .22s;
}
.sidebar-overlay.show { display: block; opacity: 1; }

@media (max-width: 992px) {
  .sidebar {
    width: var(--sb-w-mobile) !important;
    transform: translateX(-100%);
    box-shadow: none;
  }
  .sidebar.show {
    transform: translateX(0);
    box-shadow: 4px 0 20px rgba(0,0,0,.4);
  }
  .sidebar-close { display: inline-flex; }

  /* Mobile: NO collapsed state — always full drawer */
  body.sidebar-collapsed .sidebar { width: var(--sb-w-mobile) !important; }
  body.sidebar-collapsed main { margin-left: 0 !important; }
  body.sidebar-collapsed .sidebar-brand { display: flex !important; }
  body.sidebar-collapsed .sidebar .nav-link span { display: inline !important; }
  body.sidebar-collapsed .sidebar .sub-caret { display: inline !important; }
  body.sidebar-collapsed .sidebar-section { display: block !important; }
  body.sidebar-collapsed .sidebar-header { justify-content: space-between; padding: .5rem .6rem; }
  body.sidebar-collapsed .sidebar .nav-link { justify-content: flex-start; padding: 0 .5rem; gap: .55rem; }
  body.sidebar-collapsed .sidebar .nav-link > i:first-child { width: 1.1rem; font-size: .86rem; }
  body.sidebar-collapsed .sidebar-footer { align-items: stretch; }
  body.sidebar-collapsed .profile-meta { display: block !important; }
  body.sidebar-collapsed .seg-lang { display: inline-flex !important; }
  body.sidebar-collapsed .workmode-toggle { display: inline-flex !important; }
  body.sidebar-collapsed .sidebar-tools { justify-content: flex-start; }
  body.sidebar-collapsed .sidebar-logout { justify-content: flex-start; padding: 0 .5rem; }
  body.sidebar-collapsed .sidebar-logout span { display: inline !important; }
  body.sidebar-collapsed .sidebar .has-submenu .collapse { position: static; width: 100%; box-shadow: none; border: 0; padding: 0; display: block !important; }
  body.sidebar-collapsed .sidebar .has-submenu .collapse .nav-link.sub-link span { display: inline !important; }
}

/* =====================================================================
   CARDS  (~38% more compact)
   ===================================================================== */
.card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: var(--gap);
  transition: none;
}
.card:hover { transform: none; box-shadow: none; }
.card-header {
  background: var(--bg-elev-2);
  border-bottom: 1px solid var(--border);
  padding: .5rem .75rem;
  font-size: .9rem; font-weight: 600;
  display: flex; align-items: center; justify-content: space-between; gap: .5rem;
}
.card-body { padding: .75rem; }
.card-footer { background: transparent; border-top: 1px solid var(--border); padding: .5rem .75rem; }

/* statistic mini-cards */
.card .h3, .card .h4 { font-size: 1.35rem; font-weight: 700; }
.card .h5 { font-size: 1rem; }
.card .stat-label { font-size: .75rem; color: var(--text-dim); }

/* =====================================================================
   TABLES  (compact, sticky header, readable)
   ===================================================================== */
.table { color: var(--text); font-size: .85rem; margin-bottom: 0; }
.table > :not(caption) > * > * { padding: .35rem .6rem; background: transparent; }
.table thead th {
  position: sticky; top: 0; z-index: 5;
  background: var(--bg-elev-2);
  color: var(--text-dim);
  font-weight: 600; font-size: .78rem; text-transform: uppercase; letter-spacing: .02em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap; vertical-align: middle;
}
.table tbody tr { border-bottom: 1px solid var(--border-soft); }
.table tbody tr:hover { background: rgba(88,166,255,.07); }
.table tbody td { vertical-align: middle; }
.table-sm > :not(caption) > * > * { padding: .25rem .5rem; }

/* Sticky wrapper (desktop): cap height, inner scroll, frozen header.
   Applied to .table-responsive (and the explicit .sticky-head helper). */
@media (min-width: 1025px) {
  .table-responsive {
    max-height: calc(100vh - 170px);
    overflow: auto;
  }
}
.table-responsive thead th {
  position: sticky; top: 0; z-index: 6;
  background: var(--bg-elev-2);
  box-shadow: inset 0 -1px 0 var(--border);
}

/* checkboxes smaller */
.table .form-check-input, .form-check-input { width: 1rem; height: 1rem; margin-top: 0; cursor: pointer; }
.form-check { min-height: auto; margin-bottom: 0; }

/* compact action buttons inside tables */
.btn-action { padding: .2rem .45rem; font-size: .8rem; line-height: 1.2; }

/* =====================================================================
   BUTTONS  (unified height/look, square-ish action buttons)
   ===================================================================== */
.btn {
  --bs-btn-padding-y: .35rem; --bs-btn-padding-x: .7rem;
  font-size: .85rem; border-radius: var(--radius); font-weight: 500;
  display: inline-flex; align-items: center; justify-content: center; gap: .35rem;
  transition: background .15s ease, border-color .15s ease, color .15s ease;
}
.btn:hover { transform: none; box-shadow: none; }
.btn-sm { --bs-btn-padding-y: .2rem; --bs-btn-padding-x: .5rem; font-size: .8rem; }
.btn-lg { --bs-btn-padding-y: .5rem; --bs-btn-padding-x: 1rem; font-size: .95rem; }
.btn .fa-fw { width: auto; }
.btn-primary { background: var(--accent-green); border-color: var(--accent-green); color: #fff; }
.btn-primary:hover { background: var(--accent-green-h); border-color: var(--accent-green-h); color: #fff; }
.btn-outline-secondary { color: var(--text-dim); border-color: var(--border); }
.btn-outline-secondary:hover { color: var(--text); background: var(--bg-elev-2); border-color: var(--text-faint); }
.btn-outline-danger { color: var(--danger); border-color: rgba(248,81,73,.4); }
.btn-outline-danger:hover { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-outline-primary { color: var(--accent); border-color: rgba(88,166,255,.4); }
.btn-outline-primary:hover { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-success { background: var(--accent-green); border-color: var(--accent-green); }
.btn-warning, .btn-info { color: #1c2128; }

/* =====================================================================
   FORMS  (compact, inline when room)
   ===================================================================== */
.form-control, .form-select {
  background: var(--bg); border-color: var(--border); color: var(--text);
  border-radius: var(--radius);
  padding: .3rem .55rem; font-size: .85rem; height: calc(1.6em + .6rem + 2px);
  min-height: 0;
}
.form-control:focus, .form-select:focus { background: var(--bg); border-color: var(--accent); color: var(--text); box-shadow: 0 0 0 .15rem rgba(88,166,255,.2); }
.form-label { margin-bottom: .2rem; font-size: .8rem; color: var(--text-dim); font-weight: 500; }
.form-text { font-size: .75rem; color: var(--text-faint); margin-top: .15rem; }
.input-group-text { background: var(--bg-elev-2); border-color: var(--border); color: var(--text-dim); font-size: .8rem; padding: .3rem .55rem; }
.form-check-label { font-size: .85rem; }

/* Inline filter row */
.filter-bar {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: .5rem;
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius);
  padding: .5rem .65rem; margin-bottom: var(--gap);
}
.filter-bar .filter-field { display: flex; flex-direction: column; gap: .15rem; }
.filter-bar .form-control, .filter-bar .form-select { width: auto; min-width: 9rem; }
.filter-bar .filter-actions { display: flex; gap: .4rem; margin-left: auto; align-items: flex-end; }

/* =====================================================================
   STICKY PAGE TOOLBAR  (title + actions pinned on scroll)
   ===================================================================== */
.page-head {
  position: sticky; top: 0; z-index: 20;
  background: var(--bg); padding: .5rem 0 .4rem; margin-bottom: .5rem;
  border-bottom: 1px solid var(--border-soft);
  display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
}
.page-head h1, .page-head h2 { margin: 0; }

/* =====================================================================
   MODALS
   ===================================================================== */
.modal-content { background: var(--bg-elev); border: 1px solid var(--border); border-radius: var(--radius); max-height: calc(100vh - 2rem); overflow: hidden; }
.modal-header { padding: .6rem .85rem; border-bottom: 1px solid var(--border); }
.modal-header .modal-title { font-size: .95rem; font-weight: 600; }
.modal-body { padding: .85rem; overflow-y: auto; }
.modal-footer { padding: .5rem .85rem; border-top: 1px solid var(--border); gap: .4rem; }
.modal-backdrop { background: rgba(1,4,9,.7); }

/* =====================================================================
   MOBILE MODALS — full-screen "app-like" layout (≤768px)
   Header ≤56px, body scrolls, footer pinned, 90vh max.
   callModal: segmented control, 2-col grid, compact info cards.
   ===================================================================== */
@media (max-width: 768px) {
  .modal { padding: 0 !important; }
  .modal-dialog {
    margin: 0 !important;
    max-width: 100% !important;
    width: 100% !important;
    height: auto;
    max-height: 90vh;
    display: flex;
    flex-direction: column;
  }
  .modal-content {
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    max-height: 90vh;
    border: 0;
    border-radius: 14px;
    overflow: hidden;
    background: var(--bg-elev);
    max-width: 100%;
  }
  /* Header — pinned, compact ≤56px */
  .modal-header {
    position: sticky; top: 0; z-index: 3;
    flex-shrink: 0;
    display: flex; align-items: center; justify-content: space-between;
    gap: .5rem;
    padding: .5rem .8rem !important;
    padding-top: calc(.5rem + env(safe-area-inset-top, 0px)) !important;
    min-height: 52px; max-height: 56px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-elev);
  }
  .modal-header .modal-title {
    font-size: .92rem !important;
    font-weight: 700 !important;
    margin: 0; line-height: 1.2;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  }
  .modal-header .btn-close { margin: 0; padding: .4rem; flex-shrink: 0; }

  /* Body — the ONLY scroll region */
  .modal-body {
    flex: 1 1 auto;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch;
    padding: .65rem .8rem !important;
    padding-bottom: .75rem !important;
  }

  /* Footer — pinned, always visible */
  .modal-footer {
    position: sticky; bottom: 0; z-index: 3;
    flex-shrink: 0;
    display: flex !important; gap: .5rem !important;
    padding: .55rem .8rem !important;
    padding-bottom: calc(.55rem + env(safe-area-inset-bottom, 0px)) !important;
    border-top: 1px solid var(--border);
    background: var(--bg-elev);
  }
  .modal-footer > * { margin: 0 !important; }
  .modal-footer .btn {
    flex: 1 1 0; width: 100%;
    height: 46px; min-height: 46px;
    font-size: .9rem; font-weight: 600;
    display: inline-flex; align-items: center; justify-content: center;
    gap: .35rem;
  }

  /* Inputs / textareas: full width, no horizontal scroll */
  .modal-body .form-control,
  .modal-body .form-select,
  .modal-body .input-group .form-control,
  .modal-body .input-group .input-group-text {
    min-height: 44px; font-size: .92rem;
  }
  .modal-body textarea.form-control { min-height: 120px; resize: vertical; }
  .modal-body .form-control,
  .modal-body textarea.form-control { width: 100%; }

  /* ── callModal: Bulk info — compact ──────────────────────────── */
  .modal-body #callBulkInfo {
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .55rem .7rem;
  }
  .call-bulk-count {
    font-size: .85rem; font-weight: 600; color: var(--text);
    margin-bottom: .45rem;
  }

  /* ── Segmented control for send mode ────────────────────────── */
  .call-mode-segmented {
    display: flex;
    background: var(--bg);
    border: 1px solid var(--border);
    border-radius: 10px;
    overflow: hidden;
    height: 42px;
  }
  .call-mode-option {
    flex: 1 1 0;
    display: flex; align-items: center; justify-content: center;
    font-size: .82rem; font-weight: 600;
    color: var(--text-dim);
    cursor: pointer;
    transition: background .18s, color .18s;
    user-select: none;
    padding: 0 .4rem;
  }
  .call-mode-option:hover { color: var(--text); background: var(--bg-elev-2); }
  .call-mode-option.active {
    background: var(--accent);
    color: #fff;
    box-shadow: 0 1px 4px rgba(88,166,255,.25);
  }
  .call-mode-option + .call-mode-option {
    border-left: 1px solid var(--border);
  }
  .call-mode-hint {
    font-size: .72rem; color: var(--text-faint);
    margin-top: .35rem; line-height: 1.35;
  }

  /* ── callModal: Single info card — compact ───────────────────── */
  .modal-body #callSingleInfo {
    background: var(--bg-elev-2);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: .55rem .7rem;
    font-size: .85rem;
  }
  .modal-body #callSingleInfo > div { margin-bottom: .12rem; }
  .modal-body #callSingleInfo > div:last-child { margin-bottom: 0; }

  /* ── Template grid: 2 columns ────────────────────────────────── */
  .call-templates-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: .4rem;
  }
  .call-templates-grid > .btn {
    width: 100% !important;
    margin: 0 !important;
    min-height: 44px; height: 44px;
    display: inline-flex;
    align-items: center; justify-content: center;
    text-align: center;
    font-size: .82rem; font-weight: 500;
    white-space: nowrap;
    transition: background .15s, color .15s, box-shadow .15s, transform .15s;
  }
  /* Active template: subtle highlight + shadow + animation */
  .call-templates-grid > .btn.active,
  .call-templates-grid > .btn:active {
    box-shadow: 0 0 0 2px rgba(255,193,7,.3), 0 2px 8px rgba(255,193,7,.15);
    transform: scale(.97);
  }

  /* Legacy flex-wrap grid fallback for non-callModal template grids */
  .modal-body .d-flex.flex-wrap.gap-2 {
    display: grid !important;
    grid-template-columns: repeat(2, 1fr);
    gap: .4rem !important;
  }
  .modal-body .d-flex.flex-wrap.gap-2 > .btn {
    width: 100% !important;
    min-height: 44px;
    font-size: .82rem;
  }

  /* ── Collapsible variables hint ──────────────────────────────── */
  .modal-body details.vars-hint { margin-top: .35rem; }
  .modal-body details.vars-hint > summary {
    cursor: pointer; list-style: none;
    font-size: .78rem; font-weight: 600;
    color: var(--accent);
    padding: .3rem 0;
    user-select: none;
  }
  .modal-body details.vars-hint > summary::-webkit-details-marker { display: none; }
  .modal-body details.vars-hint > summary::before { content: ""; }
  .modal-body details.vars-hint .form-text { margin-top: .3rem; font-size: .75rem; }

  /* ── Export / wide modals ────────────────────────────────────── */
  .modal-dialog.modal-lg,
  .modal-dialog.modal-xl { max-width: 100% !important; }
}

/* Very narrow phones (≤420px): single-col grids, stack footer */
@media (max-width: 420px) {
  .call-templates-grid { grid-template-columns: 1fr; }
  .modal-body .d-flex.flex-wrap.gap-2 { grid-template-columns: 1fr; }
  .modal-footer { flex-direction: column; }
  .modal-footer .btn { width: 100%; }
  .call-mode-segmented { height: 40px; }
  .call-mode-option { font-size: .78rem; }
}

/* badges */
.badge { font-size: .72rem; font-weight: 500; padding: .2em .5em; border-radius: 4px; }

/* alerts tighter */
.alert { padding: .6rem .85rem; font-size: .85rem; border-radius: var(--radius); margin-bottom: var(--gap); }

/* progress */
.progress { height: 1.25rem; background: var(--bg-elev-2); border-radius: var(--radius); font-size: .75rem; }

/* =====================================================================
   WORK MODE  (global, from localStorage)
   Triggered by body.work-mode. Shrinks everything, hides secondary blocks.
   ===================================================================== */
body.work-mode { --gap: .4rem; --radius: 5px; font-size: .82rem; }
body.work-mode .card { margin-bottom: .4rem; }
body.work-mode .card-body { padding: .5rem .6rem; }
body.work-mode .card-header { padding: .35rem .6rem; }
body.work-mode .table { font-size: .8rem; }
body.work-mode .table > :not(caption) > * > * { padding: .22rem .45rem; }
body.work-mode main { padding: .6rem .75rem !important; }
body.work-mode h1, body.work-mode .h1 { font-size: 1.15rem; }
body.work-mode h2, body.work-mode .h2 { font-size: 1rem; }
body.work-mode .form-control, body.work-mode .form-select { padding: .22rem .45rem; font-size: .8rem; }
body.work-mode .sidebar .nav-link { padding: .35rem .6rem; }
body.work-mode .secondary-block, body.work-mode .hide-in-work { display: none !important; }


/* =====================================================================
   COMPACT MESSAGE TABLES  (Сообщения / Запланированные / Отправленные)
   Fixed layout, content column takes all spare width, sticky header,
   square equal action buttons, ellipsis + tooltip for long text.
   ===================================================================== */
.text-accent { color: var(--accent); }

.msg-table { table-layout: fixed; width: 100%; }
.msg-table th, .msg-table td {
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  vertical-align: middle;
}
/* Cells that may legitimately wrap (name + id, processor + time) */
.msg-table td.cell-wrap { white-space: normal; }

/* Column widths — Text column is auto (flexible), the rest are fixed. */
.msg-table .col-id      { width: 54px; }
.msg-table .col-type    { width: 104px; }
.msg-table .col-channel { width: 92px; }
.msg-table .col-topic   { width: 70px; }
.msg-table .col-text    { width: auto; }   /* главный приоритет */
.msg-table .col-time    { width: 138px; }
.msg-table .col-status  { width: 96px; }
.msg-table .col-author  { width: 118px; }
.msg-table .col-actions { width: 132px; }
.msg-table .col-from    { width: 158px; }
.msg-table .col-content { width: 320px; }
.msg-table .col-processor { width: 128px; }

/* Scheduled table: keep actions a touch wider for 3 buttons */
#scheduledTable .col-actions { width: 124px; }
#messagesTable .col-actions  { width: 150px; }  /* до 4 кнопок у pending */

/* Content cell (moderation): thumbnail + clamped text, no wrap blow-up */
.msg-table .content-cell { display: flex; gap: .5rem; align-items: center; min-width: 0; }
.msg-table .content-thumb {
  flex: 0 0 auto; width: 34px; height: 34px; border-radius: var(--radius);
  display: inline-flex; align-items: center; justify-content: center; color: #fff; font-size: .85rem;
}
.msg-table .content-thumb.bg-photo { background: linear-gradient(135deg,#667eea,#764ba2); }
.msg-table .content-thumb.bg-video { background: linear-gradient(135deg,#f093fb,#f5576c); }
.msg-table .content-thumb.bg-doc   { background: linear-gradient(135deg,#4facfe,#00f2fe); }
.msg-table .content-text { flex: 1 1 auto; min-width: 0; }

/* Universal clamp helper */
.cell-clamp {
  display: block; max-width: 100%; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap;
}

/* Action buttons: square, equal, no wrap, centered */
.msg-table .action-cell { display: inline-flex; gap: 3px; justify-content: center; flex-wrap: nowrap; }
.msg-table .btn-action {
  width: 28px; height: 28px; padding: 0; margin: 0;
  display: inline-flex; align-items: center; justify-content: center;
  flex: 0 0 auto;
}

/* Row highlight after opening from OCR center (?highlight=ID) */
.msg-table tr.row-highlight > td { background: rgba(210,153,34,.22) !important; }

/* Pinned header inside scroll container (desktop) */
@media (min-width: 1025px) {
  .msg-table thead th { position: sticky; top: 0; z-index: 6; background: var(--bg-elev-2); }
}

/* Secondary columns drop on narrow laptops to keep table on-screen */
@media (max-width: 1366px) {
  .msg-table .col-processor, .msg-table .col-author { display: none; }
}
@media (max-width: 1100px) {
  .msg-table .col-id, .msg-table .col-type, .msg-table .col-channel, .msg-table .col-topic { display: none; }
}

/* =====================================================================
   OCR CENTER
   ===================================================================== */
.ocr-dropzone { padding: 1.25rem !important; }
.ocr-result-card .card-body { padding: .6rem .75rem; }
.ocr-result-card .row.g-2 > div { font-size: .82rem; }
/* hide empty placeholder lines already avoided in JS; ensure compact */
#resultsArea .card.ocr-result-card { margin-bottom: .5rem; }

/* Universal: give content-heavy cells breathing room & ellipsis */
.cell-clamp { max-width: 480px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Reduce oversized hero icons */
.fa-3x { font-size: 2em; }
.fa-2x { font-size: 1.5em; }

/* Compact stat-card grid gap */
.row.g-2, .row.g-3 { --bs-gutter-y: .5rem; }
.secondary-block { /* helper: blocks fade in work-mode */ }

/* Pagination / pager smaller */
.pagination-sm .page-link { padding: .2rem .5rem; font-size: .8rem; }

/* =====================================================================
   MESSAGE EDITOR  (new / edit_scheduled / edit_sent — unified)
   ===================================================================== */
.msg-editor .col-form, .msg-editor .col-preview { min-width: 0; }
.msg-editor .card-body { padding: .75rem .85rem; }
.msg-editor .mb-3 { margin-bottom: .6rem !important; }

/* Telegram-like preview bubble */
.tg-preview {
  background: #0e1621; border: 1px solid var(--border); border-radius: 10px;
  padding: .5rem; font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
}
.tg-bubble {
  background: #212d3b; color: #e9edf0; border-radius: 12px 12px 12px 4px;
  padding: .55rem .7rem; max-width: 100%; font-size: .9rem; line-height: 1.45;
  word-wrap: break-word; overflow-wrap: anywhere;
}
.tg-bubble .tg-media { display: block; max-width: 100%; border-radius: 10px; margin-bottom: .5rem; }
.tg-bubble .tg-media-ph {
  background: #11171f; padding: 40px 16px; text-align: center; border-radius: 10px;
  margin-bottom: .5rem; color: #8b98a5; font-size: .85rem;
}
.tg-bubble .ph-err { background:#3a1d1d; color:#ff9b9b; padding:10px; border-radius:8px; text-align:center; }
.tg-bubble .tg-empty { color: #6b7785; font-style: italic; }
.tg-bubble strong { font-weight: 700; }
.tg-bubble em { font-style: italic; }
.tg-bubble .tg-code {
  background: #11202e; color: #79c0ff; padding: 1px 5px; border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em;
}
.tg-bubble .tg-pre {
  background: #11202e; color: #79c0ff; padding: .5rem .65rem; border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82em;
  overflow-x: auto; white-space: pre; margin: .3rem 0;
}
.tg-bubble .tg-quote {
  border-left: 3px solid #5b9bd5; padding-left: .6rem; margin: .4rem 0; color: #9fb0c0;
}
.tg-bubble .tg-quote-exp summary { cursor: pointer; color: #5b9bd5; font-size: .82rem; }
.tg-bubble .tg-link { color: #6ab3f8; text-decoration: none; }
.tg-bubble .tg-link:hover { text-decoration: underline; }
.tg-bubble .tg-emoji { font-style: normal; }

/* timezone readout */
.tz-readout { display: flex; flex-wrap: wrap; gap: .35rem .75rem; font-size: .75rem; color: var(--text-dim); }
.tz-readout b { color: var(--text); font-weight: 600; }
.char-wrap { font-size: .75rem; color: var(--text-dim); }
.char-wrap.text-warning { color: var(--warn); }
.char-wrap.text-danger { color: var(--danger); }

/* textarea editor */
.msg-editor textarea#message_text {
  min-height: 200px; resize: vertical; line-height: 1.5; font-family: inherit;
}

/* Collapsible help */
.msg-help-card { margin-top: .6rem; }
.msg-help-header {
  display: flex; align-items: center; justify-content: space-between;
  cursor: pointer; user-select: none; background: var(--bg-elev-2);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: .45rem .7rem; font-size: .85rem; font-weight: 600; color: var(--text);
}
.msg-help-header:hover { border-color: var(--accent); }
.msg-help-caret { transition: transform .2s ease; color: var(--text-dim); }
.msg-help-body { padding: .6rem .7rem; font-size: .8rem; }
.msg-help-title { color: var(--text-dim); font-weight: 600; margin: .2rem 0 .35rem; }
.msg-help-list { list-style: none; padding-left: 0; margin: 0 0 .5rem; line-height: 1.9; color: var(--text-dim); }
.msg-help-list code {
  background: var(--bg-elev-2); color: #ff7eb6; padding: 1px 5px; border-radius: 4px;
  font-size: .75rem; font-family: ui-monospace, monospace;
}
.msg-help-tip {
  font-size: .75rem; color: var(--text-dim); background: rgba(91,155,213,.1);
  border-left: 3px solid #5b9bd5; border-radius: 4px; padding: .4rem .55rem;
}
.msg-help-tip i { color: #5b9bd5; }

/* primary action emphasis; secondary de-emphasized */
.msg-editor .btn-submit { min-width: 140px; }
.msg-editor .btn-back { background: transparent; border-color: var(--border); color: var(--text-dim); }
.msg-editor .btn-back:hover { color: var(--text); border-color: var(--text-faint); }

/* Keep action row from wrapping awkwardly */
.msg-editor .action-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; margin-top: .25rem; }

/* ═══════════════════════════════════════════════════════════
   Unified message editor (modal XL)
   ═══════════════════════════════════════════════════════════ */
.modal-xl { max-width: 1280px; }

.msg-editor textarea#message_text.msg-editor-textarea {
  min-height: 450px; resize: vertical; border-radius: 0 !important;
  line-height: 1.5; font-family: inherit; font-size: .92rem;
}

/* Discord-style preview (light-on-dark, without Telegram bubble) */
.dc-preview {
  color: #dbdee1; font-size: .88rem; line-height: 1.5;
}
.dc-preview b { color: #fff; font-weight: 700; }
.dc-preview a { color: #00a8fc; text-decoration: none; }
.dc-preview a:hover { text-decoration: underline; }
.dc-preview blockquote {
  border-left: 3px solid #4e5058; padding-left: .6rem; margin: .4rem 0; color: #9b9da4;
}
.dc-preview pre {
  background: #111214; color: #e3e5e8; padding: .5rem .65rem; border-radius: 6px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .82em;
  overflow-x: auto; white-space: pre; margin: .3rem 0;
}
.dc-preview code {
  background: #232428; color: #c9cbd1; padding: 1px 5px; border-radius: 4px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .85em;
}

/* Markdown help table inside editor */
.msg-help-table td { padding: .15rem .3rem; vertical-align: middle; }
.msg-help-table code {
  background: var(--bg-elev-2); color: #ff7eb6; padding: 1px 5px; border-radius: 4px;
  font-size: .78rem; font-family: ui-monospace, monospace;
}

/* Preset buttons */
.msg-editor .preset-btn { font-size: .8rem; }

/* =====================================================================
   SEMANTIC COLOR UTILITIES
   Map common markup colors to design tokens. Prefer these classes over
   inline style="color:#hex" — tokens stay in sync with the theme.
   ===================================================================== */

.text-accent   { color: var(--accent) !important; }
.text-green    { color: var(--green) !important; }
.text-warn     { color: var(--warn) !important; }
.text-amber    { color: var(--amber) !important; }
.text-danger   { color: var(--danger) !important; }
.text-dim      { color: var(--text-dim) !important; }
.text-faint    { color: var(--text-faint) !important; }
.text-bright   { color: var(--text-bright) !important; }
.text-discord  { color: var(--discord) !important; }

.bg-elev   { background-color: var(--bg-elev) !important; }
.bg-elev-2 { background-color: var(--bg-elev-2) !important; }
.bg-elev-3 { background-color: var(--bg-elev-3) !important; }
.bg-elev-4 { background-color: var(--bg-elev-4) !important; }

.border-token   { border-color: var(--border) !important; }
.border-soft    { border-color: var(--border-soft) !important; }

/* Soft badge/status variants (translucent fill + token text) */
.badge-soft-success { background: rgba(63,185,80,.14); color: var(--green); border: 1px solid rgba(63,185,80,.35); }
.badge-soft-warn    { background: rgba(210,153,34,.14); color: var(--warn); border: 1px solid rgba(210,153,34,.35); }
.badge-soft-danger  { background: rgba(248,81,73,.14); color: var(--danger); border: 1px solid rgba(248,81,73,.35); }
.badge-soft-info    { background: rgba(88,166,255,.14); color: var(--accent); border: 1px solid rgba(88,166,255,.35); }
.badge-soft-neutral { background: var(--bg-elev-2); color: var(--text-dim); border: 1px solid var(--border); }


