/* ═══════════════════════════════════════ RESET & BASE */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f1117;
  --bg2:       #161b27;
  --bg3:       #1e2535;
  --border:    #2a3347;
  --accent:    #4f8ef7;
  --accent2:   #6366f1;
  --green:     #22c55e;
  --yellow:    #f59e0b;
  --red:       #ef4444;
  --purple:    #a855f7;
  --text:      #e2e8f0;
  --muted:     #64748b;
  --sidebar-w: 240px;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  display: flex;
  min-height: 100vh;
  font-size: 14px;
}

/* ═══════════════════════════════════════ SIDEBAR */
.sidebar {
  width: var(--sidebar-w);
  background: var(--bg2);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 100;
  transition: transform .25s ease;
}

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

.brand-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: #fff;
}

.brand-text {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.3px;
}

.sidebar-nav {
  flex: 1;
  padding: 16px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 500;
  transition: all .15s;
}

.nav-item:hover { background: var(--bg3); color: var(--text); }
.nav-item.active { background: rgba(79,142,247,.15); color: var(--accent); }
.nav-item.active i { color: var(--accent); }
.nav-item i { width: 18px; text-align: center; font-size: 15px; }

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

.server-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--muted);
}

.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--muted);
  flex-shrink: 0;
}
.status-dot.online  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.offline { background: var(--red);   box-shadow: 0 0 6px var(--red); }

/* ═══════════════════════════════════════ MAIN */
.main-wrapper {
  margin-left: var(--sidebar-w);
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

.topbar {
  height: 60px;
  background: var(--bg2);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 24px;
  gap: 16px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.topbar-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
}

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

.company-switcher {
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 8px;
}
.company-switcher select {
  background: transparent;
  border: none;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  outline: none;
  cursor: pointer;
  padding: 0;
}

.menu-toggle {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 18px;
  cursor: pointer;
  display: none;
}

.content {
  padding: 28px;
  flex: 1;
}

/* ═══════════════════════════════════════ STAT CARDS */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 28px;
}

.stat-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: border-color .2s;
}

.stat-card:hover { border-color: var(--accent); }

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

.stat-value {
  font-size: 30px;
  font-weight: 700;
  color: var(--text);
  line-height: 1;
}

.stat-icon {
  width: 38px; height: 38px;
  border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 16px;
  margin-bottom: 4px;
}

.stat-icon.blue   { background: rgba(79,142,247,.15);  color: var(--accent); }
.stat-icon.green  { background: rgba(34,197,94,.15);   color: var(--green); }
.stat-icon.yellow { background: rgba(245,158,11,.15);  color: var(--yellow); }
.stat-icon.purple { background: rgba(168,85,247,.15);  color: var(--purple); }
.stat-icon.red    { background: rgba(239,68,68,.15);   color: var(--red); }

/* ═══════════════════════════════════════ CARDS / PANELS */
.card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  margin-bottom: 20px;
  overflow: hidden;
}

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

.card-header-left { display: flex; align-items: center; gap: 10px; }
.card-header-actions { display: flex; gap: 8px; }

.card-body { padding: 20px; }

/* ═══════════════════════════════════════ TABLE */
.table-wrap { overflow-x: auto; }

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

thead tr {
  background: var(--bg3);
  border-bottom: 1px solid var(--border);
}

th {
  padding: 11px 14px;
  text-align: left;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .5px;
  color: var(--muted);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: background .12s;
}

tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg3); }

td {
  padding: 12px 14px;
  vertical-align: middle;
  color: var(--text);
}

.empty-row td {
  text-align: center;
  padding: 40px;
  color: var(--muted);
}

/* ═══════════════════════════════════════ BADGES */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  white-space: nowrap;
}

.badge-blue    { background: rgba(79,142,247,.15);  color: #7eb3ff; }
.badge-green   { background: rgba(34,197,94,.15);   color: #4ade80; }
.badge-yellow  { background: rgba(245,158,11,.15);  color: #fbbf24; }
.badge-red     { background: rgba(239,68,68,.15);   color: #f87171; }
.badge-purple  { background: rgba(168,85,247,.15);  color: #c084fc; }
.badge-gray    { background: rgba(100,116,139,.15); color: #94a3b8; }
.badge-orange  { background: rgba(249,115,22,.15);  color: #fb923c; }

/* ═══════════════════════════════════════ SCORE BAR */
.score-wrap { display: flex; align-items: center; gap: 8px; }

.score-bar {
  width: 70px; height: 6px;
  background: var(--bg3);
  border-radius: 10px;
  overflow: hidden;
}

.score-fill {
  height: 100%;
  border-radius: 10px;
  background: linear-gradient(90deg, var(--accent), var(--accent2));
}

/* ═══════════════════════════════════════ BUTTONS */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: all .15s;
  white-space: nowrap;
}

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

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

.btn-success  { background: var(--green);   color: #fff; }
.btn-success:hover:not(:disabled) { background: #16a34a; }

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

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

.btn-outline {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.btn-outline:hover:not(:disabled) { background: var(--bg3); border-color: var(--accent); color: var(--accent); }

.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-xs { padding: 3px 9px;  font-size: 11px; }
.btn-icon { padding: 6px 10px; }

/* ═══════════════════════════════════════ FORMS / FILTERS */
.filters-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 16px;
  align-items: center;
}

.filter-group { display: flex; align-items: center; gap: 6px; }

input[type="text"], input[type="search"], select {
  background: var(--bg3);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 8px;
  padding: 7px 12px;
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
  font-family: inherit;
}

input[type="text"]:focus,
input[type="search"]:focus,
select:focus { border-color: var(--accent); }

select option { background: var(--bg3); }

label { font-size: 12px; color: var(--muted); font-weight: 500; }

/* ═══════════════════════════════════════ ADMIN ACTION CARDS */
.action-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.action-card {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  transition: border-color .2s;
}

.action-card:hover { border-color: var(--accent); }

.action-icon {
  width: 48px; height: 48px;
  border-radius: 12px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px;
}

.action-title { font-size: 15px; font-weight: 600; }
.action-desc  { font-size: 12px; color: var(--muted); line-height: 1.5; }

/* ═══════════════════════════════════════ MINI CHARTS */
.chart-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 12px;
  margin-bottom: 20px;
}

.mini-donut {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 16px;
  text-align: center;
}

.donut-label { font-size: 11px; color: var(--muted); margin-top: 8px; }
.donut-value { font-size: 22px; font-weight: 700; }

/* ═══════════════════════════════════════ LOG OUTPUT */
.log-box {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 16px;
  font-family: 'Courier New', monospace;
  font-size: 12px;
  line-height: 1.6;
  max-height: 300px;
  overflow-y: auto;
  color: #a3e635;
}

.log-box .log-line { margin-bottom: 2px; }
.log-box .log-ok   { color: #4ade80; }
.log-box .log-warn { color: #fbbf24; }
.log-box .log-err  { color: #f87171; }
.log-box .log-info { color: #7eb3ff; }

/* ═══════════════════════════════════════ PROGRESS */
.progress-wrap { margin: 6px 0; }
.progress-label { font-size: 11px; color: var(--muted); margin-bottom: 4px; display: flex; justify-content: space-between; }
.progress-bar { height: 6px; background: var(--bg3); border-radius: 10px; overflow: hidden; }
.progress-fill { height: 100%; border-radius: 10px; transition: width .6s ease; }
.fill-blue   { background: linear-gradient(90deg, var(--accent), #7eb3ff); }
.fill-green  { background: linear-gradient(90deg, #16a34a, var(--green)); }
.fill-yellow { background: linear-gradient(90deg, #d97706, var(--yellow)); }
.fill-red    { background: linear-gradient(90deg, #dc2626, var(--red)); }
.fill-purple { background: linear-gradient(90deg, #9333ea, var(--purple)); }

/* ═══════════════════════════════════════ PAGE HEADER */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 12px;
}

.page-header h1 { font-size: 22px; font-weight: 700; }
.page-header p  { font-size: 13px; color: var(--muted); margin-top: 2px; }

/* ═══════════════════════════════════════ MODAL */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.7);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
  backdrop-filter: blur(3px);
}

.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: 90%;
  max-width: 640px;
  max-height: 80vh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  animation: modalIn .2s ease;
}

@keyframes modalIn {
  from { transform: scale(.95); opacity: 0; }
  to   { transform: scale(1);   opacity: 1; }
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 18px 22px;
  border-bottom: 1px solid var(--border);
  font-weight: 700;
  font-size: 15px;
}

.modal-header button {
  background: none; border: none; color: var(--muted); cursor: pointer; font-size: 18px;
}

.modal-header button:hover { color: var(--text); }

.modal-body {
  padding: 22px;
  overflow-y: auto;
}

/* ═══════════════════════════════════════ TOAST */
#toastContainer {
  position: fixed;
  bottom: 24px; right: 24px;
  z-index: 300;
  display: flex; flex-direction: column; gap: 8px;
}

.toast {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 12px 18px;
  font-size: 13px;
  font-weight: 500;
  max-width: 340px;
  display: flex; align-items: center; gap: 10px;
  animation: toastIn .25s ease;
  box-shadow: 0 8px 32px rgba(0,0,0,.4);
}

.toast.success { border-left: 3px solid var(--green); }
.toast.error   { border-left: 3px solid var(--red); }
.toast.info    { border-left: 3px solid var(--accent); }

@keyframes toastIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ═══════════════════════════════════════ DETAIL ROWS */
.detail-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.detail-row:last-child { border-bottom: none; }
.detail-key   { color: var(--muted); font-weight: 500; }
.detail-value { font-weight: 600; text-align: right; }

/* ═══════════════════════════════════════ SPINNER */
.spinner {
  display: inline-block;
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}

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

.loading-overlay {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 60px; gap: 14px; color: var(--muted);
}

.big-spinner {
  width: 40px; height: 40px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}

/* ═══════════════════════════════════════ AVATAR */
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  display: inline-flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; color: #fff; flex-shrink: 0;
}

/* ═══════════════════════════════════════ LEAD ROW */
.lead-cell-main { display: flex; align-items: center; gap: 10px; }
.lead-info strong { display: block; font-weight: 600; font-size: 13px; }
.lead-info small  { font-size: 11px; color: var(--muted); }

/* ═══════════════════════════════════════ RESPONSIVE */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }
  .main-wrapper { margin-left: 0; }
  .menu-toggle { display: flex; }
  .content { padding: 16px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

/* ═══════════════════════════════════════════════════════ USER MENU */
.user-menu { position: relative; }
.user-menu-btn {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg2); border: 1px solid var(--border);
  padding: 5px 10px; border-radius: 8px; cursor: pointer; color: var(--text);
  transition: background .15s;
}
.user-menu-btn:hover { background: var(--bg3); }
.user-avatar {
  width: 26px; height: 26px; border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #8b5cf6);
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 12px;
}
.user-name { font-size: 13px; font-weight: 600; max-width: 110px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-menu-dropdown {
  position: absolute; top: calc(100% + 6px); right: 0;
  background: var(--bg2); border: 1px solid var(--border);
  border-radius: 10px; min-width: 220px;
  box-shadow: 0 10px 30px rgba(0,0,0,.4);
  display: none; z-index: 100;
}
.user-menu-dropdown.open { display: block; }
.user-menu-header { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.user-menu-item {
  display: flex; align-items: center; gap: 10px;
  width: 100%; background: transparent; border: none;
  padding: 10px 14px; color: var(--text); font-size: 13px;
  cursor: pointer; text-align: left;
}
.user-menu-item:hover { background: var(--bg3); }
.user-menu-item:last-child { border-radius: 0 0 10px 10px; }
