:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --panel-2: #fafbfc;
  --line: #e3e6ea;
  --line-soft: #eef0f3;
  --ink: #14181f;
  --ink-2: #5b6572;
  --ink-3: #8b95a3;
  --brand: #0f5ef7;
  --brand-soft: #e8f0ff;
  --ok: #0f9d58;
  --ok-soft: #e6f6ed;
  --warn: #e8890c;
  --warn-soft: #fdf1e0;
  --crit: #dc2b2b;
  --crit-soft: #fdeaea;
  --info: #2d7ff9;
  --info-soft: #e8f1fe;
  --radius: 12px;
  --radius-s: 8px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 8px 24px rgba(16, 24, 40, .06);
  --shadow-s: 0 1px 2px rgba(16, 24, 40, .08);
  font-size: 15px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0; height: 100%;
  background: var(--bg); color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: var(--brand); text-decoration: none; }
button, input, select, textarea { font: inherit; color: inherit; }

/* ---------------------------------------------------------------- layout */
#app { height: 100%; }
.shell { display: grid; grid-template-columns: 232px 1fr; height: 100%; }

.sidebar {
  background: #0e1420; color: #cbd3e0; padding: 16px 12px;
  display: flex; flex-direction: column; gap: 4px; overflow-y: auto;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 6px 10px 18px; }
.brand .logo {
  width: 30px; height: 30px; border-radius: 8px; background: var(--brand);
  display: grid; place-items: center; color: #fff; font-weight: 800; font-size: 14px;
}
.brand b { color: #fff; font-size: 15px; letter-spacing: .2px; }
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 9px 11px; border-radius: var(--radius-s);
  cursor: pointer; color: #aab4c5; font-size: 14px; border: 0; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: #182134; color: #fff; }
.nav-item.active { background: var(--brand); color: #fff; font-weight: 600; }
.nav-item .badge { margin-left: auto; }
.nav-spacer { flex: 1; }
.sidebar-foot { border-top: 1px solid #1d283c; padding-top: 12px; font-size: 12px; color: #7d889b; }

.main { display: flex; flex-direction: column; overflow: hidden; }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 12px 20px;
  background: var(--panel); border-bottom: 1px solid var(--line); flex-shrink: 0;
}
.topbar h1 { font-size: 17px; margin: 0; font-weight: 650; }
.topbar .spacer { flex: 1; }
.search { position: relative; }
.search input {
  width: 260px; padding: 8px 12px 8px 32px; border: 1px solid var(--line);
  border-radius: 20px; background: var(--panel-2); outline: none;
}
.search input:focus { border-color: var(--brand); background: #fff; }
.search .icon { position: absolute; left: 11px; top: 8px; color: var(--ink-3); }
.content { padding: 20px; overflow-y: auto; flex: 1; }

/* ---------------------------------------------------------------- bits */
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: 8px 14px; border-radius: var(--radius-s); cursor: pointer; font-size: 14px;
  display: inline-flex; align-items: center; gap: 7px; white-space: nowrap;
}
.btn:hover { background: var(--panel-2); border-color: #d3d8df; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #0b4ed0; }
.btn.ghost { border-color: transparent; background: transparent; color: var(--ink-2); }
.btn.ghost:hover { background: var(--line-soft); }
.btn.danger { color: var(--crit); border-color: #f3d4d4; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow-s);
}
.card-head {
  padding: 14px 16px; border-bottom: 1px solid var(--line-soft);
  display: flex; align-items: center; gap: 10px;
}
.card-head h2 { margin: 0; font-size: 15px; font-weight: 650; }
.card-head .spacer { flex: 1; }
.card-body { padding: 16px; }

.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(165px, 1fr)); }
.grid.split { grid-template-columns: 1.4fr 1fr; align-items: start; }
.grid.two { grid-template-columns: 1fr 1fr; align-items: start; }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.kpi .label { font-size: 12.5px; color: var(--ink-2); display: flex; align-items: center; gap: 6px; }
.kpi .value { font-size: 25px; font-weight: 680; margin-top: 6px; letter-spacing: -.5px; }
.kpi .sub { font-size: 12px; color: var(--ink-3); margin-top: 3px; }
.kpi.alarm .value { color: var(--crit); }
.kpi.good .value { color: var(--ok); }

.pill {
  display: inline-flex; align-items: center; gap: 5px; padding: 2px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; background: var(--line-soft); color: var(--ink-2); white-space: nowrap;
}
.pill.crit { background: var(--crit-soft); color: var(--crit); }
.pill.warn { background: var(--warn-soft); color: var(--warn); }
.pill.info { background: var(--info-soft); color: var(--info); }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.brand { background: var(--brand-soft); color: var(--brand); }
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: var(--crit);
  color: #fff; font-size: 11.5px; font-weight: 700; display: inline-grid; place-items: center;
}
.badge.muted { background: #3a465c; color: #cbd3e0; }

.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.crit { background: var(--crit); } .dot.warn { background: var(--warn); }
.dot.info { background: var(--info); } .dot.ok { background: var(--ok); }

.muted { color: var(--ink-2); }
.dim { color: var(--ink-3); font-size: 13px; }
.row { display: flex; align-items: center; gap: 10px; }
.col { display: flex; flex-direction: column; gap: 4px; }
.wrap { flex-wrap: wrap; }
.right { margin-left: auto; }
.empty { padding: 34px; text-align: center; color: var(--ink-3); }
.empty .big { font-size: 30px; display: block; margin-bottom: 8px; }

/* ---------------------------------------------------------------- forms */
label.field { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--ink-2); }
label.field > span { font-weight: 550; }
input[type=text], input[type=password], input[type=email], input[type=number],
input[type=datetime-local], select, textarea {
  padding: 9px 11px; border: 1px solid var(--line); border-radius: var(--radius-s);
  background: #fff; outline: none; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px rgba(15,94,247,.12); }
textarea { resize: vertical; min-height: 74px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 13px; }
.form-grid .full { grid-column: 1 / -1; }
.switch { display: flex; align-items: center; gap: 9px; cursor: pointer; font-size: 14px; }
.switch input { width: 16px; height: 16px; accent-color: var(--brand); }

/* ---------------------------------------------------------------- table */
table { width: 100%; border-collapse: collapse; }
th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--ink-3); font-weight: 650; padding: 10px 12px; border-bottom: 1px solid var(--line);
}
td { padding: 11px 12px; border-bottom: 1px solid var(--line-soft); font-size: 14px; vertical-align: middle; }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--panel-2); }

/* ---------------------------------------------------------------- alerts */
.alert-row {
  display: flex; gap: 12px; padding: 13px 16px; border-bottom: 1px solid var(--line-soft);
  cursor: pointer; align-items: flex-start;
}
.alert-row:hover { background: var(--panel-2); }
.alert-row:last-child { border-bottom: 0; }
.alert-row .bar { width: 3px; align-self: stretch; border-radius: 2px; background: var(--warn); flex-shrink: 0; }
.alert-row.critical .bar { background: var(--crit); }
.alert-row.info .bar { background: var(--info); }
.alert-row .title { font-weight: 600; font-size: 14px; }
.alert-row .detail { font-size: 13px; color: var(--ink-2); margin-top: 3px; line-height: 1.45; }

/* ---------------------------------------------------------------- kanban */
.board { display: flex; gap: 12px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.column { flex: 0 0 268px; background: #eceff3; border-radius: var(--radius); padding: 10px; }
.column.drop { outline: 2px dashed var(--brand); outline-offset: -3px; background: var(--brand-soft); }
.column h3 { margin: 2px 4px 10px; font-size: 13px; font-weight: 650; display: flex; align-items: center; gap: 7px; }
.column h3 .count { color: var(--ink-3); font-weight: 600; }
.column h3 .sum { margin-left: auto; font-size: 12px; color: var(--ink-3); font-weight: 600; }
.lead-card {
  background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px;
  margin-bottom: 9px; cursor: grab; box-shadow: var(--shadow-s);
}
.lead-card:hover { border-color: #c9d2dd; }
.lead-card.dragging { opacity: .45; }
.lead-card .name { font-weight: 620; font-size: 14px; }
.lead-card .meta { display: flex; gap: 6px; align-items: center; margin-top: 7px; flex-wrap: wrap; font-size: 12px; color: var(--ink-3); }
.lead-card .amount { font-size: 13px; color: var(--ink-2); margin-top: 4px; font-weight: 600; }
.lead-card.crit { border-left: 3px solid var(--crit); }
.lead-card.warn { border-left: 3px solid var(--warn); }
.lead-card.info { border-left: 3px solid var(--info); }

.chan { width: 17px; height: 17px; border-radius: 5px; display: inline-grid; place-items: center; font-size: 10px; color: #fff; font-weight: 700; }
.chan.telegram { background: #229ed9; } .chan.whatsapp { background: #25d366; }
.chan.instagram { background: linear-gradient(45deg,#f9ce34,#ee2a7b,#6228d7); }
.chan.phone { background: #64748b; } .chan.email { background: #7c3aed; }
.chan.other, .chan.walkin { background: #94a3b8; }

/* ---------------------------------------------------------------- funnel */
.funnel-row { display: grid; grid-template-columns: 118px 1fr 90px; gap: 10px; align-items: center; margin-bottom: 9px; }
.funnel-bar { height: 24px; border-radius: 6px; background: var(--brand); min-width: 3px; opacity: .9; }
.funnel-bar.won { background: var(--ok); } .funnel-bar.lost { background: #b9c1cc; }
.funnel-track { background: var(--line-soft); border-radius: 6px; }

/* ---------------------------------------------------------------- chat */
.inbox { display: grid; grid-template-columns: 330px 1fr; gap: 16px; height: calc(100vh - 122px); }
.conv-list { overflow-y: auto; }
.conv {
  display: flex; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--line-soft); cursor: pointer;
}
.conv:hover, .conv.active { background: var(--brand-soft); }
.conv .avatar {
  width: 36px; height: 36px; border-radius: 50%; background: #dde3ea; display: grid; place-items: center;
  font-weight: 700; color: var(--ink-2); font-size: 13px; flex-shrink: 0;
}
.conv .who { font-weight: 620; font-size: 14px; display: flex; align-items: center; gap: 6px; }
.conv .snippet { font-size: 13px; color: var(--ink-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
.conv .who { flex-wrap: wrap; }
.conv > .dim { flex-shrink: 0; margin-left: auto; white-space: nowrap; }
.chat { display: flex; flex-direction: column; overflow: hidden; }
.chat-body { flex: 1; overflow-y: auto; padding: 18px; background: var(--panel-2); display: flex; flex-direction: column; gap: 9px; }
.bubble { max-width: 74%; padding: 9px 13px; border-radius: 14px; font-size: 14px; line-height: 1.45; }
.bubble .txt { white-space: pre-wrap; word-break: break-word; }
.bubble.in { background: #fff; border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.bubble.out { background: var(--brand); color: #fff; align-self: flex-end; border-bottom-right-radius: 4px; }
.bubble .when { font-size: 11px; opacity: .65; margin-top: 4px; }
.bubble.failed { background: var(--crit-soft); color: var(--crit); border: 1px solid #f3d4d4; }
.chat-foot { border-top: 1px solid var(--line); padding: 12px; display: flex; gap: 9px; background: var(--panel); }
.chat-foot textarea { min-height: 42px; max-height: 130px; }

/* ---------------------------------------------------------------- drawer */
.overlay {
  position: fixed; inset: 0; background: rgba(15, 22, 33, .42); z-index: 40;
  display: flex; justify-content: flex-end;
}
.drawer {
  width: min(720px, 100%); background: var(--bg); height: 100%;
  display: flex; flex-direction: column; box-shadow: -8px 0 32px rgba(0,0,0,.16);
  animation: slide .18s ease-out;
}
@keyframes slide { from { transform: translateX(28px); opacity: .5; } to { transform: none; opacity: 1; } }
.drawer-head { padding: 16px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.drawer-body { overflow-y: auto; padding: 18px 20px; display: flex; flex-direction: column; gap: 16px; }
.modal {
  background: var(--panel); border-radius: var(--radius); width: min(560px, 100%);
  margin: auto; box-shadow: var(--shadow); max-height: 90vh; overflow-y: auto;
}
.overlay.center { justify-content: center; align-items: center; padding: 20px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-top: 12px; }
.tab { padding: 8px 13px; border: 0; background: none; cursor: pointer; color: var(--ink-2); font-size: 14px; border-bottom: 2px solid transparent; }
.tab.active { color: var(--brand); border-bottom-color: var(--brand); font-weight: 620; }

.timeline { display: flex; flex-direction: column; gap: 0; }
.tl-item { display: flex; gap: 11px; padding: 11px 0; border-bottom: 1px solid var(--line-soft); }
.tl-item:last-child { border-bottom: 0; }
.tl-icon { width: 26px; height: 26px; border-radius: 50%; background: var(--line-soft); display: grid; place-items: center; font-size: 12px; flex-shrink: 0; }
.tl-body { font-size: 14px; line-height: 1.5; }
.tl-when { font-size: 12px; color: var(--ink-3); margin-top: 2px; }

/* ---------------------------------------------------------------- login */
.login-wrap { height: 100%; display: grid; place-items: center; background: linear-gradient(160deg, #0e1420, #16233c); }
.login {
  background: #fff; padding: 30px; border-radius: 16px; width: min(390px, 92vw);
  box-shadow: 0 24px 60px rgba(0,0,0,.3); display: flex; flex-direction: column; gap: 14px;
}
.login h1 { margin: 0; font-size: 20px; }
.login .hint { font-size: 13px; color: var(--ink-2); margin-top: -6px; }
.error { background: var(--crit-soft); color: var(--crit); padding: 9px 12px; border-radius: var(--radius-s); font-size: 13px; }
.notice { background: var(--ok-soft); color: var(--ok); padding: 9px 12px; border-radius: var(--radius-s); font-size: 13px; }

/* ---------------------------------------------------------------- toast */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 9px; z-index: 90; }
.toast {
  background: #14181f; color: #fff; padding: 11px 15px; border-radius: var(--radius-s);
  font-size: 13.5px; box-shadow: var(--shadow); max-width: 340px; animation: slide .15s ease-out;
}
.toast.err { background: var(--crit); }
.toast.ok { background: var(--ok); }

.code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px; padding: 8px 10px;
  word-break: break-all; user-select: all;
}

/* ---------------------------------------------------------------- mobile */
@media (max-width: 900px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    flex-direction: row; overflow-x: auto; padding: 8px; gap: 6px; align-items: center;
  }
  .brand { padding: 0 8px 0 4px; } .brand b { display: none; }
  .nav-item { width: auto; padding: 8px 10px; }
  .nav-item span.txt { display: none; }
  .nav-spacer, .sidebar-foot { display: none; }
  .inbox { grid-template-columns: 1fr; height: auto; }
  .inbox .chat { min-height: 62vh; }
  .form-grid { grid-template-columns: 1fr; }
  .grid.split, .grid.two { grid-template-columns: 1fr; }
  .search input { width: 150px; }
  .content { padding: 14px; }
}
