/* =============================================================================
   هیرا — شیوه‌نامه اصلی
   استخراج‌شده بدون تغییر از prototype/Kasb.html توسط scripts/extract_assets.py
   فونت‌ها از data URI به /static/fonts/ منتقل شده‌اند؛ بقیه دست‌نخورده است.
   این فایل را دستی ویرایش نکنید مگر برای افزودن استایل‌های جدید در انتها.
   ============================================================================= */
/* ==========================================================================
   1. EMBEDDED VAZIRMATN VARIABLE FONT (OFFLINE BASE64)
   ========================================================================== */
@font-face {
  font-family: 'Vazirmatn';
  src: url("/static/fonts/Vazirmatn-100-900.f6d31671339d.woff2") format('woff2-variations'),
       url("/static/fonts/Vazirmatn-100-900.f6d31671339d.woff2") format('woff2');
  font-weight: 100 900;
  font-style: normal;
  font-display: swap;
}


/* ==========================================================================
   2. DESIGN TOKENS & CSS VARIABLES (LIGHT / DARK THEMES)
   ========================================================================== */
:root[data-theme="light"] {
  --bg-app: #f6f6fb;
  --bg-surface: #ffffff;
  --bg-card: #ffffff;
  --bg-subtle: #f2f2f8;
  --bg-muted: #eeeef4;
  --bg-hover: #f2f2f8;
  --bg-active: #eeeef4;
  
  --text-main: #1a1730;
  --text-secondary: #6b6880;
  --text-muted: #858296;
  --text-dim: #a3a1b3;
  
  --border-subtle: rgba(40, 30, 90, 0.08);
  --border-base: rgba(40, 30, 90, 0.15);
  --border-strong: rgba(40, 30, 90, 0.24);
  
  --primary-50: #f0efff;
  --primary-100: #e6e4ff;
  --primary-200: #cbc7ff;
  --primary-500: #5b52f0;
  --primary-600: #4f46e5;
  --primary-700: #4038c8;
  --primary-gradient: linear-gradient(135deg, #4f46e5 0%, #6d4aff 100%);
  
  --ai-50: #f4f1ff;
  --ai-100: #ebe6ff;
  --ai-200: #d8ceff;
  --ai-500: #7a5ae0;
  --ai-600: #6d4aff;
  --ai-gradient: linear-gradient(135deg, #6d4aff 0%, #4f46e5 100%);
  
  --success-50: #edf8f3;
  --success-100: #d8f0e5;
  --success-500: #1f8a5b;
  --success-600: #187048;
  
  --warning-50: #fbf7ea;
  --warning-100: #f2e8bf;
  --warning-500: #b8860b;
  --warning-600: #946b08;
  
  --danger-50: #fdf1f0;
  --danger-100: #f7dddb;
  --danger-500: #d9534f;
  --danger-600: #c0492f;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -2px rgba(0, 0, 0, 0.05);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -4px rgba(0, 0, 0, 0.03);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.1), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
  --shadow-glow: 0 0 20px rgba(79, 70, 229, 0.25);
  --shadow-ai-glow: 0 0 20px rgba(109, 74, 255, 0.3);
}

:root[data-theme="dark"] {
  --bg-app: #0c0b12;
  --bg-surface: #16151f;
  --bg-card: #16151f;
  --bg-subtle: #211f2d;
  --bg-muted: #2b2938;
  --bg-hover: #211f2d;
  --bg-active: #2b2938;
  
  --text-main: #f4f3f8;
  --text-secondary: #c9c7d2;
  --text-muted: #9a98ad;
  --text-dim: #66647a;
  
  --border-subtle: rgba(255, 255, 255, 0.10);
  --border-base: rgba(255, 255, 255, 0.18);
  --border-strong: rgba(255, 255, 255, 0.28);
  
  --primary-50: #211f3b;
  --primary-100: #2d285e;
  --primary-200: #4038c8;
  --primary-500: #6d64f0;
  --primary-600: #5b52f0;
  --primary-700: #4f46e5;
  --primary-gradient: linear-gradient(135deg, #4f46e5 0%, #6d4aff 100%);
  
  --ai-50: #24183f;
  --ai-100: #382266;
  --ai-200: #5735a8;
  --ai-500: #8b6af2;
  --ai-600: #7a5ae0;
  --ai-gradient: linear-gradient(135deg, #6d4aff 0%, #4f46e5 100%);
  
  --success-50: #10291f;
  --success-100: #153d2c;
  --success-500: #42a778;
  --success-600: #1f8a5b;
  
  --warning-50: #30260f;
  --warning-100: #4a3810;
  --warning-500: #d2a22f;
  --warning-600: #b8860b;
  
  --danger-50: #35191b;
  --danger-100: #572326;
  --danger-500: #e07470;
  --danger-600: #d9534f;

  --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.4);
  --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.5), 0 2px 4px -2px rgba(0, 0, 0, 0.3);
  --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.6), 0 4px 6px -4px rgba(0, 0, 0, 0.4);
  --shadow-xl: 0 20px 25px -5px rgba(0, 0, 0, 0.7), 0 8px 10px -6px rgba(0, 0, 0, 0.5);
  --shadow-glow: 0 0 25px rgba(79, 70, 229, 0.35);
  --shadow-ai-glow: 0 0 25px rgba(109, 74, 255, 0.4);
}

/* Reset & Base */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  font-family: "Vazirmatn", system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background-color: var(--bg-app);
  color: var(--text-main);
  line-height: 1.6;
  direction: rtl;
  text-align: right;
  overflow: hidden;
  height: 100vh;
  width: 100vw;
  user-select: none;
}

.ltr {
  direction: ltr;
  unicode-bidi: embed;
  display: inline-block;
}

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

button {
  cursor: pointer;
  border: none;
  background: transparent;
}

/* Custom Scrollbar */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 9999px;
}
::-webkit-scrollbar-thumb:hover {
  background: var(--text-dim);
}

/* Layout */
#app {
  display: flex;
  height: 100vh;
  width: 100vw;
  background: var(--bg-app);
  overflow: hidden;
  position: relative;
}

/* Sidebar & Header */
.sidebar {
  width: 260px;
  min-width: 260px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-base);
  display: flex;
  flex-direction: column;
  height: 100vh;
  transition: width 0.25s cubic-bezier(0.16, 1, 0.3, 1), min-width 0.25s cubic-bezier(0.16, 1, 0.3, 1);
  z-index: 40;
  position: relative;
}

.sidebar-header {
  padding: 16px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border-subtle);
  min-height: 70px;
  height: 70px;
  position: relative;
  transition: all 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.brand-wrapper {
  display: flex;
  align-items: center;
  gap: 12px;
  overflow: hidden;
  text-decoration: none;
  min-width: 0;
}

.brand-icon {
  width: 38px;
  height: 38px;
  min-width: 38px;
  border-radius: 10px;
  background: var(--primary-gradient);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  box-shadow: var(--shadow-md);
  transition: transform 0.2s;
}

.brand-wrapper:hover .brand-icon {
  transform: scale(1.05);
}

.brand-text {
  display: flex;
  flex-direction: column;
  white-space: nowrap;
  transition: opacity 0.2s;
  overflow: hidden;
}

.brand-title {
  font-weight: 800;
  font-size: 17px;
  color: var(--text-main);
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 6px;
}

.brand-badge {
  font-size: 10px;
  font-weight: 700;
  background: var(--primary-100);
  color: var(--primary-700);
  padding: 1px 6px;
  border-radius: 6px;
}

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

.sidebar-toggle-btn {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  background: var(--bg-subtle);
  border: 1px solid var(--border-base);
  cursor: pointer;
  transition: all 0.2s cubic-bezier(0.16, 1, 0.3, 1);
  flex-shrink: 0;
}

.sidebar-toggle-btn:hover {
  background: var(--bg-hover);
  color: var(--primary-600);
  border-color: var(--primary-500);
  transform: scale(1.05);
}

.sidebar-toggle-btn .toggle-icon {
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

/* Nav Area */
.sidebar-nav {
  flex: 1;
  padding: 14px 10px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.nav-section-title {
  font-size: 10.5px;
  font-weight: 700;
  color: var(--text-dim);
  padding: 6px 12px 2px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 10px;
  color: var(--text-secondary);
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.15s ease;
  position: relative;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.nav-item.active {
  background: var(--primary-50);
  color: var(--primary-700);
  font-weight: 700;
}

:root[data-theme="dark"] .nav-item.active {
  background: rgba(79, 70, 229, 0.15);
  color: var(--primary-500);
}

.nav-item-icon {
  width: 20px;
  height: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.nav-item-label {
  white-space: nowrap;
  flex: 1;
}

.nav-item-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 9999px;
  background: var(--bg-muted);
  color: var(--text-secondary);
}

.nav-item-badge.primary {
  background: var(--primary-600);
  color: #ffffff;
}

.nav-item-badge.ai {
  background: var(--ai-gradient);
  color: #ffffff;
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 12px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg-surface);
}

.system-status-indicator {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--bg-subtle);
  border-radius: 8px;
  font-size: 12px;
  color: var(--text-muted);
  cursor: pointer;
  transition: all 0.15s;
}

.system-status-indicator:hover {
  background: var(--bg-hover);
  color: var(--text-main);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--success-500);
  box-shadow: 0 0 8px var(--success-500);
  flex-shrink: 0;
}

/* Collapsed Sidebar Rules */
.sidebar.collapsed {
  width: 72px;
  min-width: 72px;
}

.sidebar.collapsed .sidebar-header {
  padding: 16px 0;
  justify-content: center;
}

.sidebar.collapsed .brand-wrapper {
  justify-content: center;
  width: 100%;
  gap: 0;
}

.sidebar.collapsed .brand-icon {
  margin: 0 auto;
}

.sidebar.collapsed .brand-text {
  display: none;
}

.sidebar.collapsed .sidebar-toggle-btn {
  position: absolute;
  left: -13px;
  top: 22px;
  width: 26px;
  height: 26px;
  min-width: 26px;
  border-radius: 50%;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow-md);
  z-index: 50;
}

.sidebar.collapsed .sidebar-toggle-btn:hover {
  background: var(--primary-600);
  color: #ffffff;
  border-color: var(--primary-600);
  transform: scale(1.15);
  box-shadow: var(--shadow-glow);
}

.sidebar.collapsed .sidebar-toggle-btn .toggle-icon {
  transform: rotate(180deg);
}

.sidebar.collapsed .sidebar-nav {
  padding: 12px 0;
  gap: 4px;
}

.sidebar.collapsed .nav-section-title {
  display: none;
}

.sidebar.collapsed .nav-item {
  width: 46px;
  height: 46px;
  padding: 0;
  margin: 0 auto;
  justify-content: center;
  border-radius: 12px;
  gap: 0;
}

.sidebar.collapsed .nav-item-label {
  display: none;
}

.sidebar.collapsed .nav-item-icon {
  width: 22px;
  height: 22px;
  margin: 0;
}

.sidebar.collapsed .nav-item-icon svg {
  width: 20px;
  height: 20px;
}

.sidebar.collapsed .nav-item-badge {
  position: absolute;
  top: 3px;
  left: 3px;
  padding: 1px 4px;
  font-size: 9px;
  font-weight: 800;
  min-width: 16px;
  height: 16px;
  border-radius: 9999px;
  line-height: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-surface);
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
}

.sidebar.collapsed .nav-item {
  position: relative;
}

.sidebar.collapsed .nav-item::after {
  content: attr(data-tooltip);
  position: absolute;
  right: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%) scale(0.95);
  background: var(--text-main);
  color: var(--bg-surface);
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-lg);
  z-index: 100;
}

.sidebar.collapsed .nav-item:hover::after {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

.sidebar.collapsed .sidebar-footer {
  padding: 12px 0;
  display: flex;
  justify-content: center;
  align-items: center;
}

.sidebar.collapsed .system-status-indicator {
  width: 44px;
  height: 44px;
  padding: 0;
  margin: 0 auto;
  justify-content: center;
  border-radius: 12px;
  position: relative;
}

.sidebar.collapsed .system-status-indicator span {
  display: none;
}

.sidebar.collapsed .system-status-indicator::after {
  content: "سرویس‌ها: کاملاً پایدار (۹۹.۹٪)";
  position: absolute;
  right: calc(100% + 10px);
  top: 50%;
  transform: translateY(-50%) scale(0.95);
  background: var(--text-main);
  color: var(--bg-surface);
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: all 0.15s cubic-bezier(0.16, 1, 0.3, 1);
  box-shadow: var(--shadow-lg);
  z-index: 100;
}

.sidebar.collapsed .system-status-indicator:hover::after {
  opacity: 1;
  transform: translateY(-50%) scale(1);
}

/* App Header & Remaining Global Layout Styles */
.main-wrapper {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  min-width: 0;
}

.app-header {
  height: 70px;
  min-height: 70px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-base);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  z-index: 30;
  position: relative;
}

.header-left, .header-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.workspace-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-base);
  background: var(--bg-surface);
  transition: all 0.15s;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-main);
}

.workspace-btn:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
}

.org-avatar {
  width: 26px;
  height: 26px;
  border-radius: 7px;
  background: var(--primary-600);
  color: #fff;
  font-size: 12px;
  font-weight: 800;
  display: flex;
  align-items: center;
  justify-content: center;
}

.global-search-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg-subtle);
  border: 1px solid var(--border-base);
  border-radius: 12px;
  padding: 8px 16px;
  width: 440px;
  max-width: 100%;
  cursor: pointer;
  transition: all 0.2s;
}

.global-search-bar:hover {
  border-color: var(--primary-500);
  background: var(--bg-surface);
  box-shadow: var(--shadow-sm);
}

.search-placeholder {
  font-size: 13px;
  color: var(--text-muted);
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.search-kbd {
  font-size: 11px;
  font-weight: 700;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  color: var(--text-muted);
  padding: 2px 6px;
  border-radius: 6px;
  font-family: monospace;
}

.ai-copilot-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--ai-gradient);
  color: #ffffff;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s;
}

.ai-copilot-btn:hover {
  box-shadow: var(--shadow-ai-glow);
  transform: translateY(-1px);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-secondary);
  border: 1px solid var(--border-base);
  background: var(--bg-surface);
  transition: all 0.15s;
  position: relative;
}

.icon-btn:hover {
  background: var(--bg-hover);
  color: var(--text-main);
  border-color: var(--border-strong);
}

.notification-badge {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 8px;
  height: 8px;
  background: var(--danger-500);
  border-radius: 50%;
  border: 2px solid var(--bg-surface);
}

.user-profile-btn {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px 8px 4px 12px;
  border-radius: 10px;
  border: 1px solid var(--border-base);
  background: var(--bg-surface);
  cursor: pointer;
}

.user-profile-btn:hover {
  background: var(--bg-hover);
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: #2a6fdb;
  color: #fff;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
}

.user-info {
  display: flex;
  flex-direction: column;
  text-align: right;
}

.user-name {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-main);
  line-height: 1.2;
}

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

/* Dropdown Menus */
.dropdown-menu-popover {
  position: absolute;
  top: 64px;
  background: var(--bg-surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow-xl);
  z-index: 100;
  display: none;
  flex-direction: column;
  overflow: hidden;
  animation: modalPop 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}

.dropdown-menu-popover.open {
  display: flex;
}

/* Views & Pages */
.view-content {
  flex: 1;
  overflow-y: auto;
  position: relative;
  background: var(--bg-app);
}

.view-pane {
  display: none;
  min-height: 100%;
}

.view-pane.active {
  display: block;
  animation: fadeIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.page-header-bar {
  padding: 24px 32px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 16px;
}

.page-title-area {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.page-main-title {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

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

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

.btn-primary {
  background: var(--primary-600);
  color: #ffffff;
  padding: 9px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
  box-shadow: var(--shadow-sm);
}

.btn-primary:hover {
  background: var(--primary-700);
  box-shadow: var(--shadow-md);
}

.btn-secondary {
  background: var(--bg-surface);
  color: var(--text-secondary);
  border: 1px solid var(--border-base);
  padding: 8px 16px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  transition: all 0.15s;
}

.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--border-strong);
  color: var(--text-main);
}

.sub-tabs-bar {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 0 32px;
  border-bottom: 1px solid var(--border-base);
  background: var(--bg-surface);
  overflow-x: auto;
}

.sub-tab-btn {
  padding: 12px 16px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  white-space: nowrap;
  display: flex;
  align-items: center;
  gap: 6px;
}

.sub-tab-btn:hover {
  color: var(--text-main);
}

.sub-tab-btn.active {
  color: var(--primary-600);
  border-bottom-color: var(--primary-600);
  font-weight: 700;
}

:root[data-theme="dark"] .sub-tab-btn.active {
  color: var(--primary-500);
  border-bottom-color: var(--primary-500);
}

/* KPI, Cards, Layout Helpers */
.home-container, .analytics-container, .ai-hub-container, .automation-canvas-wrapper {
  padding: 24px 32px 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 16px;
}

@media (max-width: 1200px) { .kpi-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 640px) { .kpi-grid { grid-template-columns: 1fr; } }

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-base);
  border-radius: 14px;
  padding: 18px 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  box-shadow: var(--shadow-sm);
  transition: all 0.2s;
}

.kpi-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
  border-color: var(--border-strong);
}

.kpi-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.kpi-card-title {
  font-size: 13px;
  color: var(--text-muted);
  font-weight: 600;
}

.kpi-icon-wrap {
  width: 32px;
  height: 32px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.kpi-value-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.kpi-number {
  font-size: 22px;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.02em;
}

.kpi-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.kpi-badge.up { background: var(--success-50); color: var(--success-600); }
.kpi-badge.warn { background: var(--warning-50); color: var(--warning-600); }
.kpi-badge.danger { background: var(--danger-50); color: var(--danger-600); }
.kpi-footer-note { font-size: 11px; color: var(--text-dim); }

.ai-insights-hero {
  background: linear-gradient(135deg, rgba(109, 74, 255, 0.08) 0%, rgba(79, 70, 229, 0.08) 100%);
  border: 1px solid rgba(109, 74, 255, 0.3);
  border-radius: 16px;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  position: relative;
  overflow: hidden;
}

.ai-insights-hero::before {
  content: '';
  position: absolute;
  top: 0;
  right: 0;
  width: 4px;
  height: 100%;
  background: var(--ai-gradient);
}

.ai-insights-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.ai-pill-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--ai-gradient);
  color: #fff;
  padding: 3px 10px;
  border-radius: 9999px;
  font-size: 11px;
  font-weight: 700;
}

.ai-cards-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 16px;
}

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

.ai-insight-item {
  background: var(--bg-surface);
  border: 1px solid var(--border-base);
  border-radius: 12px;
  padding: 16px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 12px;
}

.ai-insight-text { font-size: 13.5px; color: var(--text-secondary); line-height: 1.7; }

.ai-insight-cta {
  align-self: flex-start;
  font-size: 12px;
  font-weight: 700;
  color: var(--ai-600);
  background: var(--ai-50);
  border: 1px solid var(--ai-200);
  padding: 6px 12px;
  border-radius: 8px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  transition: all 0.15s;
}

.ai-insight-cta:hover { background: var(--ai-100); transform: translateX(-2px); }

.command-sections-grid {
  display: grid;
  grid-template-columns: 1.1fr 1fr 0.9fr;
  gap: 20px;
}

@media (max-width: 1200px) { .command-sections-grid { grid-template-columns: 1fr; } }

.command-section-card {
  background: var(--bg-card);
  border: 1px solid var(--border-base);
  border-radius: 14px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.section-card-title {
  font-size: 15px;
  font-weight: 700;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.task-list { display: flex; flex-direction: column; gap: 10px; }

.task-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-subtle);
  border-radius: 10px;
  border: 1px solid var(--border-subtle);
  font-size: 13px;
  transition: all 0.15s;
}

.task-item:hover { border-color: var(--border-strong); background: var(--bg-hover); }
.task-item.done { opacity: 0.6; text-decoration: line-through; background: var(--bg-subtle); }
.task-checkbox { width: 18px; height: 18px; border-radius: 5px; border: 2px solid var(--border-strong); cursor: pointer; }

.funnel-bar-item { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.funnel-meta { display: flex; justify-content: space-between; font-size: 12px; font-weight: 600; }
.progress-track { height: 8px; background: var(--bg-muted); border-radius: 9999px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 9999px; transition: width 0.5s ease; }

/* Inbox 3-Column */
.inbox-layout {
  display: flex;
  height: calc(100vh - 70px);
  overflow: hidden;
  background: var(--bg-app);
}

.inbox-list-col {
  width: 340px;
  min-width: 340px;
  background: var(--bg-surface);
  border-left: 1px solid var(--border-base);
  display: flex;
  flex-direction: column;
  height: 100%;
}

.inbox-list-header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.inbox-search-input {
  width: 100%;
  padding: 8px 12px;
  border-radius: 8px;
  border: 1px solid var(--border-base);
  background: var(--bg-subtle);
  font-size: 13px;
}

.inbox-filters-scroll {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding-bottom: 4px;
}

.inbox-filter-pill {
  padding: 4px 10px;
  border-radius: 9999px;
  font-size: 11.5px;
  font-weight: 600;
  background: var(--bg-subtle);
  color: var(--text-muted);
  white-space: nowrap;
  cursor: pointer;
  transition: all 0.15s;
}

.inbox-filter-pill:hover { background: var(--bg-hover); color: var(--text-main); }
.inbox-filter-pill.active { background: var(--primary-600); color: #fff; }

.conversations-scroll { flex: 1; overflow-y: auto; }

.conversation-item {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  gap: 12px;
  cursor: pointer;
  transition: all 0.15s;
  position: relative;
}

.conversation-item:hover { background: var(--bg-hover); }
.conversation-item.active { background: var(--primary-50); border-right: 3px solid var(--primary-600); }
:root[data-theme="dark"] .conversation-item.active { background: rgba(79, 70, 229, 0.12); border-right: 3px solid var(--primary-500); }

.conv-avatar-wrap { position: relative; flex-shrink: 0; }
.conv-avatar {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 14px;
  color: #fff;
}

.channel-badge-icon {
  position: absolute;
  bottom: -2px;
  left: -2px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg-surface);
  font-size: 10px;
}

.conv-details { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.conv-top-row { display: flex; justify-content: space-between; align-items: center; }
.conv-customer-name { font-size: 13.5px; font-weight: 700; color: var(--text-main); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-time { font-size: 11px; color: var(--text-dim); }
.conv-last-msg { font-size: 12.5px; color: var(--text-muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.conv-meta-row { display: flex; align-items: center; gap: 6px; margin-top: 2px; }

.tag-badge {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 6px;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

.tag-badge.primary { background: var(--primary-50); color: var(--primary-700); }

.inbox-chat-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-app);
  height: 100%;
  min-width: 0;
  border-left: 1px solid var(--border-base);
}

.chat-thread-header {
  padding: 12px 20px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border-base);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  min-height: 65px;
}

.chat-header-info { display: flex; align-items: center; gap: 12px; }
.chat-header-actions { display: flex; align-items: center; gap: 8px; }

.ai-handoff-pill {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  border: 1px solid var(--border-base);
  background: var(--bg-subtle);
  cursor: pointer;
  transition: all 0.15s;
}

.ai-handoff-pill.ai-active { background: var(--ai-gradient); color: #fff; border-color: transparent; }

.chat-messages-area {
  flex: 1;
  padding: 20px 24px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.message-bubble-wrapper { display: flex; flex-direction: column; max-width: 75%; }
.message-bubble-wrapper.customer { align-self: flex-start; }
.message-bubble-wrapper.agent, .message-bubble-wrapper.ai-agent { align-self: flex-end; }
.message-bubble-wrapper.system { align-self: center; max-width: 90%; text-align: center; }

.system-chat-banner {
  background: var(--bg-subtle);
  border: 1px solid var(--border-base);
  padding: 6px 14px;
  border-radius: 8px;
  font-size: 11.5px;
  color: var(--text-muted);
}

.message-sender-name { font-size: 11px; font-weight: 700; color: var(--text-dim); margin-bottom: 4px; padding: 0 4px; }
.message-bubble { padding: 12px 16px; border-radius: 14px; font-size: 13.5px; line-height: 1.7; position: relative; }
.message-bubble-wrapper.customer .message-bubble { background: var(--bg-surface); color: var(--text-main); border: 1px solid var(--border-base); border-bottom-right-radius: 4px; }
.message-bubble-wrapper.agent .message-bubble { background: var(--primary-600); color: #ffffff; border-bottom-left-radius: 4px; }
.message-bubble-wrapper.ai-agent .message-bubble { background: var(--bg-surface); color: var(--text-main); border: 1px solid var(--ai-200); box-shadow: 0 0 12px rgba(109, 74, 255, 0.12); border-bottom-left-radius: 4px; }

.ai-citation-footer {
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border-base);
  font-size: 11px;
  color: var(--ai-600);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.message-time-stamp { font-size: 10.5px; color: var(--text-dim); align-self: flex-end; margin-top: 4px; padding: 0 4px; }

.chat-composer-box {
  padding: 14px 20px;
  background: var(--bg-surface);
  border-top: 1px solid var(--border-base);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.ai-suggestion-bar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: var(--ai-50);
  border: 1px solid var(--ai-200);
  border-radius: 10px;
}

.ai-suggestion-text { font-size: 12.5px; color: var(--text-secondary); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ai-apply-btn { background: var(--ai-gradient); color: #fff; padding: 4px 10px; border-radius: 6px; font-size: 11px; font-weight: 700; cursor: pointer; }

.composer-input-row { display: flex; gap: 10px; align-items: flex-end; }
.composer-textarea {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 10px 14px;
  border-radius: 10px;
  border: 1px solid var(--border-base);
  background: var(--bg-subtle);
  font-size: 13.5px;
  resize: none;
}

.inbox-context-col {
  width: 320px;
  min-width: 320px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border-base);
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.customer-profile-hero { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 8px; padding-bottom: 16px; border-bottom: 1px solid var(--border-subtle); }
.context-avatar { width: 64px; height: 64px; border-radius: 20px; background: var(--primary-gradient); color: #fff; font-size: 24px; font-weight: 800; display: flex; align-items: center; justify-content: center; box-shadow: var(--shadow-md); }
.ai-brief-card { background: var(--ai-50); border: 1px solid var(--ai-200); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.ai-brief-title { font-size: 12px; font-weight: 700; color: var(--ai-600); display: flex; align-items: center; gap: 6px; }
.ai-brief-text { font-size: 12.5px; color: var(--text-secondary); line-height: 1.7; }

/* Tables & Pipeline */
.table-container { padding: 20px 32px; }
.data-table-card { background: var(--bg-card); border: 1px solid var(--border-base); border-radius: 14px; overflow: hidden; box-shadow: var(--shadow-sm); }
.table-filter-bar { padding: 16px 20px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border-base); gap: 16px; flex-wrap: wrap; }
.search-field-wrapper { display: flex; align-items: center; gap: 8px; background: var(--bg-subtle); border: 1px solid var(--border-base); border-radius: 8px; padding: 6px 12px; width: 280px; }

.data-table { width: 100%; border-collapse: collapse; text-align: right; }
.data-table th { padding: 12px 18px; font-size: 12px; font-weight: 700; color: var(--text-muted); background: var(--bg-subtle); border-bottom: 1px solid var(--border-base); white-space: nowrap; }
.data-table td { padding: 14px 18px; font-size: 13px; color: var(--text-main); border-bottom: 1px solid var(--border-subtle); vertical-align: middle; }
.data-table tr:hover td { background: var(--bg-hover); }

/* Kanban & Deals */
.pipeline-view-container { padding: 20px 32px; display: flex; flex-direction: column; gap: 20px; height: calc(100vh - 135px); }
.pipeline-stats-strip { display: flex; align-items: center; gap: 20px; background: var(--bg-card); border: 1px solid var(--border-base); border-radius: 12px; padding: 14px 20px; flex-wrap: wrap; }
.pipeline-stat-item { display: flex; flex-direction: column; gap: 2px; padding-left: 20px; border-left: 1px solid var(--border-base); }
.pipeline-stat-item:last-child { border-left: none; }
.kanban-board-canvas { flex: 1; display: flex; gap: 16px; overflow-x: auto; padding-bottom: 16px; }
.kanban-column { width: 300px; min-width: 300px; background: var(--bg-subtle); border: 1px solid var(--border-base); border-radius: 14px; display: flex; flex-direction: column; max-height: 100%; }
.kanban-column-header { padding: 14px 16px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border-subtle); }
.col-header-title { font-size: 13.5px; font-weight: 700; display: flex; align-items: center; gap: 8px; }
.col-count-badge { font-size: 11px; font-weight: 700; background: var(--bg-muted); color: var(--text-secondary); padding: 2px 7px; border-radius: 9999px; }
.col-total-sum { font-size: 11.5px; color: var(--text-muted); font-weight: 600; }
.kanban-cards-list { flex: 1; padding: 12px; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; }

.deal-card { background: var(--bg-card); border: 1px solid var(--border-base); border-radius: 12px; padding: 14px; display: flex; flex-direction: column; gap: 10px; cursor: grab; box-shadow: var(--shadow-sm); transition: all 0.15s; }
.deal-card:hover { border-color: var(--primary-500); transform: translateY(-2px); box-shadow: var(--shadow-md); }
.deal-card-title { font-size: 13.5px; font-weight: 700; color: var(--text-main); }
.deal-card-amount { font-size: 14px; font-weight: 800; color: var(--primary-600); }
:root[data-theme="dark"] .deal-card-amount { color: var(--primary-500); }

/* Automation, AI, Analytics, Integrations, Modals */
.visual-canvas { background: var(--bg-card); border: 1px dashed var(--border-strong); border-radius: 16px; min-height: 520px; padding: 40px 20px; display: flex; flex-direction: column; align-items: center; gap: 20px; position: relative; background-image: radial-gradient(var(--border-base) 1px, transparent 1px); background-size: 20px 20px; transition: transform 0.2s ease; }
.flow-node { width: 320px; background: var(--bg-surface); border: 1px solid var(--border-base); border-radius: 14px; padding: 16px; display: flex; align-items: flex-start; gap: 12px; box-shadow: var(--shadow-md); position: relative; transition: all 0.2s; cursor: pointer; }
.flow-node:hover { transform: scale(1.02); box-shadow: var(--shadow-lg); border-color: var(--primary-500); }
.flow-node.highlighted { border-color: #1f8a5b !important; box-shadow: 0 0 18px rgba(31, 138, 91, 0.4) !important; transform: scale(1.04); }
.node-icon-box { width: 38px; height: 38px; border-radius: 10px; display: flex; align-items: center; justify-content: center; color: #fff; flex-shrink: 0; }
.flow-connector { width: 2px; height: 32px; background: var(--primary-500); position: relative; }
.flow-connector::after { content: ''; position: absolute; bottom: -4px; left: -4px; width: 10px; height: 10px; border-radius: 50%; background: var(--primary-500); }

.ai-tiers-grid, .sources-grid, .integrations-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 18px; }
@media (max-width: 1100px) { .ai-tiers-grid, .sources-grid, .integrations-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 700px) { .ai-tiers-grid, .sources-grid, .integrations-grid { grid-template-columns: 1fr; } }

.ai-tier-card, .source-card, .integration-card { background: var(--bg-card); border: 1px solid var(--border-base); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 12px; }
.ai-tier-card.featured { border-color: var(--ai-500); box-shadow: 0 0 20px rgba(109, 74, 255, 0.15); }

.chart-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; }
@media (max-width: 960px) { .chart-grid { grid-template-columns: 1fr; } }
.chart-card { background: var(--bg-card); border: 1px solid var(--border-base); border-radius: 14px; padding: 20px; display: flex; flex-direction: column; gap: 16px; }
.chart-svg { width: 100%; height: 220px; overflow: visible; }

/* Modals & Drawers */
.modal-overlay { position: fixed; inset: 0; background: rgba(26, 23, 48, 0.6); backdrop-filter: blur(4px); display: none; align-items: center; justify-content: center; z-index: 100; opacity: 0; transition: opacity 0.2s ease; }
.modal-overlay.open { display: flex; opacity: 1; }
.modal-box { background: var(--bg-surface); border: 1px solid var(--border-strong); border-radius: 16px; width: 600px; max-width: 92vw; max-height: 88vh; display: flex; flex-direction: column; box-shadow: var(--shadow-xl); overflow: hidden; animation: modalPop 0.2s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes modalPop { from { transform: scale(0.96) translateY(8px); } to { transform: scale(1) translateY(0); } }

.modal-header { padding: 18px 24px; border-bottom: 1px solid var(--border-base); display: flex; align-items: center; justify-content: space-between; }
.modal-body { padding: 24px; overflow-y: auto; display: flex; flex-direction: column; gap: 16px; }
.modal-footer { padding: 16px 24px; border-top: 1px solid var(--border-base); display: flex; align-items: center; justify-content: flex-end; gap: 10px; background: var(--bg-subtle); }

.ai-drawer { position: fixed; bottom: 24px; left: 24px; width: 400px; height: 580px; background: var(--bg-surface); border: 1px solid var(--ai-200); border-radius: 20px; box-shadow: var(--shadow-xl), var(--shadow-ai-glow); display: none; flex-direction: column; z-index: 90; overflow: hidden; animation: drawerSlide 0.25s cubic-bezier(0.16, 1, 0.3, 1); }
.ai-drawer.open { display: flex; }
@keyframes drawerSlide { from { transform: translateY(20px) scale(0.95); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }

#toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 10px; z-index: 200; pointer-events: none; }
.toast { background: var(--bg-surface); border: 1px solid var(--border-strong); border-radius: 12px; padding: 12px 18px; box-shadow: var(--shadow-lg); display: flex; align-items: center; gap: 12px; font-size: 13.5px; font-weight: 600; pointer-events: auto; animation: toastIn 0.3s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes toastIn { from { transform: translateX(50px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

.form-group { display: flex; flex-direction: column; gap: 6px; }
.form-label { font-size: 12.5px; font-weight: 700; color: var(--text-secondary); }
.form-control { width: 100%; padding: 9px 12px; border-radius: 8px; border: 1px solid var(--border-base); background: var(--bg-subtle); font-size: 13px; color: var(--text-main); transition: border-color 0.15s; }
.form-control:focus { border-color: var(--primary-500); background: var(--bg-surface); }

.switch { position: relative; display: inline-block; width: 44px; height: 24px; }
.switch input { opacity: 0; width: 0; height: 0; }
.slider { position: absolute; cursor: pointer; top: 0; left: 0; right: 0; bottom: 0; background-color: var(--border-strong); transition: .2s; border-radius: 24px; }
.slider:before { position: absolute; content: ""; height: 18px; width: 18px; left: 3px; bottom: 3px; background-color: white; transition: .2s; border-radius: 50%; }
input:checked + .slider { background-color: var(--primary-600); }
input:checked + .slider:before { transform: translateX(20px); }

/* ==========================================================================
   RESPONSIVE SYSTEM — DESKTOP / TABLET / MOBILE
   ========================================================================== */

/* Prevent flex and grid children from forcing their parents wider. */
.header-left,
.header-right,
.page-title-area,
.page-actions-area,
.kpi-card,
.command-section-card,
.chart-card,
.ai-tier-card,
.source-card,
.integration-card,
.chat-header-info,
.chat-header-actions,
.modal-header > *,
.modal-footer > * {
  min-width: 0;
}

img,
video,
canvas,
svg {
  max-width: 100%;
}

.page-subtitle,
.ai-insight-text,
.ai-brief-text,
.task-label-text,
.message-bubble,
.chart-card p,
.integration-card p,
.source-card p,
.ai-tier-card p {
  overflow-wrap: anywhere;
}

.data-table-card,
.chart-card,
.table-container,
.sub-tabs-bar,
.inbox-filters-scroll,
.kanban-board-canvas {
  -webkit-overflow-scrolling: touch;
}

/* Wide desktop and small laptop */
@media (max-width: 1280px) {
  .sidebar {
    width: 76px;
    min-width: 76px;
  }

  .sidebar .sidebar-header {
    padding: 16px 0;
    justify-content: center;
  }

  .sidebar .brand-wrapper {
    justify-content: center;
    width: 100%;
  }

  .sidebar .brand-text,
  .sidebar .nav-section-title,
  .sidebar .nav-item-label,
  .sidebar .system-status-indicator span {
    display: none;
  }

  .sidebar .sidebar-toggle-btn {
    display: none;
  }

  .sidebar .sidebar-nav {
    padding: 12px 0;
    gap: 4px;
  }

  .sidebar .nav-item {
    width: 46px;
    height: 46px;
    padding: 0;
    margin: 0 auto;
    justify-content: center;
    gap: 0;
    border-radius: 12px;
  }

  .sidebar .nav-item-badge {
    position: absolute;
    top: 3px;
    left: 3px;
    min-width: 16px;
    height: 16px;
    padding: 1px 4px;
    font-size: 9px;
    line-height: 14px;
    justify-content: center;
    border: 2px solid var(--bg-surface);
  }

  .sidebar .sidebar-footer {
    padding: 12px 0;
  }

  .sidebar .system-status-indicator {
    width: 44px;
    height: 44px;
    padding: 0;
    margin: 0 auto;
    justify-content: center;
  }

  .global-search-bar {
    width: clamp(220px, 32vw, 440px);
  }

  .app-header {
    padding-inline: 18px;
  }

  .inbox-list-col {
    width: 300px;
    min-width: 300px;
  }

  .inbox-context-col {
    width: 280px;
    min-width: 280px;
    padding: 16px;
  }
}

/* Tablet landscape and compact laptops */
@media (max-width: 1100px) {
  .user-info,
  .user-profile-btn > svg,
  .ai-copilot-btn > span:last-child {
    display: none;
  }

  .user-profile-btn {
    padding: 3px;
    border: 0;
  }

  .page-header-bar {
    align-items: flex-start;
  }

  .page-actions-area {
    flex-wrap: wrap;
    justify-content: flex-start;
  }

  .inbox-context-col {
    display: none;
  }

  .inbox-list-col {
    width: min(320px, 36vw);
    min-width: min(320px, 36vw);
  }

  .chat-thread-header {
    align-items: flex-start;
    flex-direction: column;
    gap: 10px;
  }

  .chat-header-actions {
    width: 100%;
    overflow-x: auto;
    padding-bottom: 2px;
  }

  .chat-header-actions > * {
    flex: 0 0 auto;
  }

  .table-container,
  .home-container,
  .analytics-container,
  .ai-hub-container,
  .automation-canvas-wrapper,
  .pipeline-view-container {
    padding-inline: 22px;
  }

  .data-table-card,
  .table-container {
    overflow-x: auto;
  }

  .data-table,
  .table-container table {
    min-width: 760px;
  }

  .page-header-bar {
    padding-inline: 22px;
  }

  .sub-tabs-bar {
    padding-inline: 22px;
  }
}

/* Tablet portrait */
@media (max-width: 900px) {
  .app-header {
    gap: 10px;
    padding-inline: 14px;
  }

  .header-left {
    flex: 1;
    min-width: 0;
  }

  .header-right {
    gap: 8px;
  }

  .workspace-btn > span,
  .workspace-btn > svg,
  .ai-copilot-btn > span {
    display: none;
  }

  .workspace-btn,
  .ai-copilot-btn {
    width: 40px;
    height: 40px;
    padding: 0;
    justify-content: center;
    flex: 0 0 40px;
  }

  .global-search-bar {
    width: auto;
    min-width: 0;
    flex: 1;
  }

  .page-header-bar {
    flex-direction: column;
  }

  .page-actions-area {
    width: 100%;
  }

  .page-actions-area > button,
  .page-actions-area > select {
    max-width: 100%;
  }

  .command-sections-grid,
  .ai-cards-grid,
  .chart-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  #dynamic-widgets-container {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .table-filter-bar {
    align-items: stretch;
  }

  .search-field-wrapper {
    width: min(100%, 420px);
  }

  .pipeline-view-container {
    height: auto;
    min-height: calc(100vh - 135px);
  }

  .kanban-board-canvas {
    min-height: 520px;
  }

  .chart-card > [style*="grid-template-columns"],
  .table-container > [style*="grid-template-columns"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }
}

/* Mobile navigation and stacked content */
@media (max-width: 720px) {
  body,
  #app,
  .main-wrapper {
    min-height: 100dvh;
  }

  #app {
    display: block;
  }

  .main-wrapper {
    width: 100%;
    height: 100dvh;
    padding-bottom: 66px;
  }

  .sidebar,
  .sidebar.collapsed {
    position: fixed;
    inset: auto 0 0 0;
    width: 100%;
    min-width: 0;
    height: 66px;
    z-index: 80;
    border: 0;
    border-top: 1px solid var(--border-base);
    background: color-mix(in srgb, var(--bg-surface) 94%, transparent);
    backdrop-filter: blur(16px);
  }

  .sidebar .sidebar-header,
  .sidebar.collapsed .sidebar-header,
  .sidebar .sidebar-footer,
  .sidebar.collapsed .sidebar-footer,
  .sidebar .nav-section-title,
  .sidebar.collapsed .nav-section-title {
    display: none;
  }

  .sidebar .sidebar-nav,
  .sidebar.collapsed .sidebar-nav {
    width: 100%;
    height: 66px;
    padding: 7px 8px 5px;
    flex-direction: row;
    align-items: stretch;
    gap: 4px;
    overflow-x: auto;
    overflow-y: hidden;
    scroll-snap-type: x proximity;
  }

  .sidebar .nav-item,
  .sidebar.collapsed .nav-item {
    width: 62px;
    min-width: 62px;
    height: 52px;
    padding: 5px 4px;
    margin: 0;
    flex-direction: column;
    justify-content: center;
    gap: 3px;
    scroll-snap-align: start;
    border-radius: 10px;
  }

  .sidebar .nav-item-label,
  .sidebar.collapsed .nav-item-label {
    display: block;
    width: 100%;
    flex: 0 0 auto;
    font-size: 9px;
    line-height: 1.15;
    text-align: center;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .sidebar .nav-item-icon,
  .sidebar.collapsed .nav-item-icon {
    width: 19px;
    height: 19px;
  }

  .sidebar .nav-item-icon svg,
  .sidebar.collapsed .nav-item-icon svg {
    width: 18px;
    height: 18px;
  }

  .sidebar .nav-item-badge,
  .sidebar.collapsed .nav-item-badge {
    top: 1px;
    left: 5px;
  }

  .sidebar .nav-item::after,
  .sidebar.collapsed .nav-item::after {
    display: none;
  }

  .app-header {
    height: 62px;
    min-height: 62px;
    padding-inline: 10px;
  }

  .global-search-bar {
    height: 40px;
    padding-inline: 11px;
  }

  .search-kbd {
    display: none;
  }

  .icon-btn,
  .user-avatar {
    width: 36px;
    height: 36px;
  }

  .view-content {
    min-height: 0;
  }

  .page-header-bar {
    padding: 18px 14px 12px;
    gap: 12px;
  }

  .page-main-title {
    font-size: 18px;
    line-height: 1.45;
  }

  .page-subtitle {
    font-size: 12px;
    line-height: 1.7;
  }

  .page-actions-area {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 8px;
  }

  .page-actions-area > button,
  .page-actions-area > select {
    width: 100% !important;
    min-width: 0;
    justify-content: center;
    white-space: normal;
    text-align: center;
  }

  .page-actions-area > :only-child,
  .page-actions-area > :last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  .sub-tabs-bar {
    padding-inline: 10px;
  }

  .sub-tab-btn {
    padding: 10px 12px;
    font-size: 12px;
  }

  .home-container,
  .analytics-container,
  .ai-hub-container,
  .automation-canvas-wrapper,
  .table-container,
  .pipeline-view-container {
    padding: 16px 14px 32px;
    gap: 16px;
  }

  .kpi-grid,
  .ai-cards-grid,
  .ai-tiers-grid,
  .sources-grid,
  .integrations-grid,
  .chart-grid,
  .command-sections-grid {
    grid-template-columns: minmax(0, 1fr);
    gap: 12px;
  }

  .kpi-card,
  .command-section-card,
  .chart-card,
  .ai-tier-card,
  .source-card,
  .integration-card {
    padding: 15px;
    border-radius: 12px;
  }

  .kpi-number {
    font-size: 19px;
  }

  .ai-insights-hero {
    padding: 16px;
  }

  .ai-insights-header,
  .section-card-title,
  .task-item,
  .pipeline-stats-strip {
    flex-wrap: wrap;
  }

  .chart-card [style*="display:flex"],
  .table-container [style*="display:flex"],
  .automation-canvas-wrapper [style*="display:flex"],
  .modal-body [style*="display:flex"],
  .ai-tier-card [style*="display:flex"],
  .integration-card [style*="display:flex"] {
    flex-wrap: wrap;
  }

  .ai-insight-cta,
  .btn-primary,
  .btn-secondary {
    max-width: 100%;
    white-space: normal;
  }

  /* Interaction page becomes an accessible vertical sequence. */
  .inbox-layout {
    display: flex;
    flex-direction: column;
    height: auto;
    min-height: 100%;
    overflow: visible;
  }

  .inbox-list-col {
    width: 100%;
    min-width: 0;
    height: 350px;
    min-height: 350px;
    border-left: 0;
    border-bottom: 1px solid var(--border-base);
  }

  .inbox-list-header {
    padding: 12px 14px;
  }

  .conversation-item {
    padding: 11px 14px;
  }

  .inbox-chat-col {
    width: 100%;
    height: auto;
    min-height: 640px;
    border-left: 0;
  }

  .chat-thread-header {
    padding: 12px 14px;
  }

  .chat-header-info {
    width: 100%;
  }

  .chat-header-info > div:last-child {
    min-width: 0;
  }

  .chat-header-info > div:last-child > div {
    flex-wrap: wrap;
  }

  .chat-header-actions {
    flex-wrap: nowrap;
  }

  .chat-messages-area {
    min-height: 360px;
    padding: 16px 14px;
  }

  .message-bubble-wrapper,
  .message-bubble-wrapper.system {
    max-width: 92%;
  }

  .chat-composer-box {
    padding: 12px 14px;
  }

  .ai-suggestion-bar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .ai-suggestion-text {
    min-width: 180px;
    white-space: normal;
  }

  .composer-input-row {
    flex-wrap: wrap;
  }

  .composer-textarea {
    flex-basis: calc(100% - 50px);
  }

  .inbox-context-col {
    display: flex;
    width: 100%;
    min-width: 0;
    height: auto;
    overflow: visible;
    border: 0;
    border-top: 1px solid var(--border-base);
    padding: 16px 14px 28px;
  }

  /* Tables keep their geometry and scroll instead of crushing columns. */
  .data-table-card {
    overflow-x: auto;
  }

  .data-table,
  .table-container table,
  .chart-card table {
    min-width: 720px;
  }

  .table-filter-bar {
    padding: 12px;
    flex-direction: column;
    align-items: stretch;
  }

  .table-filter-bar > div {
    width: 100%;
    flex-wrap: wrap;
  }

  .search-field-wrapper {
    width: 100%;
  }

  .pipeline-stats-strip {
    gap: 12px;
    padding: 12px;
  }

  .pipeline-stat-item {
    min-width: calc(50% - 8px);
    padding-left: 10px;
  }

  .kanban-column {
    width: min(82vw, 300px);
    min-width: min(82vw, 300px);
  }

  .visual-canvas {
    min-height: 460px;
    padding: 28px 12px;
    overflow: hidden;
  }

  .flow-node {
    width: min(100%, 320px);
    padding: 13px;
  }

  .chart-card {
    overflow-x: auto;
  }

  .chart-svg {
    min-width: 500px;
    height: 220px;
  }

  /* Inline modal grids are converted to one column. */
  .modal-body [style*="grid-template-columns"],
  .chart-card [style*="grid-template-columns"],
  .table-container [style*="grid-template-columns"] {
    grid-template-columns: minmax(0, 1fr) !important;
  }

  .modal-overlay {
    align-items: flex-end;
    padding: 0;
  }

  .modal-box,
  .modal-box[style] {
    width: 100% !important;
    max-width: 100vw;
    max-height: min(92dvh, 860px);
    border-radius: 18px 18px 0 0;
  }

  .modal-header {
    padding: 15px 16px;
    gap: 12px;
  }

  .modal-body {
    padding: 16px;
  }

  .modal-footer {
    padding: 12px 16px;
    flex-wrap: wrap;
  }

  .modal-footer > button {
    flex: 1 1 140px;
    justify-content: center;
  }

  .ai-drawer {
    inset: auto 0 66px 0;
    width: 100%;
    height: min(72dvh, 620px);
    border-radius: 18px 18px 0 0;
  }

  .dropdown-menu-popover,
  .dropdown-menu-popover[style] {
    position: fixed;
    top: 62px;
    right: 10px;
    left: 10px !important;
    width: auto !important;
    max-height: calc(100dvh - 144px);
  }

  #toast-container {
    right: 12px;
    left: 12px;
    bottom: 78px;
  }

  .toast {
    width: 100%;
  }
}

/* Narrow phones */
@media (max-width: 480px) {
  .header-right > .ai-copilot-btn {
    display: none;
  }

  .search-placeholder {
    font-size: 11.5px;
  }

  .page-actions-area {
    grid-template-columns: minmax(0, 1fr);
  }

  .page-actions-area > * {
    grid-column: 1 !important;
  }

  .kpi-grid {
    grid-template-columns: minmax(0, 1fr);
  }

  .task-item {
    align-items: flex-start;
  }

  .conv-meta-row {
    flex-wrap: wrap;
  }

  .chat-header-actions .btn-secondary {
    padding-inline: 10px;
    font-size: 11px;
  }

  .ai-handoff-pill {
    padding-inline: 9px;
    font-size: 11px;
  }

  .message-bubble {
    padding: 10px 12px;
    font-size: 13px;
  }

  .pipeline-stat-item {
    min-width: 100%;
    border-left: 0;
    border-bottom: 1px solid var(--border-base);
    padding: 0 0 8px;
  }

  .chart-svg {
    min-width: 440px;
  }
}
