/* ================================================================
 * MrPotter CRM Dashboard — Stylesheet
 * ================================================================ */

/* === CSS Variables / Theming === */
/* Elifin — elegant black & white, Chatbase-inspired monochrome palette */
:root {
  --bg-primary: #ffffff;        /* clean white — main canvas */
  --bg-secondary: #fafafa;      /* near-white — sidebar / panels */
  --bg-card: #ffffff;           /* white cards */
  --bg-input: #ffffff;          /* white inputs */
  --text-primary: #0a0a0a;      /* near-black ink */
  --text-secondary: #3f3f46;    /* dark gray */
  --text-muted: #71717a;        /* muted gray */
  --border: #e4e4e7;            /* hairline border */
  --border-light: #f4f4f5;
  --primary: #0a0a0a;           /* black — primary actions */
  --primary-hover: #27272a;
  --primary-light: rgba(9, 9, 11, 0.06);
  --success: #16a34a;           /* status green (accent only) */
  --success-light: rgba(22, 163, 74, 0.10);
  --warning: #b45309;           /* status amber (accent only) */
  --warning-light: rgba(180, 83, 9, 0.10);
  --danger: #dc2626;            /* status red (accent only) */
  --danger-light: rgba(220, 38, 38, 0.10);
  --info: #3f3f46;              /* neutral gray (was blue) */
  --info-light: rgba(63, 63, 70, 0.08);
  --shadow-sm: 0 1px 2px rgba(9, 9, 11, 0.05);
  --shadow: 0 1px 3px rgba(9, 9, 11, 0.06), 0 8px 24px rgba(9, 9, 11, 0.05);
  --shadow-lg: 0 12px 40px rgba(9, 9, 11, 0.10);
  --radius: 12px;
  --radius-sm: 9px;
  --sidebar-width: 260px;
  --topbar-height: 64px;
  --chat-customer: #f4f4f5;     /* light gray — customer bubbles */
  --chat-customer-text: #0a0a0a;
  --chat-ai: #0a0a0a;           /* black — AI bubbles */
  --chat-ai-text: #ffffff;
  --chat-agent: #3f3f46;        /* dark gray — human agent replies */
  --chat-agent-text: #ffffff;
  /* Legacy variable aliases -> map old names onto the monochrome theme so
   * stray var(--bg)/var(--surface)/etc. stop falling back to dark #0b1220. */
  --bg: var(--bg-primary);
  --bg-alt: var(--bg-secondary);
  --bg-main: var(--bg-primary);
  --surface: var(--bg-card);
  --surface-hover: var(--bg-secondary);
  --card-bg: var(--bg-card);
  --sidebar-bg: var(--bg-secondary);
  --text: var(--text-primary);
  --accent: var(--primary);
}

[data-theme="dark"] {
  /* Dark mode: clean monochrome (near-black canvas, white text) */
  --bg-primary: #0a0a0a;
  --bg-secondary: #141414;
  --bg-card: #171717;
  --bg-input: #171717;
  --text-primary: #fafafa;
  --text-secondary: #d4d4d8;
  --text-muted: #a1a1aa;
  --border: #27272a;
  --border-light: #1f1f1f;
  --primary: #fafafa;           /* white — primary actions on dark */
  --primary-hover: #e4e4e7;
  --primary-light: rgba(250, 250, 250, 0.10);
  --success-light: rgba(22, 163, 74, 0.16);
  --warning-light: rgba(180, 83, 9, 0.16);
  --danger-light: rgba(220, 38, 38, 0.16);
  --info-light: rgba(212, 212, 216, 0.10);
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.5);
  --shadow: 0 1px 3px rgba(0,0,0,0.6);
  --shadow-lg: 0 12px 40px rgba(0,0,0,0.7);
  --chat-customer: #262626;
  --chat-customer-text: #fafafa;
  --chat-ai: #fafafa;
  --chat-ai-text: #0a0a0a;
  --chat-agent: #3f3f46;
  --chat-agent-text: #fafafa;
}

/* === Reset === */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.6;
  overflow: hidden;
  height: 100vh;
}

a { color: var(--primary); text-decoration: none; }

/* === Login Screen === */
.login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-secondary);
}

.login-card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 48px 40px;
  width: 100%;
  max-width: 420px;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

.login-logo {
  text-align: center;
  margin-bottom: 32px;
}

.login-logo i {
  font-size: 48px;
  color: var(--primary);
  margin-bottom: 12px;
}

.login-logo h1 {
  font-size: 24px;
  font-weight: 700;
  color: var(--text-primary);
}

.login-logo p {
  color: var(--text-secondary);
  font-size: 14px;
  margin-top: 4px;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  font-size: 13.5px;
  font-weight: 500;
  color: var(--text-primary);
  margin-bottom: 7px;
  letter-spacing: -0.006em;
}

.form-group input:not([type="checkbox"]):not([type="radio"]):not([type="color"]):not([type="file"]),
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.form-group input[type="checkbox"],
.form-group input[type="radio"] {
  width: auto;
  margin: 0 4px 0 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

.form-group textarea {
  resize: vertical;
  min-height: 80px;
}

.error-msg {
  color: var(--danger);
  font-size: 13px;
  margin-bottom: 12px;
  padding: 8px 12px;
  background: var(--danger-light);
  border-radius: var(--radius-sm);
}

/* === Buttons === */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 20px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  transition: background-color .15s ease, border-color .15s ease, box-shadow .15s ease, color .15s ease;
  white-space: nowrap;
}
.btn:focus-visible { outline: none; box-shadow: 0 0 0 2px var(--bg-card), 0 0 0 4px rgba(9,9,11,.35); }

.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-success { background: var(--success); color: #fff; }
.btn-success:hover:not(:disabled) { opacity: 0.9; }

.btn-warning { background: var(--warning); color: #fff; }
.btn-warning:hover:not(:disabled) { opacity: 0.9; }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { opacity: 0.9; }

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

.btn-sm { padding: 6px 12px; font-size: 12px; }

.btn-block { width: 100%; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  cursor: pointer;
  transition: all 0.2s;
  font-size: 16px;
}
.icon-btn:hover { background: var(--bg-secondary); color: var(--text-primary); }

/* === Layout === */
#main-app {
  display: flex;
  flex-direction: column;   /* full-width top bar, then the body row below */
  height: 100vh;
  overflow: hidden;
}
/* Body row under the top bar: sidebar (left) + main content (right) */
.app-body {
  display: flex;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

/* === Sidebar === */
.sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  height: 100vh;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: transform 0.3s;
  z-index: 100;
}

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

.sidebar-logo {
  width: 44px; height: 44px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  background: var(--primary);
  color: #fff;
  font-size: 22px;
  flex-shrink: 0;
  overflow: hidden;
}
.sidebar-logo img { width: 100%; height: 100%; object-fit: cover; }

.sidebar-header i {
  font-size: 24px;
  color: var(--primary);
}

.sidebar-title {
  display: flex; flex-direction: column; line-height: 1.15;
  font-size: 17px;
  font-weight: 700;
  color: var(--text-primary);
}
.sidebar-title small {
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  color: var(--text-muted);
  text-transform: uppercase;
  margin-top: 2px;
}

.sidebar-toggle-mobile {
  display: none;
  margin-left: auto;
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 18px;
  cursor: pointer;
}

.sidebar-nav {
  flex: 1;
  padding: 12px;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 500;
  transition: all 0.18s ease;
  margin-bottom: 4px;
  position: relative;
}

.nav-item:hover {
  background: var(--border-light);
  color: var(--text-primary);
}

.nav-item.active {
  background: var(--bg-card);
  color: var(--text-primary);
  font-weight: 600;
  box-shadow: inset 0 0 0 1px var(--border), var(--shadow-sm);
}
.nav-item.active i { color: var(--text-primary); }

.nav-item i { width: 20px; text-align: center; }

/* Collapsible nav group headers */
.nav-group-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 14px;
  width: 100%;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  font-weight: 600;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  border-radius: var(--radius-sm);
  margin-bottom: 4px;
  transition: all 0.18s ease;
}
.nav-group-header:hover {
  background: rgba(9, 9, 11, 0.06);
  color: var(--text-primary);
}
.nav-group-header > i:first-child { width: 20px; text-align: center; }
.nav-group-header span { flex: 1; }
.nav-chevron {
  font-size: 11px;
  opacity: 0.6;
  transition: transform 0.2s ease;
}
.nav-group-header.collapsed .nav-chevron { transform: rotate(-90deg); }

.nav-group {
  overflow: hidden;
  max-height: 600px;
  transition: max-height 0.25s ease;
}
.nav-group.collapsed { max-height: 0; }

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 800;
  padding: 1px 6px;
  border-radius: 999px;
  min-width: 18px;
  height: 18px;
  text-align: center;
  letter-spacing: 0.02em;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.nav-badge-group {
  margin-left: auto;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}
.nav-badge-unread {
  /* unread = primary brand brown so it reads "to-do" without alarm */
  background: var(--primary);
}
.nav-badge-human {
  /* new human mode = warning amber — needs attention NOW */
  background: var(--warning);
  animation: badge-pulse 2s ease-in-out infinite;
}
.nav-item.active .nav-badge {
  /* keep contrast when row is active (white text on brown bg) */
  background: rgba(255,255,255,0.25);
  color: #fff;
}

.sidebar-footer {
  padding: 16px 20px;
  border-top: 1px solid var(--border);
}

.user-info {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.user-info .user-meta { min-width: 0; flex: 1; }

.user-avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: var(--primary);
  color: var(--bg-card);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  font-weight: 700;
  flex: none;
}

.user-name { font-size: 13px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.user-help { flex: none; color: var(--text-muted); }
.user-help:hover { color: var(--text-primary); }

.sidebar-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}
.sidebar-actions #notify-pref-select {
  flex: 1; min-width: 0; background: transparent; color: var(--text-secondary);
  border: 1px solid var(--border); border-radius: 7px; padding: 5px 8px; font-size: 12px; height: auto;
}

/* === Main Content === */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  min-width: 0;
}

.top-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 0 24px;
  height: var(--topbar-height);
  min-height: var(--topbar-height);
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
  position: relative;
  z-index: 200;   /* lift the bar + its dropdowns above the sidebar (z 100) */
}

.top-bar h2 {
  font-size: 18px;
  font-weight: 600;
  flex: 1;
}

.menu-btn { display: none; }

.connection-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--text-muted);
}
.connection-dot.connected { background: var(--success); }

.page-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

/* === Stats Cards === */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 16px;
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
}

.stat-icon.primary,
.stat-icon.success,
.stat-icon.warning,
.stat-icon.info { background: var(--border-light); color: var(--text-primary); }

.stat-value {
  font-size: 28px;
  font-weight: 700;
  line-height: 1;
  margin-bottom: 4px;
}

.stat-label {
  font-size: 12px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 500;
}

/* === Charts === */
.charts-grid {
  display: grid;
  grid-template-columns: 2fr 1fr;
  gap: 16px;
  margin-bottom: 24px;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
}

.chart-card h3 {
  font-size: 14px;
  font-weight: 600;
  margin-bottom: 16px;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.chart-card canvas {
  width: 100% !important;
  max-height: 250px;
}

/* === Table === */
.table-container {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.table-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.table-header h3 {
  font-size: 16px;
  font-weight: 600;
  margin-right: auto;
}

.search-input {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 12px;
}

.search-input i { color: var(--text-muted); font-size: 14px; }

.search-input input {
  border: none;
  background: none;
  color: var(--text-primary);
  font-size: 13px;
  outline: none;
  width: 180px;
  font-family: inherit;
}

.filter-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin: 12px 0;
}

.filter-tab,
.filter-tabs button {
  padding: 7px 16px;
  border: 1px solid var(--border);
  border-radius: 999px;
  background: var(--bg-card);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.16s ease;
  font-family: inherit;
  letter-spacing: 0.02em;
}

.filter-tab:hover,
.filter-tabs button:hover {
  border-color: var(--primary);
  color: var(--primary);
}

.filter-tab.active,
.filter-tabs button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: var(--shadow-sm);
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  padding: 12px 20px;
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid var(--border-light);
}

th {
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  font-size: 11px;
  letter-spacing: 0.5px;
  background: var(--bg-secondary);
}

tr:hover td { background: var(--bg-secondary); }

.table-empty {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
}

.table-empty i {
  font-size: 48px;
  margin-bottom: 12px;
  display: block;
}

/* === Badges === */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 2px 9px;
  border-radius: 6px;
  font-size: 11.5px;
  font-weight: 500;
  letter-spacing: 0;
  border: 1px solid var(--border);
}

.badge-ai { background: var(--info-light); color: var(--info); }
.badge-human { background: var(--warning-light); color: var(--warning); }
.badge-closed { background: var(--bg-secondary); color: var(--text-muted); }

.badge::before {
  content: '';
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: .7;
}

/* === Session List Cards === */
.sessions-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 4px 0;
}

.session-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  gap: 12px;
  transition: all 0.16s ease;
  box-shadow: var(--shadow-sm);
}

.session-row:hover {
  background: var(--bg-card);
  border-color: var(--border);
  box-shadow: var(--shadow);
  transform: translateY(-1px);
}
.session-row.session-unread {
  border-left: 4px solid var(--primary);
  background: linear-gradient(90deg, rgba(9, 9, 11, 0.06) 0%, var(--bg-card) 22%);
  box-shadow: 0 0 0 1px var(--primary-light), var(--shadow-sm);
}
.session-row.session-unread .session-name { font-weight: 700; color: var(--text-primary); }
.session-row.session-unread .session-preview { color: var(--text-primary); font-weight: 500; }

.session-row.session-order-interest {
  border-left: 4px solid var(--warning);
  background: linear-gradient(90deg, rgba(193,154,82,0.10) 0%, var(--bg-card) 25%);
}
.session-row.session-order-alert {
  border-left: 4px solid #D97706;  /* deeper amber/orange = more urgent than warning */
  background: linear-gradient(90deg, rgba(217,119,6,0.14) 0%, var(--bg-card) 25%);
  box-shadow: 0 0 0 1px rgba(217,119,6,0.18), var(--shadow-sm);
}
.session-row.session-payment-alert {
  border-left: 4px solid #DC2626;  /* red = top-priority */
  background: linear-gradient(90deg, rgba(220,38,38,0.12) 0%, var(--bg-card) 25%);
  box-shadow: 0 0 0 1px rgba(220,38,38,0.20), var(--shadow-sm);
}
.session-row.session-ordered {
  border-left: 4px solid var(--success);
  background: linear-gradient(90deg, rgba(93,142,90,0.08) 0%, var(--bg-card) 25%);
}
/* Priority cascade when multiple flags overlap: payment > order_alert > ordered > order_interest > unread */
.session-row.session-unread.session-order-interest { border-left-color: var(--warning); }
.session-row.session-unread.session-order-alert { border-left-color: #D97706; }
.session-row.session-unread.session-payment-alert { border-left-color: #DC2626; }
.session-row.session-unread.session-ordered { border-left-color: var(--success); }
.session-row.session-payment-alert.session-order-alert { border-left-color: #DC2626; }
.session-row.session-payment-alert.session-ordered { border-left-color: #DC2626; }

.order-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.02em;
  margin-left: 6px; vertical-align: middle;
  white-space: nowrap;
}
.order-badge-interest {
  background: var(--warning-light); color: var(--warning);
  animation: order-pulse 2.5s ease-in-out infinite;
}
.order-badge-alert {
  background: rgba(217,119,6,0.18); color: #B45309;
  animation: order-pulse 2s ease-in-out infinite;
}
.order-badge-payment {
  background: rgba(220,38,38,0.18); color: #B91C1C;
  animation: payment-pulse 1.6s ease-in-out infinite;
  font-weight: 800;
}
.order-badge-done {
  background: var(--success-light); color: var(--success);
}
@keyframes payment-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 0 rgba(220,38,38,0.3); }
  50%      { transform: scale(1.08); box-shadow: 0 0 0 4px rgba(220,38,38,0); }
}

/* Per-flag toggle buttons in chat header — show outline when inactive, filled when set */
.flag-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-secondary);
}
.flag-btn:hover { border-color: var(--text-primary); color: var(--text-primary); }
.flag-btn-interest.active { background: var(--warning); color: #fff; border-color: var(--warning); }
.flag-btn-alert.active    { background: #D97706; color: #fff; border-color: #D97706; }
.flag-btn-payment.active  { background: #DC2626; color: #fff; border-color: #DC2626; }
.flag-btn-ordered.active  { background: var(--success); color: #fff; border-color: var(--success); }
.flag-btn-interest:hover  { color: var(--warning); border-color: var(--warning); }
.flag-btn-alert:hover     { color: #D97706; border-color: #D97706; }
.flag-btn-payment:hover   { color: #DC2626; border-color: #DC2626; }
.flag-btn-ordered:hover   { color: var(--success); border-color: var(--success); }
@keyframes order-pulse {
  0%, 100% { transform: scale(1); opacity: 0.95; }
  50% { transform: scale(1.06); opacity: 1; }
}

.badge-new {
  display: inline-flex; align-items: center;
  background: var(--primary); color: #fff;
  font-size: 9px; font-weight: 800;
  letter-spacing: 0.08em;
  padding: 2px 7px; border-radius: 999px;
  margin-right: 6px;
  animation: badge-pulse 2.4s ease-in-out infinite;
  vertical-align: middle;
}
@keyframes badge-pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(9, 9, 11, 0.45); }
  50%      { box-shadow: 0 0 0 5px rgba(9, 9, 11, 0); }
}

.unread-indicator {
  position: absolute; top: -2px; right: -2px;
  width: 12px; height: 12px;
  background: var(--primary); border-radius: 50%;
  border: 2px solid var(--bg-card);
  box-shadow: 0 0 0 2px rgba(9, 9, 11, 0.18);
}

.session-lead-row {
  display: flex; flex-wrap: wrap; gap: 4px; align-items: center;
  margin-top: 4px;
}
.session-lead-name {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; color: var(--primary);
  background: var(--primary-light); padding: 2px 8px;
  border-radius: 999px;
}

.session-row-left {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 1;
  min-width: 0;
}

.session-avatar {
  width: 40px;
  height: 40px;
  min-width: 40px;
  border-radius: 50%;
  background: var(--bg-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  position: relative;
}

.status-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  border: 2px solid var(--bg-card);
}

.dot-ai { background: var(--info); }
.dot-human { background: var(--warning); }
.dot-closed { background: var(--text-muted); }

.session-info { min-width: 0; flex: 1; }

.session-name {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.session-channel {
  font-size: 11px;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 6px;
}

.session-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.session-row-right {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  min-width: 90px;
}

.session-time { font-size: 11px; color: var(--text-muted); }
.session-meta { font-size: 10px; color: var(--text-muted); }

/* === Chat Layout (Split View) === */
.chat-layout {
  display: flex;
  height: calc(100vh - var(--topbar-height) - 48px);
  gap: 0;
}

.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.chat-top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  flex-wrap: wrap;
}

.chat-action-btns {
  display: flex;
  gap: 6px;
  margin-left: auto;
}

.chat-sidebar {
  width: 300px;
  min-width: 300px;
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  background: var(--bg-card);
  overflow-y: auto;
}

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

.panel-content {
  padding: 16px;
  overflow-y: auto;
  flex: 1;
}

/* Customer Info Panel */
.customer-info-panel {
  margin-bottom: 20px;
}

.customer-info-panel h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 8px 0;
  border-bottom: 1px solid var(--border-light);
  font-size: 13px;
  gap: 8px;
}

.info-label {
  color: var(--text-muted);
  font-size: 12px;
  white-space: nowrap;
}

.info-value {
  color: var(--text-primary);
  font-weight: 500;
  text-align: right;
  word-break: break-all;
}

.session-id-code {
  font-size: 10px;
  background: var(--bg-secondary);
  padding: 2px 6px;
  border-radius: 4px;
  font-family: monospace;
}

/* Notes Panel */
.notes-panel h4 {
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 12px;
}

.note-card {
  background: var(--bg-secondary);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  margin-bottom: 8px;
  font-size: 13px;
}

.note-text {
  line-height: 1.5;
  margin-bottom: 4px;
}

.note-meta {
  font-size: 10px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 4px;
}

.note-delete {
  background: none;
  border: none;
  color: var(--danger);
  cursor: pointer;
  font-size: 10px;
  padding: 2px;
  margin-left: auto;
}

.note-input {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.note-input textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
  padding: 8px 10px;
  resize: none;
  outline: none;
}

.note-input textarea:focus {
  border-color: var(--primary);
}

/* Chat Messages */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.msg-bubble {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.5;
  position: relative;
  word-break: break-word;
}

.msg-text { white-space: pre-wrap; }

.msg-customer {
  align-self: flex-start;
  background: var(--chat-customer);
  color: var(--chat-customer-text);
  border-bottom-left-radius: 4px;
}

.msg-ai {
  align-self: flex-start;
  background: var(--chat-ai);
  color: var(--chat-ai-text);
  border-bottom-left-radius: 4px;
}

.msg-agent {
  align-self: flex-end;
  background: var(--chat-agent);
  color: var(--chat-agent-text);
  border-bottom-right-radius: 4px;
}

.msg-meta {
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

.msg-agent .msg-meta { color: rgba(255,255,255,0.7); }

.msg-system {
  align-self: center;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 12px;
  padding: 6px 16px;
  border-radius: 20px;
  text-align: center;
}

/* WhatsApp-style day separator — small centered chip injected between
   messages whenever the calendar day changes. Stretches across the
   full chat width with a hairline that fades behind the chip so the
   eye locks onto the date label. */
.msg-day-divider {
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 14px 0 6px;
  position: relative;
}
.msg-day-divider::before {
  content: '';
  position: absolute;
  left: 8%;
  right: 8%;
  top: 50%;
  height: 1px;
  background: var(--border);
  opacity: 0.6;
}
.msg-day-divider span {
  position: relative;
  z-index: 1;
  background: var(--bg-main, var(--bg-card));
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.4px;
  text-transform: uppercase;
  padding: 4px 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.chat-input-bar {
  display: flex;
  gap: 8px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.chat-input-bar textarea {
  flex: 1;
  border: none;
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  resize: none;
  min-height: 44px;
  max-height: 120px;
  outline: none;
}

/* Voice-note recording row — replaces the input row while recording */
#chat-record-bar { align-items: center; gap: 10px; }
.rec-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  background: #ef4444;
  border-radius: 50%;
  box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6);
  animation: rec-pulse 1.2s ease-out infinite;
}
@keyframes rec-pulse {
  0%   { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.6); }
  70%  { box-shadow: 0 0 0 8px rgba(239, 68, 68, 0); }
  100% { box-shadow: 0 0 0 0 rgba(239, 68, 68, 0); }
}

/* === Knowledge Base Cards === */
.kb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 16px;
}

.kb-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: box-shadow 0.2s;
}

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

.kb-card-header {
  display: flex;
  align-items: start;
  justify-content: space-between;
  margin-bottom: 12px;
}

.kb-category {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--primary);
  background: var(--primary-light);
  padding: 2px 8px;
  border-radius: 4px;
}

.kb-card h4 {
  font-size: 15px;
  font-weight: 600;
  margin-bottom: 8px;
}

.kb-card p {
  font-size: 13px;
  color: var(--text-secondary);
  line-height: 1.5;
  display: -webkit-box;
  -webkit-line-clamp: 3;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.kb-card-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border-light);
}

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

.kb-status {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 10px;
}

.kb-status.active { background: var(--success-light); color: var(--success); }
.kb-status.inactive { background: var(--danger-light); color: var(--danger); }

/* === Modal === */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  backdrop-filter: blur(4px);
}

.modal {
  background: var(--bg-card);
  border-radius: var(--radius);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}

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

.modal-header h3 { font-size: 16px; font-weight: 600; }

.modal-body { padding: 24px; }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 24px;
  border-top: 1px solid var(--border);
}

/* === Toast === */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  color: #fff;
  box-shadow: var(--shadow-lg);
  animation: toastIn 0.3s ease;
  max-width: 360px;
}

.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--info); }

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

/* === Pagination === */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 16px 20px;
  border-top: 1px solid var(--border-light);
}

.pagination button {
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}

.pagination button.active {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.pagination button:disabled { opacity: 0.3; cursor: not-allowed; }

/* === Responsive === */
@media (max-width: 1024px) {
  .chat-sidebar {
    width: 260px;
    min-width: 260px;
  }
}

@media (max-width: 768px) {
  .sidebar {
    position: fixed;
    left: 0;
    top: 0;
    transform: translateX(-100%);
  }

  .sidebar.open { transform: translateX(0); }
  .sidebar-toggle-mobile { display: block; }
  .menu-btn { display: flex; }

  .page-content { padding: 12px; }
  .charts-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .table-header { flex-direction: column; align-items: stretch; }
  .kb-grid { grid-template-columns: 1fr; }
  .hide-mobile { display: none !important; }

  /* Chat mobile layout */
  .chat-layout { flex-direction: column; height: calc(100vh - var(--topbar-height) - 24px); }

  .chat-sidebar {
    width: 100%;
    min-width: 100%;
    border-left: none;
    border-top: 1px solid var(--border);
    max-height: none;
    overflow: visible;
  }

  .sidebar-panel-toggle { display: flex !important; margin: 8px 16px; }
  .panel-content { display: none; }
  .panel-content.panel-open { display: block; }
  .chat-sidebar.panel-expanded { flex: 0 0 auto; }

  .msg-bubble { max-width: 85%; }

  .chat-top-actions { padding: 6px 0; }
  .chat-action-btns { margin-left: auto; }
  .chat-action-btns .btn { padding: 6px 8px; font-size: 11px; }

  .session-row { padding: 10px 12px; }
  .session-row-right { min-width: 70px; }

  /* Modal mobile */
  .modal { max-width: 95vw; margin: 12px; }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .stat-card { padding: 14px; }
  .stat-value { font-size: 22px; }
  .filter-tabs { flex-wrap: wrap; }
  .chat-action-btns { flex-wrap: wrap; }
}

/* === Scrollbar === */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* === Utilities === */
/* === Dashboard Filters === */
.dash-filters {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.date-range-picker {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.date-range-picker label {
  font-size: 12px;
  color: var(--text-muted);
  font-weight: 500;
}

.date-range-picker input[type="date"] {
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 13px;
  font-family: inherit;
}

.date-range-picker input[type="date"]:focus {
  outline: none;
  border-color: var(--primary);
}

.quick-filters {
  display: flex;
  gap: 4px;
  margin-left: auto;
}

.stat-icon.closed { background: var(--bg-secondary); color: var(--text-muted); }

.clickable { cursor: pointer; }
.text-truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.text-muted { color: var(--text-muted); }
.text-small { font-size: 12px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; }

/* ================================================================
 * Settings Page
 * ================================================================ */
.settings-page {
  max-width: 900px;
}

.settings-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.settings-header h3 {
  margin: 0 0 4px;
  font-size: 18px;
}

.settings-group {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 20px;
  overflow: hidden;
}

.settings-group-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px;
  background: var(--sidebar-bg);
  border-bottom: 1px solid var(--border);
}

.settings-group-header i {
  font-size: 20px;
  color: var(--primary);
  width: 28px;
  text-align: center;
}

.settings-group-header h4 {
  margin: 0;
  font-size: 15px;
}

.settings-group-header p {
  margin: 2px 0 0;
}

.settings-items {
  padding: 4px 0;
}

.setting-item {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  align-items: start;
}

.setting-item:last-child {
  border-bottom: none;
}

.setting-item.setting-empty {
  background: rgba(245, 158, 11, 0.03);
}

.setting-label {
  font-weight: 600;
  font-size: 14px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}

.setting-desc {
  margin-top: 4px;
  line-height: 1.4;
}

.setting-key {
  margin-top: 2px;
}

.setting-control {
  display: flex;
  flex-direction: column;
}

.setting-input-group {
  display: flex;
  gap: 4px;
}

.setting-input {
  flex: 1;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: 'JetBrains Mono', 'Fira Code', monospace, sans-serif;
  min-width: 0;
}

.setting-input:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

.setting-meta {
  grid-column: 1 / -1;
  font-size: 11px;
  padding-top: 4px;
}

/* Settings Mobile */
@media (max-width: 768px) {
  .setting-item {
    grid-template-columns: 1fr;
    gap: 8px;
  }

  .settings-header {
    flex-direction: column;
  }
}

/* ================================================================
 * LEADS
 * ================================================================ */
.nav-sub { padding-left: 32px; font-size: 13px; opacity: 0.85; }

.leads-toolbar {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  margin-bottom: 16px; padding: 12px; background: var(--surface);
  border-radius: 10px; border: 1px solid var(--border);
}
.leads-search {
  flex: 1; min-width: 220px; position: relative;
}
.leads-search input {
  width: 100%; padding: 8px 12px 8px 32px;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; font-size: 14px;
}
.leads-search i {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); pointer-events: none;
}
.leads-filter {
  padding: 7px 10px; background: var(--bg); border: 1px solid var(--border);
  color: var(--text); border-radius: 8px; font-size: 13px; min-width: 130px;
}
.leads-count { padding: 8px 12px; color: var(--text-muted); font-size: 13px; }
.leads-table { width: 100%; border-collapse: collapse; }
.leads-table th, .leads-table td {
  padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border);
  font-size: 14px; vertical-align: middle;
}
.leads-table th { color: var(--text-muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }
.leads-table tr:hover { background: var(--surface-hover, rgba(255,255,255,0.03)); }

.lead-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 10px; margin: 2px 4px 2px 0;
  background: #0a0a0a; color: #fff;
  border-radius: 999px; font-size: 12px; font-weight: 500;
  white-space: nowrap;
}
.lead-chip .fa-times {
  cursor: pointer; opacity: 0.7; margin-left: 2px; font-size: 10px;
}
.lead-chip .fa-times:hover { opacity: 1; }
.lead-chip-list { background: #475569; }

.tag-input-wrap {
  display: flex; flex-direction: column; gap: 6px;
  padding: 6px; background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; min-height: 38px;
}
.tag-chips { display: flex; flex-wrap: wrap; gap: 2px; }
.tag-input-row { position: relative; }
.tag-input {
  width: 100%; padding: 6px 8px; background: transparent;
  border: none; outline: none; color: var(--text); font-size: 14px;
}
.tag-suggest-list {
  position: absolute; top: 100%; left: 0; right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 8px; margin-top: 4px; max-height: 240px; overflow-y: auto;
  z-index: 100; box-shadow: 0 8px 24px rgba(0,0,0,0.25);
}
.tag-suggest-item {
  padding: 8px 12px; cursor: pointer; font-size: 14px;
  border-bottom: 1px solid var(--border);
}
.tag-suggest-item:last-child { border-bottom: none; }
.tag-suggest-item:hover { background: var(--surface-hover, rgba(255,255,255,0.05)); }
.tag-suggest-create { color: var(--primary); font-weight: 500; }

.lead-form-panel {
  margin-top: 16px; padding-top: 16px;
  border-top: 1px solid var(--border);
}
.lead-form-panel h4 {
  display: flex; align-items: center; gap: 6px;
  margin: 0 0 12px; font-size: 14px; color: var(--text);
}
.lead-status-line {
  margin-top: 8px; font-size: 12px; color: var(--success, #10b981);
  display: flex; align-items: center; gap: 6px;
}
.lead-session-link {
  margin-top: 8px; padding: 8px 12px; background: var(--bg);
  border: 1px dashed var(--border); border-radius: 8px;
  font-size: 13px; color: var(--text-muted);
}
.lead-session-link a { color: var(--primary); }

.leads-settings-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 20px;
}
@media (max-width: 768px) { .leads-settings-grid { grid-template-columns: 1fr; } }
.settings-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px;
}
.settings-card-head {
  display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px;
}
.settings-card-head h3 { margin: 0; font-size: 15px; display: flex; align-items: center; gap: 8px; }
.row-add { display: flex; gap: 6px; }
.row-add input[type="text"] {
  flex: 1; padding: 6px 10px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; color: var(--text);
}
.row-add input[type="color"] {
  width: 36px; height: 32px; border: 1px solid var(--border);
  border-radius: 6px; background: transparent; cursor: pointer;
}
.ls-row {
  display: flex; align-items: center; gap: 6px;
  padding: 8px 0; border-bottom: 1px solid var(--border);
}
.ls-row:last-child { border-bottom: none; }
.ls-row .ls-name {
  flex: 1; padding: 6px 10px; background: var(--bg);
  border: 1px solid var(--border); border-radius: 6px; color: var(--text);
}
.ls-row .ls-color {
  width: 32px; height: 28px; border: 1px solid var(--border);
  border-radius: 6px; background: transparent; cursor: pointer;
}
.empty-state {
  text-align: center; padding: 60px 20px; color: var(--text-muted);
}
.empty-state i { font-size: 48px; opacity: 0.4; margin-bottom: 12px; }

/* === Product Portfolio v2 === */

/* Product card additions */
.product-card-meta {
  display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
  font-size: 11px; margin-top: 3px;
}
.product-card-num {
  background: var(--bg-secondary);
  color: var(--text-secondary);
  padding: 1px 7px; border-radius: 4px;
  font-family: ui-monospace, monospace;
}
.product-card-stock { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 3px; }
.product-card-var {
  font-size: 11px; color: var(--text-secondary);
  margin-top: 4px;
}
.product-card-var i { margin-right: 4px; opacity: 0.6; }
.price-sale { color: var(--primary); font-weight: 700; }
.price-was { text-decoration: line-through; opacity: 0.5; font-weight: 400; font-size: 0.85em; margin-left: 4px; }

/* Stock chips */
.stock-chip {
  display: inline-block;
  padding: 1px 7px; border-radius: 4px;
  font-size: 10px; font-weight: 700; letter-spacing: 0.02em;
  text-transform: uppercase;
}
.stock-in_stock          { background: var(--success-light); color: var(--success); }
.stock-out_of_stock      { background: var(--danger-light); color: var(--danger); }
.stock-retired           { background: var(--bg-secondary); color: var(--text-muted); }
.stock-orders_only       { background: var(--warning-light); color: var(--warning); }
.stock-bulk_orders_only  { background: var(--info-light); color: var(--info); }
.stock-upcoming          { background: var(--primary-light); color: var(--primary); }

/* Stock pill multi-select (in modal) */
.stock-pills { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 4px; }
.stock-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 12px;
  background: var(--bg-card);
  transition: all 0.15s ease;
  user-select: none;
}
.stock-pill input { margin: 0; accent-color: var(--primary); }
.stock-pill:has(input:checked) {
  background: var(--primary-light);
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
}

/* Product modal — collapsible sections */
.pm-section {
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
  background: var(--bg-card);
  overflow: hidden;
}
.pm-section-head {
  width: 100%; padding: 10px 14px;
  background: var(--bg-secondary); border: none; border-bottom: 1px solid transparent;
  font-weight: 600; font-size: 13px; color: var(--text-primary);
  font-family: inherit; text-align: left; cursor: pointer;
  display: flex; align-items: center; justify-content: space-between;
}
.pm-section-head i { transition: transform 0.2s ease; opacity: 0.6; font-size: 11px; }
.pm-section.open .pm-section-head { border-bottom-color: var(--border-light); }
.pm-section.open .pm-section-head i { transform: rotate(180deg); }
.pm-section-body { padding: 14px; display: none; }
.pm-section.open .pm-section-body { display: block; }

.pm-inline-err {
  margin-top: 6px;
  padding: 8px 10px;
  background: var(--danger-light);
  color: var(--danger);
  border-radius: 6px;
  font-size: 12px;
}

/* Smart Optimize — per-product inline button row + suggestion card */
.pm-optimize-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  margin-bottom: 12px;
  padding: 10px 12px;
  background: linear-gradient(135deg, rgba(16,185,129,.08), rgba(16,185,129,.02));
  border: 1px dashed rgba(16,185,129,.3);
  border-radius: var(--radius);
}
.pm-opt-card {
  margin: 8px 0 16px;
  padding: 14px;
  background: var(--bg-secondary);
  border: 1px solid rgba(16,185,129,.4);
  border-radius: var(--radius);
}
.pm-opt-head {
  font-weight: 600;
  margin-bottom: 10px;
  color: #10b981;
}
.opt-readonly {
  padding: 8px 10px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  font-size: 13px;
  color: var(--text-secondary);
  white-space: pre-wrap;
  word-break: break-word;
}
.opt-readonly-long {
  max-height: 180px;
  overflow-y: auto;
}

/* Categories tree */
.cat-tree {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
}
.cat-row {
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border-light);
  transition: background 0.12s ease;
}
.cat-row:last-child { border-bottom: none; }
.cat-row:hover { background: var(--bg-secondary); }
.cat-name { display: flex; align-items: center; gap: 4px; font-size: 14px; }
.cat-meta { font-size: 11px; color: var(--text-muted); margin-left: 8px; }
.cat-actions { display: flex; gap: 4px; }

/* WooCommerce import log */
.woo-log {
  margin-top: 12px;
  padding: 10px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  max-height: 220px;
  overflow-y: auto;
  font-family: ui-monospace, monospace;
  font-size: 11px;
  line-height: 1.6;
  color: var(--text-secondary);
}

/* === Products grid === */
.product-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 14px;
  padding: 4px 0;
}
.product-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  overflow: hidden;
  cursor: pointer;
  transition: all 0.16s ease;
  box-shadow: var(--shadow-sm);
}
.product-card:hover {
  border-color: var(--primary);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}
.product-card-inactive { opacity: 0.55; }
.product-card-image {
  width: 100%; aspect-ratio: 1 / 1;
  background: var(--bg-secondary);
  position: relative; overflow: hidden;
}
.product-card-image img { width: 100%; height: 100%; object-fit: cover; display: block; }
.product-card-placeholder {
  width: 100%; height: 100%;
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted); background: var(--bg-secondary);
}
.product-card-placeholder i { font-size: 32px; opacity: 0.4; }
.product-card-body { padding: 12px; }
.product-card-name {
  font-weight: 600; font-size: 14px; line-height: 1.3;
  color: var(--text-primary);
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; text-overflow: ellipsis;
}
.product-card-cat {
  font-size: 10px; font-weight: 700; letter-spacing: 0.05em;
  text-transform: uppercase; color: var(--text-muted);
  margin-top: 4px;
}
.product-card-price { font-size: 13px; color: var(--primary); font-weight: 600; margin-top: 4px; }
.product-card-tags { margin-top: 6px; }
.product-inactive-flag {
  position: absolute; top: 8px; right: 8px;
  background: rgba(0,0,0,0.6); color: #fff;
  padding: 2px 8px; border-radius: 4px;
  font-size: 10px; font-weight: 700;
}

/* === Social posts list === */
.social-posts-list { display: flex; flex-direction: column; gap: 12px; }
.social-post-card {
  display: flex; gap: 12px;
  background: var(--bg-card); border: 1px solid var(--border-light);
  border-radius: var(--radius); padding: 12px;
  cursor: pointer; transition: all 0.16s ease;
  box-shadow: var(--shadow-sm);
}
.social-post-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.social-post-image {
  width: 120px; height: 120px; flex-shrink: 0;
  background: var(--bg-secondary); border-radius: var(--radius-sm);
  overflow: hidden;
}
.social-post-image img, .social-post-image .product-card-placeholder { width: 100%; height: 100%; object-fit: cover; }
.social-post-body { flex: 1; min-width: 0; }
.social-post-head { font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.social-post-caption { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; line-height: 1.4; }
.social-post-products { display: flex; flex-wrap: wrap; gap: 4px; }

/* === Health banner === */
.health-banner {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius);
  margin-bottom: 12px;
  font-size: 13px; line-height: 1.5;
  border: 1px solid transparent;
}
.health-banner i { font-size: 18px; flex-shrink: 0; margin-top: 1px; }
.health-banner.danger {
  background: var(--danger-light); color: var(--danger);
  border-color: var(--danger);
}
.health-banner.warn {
  background: var(--warning-light); color: var(--warning);
  border-color: var(--warning);
}
.health-banner.ok {
  background: var(--success-light); color: var(--success);
  border-color: var(--success);
}
.health-banner a { color: inherit; text-decoration: underline; font-weight: 600; }
.health-banner code { background: rgba(0,0,0,0.08); padding: 1px 6px; border-radius: 4px; font-size: 12px; }

/* === Bulk product upload list === */
.bulk-products-list {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 50vh; overflow-y: auto;
  margin-top: 10px;
}
.bulk-prod-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
}
.bulk-prod-row img {
  width: 56px; height: 56px; border-radius: var(--radius-sm);
  object-fit: cover; flex-shrink: 0;
  background: var(--bg-card);
}
.bulk-prod-fields {
  flex: 1; display: flex; gap: 8px; align-items: center; min-width: 0;
}
.bulk-prod-fields input[type="text"] {
  flex: 1; min-width: 0;
  padding: 8px 12px;
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text-primary); font-family: inherit;
}
.bulk-prod-fields input[type="text"]:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.bulk-prod-name { flex: 2 !important; }
.bulk-prod-status {
  display: flex; align-items: center; gap: 4px;
  flex-shrink: 0; min-width: 32px;
  font-size: 18px;
}
@media (max-width: 600px) {
  .bulk-prod-row { flex-wrap: wrap; }
  .bulk-prod-fields { width: 100%; flex-wrap: wrap; }
  .bulk-prod-name, .bulk-prod-price { flex-basis: 100% !important; }
}

/* === Confidence bar === */
.confidence-bar {
  position: relative;
  width: 80px; height: 16px;
  background: var(--bg-secondary);
  border-radius: 999px; overflow: hidden;
}
.confidence-fill {
  height: 100%; transition: width 0.3s ease;
}
.confidence-bar span {
  position: absolute; inset: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 10px; font-weight: 700; color: var(--text-primary);
  letter-spacing: 0.02em;
}

/* === Mobile === */
@media (max-width: 768px) {
  .product-grid { grid-template-columns: repeat(2, 1fr); gap: 10px; }
  .product-card-body { padding: 10px; }
  .product-card-name { font-size: 13px; }
  .social-post-card { flex-direction: column; }
  .social-post-image { width: 100%; height: 200px; }
}

/* === Collection autocomplete (--- trigger in chat input) === */
.collection-autocomplete {
  position: absolute;
  bottom: calc(100% + 6px); left: 0; right: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  max-height: 280px;
  overflow-y: auto;
  z-index: 200;
  padding: 6px;
}
.collection-autocomplete .ac-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
  color: var(--text-primary);
  transition: background 0.12s ease;
}
.collection-autocomplete .ac-item:hover,
.collection-autocomplete .ac-item.ac-active {
  background: var(--primary-light);
}
.collection-autocomplete .ac-name {
  font-weight: 600;
  color: var(--primary);
  font-family: 'JetBrains Mono', 'Menlo', monospace;
  font-size: 12.5px;
  white-space: nowrap;
}
.collection-autocomplete .ac-meta {
  font-size: 11px;
  color: var(--text-muted);
  background: var(--bg-secondary);
  padding: 2px 8px;
  border-radius: 999px;
  margin-left: auto;
  white-space: nowrap;
}
.collection-autocomplete .ac-desc {
  flex-basis: 100%;
  font-size: 11px;
  color: var(--text-secondary);
  padding-left: 0;
  opacity: 0.85;
}

/* === Baseline input styling — applies to ALL inputs not inside .form-group ===
   The marketing pages use bare inputs that need the same warm look. */
.send-step-card input[type="text"],
.send-step-card input[type="email"],
.send-step-card input[type="number"],
.send-step-card select,
.send-step-card textarea,
.csv-drop-zone + textarea,
#bk-csv {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-input);
  color: var(--text-primary);
  font-size: 14px;
  font-family: inherit;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
.send-step-card textarea, #bk-csv {
  resize: vertical; min-height: 80px;
}
.send-step-card input:focus,
.send-step-card select:focus,
.send-step-card textarea:focus,
#bk-csv:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* === Marketing — list pills, CSV upload, campaign UI === */
.mkt-lists-bar {
  display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 12px;
  padding: 12px; background: var(--bg-card);
  border: 1px solid var(--border-light); border-radius: var(--radius);
}
.mkt-list-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 6px 12px; font-size: 13px; font-weight: 500;
  background: var(--bg-secondary); color: var(--text-secondary);
  border: 1px solid var(--border-light);
  border-radius: 999px; cursor: pointer; transition: all 0.16s ease;
}
.mkt-list-pill:hover { color: var(--text-primary); border-color: var(--border); }
.mkt-list-pill.active {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.mkt-list-pill .pill-count {
  background: rgba(255,255,255,0.25); color: inherit;
  padding: 1px 7px; border-radius: 999px; font-size: 11px; font-weight: 700;
}
.mkt-list-pill:not(.active) .pill-count { background: var(--bg-card); color: var(--text-muted); }
.mkt-edit-list { font-size: 11px; opacity: 0.5; margin-left: 4px; cursor: pointer; }
.mkt-edit-list:hover { opacity: 1; }

.csv-drop-zone {
  border: 2px dashed var(--border); border-radius: var(--radius-sm);
  padding: 24px; text-align: center; color: var(--text-muted);
  margin-bottom: 8px; transition: all 0.16s ease;
}
.csv-drop-zone.drag-over {
  border-color: var(--primary); background: var(--primary-light);
  color: var(--primary);
}
.csv-drop-zone i { font-size: 28px; display: block; margin-bottom: 8px; }

.bulk-result { padding: 12px; background: var(--bg-secondary); border-radius: var(--radius-sm); margin-top: 12px; }
.bulk-stat-row { display: flex; gap: 12px; flex-wrap: wrap; }
.bulk-stat { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 500; }
.bulk-stat.ok   { background: var(--success-light); color: var(--success); }
.bulk-stat.info { background: var(--info-light); color: var(--info); }
.bulk-stat.warn { background: var(--warning-light); color: var(--warning); }

.send-step-card {
  background: var(--bg-card); border: 1px solid var(--border-light);
  border-radius: var(--radius); padding: 20px; margin-bottom: 16px;
  box-shadow: var(--shadow-sm);
}
.send-step-card h3 { display: flex; align-items: center; gap: 12px; font-size: 15px; margin-bottom: 12px; }
.send-step-card .step-num {
  display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 50%;
  background: var(--primary); color: #fff; font-size: 13px; font-weight: 700;
}

.template-card {
  display: flex; gap: 12px; align-items: flex-start;
  padding: 12px; border: 1px solid var(--border-light); border-radius: var(--radius-sm);
  margin-bottom: 8px; cursor: pointer; transition: all 0.16s ease;
}
.template-card:hover { border-color: var(--primary); background: var(--primary-light); }
.template-card input[type="radio"] { margin-top: 2px; }
.template-card input[type="radio"]:checked + div .template-name { color: var(--primary); }
.template-card .template-name { font-weight: 600; font-size: 14px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.template-card .template-lang, .template-card .template-cat {
  font-size: 10px; padding: 2px 7px; border-radius: 999px;
  font-weight: 700; letter-spacing: 0.05em; text-transform: uppercase;
}
.template-card .template-lang { background: var(--info-light); color: var(--info); }
.template-card .template-cat  { background: var(--warning-light); color: var(--warning); }
.template-card .template-preview {
  font-size: 12px; color: var(--text-secondary);
  margin-top: 6px; line-height: 1.5; white-space: pre-wrap;
}

.template-card.template-disabled {
  opacity: 0.55; cursor: not-allowed;
  background: var(--bg-secondary);
}
.template-card.template-disabled:hover {
  border-color: var(--border-light); background: var(--bg-secondary);
}
.template-card.template-disabled input[type="radio"] { cursor: not-allowed; }

.template-warning {
  margin-top: 8px; padding: 8px 10px;
  background: var(--danger-light); color: var(--danger);
  border-radius: var(--radius-sm); font-size: 12px;
  display: flex; align-items: flex-start; gap: 8px; line-height: 1.45;
}
.template-warning i { margin-top: 2px; }

.var-meta {
  display: inline-block;
  font-size: 9px; font-weight: 700; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--text-muted);
  margin-left: 6px; vertical-align: middle;
  padding: 2px 6px; border-radius: 4px;
  background: var(--bg-secondary);
}

.var-input-block {
  padding: 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  margin-bottom: 10px;
}
.var-input-label {
  font-weight: 600; font-size: 13px;
  color: var(--text-primary); margin-bottom: 8px;
  display: flex; align-items: center;
}
.var-mode-tabs {
  display: inline-flex; gap: 4px;
  padding: 3px; background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: 999px; margin-bottom: 10px;
}
.var-mode-pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 12px; font-size: 12px; font-weight: 500;
  background: transparent; color: var(--text-muted);
  border: none; cursor: pointer; border-radius: 999px;
  transition: all 0.15s ease;
}
.var-mode-pill:hover { color: var(--text-primary); }
.var-mode-pill.active {
  background: var(--primary); color: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,0.1);
}
.var-mode-pill.var-mode-dyn.active {
  background: var(--warning); color: #fff;
}
.var-mode-input { width: 100%; }
.var-mode-input input {
  width: 100%; padding: 9px 12px;
  background: var(--bg-card); border: 1px solid var(--border);
  color: var(--text-primary); border-radius: var(--radius-sm);
  font-size: 14px; font-family: inherit;
}
.var-mode-input input:focus {
  outline: none; border-color: var(--primary);
  box-shadow: 0 0 0 3px var(--primary-light);
}
.var-dyn-readout {
  padding: 10px 12px;
  background: var(--warning-light); color: var(--warning);
  border: 1px dashed var(--warning); border-radius: var(--radius-sm);
  font-size: 13px; display: flex; align-items: center; gap: 8px;
}
.var-dyn-readout i { font-size: 14px; }

.tabs { display: flex; gap: 4px; margin-bottom: 12px; border-bottom: 1px solid var(--border); }
.tab-btn {
  padding: 8px 14px; background: transparent; border: none;
  color: var(--text-muted); cursor: pointer; font-size: 13px; font-weight: 500;
  border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--primary); border-bottom-color: var(--primary); }

.recipient-list-pill {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 14px; margin: 4px;
  background: var(--bg-secondary); border: 1px solid var(--border-light);
  border-radius: 999px; cursor: pointer; transition: all 0.16s ease;
  user-select: none;
}
.recipient-list-pill.checked,
.recipient-list-pill:has(input:checked) {
  background: var(--primary-light); border-color: var(--primary); color: var(--primary);
}
.recipient-list-pill input { margin: 0; accent-color: var(--primary); }

.search-list { display: flex; flex-direction: column; gap: 4px; max-height: 320px; overflow-y: auto; padding: 4px; }
.search-item {
  display: flex; align-items: center; justify-content: space-between;
  padding: 8px 12px; border-radius: var(--radius-sm);
  background: var(--bg-secondary);
}
.search-item.added { background: var(--primary-light); }
.search-item.added button { background: var(--danger); color: #fff; }

.cs-summary {
  margin-top: 12px; padding: 10px 14px;
  background: var(--bg-secondary); border-radius: var(--radius-sm);
  font-size: 13px; color: var(--text-primary);
}

.campaign-header { margin-bottom: 16px; padding-bottom: 16px; border-bottom: 1px solid var(--border); }
.campaign-status {
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  background: var(--bg-secondary); margin-left: 8px; vertical-align: middle;
  font-weight: 600;
}
.campaign-progress { margin-top: 12px; }
.progress-bar {
  height: 10px; background: var(--bg-secondary);
  border-radius: 999px; overflow: hidden; margin-bottom: 8px;
}
.progress-fill {
  height: 100%; background: linear-gradient(90deg, var(--primary), #8B5A2B);
  transition: width 0.5s ease;
}
.progress-stats { display: flex; gap: 16px; font-size: 13px; flex-wrap: wrap; }

.status-pill {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 3px 10px; border-radius: 999px; font-size: 11px; font-weight: 600;
}
.status-pill.ok      { background: var(--success-light); color: var(--success); }
.status-pill.err     { background: var(--danger-light); color: var(--danger); }
.status-pill.pending { background: var(--bg-secondary); color: var(--text-muted); }
.error-text { font-size: 12px; color: var(--danger); }

/* === Login screen polish === */
.login-brand-mark {
  border-radius: 16px;
  background: var(--primary);
  padding: 6px;
  box-shadow: var(--shadow);
  margin-bottom: 12px;
}
.login-logo h1 {
  color: var(--text-primary);
  font-size: 26px;
  margin: 4px 0 2px;
}
.login-logo p {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  margin: 0 0 18px;
}

/* ================================================================
 * Mr. Potter ARTISAN polish — global card, button, and mobile tuning
 * ================================================================ */

/* Smoother global type rendering */
body { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; }

/* Buttons — shadcn: flat, subtle shadow, no lift */
.btn {
  font-weight: 500;
  letter-spacing: 0;
}
.btn-primary { box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { box-shadow: var(--shadow-sm); }
.btn:active:not(:disabled) { transform: none; }

/* Inputs — warm focus ring */
input, textarea, select {
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}
input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--text-muted) !important;
  box-shadow: 0 0 0 3px var(--primary-light);
}

/* Stat cards with subtle accent */
.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.16s ease;
}
.stat-card:hover { box-shadow: var(--shadow); }

/* Topbar — softer with bg-secondary */
.topbar {
  background: var(--bg-card);
  border-bottom: 1px solid var(--border);
}

/* Table headers — muted, refined */
th { font-size: 11px !important; letter-spacing: 0.05em; text-transform: uppercase; color: var(--text-muted) !important; }

/* Mobile tightening */
@media (max-width: 768px) {
  .session-row { padding: 12px; border-radius: var(--radius-sm); }
  .session-row-right { min-width: 60px; }
  .leads-toolbar { padding: 10px; gap: 6px; }
  .leads-search { min-width: 100%; flex-basis: 100%; }
  .leads-filter { flex: 1; min-width: 130px; }
  .stat-card { padding: 14px; }

  /* Table → vertical-stack-friendly on phones */
  .leads-table th, .leads-table td { padding: 8px 10px; font-size: 13px; }

  /* Chat bubbles tighter */
  .msg-bubble { padding: 9px 12px; font-size: 13.5px; }

  /* Sidebar header gets a bit smaller */
  .sidebar-header { padding: 16px; }
  .sidebar-logo { width: 38px; height: 38px; }
  .sidebar-title { font-size: 15px; }

  /* Buttons in header / actions */
  .btn { padding: 8px 12px; }
  .btn-sm { padding: 6px 10px; font-size: 12px; }
}

@media (max-width: 480px) {
  .session-name { font-size: 13.5px; }
  .session-preview { font-size: 11.5px; }
  .session-channel { display: none; }
  .leads-table th:nth-child(3),
  .leads-table td:nth-child(3) { display: none; } /* hide email col on phones */
}

/* ================================================================
   AI Cost Analytics page
   ================================================================ */
.ai-cost-page { display: flex; flex-direction: column; gap: 16px; }

.ai-cost-filters {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 14px;
  display: flex; flex-direction: column; gap: 10px;
}
.aic-presets { display: flex; gap: 6px; flex-wrap: wrap; }
.aic-custom { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.aic-custom input[type="date"],
.aic-custom input[type="text"],
.aic-custom select {
  padding: 6px 10px;
  border: 1px solid var(--border-light);
  border-radius: 6px;
  font-size: 13px;
  background: var(--bg-card);
  color: var(--text-primary);
}
.aic-custom input[type="text"] { min-width: 200px; }

/* KPI cards */
.aic-kpi-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.aic-kpi {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.aic-kpi-label { font-size: 12px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.5px; }
.aic-kpi-value { font-size: 28px; font-weight: 700; color: var(--text-primary); margin-top: 4px; line-height: 1.1; }
.aic-kpi-sub { font-size: 12px; margin-top: 4px; }

.aic-filtered-strip {
  background: linear-gradient(135deg, rgba(99,102,241,.08), rgba(99,102,241,.02));
  border: 1px solid rgba(99,102,241,.25);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-primary);
}

.aic-section {
  background: var(--bg-card);
  border: 1px solid var(--border-light);
  border-radius: var(--radius);
  padding: 16px 18px;
}
.aic-section-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 8px;
  margin-bottom: 12px;
}
.aic-section-head h3 { margin: 0; font-size: 16px; font-weight: 600; }

.aic-chart-wrap { position: relative; height: 280px; }

.aic-breakdown-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.aic-bars { display: flex; flex-direction: column; gap: 8px; }
.aic-bar-row { display: grid; grid-template-columns: 130px 1fr 110px; gap: 10px; align-items: center; font-size: 13px; }
.aic-bar-label { color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.aic-bar-track { background: var(--bg-secondary); height: 12px; border-radius: 6px; overflow: hidden; }
.aic-bar-fill { background: linear-gradient(90deg, #0a0a0a, #3f3f46); height: 100%; }
.aic-bar-val { text-align: right; font-variant-numeric: tabular-nums; }

.aic-pager { display: flex; align-items: center; gap: 8px; padding: 10px 0 0; }
.aic-link { color: var(--accent); text-decoration: none; }
.aic-link:hover { text-decoration: underline; }

/* Per-message cost chip in Sessions UI (when toggle on) */
.msg-cost-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 1px 7px;
  border-radius: 10px;
  background: rgba(99,102,241,.12);
  color: #0a0a0a;
  font-size: 11px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-left: 6px;
}
.session-cost-banner {
  background: linear-gradient(135deg, rgba(99,102,241,.08), rgba(99,102,241,.02));
  border: 1px solid rgba(99,102,241,.2);
  border-radius: var(--radius);
  padding: 8px 12px;
  font-size: 12px;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

@media (max-width: 900px) {
  .aic-kpi-row { grid-template-columns: repeat(2, 1fr); }
  .aic-breakdown-row { grid-template-columns: 1fr; }
}
@media (max-width: 600px) {
  .aic-kpi-row { grid-template-columns: 1fr; }
}

/* AI Cost — markup indicator + download button */
.aic-markup-badge {
  background: linear-gradient(135deg, rgba(16,185,129,.08), rgba(16,185,129,.02));
  border: 1px solid rgba(16,185,129,.25);
  color: var(--text-primary);
  border-radius: var(--radius);
  padding: 8px 14px;
  font-size: 13px;
  display: flex;
  align-items: center;
  gap: 8px;
}
.aic-markup-badge i { color: #10b981; }

/* KB Audit cards */
.kba-card { padding: 4px; }
.kba-card-head {
  display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
  padding-bottom: 8px; border-bottom: 1px solid var(--border-light);
}
.kba-class { padding: 2px 8px; border-radius: 10px; font-size: 11px; font-weight: 600; }
.kba-reasoning {
  background: linear-gradient(135deg, rgba(139,92,246,.08), rgba(139,92,246,.02));
  border: 1px solid rgba(139,92,246,.25);
  border-radius: 6px; padding: 8px 12px; margin-top: 8px; font-size: 13px;
}
.kba-reasoning i { color: #3f3f46; margin-right: 4px; }
.kba-pre {
  background: var(--bg-secondary);
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 10px 12px;
  font-family: monospace;
  font-size: 11px;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--text-secondary);
}
.kba-merge-target {
  border: 1px solid var(--border-light);
  border-radius: 6px;
  padding: 10px 12px;
  margin-top: 8px;
  background: var(--bg-secondary);
}
.kba-actions {
  display: flex; gap: 8px; justify-content: flex-end;
  margin-top: 14px; padding-top: 10px; border-top: 1px solid var(--border-light);
}

/* ================================================================
   Message reply feature
   ================================================================ */

/* Message bubble needs relative positioning so the reply icon can float */
.msg-bubble { position: relative; }

/* Reply icon — bottom-right corner of every bubble (consistent across
   customer / AI / agent directions so users always find it in the same
   place). Hidden until hover; on touch devices stays at low opacity so
   it's always discoverable. */
.msg-reply-btn {
  position: absolute;
  bottom: 4px;
  right: 4px;
  width: 26px;
  height: 26px;
  border: none;
  background: rgba(255, 255, 255, 0.85);
  color: var(--text-secondary);
  border-radius: 50%;
  cursor: pointer;
  opacity: 0;
  transition: opacity 0.15s ease, background 0.15s ease;
  font-size: 11px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 1px 3px rgba(0,0,0,0.15);
  z-index: 2;
}
.msg-bubble:hover .msg-reply-btn { opacity: 1; }
.msg-reply-btn:hover { background: var(--accent); color: #fff; }
/* Customer / AI bubbles use a darker base so the icon reads against the
   lighter inbound bubble background. */
.msg-customer .msg-reply-btn,
.msg-ai .msg-reply-btn { background: rgba(0,0,0,0.08); color: var(--text-secondary); }
.msg-customer .msg-reply-btn:hover,
.msg-ai .msg-reply-btn:hover { background: var(--accent); color: #fff; }

/* Tap-and-hold friendly on mobile: always visible at low opacity */
@media (hover: none) {
  .msg-reply-btn { opacity: 0.55; }
}

/* Quoted-message card above a reply's body, click-to-jump-to-original */
.msg-quote {
  background: rgba(0, 0, 0, 0.06);
  border-left: 3px solid var(--accent);
  border-radius: 6px;
  padding: 6px 10px;
  margin-bottom: 6px;
  cursor: pointer;
  transition: background 0.12s ease;
  font-size: 12px;
  line-height: 1.35;
}
.msg-quote:hover { background: rgba(0, 0, 0, 0.1); }
.msg-quote-sender { font-weight: 600; color: var(--accent); font-size: 11px; }
.msg-quote-text {
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

/* When the agent's own (outbound) bubble has a quote, use a lighter accent
   that reads against the dark bubble */
.msg-agent .msg-quote,
.msg-ai .msg-quote {
  background: rgba(255, 255, 255, 0.15);
  border-left-color: rgba(255, 255, 255, 0.6);
}
.msg-agent .msg-quote-sender,
.msg-ai .msg-quote-sender { color: rgba(255, 255, 255, 0.9); }
.msg-agent .msg-quote-text,
.msg-ai .msg-quote-text { color: rgba(255, 255, 255, 0.85); }

/* Brief highlight when jumping to a quoted message */
@keyframes msg-flash {
  0%   { box-shadow: 0 0 0 2px rgba(99,102,241,0); background-color: transparent; }
  20%  { box-shadow: 0 0 0 3px rgba(99,102,241,0.5); }
  100% { box-shadow: 0 0 0 2px rgba(99,102,241,0); background-color: transparent; }
}
.msg-bubble-flash { animation: msg-flash 1.6s ease; }

/* The composer's "replying to ___" preview bar */
.chat-reply-bar {
  margin: 0 12px;
  border-top: 1px solid var(--border-light);
  border-left: 1px solid var(--border-light);
  border-right: 1px solid var(--border-light);
  border-top-left-radius: 8px;
  border-top-right-radius: 8px;
  background: var(--bg-secondary);
}
.chat-reply-bar-body {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 12px;
}
.chat-reply-bar-accent {
  width: 3px; align-self: stretch;
  background: var(--accent); border-radius: 2px;
}
.chat-reply-bar-text { flex: 1; min-width: 0; }
.chat-reply-bar-label {
  font-size: 11px; color: var(--accent); font-weight: 600;
}
.chat-reply-bar-label i { margin-right: 4px; }
.chat-reply-bar-preview {
  font-size: 12px; color: var(--text-secondary);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.chat-reply-bar-close {
  width: 28px; height: 28px;
  border: none; background: transparent;
  color: var(--text-muted); border-radius: 50%; cursor: pointer;
}
.chat-reply-bar-close:hover { background: rgba(0,0,0,0.08); color: var(--text-primary); }

/* ================================================================
 * Chat right-sidebar — collapsible sections
 * ================================================================
 * Replaces the old flat "h4 + content" pattern. Each section has a
 * button-shaped header with chevron; clicking toggles its body. State
 * persisted in localStorage by the loadChatTagsPicker bootstrap.
 */
.chat-side-section {
  border-top: 1px solid var(--border);
}
.chat-side-section:first-child { border-top: none; }

.chat-side-head {
  display: flex; align-items: center; gap: 8px;
  width: 100%;
  padding: 12px 16px;
  background: transparent;
  border: none;
  font-size: 13px; font-weight: 600;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
}
.chat-side-head:hover { background: var(--bg-alt); }
.chat-side-head i:first-child { color: var(--primary); }
.chat-side-head > span { flex: 1; }
.chat-side-chev {
  font-size: 11px;
  color: var(--text-muted);
  transition: transform 0.18s ease;
}
.chat-side-section.collapsed .chat-side-chev { transform: rotate(-90deg); }

.chat-side-body {
  padding: 0 16px 16px;
  overflow: hidden;
  max-height: 1200px;
  transition: max-height 0.22s ease, padding 0.22s ease;
}
.chat-side-section.collapsed .chat-side-body {
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
}
/* Reset the inner panels' own padding/margin — the section wrapper handles it now */
.chat-side-body .customer-info-panel,
.chat-side-body .notes-panel,
.chat-side-body .lead-form-panel { padding: 0; border: none; background: transparent; }
.chat-side-body .customer-info-panel h4,
.chat-side-body .notes-panel h4,
.chat-side-body .lead-form-panel h4 { display: none; }

/* ================================================================
 * Chat tag chips (both in sidebar picker and as filter pills)
 * ================================================================ */
.chat-tag-chips {
  display: flex; flex-wrap: wrap; gap: 6px;
}
.chat-tag-chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px;
  font-size: 11px; font-weight: 600;
  border-radius: 999px;
  border: 1.5px solid var(--primary);
  background: transparent;
  cursor: pointer;
  transition: transform 0.08s ease, filter 0.12s ease;
  white-space: nowrap;
}
.chat-tag-chip:hover { filter: brightness(1.1); transform: translateY(-1px); }
.chat-tag-chip.on { box-shadow: 0 1px 2px rgba(0,0,0,0.1); }

/* Filter strip at the top of the Chats list */
.sessions-tag-filter {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: 10px 16px;
  background: var(--bg-alt);
  border-bottom: 1px solid var(--border);
}
.sessions-tag-filter-label {
  font-size: 12px; font-weight: 600;
  color: var(--text-muted);
  margin-right: 4px;
}

/* Chat tag chips inside a session row (small + dense) */
.session-chat-tags-row {
  display: flex; flex-wrap: wrap; gap: 4px;
  margin-top: 4px;
}
.session-chat-tag {
  color: #fff !important;
  border-radius: 4px !important;
  font-weight: 600;
}

/* ================================================================
 * Chat sidebar — Orders section
 * ================================================================
 * Compact, information-dense order cards used inside the chat
 * sidebar's collapsible "Orders" section. Reuses .order-status-badge
 * but renders the cards smaller than the full Orders dashboard.
 */
.chat-side-count {
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  margin-left: -2px;
}
.chat-orders-list {
  display: flex; flex-direction: column; gap: 8px;
}
.chat-order-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--bg-alt, var(--surface, transparent));
}
.chat-order-head {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 4px;
}
.chat-order-num {
  font-size: 13px; font-weight: 600;
  color: var(--text-primary);
}
.chat-order-head .order-status-badge {
  font-size: 11px;
  padding: 2px 8px;
}
.chat-order-total {
  margin-left: auto;
  font-size: 13px; font-weight: 600;
  color: var(--text-primary);
  white-space: nowrap;
}
.chat-order-meta {
  font-size: 11px;
  line-height: 1.4;
  margin-bottom: 6px;
}
.chat-order-actions {
  display: flex; flex-wrap: wrap; gap: 4px;
}
.chat-order-actions .btn {
  padding: 3px 8px;
  font-size: 11px;
  line-height: 1.3;
}
.chat-order-actions .btn-xs {
  padding: 3px 8px;
  font-size: 11px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-primary);
  border-radius: 6px;
  cursor: pointer;
  display: inline-flex; align-items: center; gap: 4px;
}
.chat-order-actions .btn-xs:hover {
  background: var(--bg-alt, rgba(99,102,241,0.06));
  border-color: var(--primary);
}
.chat-order-actions .btn-xs:disabled {
  opacity: 0.6; cursor: wait;
}

/* Delivery push — compact chip used on chat-sidebar order cards once
   the invoice has been shipped to WordPress. The ⚡ icon next to the
   WP order number means "auto-pushed by the payment hook" (vs the
   agent manually clicking Push delivery). */
.chat-order-delivery-chip {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600;
  color: var(--success, #15803d);
  background: rgba(34, 197, 94, 0.10);
  border: 1px solid rgba(34, 197, 94, 0.30);
  padding: 2px 8px;
  border-radius: 10px;
  white-space: nowrap;
}

/* Delivery push — order-detail card. Same green palette as the chip
   so the "pushed" state is visually consistent across both places. */
.delivery-pushed-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: 8px;
  font-size: 13px;
}
.delivery-pushed-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(34, 197, 94, 0.12);
  border: 1px solid rgba(34, 197, 94, 0.35);
  color: var(--success, #15803d);
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
}
.delivery-auto-teaser {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 500;
  color: var(--primary, #0a0a0a);
  background: rgba(99, 102, 241, 0.10);
  border: 1px solid rgba(99, 102, 241, 0.25);
  padding: 2px 8px;
  border-radius: 10px;
}
.delivery-pushed-time { font-size: 11px; }

/* Banner — sits below the pushed row when WP succeeded but ERP
   acknowledgement failed (yellow), or below the push button when the
   last manual attempt errored (red). */
.delivery-banner {
  margin-top: 8px;
  padding: 8px 12px;
  border-radius: 6px;
  font-size: 12px;
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
}
.delivery-banner-warn  { background: rgba(245, 158, 11, 0.10); border: 1px solid rgba(245, 158, 11, 0.35); color: #b45309; }
.delivery-banner-error { background: rgba(239, 68, 68, 0.10);  border: 1px solid rgba(239, 68, 68, 0.35);  color: #b91c1c; }
.delivery-banner .btn-xs {
  font-size: 11px; padding: 2px 8px;
  background: transparent; border: 1px solid currentColor;
  color: inherit; border-radius: 5px;
}

/* ================================================================
 * Chat Tags admin page
 * ================================================================ */
.chat-tags-page { padding: 16px; max-width: 1100px; margin: 0 auto; }
.chat-tags-table input[type="text"] {
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 4px;
  font-size: 13px;
  background: var(--bg);
  color: var(--text-primary);
}
.chat-tags-table input[type="text"]:focus {
  outline: none;
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(99,102,241,0.18);
}

/* ================================================================
 * Image lightbox — click-to-preview overlay
 * ================================================================ */
.img-lightbox {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.92);
  z-index: 10000;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  cursor: zoom-out;
}
.img-lightbox img {
  max-width: 95vw; max-height: 90vh; object-fit: contain;
  border-radius: 4px;
  box-shadow: 0 10px 40px rgba(0,0,0,0.5);
  cursor: default;
}
.img-lightbox-close {
  position: absolute; top: 20px; right: 20px;
  background: rgba(255,255,255,0.18);
  color: white;
  border: none;
  width: 46px; height: 46px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background 0.15s ease, transform 0.08s ease;
}
.img-lightbox-close:hover { background: rgba(255,255,255,0.35); transform: scale(1.06); }
.img-lightbox-close:active { transform: scale(0.96); }
/* Images opted into the lightbox get a zoom-in cursor */
img.lb-img { cursor: zoom-in; }

/* =====================================================================
 * Orders → Customers + Invoice PDF Settings
 * ===================================================================== */

/* Customer table rows are clickable; hover hint reuses leads-table hover */
.cust-row:hover { background: var(--surface-hover, rgba(255,255,255,0.03)); }

/* Inline dedup banner inside the New-Customer modal */
.dedup-banner {
  background: rgba(245, 158, 11, 0.10);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: var(--text);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 13px;
}
.dedup-banner-head {
  display: flex; align-items: center; gap: 6px;
  font-weight: 600; margin-bottom: 8px;
}
.dedup-banner-head .fa-exclamation-triangle { color: #f59e0b; }
.dedup-banner-actions {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}

/* Invoice PDF Settings — three stacked cards on a single column.
   Wider screens get the same single-column layout (each card is busy
   enough not to want to compete for horizontal space). */
.invoice-pdf-settings {
  display: flex; flex-direction: column; gap: 16px;
  max-width: 820px;
}
.invoice-pdf-settings .settings-card-head p { font-size: 12px; }

/* ERP key reveal row — input + Reveal/Hide button side-by-side */
.ips-secret-row {
  display: flex; gap: 6px; align-items: stretch;
}
.ips-secret-row input {
  flex: 1; padding: 8px 10px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text);
  font-family: ui-monospace, monospace; font-size: 13px;
}

/* Invoice logo upload row — thumbnail + controls */
.ips-logo-row {
  display: flex; gap: 14px; align-items: center; flex-wrap: wrap;
}
.ips-logo-thumb {
  width: 120px; height: 90px;
  border-radius: 8px; background: #fff;
  border: 1px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  overflow: hidden; flex-shrink: 0;
}
.ips-logo-thumb img {
  max-width: 100%; max-height: 100%; object-fit: contain;
}
.ips-logo-thumb i { font-size: 28px; color: var(--text-muted); }

/* The settings-card pattern is reused as-is, but generic inputs/textarea
   inside the invoice page need the standard form polish */
.invoice-pdf-settings .form-group input[type="text"],
.invoice-pdf-settings .form-group textarea {
  width: 100%; padding: 8px 10px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 6px; color: var(--text);
}
.invoice-pdf-settings .form-group textarea { resize: vertical; min-height: 80px; }

/* =====================================================================
 * ORDERS — Phase 6
 * ===================================================================== */

/* --- Status badges --- */
.order-status-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  background: var(--surface, rgba(255,255,255,0.04));
  border: 1px solid var(--border);
  color: var(--text-primary);
  white-space: nowrap;
}
.order-status-badge-lg { padding: 6px 14px; font-size: 13px; }
.order-status-dot {
  width: 8px; height: 8px; border-radius: 999px; display: inline-block;
}
.order-status-badge.st-paid { background: rgba(16,185,129,0.12); border-color: rgba(16,185,129,0.35); }
.order-status-badge.st-unpaid { background: rgba(239,68,68,0.10); border-color: rgba(239,68,68,0.35); }
.order-status-badge.st-partial { background: rgba(245,158,11,0.10); border-color: rgba(245,158,11,0.35); }
.order-status-badge.st-cancelled { background: rgba(55,65,81,0.15); border-color: rgba(55,65,81,0.35); color: var(--text-muted); }
.order-status-badge.st-discarded { background: transparent; border-color: var(--border); color: var(--text-muted); }
.order-status-badge.st-draft { background: rgba(156,163,175,0.10); border-color: rgba(156,163,175,0.35); }
/* Delivery-created — sits next to the Paid badge on chat-sidebar
   order cards once the WP push has happened. Same green palette as
   .st-paid so the eye reads "another good thing happened". */
.order-status-badge.st-delivery-created {
  background: rgba(16,185,129,0.12);
  border-color: rgba(16,185,129,0.35);
  color: #047857;
}
/* Tracking-saved — third progress badge once CityPak has handed back
   the tracking number. Indigo palette so it's distinct from "paid"
   and "delivery created" while still reading positive. */
.order-status-badge.st-tracking-saved {
  background: rgba(99,102,241,0.12);
  border-color: rgba(99,102,241,0.35);
  color: #0a0a0a;
}

/* Tracking sub-block inside the order-detail Delivery card. Sits
   right below the green "Pushed to WP" pill. Two visual states:
   no-tracking-yet (just a button) vs tracking-saved (number + waybill
   + status chip + actions). */
.delivery-tracking-block {
  margin-top: 12px;
  padding-top: 10px;
  border-top: 1px dashed var(--border);
}
.delivery-tracking-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 12px;
  font-size: 13px;
  margin-bottom: 4px;
}
.delivery-tracking-row strong { font-weight: 600; margin-right: 4px; color: var(--text-muted); }
.tracking-status-chip {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 10px;
  font-size: 11px; font-weight: 600;
  background: rgba(99,102,241,0.10);
  border: 1px solid rgba(99,102,241,0.25);
  color: #0a0a0a;
  text-transform: uppercase; letter-spacing: 0.5px;
}
.delivery-tracking-actions {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 6px;
}

/* Delivery-state badge — AI-derived journey stage shown on the order
   detail Delivery card AND as a small chip on chat-sidebar cards.
   Colour signals the stage: green = delivered, blue = in delivery,
   amber = handed over (waiting on first scan), grey = unknown. */
.delivery-state-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 3px 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600;
  border: 1px solid transparent;
}
.delivery-state-badge.st-delivered    { background: rgba(16,185,129,0.14); border-color: rgba(16,185,129,0.4); color: #047857; }
.delivery-state-badge.st-in-delivery  { background: rgba(59,130,246,0.12); border-color: rgba(59,130,246,0.35); color: #1d4ed8; }
.delivery-state-badge.st-handed-over  { background: rgba(245,158,11,0.12); border-color: rgba(245,158,11,0.35); color: #b45309; }
.delivery-state-badge.st-unknown      { background: rgba(156,163,175,0.10); border-color: rgba(156,163,175,0.35); color: var(--text-muted); }
/* Two parallel status rows — Order (WP) on top, Delivery (AI scan)
   below. Stacked vertically so the agent sees them as separate
   facts rather than one merged status. */
.delivery-status-stack {
  display: flex; flex-direction: column; gap: 4px;
  margin-top: 8px;
}

/* Online card payment (OnePay) — order detail card */
.op-link-row {
  display: flex; gap: 6px; align-items: center;
  margin-bottom: 4px;
}
.op-link-url {
  flex: 1;
  padding: 8px 10px;
  font-size: 12px;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', Consolas, monospace;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-alt, rgba(99,102,241,0.04));
  color: var(--text-primary);
  cursor: text;
}
.op-actions {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 10px;
}
.op-paid-row {
  display: flex; align-items: center; flex-wrap: wrap; gap: 6px;
}
.op-paid-badge {
  display: inline-flex; align-items: center; gap: 6px;
  background: rgba(16,185,129,0.14);
  border: 1px solid rgba(16,185,129,0.4);
  color: #047857;
  font-weight: 600;
  font-size: 13px;
  padding: 4px 12px;
  border-radius: 999px;
}

/* Replacement-order linkage banner (above the order title) */
.rep-banner {
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin: 8px 0 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}
.rep-banner-child {
  background: rgba(245, 158, 11, 0.10);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #b45309;
}
.rep-banner-parent {
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid rgba(99, 102, 241, 0.25);
  color: var(--text-primary);
}
.rep-link {
  font-weight: 600;
  color: inherit;
  text-decoration: underline;
}
.rep-link:hover { text-decoration: none; }

/* Orders Report — KPI tiles + chart cards + status pills */
.rep-tiles {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 12px;
}
.rep-tile {
  background: var(--bg-card, var(--surface));
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
}
.rep-tile-label {
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 1.2px;
  text-transform: uppercase;
  color: var(--text-muted);
}
.rep-tile-value {
  font-size: 26px;
  font-weight: 700;
  color: var(--text-primary);
  margin: 6px 0 2px;
}
.rep-tile-meta { font-size: 12px; }
.rep-tile-warn { border-color: rgba(239, 68, 68, 0.35); background: rgba(239, 68, 68, 0.04); }
.rep-status-pills { display: flex; flex-wrap: wrap; gap: 8px; }
.rep-status-pill {
  font-size: 12px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(99, 102, 241, 0.08);
  border: 1px solid var(--border);
}
.rep-status-pill.st-paid     { background: rgba(16,185,129,0.12); border-color: rgba(16,185,129,0.35); color: #047857; }
.rep-status-pill.st-unpaid   { background: rgba(239,68,68,0.10);  border-color: rgba(239,68,68,0.35);  color: #b91c1c; }
.rep-status-pill.st-partially_paid { background: rgba(245,158,11,0.10); border-color: rgba(245,158,11,0.35); color: #b45309; }
.rep-status-pill.st-cancelled { background: rgba(55,65,81,0.10); border-color: rgba(55,65,81,0.35); color: var(--text-muted); }
.rep-controls input[type="date"], .rep-controls select {
  padding: 6px 10px; border: 1px solid var(--border); border-radius: 6px;
  background: var(--bg-card, var(--surface)); color: var(--text-primary);
  font-size: 13px;
}

/* Text Templates — management page */
.tt-list { display: flex; flex-direction: column; gap: 8px; }
.tt-card {
  background: var(--bg-card, var(--surface));
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 14px;
  transition: border-color 0.15s;
}
.tt-card:hover { border-color: var(--primary, #0a0a0a); }
.tt-card-head {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  margin-bottom: 6px;
}
.tt-card-actions { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.tt-slug {
  display: inline-block;
  font-family: 'SF Mono', Monaco, 'Cascadia Code', Consolas, monospace;
  font-size: 12px;
  color: var(--primary, #0a0a0a);
  background: rgba(99,102,241,0.08);
  padding: 2px 8px; border-radius: 4px;
  margin-right: 8px;
}
.tt-title { font-weight: 600; font-size: 13px; }
.tt-body {
  font-size: 12px;
  color: var(--text-primary);
  white-space: pre-wrap;
  margin-bottom: 2px;
  line-height: 1.5;
}
.tt-desc { font-size: 11px; font-style: italic; }
/* Suggester preview line for templates — slightly larger so the
   snippet is readable. */
.collection-autocomplete .ac-item[data-trigger=",,,"] .ac-desc {
  white-space: pre-wrap;
  max-height: 38px;
  overflow: hidden;
}

/* PDF download split-button — main face triggers the default
   (invoice), caret opens a 3-option menu. Sits inline with the
   other order-detail action buttons. */
.pdf-dropdown {
  display: inline-flex; position: relative;
}
.pdf-dropdown .pdf-dropdown-main {
  border-top-right-radius: 0; border-bottom-right-radius: 0;
  border-right: 1px solid var(--border);
}
.pdf-dropdown .pdf-dropdown-toggle {
  border-top-left-radius: 0; border-bottom-left-radius: 0;
  padding-left: 8px; padding-right: 8px;
  margin-left: -1px;
}
.pdf-dropdown-menu {
  position: absolute; top: 100%; left: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  margin-top: 4px;
  z-index: 100;
  min-width: 230px;
  overflow: hidden;
}
.pdf-dropdown-menu button {
  display: flex; align-items: center; gap: 10px;
  width: 100%;
  background: transparent; border: none;
  padding: 10px 14px;
  font-size: 13px;
  color: var(--text-primary);
  cursor: pointer;
  text-align: left;
}
.pdf-dropdown-menu button:hover {
  background: var(--bg-alt, rgba(99,102,241,0.08));
}
.pdf-dropdown-menu button i {
  color: var(--primary, #0a0a0a);
  width: 16px;
  text-align: center;
}

/* Same palette echoed for the compact chat-sidebar variants — they
   sit next to "Paid" + "Delivery order created" + tracking chips. */
.order-status-badge.st-delivered-final    { background: rgba(16,185,129,0.14); border-color: rgba(16,185,129,0.4); color: #047857; }
.order-status-badge.st-in-delivery-chip   { background: rgba(59,130,246,0.12); border-color: rgba(59,130,246,0.35); color: #1d4ed8; }
.order-status-badge.st-handed-over-chip   { background: rgba(245,158,11,0.12); border-color: rgba(245,158,11,0.35); color: #b45309; }

/* Milestone preview — collapsible <details> block showing the
   sequence of messages that "Send tracking" will fire. Agent can
   sanity-check the AI-generated wording before clicking. */
.delivery-milestones {
  margin-top: 10px;
  padding: 8px 10px;
  background: rgba(99,102,241,0.04);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
}
.delivery-milestones summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--text-muted);
  user-select: none;
}
.delivery-milestones summary:hover { color: var(--text-primary); }
.delivery-milestones-list {
  margin: 8px 0 0;
  padding-left: 22px;
  line-height: 1.6;
}
.delivery-milestones-list li {
  color: var(--text-primary);
  margin-bottom: 2px;
}
/* Milestones that are skipped by the "delivered → last only" rule
   are shown strikethrough + muted so the agent can see exactly
   which lines won't be sent. */
.delivery-milestones-list li.milestone-skipped {
  color: var(--text-muted);
  text-decoration: line-through;
  opacity: 0.6;
}

/* --- Dashboard page --- */
.orders-page { display: flex; flex-direction: column; gap: 12px; }
.orders-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.orders-title { margin: 0; font-size: 20px; font-weight: 700; }
.orders-header-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.orders-pills { display: flex; gap: 6px; flex-wrap: wrap; }
.orders-pill {
  padding: 6px 14px; border-radius: 999px;
  background: var(--surface, var(--bg)); border: 1px solid var(--border);
  color: var(--text-primary); font-size: 13px; font-weight: 500;
  cursor: pointer;
}
.orders-pill:hover { background: var(--surface-hover, rgba(255,255,255,0.04)); }
.orders-pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.orders-pill.faded { opacity: 0.55; }
.orders-pill.faded.active { opacity: 1; }

.orders-filters {
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  padding: 12px; background: var(--surface, var(--bg)); border: 1px solid var(--border);
  border-radius: 10px;
}
.orders-search { flex: 1; min-width: 200px; position: relative; }
.orders-search input {
  width: 100%; padding: 8px 12px 8px 32px;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text-primary); border-radius: 8px; font-size: 14px;
}
.orders-search i {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-muted); pointer-events: none;
}
.orders-date-label {
  display: flex; align-items: center; gap: 6px;
  font-size: 12px; color: var(--text-muted);
}
.orders-date-label input[type="date"] {
  padding: 6px 8px;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text-primary); border-radius: 6px; font-size: 13px;
}
.orders-clear {
  font-size: 12px; color: var(--primary); cursor: pointer;
  text-decoration: underline; margin-left: 4px;
}
.orders-count { color: var(--text-muted); font-size: 13px; padding: 4px 2px; }

.orders-list { display: flex; flex-direction: column; gap: 8px; }
.ord-row {
  display: grid;
  grid-template-columns: 1.4fr 1.3fr auto auto;
  align-items: center; gap: 12px;
  padding: 12px 14px;
  background: var(--bg-card, var(--surface)); border: 1px solid var(--border);
  border-radius: 10px;
  cursor: pointer; transition: background 0.12s ease;
}
.ord-row:hover { background: var(--surface-hover, rgba(255,255,255,0.04)); }
.ord-row-main { min-width: 0; }
.ord-row-num { font-weight: 700; font-size: 14px; }
.ord-row-cust { font-size: 13px; color: var(--text-primary); margin-top: 2px; }
.ord-row-phone { color: var(--text-muted); font-size: 12px; }
.ord-row-meta {
  display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px;
  color: var(--text-muted);
}
.ord-row-amt { color: var(--text-primary); font-weight: 600; }
.ord-row-status { display: flex; align-items: center; }
.ord-row-menu { display: flex; align-items: center; }

.ord-row-popup {
  position: absolute; z-index: 200; min-width: 200px;
  background: var(--bg-card, var(--surface)); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px; box-shadow: var(--shadow-lg);
}
.ord-row-popup button {
  display: flex; align-items: center; gap: 8px;
  width: 100%; padding: 8px 12px;
  background: none; border: none; cursor: pointer;
  color: var(--text-primary); font-size: 13px; text-align: left;
  border-radius: 6px;
}
.ord-row-popup button:hover { background: var(--surface-hover, rgba(255,255,255,0.05)); }
.ord-row-popup button.danger { color: var(--danger); }

@media (max-width: 768px) {
  .ord-row { grid-template-columns: 1fr auto; gap: 8px; }
  .ord-row-meta { grid-column: 1 / -1; }
  .ord-row-status { grid-column: 1 / 2; }
  .ord-row-menu { grid-column: 2 / 3; justify-self: end; }
}

/* --- Detail page --- */
.order-detail { display: flex; flex-direction: column; gap: 14px; max-width: 1100px; }
.order-detail-top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.order-detail-status-wrap { flex: 1; text-align: center; }
.order-detail-head h2 { margin: 0; font-size: 22px; font-weight: 700; }
.order-detail-sub { font-size: 12px; margin-top: 4px; }

.order-meta-strip {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px;
  padding: 14px; background: var(--surface, var(--bg-card)); border: 1px solid var(--border);
  border-radius: 10px;
}
.ord-meta-label { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.04em; }
.ord-meta-val { font-size: 15px; font-weight: 600; margin-top: 2px; }

.order-erp-row { font-size: 12px; padding: 4px 2px; }
.order-erp-row a { color: var(--primary); }

.order-action-row { display: flex; flex-wrap: wrap; gap: 6px; }

.order-detail-grid {
  display: grid; grid-template-columns: 1fr 320px; gap: 14px;
}
.order-detail-left { display: flex; flex-direction: column; gap: 14px; min-width: 0; }
.order-detail-right { position: sticky; top: 12px; align-self: start; }

.order-totals-card {
  background: var(--bg-card, var(--surface)); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px;
  display: flex; flex-direction: column; gap: 8px;
}
/* gap is the belt-and-braces — flex space-between alone fails to
   separate the label and the value when the card is narrow + both
   spans are bold (the browser pulls them flush). 12px gap guarantees
   visual separation in every viewport / theme. */
.ord-tot-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.ord-tot-row > span:last-child { white-space: nowrap; }
.ord-tot-final { font-size: 16px; font-weight: 700; padding-top: 8px; border-top: 1px solid var(--border); }
.ord-tot-paid { color: var(--success); }
.ord-tot-bal { font-size: 15px; font-weight: 700; padding-top: 8px; border-top: 1px dashed var(--border); }

.ord-cust-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px; font-size: 13px;
}
@media (max-width: 600px) { .ord-cust-grid { grid-template-columns: 1fr; } }

.ord-items-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.ord-items-table th, .ord-items-table td {
  text-align: left; padding: 8px 10px;
  border-bottom: 1px solid var(--border); vertical-align: middle;
}
.ord-items-table th { color: var(--text-muted); font-weight: 600; font-size: 11px; text-transform: uppercase; }
.ord-items-table .ord-num-col { text-align: right; white-space: nowrap; }
.ord-item-thumb {
  width: 32px; height: 32px; object-fit: cover;
  border-radius: 4px; vertical-align: middle; margin-right: 8px;
}
span.ord-item-thumb.delivery {
  display: inline-flex; align-items: center; justify-content: center;
  background: #f4f4f5; color: #71717a; border: 1px solid #e4e4e7;
}
span.ord-item-thumb.delivery i { font-size: 16px; }

@media (max-width: 900px) {
  .order-detail-grid { grid-template-columns: 1fr; }
  .order-detail-right { position: static; }
}

/* --- Record payment modal --- */
.ord-pay-balance {
  padding: 12px; background: var(--surface, rgba(255,255,255,0.03));
  border-radius: 8px; margin-bottom: 12px; font-size: 13px;
  border: 1px solid var(--border);
}
.ord-pay-balance strong { font-size: 16px; }

/* --- Cancel modal --- */
.ord-cancel-summary {
  padding: 12px; background: var(--surface, rgba(255,255,255,0.03));
  border-radius: 8px; margin-bottom: 12px; font-size: 13px;
  border: 1px solid var(--border);
  display: flex; flex-direction: column; gap: 4px;
}

/* =====================================================================
 * ORDER FORM (full-screen overlay)
 * ===================================================================== */
.order-form-overlay {
  position: fixed; inset: 0; z-index: 1100;
  background: var(--bg, #0b1220);
  overflow-y: auto;
}
.order-form-inner {
  max-width: 980px; margin: 0 auto;
  padding: 16px 16px 120px;
  position: relative;
  min-height: 100vh;
}
.order-form-header {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 12px;
  padding: 12px 0;
  background: var(--bg, #0b1220);
  border-bottom: 1px solid var(--border);
}
.order-form-title { margin: 0; flex: 1; font-size: 18px; font-weight: 700; }
.order-form-status { margin-right: 8px; }
.order-form-close {
  display: inline-flex; align-items: center; justify-content: center;
  width: 36px; height: 36px;
}
.order-form-banner {
  padding: 10px 12px; border-radius: 8px; font-size: 13px;
  margin: 12px 0;
}
.order-form-banner.warn {
  background: rgba(245,158,11,0.10); border: 1px solid rgba(245,158,11,0.35);
}
.order-form-banner.danger {
  background: rgba(239,68,68,0.10); border: 1px solid rgba(239,68,68,0.35);
}

.order-form-body {
  display: flex; flex-direction: column; gap: 14px; margin-top: 12px;
}
.order-form-card {
  background: var(--bg-card, var(--surface)); border: 1px solid var(--border);
  border-radius: 10px; padding: 16px;
}
.ofc-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; gap: 12px; }
.ofc-head h3 { margin: 0; font-size: 14px; }
.ofc-subtotal { font-size: 13px; color: var(--text-muted); }

.ofc-pills { display: flex; gap: 6px; margin-bottom: 12px; flex-wrap: wrap; }
.ofc-pill {
  padding: 6px 12px; border-radius: 999px;
  background: var(--surface, var(--bg)); border: 1px solid var(--border);
  color: var(--text-primary); font-size: 13px; cursor: pointer;
}
.ofc-pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.ofc-pill:disabled { opacity: 0.5; cursor: not-allowed; }

.ofc-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 10px 16px;
}
@media (max-width: 600px) { .ofc-grid { grid-template-columns: 1fr; } }

.ofc-cust-card {
  background: var(--surface, rgba(255,255,255,0.03));
  border: 1px solid var(--border); border-radius: 8px;
  padding: 12px;
}
.ofc-cust-row { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.ofc-link { color: var(--primary); font-size: 12px; }

.ofc-search-wrap { position: relative; }
.ofc-search-wrap input {
  width: 100%; padding: 10px 12px;
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text-primary); font-size: 14px;
}

.ord-autocomplete {
  position: absolute; z-index: 200; left: 0; right: 0; top: 100%;
  margin-top: 4px;
  background: var(--bg-card, var(--surface)); border: 1px solid var(--border);
  border-radius: 8px; box-shadow: var(--shadow-lg);
  max-height: 280px; overflow-y: auto;
}
.ord-autocomplete .ac-item {
  display: flex; gap: 10px; align-items: center;
  padding: 8px 12px; cursor: pointer;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.ord-autocomplete .ac-item:last-child { border-bottom: none; }
.ord-autocomplete .ac-item:hover { background: var(--surface-hover, rgba(255,255,255,0.05)); }
.ord-autocomplete .ac-thumb {
  width: 36px; height: 36px; object-fit: cover; border-radius: 4px;
  background: var(--surface);
}
.ord-autocomplete .ac-thumb.empty { background: var(--surface); }
.ord-autocomplete .ac-name { font-weight: 600; }
.ord-autocomplete .ac-meta { color: var(--text-muted); font-size: 12px; }
.ord-autocomplete .ac-empty { padding: 10px 12px; color: var(--text-muted); font-size: 13px; }

.ofg-amt { font-weight: 600; padding-top: 4px; }

/* Line items */
.line-item-row {
  border: 1px solid var(--border); border-radius: 8px;
  padding: 10px; margin-bottom: 8px;
  background: var(--surface, rgba(255,255,255,0.02));
}
.line-item-top {
  display: flex; gap: 10px; align-items: center;
}
.line-item-thumb {
  width: 48px; height: 48px; object-fit: cover; border-radius: 6px;
  background: var(--bg); flex-shrink: 0;
}
.line-item-thumb.empty {
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
}
.line-item-thumb.delivery {
  display: flex; align-items: center; justify-content: center;
  background: #f4f4f5; color: #71717a;
  border: 1px solid #e4e4e7;
}
.line-item-thumb.delivery i { font-size: 18px; }
.order-detail-back-group { display: flex; gap: 6px; align-items: center; }
.line-item-desc-wrap { flex: 1; position: relative; min-width: 0; }
.line-item-desc-wrap input {
  width: 100%; padding: 8px 10px;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text-primary); border-radius: 6px; font-size: 14px;
}
.line-item-bottom {
  display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 10px;
  align-items: flex-end;
}
.line-item-bottom label {
  display: flex; flex-direction: column; gap: 4px;
  font-size: 12px; color: var(--text-muted);
}
.line-item-bottom input, .line-item-bottom select {
  padding: 6px 8px;
  background: var(--bg); border: 1px solid var(--border);
  color: var(--text-primary); border-radius: 6px; font-size: 13px;
}
.line-item-bottom .li-qty   { width: 80px; }
.line-item-bottom .li-price { width: 120px; }
.line-item-bottom .li-dtype { width: 150px; }
.line-item-bottom .li-dval  { width: 100px; }
.line-item-bottom .li-total {
  margin-left: auto; font-size: 12px; color: var(--text-muted);
  text-align: right;
}
.line-item-bottom .li-total strong { display: block; font-size: 15px; color: var(--text-primary); }
@media (max-width: 600px) {
  .line-item-bottom .li-total { margin-left: 0; width: 100%; text-align: left; }
}

/* Sticky bottom action bar */
.order-form-sticky {
  position: fixed; bottom: 0; left: 0; right: 0; z-index: 6;
  display: flex; justify-content: flex-end; gap: 8px;
  padding: 12px 16px;
  background: var(--bg-card, var(--surface));
  border-top: 1px solid var(--border);
  box-shadow: 0 -4px 16px rgba(0,0,0,0.18);
}
@media (max-width: 600px) {
  .order-form-sticky { flex-wrap: wrap; padding: 10px; }
  .order-form-sticky .btn { flex: 1 1 auto; }
}

/* Final-total card */
.order-form-total { padding: 22px 16px; text-align: right; }
.order-final-total {
  display: flex; align-items: baseline; justify-content: flex-end; gap: 16px;
}
.ofc-tot-label { font-size: 12px; color: var(--text-muted); letter-spacing: 0.08em; }
.ofc-tot-value { font-size: 28px; font-weight: 800; }

/* Reuse the dedup banner inline */
.dedup-banner-inline {
  background: rgba(245, 158, 11, 0.10);
  border: 1px solid rgba(245, 158, 11, 0.35);
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 13px;
}
.dedup-banner-inline .dedup-banner-head {
  display: flex; align-items: center; gap: 6px;
  font-weight: 600; margin-bottom: 8px;
}
.dedup-banner-inline .dedup-banner-head .fa-exclamation-triangle { color: #f59e0b; }
.dedup-banner-inline .dedup-banner-actions {
  display: flex; flex-wrap: wrap; gap: 6px; align-items: center;
}

/* Order-detail HARD DELETE button (admin-only) — ghost variant with a
   red outline so it visually separates from the safe ghost actions. */
.od-delete-btn {
  color: var(--danger);
  border-color: var(--danger) !important;
  border-style: solid;
  border-width: 1px;
}
.od-delete-btn:hover:not(:disabled) {
  background: var(--danger-light);
}

/* AI auto-fill: customer-update banner shown when AI found contact
   info missing from the existing customer record. */
.ai-cust-update-banner {
  background: linear-gradient(135deg, #f4f4f5, #fafafa);
  border: 1px solid #c4b5fd;
  border-radius: 8px;
  padding: 12px 14px;
  margin-bottom: 12px;
  font-size: 13px;
}
.ai-cust-update-banner-head {
  font-weight: 600;
  color: #0a0a0a;
  margin-bottom: 6px;
}
.ai-cust-update-banner-head i { margin-right: 4px; }
.ai-cust-update-banner-body { color: var(--text-primary); line-height: 1.5; }
.ai-cust-update-banner-body strong { color: var(--text-muted); font-weight: 600; }
.ai-cust-update-banner-actions {
  display: flex; gap: 8px;
  margin-top: 10px;
}
.ai-cust-old { color: var(--text-muted); text-decoration: line-through; }
.ai-cust-new { color: #0a0a0a; font-weight: 600; }

/* ================================================================
 * Order Issues & Feedback
 * ================================================================
 * Card lives in the order-detail left column between Payments and
 * Notes. Reuses the .settings-card chrome. Each .issue-card has a
 * severity-coloured left border so the agent can scan a long list.
 * The small .order-alert-icon variant is also reused on the orders
 * dashboard row and the chat-sidebar order card. */

.order-issues-card .issues-card-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
}
.issues-count-badge {
  font-size: 11px; font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-hover, #f3f4f6);
  color: var(--text-muted);
}
.issues-empty {
  font-size: 13px;
  padding: 14px 4px;
  text-align: center;
  border: 1px dashed var(--border, #e5e7eb);
  border-radius: 8px;
}
.issues-list {
  display: flex; flex-direction: column;
  gap: 10px;
}
.issue-card {
  border: 1px solid var(--border, #e5e7eb);
  border-left-width: 4px;
  border-radius: 8px;
  padding: 12px 14px;
  background: var(--surface, #fff);
}
.issue-sev-critical { border-left-color: #dc2626; background: rgba(220, 38, 38, 0.04); }
.issue-sev-warning  { border-left-color: #ea580c; background: rgba(234, 88, 12, 0.04); }
.issue-sev-info     { border-left-color: #3b82f6; background: rgba(59, 130, 246, 0.04); }

.issue-head {
  display: flex; align-items: center; gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.issue-severity-icon {
  font-size: 14px;
  width: 18px;
  display: inline-flex; align-items: center; justify-content: center;
}
.issue-type-label {
  font-weight: 600;
  font-size: 14px;
  color: var(--text-primary);
}
.issue-status-badge {
  font-size: 11px; font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
}
.issue-status-open      { background: #fef3c7; color: #92400e; }
.issue-status-resolved  { background: #d1fae5; color: #065f46; }
.issue-meta {
  font-size: 12px;
  margin-left: auto;
}
.issue-message {
  font-size: 13px;
  line-height: 1.5;
  white-space: pre-wrap;
  color: var(--text-primary);
}
.issue-resolved-line {
  font-size: 12px;
  margin-top: 8px;
  padding-top: 8px;
  border-top: 1px dashed var(--border, #e5e7eb);
}
.issue-resolution-note {
  margin-top: 4px;
  color: var(--text-muted);
}
.issue-actions {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin-top: 10px;
}
.issue-actions .btn-xs {
  padding: 4px 10px;
  font-size: 12px;
}
.issue-delete-btn {
  color: var(--danger, #dc2626);
}
.issue-modal-status {
  font-size: 13px;
  margin-bottom: 10px;
  color: var(--text-muted);
}

/* Small inline alert pip used on the orders dashboard row + chat
   sidebar order card. Sized to sit next to the customer name without
   pushing the layout around. Click bubbles up to the row → order
   detail (no separate handler needed). */
.order-alert-icon {
  display: inline-flex; align-items: center; justify-content: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  font-size: 11px;
  cursor: pointer;
  margin-left: 4px;
  vertical-align: middle;
}
.order-alert-critical { background: #fee2e2; color: #b91c1c; }
.order-alert-warning  { background: #ffedd5; color: #c2410c; }
.order-alert-info     { background: #dbeafe; color: #1d4ed8; }
.order-alert-icon:hover { filter: brightness(0.95); }

/* ================================================================
 * Lucide line-icon shim (shadcn) — SVGs injected in place of the
 * old Font Awesome <i> glyphs; sized to 1em so all existing
 * font-size-based icon sizing keeps working.
 * ================================================================ */
.licon { display: inline-flex; align-items: center; justify-content: center; line-height: 0; }
.licon > svg, i.licon svg { width: 1em; height: 1em; stroke-width: 2; vertical-align: middle; }
.nav-item .licon, .nav-group-header .licon { width: 20px; }
.lucide-spin { animation: lucide-spin 0.9s linear infinite; transform-origin: center; }
@keyframes lucide-spin { to { transform: rotate(360deg); } }

/* ================================================================
 * Agent-first shell — Playground, Deploy, sidebar Credits
 * ================================================================ */
.pg-wrap{display:grid;grid-template-columns:300px 1fr;gap:0;height:calc(100vh - var(--topbar-height) - 40px);min-height:520px;border:1px solid var(--border);border-radius:var(--radius);overflow:hidden;background:var(--bg-card)}
.pg-cfg{border-right:1px solid var(--border);padding:20px;overflow:auto;display:flex;flex-direction:column;gap:16px}
.pg-status{display:flex;align-items:center;gap:10px;border:1px solid var(--border);border-radius:var(--radius);padding:12px 14px}
.pg-status .pg-dot{width:8px;height:8px;border-radius:50%;background:var(--success);box-shadow:0 0 0 3px var(--success-light);flex:0 0 auto}
.pg-status b{font-size:13.5px}.pg-status small{display:block;color:var(--text-muted);font-size:12px}
.pg-field label{display:block;font-size:12.5px;font-weight:550;color:var(--text-secondary);margin-bottom:6px}
.pg-static{font-size:13.5px;border:1px solid var(--border);border-radius:var(--radius-sm);padding:9px 12px;background:var(--bg-secondary);color:var(--text-primary)}
.pg-field textarea{width:100%;border:1px solid var(--border);border-radius:var(--radius-sm);padding:10px 12px;font:inherit;font-size:13.5px;color:var(--text-primary);background:var(--bg-input);line-height:1.55;resize:vertical;min-height:120px}
.pg-note{font-size:12px;margin-top:6px}
.pg-links{display:flex;gap:8px;flex-wrap:wrap;margin-top:auto}
.pg-chatwrap{background:radial-gradient(circle at 1px 1px,var(--border) 1px,transparent 0) 0 0/22px 22px,var(--bg-secondary);padding:22px;display:flex;flex-direction:column;overflow:auto}
.pg-chat{margin:auto;width:100%;max-width:480px;background:var(--bg-card);border:1px solid var(--border);border-radius:16px;box-shadow:var(--shadow-lg);display:flex;flex-direction:column;overflow:hidden;height:min(560px,calc(100vh - var(--topbar-height) - 130px))}
.pg-chead{display:flex;align-items:center;gap:10px;padding:13px 16px;border-bottom:1px solid var(--border)}
.pg-cav{width:30px;height:30px;border-radius:50%;background:var(--primary);color:#fff;display:flex;align-items:center;justify-content:center;font-size:14px}
.pg-chead b{font-size:14px}
.pg-log{flex:1;padding:16px;display:flex;flex-direction:column;gap:10px;overflow:auto}
.pg-bub{max-width:82%;padding:10px 13px;font-size:13.5px;line-height:1.5;border-radius:14px;white-space:pre-wrap}
.pg-bub.ai{align-self:flex-start;background:var(--bg-secondary);color:var(--text-primary);border-bottom-left-radius:5px}
.pg-bub.me{align-self:flex-end;background:var(--primary);color:#fff;border-bottom-right-radius:5px}
.pg-bub.typing{color:var(--text-muted)}
.pg-chips{display:flex;flex-wrap:wrap;gap:7px;padding:0 16px 4px}
.pg-chip{font-size:12.5px;padding:6px 12px;border:1px solid var(--border);border-radius:999px;background:var(--bg-card);color:var(--text-secondary);cursor:pointer}
.pg-chip:hover{border-color:var(--text-muted);background:var(--bg-secondary)}
.pg-foot{display:flex;gap:8px;align-items:center;padding:12px;border-top:1px solid var(--border)}
.pg-foot input{flex:1;border:1px solid var(--border);border-radius:999px;padding:9px 15px;font:inherit;font-size:13.5px;background:var(--bg-input)}
.pg-foot .btn{border-radius:50%;width:38px;height:38px;padding:0}
.pg-powered{text-align:center;font-size:11px;color:var(--text-muted);margin-top:12px}
@media(max-width:820px){.pg-wrap{grid-template-columns:1fr;height:auto}.pg-cfg{border-right:none;border-bottom:1px solid var(--border)}}

.dep-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(300px,1fr));gap:16px}
.dep-card{border:1px solid var(--border);border-radius:var(--radius);padding:18px;background:var(--bg-card);display:flex;flex-direction:column;gap:8px}
.dep-top{display:flex;align-items:center;justify-content:space-between}
.dep-ic{width:40px;height:40px;border-radius:10px;background:var(--bg-secondary);display:flex;align-items:center;justify-content:center;font-size:18px;color:var(--text-primary)}
.dep-card h3{font-size:15px;font-weight:600;margin:2px 0 0}
.dep-card p{font-size:13px;margin:0;flex:1}
.dep-meta{font-size:12px}
.dep-pill{font-size:11.5px;font-weight:600;padding:3px 10px;border-radius:999px;border:1px solid var(--border);color:var(--text-muted);background:var(--bg-secondary)}
.dep-pill.on{color:#166534;background:#f0fdf4;border-color:#bbf7d0}
.dep-card .btn{align-self:flex-start;margin-top:4px}

.credits-card{border:1px solid var(--border);border-radius:var(--radius);padding:13px 14px;margin-bottom:12px;background:var(--bg-card)}
.credits-card.cc-low{border-color:var(--danger)}
.cc-head{display:flex;justify-content:space-between;align-items:center;margin-bottom:8px}
.cc-title{display:inline-flex;align-items:center;gap:6px;font-size:11px;font-weight:600;color:var(--text-muted);text-transform:uppercase;letter-spacing:.05em}
.cc-plan{font-size:11px;font-weight:600;color:var(--text-secondary);background:var(--bg-secondary);border:1px solid var(--border);border-radius:999px;padding:2px 9px}
.cc-balance{display:flex;align-items:baseline;gap:6px}
.cc-balance b{font-size:22px;font-weight:700;color:var(--text-primary);font-variant-numeric:tabular-nums;letter-spacing:-.01em}
.cc-balance small{font-size:11px;color:var(--text-muted)}
.credits-bar{height:6px;border-radius:999px;background:var(--bg-secondary);margin:9px 0 8px;overflow:hidden}
.credits-bar i{display:block;height:100%;width:0;background:var(--text-primary);border-radius:999px;transition:width .4s}
.cc-used{display:flex;justify-content:space-between;align-items:baseline;font-size:12px;color:var(--text-muted);margin-bottom:11px}
.cc-used b{color:var(--text-secondary);font-weight:600;font-variant-numeric:tabular-nums}

/* ================================================================
 * Native mobile-app feel — bottom tab bar, safe areas, no bounce
 * ================================================================ */
* { -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; }
body { overscroll-behavior: none; height: 100dvh; }
.sidebar, .mobile-tabs, .top-bar { -webkit-user-select: none; user-select: none; }
.page-content { -webkit-overflow-scrolling: touch; overscroll-behavior: contain; }
.mobile-tabs { display: none; }

@media (max-width: 768px) {
  .mobile-tabs {
    display: flex; position: fixed; left: 0; right: 0; bottom: 0; z-index: 200;
    background: rgba(255,255,255,.92);
    -webkit-backdrop-filter: saturate(1.6) blur(12px); backdrop-filter: saturate(1.6) blur(12px);
    border-top: 1px solid var(--border);
    height: calc(56px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mtab {
    flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px;
    background: none; border: none; cursor: pointer; color: var(--text-muted);
    font: inherit; font-size: 10px; font-weight: 500; letter-spacing: -.01em;
    padding: 9px 0 0; position: relative;
  }
  .mtab .licon { font-size: 20px; }
  .mtab.active { color: var(--text-primary); }
  .mtab:active { opacity: .55; }
  .mtab-badge {
    position: absolute; top: 5px; left: 50%; margin-left: 3px;
    min-width: 16px; height: 16px; padding: 0 4px; border-radius: 8px;
    background: var(--danger); color: #fff; font-size: 9.5px; font-weight: 600;
    display: flex; align-items: center; justify-content: center; line-height: 1;
  }
  .page-content { padding-bottom: calc(66px + env(safe-area-inset-bottom)) !important; }
  .menu-btn { display: none !important; }
  #sidebar.open ~ .mobile-tabs { display: none; }
  .sidebar { z-index: 250; box-shadow: var(--shadow-lg); height: 100dvh; padding-bottom: env(safe-area-inset-bottom); }
  .top-bar { padding-top: env(safe-area-inset-top); height: calc(var(--topbar-height) + env(safe-area-inset-top)); }
  input, textarea, select,
  .form-group input, .form-group select, .form-group textarea,
  .pg-foot input, .search-input input { font-size: 16px !important; }
  #cop-fab { bottom: calc(70px + env(safe-area-inset-bottom)) !important; }
}

/* ================================================================
 * Section switcher (CRM / Products / Orders / Accounting)
 * ================================================================ */
.top-bar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
/* Top-bar brand + breadcrumb (proposal layout) */
.tb-brand { display: inline-flex; align-items: center; gap: 8px; text-decoration: none; flex: none; }
.tb-logo { display: inline-flex; align-items: center; justify-content: center; width: 26px; height: 26px; border-radius: 7px; background: #0a0a0a; flex: none; }
.tb-logo svg { width: 16px; height: 16px; stroke: #fff; }
.tb-name { font-size: 15px; font-weight: 700; color: var(--text-primary); letter-spacing: -.01em; }
.tb-sep { color: var(--text-muted); font-size: 15px; flex: none; }
/* Top-bar wallet pill */
.tb-credits { display: inline-flex; align-items: center; gap: 7px; font: inherit; font-size: 12.5px; font-weight: 600; color: var(--text-primary); background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 999px; padding: 5px 11px; cursor: pointer; transition: background .15s, border-color .15s; }
.tb-credits:hover { background: var(--bg-card); border-color: var(--text-muted); }
.tb-credits .fa-wallet { font-size: 11px; color: var(--text-muted); }
.tb-cbar { width: 34px; height: 5px; border-radius: 999px; background: var(--border); overflow: hidden; }
.tb-cbar i { display: block; height: 100%; width: 0; background: var(--text-primary); border-radius: 999px; transition: width .4s; }
.tb-credits.tb-low { border-color: var(--danger); color: var(--danger); }
.tb-credits.tb-low .tb-cbar i { background: var(--danger); }
.tb-icon { color: var(--text-muted); }
.tb-icon:hover { color: var(--text-primary); }
.tb-avatar { width: 30px; height: 30px; border-radius: 50%; background: var(--primary); color: var(--bg-card); display: inline-flex; align-items: center; justify-content: center; font-size: 12.5px; font-weight: 700; flex: none; }
/* Section switcher — compact dropdown inside the top-bar actions cluster */
.section-dd { position: relative; }
.section-dd-btn { display: inline-flex; align-items: center; gap: 8px; font: inherit; font-size: 13px; font-weight: 600; color: var(--text-primary); background: var(--bg-card); border: 1px solid var(--border); border-radius: 9px; padding: 7px 13px; cursor: pointer; transition: background .15s, border-color .15s; }
.section-dd-btn:hover { background: var(--bg-secondary); }
.section-dd.open .section-dd-btn { border-color: var(--text-primary); }
.section-dd-caret { font-size: 10px; color: var(--text-muted); transition: transform .18s; }
.section-dd.open .section-dd-caret { transform: rotate(180deg); }
.section-dd-menu { position: absolute; top: calc(100% + 6px); left: 0; right: auto; min-width: 200px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 11px; box-shadow: var(--shadow-lg); padding: 6px; z-index: 60; opacity: 0; transform: translateY(-4px); pointer-events: none; transition: opacity .15s, transform .15s; }
.section-dd.open .section-dd-menu { opacity: 1; transform: translateY(0); pointer-events: auto; }
.section-dd-item { display: flex; align-items: center; gap: 10px; width: 100%; font: inherit; font-size: 13px; font-weight: 500; color: var(--text-secondary); background: none; border: none; border-radius: 7px; padding: 9px 10px; cursor: pointer; text-align: left; }
.section-dd-item > span { flex: 1; }
.section-dd-item > i:first-child { width: 16px; text-align: center; color: var(--text-muted); font-size: 13px; }
.section-dd-item:hover { background: var(--bg-secondary); color: var(--text-primary); }
.section-dd-check { opacity: 0; color: var(--text-primary); font-size: 12px; }
.section-dd-item.on { color: var(--text-primary); font-weight: 600; }
.section-dd-item.on > i:first-child { color: var(--text-primary); }
.section-dd-item.on .section-dd-check { opacity: 1; }
.top-bar h2.page-title-top { flex: 0 0 auto; font-size: 15px; font-weight: 600; color: var(--text-primary); }

.empty-hero { max-width: 440px; margin: 64px auto; text-align: center; display: flex; flex-direction: column; align-items: center; }
.empty-hero-ic { width: 56px; height: 56px; border-radius: 16px; background: var(--bg-secondary); border: 1px solid var(--border); display: flex; align-items: center; justify-content: center; font-size: 24px; color: var(--text-muted); margin-bottom: 16px; }
.empty-hero h2 { font-size: 20px; margin: 0 0 6px; }
.pill { display: inline-flex; align-items: center; font-size: 12px; font-weight: 600; padding: 4px 12px; border-radius: 999px; border: 1px solid var(--border); }
.pill-mut { color: var(--text-muted); background: var(--bg-secondary); }

/* Brand lives in the top bar now (proposal layout) → drop the sidebar logo on desktop */
@media (min-width: 769px) {
  .sidebar-header { display: none; }
  .sidebar-nav { padding-top: 14px; }
}
@media (max-width: 768px) {
  .page-title-top, .top-bar h2.page-title-top { display: none; }
  .tb-sep, .tb-name, .tb-credits, #tb-help { display: none; }
  .section-dd-btn { padding: 6px 11px; font-size: 12.5px; }
}

/* ================================================================
 * Accounting — single-entry cash book
 * ================================================================ */
.acc-wrap { display: flex; flex-direction: column; gap: 16px; }
.acc-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.acc-range { display: flex; align-items: center; gap: 8px; }
.acc-range input { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; font: inherit; font-size: 13px; background: var(--bg-input); color: var(--text-primary); }
.acc-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.acc-kpis { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; }
.acc-kpi { border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 18px; background: var(--bg-card); }
.acc-kpi-l { font-size: 12.5px; color: var(--text-muted); }
.acc-kpi-v { font-size: 24px; font-weight: 650; letter-spacing: -.02em; margin-top: 4px; font-variant-numeric: tabular-nums; }
.acc-kpi.acc-in .acc-kpi-v { color: #166534; }
.acc-kpi.acc-out .acc-kpi-v { color: #991b1b; }
.acc-kpi.acc-neutral .acc-kpi-v { color: var(--text-primary); }
.acc-cols { display: grid; grid-template-columns: 1fr 320px; gap: 16px; align-items: start; }
.acc-book { padding: 0; overflow: hidden; }
.acc-book-head { display: flex; align-items: baseline; justify-content: space-between; padding: 14px 18px; border-bottom: 1px solid var(--border); }
.acc-book-head h3, .acc-side h3 { font-size: 14px; font-weight: 600; margin: 0; }
.acc-side { padding: 18px; }
.acc-side h3 { margin-bottom: 12px; }
.acc-empty { padding: 40px; text-align: center; font-size: 13.5px; }
.acc-catrow { margin-bottom: 12px; }
.acc-catrow-top { display: flex; justify-content: space-between; font-size: 13px; margin-bottom: 5px; }
.acc-catrow-top b { font-variant-numeric: tabular-nums; }
.acc-catbar { height: 6px; background: var(--border-light); border-radius: 3px; overflow: hidden; }
.acc-catbar i { display: block; height: 100%; background: var(--primary); border-radius: 3px; }
@media (max-width: 900px) { .acc-cols { grid-template-columns: 1fr; } }

/* Accounting — cash-flow chart */
.acc-chartcard { padding: 16px 18px; }
.acc-chart-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.acc-chart-head h3 { font-size: 14px; font-weight: 600; margin: 0; }
.acc-bucket { display: inline-flex; gap: 2px; background: var(--bg-secondary); border: 1px solid var(--border); border-radius: 8px; padding: 2px; }
.acc-bucket button { border: none; background: none; font: inherit; font-size: 12px; font-weight: 500; color: var(--text-muted); padding: 5px 12px; border-radius: 6px; cursor: pointer; }
.acc-bucket button.on { background: var(--bg-card); color: var(--text-primary); box-shadow: var(--shadow-sm); }
.acc-chart-wrap { height: 230px; position: relative; }

/* Accounting — accounts card + manage modal */
.acc-rightcol { display: flex; flex-direction: column; gap: 16px; }
.acc-side-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.acc-side-head h3 { margin: 0; }
.acc-acctrow { display: flex; justify-content: space-between; align-items: baseline; padding: 8px 0; border-bottom: 1px solid var(--border-light); font-size: 13.5px; }
.acc-acctrow:last-child { border-bottom: none; }
.acc-acctrow b { font-variant-numeric: tabular-nums; }
.acc-mhead { display: grid; grid-template-columns: 1fr 130px 36px; gap: 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.acc-mrow { display: grid; grid-template-columns: 1fr 130px 36px; gap: 8px; align-items: center; margin-bottom: 8px; }
.acc-mrow input { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; font: inherit; font-size: 13.5px; background: var(--bg-input); color: var(--text-primary); width: 100%; }
.acc-mnew { grid-template-columns: 1fr 130px auto; margin-top: 6px; padding-top: 10px; border-top: 1px solid var(--border); }

/* Accounting — recurring + tax modals */
.acc-rrow { display: grid; grid-template-columns: auto 1fr auto auto auto; gap: 10px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--border-light); font-size: 13.5px; }
.acc-rrow:last-of-type { border-bottom: none; }
.acc-rdesc { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.acc-rrow b { font-variant-numeric: tabular-nums; }
.acc-rmonth { font-size: 11.5px; }
.acc-rnew { display: grid; grid-template-columns: 110px 1fr 1fr auto; gap: 8px; margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--border); }
.acc-rnew select, .acc-rnew input { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 10px; font: inherit; font-size: 13.5px; background: var(--bg-input); color: var(--text-primary); width: 100%; }
.acc-taxrow { display: flex; justify-content: space-between; align-items: baseline; padding: 9px 0; border-bottom: 1px solid var(--border-light); font-size: 14px; }
.acc-taxrow b { font-variant-numeric: tabular-nums; }
.acc-taxprofit { font-weight: 600; }
.acc-taxprofit b { color: #166534; }

/* Orders — source filter pills (match the status pill row) */
#ord-src-pills { margin: 4px 0 8px; }
.orders-src-pill { display: inline-flex; align-items: center; gap: 6px; padding: 6px 13px; margin: 0 6px 8px 0; border: 1px solid var(--border); border-radius: 999px; background: var(--bg-card); color: var(--text-secondary); font: inherit; font-size: 12.5px; font-weight: 500; cursor: pointer; transition: border-color .15s, background .15s, color .15s; }
.orders-src-pill:hover { border-color: var(--text-muted); color: var(--text-primary); }
.orders-src-pill.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.orders-src-pill .licon { font-size: 12px; }

/* Accounting — AI import review */
.ir-head, .ir-row { display: grid; grid-template-columns: 100px 130px 100px 1fr 1.4fr; gap: 8px; align-items: center; min-width: 620px; }
.ir-head { font-size: 11px; text-transform: uppercase; letter-spacing: .04em; margin-bottom: 6px; }
.ir-row { margin-bottom: 8px; }
.ir-row input, .ir-row select { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 7px 9px; font: inherit; font-size: 13px; background: var(--bg-input); color: var(--text-primary); width: 100%; }
.ir-warn input, .ir-warn select { border-color: var(--warning); }
.ir-q { font-size: 12px; color: var(--warning); margin: -3px 0 10px 4px; display: flex; gap: 6px; align-items: center; min-width: 620px; }
#ir-list { max-height: 46vh; overflow-y: auto; }

/* Widen the modal for the AI-import review (5-column grid needs room) */
.modal:has(#ir-list) { max-width: 780px; width: 94vw; }

/* Wallet top-up button (sidebar credits card) */
.topup-btn { margin-top: 9px; width: 100%; border: 1px solid var(--border); background: var(--bg-card); color: var(--text-primary); font: inherit; font-size: 12.5px; font-weight: 550; padding: 7px 10px; border-radius: var(--radius-sm); cursor: pointer; transition: background .15s; }
.topup-btn:hover { background: var(--bg-secondary); }

/* ================================================================
 * Polish pass — thin scrollbars, focus rings, playground flow
 * ================================================================ */
* { scrollbar-width: thin; scrollbar-color: #d4d4d8 transparent; }
::-webkit-scrollbar { width: 9px; height: 9px; }
::-webkit-scrollbar-thumb { background: #d4d4d8; border-radius: 999px; }
::-webkit-scrollbar-thumb:hover { background: #a1a1aa; }
::-webkit-scrollbar-track { background: transparent; }

/* Keyboard focus rings (visible only for keyboard nav) */
a:focus-visible, button:focus-visible, [tabindex]:focus-visible,
.nav-item:focus-visible, .section-dd-btn:focus-visible, .section-dd-item:focus-visible, .mtab:focus-visible, .filter-tab:focus-visible {
  outline: none; box-shadow: 0 0 0 2px var(--bg-card), 0 0 0 4px rgba(9,9,11,.30);
}
input:focus-visible, textarea:focus-visible, select:focus-visible { outline: none; }

/* Playground config: links flow under Save (no bottom gap) */
.pg-links { margin-top: 16px; }

/* Consistent modern empty-state icon (every empty table/section) */
.table-empty { padding: 52px 20px; }
.table-empty i, .empty-state i { font-size: 22px; width: 52px; height: 52px; border-radius: 14px; background: var(--bg-secondary); border: 1px solid var(--border); display: inline-flex; align-items: center; justify-content: center; margin-bottom: 14px; color: var(--text-muted); }

/* ===== Knowledge: training status bar ===== */
.kb-statusbar { display:flex; align-items:center; justify-content:space-between; gap:16px;
  padding:14px 16px; margin-bottom:16px; background:var(--bg-card); border:1px solid var(--border); border-radius:var(--radius); }
.kb-sb-main { display:flex; align-items:center; gap:12px; min-width:0; }
.kb-sb-dot { width:9px; height:9px; border-radius:999px; background:var(--text-muted); flex:none; }
.kb-sb-dot.ok { background:var(--success); box-shadow:0 0 0 3px var(--success-light); }
.kb-sb-dot.warn { background:var(--warning); box-shadow:0 0 0 3px var(--warning-light); }
.kb-sb-titlerow { display:flex; align-items:center; gap:8px; }
.kb-sb-titlerow b { font-size:14px; }
.kb-sb-text small { display:block; font-size:12px; margin-top:2px; }
.kb-sb-badge { display:inline-flex; align-items:center; font-size:11px; font-weight:600; padding:2px 8px; border-radius:999px;
  border:1px solid var(--border); color:var(--text-secondary); background:var(--bg-secondary); }
.kb-sb-badge.ok { color:var(--success); border-color:var(--success); background:var(--success-light); }
.kb-sb-badge.warn { color:var(--warning); border-color:var(--warning); background:var(--warning-light); }
.btn.pulse { animation: kbPulse 1.8s ease-in-out infinite; }
@keyframes kbPulse { 0%,100% { box-shadow:0 0 0 0 rgba(180,83,9,.0); } 50% { box-shadow:0 0 0 4px rgba(180,83,9,.18); } }

/* ===== Knowledge: training progress stepper (modal) ===== */
.kb-train-steps { display:flex; flex-direction:column; gap:2px; margin:4px 0 18px; }
.kb-train-step { display:flex; align-items:center; gap:12px; padding:9px 4px; color:var(--text-muted); font-size:14px;
  opacity:.55; transition:opacity .25s, color .25s; }
.kbt-ic { width:22px; height:22px; border-radius:999px; border:2px solid var(--border); flex:none; position:relative; box-sizing:border-box; transition:all .25s; }
.kb-train-step.active { opacity:1; color:var(--text-primary); }
.kb-train-step.active .kbt-ic { border-color:var(--text-primary); border-top-color:transparent; animation:kbtSpin .7s linear infinite; }
.kb-train-step.done { opacity:1; color:var(--text-secondary); }
.kb-train-step.done .kbt-ic { background:var(--success); border-color:var(--success); animation:none; }
.kb-train-step.done .kbt-ic::after { content:''; position:absolute; left:7px; top:3px; width:5px; height:9px; border:solid #fff; border-width:0 2px 2px 0; transform:rotate(45deg); }
@keyframes kbtSpin { to { transform:rotate(360deg); } }
.kb-train-bar { height:6px; background:var(--bg-secondary); border-radius:999px; overflow:hidden; }
.kb-train-fill { height:100%; width:0; background:var(--text-primary); border-radius:999px; transition:width .5s ease; }
.kb-train-msg { margin-top:14px; font-size:13px; }
.kb-train-msg.ok { color:var(--success); font-weight:600; }
.kb-train-msg.err { color:var(--danger); font-weight:600; }

/* ================================================================
 * Bare form controls — give un-classed selects/inputs the shadcn
 * bordered look (dispatch, issues/refunds filters, etc.). Keeps the
 * native caret; more-specific rules still win where they exist.
 * ================================================================ */
select { padding: 8px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm); background-color: var(--bg-input); color: var(--text-primary); font: inherit; font-size: 13.5px; cursor: pointer; height: 38px; }
input[type="checkbox"], input[type="radio"] { accent-color: var(--primary); cursor: pointer; }

/* ================================================================
 * Order-ops card system — shared by Issues / Refunds / Additional
 * Payments (these classes had NO CSS, so those pages rendered as raw
 * stacked text). One consistent card + status pill + KPI tile set.
 * ================================================================ */
.ref-summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.ref-summary-tile { background: var(--bg-card); border: 1px solid var(--border); border-left: 3px solid var(--text-muted); border-radius: var(--radius); padding: 16px 18px; }
.ref-summary-pending { border-left-color: var(--warning); }
.ref-summary-processed { border-left-color: var(--success); }
.ref-summary-failed { border-left-color: var(--danger); }
.rs-num { font-size: 24px; font-weight: 700; line-height: 1.1; color: var(--text-primary); }
.rs-lbl { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .05em; margin-top: 5px; }
.rs-amt { font-size: 13px; font-weight: 600; color: var(--text-secondary); margin-top: 7px; }

.iss-mgr-card { background: var(--bg-card); border: 1px solid var(--border); border-left: 3px solid var(--border); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 10px; }
.iss-mgr-card.iss-sev-warning, .iss-mgr-card.ref-status-pending { border-left-color: var(--warning); }
.iss-mgr-card.iss-sev-critical, .iss-mgr-card.ref-status-failed { border-left-color: var(--danger); }
.iss-mgr-card.iss-sev-info { border-left-color: var(--text-muted); }
.iss-mgr-card.ref-status-processed { border-left-color: var(--success); }
.iss-mgr-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.iss-mgr-type { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.iss-mgr-status { display: inline-flex; align-items: center; font-size: 11px; font-weight: 600; padding: 2px 9px; border-radius: 999px; text-transform: uppercase; letter-spacing: .03em; border: 1px solid var(--border); color: var(--text-secondary); background: var(--bg-secondary); }
.iss-mgr-status.open, .iss-mgr-status.ref-status-pending { color: var(--warning); border-color: var(--warning); background: var(--warning-light); }
.iss-mgr-status.resolved, .iss-mgr-status.ref-status-processed { color: var(--success); border-color: var(--success); background: var(--success-light); }
.iss-mgr-status.ref-status-failed { color: var(--danger); border-color: var(--danger); background: var(--danger-light); }
.iss-mgr-context { font-size: 13px; color: var(--text-secondary); margin-top: 8px; }
.iss-mgr-context a, .rep-link { color: var(--text-primary); text-decoration: none; font-weight: 600; }
.iss-mgr-context a:hover, .rep-link:hover { text-decoration: underline; }
.iss-mgr-message { font-size: 13px; color: var(--text-muted); margin-top: 6px; line-height: 1.5; }
.iss-mgr-resolved { font-size: 12px; margin-top: 8px; }
.iss-mgr-actions { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 12px; }
.iss-mgr-rep, .iss-mgr-replacement { font-size: 13px; color: var(--text-secondary); margin-top: 6px; }
.iss-mgr-rep-badge { display: inline-flex; align-items: center; font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px; background: var(--bg-secondary); border: 1px solid var(--border); color: var(--text-secondary); }

/* ================================================================
 * Users & permissions — role badges, status pills, permission grid
 * ================================================================ */
.role-badge { display: inline-flex; align-items: center; font-size: 11px; font-weight: 600; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--border); background: var(--bg-secondary); color: var(--text-secondary); }
.role-badge.role-tech_admin, .role-badge.role-superadmin { border-color: var(--text-primary); background: var(--text-primary); color: var(--bg-card); }
.role-badge.role-admin { border-color: var(--text-secondary); color: var(--text-primary); }
.status-pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12px; font-weight: 500; color: var(--text-secondary); }
.status-pill::before { content: ''; width: 7px; height: 7px; border-radius: 999px; background: var(--text-muted); }
.status-pill.is-on { color: var(--success); }
.status-pill.is-on::before { background: var(--success); }
.status-pill.is-off::before { background: var(--text-muted); }

.form-row { display: flex; gap: 14px; flex-wrap: wrap; }
.form-row > .form-group { min-width: 0; }
.perm-note { font-size: 12px; margin-bottom: 10px; }
.perm-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 10px; }
.perm-group { border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; background: var(--bg-secondary); }
.perm-group-title { font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: 8px; }
.perm-item { display: flex; align-items: center; gap: 8px; padding: 4px 0; font-size: 13px; color: var(--text-secondary); cursor: pointer; }
.perm-item input { width: auto; margin: 0; accent-color: var(--primary); cursor: pointer; }
.perm-item input:disabled { cursor: not-allowed; }
.perm-item:has(input:checked) { color: var(--text-primary); font-weight: 500; }

/* ================================================================
 * Content page header (proposal layout) — title + subtitle + actions
 * at the top of the main panel, above the page content.
 * ================================================================ */
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; padding: 22px 24px 0; }
.page-head.hidden { display: none; }
.page-head-title { font-size: 22px; font-weight: 700; letter-spacing: -.02em; color: var(--text-primary); margin: 0; line-height: 1.2; }
.page-head-sub { font-size: 13.5px; color: var(--text-muted); margin: 4px 0 0; line-height: 1.5; }
.page-head-sub:empty { display: none; }
.page-head-actions { display: flex; align-items: center; gap: 8px; flex: none; }
.page-head-actions:empty { display: none; }
/* the page content already pads 24px, so trim its top when a header sits above */
.page-head + .page-content { padding-top: 18px; }
@media (max-width: 768px) {
  .page-head { padding: 16px 12px 0; }
  .page-head-title { font-size: 19px; }
  .page-head + .page-content { padding-top: 12px; }
}

/* ================================================================
 * Fidelity pass — match the proposal's type + icon scale/quality.
 * Icons were 1em @ stroke 2 (small + heavy); proposal uses ~17-18px
 * @ 1.75. Also crisper type (font-smoothing + tighter tracking).
 * ================================================================ */
body { -webkit-font-smoothing: antialiased; -moz-osx-font-smoothing: grayscale; letter-spacing: -0.01em; }
/* All line-icons: a touch larger + a finer, more refined stroke */
.licon > svg, i.licon svg { width: 1.18em; height: 1.18em; stroke-width: 1.75; }
/* Sidebar nav: more generous size + 18px icons (proposal feel) */
.nav-item { font-size: 15px; padding: 11px 13px; gap: 11px; }
.nav-group-header { font-size: 15px; }
.nav-item .licon, .nav-group-header .licon { width: 22px; }
.nav-item .licon svg, .nav-group-header .licon svg { width: 18px; height: 18px; }
.nav-item i, .nav-group-header > i:first-child { width: 22px; font-size: 16px; }
.nav-sub { font-size: 14px; }
/* Content page header a touch bigger, like the proposal */
.page-head-title { font-size: 23px; }
.page-head-sub { font-size: 14px; }
/* Top-bar controls scale up slightly for balance */
.section-dd-btn { font-size: 13.5px; padding: 8px 14px; }
.tb-credits { font-size: 13px; }
.tb-icon svg { width: 18px; height: 18px; }

/* Full-width top bar layout: sidebar fills the body row (not 100vh) on desktop */
@media (min-width: 769px) {
  .sidebar { height: auto; }
}

/* ================================================================
 * Top-bar account menu (avatar dropdown) + My Profile page
 * ================================================================ */
.tb-user { position: relative; }
.tb-avatar { border: none; cursor: pointer; padding: 0; font-family: inherit; }
.tb-user-menu { position: absolute; top: calc(100% + 8px); right: 0; min-width: 236px; background: var(--bg-card); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg); padding: 8px; z-index: 70; opacity: 0; transform: translateY(-4px); pointer-events: none; transition: opacity .15s, transform .15s; }
.tb-user.open .tb-user-menu { opacity: 1; transform: translateY(0); pointer-events: auto; }
.tb-user-head { display: flex; align-items: center; gap: 10px; padding: 6px 8px 12px; border-bottom: 1px solid var(--border); margin-bottom: 8px; }
.tb-user-av { width: 38px; height: 38px; border-radius: 50%; background: var(--primary); color: var(--bg-card); display: inline-flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 700; flex: none; }
.tb-user-name { font-size: 14px; font-weight: 600; color: var(--text-primary); }
.tb-user-role { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 1px; }
.tb-user-note { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); padding: 2px 8px 6px; }
.tb-user-select { width: 100%; margin-bottom: 4px; }
.tb-user-div { height: 1px; background: var(--border); margin: 8px 4px; }
.tb-user-item { display: flex; align-items: center; gap: 10px; width: 100%; font: inherit; font-size: 13.5px; color: var(--text-secondary); background: none; border: none; border-radius: 8px; padding: 9px 10px; cursor: pointer; text-align: left; }
.tb-user-item i { width: 16px; text-align: center; color: var(--text-muted); }
.tb-user-item:hover { background: var(--bg-secondary); color: var(--text-primary); }
.tb-user-item.danger { color: var(--danger); }
.tb-user-item.danger i { color: var(--danger); }

.prof-wrap { max-width: 560px; display: flex; flex-direction: column; gap: 16px; }
.prof-card { background: var(--bg-card); border: 1px solid var(--border); border-radius: var(--radius); padding: 20px; }
.prof-card h3 { margin: 0 0 4px; font-size: 15px; }
.prof-head { display: flex; align-items: center; gap: 14px; margin-bottom: 12px; }
.prof-av { width: 52px; height: 52px; border-radius: 50%; background: var(--primary); color: var(--bg-card); display: inline-flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 700; flex: none; }
.prof-name { font-size: 18px; font-weight: 700; margin-bottom: 4px; }
.prof-rows { display: flex; flex-direction: column; }
.prof-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 11px 0; border-top: 1px solid var(--border); font-size: 13.5px; }
.prof-row span { color: var(--text-muted); }
.prof-row b { color: var(--text-primary); font-weight: 600; word-break: break-word; text-align: right; }
.prof-select { width: 100%; }
