/* ==========================================================================
   TREELIFE AI — INTERNAL ADMIN PANEL STYLES
   /crm — Employee access management, cost auditor, approvals
   ========================================================================== */

:root {
  /* Sidebar */
  --bg-sidebar: #0d1117;
  --bg-sidebar-hover: #1c2333;
  --bg-sidebar-active: #1f6feb22;
  --sidebar-active-border: #1f6feb;

  /* Main canvas */
  --bg-canvas: #f6f8fa;
  --bg-white: #ffffff;
  --bg-card: #ffffff;

  /* Text */
  --text-color: #1c2128;
  --text-muted: #57606a;
  --text-light: #8b949e;
  --text-sidebar: #c9d1d9;
  --text-sidebar-muted: #8b949e;

  /* Accent */
  --accent-color: #1f6feb;
  --accent-hover: #388bfd;
  --accent-light: rgba(31, 111, 235, 0.1);

  /* Status colors */
  --success-color: #238636;
  --success-light: rgba(35, 134, 54, 0.1);
  --danger-color: #da3633;
  --danger-light: rgba(218, 54, 51, 0.1);
  --warning-color: #9e6a03;
  --warning-bg: #fff8c5;
  --orange-color: #e3b341;

  /* Borders */
  --border-color: #d0d7de;
  --border-light: #f0f2f5;

  /* Shadows */
  --shadow-sm: 0 1px 3px rgba(0,0,0,0.06), 0 1px 2px rgba(0,0,0,0.04);
  --shadow-md: 0 4px 12px rgba(0,0,0,0.08), 0 2px 6px rgba(0,0,0,0.04);
  --shadow-card: 0 0 0 1px var(--border-color);

  /* Transition */
  --transition: all 0.18s cubic-bezier(0.4, 0, 0.2, 1);

  /* Fonts */
  --font-sans: 'Inter', -apple-system, sans-serif;
  --font-title: 'Outfit', sans-serif;
  --font-mono: 'Fira Code', 'Courier New', monospace;
}

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

body {
  font-family: var(--font-sans);
  background: var(--bg-canvas);
  color: var(--text-color);
  font-size: 13px;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
}

input, button, select, textarea {
  font-family: inherit;
  outline: none;
}

.hidden { display: none !important; }

/* ===== LAYOUT ===== */
.crm-layout {
  display: flex;
  width: 100vw;
  height: 100vh;
}

/* ===== SIDEBAR ===== */
.crm-sidebar {
  width: 240px;
  background: var(--bg-sidebar);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  border-right: 1px solid rgba(255,255,255,0.06);
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 20px 18px;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  margin-bottom: 8px;
}

.brand-logo {
  width: 34px;
  height: 34px;
  background: var(--accent-color);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 13px;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 0 12px rgba(31,111,235,0.4);
}

.brand-text {
  display: flex;
  flex-direction: column;
  gap: 1px;
  overflow: hidden;
}

.brand-title {
  font-weight: 600;
  font-size: 13px;
  color: #e6edf3;
  white-space: nowrap;
}

.brand-subtitle {
  font-size: 10px;
  color: var(--text-sidebar-muted);
  white-space: nowrap;
}

/* Nav */
.sidebar-nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 0 10px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 8px;
  width: 100%;
  padding: 9px 10px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-sidebar-muted);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
  position: relative;
}

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

.nav-item.active {
  background: var(--bg-sidebar-active);
  color: #58a6ff;
  border-left: 2px solid var(--sidebar-active-border);
  padding-left: 8px;
}

.nav-icon {
  font-size: 14px;
  flex-shrink: 0;
  width: 18px;
  text-align: center;
}

.badge-count {
  margin-left: auto;
  background: var(--danger-color);
  color: white;
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 10px;
}

.sidebar-footer {
  padding: 10px;
  border-top: 1px solid rgba(255,255,255,0.06);
}

.btn-signout {
  color: var(--text-sidebar-muted) !important;
}

/* ===== MAIN AREA ===== */
.crm-main {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* Header */
.crm-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  height: 54px;
  background: var(--bg-white);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

.header-breadcrumbs {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-color);
}

.breadcrumb-separator {
  color: var(--border-color);
}

.breadcrumb-sub {
  font-weight: 400;
  color: var(--text-muted);
  font-size: 12px;
}

.header-actions {
  display: flex;
  align-items: center;
  gap: 16px;
}

.notification-bell {
  font-size: 16px;
  position: relative;
  cursor: pointer;
}

.bell-dot {
  position: absolute;
  top: -2px;
  right: -2px;
  width: 7px;
  height: 7px;
  background: var(--danger-color);
  border-radius: 50%;
  border: 1px solid white;
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 8px;
}

.profile-avatar {
  width: 30px;
  height: 30px;
  background: var(--accent-color);
  border-radius: 50%;
  color: white;
  font-weight: 600;
  font-size: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
}

.profile-info {
  display: flex;
  flex-direction: column;
  gap: 1px;
}

.profile-name {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-color);
}

.profile-role {
  font-size: 10px;
  color: var(--text-muted);
}

/* Content pane scroll area */
.crm-content {
  flex: 1;
  overflow-y: auto;
  padding: 24px;
}

.tab-pane {
  animation: fadeIn 0.2s ease;
}

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

/* ===== KPI CARDS ===== */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 14px;
  margin-bottom: 20px;
}

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}

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

.kpi-card.card-blue { border-top: 3px solid #1f6feb; }
.kpi-card.card-green { border-top: 3px solid #238636; }
.kpi-card.card-orange { border-top: 3px solid #e3b341; }
.kpi-card.card-purple { border-top: 3px solid #8957e5; }

.kpi-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
}

.kpi-title {
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  color: var(--text-muted);
}

.kpi-icon {
  font-size: 16px;
  opacity: 0.7;
}

.kpi-value {
  font-family: var(--font-title);
  font-size: 28px;
  font-weight: 700;
  color: var(--text-color);
  line-height: 1;
  margin-bottom: 6px;
}

.kpi-subtext {
  font-size: 10px;
  color: var(--text-muted);
}

.kpi-subtext.highlight {
  color: var(--accent-color);
  font-weight: 600;
}

.kpi-badges {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.badge-sub {
  font-size: 9px;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 20px;
  text-transform: uppercase;
  letter-spacing: 0.3px;
}

.badge-sub.green { background: var(--success-light); color: var(--success-color); }
.badge-sub.gray { background: var(--border-light); color: var(--text-muted); }
.badge-sub.blue { background: var(--accent-light); color: var(--accent-color); }
.badge-sub.red { background: var(--danger-light); color: var(--danger-color); }
.badge-sub.orange { background: #fff3cd; color: #92600a; }

/* ===== DASHBOARD BOTTOM GRID ===== */
.dashboard-bottom-grid {
  display: grid;
  grid-template-columns: 1fr 280px;
  gap: 16px;
}

.panel-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.panel-title {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-color);
  display: flex;
  align-items: center;
  gap: 6px;
}

.panel-title-sub {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.5px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.pulse-dot {
  width: 7px;
  height: 7px;
  background: #10b981;
  border-radius: 50%;
  display: inline-block;
  animation: pulse 2s infinite;
}

@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.3); }
}

.live-sync-badge {
  font-size: 9px;
  font-weight: 700;
  padding: 2px 7px;
  background: var(--success-light);
  color: var(--success-color);
  border-radius: 4px;
  letter-spacing: 0.5px;
}

.stream-panel {
  overflow: hidden;
}

.stream-list {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-height: 300px;
  overflow-y: auto;
}

.stream-placeholder {
  text-align: center;
  padding: 30px;
  color: var(--text-muted);
  font-size: 11px;
}

.stream-item {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 10px 0;
  border-bottom: 1px solid var(--border-light);
}

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

.stream-avatar {
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: var(--accent-color);
  color: white;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.stream-body {
  flex: 1;
  overflow: hidden;
}

.stream-user {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-color);
  display: block;
  margin-bottom: 2px;
}

.stream-text {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  margin-bottom: 3px;
}

.stream-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  color: var(--text-light);
}

.stream-tag {
  font-size: 9px;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 3px;
  text-transform: uppercase;
}

.stream-tag.user {
  background: var(--accent-light);
  color: var(--accent-color);
}

.stream-tag.ai {
  background: var(--success-light);
  color: var(--success-color);
}

.side-widgets {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.widget-title {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 10px;
}

.widget-content {
  color: var(--text-color);
}

/* ===== SECTION TOPBAR ===== */
.section-topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 16px;
}

.section-topbar h3 {
  font-size: 16px;
  font-weight: 600;
  color: var(--text-color);
  margin-bottom: 4px;
}

.section-desc {
  font-size: 11px;
  color: var(--text-muted);
  display: block;
  max-width: 500px;
}

/* ===== USER STAT ROW ===== */
.user-stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.user-stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 8px;
  padding: 12px 14px;
  text-align: center;
}

.user-stat-label {
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  margin-bottom: 4px;
  display: block;
}

.user-stat-val {
  font-family: var(--font-title);
  font-size: 22px;
  font-weight: 700;
  color: var(--text-color);
}

/* ===== TABLES ===== */
.crm-table-wrapper,
.cms-table-wrapper {
  overflow-x: auto;
}

.cms-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.cms-table thead th {
  padding: 9px 12px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--text-muted);
  background: var(--border-light);
  border-bottom: 1px solid var(--border-color);
  text-align: left;
  white-space: nowrap;
}

.cms-table tbody tr {
  border-bottom: 1px solid var(--border-light);
  transition: background 0.1s;
}

.cms-table tbody tr:hover {
  background: #f8fafd;
}

.cms-table tbody tr:last-child {
  border-bottom: none;
}

.cms-table tbody td {
  padding: 10px 12px;
  vertical-align: middle;
  color: var(--text-color);
}

.tr-clickable {
  cursor: pointer;
}

.tr-expanded td {
  background: #f8fafd;
}

.expanded-row-details {
  background: var(--border-light);
}

.expanded-row-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.detail-item {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.detail-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.4px;
  font-weight: 600;
}

.detail-val {
  font-size: 12px;
  font-weight: 500;
  color: var(--text-color);
}

.chevron-icon {
  transition: transform 0.2s;
  display: inline-block;
  color: var(--text-muted);
}

.tr-expanded .chevron-icon {
  transform: rotate(90deg);
}

/* ===== BADGES ===== */
.badge-role {
  font-size: 9px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.badge-role.admin {
  background: var(--accent-light);
  color: var(--accent-color);
}

.badge-role.user {
  background: var(--border-light);
  color: var(--text-muted);
}

.badge-status {
  font-size: 9px;
  font-weight: 700;
  padding: 3px 8px;
  border-radius: 4px;
  text-transform: uppercase;
}

.badge-status.success { background: var(--success-light); color: var(--success-color); }
.badge-status.failed { background: var(--danger-light); color: var(--danger-color); }
.badge-status.cut-off, .badge-status.aborted { background: #fff3cd; color: #92600a; }
.badge-status.pending { background: #fff3cd; color: #92600a; }
.badge-status.approved { background: var(--success-light); color: var(--success-color); }
.badge-status.rejected { background: var(--danger-light); color: var(--danger-color); }

.badge-type {
  font-size: 9px;
  font-weight: 600;
  padding: 2px 6px;
  border-radius: 3px;
}

.badge-type.chat { background: var(--accent-light); color: var(--accent-color); }
.badge-type.file_upload { background: #f3e8ff; color: #8957e5; }
.badge-type.embedding { background: #fef3c7; color: #92600a; }

/* ===== QUOTA PROGRESS BAR ===== */
.quota-bar-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
}

.quota-bar-track {
  flex: 1;
  height: 4px;
  background: var(--border-light);
  border-radius: 2px;
  overflow: hidden;
  min-width: 60px;
}

.quota-bar-fill {
  height: 100%;
  border-radius: 2px;
  transition: width 0.5s ease;
}

.quota-bar-fill.safe { background: var(--success-color); }
.quota-bar-fill.warn { background: var(--orange-color); }
.quota-bar-fill.danger { background: var(--danger-color); }

.quota-pct-label {
  font-size: 10px;
  font-weight: 600;
  color: var(--text-muted);
  flex-shrink: 0;
  min-width: 32px;
  text-align: right;
}

/* ===== METRICS SUMMARY CARDS ===== */
.metrics-summary-cards {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.metric-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 16px;
  text-align: center;
  box-shadow: var(--shadow-sm);
}

.savings-card {
  border-top: 3px solid #238636;
}

.metric-val {
  font-family: var(--font-title);
  font-size: 24px;
  font-weight: 700;
  color: var(--text-color);
  margin-bottom: 4px;
}

.metric-label {
  font-size: 10px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  font-weight: 600;
}

/* ===== CHARTS ===== */
.analytics-charts-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-bottom: 20px;
}

.chart-card {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 16px;
  box-shadow: var(--shadow-sm);
}

.chart-card h4 {
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 12px;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}

.chart-container {
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.svg-bar {
  cursor: pointer;
  opacity: 0.85;
  transition: opacity 0.15s;
}

.svg-bar:hover { opacity: 1; }

/* ===== DEVELOPER PANEL ===== */
.developer-panel {
  background: var(--bg-card);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  padding: 14px 16px;
  margin: 16px 0;
}

.developer-panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  cursor: pointer;
}

.developer-panel-header h4 {
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
}

.developer-panel-toggle {
  font-size: 11px;
  color: var(--accent-color);
  cursor: pointer;
  font-weight: 500;
}

.developer-panel-body {
  margin-top: 12px;
  border-top: 1px solid var(--border-light);
  padding-top: 12px;
}

.developer-panel-body p {
  font-size: 11px;
  color: var(--text-muted);
  margin-bottom: 12px;
}

.developer-actions {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

/* ===== BUTTONS ===== */
.btn-primary {
  background: var(--accent-color);
  color: white;
  border: none;
  border-radius: 6px;
  padding: 8px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-primary:hover {
  background: var(--accent-hover);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-white);
  color: var(--text-color);
  border: 1px solid var(--border-color);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 11px;
  font-weight: 500;
  cursor: pointer;
  transition: var(--transition);
}

.btn-secondary:hover {
  background: var(--border-light);
  border-color: var(--text-muted);
}

.btn-danger-outline {
  background: transparent;
  color: var(--danger-color);
  border: 1px solid var(--danger-color);
  border-radius: 6px;
  padding: 7px 12px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  transition: var(--transition);
}

.btn-danger-outline:hover {
  background: var(--danger-light);
}

.btn-actions-wrap {
  display: flex;
  gap: 4px;
}

.btn-action {
  background: transparent;
  border: none;
  cursor: pointer;
  padding: 4px 6px;
  border-radius: 4px;
  font-size: 13px;
  transition: background 0.1s;
}

.btn-action:hover { background: var(--border-light); }

/* ===== MODAL ===== */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9999;
  backdrop-filter: blur(2px);
}

.modal-card {
  background: var(--bg-white);
  border-radius: 12px;
  width: 480px;
  max-width: 95vw;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: 0 20px 60px rgba(0,0,0,0.2);
  animation: slideUp 0.2s ease;
}

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

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

.modal-header h4 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-color);
}

.modal-close {
  background: none;
  border: none;
  font-size: 20px;
  color: var(--text-muted);
  cursor: pointer;
  line-height: 1;
  padding: 2px 6px;
  border-radius: 4px;
  transition: var(--transition);
}

.modal-close:hover {
  background: var(--border-light);
  color: var(--text-color);
}

.modal-body {
  padding: 20px;
}

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

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-color);
  margin-bottom: 6px;
}

.form-group input,
.form-group select,
.form-group textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border-color);
  border-radius: 6px;
  font-size: 12px;
  color: var(--text-color);
  background: var(--bg-white);
  transition: var(--transition);
}

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

/* Model checkbox labels */
.model-checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: 6px;
  transition: background 0.1s;
  font-weight: normal !important;
}

.model-checkbox-label:hover {
  background: var(--border-light);
}

.model-checkbox-label input[type="checkbox"] {
  width: auto;
  margin: 0;
  cursor: pointer;
}

.model-chip {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 4px;
  white-space: nowrap;
}

.chip-haiku { background: var(--success-light); color: var(--success-color); }
.chip-sonnet { background: var(--accent-light); color: var(--accent-color); }
.chip-opus { background: #f3e8ff; color: #8957e5; }

/* ===== MISC ===== */
.check-green { color: var(--success-color); font-weight: 700; }
.cross-gray { color: var(--text-light); }
