/* LiteCRM styles */
:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --border-strong: #d1d5db;
  --accent: #2563eb;
  --accent-hover: #1d4ed8;
  --accent-soft: #eef3ff;
  --on-accent: #ffffff;
  --danger: #dc2626;
  --danger-soft: #fef2f2;
  --warn: #c2410c;
  --radius: 10px;
  --shadow: 0 1px 2px rgb(16 24 40 / .05), 0 1px 3px rgb(16 24 40 / .07);
  --shadow-lg: 0 16px 40px rgb(16 24 40 / .18);
  --panel-w: 480px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0d1015;
    --surface: #151920;
    --surface-2: #1a1f27;
    --text: #e6e8eb;
    --muted: #9aa3b0;
    --border: #252b35;
    --border-strong: #343b47;
    --accent: #5b8def;
    --accent-hover: #7ba3f5;
    --accent-soft: #19243a;
    --danger: #f87171;
    --danger-soft: #2a1618;
    --warn: #fb923c;
    --shadow: none;
    --shadow-lg: 0 16px 40px rgb(0 0 0 / .55);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; }
body {
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0; letter-spacing: -.01em; }
h2 { font-size: 20px; margin: 0; letter-spacing: -.01em; }
h3 { font-size: 14px; margin: 0 0 12px; }
input, select, textarea, button { font: inherit; color: inherit; }
input, select, textarea {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  padding: 8px 10px;
  width: 100%;
  outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
textarea { resize: vertical; min-height: 64px; }
input[type=checkbox], input[type=radio] { width: auto; accent-color: var(--accent); margin: 0; }
label { display: block; font-weight: 500; }
label > input, label > select, label > textarea { margin-top: 4px; font-weight: 400; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.nowrap { white-space: nowrap; }
.grow { flex: 1; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.boot { padding: 40px; color: var(--muted); }
.loading, .empty { padding: 32px; text-align: center; color: var(--muted); }

.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.i.lg { width: 32px; height: 32px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  border-radius: 8px; padding: 7px 12px; font-weight: 500; cursor: pointer; text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); }
.btn:disabled { opacity: .5; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.primary:hover { background: var(--accent-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.danger-ghost { color: var(--danger); }
.btn.danger-ghost:hover { background: var(--danger-soft); }
.btn.sm { padding: 4px 9px; font-size: 13px; }
.btn.sm .i { width: 15px; height: 15px; }
.btn.lg { padding: 10px 18px; font-size: 15px; }
.btn.block { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--accent); cursor: pointer; font-weight: 500; display: inline-flex; align-items: center; gap: 4px; }
.link:hover { text-decoration: underline; }
.link.danger { color: var(--danger); }
.link.strong { color: var(--text); font-weight: 600; }
.icon-btn { background: none; border: 0; padding: 6px; border-radius: 8px; cursor: pointer; color: var(--muted); display: inline-flex; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.sm { padding: 3px; }
.icon-btn.sm .i { width: 15px; height: 15px; }
.pill { border: 1px solid var(--border-strong); background: var(--surface); border-radius: 999px; padding: 4px 10px; font-size: 12.5px; cursor: pointer; }
.pill:hover { border-color: var(--accent); color: var(--accent); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
.card.pad { padding: 18px; }

.chip {
  display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 500;
  padding: 2px 9px 2px 8px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--border); white-space: nowrap;
}
.chip i { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.att { margin-left: 6px; font-size: 12px; color: var(--muted); }
.tag { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 1px 8px; border-radius: 6px; background: var(--accent-soft); color: var(--accent); font-weight: 500; }
.tag .i { width: 13px; height: 13px; }
.tag.off { background: var(--danger-soft); color: var(--danger); }

/* ---------- login ---------- */
.login-page { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.login { width: 100%; max-width: 360px; padding: 28px; display: grid; gap: 14px; }
.login .brand { padding: 0 0 6px; font-size: 18px; }
.err { color: var(--danger); font-size: 13px; min-height: 1em; }

/* ---------- shell ---------- */
.shell { display: grid; grid-template-columns: 220px minmax(0, 1fr); min-height: 100vh; }
.side {
  position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; gap: 8px;
  background: var(--surface); border-right: 1px solid var(--border); padding: 16px 12px; z-index: 20;
}
.brand { display: flex; align-items: center; gap: 9px; font-weight: 700; font-size: 16px; padding: 4px 8px 14px; }
.brand svg { width: 26px; height: 26px; flex: none; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; }
.nav a {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px;
  color: var(--text); text-decoration: none; font-weight: 500;
}
.nav a:hover { background: var(--surface-2); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.badge { margin-left: auto; background: var(--danger); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 600; line-height: 1.5; }
.me { position: relative; }
.me summary { list-style: none; display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; cursor: pointer; }
.me summary::-webkit-details-marker { display: none; }
.me summary:hover { background: var(--surface-2); }
.avatar { width: 32px; height: 32px; border-radius: 50%; background: var(--accent-soft); color: var(--accent); display: grid; place-items: center; font-weight: 700; font-size: 13px; flex: none; }
.me-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.me-info { min-width: 0; }
.me-pop {
  position: absolute; bottom: calc(100% + 6px); left: 0; right: 0; background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg); padding: 6px; display: grid; z-index: 40;
}
.me-pop button { background: none; border: 0; text-align: left; padding: 8px 10px; border-radius: 6px; cursor: pointer; }
.me-pop button:hover { background: var(--surface-2); }

.main { padding: 24px 28px 56px; min-width: 0; transition: margin-right .18s ease; }
.head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 18px; }
.head h1 { flex: 1; min-width: 160px; }
.head-actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.head-actions .sel { width: auto; }

/* ---------- dashboard ---------- */
.tiles { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { text-align: left; padding: 16px 18px; cursor: pointer; font: inherit; color: inherit; }
.tile:disabled { cursor: default; }
.tile:not(:disabled):hover { border-color: var(--accent); }
.tile-n { font-size: 28px; font-weight: 700; letter-spacing: -.02em; font-variant-numeric: tabular-nums; }
.tile-l { color: var(--muted); font-weight: 500; }
.grid2 { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr); gap: 16px; align-items: start; }
.grid2 > :only-child { grid-column: 1 / -1; max-width: 640px; }
.bars { display: grid; gap: 4px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 56px; align-items: center; gap: 10px; background: none; border: 0; padding: 5px 6px; border-radius: 6px; cursor: pointer; text-align: left; }
.bar-row:hover { background: var(--surface-2); }
.bar-track { height: 8px; background: var(--surface-2); border-radius: 999px; overflow: hidden; border: 1px solid var(--border); }
.bar-fill { display: block; height: 100%; border-radius: 999px; min-width: 0; }
.bar-n { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }
.warn { color: var(--warn); font-weight: 600; }

/* ---------- tables ---------- */
.table-card { overflow-x: auto; }
.table-scroll { overflow-x: auto; }
.tbl { width: 100%; border-collapse: collapse; }
.tbl th {
  text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); padding: 10px 12px;
  border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap;
}
.tbl th.num { text-align: right; }
.tbl td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.tbl tbody tr:last-child td { border-bottom: 0; }
.tbl.compact td, .tbl.compact th { padding: 7px 10px; }
.tbl.leads tbody tr, .tbl tr.click { cursor: pointer; }
.tbl.leads tbody tr:hover, .tbl tr.click:hover { background: var(--surface-2); }
.tbl tr.current, .tbl tr.current:hover { background: var(--accent-soft); }
.tbl tr.inactive td { opacity: .55; }
.tbl td.actions { text-align: right; white-space: nowrap; }
.tbl td.actions .btn + .btn { margin-left: 4px; }
.tbl th.ck, .tbl td.ck { width: 36px; padding-right: 0; }
.tbl td.due { color: var(--danger); font-weight: 600; }
.tbl td.pre { white-space: pre-line; font-size: 12.5px; color: var(--muted); }
.tbl td.ell { max-width: 220px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nm { font-weight: 600; }
.m-only { display: none; }
.sub .due-t { color: var(--danger); font-weight: 600; }
.sub { color: var(--muted); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 360px; }

.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.filters .sel { width: auto; max-width: 220px; }
.search { position: relative; flex: 1 1 240px; max-width: 380px; font-weight: 400; }
.search .i { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--muted); width: 16px; height: 16px; }
.search input { padding-left: 34px; margin: 0; }
.sel.sm { padding: 4px 8px; font-size: 13px; width: auto; }

.bulkbar {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 10px 12px; margin-bottom: 12px;
  background: var(--accent-soft); border: 1px solid var(--accent); border-radius: var(--radius);
}
.bulkbar .sep { flex: 1; }
.pager { display: flex; align-items: center; justify-content: flex-end; gap: 8px; margin-top: 12px; }

/* ---------- lead panel ---------- */
.scrim { position: fixed; inset: 0; background: rgb(0 0 0 / .3); z-index: 29; }
.panel {
  position: fixed; top: 0; right: 0; bottom: 0; width: min(var(--panel-w), 100%);
  background: var(--surface); border-left: 1px solid var(--border); box-shadow: var(--shadow-lg);
  display: flex; flex-direction: column; z-index: 30;
  transform: translateX(100%); visibility: hidden; transition: transform .18s ease, visibility 0s linear .18s;
}
.panel.open { transform: none; visibility: visible; transition: transform .18s ease; }
@media (min-width: 1180px) {
  .scrim { display: none; }
  .shell.panel-open .main { margin-right: var(--panel-w); }
  .shell.panel-open .hide-md { display: none; }
}
.p-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.p-body { flex: 1; overflow-y: auto; padding: 18px 20px 28px; display: grid; gap: 22px; align-content: start; }
.p-title { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.p-line { display: flex; align-items: center; gap: 8px; margin: 6px 0; color: var(--muted); }
.p-line a { color: var(--text); text-decoration: none; font-weight: 500; }
.p-line a:hover { color: var(--accent); }
.p-line a.phone { font-size: 18px; font-weight: 600; letter-spacing: .01em; }
.p-meta { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.p-meta label { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.p-meta select { margin: 0; max-width: 170px; }
.p-contact.edit { display: grid; gap: 10px; }
.p-label { font-weight: 600; margin-bottom: 8px; display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.st-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
.st-btn {
  display: flex; align-items: center; gap: 7px; text-align: left; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); border-radius: 8px; padding: 8px 9px; font-weight: 500; cursor: pointer;
  font-size: 13px; line-height: 1.2;
}
.st-btn::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--c); flex: none; }
.st-btn:hover { border-color: var(--c); }
.st-btn.on { background: var(--c); border-color: var(--c); color: #fff; }
.st-btn.on::before { background: #fff; }
.st-btn kbd { margin-left: auto; font: 11px ui-monospace, monospace; opacity: .55; }
.cb-set { margin-top: 10px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; padding: 9px 12px; border-radius: 8px; background: var(--accent-soft); }
.cb-set.due { background: var(--danger-soft); color: var(--danger); }
.cb-edit { margin-top: 12px; padding: 12px; border: 1px dashed var(--border-strong); border-radius: 8px; display: grid; gap: 10px; }
.quick { display: flex; gap: 6px; flex-wrap: wrap; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row input { flex: 1 1 180px; width: auto; }
.row-end { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.timeline { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 14px; }
.timeline li { border-left: 2px solid var(--border); padding-left: 12px; }
.timeline li.tl-note, .timeline li.tl-import { border-left-color: var(--accent); }
.tl-meta { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
.tl-meta b { color: var(--text); font-weight: 600; }
.note-body { white-space: pre-wrap; word-break: break-word; }
.p-foot { border-top: 1px solid var(--border); padding-top: 14px; }

/* ---------- import ---------- */
.drop {
  display: grid; justify-items: center; gap: 6px; padding: 48px 20px; border: 2px dashed var(--border-strong);
  cursor: pointer; text-align: center; color: var(--muted); font-weight: 400;
}
.drop:hover, .drop.over { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.drop-t { font-size: 16px; font-weight: 600; color: var(--text); }
.imp-file { display: flex; align-items: center; gap: 10px; margin-bottom: 16px; flex-wrap: wrap; }
.imp-grid { display: grid; grid-template-columns: minmax(0, 1.3fr) minmax(0, 1fr); gap: 16px; margin-bottom: 16px; align-items: start; }
.imp-grid h3 + * { margin-bottom: 4px; }
.imp-grid section > h3:not(:first-child) { margin-top: 20px; }
.check { display: flex; align-items: center; gap: 8px; font-weight: 400; padding: 4px 0; cursor: pointer; }
.check select { width: auto; margin: 0; }
.checks { display: grid; gap: 0; }
.indent { padding-left: 24px; }
.map { margin: 10px 0; }
.map select { min-width: 120px; }
.imp-go { display: flex; justify-content: flex-end; align-items: center; gap: 16px; margin-top: 16px; }
.done { text-align: center; padding: 40px 20px; display: grid; gap: 10px; justify-items: center; }
.done .big { font-size: 40px; font-weight: 700; letter-spacing: -.02em; }

/* ---------- access ---------- */
#main > .card + .card, #main > .card + p { margin-top: 14px; }
.access-status { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; border-left: 4px solid var(--border-strong); }
.access-status.on { border-left-color: var(--accent); }
.access-status h3 { margin: 0 0 4px; font-size: 15px; }
.access-status p { margin: 0; }
.myip { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.ip-form { margin-bottom: 12px; }
.ip-form input { flex: 1 1 200px; }

/* ---------- modal ---------- */
.modal-wrap { position: fixed; inset: 0; background: rgb(0 0 0 / .4); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { width: 100%; max-width: 440px; padding: 22px; display: grid; gap: 14px; max-height: calc(100vh - 32px); overflow-y: auto; }
.modal h3 { font-size: 17px; margin: 0; }
.m-body { display: grid; gap: 12px; }
.m-body p { margin: 0; }
.m-foot { display: flex; justify-content: flex-end; gap: 8px; }
.m-err:empty { display: none; }
.m-err { color: var(--danger); font-size: 13px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.pw-row { display: flex; gap: 6px; margin-top: 4px; }
.pw-row input { margin: 0; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: #111827; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-lg);
  transition: opacity .15s, transform .15s; z-index: 60; max-width: calc(100% - 32px); font-weight: 500;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.err { background: var(--danger); }

/* ---------- responsive ---------- */
@media (max-width: 1100px) {
  .hide-md { display: none; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid2, .imp-grid { grid-template-columns: minmax(0, 1fr); }
  .grid2 > :only-child { max-width: none; }
}
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto 1fr; }
  .m-only { display: block; }
  .side { position: sticky; top: 0; height: auto; flex-direction: row; align-items: center; padding: 8px 12px; border-right: 0; border-bottom: 1px solid var(--border); }
  .brand { padding: 0; }
  .brand span { display: none; }
  .nav { flex-direction: row; overflow-x: auto; gap: 2px; }
  .nav a { padding: 7px 9px; position: relative; }
  .nav a span { display: none; }
  .nav .badge { position: absolute; top: 0; right: -2px; font-size: 10px; padding: 0 5px; }
  .me summary { padding: 2px; }
  .me-info { display: none; }
  .me-pop { left: auto; right: 0; bottom: auto; top: calc(100% + 6px); min-width: 180px; }
  .main { padding: 16px 16px 48px; }
  .hide-sm { display: none; }
  .sub { max-width: 50vw; }
  .tbl td, .tbl th { padding-left: 9px; padding-right: 9px; }
  .bar-row { grid-template-columns: 120px 1fr 44px; }
  .st-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .st-btn kbd { display: none; }
  .row2 { grid-template-columns: 1fr; }
  .filters .sel { flex: 1 1 140px; max-width: none; }
  .search { max-width: none; flex-basis: 100%; }
}
