/* ==========================================================================
   CRM wearebigg — design system
   Tokens first, then layout, then components. Light + dark.
   ========================================================================== */

:root {
  --bg:            #f6f7fb;
  --surface:       #ffffff;
  --surface-2:     #f9fafb;
  --surface-3:     #f1f3f9;
  --border:        #e4e7ee;
  --border-strong: #d3d8e3;
  --text:          #131722;
  --text-muted:    #616b80;
  --text-faint:    #8b93a7;

  --brand:         #4f46e5;
  --brand-hover:   #4338ca;
  --brand-soft:    #eef0ff;
  --brand-text:    #4338ca;

  --success:       #0e9f6e;
  --success-soft:  #e3f6ee;
  --warning:       #d97706;
  --warning-soft:  #fdf1e0;
  --danger:        #dc2626;
  --danger-soft:   #fdeaea;
  --info:          #0284c7;
  --info-soft:     #e4f2fb;

  --shadow-sm: 0 1px 2px rgba(16, 24, 40, .06);
  --shadow:    0 2px 8px rgba(16, 24, 40, .08);
  --shadow-lg: 0 12px 32px rgba(16, 24, 40, .14);

  --radius:    10px;
  --radius-lg: 14px;
  --sidebar-w: 244px;
  --topbar-h:  60px;
  --font: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

[data-theme="dark"] {
  --bg:            #0e1117;
  --surface:       #161b24;
  --surface-2:     #1c222d;
  --surface-3:     #232a37;
  --border:        #262d3a;
  --border-strong: #333c4d;
  --text:          #e8ecf4;
  --text-muted:    #9aa4b8;
  --text-faint:    #6d7688;

  --brand:         #6366f1;
  --brand-hover:   #7c7ff5;
  --brand-soft:    #1e2140;
  --brand-text:    #a5b4fc;

  --success-soft:  #0d2b22;
  --warning-soft:  #2e2213;
  --danger-soft:   #2e1616;
  --info-soft:     #10222f;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, .4);
  --shadow:    0 2px 10px rgba(0, 0, 0, .45);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, .6);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-text); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0; font-weight: 600; letter-spacing: -0.01em; }

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

/* ---------------------------------------------------------------- layout */

.layout { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 40;
  transition: transform .22s ease;
}

.sidebar__brand {
  height: var(--topbar-h);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.sidebar__logo {
  width: 30px; height: 30px;
  border-radius: 8px;
  background: linear-gradient(135deg, var(--brand), #8b5cf6);
  color: #fff;
  display: grid; place-items: center;
  font-weight: 700; font-size: 13px;
  flex-shrink: 0;
}
.sidebar__title { font-weight: 650; font-size: 14.5px; letter-spacing: -.02em; }
.sidebar__sub   { font-size: 11px; color: var(--text-faint); margin-top: -2px; }

.sidebar__nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.nav-group { margin-bottom: 4px; }
.nav-label {
  font-size: 10.5px; font-weight: 600; text-transform: uppercase;
  letter-spacing: .07em; color: var(--text-faint);
  padding: 12px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 10px; border-radius: 8px;
  color: var(--text-muted); font-weight: 500; font-size: 13.5px;
  cursor: pointer; user-select: none;
  transition: background .12s, color .12s;
}
.nav-item:hover { background: var(--surface-3); color: var(--text); text-decoration: none; }
.nav-item.active { background: var(--brand-soft); color: var(--brand-text); font-weight: 600; }
.nav-item svg { width: 17px; height: 17px; flex-shrink: 0; }
.nav-item__badge {
  margin-left: auto; background: var(--danger); color: #fff;
  font-size: 10.5px; font-weight: 600; padding: 1px 6px; border-radius: 999px;
}

.sidebar__footer { border-top: 1px solid var(--border); padding: 10px; }

.main { flex: 1; margin-left: var(--sidebar-w); min-width: 0; display: flex; flex-direction: column; }

.topbar {
  height: var(--topbar-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 20px;
  position: sticky; top: 0; z-index: 30;
}

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

.page-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 18px; flex-wrap: wrap;
}
.page-title { font-size: 21px; font-weight: 650; letter-spacing: -.02em; }
.page-sub { color: var(--text-muted); font-size: 13px; margin-top: 2px; }

/* --------------------------------------------------------------- controls */

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  padding: 8px 14px; border-radius: 8px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  font: inherit; font-size: 13.5px; font-weight: 550;
  cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--surface-3); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn svg { width: 15px; height: 15px; }

.btn--primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn--primary:hover { background: var(--brand-hover); border-color: var(--brand-hover); }
.btn--danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn--danger:hover { opacity: .9; background: var(--danger); }
.btn--ghost { background: transparent; border-color: transparent; color: var(--text-muted); }
.btn--ghost:hover { background: var(--surface-3); color: var(--text); }
.btn--sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn--icon { padding: 7px; }
.btn--block { width: 100%; }

.input, .select, .textarea {
  width: 100%;
  padding: 8px 11px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  font: inherit; font-size: 13.5px;
  transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--brand) 18%, transparent);
}
.input::placeholder { color: var(--text-faint); }
.textarea { resize: vertical; min-height: 80px; }
.select { appearance: none; padding-right: 30px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%23888' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 9px center; background-size: 15px; }

.field { margin-bottom: 14px; }
.label { display: block; font-size: 12.5px; font-weight: 550; color: var(--text-muted); margin-bottom: 5px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }

.search {
  position: relative; flex: 1; max-width: 420px;
}
.search .input { padding-left: 34px; background: var(--surface-2); }
.search svg { position: absolute; left: 11px; top: 50%; transform: translateY(-50%);
  width: 15px; height: 15px; color: var(--text-faint); pointer-events: none; }

.toolbar { display: flex; gap: 9px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .select, .toolbar .input { width: auto; min-width: 145px; }

/* ----------------------------------------------------------------- cards */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
}
.card__head {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.card__title { font-size: 14.5px; font-weight: 600; }
.card__body { padding: 18px; }
.card__body--flush { padding: 0; }

.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; margin-bottom: 20px; }
.kpi {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius-lg); padding: 16px 18px; box-shadow: var(--shadow-sm);
}
.kpi__label { font-size: 12px; color: var(--text-muted); font-weight: 550; display: flex; align-items: center; gap: 7px; }
.kpi__value { font-size: 25px; font-weight: 680; letter-spacing: -.03em; margin-top: 7px; }
.kpi__meta { font-size: 12px; color: var(--text-faint); margin-top: 3px; }
.kpi__icon {
  width: 28px; height: 28px; border-radius: 8px; display: grid; place-items: center;
  background: var(--brand-soft); color: var(--brand-text);
}
.kpi__icon svg { width: 15px; height: 15px; }

/* ---------------------------------------------------------------- tables */

.table-wrap { overflow-x: auto; }
table.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-weight: 600; font-size: 11.5px; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-faint);
  padding: 11px 16px; border-bottom: 1px solid var(--border); white-space: nowrap;
  background: var(--surface-2);
}
.table td { padding: 12px 16px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr { transition: background .1s; }
.table tbody tr:hover { background: var(--surface-2); }
.table tbody tr.clickable { cursor: pointer; }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }
.table .actions { text-align: right; white-space: nowrap; }

.empty { padding: 52px 20px; text-align: center; color: var(--text-muted); }
.empty svg { width: 38px; height: 38px; color: var(--text-faint); margin-bottom: 12px; }
.empty__title { font-weight: 600; color: var(--text); margin-bottom: 4px; }

/* --------------------------------------------------------------- badges */

.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 9px; border-radius: 999px;
  font-size: 11.5px; font-weight: 600; white-space: nowrap;
  background: var(--surface-3); color: var(--text-muted);
}
.badge--success { background: var(--success-soft); color: var(--success); }
.badge--warning { background: var(--warning-soft); color: var(--warning); }
.badge--danger  { background: var(--danger-soft);  color: var(--danger); }
.badge--info    { background: var(--info-soft);    color: var(--info); }
.badge--brand   { background: var(--brand-soft);   color: var(--brand-text); }
.badge__dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 8px; border-radius: 6px; font-size: 11.5px; font-weight: 550;
}

.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  background: var(--brand-soft); color: var(--brand-text);
  display: grid; place-items: center;
  font-size: 11.5px; font-weight: 650; flex-shrink: 0; text-transform: uppercase;
}
.avatar--sm { width: 24px; height: 24px; font-size: 10px; }
.avatar--lg { width: 46px; height: 46px; font-size: 16px; }

/* --------------------------------------------------------------- kanban */

.board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.board__col {
  flex: 0 0 288px; background: var(--surface-2);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  display: flex; flex-direction: column; max-height: calc(100vh - 210px);
}
.board__col.drag-over { border-color: var(--brand); background: var(--brand-soft); }
.board__head { padding: 12px 14px; border-bottom: 1px solid var(--border); }
.board__name { display: flex; align-items: center; gap: 7px; font-weight: 600; font-size: 13.5px; }
.board__count { margin-left: auto; font-size: 11.5px; color: var(--text-faint); font-weight: 600; }
.board__sum { font-size: 12px; color: var(--text-muted); margin-top: 4px; font-variant-numeric: tabular-nums; }
.board__list { padding: 10px; overflow-y: auto; flex: 1; min-height: 70px; display: flex; flex-direction: column; gap: 9px; }

.deal-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: 10px; padding: 11px 12px; cursor: grab;
  box-shadow: var(--shadow-sm); transition: box-shadow .12s, transform .12s;
}
.deal-card:hover { box-shadow: var(--shadow); }
.deal-card.dragging { opacity: .45; }
.deal-card__title { font-weight: 600; font-size: 13.5px; margin-bottom: 3px; }
.deal-card__company { font-size: 12px; color: var(--text-muted); }
.deal-card__foot { display: flex; align-items: center; gap: 8px; margin-top: 9px; }
.deal-card__value { font-weight: 650; font-size: 13.5px; font-variant-numeric: tabular-nums; }
.deal-card__rot { color: var(--warning); }

/* --------------------------------------------------------------- modals */

.overlay {
  position: fixed; inset: 0; background: rgba(11, 15, 25, .55);
  backdrop-filter: blur(2px);
  display: grid; place-items: center; padding: 20px; z-index: 100;
  animation: fade .14s ease;
}
@keyframes fade { from { opacity: 0 } to { opacity: 1 } }

.modal {
  background: var(--surface); border-radius: 16px;
  box-shadow: var(--shadow-lg); border: 1px solid var(--border);
  width: 100%; max-width: 560px; max-height: 90vh;
  display: flex; flex-direction: column;
  animation: pop .16s ease;
}
@keyframes pop { from { opacity: 0; transform: translateY(8px) scale(.99) } to { opacity: 1; transform: none } }
.modal--lg { max-width: 880px; }
.modal--xl { max-width: 1080px; }
.modal__head {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.modal__title { font-size: 16px; font-weight: 620; }
.modal__body { padding: 20px; overflow-y: auto; flex: 1; }
.modal__foot {
  padding: 14px 20px; border-top: 1px solid var(--border);
  display: flex; justify-content: flex-end; gap: 9px;
}

/* --------------------------------------------------------------- drawer */

.drawer {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(720px, 100%);
  background: var(--surface); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg); z-index: 100;
  display: flex; flex-direction: column;
  animation: slide .2s ease;
}
@keyframes slide { from { transform: translateX(24px); opacity: .6 } to { transform: none; opacity: 1 } }

/* --------------------------------------------------------------- toasts */

.toasts { position: fixed; bottom: 20px; right: 20px; z-index: 200; display: flex; flex-direction: column; gap: 9px; }
.toast {
  background: var(--surface); border: 1px solid var(--border);
  border-left: 3px solid var(--brand);
  border-radius: 10px; padding: 11px 15px; box-shadow: var(--shadow-lg);
  font-size: 13.5px; min-width: 250px; max-width: 380px;
  animation: pop .16s ease;
}
.toast--success { border-left-color: var(--success); }
.toast--error   { border-left-color: var(--danger); }

/* ----------------------------------------------------------------- misc */

.tabs { display: flex; gap: 3px; border-bottom: 1px solid var(--border); margin-bottom: 18px; overflow-x: auto; }
.tab {
  padding: 9px 14px; font-size: 13.5px; font-weight: 550; color: var(--text-muted);
  border-bottom: 2px solid transparent; cursor: pointer; white-space: nowrap;
}
.tab:hover { color: var(--text); }
.tab.active { color: var(--brand-text); border-bottom-color: var(--brand); }

.timeline { position: relative; padding-left: 26px; }
.timeline::before { content: ''; position: absolute; left: 8px; top: 6px; bottom: 6px; width: 2px; background: var(--border); }
.timeline__item { position: relative; padding-bottom: 18px; }
.timeline__dot {
  position: absolute; left: -22px; top: 3px; width: 12px; height: 12px;
  border-radius: 50%; background: var(--surface); border: 2px solid var(--border-strong);
}
.timeline__time { font-size: 11.5px; color: var(--text-faint); }

.progress { height: 6px; border-radius: 999px; background: var(--surface-3); overflow: hidden; }
.progress__bar { height: 100%; background: var(--brand); border-radius: 999px; transition: width .3s; }

.muted { color: var(--text-muted); }
.faint { color: var(--text-faint); }
.num   { font-variant-numeric: tabular-nums; }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.flex  { display: flex; align-items: center; gap: 9px; }
.flex-between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grow  { flex: 1; }
.hidden { display: none !important; }
.mt-0 { margin-top: 0 } .mt-2 { margin-top: 8px } .mt-3 { margin-top: 12px } .mt-4 { margin-top: 16px }
.mb-2 { margin-bottom: 8px } .mb-3 { margin-bottom: 12px } .mb-4 { margin-bottom: 16px }
.text-sm { font-size: 12.5px } .text-xs { font-size: 11.5px }
.fw-600 { font-weight: 600 }

.spinner {
  width: 20px; height: 20px; border: 2px solid var(--border-strong);
  border-top-color: var(--brand); border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg) } }
.loading { display: grid; place-items: center; padding: 60px; }

/* --------------------------------------------------------------- charts */

.chart { width: 100%; height: 220px; }
.chart-bars { display: flex; align-items: flex-end; gap: 6px; height: 180px; padding-top: 10px; }
.chart-bar { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; gap: 3px; min-width: 0; }
.chart-bar__fill { background: var(--brand); border-radius: 4px 4px 0 0; min-height: 2px; transition: height .3s; }
.chart-bar__fill--lost { background: var(--danger); opacity: .55; }
.chart-bar__label { font-size: 10px; color: var(--text-faint); text-align: center; margin-top: 5px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.funnel__row { display: flex; align-items: center; gap: 12px; margin-bottom: 10px; }
.funnel__name { width: 130px; font-size: 12.5px; flex-shrink: 0; }
.funnel__bar { flex: 1; height: 26px; background: var(--surface-3); border-radius: 6px; overflow: hidden; }
.funnel__fill { height: 100%; border-radius: 6px; display: flex; align-items: center; padding: 0 9px;
  color: #fff; font-size: 11.5px; font-weight: 600; }
.funnel__val { width: 110px; text-align: right; font-size: 12.5px; font-variant-numeric: tabular-nums; flex-shrink: 0; }

/* ---------------------------------------------------------------- login */

.login-page {
  min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1100px 600px at 20% -10%, color-mix(in srgb, var(--brand) 16%, transparent), transparent), var(--bg);
}
.login-card {
  width: 100%; max-width: 396px; background: var(--surface);
  border: 1px solid var(--border); border-radius: 18px;
  box-shadow: var(--shadow-lg); padding: 32px;
}
.login-logo {
  width: 48px; height: 48px; border-radius: 13px; margin: 0 auto 16px;
  background: linear-gradient(135deg, var(--brand), #8b5cf6); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 17px;
}

/* --------------------------------------------------------- printable doc */

.doc-print { max-width: 820px; margin: 0 auto; background: #fff; color: #111; padding: 44px; }
.doc-print table { width: 100%; border-collapse: collapse; }
.doc-print th { text-align: left; border-bottom: 2px solid #333; padding: 8px 6px; font-size: 12px; }
.doc-print td { border-bottom: 1px solid #ddd; padding: 8px 6px; font-size: 13px; }

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
  .main { margin-left: 0 !important; }
  .content { padding: 0 !important; }
  body { background: #fff; }
}

/* ------------------------------------------------------------ responsive */

@media (max-width: 1024px) {
  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .content { padding: 14px; }
  .modal { max-width: 100%; }
}
