:root {
  --brand: #4f46e5;
  --brand-600: #4f46e5;
  --brand-700: #4338ca;
  --brand-soft: #eef2ff;
  --bg: #f6f7fb;
  --panel: #ffffff;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e6e8ef;
  --line-soft: #eef1f6;
  --good: #16a34a;
  --warn: #d97706;
  --bad: #dc2626;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.06), 0 1px 3px rgba(16,24,40,.1);
  --shadow-lg: 0 10px 30px rgba(16,24,40,.12);
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  font-family: 'Inter', system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: var(--bg);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}
a { color: var(--brand-700); text-decoration: none; }
.boot { display: grid; place-items: center; height: 100vh; color: var(--muted); }

/* ---------- Auth screens ---------- */
.auth-wrap { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-hero {
  background: linear-gradient(150deg, var(--brand-700), var(--brand-600) 55%, #7c3aed);
  color: #fff; padding: 56px; display: flex; flex-direction: column; justify-content: center;
}
.auth-hero h1 { font-size: 40px; line-height: 1.1; margin: 0 0 16px; font-weight: 800; letter-spacing: -.02em; }
.auth-hero p { font-size: 17px; opacity: .92; max-width: 460px; line-height: 1.6; }
.auth-features { margin-top: 34px; display: grid; gap: 12px; }
.auth-features div { display: flex; gap: 10px; align-items: center; opacity: .95; }
.auth-features .dot { width: 22px; height: 22px; border-radius: 50%; background: rgba(255,255,255,.2); display: grid; place-items: center; font-size: 13px; }
.auth-panel { display: grid; place-items: center; padding: 32px; }
.auth-card { width: 100%; max-width: 380px; }
.auth-card h2 { margin: 0 0 6px; font-size: 24px; font-weight: 700; }
.auth-card .sub { color: var(--muted); margin: 0 0 24px; }
@media (max-width: 860px) { .auth-wrap { grid-template-columns: 1fr; } .auth-hero { display: none; } }

/* ---------- Forms ---------- */
label.field { display: block; margin-bottom: 14px; }
label.field span { display: block; font-weight: 600; margin-bottom: 6px; font-size: 13px; }
input, select, textarea {
  width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px;
  font: inherit; color: var(--ink); background: #fff; outline: none; transition: border .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft); }
textarea { min-height: 90px; resize: vertical; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 16px; border-radius: 10px; border: 1px solid transparent; background: var(--brand);
  color: #fff; font-weight: 600; cursor: pointer; font-size: 14px; transition: filter .15s, transform .05s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(1px); }
.btn.block { width: 100%; }
.btn.secondary { background: #fff; color: var(--ink); border-color: var(--line); }
.btn.ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn.danger { background: var(--bad); }
.btn.sm { padding: 6px 11px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.err { color: var(--bad); font-size: 13px; margin: 8px 0; min-height: 18px; }
.muted { color: var(--muted); }
.link-btn { background: none; border: none; color: var(--brand-700); cursor: pointer; font: inherit; padding: 0; }

/* ---------- App layout ---------- */
.layout { display: grid; grid-template-columns: 250px 1fr; min-height: 100vh; }
.sidebar { background: #0f1729; color: #cbd5e1; display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; padding: 18px 18px; border-bottom: 1px solid rgba(255,255,255,.07); }
.brand .logo { width: 34px; height: 34px; border-radius: 9px; background: var(--brand); display: grid; place-items: center; color: #fff; font-weight: 800; overflow: hidden; flex: none; }
.brand .logo img { width: 100%; height: 100%; object-fit: cover; }
.brand .name { font-weight: 700; color: #fff; font-size: 15px; line-height: 1.1; }
.brand .name small { display: block; color: #64748b; font-weight: 500; font-size: 11px; }
.nav { padding: 10px; overflow-y: auto; flex: 1; }
.nav .group { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: #64748b; padding: 14px 12px 6px; }
.nav a { display: flex; align-items: center; gap: 11px; padding: 9px 12px; border-radius: 9px; color: #cbd5e1; font-weight: 500; margin-bottom: 2px; }
.nav a:hover { background: rgba(255,255,255,.06); color: #fff; }
.nav a.active { background: var(--brand); color: #fff; }
.nav a .ico { width: 18px; text-align: center; opacity: .9; }
.nav a .badge { margin-left: auto; background: var(--bad); color: #fff; border-radius: 20px; font-size: 11px; padding: 1px 7px; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar { display: flex; align-items: center; gap: 14px; padding: 12px 22px; background: var(--panel); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 20; }
.topbar .page-title { font-size: 17px; font-weight: 700; }
.subswitch { position: relative; margin-left: auto; }
.subswitch button { display: flex; align-items: center; gap: 8px; padding: 7px 12px; border: 1px solid var(--line); background: #fff; border-radius: 10px; cursor: pointer; font: inherit; font-weight: 600; }
.subswitch .caret { color: var(--muted); }
.menu { position: absolute; right: 0; top: calc(100% + 6px); background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow-lg); min-width: 240px; padding: 6px; z-index: 50; }
.menu .item { display: flex; align-items: center; gap: 8px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.menu .item:hover { background: var(--bg); }
.menu .item.active { background: var(--brand-soft); color: var(--brand-700); font-weight: 600; }
.menu .divider { height: 1px; background: var(--line); margin: 6px 4px; }
.avatar { width: 34px; height: 34px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-700); display: grid; place-items: center; font-weight: 700; cursor: pointer; }

.content { padding: 22px; max-width: 1300px; width: 100%; margin: 0 auto; }

/* ---------- Cards / tables ---------- */
.card { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.card .card-h { display: flex; align-items: center; gap: 10px; padding: 14px 16px; border-bottom: 1px solid var(--line-soft); }
.card .card-h h3 { margin: 0; font-size: 15px; font-weight: 700; }
.card .card-b { padding: 16px; }
.grid { display: grid; gap: 16px; }
.kpis { grid-template-columns: repeat(4, 1fr); }
.kpi { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.kpi .k-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.kpi .k-val { font-size: 26px; font-weight: 800; margin-top: 6px; letter-spacing: -.02em; }
.kpi .k-ico { float: right; width: 38px; height: 38px; border-radius: 10px; background: var(--brand-soft); color: var(--brand-700); display: grid; place-items: center; font-size: 18px; }
@media (max-width: 1050px) { .kpis { grid-template-columns: repeat(2, 1fr); } }

table.tbl { width: 100%; border-collapse: collapse; }
table.tbl th { text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding: 10px 14px; border-bottom: 1px solid var(--line); }
table.tbl td { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.tbl tr:last-child td { border-bottom: none; }
table.tbl tr.clickable { cursor: pointer; }
table.tbl tr.clickable:hover { background: var(--bg); }

.tag { display: inline-block; background: var(--brand-soft); color: var(--brand-700); border-radius: 20px; padding: 2px 10px; font-size: 12px; font-weight: 600; margin: 0 4px 4px 0; }
.pill { display: inline-flex; align-items: center; gap: 5px; border-radius: 20px; padding: 3px 10px; font-size: 12px; font-weight: 600; }
.pill.green { background: #dcfce7; color: #166534; }
.pill.gray { background: #eef1f6; color: #475569; }
.pill.amber { background: #fef3c7; color: #92400e; }
.pill.red { background: #fee2e2; color: #991b1b; }
.pill.blue { background: #dbeafe; color: #1e40af; }

.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; }
.page-head h1 { margin: 0; font-size: 22px; font-weight: 800; letter-spacing: -.02em; }
.page-head .spacer { flex: 1; }
.toolbar { display: flex; gap: 10px; align-items: center; margin-bottom: 16px; flex-wrap: wrap; }
.search { max-width: 300px; }
.empty { text-align: center; color: var(--muted); padding: 40px 20px; }
.empty .big { font-size: 36px; margin-bottom: 8px; }

/* ---------- Kanban ---------- */
.board { display: flex; gap: 14px; overflow-x: auto; padding-bottom: 12px; align-items: flex-start; }
.col { background: #eef1f6; border-radius: 12px; width: 280px; flex: none; }
.col-h { display: flex; align-items: center; gap: 8px; padding: 12px 14px; font-weight: 700; font-size: 13px; }
.col-h .count { color: var(--muted); font-weight: 600; }
.col-h .sum { margin-left: auto; color: var(--brand-700); font-weight: 700; font-size: 12px; }
.col-b { padding: 0 10px 10px; min-height: 40px; display: flex; flex-direction: column; gap: 8px; }
.col-b.drop-over { outline: 2px dashed var(--brand); outline-offset: -4px; border-radius: 10px; }
.oppcard { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 11px 12px; box-shadow: var(--shadow); cursor: grab; }
.oppcard:active { cursor: grabbing; }
.oppcard .t { font-weight: 600; }
.oppcard .v { color: var(--good); font-weight: 700; margin-top: 4px; }
.oppcard .c { color: var(--muted); font-size: 12px; margin-top: 4px; }

/* ---------- Conversations ---------- */
.inbox { display: grid; grid-template-columns: 320px 1fr; height: calc(100vh - 150px); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; background: #fff; }
.conv-list { border-right: 1px solid var(--line); overflow-y: auto; }
.conv-item { padding: 12px 14px; border-bottom: 1px solid var(--line-soft); cursor: pointer; display: flex; gap: 10px; }
.conv-item:hover, .conv-item.active { background: var(--bg); }
.conv-item .who { font-weight: 600; }
.conv-item .prev { color: var(--muted); font-size: 13px; margin-top: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 210px; }
.thread { display: flex; flex-direction: column; }
.thread-h { padding: 14px 16px; border-bottom: 1px solid var(--line); font-weight: 700; display: flex; gap: 10px; align-items: center; }
.thread-b { flex: 1; overflow-y: auto; padding: 18px; background: var(--bg); display: flex; flex-direction: column; gap: 10px; }
.bubble { max-width: 70%; padding: 10px 13px; border-radius: 14px; line-height: 1.4; }
.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 .meta { font-size: 11px; opacity: .7; margin-top: 4px; }
.thread-f { padding: 12px; border-top: 1px solid var(--line); display: flex; gap: 10px; }
.thread-f input { flex: 1; }

/* ---------- Contact detail ---------- */
.detail { display: grid; grid-template-columns: 320px 1fr; gap: 16px; align-items: start; }
@media (max-width: 900px) { .detail, .inbox { grid-template-columns: 1fr; } .kpis { grid-template-columns: 1fr 1fr; } }
.timeline .ev { display: flex; gap: 12px; padding: 10px 0; border-bottom: 1px solid var(--line-soft); }
.timeline .ev .dot { width: 30px; height: 30px; border-radius: 50%; background: var(--brand-soft); color: var(--brand-700); display: grid; place-items: center; flex: none; font-size: 13px; }
.timeline .ev .txt { flex: 1; }
.timeline .ev .when { color: var(--muted); font-size: 12px; }

/* funnel */
.funnel { display: grid; gap: 8px; }
.funnel .row { display: grid; grid-template-columns: 140px 1fr 46px; align-items: center; gap: 10px; }
.funnel .bar { height: 26px; background: var(--brand); border-radius: 6px; min-width: 4px; }
.funnel .row:nth-child(2) .bar { opacity: .85; } .funnel .row:nth-child(3) .bar { opacity: .7; }
.funnel .row:nth-child(4) .bar { opacity: .55; } .funnel .row:nth-child(5) .bar { opacity: .4; }

/* integrations */
.intg-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
@media (max-width: 900px){ .intg-grid { grid-template-columns: 1fr; } }
.intg { border: 1px solid var(--line); border-radius: 12px; padding: 14px; background: #fff; display: flex; flex-direction: column; gap: 8px; }
.intg .top { display: flex; align-items: center; gap: 10px; }
.intg .ic { width: 40px; height: 40px; border-radius: 10px; background: var(--brand-soft); display: grid; place-items: center; font-size: 18px; }
.intg .nm { font-weight: 700; }
.intg .ds { color: var(--muted); font-size: 13px; flex: 1; }
.stage-tab { display: inline-flex; gap: 6px; }

/* modal */
.modal-back { position: fixed; inset: 0; background: rgba(15,23,42,.45); display: grid; place-items: center; z-index: 100; padding: 20px; }
.modal { background: #fff; border-radius: 16px; box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto; }
.modal .m-h { padding: 16px 20px; border-bottom: 1px solid var(--line); font-weight: 700; font-size: 16px; display: flex; align-items: center; }
.modal .m-b { padding: 20px; }
.modal .m-f { padding: 14px 20px; border-top: 1px solid var(--line); display: flex; gap: 10px; justify-content: flex-end; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* toast */
#toast-host { position: fixed; right: 20px; bottom: 20px; display: flex; flex-direction: column; gap: 10px; z-index: 200; }
.toast { background: #0f1729; color: #fff; padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 500; max-width: 340px; animation: pop .2s ease; }
.toast.good { background: #14532d; } .toast.bad { background: #7f1d1d; }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

.stars { color: #f59e0b; letter-spacing: 2px; }
.hint { background: var(--brand-soft); color: var(--brand-700); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin-bottom: 14px; }
code.copy { background: var(--bg); padding: 2px 7px; border-radius: 6px; cursor: pointer; border: 1px solid var(--line); font-size: 12px; }

/* ---------- print (invoices, reports) ---------- */
@media print {
  .sidebar, .topbar, .no-print, .page-head button, .page-head a.btn { display: none !important; }
  .layout { grid-template-columns: 1fr !important; }
  .content { padding: 0 !important; max-width: none !important; }
  .card { border: none !important; box-shadow: none !important; }
  body { background: #fff !important; }
  a[href]::after { content: none !important; }
}
