/* ==========================================================================
   OPSIYS — Premium AI Automation SaaS Workspace
   Design System, Components & Layout
   ========================================================================== */

:root {
  /* Color Palette - Deep Navy Sidebar */
  --sidebar-bg: #0b132b;
  --sidebar-surface: #111c3d;
  --sidebar-border: rgba(255, 255, 255, 0.08);
  --sidebar-text: #94a3b8;
  --sidebar-text-bright: #f8fafc;
  --sidebar-hover: rgba(255, 255, 255, 0.06);
  --sidebar-active-bg: rgba(13, 148, 136, 0.16);
  --sidebar-active-text: #2dd4bf;
  --sidebar-active-border: #0d9488;

  /* Workspace & Surfaces */
  --bg-app: #f8fafc;
  --surface: #ffffff;
  --surface-subtle: #f1f5f9;
  --surface-hover: #f8fafc;
  --border: #e2e8f0;
  --border-subtle: #edf2f7;
  --border-focus: #0d9488;

  /* Typography Colors */
  --text-main: #0f172a;
  --text-body: #334155;
  --text-muted: #64748b;
  --text-faint: #94a3b8;
  --text-inverse: #ffffff;

  /* Brand Accents - Emerald / Teal */
  --teal-50: #f0fdfa;
  --teal-100: #ccfbf1;
  --teal-200: #99f6e4;
  --teal-500: #14b8a6;
  --teal-600: #0d9488;
  --teal-700: #0f766e;
  --teal-800: #115e59;
  --emerald-500: #10b981;
  --emerald-600: #059669;

  /* Semantic Status Tokens */
  --status-success-bg: #ecfdf5;
  --status-success-text: #059669;
  --status-success-border: #a7f3d0;

  --status-info-bg: #eff6ff;
  --status-info-text: #2563eb;
  --status-info-border: #bfdbfe;

  --status-warning-bg: #fffbeb;
  --status-warning-text: #d97706;
  --status-warning-border: #fde68a;

  --status-purple-bg: #faf5ff;
  --status-purple-text: #7c3aed;
  --status-purple-border: #e9d5ff;

  --status-danger-bg: #fef2f2;
  --status-danger-text: #dc2626;
  --status-danger-border: #fecaca;

  --status-neutral-bg: #f1f5f9;
  --status-neutral-text: #475569;
  --status-neutral-border: #cbd5e1;

  /* Shadows & Elevation */
  --shadow-xs: 0 1px 2px 0 rgba(15, 23, 42, 0.05);
  --shadow-sm: 0 1px 3px 0 rgba(15, 23, 42, 0.08), 0 1px 2px -1px rgba(15, 23, 42, 0.08);
  --shadow-md: 0 4px 6px -1px rgba(15, 23, 42, 0.08), 0 2px 4px -2px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 10px 15px -3px rgba(15, 23, 42, 0.08), 0 4px 6px -4px rgba(15, 23, 42, 0.04);
  --shadow-modal: 0 20px 25px -5px rgba(15, 23, 42, 0.15), 0 8px 10px -6px rgba(15, 23, 42, 0.1);

  /* Radii */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
  --radius-xl: 16px;
  --radius-full: 9999px;

  /* Transitions */
  --transition-fast: 0.15s ease;
  --transition-normal: 0.2s ease;
}

/* ==========================================================================
   Base & Resets
   ========================================================================== */
*, *::before, *::after {
  box-sizing: border-box;
}

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
}

body {
  font-family: Inter, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
  font-size: 13.5px;
  line-height: 1.5;
  color: var(--text-body);
  background-color: var(--bg-app);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

h1, h2, h3, h4, h5, h6 {
  color: var(--text-main);
  margin-top: 0;
  font-weight: 600;
  letter-spacing: -0.02em;
}

a {
  color: var(--teal-600);
  text-decoration: none;
  transition: color var(--transition-fast);
}
a:hover {
  color: var(--teal-700);
}

p {
  margin: 0 0 8px;
}

button, input, select, textarea {
  font: inherit;
}

/* ==========================================================================
   Application Shell Layout
   ========================================================================== */
.app-shell {
  display: flex;
  height: 100vh;
  width: 100vw;
  overflow: hidden;
  background: var(--bg-app);
}

/* Left Sidebar */
.app-sidebar {
  width: 250px;
  min-width: 250px;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--sidebar-border);
  display: flex;
  flex-direction: column;
  color: var(--sidebar-text);
  z-index: 40;
  transition: transform var(--transition-normal), width var(--transition-normal);
  user-select: none;
}

.sidebar-brand {
  padding: 20px 18px 18px;
  display: flex;
  align-items: center;
  gap: 12px;
  border-bottom: 1px solid var(--sidebar-border);
}

.brand-icon-wrap {
  width: 34px;
  height: 34px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, #0d9488 0%, #10b981 100%);
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(13, 148, 136, 0.4);
}

.brand-text {
  display: flex;
  flex-direction: column;
}

.brand-name {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -0.01em;
  color: var(--sidebar-text-bright);
  line-height: 1.2;
}

.brand-badge {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--sidebar-active-text);
}

/* Sidebar Navigation */
.sidebar-nav {
  flex: 1;
  overflow-y: auto;
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-section-title {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  padding: 10px 10px 6px;
  margin-top: 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 9px 12px;
  border-radius: var(--radius-md);
  color: var(--sidebar-text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  text-decoration: none;
}

.nav-item:hover {
  color: var(--sidebar-text-bright);
  background: var(--sidebar-hover);
}

.nav-item.active {
  color: var(--sidebar-active-text);
  background: var(--sidebar-active-bg);
  font-weight: 600;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: 0;
  top: 6px;
  bottom: 6px;
  width: 3px;
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
  background: var(--sidebar-active-border);
}

.nav-icon {
  width: 17px;
  height: 17px;
  flex-shrink: 0;
  stroke-width: 2;
}

.nav-label {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.nav-count {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: var(--radius-full);
  background: rgba(255, 255, 255, 0.09);
  color: var(--sidebar-text-bright);
  min-width: 18px;
  text-align: center;
}

.nav-item.active .nav-count {
  background: rgba(13, 148, 136, 0.3);
  color: var(--sidebar-active-text);
}

/* Sidebar Footer */
.sidebar-footer {
  padding: 14px 14px;
  border-top: 1px solid var(--sidebar-border);
  background: rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.mode-card {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--sidebar-border);
  border-radius: var(--radius-md);
  padding: 10px 11px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

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

.mode-pill {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 6px;
  border-radius: 4px;
  background: rgba(234, 179, 8, 0.18);
  color: #fde047;
  display: inline-flex;
  align-items: center;
  gap: 5px;
}

.mode-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: #eab308;
}

.mode-desc {
  font-size: 10.5px;
  color: #94a3b8;
  line-height: 1.35;
}

/* ==========================================================================
   Main Workspace & Top Bar
   ========================================================================== */
.app-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  height: 100vh;
  overflow: hidden;
}

.app-topbar {
  height: 62px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-shrink: 0;
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 16px;
  min-width: 0;
}

.mobile-toggle {
  display: none;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  padding: 6px;
  border-radius: var(--radius-sm);
}

.topbar-title-block {
  display: flex;
  flex-direction: column;
}

.topbar-title {
  font-size: 16px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
  line-height: 1.2;
}

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

.topbar-center {
  flex: 1;
  max-width: 440px;
  margin: 0 auto;
}

.global-search-box {
  position: relative;
  width: 100%;
}

.global-search-box input {
  width: 100%;
  background: var(--surface-subtle);
  border: 1px solid transparent;
  border-radius: var(--radius-md);
  padding: 7px 12px 7px 34px;
  font-size: 12.5px;
  color: var(--text-main);
  transition: all var(--transition-fast);
}

.global-search-box input:focus {
  background: #fff;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.12);
  outline: none;
}

.search-icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 15px;
  height: 15px;
  color: var(--text-muted);
  pointer-events: none;
}

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

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 10px;
  border-radius: var(--radius-full);
  font-size: 11.5px;
  font-weight: 600;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  color: var(--text-body);
}

.status-pill.online {
  background: var(--status-success-bg);
  border-color: var(--status-success-border);
  color: var(--status-success-text);
}

.status-pill.warning {
  background: var(--status-warning-bg);
  border-color: var(--status-warning-border);
  color: var(--status-warning-text);
}

.indicator-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* Main Content Area */
.app-content {
  flex: 1;
  overflow-y: auto;
  position: relative;
  background: var(--bg-app);
}

.view-pane {
  display: none;
  padding: 24px;
  animation: fadeIn 0.18s cubic-bezier(0.16, 1, 0.3, 1);
  min-height: 100%;
}

.view-pane.active {
  display: block;
}

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

/* ==========================================================================
   Shared SaaS UI Components
   ========================================================================== */
/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  transition: all var(--transition-fast);
  white-space: nowrap;
  user-select: none;
}

.btn:focus-visible {
  outline: 2px solid var(--teal-600);
  outline-offset: 2px;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
  filter: grayscale(10%);
}

.btn-primary {
  background: var(--teal-600);
  color: #ffffff;
  border-color: var(--teal-700);
  box-shadow: 0 1px 2px rgba(13, 148, 136, 0.2);
}
.btn-primary:hover:not(:disabled) {
  background: var(--teal-700);
}

.btn-secondary {
  background: var(--surface);
  color: var(--text-body);
  border-color: var(--border);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--surface-subtle);
  color: var(--text-main);
  border-color: #cbd5e1;
}

.btn-outline {
  background: transparent;
  color: var(--teal-700);
  border-color: var(--teal-200);
}
.btn-outline:hover:not(:disabled) {
  background: var(--teal-50);
  border-color: var(--teal-500);
}

.btn-danger {
  background: var(--status-danger-bg);
  color: var(--status-danger-text);
  border-color: var(--status-danger-border);
}
.btn-danger:hover:not(:disabled) {
  background: #fee2e2;
}

.btn-sm {
  padding: 5px 9px;
  font-size: 11.5px;
  border-radius: var(--radius-sm);
  gap: 5px;
}

.btn-icon-only {
  padding: 7px;
  border-radius: var(--radius-md);
}

/* Badges & Status Pills */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  line-height: 1.25;
  white-space: nowrap;
  border: 1px solid transparent;
}

.badge-success {
  background: var(--status-success-bg);
  color: var(--status-success-text);
  border-color: var(--status-success-border);
}

.badge-info {
  background: var(--status-info-bg);
  color: var(--status-info-text);
  border-color: var(--status-info-border);
}

.badge-warning {
  background: var(--status-warning-bg);
  color: var(--status-warning-text);
  border-color: var(--status-warning-border);
}

.badge-purple {
  background: var(--status-purple-bg);
  color: var(--status-purple-text);
  border-color: var(--status-purple-border);
}

.badge-danger {
  background: var(--status-danger-bg);
  color: var(--status-danger-text);
  border-color: var(--status-danger-border);
}

.badge-neutral {
  background: var(--status-neutral-bg);
  color: var(--status-neutral-text);
  border-color: var(--status-neutral-border);
}

/* Cards & Panels */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
  transition: box-shadow var(--transition-fast);
}

.card:hover {
  box-shadow: var(--shadow-md);
}

.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.card-title {
  font-size: 14.5px;
  font-weight: 700;
  margin: 0;
  color: var(--text-main);
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-subtitle {
  font-size: 11.5px;
  color: var(--text-muted);
  margin: 3px 0 0;
}

.card-body {
  padding: 20px;
}

/* Form Controls */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 16px;
}

.form-label {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-main);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 8px 12px;
  background: #ffffff;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-main);
  font-size: 13px;
  transition: all var(--transition-fast);
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.12);
}

.form-textarea {
  resize: vertical;
  min-height: 72px;
  line-height: 1.45;
}

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

/* Data Tables */
.table-wrap {
  overflow-x: auto;
  border-radius: var(--radius-md);
  border: 1px solid var(--border-subtle);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: left;
  font-size: 12.5px;
}

.data-table th {
  background: var(--surface-subtle);
  padding: 10px 14px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.data-table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-body);
  vertical-align: middle;
}

.data-table tr:last-child td {
  border-bottom: none;
}

.data-table tr:hover td {
  background: var(--surface-hover);
}

/* ==========================================================================
   Page 1: Overview Dashboard
   ========================================================================== */
.overview-grid {
  display: grid;
  gap: 20px;
}

.stats-grid-6 {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 14px;
}

.metric-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px 16px 14px;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  position: relative;
  overflow: hidden;
  transition: transform var(--transition-fast), box-shadow var(--transition-fast);
}

.metric-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.metric-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}

.metric-label {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.metric-icon-wrap {
  width: 30px;
  height: 30px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
}

.metric-icon-wrap.teal { background: var(--teal-50); color: var(--teal-600); }
.metric-icon-wrap.emerald { background: var(--status-success-bg); color: var(--status-success-text); }
.metric-icon-wrap.blue { background: var(--status-info-bg); color: var(--status-info-text); }
.metric-icon-wrap.amber { background: var(--status-warning-bg); color: var(--status-warning-text); }
.metric-icon-wrap.purple { background: var(--status-purple-bg); color: var(--status-purple-text); }
.metric-icon-wrap.indigo { background: #eef2ff; color: #4f46e5; }

.metric-value {
  font-size: 26px;
  font-weight: 800;
  letter-spacing: -0.03em;
  color: var(--text-main);
  line-height: 1.1;
}

.metric-meta {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  display: flex;
  align-items: center;
  gap: 4px;
}

.overview-main-columns {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 20px;
}

.quick-actions-bar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}

/* ==========================================================================
   Page 2: Inbox Workspace (3-Panel)
   ========================================================================== */
#view-inbox {
  padding: 0 !important;
  height: calc(100vh - 62px);
  max-height: calc(100vh - 62px);
  overflow: hidden;
}

.inbox-workspace {
  display: grid;
  grid-template-columns: 280px 1fr 320px;
  height: 100%;
  max-height: 100%;
  margin: 0;
  background: var(--surface);
  border-top: none;
  overflow: hidden;
  box-sizing: border-box;
}

/* Inbox Panel 1: Contacts Rail */
.inbox-contacts-panel {
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: #fdfdfd;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  overflow: hidden;
}

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

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

.contacts-title {
  font-size: 14px;
  font-weight: 700;
  color: var(--text-main);
  margin: 0;
}

.contact-search-box input {
  width: 100%;
  padding: 6px 10px;
  background: var(--surface-subtle);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  font-size: 12px;
}

.contacts-filter-tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  -ms-overflow-style: none;
  padding: 0 14px 10px;
  border-bottom: 1px solid var(--border-subtle);
}

.contacts-filter-tabs::-webkit-scrollbar {
  display: none;
}

.contact-filter-chip {
  padding: 3px 8px;
  border-radius: var(--radius-full);
  font-size: 11px;
  font-weight: 600;
  background: var(--surface-subtle);
  color: var(--text-muted);
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
}

.contact-filter-chip.active {
  background: var(--teal-50);
  color: var(--teal-700);
  border-color: var(--teal-200);
}

.contacts-list {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.contact-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 10px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  border: 1px solid transparent;
  color: inherit;
}

.contact-item:hover {
  background: var(--surface-subtle);
}

.contact-item.active {
  background: var(--teal-50);
  border-color: var(--teal-100);
}

.avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: #e2e8f0;
  color: var(--text-body);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.contact-item.active .avatar {
  background: var(--teal-600);
  color: #fff;
}

.contact-info {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.contact-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.contact-name {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-main);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-snippet {
  font-size: 11px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.contact-row-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 3px;
}

/* Inbox Panel 2: Chat Area */
.inbox-chat-panel {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  background: #f8fafc;
  position: relative;
  overflow: hidden;
}

.chat-header {
  padding: 12px 20px;
  background: #ffffff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-shrink: 0;
}

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

.chat-messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  padding: 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background-color: #f8fafc;
  background-image: radial-gradient(#e2e8f0 0.8px, transparent 0.8px);
  background-size: 18px 18px;
}

.chat-bubble-row {
  display: flex;
  width: 100%;
}

.chat-bubble-row.inbound {
  justify-content: flex-start;
}

.chat-bubble-row.outbound {
  justify-content: flex-end;
}

.chat-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: var(--radius-lg);
  font-size: 13px;
  line-height: 1.5;
  box-shadow: var(--shadow-xs);
  position: relative;
  word-break: break-word;
}

.chat-bubble.inbound {
  background: #ffffff;
  border: 1px solid var(--border);
  color: var(--text-main);
  border-top-left-radius: 3px;
}

.chat-bubble.outbound {
  background: #ecfdf5;
  border: 1px solid #a7f3d0;
  color: #064e3b;
  border-top-right-radius: 3px;
}

.bubble-sender {
  font-size: 9.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 3px;
}

.chat-bubble.inbound .bubble-sender { color: var(--text-muted); }
.chat-bubble.outbound .bubble-sender { color: var(--teal-700); }

.bubble-time {
  font-size: 9.5px;
  color: var(--text-muted);
  text-align: right;
  margin-top: 4px;
  display: block;
}

.typing-dots {
  display: inline-flex;
  gap: 4px;
  align-items: center;
  padding: 4px 0;
}

.typing-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--teal-600);
  animation: typingBounce 1.3s infinite ease-in-out;
}

.typing-dot:nth-child(2) { animation-delay: 0.2s; }
.typing-dot:nth-child(3) { animation-delay: 0.4s; }

@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.35; }
  40% { transform: scale(1.15); opacity: 1; }
}

.chat-composer-box {
  background: #ffffff;
  border-top: 1px solid var(--border);
  padding: 12px 18px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.composer-input-row {
  display: flex;
  gap: 10px;
  align-items: flex-end;
}

.composer-textarea {
  flex: 1;
  min-height: 42px;
  max-height: 120px;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-size: 13px;
  resize: vertical;
}

.composer-textarea:focus {
  outline: none;
  border-color: var(--teal-600);
  box-shadow: 0 0 0 3px rgba(13, 148, 136, 0.12);
}

.composer-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 10.5px;
  color: var(--text-muted);
}

/* Inbox Panel 3: CRM Details Drawer */
.inbox-details-panel {
  border-left: 1px solid var(--border);
  background: #ffffff;
  height: 100%;
  max-height: 100%;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.details-header {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.lead-profile-card {
  padding: 16px 16px 36px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
}

.score-badge-box {
  background: var(--teal-50);
  border: 1px solid var(--teal-100);
  border-radius: var(--radius-md);
  padding: 10px 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.score-val {
  font-size: 18px;
  font-weight: 800;
  color: var(--teal-700);
}

/* ==========================================================================
   Page 4: Automations
   ========================================================================== */
.automations-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
}

.automation-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 18px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-fast);
}

.automation-card:hover {
  box-shadow: var(--shadow-md);
  border-color: #cbd5e1;
}

.auto-card-top {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin-bottom: 12px;
}

.auto-icon-box {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-md);
  background: var(--teal-50);
  color: var(--teal-600);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.auto-card-content h3 {
  font-size: 14px;
  margin: 0 0 4px;
  color: var(--text-main);
}

.auto-card-content p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.45;
  margin: 0;
}

.auto-card-meta {
  padding-top: 14px;
  margin-top: 14px;
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-muted);
}

/* ==========================================================================
   Page 7: Activity Logs Audit Trail
   ========================================================================== */
.activity-filters-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.activity-badge {
  font-size: 9.5px;
  font-weight: 700;
  letter-spacing: 0.05em;
  padding: 3px 8px;
  border-radius: 4px;
  border: 1px solid transparent;
  white-space: nowrap;
}

.badge-message_in { background: #e0f2fe; color: #0369a1; border-color: #bae6fd; }
.badge-outbound_message { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.badge-ai_response { background: #ecfdf5; color: #059669; border-color: #a7f3d0; }
.badge-fallback_response { background: #fffbeb; color: #d97706; border-color: #fde68a; }
.badge-lead_qualified { background: #faf5ff; color: #7c3aed; border-color: #e9d5ff; }
.badge-lead_created { background: #eef2ff; color: #4f46e5; border-color: #c7d2fe; }
.badge-followup_created, .badge-followup_processed, .badge-followup_completed { background: #f0fdfa; color: #0f766e; border-color: #99f6e4; }
.badge-opt_out, .badge-followup_cancelled, .badge-message_blocked { background: #fef2f2; color: #dc2626; border-color: #fecaca; }
.badge-handoff, .badge-handoff_created, .badge-handoff_completed { background: #fff7ed; color: #c2410c; border-color: #ffedd5; }
.badge-settings_updated, .badge-opt_in_resumed, .badge-profile_updated, .badge-system_reset { background: #f1f5f9; color: #475569; border-color: #cbd5e1; }

/* ==========================================================================
   Page 8: Analytics Visuals
   ========================================================================== */
.analytics-grid {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 20px;
}

.progress-bar-wrap {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 12px;
}

.progress-bar-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12px;
  font-weight: 500;
}

.progress-track {
  height: 8px;
  background: var(--surface-subtle);
  border-radius: var(--radius-full);
  overflow: hidden;
}

.progress-fill {
  height: 100%;
  border-radius: var(--radius-full);
  background: var(--teal-600);
  transition: width 0.4s ease;
}

.progress-fill.emerald { background: var(--emerald-500); }
.progress-fill.blue { background: #3b82f6; }
.progress-fill.amber { background: #f59e0b; }
.progress-fill.purple { background: #8b5cf6; }
.progress-fill.red { background: #ef4444; }

/* ==========================================================================
   Modals & Toast Notifications
   ========================================================================== */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.55);
  backdrop-filter: blur(2px);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.modal-overlay.open {
  display: flex;
}

.modal-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-modal);
  border: 1px solid var(--border);
  overflow: hidden;
  animation: modalScale 0.18s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes modalScale {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

.modal-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0;
}

.modal-body {
  padding: 20px;
}

.modal-footer {
  padding: 14px 20px;
  background: var(--surface-subtle);
  border-top: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
}

/* Toast System */
.toast-container {
  position: fixed;
  bottom: 20px;
  right: 20px;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  background: var(--surface);
  color: var(--text-main);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 10px 16px;
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  animation: slideToast 0.22s cubic-bezier(0.16, 1, 0.3, 1);
}

.toast.success { border-color: var(--status-success-border); color: var(--status-success-text); }
.toast.error { border-color: var(--status-danger-border); color: var(--status-danger-text); }

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

/* Spinner */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 40px 20px;
  color: var(--text-muted);
}
.empty-state-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-lg);
  background: var(--surface-subtle);
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 12px;
  color: var(--text-muted);
}

/* ==========================================================================
   Responsive Breakpoints
   ========================================================================== */
@media (max-width: 1280px) {
  .stats-grid-6 { grid-template-columns: repeat(3, 1fr); }
  .automations-grid { grid-template-columns: repeat(2, 1fr); }
  .overview-main-columns { grid-template-columns: 1fr; }
  .inbox-workspace { grid-template-columns: 260px 1fr 280px; }
}

@media (max-width: 1024px) {
  .inbox-workspace { grid-template-columns: 260px 1fr; }
  .inbox-details-panel { display: none; }
  .analytics-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .app-sidebar {
    position: fixed;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-modal);
  }
  .app-sidebar.mobile-open {
    transform: translateX(0);
  }
  .mobile-toggle { display: block; }
  .stats-grid-6 { grid-template-columns: repeat(2, 1fr); }
  .automations-grid { grid-template-columns: 1fr; }
  .inbox-workspace { grid-template-columns: 1fr; }
  .inbox-contacts-panel { display: none; }
  .inbox-contacts-panel.show-mobile { display: flex; }
  .topbar-center { display: none; }
  .app-topbar { padding: 0 16px; }
  .view-pane { padding: 16px; }
}
