/* ============================================================
   COMMPRO — CORPORATE DESIGN SYSTEM v2
   ============================================================ */

/* ── Security: disable text selection globally; re-enable in inputs ── */
*, *::before, *::after {
  -webkit-user-select: none;
  -moz-user-select:    none;
  -ms-user-select:     none;
  user-select:         none;
}
input, textarea, select, [contenteditable] {
  -webkit-user-select: text;
  -moz-user-select:    text;
  -ms-user-select:     text;
  user-select:         text;
}

@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700;800&display=swap');

:root {
  --primary:    #1d4ed8;
  --primary-d:  #1e40af;
  --primary-l:  #eff6ff;
  --secondary:  #6d28d9;
  --success:    #15803d;
  --success-l:  #f0fdf4;
  --warning:    #b45309;
  --warning-l:  #fffbeb;
  --danger:     #b91c1c;
  --danger-l:   #fef2f2;
  --info:       #0369a1;
  --info-l:     #e0f2fe;

  --bg:         #f3f4f6;
  --surface:    #ffffff;
  --surface-2:  #f9fafb;
  --border:     #e5e7eb;
  --border-d:   #d1d5db;

  --text:       #111827;
  --text-2:     #374151;
  --text-muted: #6b7280;
  --text-light: #9ca3af;

  --sidebar-bg:  #0f1419;
  --sidebar-w:   256px;
  --topbar-h:    60px;
  --radius:      8px;
  --radius-lg:   12px;

  --shadow-sm:  0 1px 2px rgba(0,0,0,.05);
  --shadow:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-md:  0 4px 12px rgba(0,0,0,.08), 0 2px 4px rgba(0,0,0,.04);
  --shadow-lg:  0 10px 30px rgba(0,0,0,.10), 0 4px 8px rgba(0,0,0,.05);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: 14px; }
body {
  font-family: 'Inter', system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  line-height: 1.5;
}

/* ══════════════════════════════════════════
   LAYOUT
══════════════════════════════════════════ */
.layout   { display: flex; min-height: 100vh; }
.main     { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; min-height: 100vh; }
.page-content { padding: 28px 32px; flex: 1; }

/* ══════════════════════════════════════════
   SIDEBAR
══════════════════════════════════════════ */
.sidebar {
  width: var(--sidebar-w);
  background: var(--sidebar-bg);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0;
  height: 100vh;
  z-index: 50;
  overflow-y: auto;
  border-right: 1px solid rgba(255,255,255,.04);
}

.sidebar-logo {
  padding: 20px 20px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid rgba(255,255,255,.06);
  margin-bottom: 8px;
}
.sidebar-logo .logo-icon {
  width: 34px; height: 34px;
  background: var(--primary);
  border-radius: 8px;
  display: grid;
  place-items: center;
  font-size: .8rem;
  font-weight: 800;
  color: #fff;
  letter-spacing: .02em;
  flex-shrink: 0;
}
.sidebar-logo .logo-text { color: #f9fafb; font-weight: 700; font-size: .95rem; line-height: 1.2; }
.sidebar-logo .logo-sub  { color: #4b5563; font-size: .68rem; font-weight: 500; margin-top: 1px; }

.sidebar-nav  { flex: 1; padding: 4px 0 12px; }

.nav-section {
  padding: 16px 16px 5px;
  color: #374151;
  font-size: .65rem;
  font-weight: 600;
  letter-spacing: .1em;
  text-transform: uppercase;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  color: #9ca3af;
  font-size: .82rem;
  font-weight: 500;
  text-decoration: none;
  cursor: pointer;
  transition: all .12s;
  border-radius: 0;
  margin: 1px 8px;
  border-radius: 6px;
  border-left: none;
  position: relative;
}
.nav-item:hover { background: rgba(255,255,255,.06); color: #e5e7eb; }
.nav-item.active {
  background: rgba(29,78,216,.2);
  color: #93c5fd;
  font-weight: 600;
}
.nav-item.active::before {
  content: '';
  position: absolute;
  left: 0; top: 50%;
  transform: translateY(-50%);
  width: 3px; height: 18px;
  background: var(--primary);
  border-radius: 0 2px 2px 0;
  margin-left: -8px;
}

.nav-icon {
  width: 18px; height: 18px;
  display: grid;
  place-items: center;
  flex-shrink: 0;
  opacity: .7;
}
.nav-item.active .nav-icon { opacity: 1; }
.nav-item:hover .nav-icon  { opacity: .9; }

.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: .6rem;
  font-weight: 700;
  padding: 1px 5px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.sidebar-footer {
  padding: 14px 16px;
  border-top: 1px solid rgba(255,255,255,.06);
}
.user-card  { display: flex; align-items: center; gap: 10px; }
.avatar {
  width: 34px; height: 34px;
  border-radius: 50%;
  background: var(--primary);
  display: grid;
  place-items: center;
  color: #fff;
  font-weight: 700;
  font-size: .78rem;
  flex-shrink: 0;
}
.avatar.agent    { background: var(--secondary); }
.avatar.customer { background: var(--success); }
.user-info  { flex: 1; min-width: 0; }
.user-name  { color: #f3f4f6; font-size: .82rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-role  { color: #4b5563; font-size: .7rem; font-weight: 500; margin-top: 1px; }

/* ══════════════════════════════════════════
   TOPBAR
══════════════════════════════════════════ */
.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 28px;
  position: sticky;
  top: 0;
  z-index: 40;
}
.page-title {
  font-size: .95rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.01em;
}
.topbar-right { display: flex; align-items: center; gap: 10px; }

.btn-icon {
  width: 34px; height: 34px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: var(--surface);
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text-muted);
  position: relative;
  transition: background .12s;
}
.btn-icon:hover { background: var(--surface-2); }
.badge-dot {
  width: 7px; height: 7px;
  background: var(--danger);
  border-radius: 50%;
  position: absolute;
  top: 6px; right: 6px;
  border: 1.5px solid #fff;
}

/* ══════════════════════════════════════════
   KPI CARDS
══════════════════════════════════════════ */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}
.kpi-card {
  background: var(--surface);
  border-radius: var(--radius);
  padding: 20px;
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  position: relative;
  overflow: hidden;
  transition: box-shadow .15s;
}
.kpi-card:hover { box-shadow: var(--shadow-md); }

.kpi-card::after {
  content: '';
  position: absolute;
  top: 0; left: 0; right: 0;
  height: 3px;
  border-radius: var(--radius) var(--radius) 0 0;
}
.kpi-card.blue::after   { background: var(--primary); }
.kpi-card.green::after  { background: var(--success); }
.kpi-card.orange::after { background: var(--warning); }
.kpi-card.purple::after { background: var(--secondary); }
.kpi-card.red::after    { background: var(--danger); }
.kpi-card.teal::after   { background: var(--info); }

.kpi-icon {
  width: 36px; height: 36px;
  border-radius: 8px;
  display: grid;
  place-items: center;
  margin-bottom: 14px;
}
.kpi-icon.blue   { background: var(--primary-l); color: var(--primary); }
.kpi-icon.green  { background: var(--success-l); color: var(--success); }
.kpi-icon.orange { background: var(--warning-l); color: var(--warning); }
.kpi-icon.purple { background: #f5f3ff; color: var(--secondary); }
.kpi-icon.red    { background: var(--danger-l); color: var(--danger); }
.kpi-icon.teal   { background: var(--info-l); color: var(--info); }

.kpi-label { font-size: .72rem; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .06em; margin-bottom: 4px; }
.kpi-value { font-size: 1.6rem; font-weight: 800; color: var(--text); line-height: 1.1; letter-spacing: -.03em; }
.kpi-sub   { font-size: .75rem; color: var(--text-light); margin-top: 4px; }
.kpi-trend { font-size: .72rem; font-weight: 600; margin-top: 4px; display: flex; align-items: center; gap: 3px; }
.kpi-trend.up   { color: var(--success); }
.kpi-trend.down { color: var(--danger); }

/* ══════════════════════════════════════════
   CARDS
══════════════════════════════════════════ */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.card-header {
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--surface);
}
.card-title {
  font-size: .875rem;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -.01em;
}
.card-body { padding: 20px; }

/* ══════════════════════════════════════════
   TABLES
══════════════════════════════════════════ */
.table-wrap { overflow-x: auto; }
table       { width: 100%; border-collapse: collapse; font-size: .82rem; }

thead tr { background: var(--surface-2); }
th {
  padding: 9px 14px;
  text-align: left;
  font-size: .68rem;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .07em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
td {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  color: var(--text-2);
  vertical-align: middle;
  font-size: .82rem;
}
tr:last-child td    { border-bottom: none; }
tbody tr:hover td   { background: #fafafa; }
.num { text-align: right; font-variant-numeric: tabular-nums; font-feature-settings: "tnum"; }

/* ══════════════════════════════════════════
   BADGES
══════════════════════════════════════════ */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: .68rem;
  font-weight: 600;
  white-space: nowrap;
  letter-spacing: .01em;
}
.badge::before {
  content: '';
  width: 5px; height: 5px;
  border-radius: 50%;
  background: currentColor;
  opacity: .8;
}
.badge-success { background: #dcfce7; color: #166534; }
.badge-warning { background: #fef9c3; color: #854d0e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-muted   { background: #f3f4f6; color: #4b5563; }
.badge-purple  { background: #ede9fe; color: #5b21b6; }

/* ══════════════════════════════════════════
   BUTTONS
══════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius);
  font-size: .8rem;
  font-weight: 600;
  cursor: pointer;
  border: none;
  text-decoration: none;
  transition: all .12s;
  white-space: nowrap;
  font-family: inherit;
  letter-spacing: .01em;
}
.btn-primary {
  background: var(--primary);
  color: #fff;
  box-shadow: 0 1px 2px rgba(29,78,216,.3);
}
.btn-primary:hover {
  background: var(--primary-d);
  box-shadow: 0 3px 8px rgba(29,78,216,.3);
  transform: translateY(-1px);
}
.btn-outline {
  background: transparent;
  border: 1px solid var(--border-d);
  color: var(--text-2);
}
.btn-outline:hover { border-color: var(--primary); color: var(--primary); background: var(--primary-l); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #166534; }
.btn-danger  { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #991b1b; }
.btn-sm  { padding: 5px 10px; font-size: .75rem; }
.btn-ghost { background: transparent; color: var(--text-muted); border: none; }
.btn-ghost:hover { color: var(--primary); background: var(--primary-l); }

/* ══════════════════════════════════════════
   FORMS
══════════════════════════════════════════ */
.form-row         { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; margin-bottom: 14px; }
.form-row.full    { grid-template-columns: 1fr; }
.form-row.three   { grid-template-columns: 1fr 1fr 1fr; }
.form-group       { display: flex; flex-direction: column; gap: 4px; }
label             { font-size: .75rem; font-weight: 600; color: var(--text-2); }

input, select, textarea {
  padding: 8px 11px;
  border: 1px solid var(--border-d);
  border-radius: var(--radius);
  font-size: .82rem;
  color: var(--text);
  background: var(--surface);
  outline: none;
  transition: border-color .12s, box-shadow .12s;
  width: 100%;
  font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(29,78,216,.1);
}
input[readonly]  { background: var(--surface-2); color: var(--text-muted); }
input::placeholder { color: var(--text-light); }

/* ══════════════════════════════════════════
   CHARTS
══════════════════════════════════════════ */
.chart-box {
  background: var(--surface-2);
  border-radius: var(--radius);
  height: 200px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  gap: 8px;
  font-size: .82rem;
  border: 1px dashed var(--border-d);
}
.chart-bars   { display: flex; align-items: flex-end; gap: 5px; height: 100px; }
.chart-bar    { width: 24px; border-radius: 3px 3px 0 0; background: var(--primary); opacity: .75; }
.chart-labels { display: flex; gap: 5px; }
.chart-label  { width: 24px; font-size: .6rem; text-align: center; color: var(--text-light); }

/* ══════════════════════════════════════════
   PROGRESS
══════════════════════════════════════════ */
.progress       { height: 6px; background: var(--border); border-radius: 3px; overflow: hidden; }
.progress-fill  { height: 100%; border-radius: 3px; background: var(--primary); transition: width .5s; }
.progress-fill.green  { background: var(--success); }
.progress-fill.orange { background: var(--warning); }
.progress-fill.red    { background: var(--danger); }

/* ══════════════════════════════════════════
   TIMELINE
══════════════════════════════════════════ */
.timeline    { display: flex; flex-direction: column; gap: 0; }
.tl-item     { display: flex; gap: 14px; padding-bottom: 18px; position: relative; }
.tl-item:last-child { padding-bottom: 0; }
.tl-item:not(:last-child)::after {
  content: '';
  position: absolute;
  left: 4px; top: 14px;
  width: 1px;
  height: calc(100% - 10px);
  background: var(--border);
}
.tl-dot      { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); margin-top: 4px; flex-shrink: 0; position: relative; z-index: 1; }
.tl-dot.green  { background: var(--success); }
.tl-dot.orange { background: var(--warning); }
.tl-dot.red    { background: var(--danger); }
.tl-dot.gray   { background: var(--text-light); }
.tl-content  { flex: 1; }
.tl-title    { font-size: .82rem; font-weight: 600; color: var(--text); }
.tl-time     { font-size: .72rem; color: var(--text-light); margin-top: 2px; }

/* ══════════════════════════════════════════
   MODAL
══════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.45);
  display: grid; place-items: center;
  z-index: 100;
  backdrop-filter: blur(2px);
}
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  width: min(560px, 95vw);
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
}
.modal-header  { padding: 18px 22px; border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; }
.modal-title   { font-size: .9rem; font-weight: 700; letter-spacing: -.01em; }
.modal-body    { padding: 22px; }
.modal-footer  { padding: 14px 22px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }
.close-btn     { width: 28px; height: 28px; display: grid; place-items: center; border-radius: 6px; cursor: pointer; color: var(--text-muted); border: none; background: transparent; }
.close-btn:hover { background: var(--bg); }

/* ══════════════════════════════════════════
   STEPS
══════════════════════════════════════════ */
.steps       { display: flex; align-items: center; gap: 0; margin-bottom: 24px; }
.step        { display: flex; align-items: center; gap: 8px; }
.step-circle {
  width: 26px; height: 26px;
  border-radius: 50%;
  border: 1.5px solid var(--border-d);
  display: grid; place-items: center;
  font-size: .72rem; font-weight: 700;
  color: var(--text-muted);
  background: var(--surface);
  flex-shrink: 0;
}
.step.done .step-circle   { background: var(--success); border-color: var(--success); color: #fff; }
.step.active .step-circle { background: var(--primary); border-color: var(--primary); color: #fff; }
.step-label  { font-size: .75rem; font-weight: 600; color: var(--text-muted); }
.step.active .step-label  { color: var(--primary); }
.step.done .step-label    { color: var(--success); }
.step-line   { flex: 1; height: 1.5px; background: var(--border); min-width: 32px; }
.step-line.done { background: var(--success); }

/* ══════════════════════════════════════════
   FILTER / SEARCH BAR
══════════════════════════════════════════ */
.filter-bar {
  display: flex; flex-wrap: wrap; gap: 8px;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
}
.filter-label { font-size: .72rem; font-weight: 700; color: var(--text-muted); white-space: nowrap; text-transform: uppercase; letter-spacing: .05em; }
.filter-bar select, .filter-bar input { padding: 6px 10px; font-size: .78rem; min-width: 120px; }

.search-bar {
  display: flex; align-items: center; gap: 7px;
  border: 1px solid var(--border-d);
  border-radius: var(--radius);
  padding: 0 10px;
  background: var(--surface);
  transition: border-color .12s;
}
.search-bar:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(29,78,216,.08); }
.search-bar input {
  border: none; padding: 7px 0;
  flex: 1; font-size: .8rem;
  min-width: 0;
}
.search-bar input:focus { box-shadow: none; }
.search-icon { color: var(--text-light); flex-shrink: 0; }

/* ══════════════════════════════════════════
   LEVEL BADGES
══════════════════════════════════════════ */
.level-badge {
  display: inline-grid;
  place-items: center;
  width: 20px; height: 20px;
  border-radius: 50%;
  font-size: .62rem;
  font-weight: 800;
}
.level-1 { background: #dbeafe; color: #1e40af; }
.level-2 { background: #ede9fe; color: #5b21b6; }
.level-3 { background: #fce7f3; color: #9d174d; }

/* ══════════════════════════════════════════
   UTILITIES
══════════════════════════════════════════ */
.flex            { display: flex; }
.flex-col        { flex-direction: column; }
.items-center    { align-items: center; }
.justify-between { justify-content: space-between; }
.justify-end     { justify-content: flex-end; }
.flex-wrap       { flex-wrap: wrap; }
.gap-4    { gap: 4px; }
.gap-8    { gap: 8px; }
.gap-12   { gap: 12px; }
.gap-16   { gap: 16px; }
.gap-20   { gap: 20px; }

.mt-4  { margin-top: 4px; }
.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mb-4  { margin-bottom: 4px; }
.mb-8  { margin-bottom: 8px; }
.mb-12 { margin-bottom: 12px; }
.mb-16 { margin-bottom: 16px; }
.mb-20 { margin-bottom: 20px; }
.mb-24 { margin-bottom: 24px; }

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

.text-xs      { font-size: .72rem; }
.text-sm      { font-size: .82rem; }
.text-muted   { color: var(--text-muted); }
.text-light   { color: var(--text-light); }
.text-right   { text-align: right; }
.font-bold    { font-weight: 700; }
.font-semibold { font-weight: 600; }
.font-medium  { font-weight: 500; }
.text-primary { color: var(--primary); }
.text-success { color: var(--success); }
.text-danger  { color: var(--danger); }
.text-warning { color: var(--warning); }
.text-info    { color: var(--info); }
.truncate     { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.w-full       { width: 100%; }
.divider      { height: 1px; background: var(--border); margin: 16px 0; }

/* ══════════════════════════════════════════
   SECTION HEADER (inline with icon)
══════════════════════════════════════════ */
.section-header {
  display: flex; align-items: center; gap: 8px;
  font-size: .72rem; font-weight: 700;
  text-transform: uppercase; letter-spacing: .07em;
  color: var(--text-muted);
  padding-bottom: 10px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 16px;
}

/* ══════════════════════════════════════════
   EMPTY STATE
══════════════════════════════════════════ */
.empty-state {
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  padding: 48px 24px;
  color: var(--text-muted);
  gap: 10px;
  text-align: center;
}
.empty-state svg { opacity: .3; }
.empty-state h3  { font-size: .9rem; font-weight: 600; color: var(--text-2); }
.empty-state p   { font-size: .8rem; max-width: 260px; }

/* ══════════════════════════════════════════
   COMM PILL (inline commission tag)
══════════════════════════════════════════ */
.comm-pill {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 7px;
  font-size: .68rem;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 600;
}
