/* =====================================================
   FuturePBX — Main Application Stylesheet (app.css)
   =====================================================

   The primary design system for the FuturePBX multi-tenant PBX management UI.
   Defines all core layout, component, and utility styles for the application.

   STRUCTURE:
     1. CSS Custom Properties (:root)  — brand colors, spacing, shadows, radii
     2. Reset                          — universal box-sizing, base font
     3. Layout Shell                   — .app-wrapper flex container
     4. Sidebar                        — fixed left nav (260px), logo, PBX badge, nav items
     5. Topbar                         — fixed top bar with breadcrumbs, user menu
     6. Main Content                   — page container offset by sidebar + topbar
     7. Page Header                    — title block + action buttons
     8. Stats Row                      — auto-fit grid of stat cards (dashboard KPIs)
     9. Cards                          — generic card component (header, body)
    10. Data Table                     — full-width table with sticky header styling
    11. Search Bar / Toolbar           — inline search + record count
    12. Badges                         — pill-shaped status indicators (7 color variants)
    13. Buttons                        — primary (gradient), success, danger, outline, icon-only
    14. Forms                          — grid layout, inputs, selects, toggle switches
    15. Alerts                         — success/danger/info/warning notification bars
    16. Empty State                    — centered placeholder for zero-record views
    17. Modals                         — overlay + animated modal box (z-index: 2000)
    18. Tabs                           — horizontal tab bar with active underline
    19. Login Page                     — split layout (brand left + form right)
    20. Dashboard Specifics            — 2-column grid, quick-links
    21. Chips / Tags                   — small inline labels
    22. Pagination                     — numbered page buttons
    23. Utilities                      — display, flex, spacing, text helpers
    24. Scrollbar                      — custom thin scrollbar (brand purple)
    25. Responsive                     — breakpoints at 1024px and 768px
    26. AI Chat Widgets                — simulation, iframe, and card widgets (in-chat)

   COLOR SCHEME:
     Brand primary: #7a2a8f (deep purple) — used for primary actions, active states
     Brand secondary: #c972ad (pink)      — gradients, hover accents
     Brand accent: #46c5e5 (cyan/teal)    — tertiary highlight
     Brand gradient: 135deg from purple -> pink -> cyan
     Sidebar: #1a1230 (very dark indigo)  — high contrast with light content area
     Content background: #f4f6fc (light blue-gray)
     Cards/topbar: #ffffff

   BREAKPOINTS:
     <= 1024px — narrower sidebar (220px), hide login left panel, single-col dashboard
     <= 768px  — sidebar off-canvas (mobile drawer), topbar full-width, hamburger menu

   Z-INDEX HIERARCHY:
     Topbar:        999
     Sidebar:      1000
     Mobile overlay:1050
     Mobile sidebar:1100
     Modal overlay: 2000
     AI chat toggle:9998
     AI chat panel: 9999

   NOTE: Do NOT modify phone.css or phone.*.css files (WebRTC phone styles)
         per golden rule #6. Those are maintained separately.

   Font: Inter (Google Fonts), weights 300-800, with system-ui fallback.
   ===================================================== */

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root, [data-theme="light"] {
  --sidebar-width: 260px;
  --topbar-height: 64px;

  /* Brand — FuturePBX palette (origami hummingbird) */
  --brand-primary:   #7a2a8f;
  --brand-secondary: #c972ad;
  --brand-gradient:  linear-gradient(135deg, #7a2a8f 0%, #c972ad 50%, #46c5e5 100%);
  --brand-accent:    #46c5e5;

  /* Sidebar */
  --sidebar-bg:      #ffffff;
  --sidebar-text:    #64748b;
  --sidebar-hover:   rgba(122,42,143,.08);
  --sidebar-active:  rgba(122,42,143,.12);
  --sidebar-border:  #e2e8f0;

  /* Content */
  --content-bg:      #f4f6fc;
  --topbar-bg:       #ffffff;
  --card-bg:         #ffffff;

  /* Text */
  --text-primary:    #0f172a;
  --text-secondary:  #64748b;
  --text-muted:      #94a3b8;

  /* Status */
  --success:  #10b981;
  --warning:  #f59e0b;
  --danger:   #ef4444;
  --info:     #3b82f6;

  /* Sidebar labels */
  --sidebar-logo-text:   var(--text-primary);
  --sidebar-pbx-name:    var(--text-primary);
  --sidebar-pbx-bg:      rgba(122,42,143,.06);
  --nav-section-color:   var(--text-muted);

  /* Backgrounds (generic) */
  --bg-primary:      #ffffff;
  --bg-secondary:    #f8faff;

  /* Borders & hover (UI chrome) */
  --border-color:    #e8ecf4;
  --hover-bg:        #f8f5fa;
  --hover-border:    #d8b4e8;

  /* UI */
  --radius-sm:   6px;
  --radius-md:   10px;
  --radius-lg:   16px;
  --shadow-sm:   0 1px 3px rgba(0,0,0,.06), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:   0 4px 16px rgba(0,0,0,.08);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.12);
  --transition:  all .2s ease;
}

[data-theme="dark"] {
  --sidebar-bg:      #0d0b14;
  --sidebar-text:    #c4b5d8;
  --sidebar-hover:   rgba(201,114,173,.2);
  --sidebar-active:  rgba(201,114,173,.3);
  --sidebar-border:  rgba(255,255,255,.06);

  --content-bg:      #0f1117;
  --topbar-bg:       #1a1d27;
  --card-bg:         #1a1d27;
  --bg-primary:      #1a1d27;
  --bg-secondary:    #252836;

  --text-primary:    #e2e8f0;
  --text-secondary:  #94a3b8;
  --text-muted:      #64748b;

  --sidebar-logo-text:   #e2e8f0;
  --sidebar-pbx-name:    #e2e8f0;
  --sidebar-pbx-bg:      rgba(255,255,255,.07);
  --nav-section-color:   rgba(160,172,210,.6);

  --border-color:    rgba(255,255,255,.08);
  --hover-bg:        rgba(255,255,255,.06);
  --hover-border:    rgba(201,114,173,.4);

  --shadow-sm:   0 1px 3px rgba(0,0,0,.2), 0 1px 2px rgba(0,0,0,.15);
  --shadow-md:   0 4px 16px rgba(0,0,0,.3);
  --shadow-lg:   0 8px 32px rgba(0,0,0,.4);
}

/* ── Reset ─────────────────────────────────────────────────────────────
   Universal box-sizing and base typography. Uses Inter font (Google Fonts)
   with antialiased rendering. Base font size: 14px.
   ──────────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
  color: var(--text-primary);
  background: var(--content-bg);
  -webkit-font-smoothing: antialiased;
}

/* ── Layout Shell ──────────────────────────────────────────────────────
   Top-level flex container. Sidebar sits on the left (fixed), main content
   fills the remaining space to the right. min-height: 100vh ensures the
   layout always fills the viewport.
   ──────────────────────────────────────────────────────────────────── */
.app-wrapper {
  display: flex;
  min-height: 100vh;
}

/* ── SIDEBAR ───────────────────────────────────────────────────────────
   Fixed left navigation panel (260px wide, z-index: 1000). Contains:
   - Logo block (top, same height as topbar for alignment)
   - PBX info badge (shows current tenant name + green status dot)
   - Scrollable nav sections with grouped nav-items
   - Footer area (logout, settings)
   On mobile (<=768px), slides off-screen to -280px and toggles via
   .mobile-open class with a dark overlay backdrop.
   ──────────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: 0; left: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  z-index: 1000;
  overflow: hidden;
  border-right: 1px solid var(--sidebar-border);
}

.sidebar-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  padding: 16px 20px 12px;
  border-bottom: 1px solid var(--sidebar-border);
  text-decoration: none;
  flex-shrink: 0;
}

.sidebar-logo .logo-icon {
  width: 120px; height: 120px;
  background: transparent;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
  overflow: visible;
  animation: bird-float 3s ease-in-out infinite;
}
@keyframes bird-float {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-6px); }
}

.sidebar-logo .logo-text {
  text-align: center;
  line-height: 1;
}

.sidebar-logo .logo-text span {
  display: block;
  font-size: 9px;
  font-weight: 600;
  color: var(--sidebar-text);
  letter-spacing: 1.2px;
  text-transform: uppercase;
}

.sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 12px 0;
  scrollbar-width: none;
}
.sidebar-content::-webkit-scrollbar { display: none; }

/* PBX info badge */
.sidebar-pbx {
  margin: 4px 12px 12px;
  padding: 10px 12px;
  background: var(--sidebar-pbx-bg);
  border-radius: var(--radius-md);
  border: 1px solid var(--sidebar-border);
}
.sidebar-pbx .pbx-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .8px;
  color: var(--sidebar-text);
  font-weight: 500;
}
.sidebar-pbx .pbx-name {
  font-size: 13px;
  color: var(--sidebar-pbx-name);
  font-weight: 600;
  margin-top: 2px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.pbx-dot { width:7px;height:7px;border-radius:50%;background:var(--success);flex-shrink:0; }

/* Section label */
.nav-section {
  padding: 16px 20px 6px;
  font-size: 10px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: var(--nav-section-color);
}

/* Nav item */
.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 20px;
  margin: 1px 8px;
  border-radius: var(--radius-md);
  text-decoration: none;
  color: var(--sidebar-text);
  font-size: 13.5px;
  font-weight: 500;
  transition: var(--transition);
  position: relative;
}
.nav-item:hover {
  background: var(--sidebar-hover);
  color: var(--brand-primary);
}
.nav-item.active {
  background: var(--sidebar-active);
  color: var(--brand-primary);
  font-weight: 600;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: -8px; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 20px;
  background: var(--brand-primary);
  border-radius: 0 3px 3px 0;
}
.nav-item .nav-icon {
  width: 18px; text-align: center;
  font-size: 15px;
  flex-shrink: 0;
  opacity: .8;
}
.nav-item.active .nav-icon,
.nav-item:hover .nav-icon { opacity: 1; }

.nav-badge {
  margin-left: auto;
  background: var(--brand-primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 20px;
  min-width: 18px;
  text-align: center;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 8px;
  border-top: 1px solid var(--sidebar-border);
  flex-shrink: 0;
}

/* ── TOPBAR ────────────────────────────────────────────────────────────
   Fixed horizontal bar at the top (64px tall, z-index: 999). Offset from
   the left by --sidebar-width so it doesn't overlap the sidebar. Contains:
   - Left: breadcrumb navigation
   - Right: action buttons (icon buttons) + user avatar/menu dropdown
   On mobile, left offset resets to 0 (sidebar is hidden).
   ──────────────────────────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0; left: var(--sidebar-width); right: 0;
  height: var(--topbar-height);
  background: var(--topbar-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  z-index: 999;
  box-shadow: var(--shadow-sm);
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.breadcrumb-nav {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
  color: var(--text-secondary);
}
.breadcrumb-nav .crumb-active {
  color: var(--text-primary);
  font-weight: 600;
}
.breadcrumb-sep { color: var(--text-muted); font-size: 12px; }

.topbar-right {
  display: flex;
  align-items: center;
  gap: 16px;
}

.topbar-btn {
  width: 36px; height: 36px;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-color);
  background: transparent;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  color: var(--text-secondary);
  font-size: 15px;
  transition: var(--transition);
  text-decoration: none;
}
.topbar-btn:hover { background: var(--hover-bg); color: var(--brand-primary); border-color: var(--hover-border); }

.user-menu {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 12px 6px 6px;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  cursor: pointer;
  transition: var(--transition);
  text-decoration: none;
  color: var(--text-primary);
}
.user-menu:hover { background: var(--hover-bg); border-color: var(--hover-border); }

.user-avatar {
  width: 32px; height: 32px;
  border-radius: var(--radius-md);
  background: var(--brand-gradient);
  display: flex; align-items: center; justify-content: center;
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-info { line-height: 1.2; }
.user-info .user-name { font-size: 13px; font-weight: 600; }
.user-info .user-role { font-size: 11px; color: var(--text-secondary); }

/* ── MAIN CONTENT ──────────────────────────────────────────────────────
   Primary content area, offset by sidebar width (margin-left) and topbar
   height (padding-top). Contains the .page-container which caps content
   at 1600px max-width with 28px padding.
   ──────────────────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  margin-left: var(--sidebar-width);
  padding-top: var(--topbar-height);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.page-container {
  flex: 1;
  padding: 28px;
  max-width: 1600px;
}

/* ── PAGE HEADER ────────────────────────────────────── */
.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 24px;
  gap: 16px;
}

.page-title-block { flex: 1; }

.page-title {
  font-size: 22px;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -.4px;
  margin-bottom: 3px;
}

.page-subtitle {
  font-size: 13px;
  color: var(--text-secondary);
  font-weight: 400;
}

.page-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

/* ── STATS ROW ──────────────────────────────────────── */
.stats-row, .stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  padding: 20px;
  box-shadow: var(--shadow-sm);
  border: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  gap: 16px;
  transition: var(--transition);
  text-decoration: none;
  color: inherit;
}
.stat-card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); }

.stat-icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
  flex-shrink: 0;
}
.stat-icon.blue   { background: rgba(122,42,143,.1); color: var(--brand-primary); }
.stat-icon.green  { background: rgba(16,185,129,.1); color: var(--success); }
.stat-icon.orange { background: rgba(245,158,11,.1); color: var(--warning); }
.stat-icon.red    { background: rgba(239,68,68,.1);  color: var(--danger); }
.stat-icon.purple { background: rgba(124,58,237,.1); color: var(--brand-secondary); }
.stat-icon.teal   { background: rgba(20,184,166,.1); color: #14b8a6; }

.stat-info .stat-value {
  font-size: 26px;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -1px;
  line-height: 1;
}
.stat-info .stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  font-weight: 500;
  margin-top: 3px;
}
.stat-info .stat-sub {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── CARDS ──────────────────────────────────────────── */
.card {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}

.card-header {
  padding: 18px 22px;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--card-bg);
}

.card-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}
.card-title i { color: var(--brand-primary); font-size: 15px; }

.card-body { padding: 22px; }

/* ── DATA TABLE ────────────────────────────────────────────────────────
   Full-width table for listing records (extensions, CLIs, routes, etc.).
   Header row has uppercase labels on a light blue-gray background.
   Rows have subtle hover highlight and 1px bottom borders.
   Helper classes: .td-primary (bold), .td-secondary (muted), .td-mono (monospace).
   Wrapped in .table-wrapper for horizontal scroll on narrow screens.
   ──────────────────────────────────────────────────────────────────── */
.table-wrapper {
  overflow-x: auto;
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.data-table thead th {
  padding: 11px 14px;
  background: var(--hover-bg);
  color: var(--text-secondary);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
  text-align: left;
}

.data-table tbody tr {
  border-bottom: 1px solid var(--border-color);
  transition: background .12s;
}
.data-table tbody tr:last-child { border-bottom: none; }
.data-table tbody tr:hover { background: var(--hover-bg); }

.data-table tbody td {
  padding: 12px 14px;
  color: var(--text-primary);
  vertical-align: middle;
}

.td-primary {
  font-weight: 600;
  color: var(--text-primary);
  font-size: 14px;
}
.td-secondary { color: var(--text-secondary); }
.td-mono { font-family: 'Courier New', monospace; font-size: 13px; font-weight: 600; }

/* ── SEARCH BAR ─────────────────────────────────────── */
.table-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border-color);
  background: var(--card-bg);
  flex-wrap: wrap;
}

.search-box {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 340px;
}
.search-box i {
  position: absolute;
  left: 11px; top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 13px;
}
.search-box input {
  width: 100%;
  padding: 8px 12px 8px 32px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--hover-bg);
  outline: none;
  transition: var(--transition);
}
.search-box input:focus { border-color: var(--brand-primary); background: var(--card-bg); box-shadow: 0 0 0 3px rgba(122,42,143,.1); }

.record-count {
  font-size: 12px;
  color: var(--text-muted);
  margin-left: auto;
  flex-shrink: 0;
}

/* ── BADGES ─────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .2px;
  white-space: nowrap;
}

.badge-green  { background: rgba(16,185,129,.12); color: #059669; }
.badge-red    { background: rgba(239,68,68,.12);  color: #dc2626; }
.badge-blue   { background: rgba(79,110,247,.12); color: #3b5fe2; }
.badge-orange { background: rgba(245,158,11,.12); color: #d97706; }
.badge-gray   { background: rgba(100,116,139,.1); color: #4b5563; }
.badge-purple { background: rgba(124,58,237,.12); color: #7c3aed; }
.badge-teal   { background: rgba(20,184,166,.12); color: #0d9488; }

.badge i { font-size: 8px; }

/* ── BUTTONS ────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: var(--transition);
  white-space: nowrap;
  line-height: 1;
}
.btn i { font-size: 13px; }

.btn-primary {
  background: var(--brand-gradient);
  color: #fff;
  box-shadow: 0 2px 8px rgba(122,42,143,.3);
}
.btn-primary:hover { opacity: .9; box-shadow: 0 4px 12px rgba(122,42,143,.4); transform: translateY(-1px); color: #fff; }

.btn-success  { background: var(--success); color: #fff; }
.btn-success:hover { opacity:.9; color:#fff; }
.btn-danger   { background: var(--danger);  color: #fff; }
.btn-danger:hover  { opacity:.9; color:#fff; }
.btn-warning  { background: var(--warning); color: #fff; }

.btn-secondary {
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.btn-secondary:hover { background: var(--hover-bg); color: var(--text-primary); }

.btn-outline {
  background: transparent;
  border: 1px solid var(--border-color);
  color: var(--text-secondary);
}
.btn-outline:hover { background: var(--hover-bg); border-color: var(--hover-border); color: var(--brand-primary); }

.btn-sm { padding: 5px 10px; font-size: 12px; gap: 5px; }
.btn-sm i { font-size: 11px; }
.btn-xs { padding: 3px 8px; font-size: 11px; border-radius: var(--radius-sm); }

/* Icon-only action buttons */
.action-btns { display: flex; align-items: center; gap: 5px; }
.btn-icon {
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  border: none;
  display: flex; align-items: center; justify-content: center;
  cursor: pointer;
  font-size: 13px;
  transition: var(--transition);
  text-decoration: none;
}
.btn-icon-view   { background: rgba(122,42,143,.1); color: var(--brand-primary); }
.btn-icon-edit   { background: rgba(245,158,11,.1); color: var(--warning); }
.btn-icon-delete { background: rgba(239,68,68,.1);  color: var(--danger); }
.btn-icon:hover  { filter: brightness(1.1); transform: scale(1.08); }

/* ── FORMS ─────────────────────────────────────────────────────────────
   Responsive form layout using CSS Grid. .form-grid auto-fills columns
   at 280px minimum width. Modifiers: .cols-2, .cols-3, .full (single col).
   Form controls get a purple focus ring (3px, 10% opacity) matching brand.
   Includes toggle switch component (.toggle) for boolean settings.
   ──────────────────────────────────────────────────────────────────── */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 18px;
}
.form-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.form-grid.cols-3 { grid-template-columns: repeat(3, 1fr); }
.form-grid.full   { grid-template-columns: 1fr; }
.form-span-2      { grid-column: span 2; }

.form-group { display: flex; flex-direction: column; gap: 5px; }

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .5px;
}

.form-control {
  padding: 9px 13px;
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  font-size: 13.5px;
  font-family: inherit;
  color: var(--text-primary);
  background: var(--card-bg);
  transition: var(--transition);
  outline: none;
  width: 100%;
}
.form-control:focus { border-color: var(--brand-primary); box-shadow: 0 0 0 3px rgba(122,42,143,.1); }
.form-control::placeholder { color: var(--text-muted); }
.form-control:disabled { background: var(--hover-bg); color: var(--text-muted); }

select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

.form-hint { font-size: 11px; color: var(--text-muted); }

.form-section {
  margin-bottom: 24px;
  padding-bottom: 24px;
  border-bottom: 1px solid var(--border-color);
}
.form-section:last-child { border-bottom: none; margin-bottom: 0; padding-bottom: 0; }

.form-section-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 7px;
}
.form-section-title i { color: var(--brand-primary); }

/* Toggle switch */
.toggle-wrap { display: flex; align-items: center; gap: 10px; min-height: 38px; }
.toggle {
  position: relative;
  width: 40px; height: 22px;
  flex-shrink: 0;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
  position: absolute; inset: 0;
  background: #d1d5db;
  border-radius: 22px;
  cursor: pointer;
  transition: .2s;
}
.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; top: 3px;
  background: white;
  border-radius: 50%;
  transition: .2s;
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked + .toggle-slider { background: var(--brand-primary); }
.toggle input:checked + .toggle-slider::before { transform: translateX(18px); }
.toggle-label { font-size: 13px; font-weight: 500; color: var(--text-primary); }

/* ── ALERTS ─────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 13px 16px;
  border-radius: var(--radius-md);
  font-size: 13px;
  margin-bottom: 16px;
}
.alert i { font-size: 15px; margin-top: 1px; flex-shrink: 0; }
.alert-success { background: rgba(16,185,129,.1); color: #065f46; border: 1px solid rgba(16,185,129,.25); }
.alert-danger  { background: rgba(239,68,68,.1);  color: #991b1b; border: 1px solid rgba(239,68,68,.25); }
.alert-info    { background: rgba(122,42,143,.1);  color: #1e40af; border: 1px solid rgba(79,110,247,.25); }
.alert-warning { background: rgba(245,158,11,.1);  color: #92400e; border: 1px solid rgba(245,158,11,.25); }

/* ── EMPTY STATE ────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 60px 20px;
  text-align: center;
}
.empty-state .empty-icon {
  font-size: 48px;
  color: var(--hover-border);
  margin-bottom: 16px;
}
.empty-state h3 { font-size: 16px; font-weight: 600; color: var(--text-secondary); margin-bottom: 6px; }
.empty-state p  { font-size: 13px; color: var(--text-muted); max-width: 280px; }

/* ── MODAL ─────────────────────────────────────────────────────────────
   Overlay-based modal dialog (z-index: 2000, above everything except AI chat).
   Uses opacity + pointer-events for show/hide, with a slight scale+translate
   animation on the .modal-box. Backdrop has blur(3px) for depth effect.
   .modal-lg variant widens max-width to 800px. Max height 90vh with scroll.
   ──────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(15,23,42,.5);
  backdrop-filter: blur(3px);
  z-index: 2000;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal-box {
  background: var(--card-bg);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(16px) scale(.98);
  transition: transform .2s;
}
.modal-overlay.open .modal-box { transform: none; }
.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border-color);
}
.modal-title { font-size: 15px; font-weight: 700; color: var(--text-primary); }
.modal-close { background: none; border: none; font-size: 18px; cursor: pointer; color: var(--text-muted); padding: 2px; }
.modal-close:hover { color: var(--danger); }
.modal-body { padding: 24px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border-color); display: flex; justify-content: flex-end; gap: 10px; }
.modal-lg .modal-box { max-width: 800px; }

/* ── TABS ───────────────────────────────────────────── */
.tabs {
  display: flex;
  gap: 2px;
  border-bottom: 2px solid var(--border-color);
  margin-bottom: 24px;
}
.tab {
  padding: 10px 18px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  display: flex;
  align-items: center;
  gap: 7px;
  transition: var(--transition);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
}
.tab:hover { color: var(--brand-primary); background: rgba(122,42,143,.05); }
.tab.active { color: var(--brand-primary); border-bottom-color: var(--brand-primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* ── LOGIN PAGE ────────────────────────────────────────────────────────
   Split-panel login layout: left side shows brand imagery with gradient
   background and decorative radial-gradient circles (pseudo-elements);
   right side (480px fixed width) contains the login form. On tablets
   (<=1024px), the left panel hides and the form takes full width.
   ──────────────────────────────────────────────────────────────────── */
.login-page {
  min-height: 100vh;
  display: flex;
  background: var(--sidebar-bg);
}
.login-left {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 40px;
  background: linear-gradient(135deg, #1a1230 0%, #2d1640 40%, #1a2a4a 100%);
  position: relative;
  overflow: hidden;
}
.login-left::before {
  content: '';
  position: absolute;
  width: 500px; height: 500px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(70,197,229,.12) 0%, transparent 70%);
  top: -100px; right: -100px;
}
.login-left::after {
  content: '';
  position: absolute;
  width: 300px; height: 300px;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(201,114,173,.1) 0%, transparent 70%);
  bottom: -50px; left: -50px;
}
.login-left-content { position: relative; z-index: 1; text-align: center; color: #fff; max-width: 360px; }
.login-brand-icon {
  width: 72px; height: 72px;
  background: transparent;
  border-radius: 20px;
  display: flex; align-items: center; justify-content: center;
  font-size: 32px;
  margin: 0 auto 24px;
}
.login-left-content h1 { font-size: 28px; font-weight: 800; margin-bottom: 8px; letter-spacing: -.5px; }
.login-left-content p  { color: rgba(255,255,255,.6); font-size: 14px; line-height: 1.6; }
.login-features { margin-top: 36px; text-align: left; display: flex; flex-direction: column; gap: 12px; }
.login-feature {
  display: flex; align-items: center; gap: 12px;
  background: rgba(255,255,255,.06);
  border-radius: var(--radius-md);
  padding: 12px 16px;
  font-size: 13px;
  color: rgba(255,255,255,.8);
}
.login-feature i { color: var(--brand-accent, #46c5e5); font-size: 16px; }

.login-right {
  width: 480px;
  flex-shrink: 0;
  background: var(--card-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 48px 48px;
}
.login-form-wrap { width: 100%; max-width: 360px; }
.login-form-title  { font-size: 22px; font-weight: 800; color: var(--text-primary); margin-bottom: 4px; }
.login-form-subtitle { font-size: 13px; color: var(--text-secondary); margin-bottom: 28px; }

/* ── DASHBOARD SPECIFICS ────────────────────────────── */
.dashboard-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
  margin-top: 20px;
}
.quick-links-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 10px;
  padding: 16px;
}
.quick-link {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  border-radius: var(--radius-md);
  background: var(--hover-bg);
  border: 1px solid var(--border-color);
  text-decoration: none;
  color: var(--text-primary);
  font-size: 13px;
  font-weight: 500;
  transition: var(--transition);
}
.quick-link:hover { background: var(--hover-bg); border-color: var(--hover-border); color: var(--brand-primary); }
.quick-link i { font-size: 16px; width: 20px; text-align: center; }

/* ── CHIP / TAG ─────────────────────────────────────── */
.chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  background: var(--border-color);
  border-radius: 20px;
  font-size: 11px;
  color: var(--text-secondary);
  font-weight: 500;
}

/* ── PAGINATION ─────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 14px 18px;
  border-top: 1px solid var(--border-color);
  justify-content: flex-end;
}
.page-btn {
  width: 30px; height: 30px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  background: var(--card-bg);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: var(--transition);
  color: var(--text-secondary);
  text-decoration: none;
}
.page-btn:hover { border-color: var(--brand-primary); color: var(--brand-primary); }
.page-btn.active { background: var(--brand-primary); color: #fff; border-color: var(--brand-primary); }

/* ── UTILITIES ──────────────────────────────────────── */
.d-flex  { display: flex; }
.d-none  { display: none; }
.align-center { align-items: center; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.mt-0 { margin-top: 0; }
.mb-0 { margin-bottom: 0; }
.text-muted { color: var(--text-muted); }
.text-right { text-align: right; }
.fw-600 { font-weight: 600; }
.w-100 { width: 100%; }
.separator { height: 1px; background: var(--border-color); margin: 12px 0; }

/* ── SCROLLBAR ──────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--hover-border); border-radius: 10px; }
::-webkit-scrollbar-thumb:hover { background: var(--brand-primary); }

.mobile-menu-btn { display: none; }

/* ── RESPONSIVE ────────────────────────────────────────────────────────
   Two breakpoints:
     <= 1024px: Sidebar narrows to 220px, login left panel hidden,
                dashboard grid collapses to single column.
     <= 768px:  Sidebar becomes off-canvas drawer (slides from left),
                topbar spans full width, page padding reduced to 16px,
                mobile hamburger menu button appears.
   ──────────────────────────────────────────────────────────────────── */
@media (max-width: 1024px) {
  :root { --sidebar-width: 220px; }
  .login-left { display: none; }
  .login-right { width: 100%; }
  .dashboard-grid { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .sidebar {
    left: -280px !important;
    transition: left .3s ease;
    z-index: 1100;
    width: 260px;
  }
  .sidebar.mobile-open {
    left: 0 !important;
  }
  .sidebar-overlay {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0,0,0,.4);
    z-index: 1050;
  }
  .sidebar-overlay.active {
    display: block;
  }
  .main-content { margin-left: 0; }
  .topbar { left: 0; }
  .page-container { padding: 16px; }
  .mobile-menu-btn {
    display: flex !important;
    align-items: center;
    justify-content: center;
    width: 38px;
    height: 38px;
    border: none;
    border-radius: 8px;
    background: var(--card-bg, #fff);
    color: var(--brand-primary);
    font-size: 20px;
    cursor: pointer;
    margin-right: 8px;
    flex-shrink: 0;
  }
}

/* =====================================================
   AI Chat Widgets — Interactive Components Rendered Inside Chat Messages
   =====================================================
   These styles support three widget types rendered by the AI assistant
   inside chat message bubbles (driven by ai-chat.js widget renderer):

   1. SIMULATION WIDGET (.ai-widget / .ai-sim-*)
      Visualizes call routing flow as a vertical node chain with connectors.
      Nodes can be audio-playable (.ai-sim-node-audio) with hover glow and
      pulse animation, or editable (.ai-sim-node-editable) with a pencil icon.
      IVR branches (.ai-sim-branches) fan out horizontally with key badges.

   2. IFRAME WIDGET (.ai-iframe-widget)
      Embeds a page (create/edit forms) inside the chat via an <iframe>.
      Header bar with title + close button; loading spinner overlay.

   3. CARD WIDGET (.ai-card-widget)
      Displays a resource summary (extension, route, etc.) as a 2-column
      grid of label/value pairs with optional action buttons at the bottom.

   These classes are defined here (in app.css) rather than ai-chat.css
   because widgets can appear both in the floating chat panel and in the
   full-page AI assistant view (ai_assistant.php).
   ===================================================== */

/* -- Simulation Widget (mirrors call_simulator.php) -- */
.ai-widget { border:1px solid var(--border-color); border-radius:12px; overflow:hidden; margin-top:12px; background:var(--bg-primary); }
.ai-sim-header { padding:16px 20px 12px; }
.ai-sim-badges { display:flex; flex-wrap:wrap; gap:8px; }
.ai-sim-badge { font-size:0.85rem; padding:6px 14px; border-radius:20px; font-weight:600; }
.ai-sim-badge-blue { background:#dbeafe; color:#1d4ed8; }
.ai-sim-badge-green { background:#d1fae5; color:#065f46; }
.ai-sim-badge-orange { background:#ffedd5; color:#9a3412; }
.ai-sim-flow { padding:4px 20px 20px; display:flex; flex-direction:column; gap:0; }
.ai-sim-node { display:flex; align-items:flex-start; gap:12px; padding:10px 14px; border-radius:10px; background:var(--bg-secondary); border-left:3px solid #6366f1; transition:box-shadow .2s; }
.ai-sim-node-label { font-size:0.65rem; font-weight:600; text-transform:uppercase; margin-bottom:2px; }
.ai-sim-node-desc { font-size:0.85rem; line-height:1.4; }
.ai-sim-connector { width:2px; height:20px; background:var(--border-color); margin-left:22px; }

/* Audio hover play */
.ai-sim-node-audio { cursor:pointer; }
.ai-sim-node-audio:hover { box-shadow:0 0 0 2px var(--brand-primary),0 4px 12px rgba(0,0,0,.15); }
.ai-sim-node-audio.sim-playing { box-shadow:0 0 0 2px #a855f7,0 4px 16px rgba(168,85,247,.25); }
.ai-sim-speaker { margin-left:6px; font-size:0.7rem; }
.ai-sim-node-audio.sim-playing .ai-sim-speaker { animation:ai-pulse-speaker .8s infinite alternate; }
@keyframes ai-pulse-speaker { from{opacity:.5} to{opacity:1} }

/* Editable nodes */
.ai-sim-node-editable { cursor:pointer; }
.ai-sim-node-editable:hover { box-shadow:0 0 0 2px var(--brand-accent,#f59e0b),0 4px 12px rgba(0,0,0,.12); }
.ai-sim-edit-icon { opacity:0; transition:opacity .2s; color:var(--brand-accent,#f59e0b); flex-shrink:0; font-size:0.85rem; margin-left:auto; }
.ai-sim-node-editable:hover .ai-sim-edit-icon { opacity:1; }

/* Mini nodes (inside IVR branches) */
.ai-sim-node-mini { display:flex; align-items:flex-start; gap:8px; padding:6px 10px; border-radius:8px; background:var(--bg-secondary); border-left:3px solid var(--border-color); transition:box-shadow .2s; cursor:default; margin-top:4px; }
.ai-sim-node-mini.ai-sim-node-audio { cursor:pointer; }
.ai-sim-node-mini.ai-sim-node-editable { cursor:pointer; }
.ai-sim-node-mini.ai-sim-node-audio:hover { box-shadow:0 0 0 2px var(--brand-primary),0 2px 8px rgba(0,0,0,.1); }
.ai-sim-mini-label { font-size:0.6rem; font-weight:600; text-transform:uppercase; margin-bottom:1px; }
.ai-sim-mini-desc { font-size:0.75rem; line-height:1.3; }

/* IVR branches */
.ai-sim-branches { display:flex; flex-wrap:wrap; gap:12px; padding:4px 0 4px 12px; }
.ai-sim-branch { display:flex; flex-direction:column; align-items:center; min-width:140px; max-width:240px; flex:1; position:relative; }
.ai-sim-branch-line { width:2px; height:14px; background:var(--border-color); }
.ai-sim-key { display:inline-flex; align-items:center; justify-content:center; min-width:32px; height:28px; padding:0 10px; border-radius:6px; background:#a855f7; color:#fff; font-weight:700; font-size:0.8rem; margin-bottom:6px; }
.ai-sim-branch-content { width:100%; }
.ai-sim-branch-dest { font-size:0.78rem; font-weight:600; text-align:center; color:var(--text-primary); margin-bottom:4px; line-height:1.3; }

/* -- Iframe Widget -- */
.ai-iframe-widget { border:1px solid var(--border-color); border-radius:12px; overflow:hidden; margin-top:12px; background:var(--bg-primary); }
.ai-iframe-header { display:flex; align-items:center; justify-content:space-between; padding:10px 16px; background:var(--bg-secondary); border-bottom:1px solid var(--border-color); font-size:0.85rem; font-weight:600; }
.ai-iframe-header span { display:flex; align-items:center; gap:6px; }
.ai-iframe-close { background:none; border:none; cursor:pointer; color:var(--text-secondary); font-size:18px; padding:4px; border-radius:4px; }
.ai-iframe-close:hover { background:var(--bg-secondary); color:var(--text-primary); }
.ai-iframe-body { position:relative; min-height:200px; overflow:visible; }
.ai-iframe-body iframe { width:100%; border:none; min-height:300px; display:block; }
.ai-iframe-loading { position:absolute; top:50%; left:50%; transform:translate(-50%,-50%); color:var(--text-secondary); font-size:0.85rem; display:flex; align-items:center; gap:8px; }
.ai-iframe-loading i { animation:spin 1s linear infinite; }
@keyframes spin { from{transform:rotate(0)} to{transform:rotate(360deg)} }

/* -- Card Widget -- */
.ai-card-widget { border:1px solid var(--border-color); border-radius:12px; overflow:hidden; margin-top:12px; background:var(--bg-primary); }
.ai-card-header { display:flex; align-items:center; gap:10px; padding:14px 16px; background:var(--bg-secondary); border-bottom:1px solid var(--border-color); }
.ai-card-header i { font-size:20px; color:var(--brand-primary); }
.ai-card-header span { font-weight:600; font-size:0.9rem; }
.ai-card-body { padding:16px; display:grid; grid-template-columns:1fr 1fr; gap:12px; }
.ai-card-field { display:flex; flex-direction:column; gap:2px; }
.ai-card-field-label { font-size:0.7rem; text-transform:uppercase; color:var(--text-secondary); font-weight:600; letter-spacing:0.3px; }
.ai-card-field-value { font-size:0.85rem; color:var(--text-primary); }
.ai-card-actions { padding:12px 16px; border-top:1px solid var(--border-color); display:flex; gap:8px; }
.ai-card-actions .btn { font-size:0.8rem; padding:6px 14px; }
