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

:root {
  --bg: #f5f5f3;
  --surface: #ffffff;
  --surface2: #f0f0ee;
  --surface3: #e8e8e5;
  --sidebar-w: 232px;
  --sidebar-w-collapsed: 64px;
  --sidebar: #0c1e38;
  --sidebar-deep: #08152a;
  --sidebar-text: #c8d8ec;
  --sidebar-muted: #5d7a9a;
  --sidebar-hover: rgba(255,255,255,0.06);
  --sidebar-active: rgba(255,255,255,0.1);
  --sidebar-line: rgba(255,255,255,0.07);
  --text: #111827;
  --text-secondary: #6b7280;
  --text-tertiary: #9ca3af;
  --border: #e5e7eb;
  --accent: #2563eb;
  --accent-light: #dbeafe;
  --accent-hover: #1d4ed8;
  --success: #059669;
  --success-light: #d1fae5;
  --warning: #d97706;
  --warning-light: #fef3c7;
  --danger: #dc2626;
  --danger-light: #fee2e2;
  --purple: #7c3aed;
  --purple-light: #ede9fe;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
  --shadow: 0 1px 4px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.07), 0 1px 4px rgba(0,0,0,0.04);
}

[data-dark="true"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface2: #1c2230;
  --surface3: #232b3b;
  --sidebar: #070c15;
  --sidebar-deep: #040810;
  --sidebar-muted: #4a6278;
  --text: #e6edf3;
  --text-secondary: #8b949e;
  --text-tertiary: #5a6672;
  --border: #2d3748;
  --accent-light: #1a3260;
  --success-light: #064e3b;
  --warning-light: #451a03;
  --danger-light: #450a0a;
  --purple-light: #2d1b6b;
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2);
  --shadow: 0 1px 4px rgba(0,0,0,0.3);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.4);
}

[data-accent="indigo"] { --accent: #6366f1; --accent-hover: #4f46e5; }
[data-accent="teal"]   { --accent: #0d9488; --accent-hover: #0f766e; }
[data-accent="blue"]   { --accent: #2563eb; --accent-hover: #1d4ed8; }

html, body { height: 100%; font-family: 'DM Sans', sans-serif; background: var(--bg); color: var(--text); }
body { -webkit-font-smoothing: antialiased; }
button { font-family: inherit; cursor: pointer; }
a { color: inherit; text-decoration: none; }
* { transition: background-color 0.15s, border-color 0.15s, color 0.15s; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 10px; }

/* === Utility classes === */
.btn-primary {
  background: var(--accent); color: #fff; border: none;
  border-radius: var(--radius-sm); padding: 8px 16px;
  font-size: 0.875rem; font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.15s;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost {
  background: transparent; border: 1px solid var(--border);
  color: var(--text-secondary); border-radius: var(--radius-sm);
  padding: 7px 14px; font-size: 0.875rem; font-weight: 500;
  cursor: pointer; display: inline-flex; align-items: center; gap: 6px;
  transition: background 0.15s, color 0.15s;
}
.btn-ghost:hover { background: var(--surface2); color: var(--text); }
.btn-danger {
  background: var(--danger); color: #fff; border: none;
  border-radius: var(--radius-sm); padding: 8px 16px;
  font-size: 0.875rem; font-weight: 600; cursor: pointer;
}
.card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); box-shadow: var(--shadow);
}

/* === Shell Layout === */
.bb-sidebar {
  position: fixed; top: 0; left: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--sidebar);
  border-right: 1px solid var(--sidebar-line);
  display: flex; flex-direction: column;
  transition: width 0.2s ease;
  overflow: hidden;
  z-index: 100;
}
.bb-sidebar.collapsed { width: var(--sidebar-w-collapsed); }

.bb-main {
  margin-left: var(--sidebar-w);
  min-height: 100vh;
  display: flex; flex-direction: column;
  transition: margin-left 0.2s ease;
  background: var(--bg);
}
.bb-main.collapsed { margin-left: var(--sidebar-w-collapsed); }

.bb-sidebar-logo {
  padding: 20px;
  border-bottom: 1px solid var(--sidebar-line);
  display: flex; align-items: center; gap: 10px;
  overflow: hidden; white-space: nowrap; flex-shrink: 0;
  text-decoration: none;
}
.bb-sidebar-logo-text {
  font-weight: 700; font-size: 1.0625rem; letter-spacing: -0.02em;
  color: #fff; transition: opacity 0.15s, width 0.2s;
}
.bb-sidebar.collapsed .bb-sidebar-logo-text { opacity: 0; width: 0; }

.bb-sidebar-nav { flex: 1; padding: 4px 8px; overflow-y: auto; overflow-x: hidden; }
.bb-sidebar-bottom { padding: 4px 8px; border-top: 1px solid var(--sidebar-line); flex-shrink: 0; }

.bb-nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 8px; margin-bottom: 2px;
  color: var(--sidebar-muted);
  font-size: 0.875rem; font-weight: 400;
  white-space: nowrap; overflow: hidden;
  transition: background 0.15s, color 0.15s;
  text-decoration: none;
}
.bb-nav-item:hover { background: var(--sidebar-hover); color: var(--sidebar-text); }
.bb-nav-item.active { background: var(--sidebar-active); color: #fff; font-weight: 600; }
.bb-sidebar.collapsed .bb-nav-item { padding: 9px 0; justify-content: center; }
.bb-sidebar.collapsed .bb-nav-label { display: none; }
.bb-sidebar.collapsed .bb-nav-badge { display: none; }

.bb-nav-badge {
  font-size: 0.68rem; font-weight: 700; margin-left: auto;
  background: rgba(255,255,255,0.1); color: var(--sidebar-text);
  padding: 1px 6px; border-radius: 20px; flex-shrink: 0;
}
.bb-nav-icon { flex-shrink: 0; display: flex; }

.bb-topbar {
  height: 56px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; padding: 0 24px; gap: 16px;
  position: sticky; top: 0; z-index: 50; flex-shrink: 0;
}
.bb-topbar-title { font-size: 0.9375rem; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; }

.bb-topbar-search { flex: 1; max-width: 320px; position: relative; }
.bb-topbar-search input {
  width: 100%; padding: 7px 12px 7px 32px; font-size: 0.875rem;
  background: var(--surface2); border: 1.5px solid transparent;
  border-radius: 8px; color: var(--text); outline: none; font-family: inherit;
  transition: border-color 0.15s;
}
.bb-topbar-search input:focus { border-color: var(--accent); }
.bb-topbar-search-icon {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-tertiary); pointer-events: none; display: flex;
}
.bb-topbar-spacer { flex: 1; }
.bb-topbar-actions { display: flex; align-items: center; gap: 8px; }

.bb-icon-btn {
  position: relative; background: none; border: none;
  color: var(--text-secondary); cursor: pointer; padding: 6px;
  border-radius: 6px; display: flex; align-items: center;
  transition: background 0.15s;
}
.bb-icon-btn:hover { background: var(--surface2); }

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

.bb-plan-widget {
  margin: 10px 8px 12px; padding: 12px;
  background: rgba(255,255,255,0.04); border-radius: 8px;
}
.bb-sidebar.collapsed .bb-plan-widget { display: none; }

.bb-user-widget {
  display: flex; align-items: center; gap: 10px;
  padding: 10px; border-radius: 8px; cursor: pointer;
  transition: background 0.15s; text-decoration: none;
}
.bb-user-widget:hover { background: var(--sidebar-hover); }
.bb-sidebar.collapsed .bb-user-widget { justify-content: center; padding: 10px 0; }
.bb-sidebar.collapsed .bb-user-info { display: none; }

.bb-user-avatar {
  width: 28px; height: 28px; border-radius: 50%;
  background: #1d4ed8; display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 700; color: #fff; flex-shrink: 0;
}

/* === Notifications badge === */
.bb-notif-badge {
  position: absolute; top: 2px; right: 2px;
  width: 16px; height: 16px; background: var(--danger); border-radius: 50%;
  font-size: 0.6rem; font-weight: 700; color: #fff;
  display: flex; align-items: center; justify-content: center;
  border: 2px solid var(--surface);
}

/* === Help bot === */
.bb-helpbot-window {
  position: fixed; bottom: 88px; right: 24px; width: 360px; height: 480px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 16px;
  box-shadow: var(--shadow-md); display: flex; flex-direction: column;
  overflow: hidden; z-index: 200;
}
.bb-helpbot-btn {
  position: fixed; bottom: 24px; right: 24px;
  width: 52px; height: 52px; border-radius: 50%;
  background: var(--accent); border: none; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 4px 20px rgba(37,99,235,0.4); z-index: 200;
  transition: transform 0.15s;
}
.bb-helpbot-btn:hover { transform: scale(1.08); }

/* === Animations === */
@keyframes bb-bounce { 0%,60%,100%{transform:translateY(0)} 30%{transform:translateY(-6px)} }
@keyframes bb-fadein { from { opacity:0; transform:translateY(8px); } to { opacity:1; transform:translateY(0); } }
.bb-fadein { animation: bb-fadein 0.2s ease-out; }

/* === Slideout panel === */
.bb-slideout-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.4);
  z-index: 300; opacity: 0; pointer-events: none; transition: opacity 0.2s;
}
.bb-slideout-overlay.open { opacity: 1; pointer-events: all; }
.bb-slideout {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 440px; background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-md); z-index: 301; overflow-y: auto;
  transform: translateX(100%); transition: transform 0.25s ease;
}
.bb-slideout.open { transform: translateX(0); }

/* === Modal === */
.bb-modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,0.5);
  z-index: 400; display: none; align-items: center; justify-content: center;
}
.bb-modal-overlay.open { display: flex; }
.bb-modal {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow-md); width: 100%; max-height: 90vh; overflow-y: auto;
}

/* === Form elements === */
.bb-input {
  width: 100%; padding: 9px 12px; font-size: 0.875rem;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 8px; outline: none; font-family: inherit; color: var(--text);
  transition: border-color 0.15s;
}
.bb-input:focus { border-color: var(--accent); }

.bb-select {
  width: 100%; padding: 9px 12px; font-size: 0.875rem;
  background: var(--surface); border: 1.5px solid var(--border);
  border-radius: 8px; outline: none; font-family: inherit; color: var(--text);
  cursor: pointer; transition: border-color 0.15s;
}
.bb-select:focus { border-color: var(--accent); }

.bb-label {
  display: block; font-size: 0.82rem; font-weight: 500;
  margin-bottom: 6px; color: var(--text);
}

/* === Tabs === */
.bb-tabs {
  display: flex; gap: 2px; background: var(--surface2);
  padding: 3px; border-radius: 8px; border: 1px solid var(--border);
}
.bb-tab {
  padding: 5px 14px; border-radius: 5px; border: none;
  background: transparent; color: var(--text-secondary);
  font-size: 0.82rem; font-weight: 500; cursor: pointer;
  font-family: inherit; transition: background 0.15s, color 0.15s;
}
.bb-tab.active {
  background: var(--accent); color: #fff;
}

/* === Filter chips === */
.bb-chip {
  padding: 5px 12px; border-radius: 20px; border: 1px solid var(--border);
  background: var(--surface); color: var(--text-secondary);
  font-size: 0.8rem; font-weight: 500; cursor: pointer; font-family: inherit;
  transition: all 0.15s;
}
.bb-chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }
.bb-chip:hover:not(.active) { background: var(--surface2); }

/* === Status badges === */
.bb-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px; border-radius: 20px; font-size: 0.72rem; font-weight: 600;
}
.bb-badge-success { background: var(--success-light); color: var(--success); }
.bb-badge-warning { background: var(--warning-light); color: var(--warning); }
.bb-badge-danger  { background: var(--danger-light);  color: var(--danger);  }
.bb-badge-accent  { background: var(--accent-light);  color: var(--accent);  }
.bb-badge-purple  { background: var(--purple-light);  color: var(--purple);  }
.bb-badge-muted   { background: var(--surface2);      color: var(--text-secondary); }

/* === Progress bar === */
.bb-progress { height: 5px; background: var(--surface2); border-radius: 4px; overflow: hidden; }
.bb-progress-bar { height: 100%; border-radius: 4px; transition: width 0.3s; }

/* === Table === */
.bb-table { width: 100%; border-collapse: collapse; font-size: 0.875rem; }
.bb-table th {
  padding: 9px 20px; text-align: left; font-weight: 600;
  font-size: 0.72rem; color: var(--text-secondary);
  text-transform: uppercase; letter-spacing: 0.04em;
  background: var(--surface2);
}
.bb-table td { padding: 11px 20px; border-bottom: 1px solid var(--border); }
.bb-table tr:last-child td { border-bottom: none; }
.bb-table tbody tr { transition: background 0.1s; }
.bb-table tbody tr:hover { background: var(--surface2); }

/* === Toast === */
.bb-toast {
  display: flex; align-items: center; gap: 10px;
  padding: 12px 16px; border-radius: var(--radius-sm);
  background: var(--surface); border: 1px solid var(--border);
  box-shadow: var(--shadow-md); font-size: 0.875rem;
  animation: bb-fadein 0.2s ease-out;
}

/* Mobile sidebar overlay */
.bb-sidebar-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,0.5); z-index: 99;
}
@media (max-width: 768px) {
  .bb-sidebar { transform: translateX(-100%); transition: transform 0.2s, width 0.2s; width: var(--sidebar-w) !important; }
  .bb-sidebar.mobile-open { transform: translateX(0); }
  .bb-sidebar-overlay.open { display: block; }
  .bb-main { margin-left: 0 !important; }
}
