/* ==========================================================================
   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); }

/* Contact links on deal cards and rows. Sized to stay tappable on mobile
   without dominating the card. */
.deal-comms { display: flex; flex-direction: column; gap: 3px; margin-top: 7px; }
.deal-comm {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12.5px; color: var(--text-muted); text-decoration: none;
  min-width: 0; max-width: 100%;
}
.deal-comm span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.deal-comm svg { flex-shrink: 0; color: var(--text-faint); }
.deal-comm:hover { color: var(--brand-text); text-decoration: none; }
.deal-comm:hover svg { color: var(--brand); }

.deal-comms--compact { gap: 2px; margin-top: 6px; padding-top: 6px; border-top: 1px dashed var(--border); }
.deal-comms--compact .deal-comm { font-size: 11.5px; }

/* Full deal URL under a task, so it can be read, clicked or copied. */
.task-link { display: flex; align-items: center; gap: 4px; margin-top: 3px; min-width: 0; }
.task-link a {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 11px; color: var(--text-faint);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.task-link a:hover { color: var(--brand-text); }
.task-link button { opacity: .5; }
.task-link button:hover { opacity: 1; }

/* Activity-type picker: the native radio alone reads poorly at this size. */
.type-pick--on { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-text); font-weight: 600; }

/* Row actions stay quiet until the entry is hovered. */
.timeline__item [data-act-done],
.timeline__item [data-act-edit],
.timeline__item [data-act-del] { opacity: 0; transition: opacity .12s; }
.timeline__item:hover [data-act-done],
.timeline__item:hover [data-act-edit],
.timeline__item:hover [data-act-del],
.timeline__item [data-act-done]:focus,
.timeline__item [data-act-edit]:focus,
.timeline__item [data-act-del]:focus { opacity: 1; }
@media (hover: none) {
  .timeline__item [data-act-done],
  .timeline__item [data-act-edit],
  .timeline__item [data-act-del] { opacity: 1; }
}

/* ------------------------------------------------------------- day plan */

.day-clock {
  font-variant-numeric: tabular-nums; font-weight: 700; font-size: 17px;
  letter-spacing: -.02em; color: var(--text);
}

.day-plan { position: relative; }
/* The spine runs behind the dots, down the time gutter. */
.day-plan::before {
  content: ''; position: absolute; left: 63px; top: 6px; bottom: 6px;
  width: 2px; background: var(--border);
}

.day-row { position: relative; display: flex; align-items: flex-start; gap: 12px; padding: 7px 0; }
.day-row__time {
  width: 46px; flex-shrink: 0; text-align: right;
  font-variant-numeric: tabular-nums; font-size: 12.5px; font-weight: 600;
  color: var(--text-muted); padding-top: 1px;
}
.day-row__dot {
  position: relative; z-index: 1; flex-shrink: 0; margin-top: 4px;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--surface); border: 2px solid var(--border-strong);
}
.day-row__body { flex: 1; min-width: 0; padding-bottom: 2px; }

.day-row--done .day-row__dot { border-color: var(--success); background: var(--success); }
.day-row--done .day-row__body .fw-600 { text-decoration: line-through; opacity: .6; }
.day-row--done .day-row__time { opacity: .55; }

.day-row--late .day-row__dot { border-color: var(--danger); background: var(--danger); }
.day-row--late .day-row__time { color: var(--danger); }

.day-row--next .day-row__dot { border-color: var(--brand); }
.day-row--next .day-row__body {
  background: var(--brand-soft); border-radius: 8px;
  margin: -5px -9px; padding: 5px 9px 6px;
}

/* The now line cuts across the whole plan. */
.day-now { position: relative; display: flex; align-items: center; gap: 8px; margin: 9px 0; }
.day-now::after {
  content: ''; flex: 1; height: 2px; border-radius: 2px;
  background: var(--danger); opacity: .55;
}
.day-now__label {
  flex-shrink: 0; font-size: 10.5px; font-weight: 700; letter-spacing: .07em;
  color: #fff; background: var(--danger);
  padding: 2px 8px; border-radius: 999px;
}

.day-row [data-day-done], .day-row [data-day-edit] { opacity: 0; transition: opacity .12s; }
.day-row:hover [data-day-done], .day-row:hover [data-day-edit],
.day-row [data-day-done]:focus, .day-row [data-day-edit]:focus { opacity: 1; }
@media (hover: none) {
  .day-row [data-day-done], .day-row [data-day-edit] { opacity: 1; }
}

@media (max-width: 640px) {
  .day-plan::before { left: 51px; }
  .day-row__time { width: 38px; }
}

/* Day groups under today's plan. */
.next-day + .next-day { margin-top: 14px; }
.next-day__label {
  font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-faint); padding: 10px 0 4px;
}
.next-day .day-row__time { color: var(--text-faint); }
.next-day .day-plan::before { opacity: .6; }

.day-summary { cursor: pointer; opacity: .7; }
.day-summary:hover { opacity: 1; }
.day-summary .day-row__dot { border-style: dashed; background: var(--surface); border-color: var(--border-strong); }

/* ------------------------------------------------------------ chat agent */

.chat-layout { display: grid; grid-template-columns: 232px minmax(0, 1fr); gap: 16px; align-items: start; }
.chat-sessions { padding: 8px; position: sticky; top: 82px; max-height: calc(100vh - 110px); overflow-y: auto; }

.chat-main { display: flex; flex-direction: column; height: calc(100vh - 178px); min-height: 440px; }
.chat-log { flex: 1; overflow-y: auto; padding: 18px; display: flex; flex-direction: column; gap: 14px; }

.chat-msg { display: flex; }
.chat-msg--user { justify-content: flex-end; }
.chat-bubble {
  max-width: 78%; padding: 11px 14px; border-radius: 14px;
  font-size: 14px; line-height: 1.6; word-wrap: break-word;
}
.chat-msg--user .chat-bubble { background: var(--brand); color: #fff; border-bottom-right-radius: 4px; }
.chat-msg--assistant .chat-bubble {
  background: var(--surface-2); border: 1px solid var(--border);
  border-bottom-left-radius: 4px;
}

/* What the agent actually did, shown above its answer. */
.chat-tools { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 9px; }
.chat-tool {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; font-weight: 600; padding: 2px 8px; border-radius: 999px;
  background: var(--success-soft); color: var(--success);
}
.chat-tool--error { background: var(--danger-soft); color: var(--danger); }
.chat-tool--running { background: var(--brand-soft); color: var(--brand-text); }
.chat-tool__spin {
  width: 9px; height: 9px; border: 1.5px solid currentColor; border-top-color: transparent;
  border-radius: 50%; display: inline-block; animation: spin .7s linear infinite;
}
/* While streaming the text is raw, so keep its line breaks. */
.chat-stream { white-space: pre-wrap; }
.chat-stream::after {
  content: '▋'; animation: caret 1s steps(2) infinite; opacity: .45; margin-left: 1px;
}
@keyframes caret { 50% { opacity: 0 } }

.chat-batch { max-width: 100%; border-color: var(--brand); background: var(--brand-soft); }

/* Markdown inside a reply: tighter than the docs page, and tables scroll
   rather than stretch the bubble past the panel. */
.chat-bubble > :first-child { margin-top: 0; }
.chat-bubble > :last-child { margin-bottom: 0; }
.chat-bubble p { margin: 6px 0; }
.chat-bubble h1, .chat-bubble h2, .chat-bubble h3 { font-size: 14.5px; margin: 12px 0 6px; }
.chat-bubble ul, .chat-bubble ol { margin: 6px 0; padding-left: 20px; }
.chat-bubble li { margin: 2px 0; }
.chat-bubble code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; font-size: 12.5px; }
.chat-bubble .code-block pre {
  background: var(--surface-3); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 12px; overflow-x: auto; margin: 8px 0; font-size: 12.5px;
}
.chat-bubble .code-block .copy-btn { display: none; }
.chat-bubble .table-scroll { overflow-x: auto; margin: 8px 0; }
.chat-bubble table { border-collapse: collapse; font-size: 13px; width: 100%; }
.chat-bubble th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-faint); padding: 6px 10px; border-bottom: 1px solid var(--border-strong); white-space: nowrap;
}
.chat-bubble td { padding: 6px 10px; border-bottom: 1px solid var(--border); }
.chat-bubble tbody tr:last-child td { border-bottom: none; }
.chat-bubble hr { border: none; border-top: 1px solid var(--border); margin: 12px 0; }
.chat-msg--user .chat-bubble code { background: rgba(255,255,255,.22); color: #fff; }

.chat-composer {
  display: flex; gap: 8px; align-items: flex-end;
  padding: 12px; border-top: 1px solid var(--border);
}
.chat-composer .textarea { min-height: 46px; max-height: 160px; resize: vertical; }
.chat-composer .btn { height: 40px; padding: 0 14px; }

.chat-welcome { margin: auto; text-align: center; max-width: 560px; padding: 20px; }
.chat-examples { display: flex; flex-direction: column; gap: 6px; }
.chat-examples .btn {
  text-align: left; justify-content: flex-start; white-space: normal;
  line-height: 1.45; padding: 9px 12px;
}

@media (max-width: 900px) {
  .chat-layout { grid-template-columns: 1fr; }
  .chat-sessions { position: static; max-height: 180px; }
  .chat-main { height: calc(100vh - 300px); }
  .chat-bubble { max-width: 92%; }
}

/* -------------------------------------------------------------- reminders */

.bell-badge {
  position: absolute; top: 1px; right: 1px;
  min-width: 15px; height: 15px; padding: 0 3px;
  border-radius: 999px; background: var(--warning); color: #fff;
  font-size: 9.5px; font-weight: 700; line-height: 15px; text-align: center;
  border: 2px solid var(--surface); box-sizing: content-box;
}
.bell-badge--overdue { background: var(--danger); animation: bell-pulse 1.8s ease-in-out infinite; }
@keyframes bell-pulse {
  0%, 100% { transform: scale(1); }
  50%      { transform: scale(1.18); }
}

/* One-time ask, bottom-left so it never covers the toasts. */
.notify-prompt {
  position: fixed; bottom: 20px; left: 20px; z-index: 150;
  width: min(370px, calc(100vw - 40px)); padding: 16px;
  box-shadow: var(--shadow-lg); border-color: var(--brand);
  animation: pop .2s ease;
}
@media (max-width: 640px) {
  .notify-prompt { left: 12px; right: 12px; bottom: 12px; width: auto; }
}

.bell-panel {
  position: absolute; top: calc(100% + 8px); right: 0;
  width: 310px; max-height: 420px; overflow-y: auto;
  padding: 8px; z-index: 60; box-shadow: var(--shadow-lg);
}

@media (prefers-reduced-motion: reduce) {
  .bell-badge--overdue { animation: none; }
}

/* --------------------------------------------------------------- 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%; }
}
