/* ==========================================================================
   Apple Human Interface Guidelines (HIG) Design System — Almasar AI OS
   Grounded in Apple HIG (2026):
   - Liquid Glass strictly on Functional Layer (topbar, sidebar, mobile tab bar, sheets)
   - Clean opaque Apple System Grouped surfaces in Content Layer (#F5F5F7 / #000000)
   - WCAG AA 4.5:1+ verified label hierarchy (#1D1D1F, #515154, #6E6E73 | #F5F5F7, #A1A1A6, #8E8E93)
   - Single Apple Blue (#0071E3 / #0A84FF) primary action budget per view
   - 44x44 pt touch targets on coarse pointers + Reduced Motion / Transparency / High Contrast
   ========================================================================== */

@font-face {
  font-family: "CairoLocal";
  src: url("/assets/fonts/Cairo-Variable.ttf") format("truetype");
  font-weight: 200 900;
  font-style: normal;
  font-display: swap;
}

:root,
body:not(.theme-dark) {
  --apple-bg: #f5f5f7;
  --apple-surface: #ffffff;
  --apple-surface-secondary: #fbfbfd;
  --apple-surface-grouped: #f5f5f7;
  --apple-fill: rgba(118, 118, 128, 0.12);
  --apple-fill-hover: rgba(118, 118, 128, 0.18);
  --apple-fill-subtle: rgba(118, 118, 128, 0.06);
  --apple-label: #1d1d1f;
  --apple-label-secondary: #515154;
  --apple-label-tertiary: #6e6e73;
  --apple-separator: rgba(60, 60, 67, 0.13);
  --apple-separator-strong: rgba(60, 60, 67, 0.24);
  --apple-accent: #0071e3;
  --apple-accent-hover: #0077ed;
  --apple-accent-pressed: #0068d1;
  --apple-accent-soft: rgba(0, 113, 227, 0.1);
  --apple-green: #1d8348;
  --apple-green-bg: rgba(52, 199, 89, 0.14);
  --apple-red: #d70015;
  --apple-red-bg: rgba(255, 59, 48, 0.12);
  --apple-amber: #b25000;
  --apple-amber-bg: rgba(255, 149, 0, 0.14);

  /* Liquid Glass (Regular Variant — Functional Layer Only) */
  --glass-bg: rgba(255, 255, 255, 0.74);
  --glass-sidebar-bg: rgba(248, 248, 250, 0.78);
  --glass-border: rgba(0, 0, 0, 0.08);
  --glass-highlight: inset 0 0.5px 0 rgba(255, 255, 255, 0.85);
  --apple-shadow-card: 0 2px 12px rgba(0, 0, 0, 0.035), 0 0.5px 1px rgba(0, 0, 0, 0.04);
  --apple-shadow-elevated: 0 12px 34px rgba(0, 0, 0, 0.08), 0 2px 6px rgba(0, 0, 0, 0.04);
  --apple-shadow-sheet: 0 24px 68px rgba(0, 0, 0, 0.2), 0 4px 16px rgba(0, 0, 0, 0.06);

  /* Bridge legacy variables seamlessly */
  --bg: var(--apple-bg);
  --bg-card: var(--apple-surface);
  --bg-elevated: var(--apple-surface-grouped);
  --bg-soft: var(--apple-surface-grouped);
  --surface: var(--apple-surface);
  --border: var(--apple-separator);
  --border-strong: rgba(0, 113, 227, 0.35);
  --text: var(--apple-label);
  --text-muted: var(--apple-label-secondary);
  --primary: var(--apple-accent);
  --primary-hover: var(--apple-accent-hover);
  --accent: var(--apple-accent);
  --radius: 20px;
}

body.theme-dark {
  --apple-bg: #000000;
  --apple-surface: #1c1c1e;
  --apple-surface-secondary: #242426;
  --apple-surface-grouped: #2c2c2e;
  --apple-fill: rgba(118, 118, 128, 0.24);
  --apple-fill-hover: rgba(118, 118, 128, 0.34);
  --apple-fill-subtle: rgba(118, 118, 128, 0.14);
  --apple-label: #f5f5f7;
  --apple-label-secondary: #a1a1a6;
  --apple-label-tertiary: #8e8e93;
  --apple-separator: rgba(84, 84, 88, 0.48);
  --apple-separator-strong: rgba(120, 120, 128, 0.56);
  --apple-accent: #0a84ff;
  --apple-accent-hover: #409cff;
  --apple-accent-pressed: #0070e0;
  --apple-accent-soft: rgba(10, 132, 255, 0.18);
  --apple-green: #30d158;
  --apple-green-bg: rgba(48, 209, 88, 0.18);
  --apple-red: #ff453a;
  --apple-red-bg: rgba(255, 69, 58, 0.18);
  --apple-amber: #ff9f0a;
  --apple-amber-bg: rgba(255, 159, 10, 0.18);

  --glass-bg: rgba(28, 28, 30, 0.74);
  --glass-sidebar-bg: rgba(22, 22, 24, 0.78);
  --glass-border: rgba(255, 255, 255, 0.11);
  --glass-highlight: inset 0 0.5px 0 rgba(255, 255, 255, 0.12);
  --apple-shadow-card: 0 4px 20px rgba(0, 0, 0, 0.36);
  --apple-shadow-elevated: 0 14px 40px rgba(0, 0, 0, 0.52);
  --apple-shadow-sheet: 0 28px 80px rgba(0, 0, 0, 0.72);

  --bg: var(--apple-bg);
  --bg-card: var(--apple-surface);
  --bg-elevated: var(--apple-surface-grouped);
  --bg-soft: var(--apple-surface-grouped);
  --surface: var(--apple-surface);
  --border: var(--apple-separator);
  --border-strong: rgba(10, 132, 255, 0.45);
  --text: var(--apple-label);
  --text-muted: var(--apple-label-secondary);
  --primary: var(--apple-accent);
  --primary-hover: var(--apple-accent-hover);
  --accent: var(--apple-accent);
}

/* Base Canvas & Apple SF Typography Scale */
html {
  color-scheme: light dark;
  -webkit-text-size-adjust: 100%;
}

body,
body:not(.theme-dark),
body.theme-dark {
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display", "SF Pro Arabic", "IBM Plex Sans Arabic", "Cairo", system-ui, sans-serif !important;
  background: var(--apple-bg) !important;
  background-image: none !important;
  color: var(--apple-label) !important;
  font-size: 14px;
  line-height: 1.55;
  letter-spacing: -0.008em;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

/* App Shell & Collapsible macOS Split View */
.app-shell {
  display: grid;
  grid-template-columns: 268px minmax(0, 1fr);
  min-height: 100dvh;
  transition: grid-template-columns 0.26s cubic-bezier(0.25, 1, 0.5, 1);
}

body.sidebar-collapsed .app-shell {
  grid-template-columns: 0px minmax(0, 1fr);
}

body.sidebar-collapsed .sidebar {
  transform: translateX(102%);
  opacity: 0;
  pointer-events: none;
  padding-inline: 0;
  border: none;
  overflow: hidden;
}

/* ==========================================================================
   1. FUNCTIONAL LAYER — Liquid Glass (Sidebar, Topbar, Sheets, Mobile Tab Bar)
   ========================================================================== */
.sidebar,
body:not(.theme-dark) .sidebar,
body.theme-dark .sidebar {
  background: var(--glass-sidebar-bg) !important;
  backdrop-filter: blur(28px) saturate(180%) !important;
  -webkit-backdrop-filter: blur(28px) saturate(180%) !important;
  border-left: 0.5px solid var(--glass-border) !important;
  box-shadow: var(--glass-highlight) !important;
  padding: 16px 12px !important;
  gap: 10px !important;
  transition: transform 0.26s cubic-bezier(0.25, 1, 0.5, 1), opacity 0.2s ease;
  z-index: 60;
}

.brand-box,
body:not(.theme-dark) .brand-box,
body.theme-dark .brand-box {
  background: transparent !important;
  border: none !important;
  box-shadow: none !important;
  padding: 6px 8px 10px !important;
  border-bottom: 0.5px solid var(--apple-separator) !important;
  border-radius: 0 !important;
}

.brand-logo-mark svg rect {
  fill: var(--apple-accent) !important;
}

.brand-logo-mark {
  filter: none !important;
}

.brand-title,
body:not(.theme-dark) .brand-title {
  font-size: 14.5px !important;
  font-weight: 700 !important;
  color: var(--apple-label) !important;
  letter-spacing: -0.015em;
}

.brand-sub,
body:not(.theme-dark) .brand-sub,
body.theme-dark .brand-sub {
  font-size: 12px !important;
  font-weight: 500 !important;
  color: var(--apple-label-tertiary) !important;
}

.zero-cost-pill,
body:not(.theme-dark) .zero-cost-pill,
body.theme-dark .zero-cost-pill {
  background: var(--apple-fill-subtle) !important;
  border: 0.5px solid var(--apple-separator) !important;
  color: var(--apple-label-secondary) !important;
  border-radius: 980px !important;
  padding: 6px 12px !important;
  font-size: 12px !important;
  font-weight: 600 !important;
}

.dot-live {
  background: #34c759 !important;
  box-shadow: 0 0 0 3px rgba(52, 199, 89, 0.2) !important;
  animation: none !important;
}

/* macOS Sidebar Group Headers & Navigation Rows */
.nav-group-label,
body:not(.theme-dark) .nav-group-label,
body.theme-dark .nav-group-label {
  font-size: 11.5px !important;
  font-weight: 700 !important;
  color: var(--apple-label-tertiary) !important;
  margin: 14px 10px 4px !important;
  padding-top: 10px !important;
  border-top: 0.5px solid var(--apple-separator) !important;
  letter-spacing: 0 !important;
}

.nav-group-label:first-child {
  border-top: none !important;
  margin-top: 4px !important;
  padding-top: 0 !important;
}

.nav-item,
body:not(.theme-dark) .nav-item,
body.theme-dark .nav-item {
  border-radius: 10px !important;
  padding: 8px 10px !important;
  min-height: 36px;
  margin: 1px 0 !important;
  font-size: 13.5px !important;
  font-weight: 500 !important;
  color: var(--apple-label) !important;
  border: none !important;
  background: transparent !important;
  box-shadow: none !important;
  transition: background-color 0.14s ease, color 0.14s ease !important;
}

.nav-item .nav-ic {
  color: var(--apple-accent) !important;
  opacity: 0.92 !important;
}

.nav-item:hover,
body:not(.theme-dark) .nav-item:hover,
body.theme-dark .nav-item:hover {
  background: var(--apple-fill-subtle) !important;
  color: var(--apple-label) !important;
  transform: none !important;
}

.nav-item.active,
body:not(.theme-dark) .nav-item.active,
body.theme-dark .nav-item.active {
  background: var(--apple-fill) !important;
  color: var(--apple-accent) !important;
  font-weight: 700 !important;
  box-shadow: none !important;
}

.nav-item.active .nav-ic {
  color: var(--apple-accent) !important;
  opacity: 1 !important;
}

.sidebar-footer {
  border-top: 0.5px solid var(--apple-separator) !important;
  padding: 12px 8px 4px !important;
  color: var(--apple-label-tertiary) !important;
  font-size: 11.5px !important;
}

.mode-line strong {
  color: var(--apple-label-secondary) !important;
  font-weight: 600 !important;
}

/* Sticky Liquid Glass Window Toolbar (Topbar) */
.main-content {
  padding: 0 28px 56px !important;
  max-width: 1480px;
}

.topbar,
body:not(.theme-dark) .topbar,
body.theme-dark .topbar {
  position: sticky !important;
  top: 12px !important;
  z-index: 50 !important;
  margin: 12px 0 24px !important;
  padding: 12px 18px !important;
  min-height: 64px !important;
  border-radius: 18px !important;
  background: var(--glass-bg) !important;
  backdrop-filter: blur(28px) saturate(180%) !important;
  -webkit-backdrop-filter: blur(28px) saturate(180%) !important;
  border: 0.5px solid var(--glass-border) !important;
  box-shadow: var(--glass-highlight), 0 8px 24px rgba(0, 0, 0, 0.04) !important;
}

.topbar-title-group {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1 1 300px;
}

.sidebar-toggle-btn {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  border: none;
  background: var(--apple-fill-subtle);
  color: var(--apple-label-secondary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  flex-shrink: 0;
  transition: background-color 0.15s ease, color 0.15s ease;
}

.sidebar-toggle-btn:hover {
  background: var(--apple-fill);
  color: var(--apple-label);
}

.topbar h1,
body:not(.theme-dark) .topbar h1 {
  font-size: 21px !important;
  font-weight: 700 !important;
  color: var(--apple-label) !important;
  letter-spacing: -0.022em !important;
  line-height: 1.25 !important;
}

.subtitle,
body:not(.theme-dark) .subtitle {
  font-size: 12.5px !important;
  color: var(--apple-label-tertiary) !important;
  margin-top: 2px !important;
}

/* ==========================================================================
   2. CONTENT LAYER — Opaque Apple Bento Surfaces (Zero Blur on Content!)
   ========================================================================== */
.card,
.kpi-card,
.agent-card,
.dept-emp-card,
.inbox-pane-card,
.studio-post-card,
.radar-post-card,
.post-card-pro,
body:not(.theme-dark) .card,
body:not(.theme-dark) .kpi-card,
body:not(.theme-dark) .agent-card,
body:not(.theme-dark) .dept-emp-card,
body:not(.theme-dark) .inbox-pane-card,
body:not(.theme-dark) .studio-post-card {
  backdrop-filter: none !important;
  -webkit-backdrop-filter: none !important;
  background: var(--apple-surface) !important;
  border: 0.5px solid var(--apple-separator) !important;
  border-top: 0.5px solid var(--apple-separator) !important;
  border-radius: 20px !important;
  box-shadow: var(--apple-shadow-card) !important;
  color: var(--apple-label) !important;
}

.card {
  padding: 22px 24px !important;
}

.card-header,
body:not(.theme-dark) .card-header {
  border-bottom: 0.5px solid var(--apple-separator) !important;
  padding-bottom: 14px !important;
  margin-bottom: 16px !important;
}

.card-header h2,
.card-header h3,
.section-header h2,
body:not(.theme-dark) .card-header h2,
body:not(.theme-dark) .card-header h3,
body:not(.theme-dark) h2,
body:not(.theme-dark) h3,
body:not(.theme-dark) h4,
body:not(.theme-dark) strong {
  color: var(--apple-label) !important;
  letter-spacing: -0.015em;
}

.muted-note,
.hint,
body:not(.theme-dark) .muted-note,
body:not(.theme-dark) .hint {
  color: var(--apple-label-tertiary) !important;
  font-size: 13px !important;
}

/* Apple Bento KPI Tiles */
.kpi-grid {
  gap: 14px !important;
  margin-bottom: 20px !important;
}

.kpi-card,
body:not(.theme-dark) .kpi-card {
  padding: 18px 20px !important;
  border-radius: 20px !important;
  transition: transform 0.2s cubic-bezier(0.25, 1, 0.5, 1), box-shadow 0.2s ease !important;
}

.kpi-card:hover,
body:not(.theme-dark) .kpi-card:hover {
  transform: translateY(-2px) !important;
  box-shadow: var(--apple-shadow-elevated) !important;
  border-color: var(--apple-separator-strong) !important;
}

.kpi-label,
body:not(.theme-dark) .kpi-label {
  font-size: 12.5px !important;
  font-weight: 600 !important;
  color: var(--apple-label-secondary) !important;
}

.kpi-value,
body:not(.theme-dark) .kpi-value {
  font-size: 28px !important;
  font-weight: 700 !important;
  letter-spacing: -0.03em !important;
  color: var(--apple-label) !important;
  font-variant-numeric: tabular-nums;
  margin: 6px 0 4px !important;
}

.kpi-note,
body:not(.theme-dark) .kpi-note {
  font-size: 12px !important;
  font-weight: 500 !important;
  color: var(--apple-label-tertiary) !important;
}

/* Adaptive Apple Bento Banners (ROI, Enterprise Stack, Super-Admin, Onboarding) */
.onb-card,
body:not(.theme-dark) .onb-card,
body.theme-dark .onb-card {
  background: var(--apple-surface) !important;
  border: 0.5px solid var(--apple-separator) !important;
  border-radius: 20px !important;
  box-shadow: var(--apple-shadow-card) !important;
  color: var(--apple-label) !important;
}

.onb-progress-track {
  background: var(--apple-fill) !important;
}

.onb-progress-fill {
  background: var(--apple-accent) !important;
}

.onb-step,
body:not(.theme-dark) .onb-step,
body.theme-dark .onb-step {
  background: var(--apple-surface-grouped) !important;
  border: 0.5px solid var(--apple-separator) !important;
  border-radius: 14px !important;
  color: var(--apple-label) !important;
}

.onb-step strong {
  color: var(--apple-label) !important;
}

.onb-step small {
  color: var(--apple-label-tertiary) !important;
}

.onb-check {
  background: var(--apple-accent-soft) !important;
  color: var(--apple-accent) !important;
}

.onb-step.done,
body:not(.theme-dark) .onb-step.done,
body.theme-dark .onb-step.done {
  background: var(--apple-green-bg) !important;
  border-color: transparent !important;
}

.onb-step.done .onb-check {
  background: var(--apple-green) !important;
  color: #ffffff !important;
}

.onb-step.done strong {
  color: var(--apple-green) !important;
}

.apple-bento-banner {
  background: var(--apple-surface) !important;
  border: 0.5px solid var(--apple-separator) !important;
  border-radius: 20px !important;
  padding: 20px 22px !important;
  margin-bottom: 18px !important;
  box-shadow: var(--apple-shadow-card) !important;
}

.apple-bento-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 14px;
}

.apple-bento-title {
  font-weight: 700;
  font-size: 16px;
  color: var(--apple-label);
  letter-spacing: -0.015em;
}

.apple-bento-sub {
  font-size: 12.5px;
  color: var(--apple-label-tertiary);
  margin-top: 2px;
}

.apple-metrics-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 12px;
}

.apple-metric-tile {
  background: var(--apple-surface-grouped) !important;
  border: 0.5px solid var(--apple-separator) !important;
  border-radius: 14px;
  padding: 12px 14px;
}

.apple-metric-tile-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--apple-label-secondary);
}

.apple-metric-tile-val {
  font-size: 19px;
  font-weight: 700;
  color: var(--apple-label);
  margin-top: 4px;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.apple-metric-tile-val.accent {
  color: var(--apple-accent);
}

.apple-metric-tile-val.green {
  color: var(--apple-green);
}

.apple-stack-tile {
  background: var(--apple-surface-grouped);
  border: 0.5px solid var(--apple-separator);
  border-radius: 13px;
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.apple-stack-tile-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--apple-label-tertiary);
}

.apple-stack-tile-live {
  color: var(--apple-green);
  font-size: 11px;
  font-weight: 700;
}

.apple-stack-tile-val {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--apple-label);
}

/* ==========================================================================
   3. BUTTONS, CONTROLS & INPUTS — Apple Pill & Push Button Restraint
   ========================================================================== */
.btn,
body:not(.theme-dark) .btn,
body.theme-dark .btn {
  border-radius: 980px !important;
  padding: 9px 18px !important;
  font-size: 13.5px !important;
  font-weight: 600 !important;
  letter-spacing: -0.005em;
  transition: background-color 0.15s ease, transform 0.12s ease, opacity 0.15s ease !important;
}

.btn:active {
  transform: scale(0.97) !important;
}

.btn-sm,
body:not(.theme-dark) .btn-sm {
  padding: 6px 14px !important;
  font-size: 12.5px !important;
  min-height: 32px;
}

/* Primary Button: Pure Apple System Blue (No Multi-Stop Neon Gradients) */
.btn-primary,
body:not(.theme-dark) .btn-primary,
body.theme-dark .btn-primary {
  background: var(--apple-accent) !important;
  color: #ffffff !important;
  border: none !important;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.08) !important;
}

.btn-primary:hover,
body:not(.theme-dark) .btn-primary:hover,
body.theme-dark .btn-primary:hover {
  background: var(--apple-accent-hover) !important;
  transform: none !important;
  box-shadow: 0 2px 8px rgba(0, 113, 227, 0.25) !important;
}

/* Secondary Button: Apple Tinted Monochrome Fill */
.btn-outline,
body:not(.theme-dark) .btn-outline,
body.theme-dark .btn-outline {
  background: var(--apple-fill) !important;
  color: var(--apple-label) !important;
  border: none !important;
  box-shadow: none !important;
}

.btn-outline:hover,
body:not(.theme-dark) .btn-outline:hover,
body.theme-dark .btn-outline:hover {
  background: var(--apple-fill-hover) !important;
  color: var(--apple-label) !important;
}

/* Destructive Role Button */
.btn-danger-outline,
body:not(.theme-dark) .btn-danger-outline,
body.theme-dark .btn-danger-outline {
  background: var(--apple-red-bg) !important;
  color: var(--apple-red) !important;
  border: none !important;
}

.btn-danger-outline:hover,
body:not(.theme-dark) .btn-danger-outline:hover {
  filter: brightness(0.96);
}

.btn-chat-emp,
body:not(.theme-dark) .btn-chat-emp,
body.theme-dark .btn-chat-emp {
  background: var(--apple-accent-soft) !important;
  color: var(--apple-accent) !important;
  border: none !important;
  border-radius: 980px !important;
  padding: 6px 13px !important;
  font-weight: 600 !important;
}

.btn-chat-emp:hover,
body:not(.theme-dark) .btn-chat-emp:hover {
  background: var(--apple-accent) !important;
  color: #ffffff !important;
}

/* Preset & Filter Chips */
.preset-chip,
.filter-pill,
body:not(.theme-dark) .preset-chip,
body:not(.theme-dark) .filter-pill {
  background: var(--apple-fill-subtle) !important;
  border: 0.5px solid var(--apple-separator) !important;
  color: var(--apple-label-secondary) !important;
  border-radius: 980px !important;
  padding: 7px 14px !important;
  font-size: 12.5px !important;
  font-weight: 500 !important;
  transition: background-color 0.15s ease, color 0.15s ease, border-color 0.15s ease !important;
}

.preset-chip:hover,
.filter-pill:hover,
body:not(.theme-dark) .preset-chip:hover,
body:not(.theme-dark) .filter-pill:hover {
  background: var(--apple-fill) !important;
  color: var(--apple-label) !important;
  border-color: var(--apple-separator-strong) !important;
}

.filter-pill.active,
body:not(.theme-dark) .filter-pill.active {
  background: var(--apple-label) !important;
  color: var(--apple-surface) !important;
  border-color: var(--apple-label) !important;
}

/* Apple Rounded Inputs & Focus Ring */
.input,
.select,
.textarea,
body:not(.theme-dark) .input,
body:not(.theme-dark) .select,
body:not(.theme-dark) .textarea,
body.theme-dark .input,
body.theme-dark .select,
body.theme-dark .textarea {
  background: var(--apple-surface-grouped) !important;
  color: var(--apple-label) !important;
  border: 1px solid var(--apple-separator) !important;
  border-radius: 12px !important;
  padding: 10px 14px !important;
  font-size: 14px !important;
  min-height: 40px;
}

.input::placeholder,
.textarea::placeholder,
body:not(.theme-dark) .input::placeholder,
body:not(.theme-dark) .textarea::placeholder {
  color: var(--apple-label-tertiary) !important;
}

.input:focus,
.select:focus,
.textarea:focus,
body:not(.theme-dark) .input:focus,
body:not(.theme-dark) .select:focus,
body:not(.theme-dark) .textarea:focus {
  background: var(--apple-surface) !important;
  border-color: var(--apple-accent) !important;
  box-shadow: 0 0 0 3.5px var(--apple-accent-soft) !important;
  outline: none !important;
}

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

/* ==========================================================================
   4. SEMANTIC ITEMS, LISTS, TABLES, CHAT & MODALS (Light & Dark Unified)
   ========================================================================== */
.item-box,
.agent-task,
.agent-task-box,
.post-text,
.sop-preview,
.post-details-drawer,
.dev-drawer,
.qr-box,
.suite-actions-strip,
.dept-emp-card .dept-emp-last,
.participant-chip,
.chat-messages,
body:not(.theme-dark) .item-box,
body:not(.theme-dark) .agent-task-box,
body:not(.theme-dark) .post-text,
body:not(.theme-dark) .sop-preview,
body:not(.theme-dark) .post-details-drawer,
body:not(.theme-dark) .dev-drawer,
body:not(.theme-dark) .qr-box,
body:not(.theme-dark) .suite-actions-strip,
body:not(.theme-dark) .dept-emp-card .dept-emp-last,
body:not(.theme-dark) .participant-chip,
body:not(.theme-dark) .chat-messages {
  background: var(--apple-surface-grouped) !important;
  color: var(--apple-label) !important;
  border: 0.5px solid var(--apple-separator) !important;
  border-radius: 14px !important;
}

.agent-dept {
  color: var(--apple-accent) !important;
  font-weight: 600;
}

.model-pill,
body:not(.theme-dark) .model-pill {
  background: var(--apple-fill-subtle) !important;
  color: var(--apple-label-secondary) !important;
  border: 0.5px solid var(--apple-separator) !important;
  border-radius: 8px !important;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace !important;
}

/* Semantic Status Badges (Color + Text Label) */
.status-badge,
body:not(.theme-dark) .status-badge {
  border-radius: 980px !important;
  padding: 4px 10px !important;
  font-size: 11.5px !important;
  font-weight: 600 !important;
  border: none !important;
}

.badge-idle,
body:not(.theme-dark) .status-badge.badge-idle {
  background: var(--apple-fill) !important;
  color: var(--apple-label-secondary) !important;
}

.badge-working,
body:not(.theme-dark) .status-badge.badge-working,
body:not(.theme-dark) .status-badge.info {
  background: var(--apple-accent-soft) !important;
  color: var(--apple-accent) !important;
}

.badge-completed,
body:not(.theme-dark) .status-badge.badge-completed,
body:not(.theme-dark) .status-badge.ok,
body:not(.theme-dark) .status-badge.active,
body:not(.theme-dark) .status-badge.approved {
  background: var(--apple-green-bg) !important;
  color: var(--apple-green) !important;
}

.badge-warning,
body:not(.theme-dark) .status-badge.badge-warning,
body:not(.theme-dark) .status-badge.warn,
body:not(.theme-dark) .status-badge.pending {
  background: var(--apple-amber-bg) !important;
  color: var(--apple-amber) !important;
}

.badge-alert,
body:not(.theme-dark) .status-badge.badge-alert,
body:not(.theme-dark) .status-badge.danger,
body:not(.theme-dark) .status-badge.err,
body:not(.theme-dark) .status-badge.rejected {
  background: var(--apple-red-bg) !important;
  color: var(--apple-red) !important;
}

/* Apple iMessage-Style Chat Bubbles */
.chat-owner,
.emp-chat-bubble.user,
body:not(.theme-dark) .chat-owner,
body:not(.theme-dark) .emp-chat-bubble.user {
  background: var(--apple-accent) !important;
  color: #ffffff !important;
  border: none !important;
  border-radius: 18px 18px 4px 18px !important;
}

.chat-ceo,
.emp-chat-bubble.agent,
body:not(.theme-dark) .chat-ceo,
body:not(.theme-dark) .emp-chat-bubble.agent {
  background: var(--apple-surface) !important;
  color: var(--apple-label) !important;
  border: 0.5px solid var(--apple-separator) !important;
  border-radius: 18px 18px 18px 4px !important;
}

/* Apple Modal Sheets & Dialogs */
.emp-chat-modal,
body:not(.theme-dark) .emp-chat-modal {
  background: rgba(0, 0, 0, 0.36) !important;
  backdrop-filter: blur(10px) !important;
  -webkit-backdrop-filter: blur(10px) !important;
}

.emp-chat-box,
.warroom-modal,
body:not(.theme-dark) .emp-chat-box {
  background: var(--apple-surface) !important;
  border: 0.5px solid var(--glass-border) !important;
  border-radius: 24px !important;
  box-shadow: var(--apple-shadow-sheet) !important;
}

.emp-chat-header,
.emp-chat-form,
body:not(.theme-dark) .emp-chat-header,
body:not(.theme-dark) .emp-chat-form {
  background: var(--glass-bg) !important;
  backdrop-filter: blur(24px) saturate(180%) !important;
  -webkit-backdrop-filter: blur(24px) saturate(180%) !important;
  border-color: var(--apple-separator) !important;
}

#messengerPreviewTrack {
  background: var(--apple-surface-grouped) !important;
}

/* Data Tables */
.data-table,
body:not(.theme-dark) .data-table {
  background: var(--apple-surface) !important;
  border: 0.5px solid var(--apple-separator) !important;
  border-radius: 16px !important;
}

.data-table thead th,
body:not(.theme-dark) .data-table thead th {
  background: var(--apple-surface-grouped) !important;
  color: var(--apple-label-tertiary) !important;
  font-size: 12px !important;
  font-weight: 600 !important;
  border-bottom: 0.5px solid var(--apple-separator) !important;
}

.data-table td,
body:not(.theme-dark) .data-table td {
  color: var(--apple-label) !important;
  border-bottom: 0.5px solid var(--apple-separator) !important;
}

/* Toast Notification (Liquid Glass Pill) */
.toast,
body:not(.theme-dark) .toast {
  background: var(--glass-bg) !important;
  backdrop-filter: blur(28px) saturate(180%) !important;
  -webkit-backdrop-filter: blur(28px) saturate(180%) !important;
  color: var(--apple-label) !important;
  border: 0.5px solid var(--glass-border) !important;
  border-radius: 980px !important;
  padding: 12px 22px !important;
  box-shadow: var(--apple-shadow-elevated) !important;
}

/* ==========================================================================
   5. MOBILE / COMPACT SIZE CLASS (<= 960px):
      iOS Floating Liquid Glass Bottom Tab Bar + Slide-Over Sections Sheet
   ========================================================================== */
.apple-mobile-tabbar,
.apple-sidebar-backdrop {
  display: none;
}

@media (max-width: 960px) {
  .sidebar-toggle-btn {
    display: none !important;
  }

  .app-shell,
  body.sidebar-collapsed .app-shell {
    grid-template-columns: 1fr !important;
  }

  .main-content {
    padding: 0 14px calc(92px + env(safe-area-inset-bottom, 0px)) !important;
  }

  .topbar {
    top: 8px !important;
    margin: 8px 0 16px !important;
    padding: 12px 14px !important;
    border-radius: 16px !important;
  }

  .topbar-actions {
    width: 100%;
    justify-content: flex-start;
    gap: 8px !important;
  }

  .topbar-actions #activeTenantSelect {
    max-width: 100% !important;
    flex: 1 1 100%;
  }

  /* Convert Sidebar from 700px top-blocker into an iOS Slide-Over Sheet */
  .sidebar,
  body:not(.theme-dark) .sidebar,
  body.theme-dark .sidebar {
    position: fixed !important;
    top: 0 !important;
    right: 0 !important;
    bottom: 0 !important;
    width: min(310px, 86vw) !important;
    height: 100dvh !important;
    z-index: 1200 !important;
    transform: translateX(105%) !important;
    opacity: 1 !important;
    pointer-events: auto !important;
    padding: 20px 14px calc(24px + env(safe-area-inset-bottom, 0px)) !important;
    box-shadow: -16px 0 48px rgba(0, 0, 0, 0.25) !important;
  }

  body.mobile-drawer-open .sidebar {
    transform: translateX(0) !important;
  }

  .apple-sidebar-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 1150;
    background: rgba(0, 0, 0, 0.35);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.22s ease;
  }

  body.mobile-drawer-open .apple-sidebar-backdrop {
    opacity: 1;
    pointer-events: auto;
  }

  /* iOS Floating Liquid Glass Tab Bar */
  .apple-mobile-tabbar {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    align-items: center;
    position: fixed;
    right: 12px;
    left: 12px;
    bottom: calc(10px + env(safe-area-inset-bottom, 0px));
    z-index: 1100;
    height: 62px;
    padding: 4px 6px;
    border-radius: 980px;
    background: var(--glass-bg);
    backdrop-filter: blur(30px) saturate(190%);
    -webkit-backdrop-filter: blur(30px) saturate(190%);
    border: 0.5px solid var(--glass-border);
    box-shadow: var(--glass-highlight), 0 10px 32px rgba(0, 0, 0, 0.14);
  }

  .apple-tab-btn {
    border: none;
    background: transparent;
    color: var(--apple-label-tertiary);
    font-family: inherit;
    font-size: 10.5px;
    font-weight: 600;
    min-height: 48px;
    border-radius: 980px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 3px;
    cursor: pointer;
    transition: color 0.15s ease, background-color 0.15s ease;
  }

  .apple-tab-btn svg {
    width: 20px;
    height: 20px;
  }

  .apple-tab-btn.active {
    color: var(--apple-accent);
    background: var(--apple-accent-soft);
    font-weight: 700;
  }
}

/* ==========================================================================
   6. ACCESSIBILITY GUARANTEES: Touch Targets, Reduced Transparency,
      Increased Contrast & Reduced Motion (Apple HIG Lens 1)
   ========================================================================== */
@media (pointer: coarse) {
  .btn,
  .btn-sm,
  .nav-item,
  .preset-chip,
  .filter-pill,
  .input,
  .select {
    min-height: 44px !important;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .sidebar,
  .topbar,
  .emp-chat-header,
  .emp-chat-form,
  .toast,
  .apple-mobile-tabbar {
    backdrop-filter: none !important;
    -webkit-backdrop-filter: none !important;
    background: var(--apple-surface) !important;
  }
}

@media (prefers-contrast: more) {
  :root,
  body:not(.theme-dark) {
    --apple-separator: rgba(0, 0, 0, 0.34);
    --apple-label-tertiary: #3a3a3c;
    --apple-accent: #0040dd;
  }
  body.theme-dark {
    --apple-separator: rgba(255, 255, 255, 0.45);
    --apple-label-tertiary: #d1d1d6;
    --apple-accent: #409cff;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
