/* ------------------------------------------------------------------ *
 * Tokens                                                               *
 * ------------------------------------------------------------------ */
:root {
  color-scheme: light dark;

  --bg:          #f6f7f9;
  --surface:     #ffffff;
  --surface-2:   #fbfbfc;
  --surface-3:   #f1f2f5;
  --border:      #e2e4e9;
  --border-2:    #d3d6dd;
  --text:        #16181d;
  --text-2:      #5b6070;
  --text-3:      #666c7c;
  --accent:      #5b47e0;
  --accent-soft: #ede9fe;
  --accent-text: #4a37c8;
  --green:       #167a52;
  --green-soft:  #dcf5e9;
  --amber:       #9a6206;
  --amber-soft:  #fdf0d5;
  --red:         #b02a2a;
  --red-soft:    #fbe3e3;
  --blue:        #1a5fb4;
  --blue-soft:   #dce9fb;
  --slate-soft:  #eceef2;

  --radius:   10px;
  --radius-s: 7px;
  --shadow:   0 1px 2px rgba(16,18,24,.06), 0 4px 16px rgba(16,18,24,.05);
  --shadow-lg:0 8px 40px rgba(16,18,24,.16);

  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Inter, Roboto, sans-serif;
}

/* Dark tokens live in one place and are applied three ways: to an explicit
   dark choice, and to the system preference unless light was chosen. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg:          #0e0f13;
    --surface:     #16181d;
    --surface-2:   #1b1e24;
    --surface-3:   #22262e;
    --border:      #282c34;
    --border-2:    #363b45;
    --text:        #e8eaef;
    --text-2:      #a2a9b8;
    --text-3:      #878fa1;
    --accent:      #8b7cf6;
    --accent-soft: #2a2450;
    --accent-text: #b3a6ff;
    --green:       #4ade80;
    --green-soft:  #14311f;
    --amber:       #fbbf60;
    --amber-soft:  #38290c;
    --red:         #f87171;
    --red-soft:    #3a1717;
    --blue:        #7cb0f8;
    --blue-soft:   #12294a;
    --slate-soft:  #24272f;
    --shadow:   0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    --shadow-lg:0 8px 40px rgba(0,0,0,.6);
  }
}

:root[data-theme="dark"] {
    --bg:          #0e0f13;
    --surface:     #16181d;
    --surface-2:   #1b1e24;
    --surface-3:   #22262e;
    --border:      #282c34;
    --border-2:    #363b45;
    --text:        #e8eaef;
    --text-2:      #a2a9b8;
    --text-3:      #878fa1;
    --accent:      #8b7cf6;
    --accent-soft: #2a2450;
    --accent-text: #b3a6ff;
    --green:       #4ade80;
    --green-soft:  #14311f;
    --amber:       #fbbf60;
    --amber-soft:  #38290c;
    --red:         #f87171;
    --red-soft:    #3a1717;
    --blue:        #7cb0f8;
    --blue-soft:   #12294a;
    --slate-soft:  #24272f;
    --shadow:   0 1px 2px rgba(0,0,0,.4), 0 4px 16px rgba(0,0,0,.3);
    --shadow-lg:0 8px 40px rgba(0,0,0,.6);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--sans);
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent-text); }

/* ------------------------------------------------------------------ *
 * Shell                                                                *
 * ------------------------------------------------------------------ */
.app {
  display: grid;
  grid-template-columns: 220px 1fr;
  grid-template-rows: 54px 1fr;
  grid-template-areas: "brand topbar" "nav main";
  height: 100vh;
}

.brand {
  grid-area: brand;
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 0 16px;
  border-right: 1px solid var(--border);
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  font-weight: 650;
  letter-spacing: -.01em;
}
.brand .logo {
  width: 26px; height: 26px;
  display: grid; place-items: center;
  border-radius: 7px;
  background: linear-gradient(140deg, var(--accent), #a855f7);
  color: #fff; font-size: 14px; font-weight: 700;
  flex: none;
}
.brand small { display: block; font-weight: 400; font-size: 10.5px; color: var(--text-3); letter-spacing: .02em; }

.topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.nav {
  grid-area: nav;
  background: var(--surface);
  border-right: 1px solid var(--border);
  padding: 10px 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
.nav-item {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 10px;
  border-radius: var(--radius-s);
  cursor: pointer;
  color: var(--text-2);
  font-weight: 500;
  border: 0; background: none; width: 100%; text-align: left;
}
.nav-item:hover { background: var(--surface-3); color: var(--text); }
.nav-item.active { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.nav-item .ico { width: 16px; text-align: center; opacity: .85; flex: none; }
.nav-item .count { margin-left: auto; font-size: 11px; color: var(--text-3); font-variant-numeric: tabular-nums; }
.nav-sep { margin: 10px 10px 6px; font-size: 10.5px; text-transform: uppercase; letter-spacing: .07em; color: var(--text-3); font-weight: 600; }

.main {
  grid-area: main;
  overflow-y: auto;
  padding: 20px 24px 60px;
  scroll-behavior: smooth;
}
.main.flush { padding: 0; }

/* ------------------------------------------------------------------ *
 * Controls                                                             *
 * ------------------------------------------------------------------ */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 13px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  font-weight: 550;
  white-space: nowrap;
  transition: background .12s, border-color .12s, transform .06s;
}
.btn:hover:not(:disabled) { background: var(--surface-3); border-color: var(--text-3); }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--surface-3); }
.btn.danger { color: var(--red); border-color: var(--border-2); }
.btn.danger:hover:not(:disabled) { background: var(--red-soft); border-color: var(--red); }
.btn.sm { padding: 4px 9px; font-size: 12.5px; }

.input, .select, textarea.input {
  padding: 7px 10px;
  border-radius: var(--radius-s);
  border: 1px solid var(--border-2);
  background: var(--surface);
  color: var(--text);
  width: 100%;
  outline: none;
}
.input:focus, .select:focus, textarea.input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}
.input::placeholder { color: var(--text-3); }
textarea.input { resize: vertical; min-height: 72px; font-family: inherit; }

.search {
  position: relative;
  flex: 1;
  max-width: 460px;
}
.search .input { padding-left: 30px; }
.search .mag {
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  color: var(--text-3); pointer-events: none; font-size: 13px;
}

.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 12px; font-weight: 600;
  color: var(--text-2);
  margin-bottom: 5px;
}
.field .hint { font-size: 11.5px; color: var(--text-3); margin-top: 5px; line-height: 1.45; }

.check { display: flex; align-items: center; gap: 7px; cursor: pointer; padding: 3px 0; font-size: 13px; }
.check input { accent-color: var(--accent); width: 14px; height: 14px; }

/* ------------------------------------------------------------------ *
 * Cards, tables, chips                                                 *
 * ------------------------------------------------------------------ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-h {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
  font-weight: 620;
}
.card-h .sub { font-weight: 400; color: var(--text-3); font-size: 12.5px; }
.card-b { padding: 16px; }

.page-h {
  display: flex; align-items: flex-end; gap: 12px;
  margin-bottom: 16px; flex-wrap: wrap;
}
.page-h h1 { margin: 0; font-size: 21px; letter-spacing: -.02em; font-weight: 660; }
.page-h .sub { color: var(--text-3); font-size: 13px; }
.page-h .spacer { flex: 1; }

.grid { display: grid; gap: 14px; }
.kpis { grid-template-columns: repeat(auto-fit, minmax(178px, 1fr)); }

.kpi { padding: 14px 16px; }
.kpi .label {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); font-weight: 600; margin-bottom: 6px;
}
.kpi .value { font-size: 25px; font-weight: 660; letter-spacing: -.025em; font-variant-numeric: tabular-nums; }
.kpi .value.sm { font-size: 19px; }
.kpi .foot { font-size: 12px; color: var(--text-3); margin-top: 3px; }

table.tbl { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.tbl th {
  text-align: left;
  font-size: 11px; text-transform: uppercase; letter-spacing: .055em;
  color: var(--text-3); font-weight: 650;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  position: sticky; top: 0; z-index: 2;
  white-space: nowrap;
}
table.tbl th.sortable { cursor: pointer; user-select: none; }
table.tbl th.sortable:hover { color: var(--text); }
table.tbl th.on { color: var(--accent-text); }
table.tbl td {
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
table.tbl tbody tr { cursor: pointer; }
table.tbl tbody tr:hover td { background: var(--surface-2); }
table.tbl tbody tr.sel td { background: var(--accent-soft); }
table.tbl .num { text-align: right; }
table.tbl .nowrap { white-space: nowrap; }

.tbl-wrap { overflow: auto; max-height: calc(100vh - 250px); }

.chip {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 2px 8px;
  border-radius: 100px;
  font-size: 11.5px; font-weight: 600;
  background: var(--slate-soft); color: var(--text-2);
  white-space: nowrap;
}
.chip.green { background: var(--green-soft); color: var(--green); }
.chip.amber { background: var(--amber-soft); color: var(--amber); }
.chip.red   { background: var(--red-soft);   color: var(--red); }
.chip.blue  { background: var(--blue-soft);  color: var(--blue); }
.chip.violet{ background: var(--accent-soft);color: var(--accent-text); }

.tag {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 2px 7px; border-radius: 5px;
  background: var(--accent-soft); color: var(--accent-text);
  font-size: 11.5px; font-weight: 550;
}
.tag button { border: 0; background: none; cursor: pointer; color: inherit; opacity: .6; padding: 0; line-height: 1; }
.tag button:hover { opacity: 1; }

.avatar {
  width: 30px; height: 30px; border-radius: 50%;
  display: grid; place-items: center;
  background: var(--accent-soft); color: var(--accent-text);
  font-size: 11.5px; font-weight: 680; flex: none;
  text-transform: uppercase;
}
.avatar.lg { width: 46px; height: 46px; font-size: 16px; }

.who { display: flex; align-items: center; gap: 10px; min-width: 0; }
.who .nm { font-weight: 570; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who .em { font-size: 12px; color: var(--text-3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.muted { color: var(--text-3); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.right { text-align: right; }
.row { display: flex; align-items: center; gap: 8px; }
.wrap { flex-wrap: wrap; }
.spacer { flex: 1; }

/* ------------------------------------------------------------------ *
 * Bars & charts                                                        *
 * ------------------------------------------------------------------ */
.bar-track { height: 6px; border-radius: 100px; background: var(--surface-3); overflow: hidden; min-width: 60px; }
.bar-fill  { height: 100%; border-radius: 100px; background: var(--accent); }

.spark { display: flex; align-items: flex-end; gap: 2px; height: 130px; }
.spark .col { flex: 1; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; gap: 3px; min-width: 0; }
.spark .bar {
  width: 100%; border-radius: 3px 3px 0 0;
  background: var(--accent); opacity: .85; min-height: 2px;
  transition: opacity .12s;
}
.spark .col:hover .bar { opacity: 1; }
.spark .lab { font-size: 9.5px; color: var(--text-3); white-space: nowrap; transform: rotate(-45deg); transform-origin: center; height: 12px; }

/* ------------------------------------------------------------------ *
 * Contacts split view                                                  *
 * ------------------------------------------------------------------ */
.split { display: grid; grid-template-columns: 1fr; height: 100%; }
.split.open { grid-template-columns: 1fr minmax(420px, 33%); }

.list-pane { min-width: 0; display: flex; flex-direction: column; height: 100%; }
.list-toolbar {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  display: flex; align-items: center; gap: 9px; flex-wrap: wrap;
}
.list-scroll { overflow: auto; flex: 1; }

.detail-pane {
  border-left: 1px solid var(--border);
  background: var(--surface);
  overflow-y: auto;
  height: 100%;
}
.detail-h {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; background: var(--surface); z-index: 3;
}
.detail-b { padding: 16px 20px 60px; }

.kv { display: grid; grid-template-columns: 104px 1fr; gap: 6px 12px; font-size: 13px; }
.kv dt { color: var(--text-3); }
.kv dd { margin: 0; word-break: break-word; }

.sect-t {
  font-size: 11px; text-transform: uppercase; letter-spacing: .06em;
  color: var(--text-3); font-weight: 650;
  margin: 22px 0 9px;
  display: flex; align-items: center; gap: 8px;
}
.sect-t::after { content: ''; flex: 1; height: 1px; background: var(--border); }

.ord {
  border: 1px solid var(--border);
  border-radius: var(--radius-s);
  margin-bottom: 9px;
  overflow: hidden;
  background: var(--surface-2);
}
.ord-h {
  padding: 9px 12px;
  display: flex; align-items: center; gap: 9px;
  cursor: pointer;
  flex-wrap: nowrap;
}
.ord-h > .date { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ord-h > .chev { transition: transform .15s; flex: none; }
.ord.open > .ord-h > .chev { transform: rotate(180deg); }
.ord-h > .cnt { flex: none; }
.ord-h:hover { background: var(--surface-3); }
.ord-b { padding: 0 12px 12px; border-top: 1px solid var(--border); }
.ord table { width: 100%; border-collapse: collapse; font-size: 12.5px; }
.ord table td { padding: 6px 0; border-bottom: 1px dashed var(--border); }
.ord table tr:last-child td { border-bottom: 0; }

.mini-stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 1px; background: var(--border); border: 1px solid var(--border); border-radius: var(--radius-s); overflow: hidden; }
.mini-stats > div { background: var(--surface); padding: 10px 12px; }
.mini-stats .l { font-size: 10.5px; text-transform: uppercase; letter-spacing: .05em; color: var(--text-3); font-weight: 600; }
.mini-stats .v { font-size: 16px; font-weight: 640; margin-top: 2px; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ *
 * Filters drawer                                                       *
 * ------------------------------------------------------------------ */
.filters {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px 14px;
  align-items: end;
}
.filters .field { margin: 0; }

/* ------------------------------------------------------------------ *
 * Modal / onboarding                                                   *
 * ------------------------------------------------------------------ */
.backdrop {
  position: fixed; inset: 0;
  background: rgba(10,11,15,.55);
  backdrop-filter: blur(3px);
  display: grid; place-items: center;
  z-index: 100;
  padding: 20px;
  overflow-y: auto;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  box-shadow: var(--shadow-lg);
  width: min(600px, 100%);
  max-height: 92vh;
  overflow-y: auto;
}
.modal-h { padding: 20px 22px 0; }
.modal-h h2 { margin: 0 0 5px; font-size: 18px; letter-spacing: -.02em; }
.modal-h p { margin: 0; color: var(--text-2); font-size: 13px; line-height: 1.55; }
.modal-b { padding: 18px 22px; }
.modal-f {
  padding: 14px 22px;
  border-top: 1px solid var(--border);
  display: flex; gap: 9px; justify-content: flex-end;
  position: sticky; bottom: 0; background: var(--surface);
}

.notice {
  padding: 11px 13px;
  border-radius: var(--radius-s);
  font-size: 12.5px;
  line-height: 1.55;
  border: 1px solid;
}
.notice.info  { background: var(--blue-soft);  border-color: transparent; color: var(--blue); }
.notice.ok    { background: var(--green-soft); border-color: transparent; color: var(--green); }
.notice.warn  { background: var(--amber-soft); border-color: transparent; color: var(--amber); }
.notice.error { background: var(--red-soft);   border-color: transparent; color: var(--red); }
.notice strong { display: block; margin-bottom: 3px; }

.steps { counter-reset: s; margin: 0; padding: 0; list-style: none; }
.steps li {
  counter-increment: s;
  position: relative;
  padding: 0 0 11px 27px;
  font-size: 13px; line-height: 1.55; color: var(--text-2);
}
.steps li::before {
  content: counter(s);
  position: absolute; left: 0; top: 1px;
  width: 18px; height: 18px; border-radius: 50%;
  background: var(--accent-soft); color: var(--accent-text);
  font-size: 10.5px; font-weight: 700;
  display: grid; place-items: center;
}
.steps code { background: var(--surface-3); padding: 1px 5px; border-radius: 4px; font-size: 12px; font-family: var(--mono); }

/* ------------------------------------------------------------------ *
 * Sync progress                                                        *
 * ------------------------------------------------------------------ */
.sync-pill {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 11px;
  border-radius: 100px;
  background: var(--accent-soft);
  color: var(--accent-text);
  font-size: 12.5px; font-weight: 570;
  max-width: 420px;
}
.sync-pill .dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: currentColor;
  animation: pulse 1.3s ease-in-out infinite;
  flex: none;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .3; } }
.sync-pill .txt { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.progress { height: 4px; background: var(--surface-3); border-radius: 100px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); transition: width .4s ease; }

.log {
  font-family: var(--mono); font-size: 11.5px; line-height: 1.65;
  background: var(--surface-3);
  border-radius: var(--radius-s);
  padding: 10px 12px;
  max-height: 190px; overflow-y: auto;
  color: var(--text-2);
  white-space: pre-wrap; word-break: break-word;
}

.empty {
  text-align: center;
  padding: 56px 20px;
  color: var(--text-3);
}
.empty .big { font-size: 34px; margin-bottom: 10px; opacity: .5; }
.empty h3 { margin: 0 0 6px; color: var(--text-2); font-size: 15px; font-weight: 600; }
.empty p { margin: 0 auto; max-width: 380px; font-size: 13px; line-height: 1.6; }

.spin {
  width: 15px; height: 15px;
  border: 2px solid var(--border-2);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
  flex: none;
}
@keyframes spin { to { transform: rotate(360deg); } }

.toast-host {
  position: fixed; bottom: 18px; right: 18px;
  display: flex; flex-direction: column; gap: 8px;
  z-index: 200; max-width: 400px;
}
.toast {
  padding: 11px 14px;
  border-radius: var(--radius-s);
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow-lg);
  font-size: 13px;
  animation: slidein .18s ease;
}
.toast.error { border-left: 3px solid var(--red); }
.toast.ok    { border-left: 3px solid var(--green); }
@keyframes slidein { from { transform: translateX(14px); opacity: 0; } }

@media (max-width: 900px) {
  .app { grid-template-columns: 60px 1fr; }
  .brand span.full, .nav-item span.lbl { display: none; }
  .split.open { grid-template-columns: 1fr; }
  .split.open .list-pane { display: none; }
}

/* ------------------------------------------------------------------ *
 * Segment builder                                                      *
 * ------------------------------------------------------------------ */
.seg-layout { display: grid; grid-template-columns: 236px 1fr; gap: 16px; align-items: start; }

.seg-saved { position: sticky; top: 0; }
.seg-saved .item {
  display: flex; align-items: center; gap: 7px;
  padding: 7px 10px; border-radius: var(--radius-s);
  cursor: pointer; font-size: 13px; color: var(--text-2);
}
.seg-saved .item:hover { background: var(--surface-3); color: var(--text); }
.seg-saved .item.on { background: var(--accent-soft); color: var(--accent-text); font-weight: 600; }
.seg-saved .item .x { margin-left: auto; opacity: 0; border: 0; background: none; cursor: pointer; color: inherit; }
.seg-saved .item:hover .x { opacity: .6; }
.seg-saved .item .x:hover { opacity: 1; color: var(--red); }

.rgroup {
  border: 1px solid var(--border-2);
  border-radius: var(--radius-s);
  background: var(--surface-2);
  margin-bottom: 9px;
}
.rgroup.depth-1 { background: var(--surface); }
.rgroup.depth-2 { background: var(--surface-2); }
.rgroup-h {
  display: flex; align-items: center; gap: 9px;
  padding: 8px 11px;
  border-bottom: 1px solid var(--border);
}
.rgroup-b { padding: 11px; }

.andor { display: inline-flex; border: 1px solid var(--border-2); border-radius: 6px; overflow: hidden; }
.andor button {
  border: 0; background: var(--surface); color: var(--text-2);
  padding: 3px 11px; cursor: pointer; font-size: 12px; font-weight: 650;
}
.andor button.on { background: var(--accent); color: #fff; }

.cond {
  display: flex; align-items: flex-start; gap: 7px; flex-wrap: wrap;
  padding: 8px; margin-bottom: 7px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
}
.cond > .select, .cond > .input { width: auto; min-width: 90px; }
.cond .fieldsel { min-width: 176px; }
.cond .opsel { min-width: 128px; }
.cond .val { min-width: 110px; }
.cond .kill { margin-left: auto; border: 0; background: none; cursor: pointer; color: var(--text-3); padding: 4px 6px; border-radius: 5px; }
.cond .kill:hover { background: var(--red-soft); color: var(--red); }

.submatch {
  display: flex; flex-wrap: wrap; gap: 7px; align-items: center;
  width: 100%; margin-top: 7px; padding: 9px;
  background: var(--surface-2);
  border: 1px dashed var(--border-2);
  border-radius: 6px;
}
.submatch .lbl { font-size: 11.5px; color: var(--text-3); font-weight: 600; }
.submatch select, .submatch input { width: auto; }
.submatch select[multiple] { min-width: 150px; height: 74px; }

.seg-count {
  display: flex; align-items: baseline; gap: 9px;
  padding: 13px 16px;
  background: var(--accent-soft);
  border-radius: var(--radius-s);
  margin-bottom: 12px;
}
.seg-count .n { font-size: 26px; font-weight: 680; color: var(--accent-text); font-variant-numeric: tabular-nums; letter-spacing: -.02em; }
.seg-count .w { color: var(--accent-text); font-size: 13px; }

.tmpl {
  display: block; width: 100%; text-align: left;
  padding: 9px 11px; margin-bottom: 7px;
  border: 1px solid var(--border); border-radius: var(--radius-s);
  background: var(--surface); cursor: pointer;
}
.tmpl:hover { border-color: var(--accent); background: var(--surface-2); }
.tmpl strong { display: block; font-size: 13px; margin-bottom: 2px; }
.tmpl span { font-size: 12px; color: var(--text-3); line-height: 1.45; }

@media (max-width: 1000px) { .seg-layout { grid-template-columns: 1fr; } .seg-saved { position: static; } }

/* ------------------------------------------------------------------ *
 * Contact drawer                                                       *
 * ------------------------------------------------------------------ */
/* Animated on insertion rather than by toggling a class, so the panel is never
   left off-screen if a render frame does not arrive. */
/* Purely a visual dim. It does not catch clicks, so a row behind the drawer can
   be clicked straight through to swap contacts without closing first. */
.drawer-scrim {
  position: fixed; inset: 0;
  background: rgba(10, 11, 15, .28);
  z-index: 90;
  pointer-events: none;
  animation: scrim-in .18s ease both;
}
.drawer {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: min(520px, 94vw);
  z-index: 91;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -14px 0 42px rgba(16, 18, 24, .16);
  overflow-y: auto;
  animation: drawer-in .2s cubic-bezier(.32, .72, 0, 1) both;
}
.drawer-scrim.out { animation: scrim-in .16s ease reverse both; }
.drawer.out       { animation: drawer-in .16s ease reverse both; }

@keyframes drawer-in { from { transform: translateX(100%); } to { transform: translateX(0); } }
@keyframes scrim-in  { from { opacity: 0; } to { opacity: 1; } }

@media (prefers-reduced-motion: reduce) {
  .drawer, .drawer-scrim, .drawer.out, .drawer-scrim.out { animation: none; }
}

/* The drawer reuses the contact detail markup, so give it the same spacing
   the split-view pane has. */
.drawer .detail-h { position: sticky; top: 0; background: var(--surface); z-index: 3; }

.drawer-loading { display: grid; place-items: center; height: 160px; }

/* The awaiting-payment tile is a doorway into the matching segment. */
.kpi.awaiting { border-color: var(--amber); }
.kpi.awaiting .value { color: var(--amber); }
.kpi.awaiting:hover { background: var(--amber-soft); }

/* ------------------------------------------------------------------ *
 * Forecast                                                             *
 * ------------------------------------------------------------------ */
.fc-filters {
  display: flex; flex-wrap: wrap; align-items: flex-end; gap: 10px 14px;
  padding: 12px 16px; background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.fc-filters .field { margin: 0; }
.fc-filters .select, .fc-filters .input { width: auto; min-width: 120px; }

.gauge { display: inline-flex; align-items: center; gap: 7px; }
.gauge .track { width: 44px; height: 6px; border-radius: 100px; background: var(--surface-3); overflow: hidden; }
.gauge .fill { height: 100%; border-radius: 100px; background: var(--accent); }
.gauge .fill.hot { background: var(--green); }
.gauge .fill.warm { background: var(--amber); }
.gauge .fill.cold { background: var(--text-3); }
.gauge .pct { font-variant-numeric: tabular-nums; font-weight: 600; min-width: 34px; }

.why { font-size: 11.5px; color: var(--text-3); line-height: 1.4; }
.due-chip {
  display: inline-block; padding: 2px 8px; border-radius: 100px;
  font-size: 11.5px; font-weight: 650; white-space: nowrap;
}
.due-chip.now  { background: var(--green-soft); color: var(--green); }
.due-chip.soon { background: var(--amber-soft); color: var(--amber); }
.due-chip.late { background: var(--red-soft);   color: var(--red); }
.due-chip.far  { background: var(--slate-soft); color: var(--text-3); }

.model-card { font-size: 12.5px; line-height: 1.6; color: var(--text-2); }
.model-card dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 0; }
.model-card dt { color: var(--text-3); white-space: nowrap; }
.model-card dd { margin: 0; font-variant-numeric: tabular-nums; }

/* ------------------------------------------------------------------ *
 * Sales pipeline                                                       *
 * ------------------------------------------------------------------ */
.pl-cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(310px, 1fr)); gap: 14px; align-items: start; }

.rep { border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.rep-h {
  padding: 11px 14px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 9px;
}
.rep-h .nm { font-weight: 640; }
.rep-h .meta { font-size: 11.5px; color: var(--text-3); }
.rep-b { max-height: 560px; overflow-y: auto; }

.call {
  display: grid; grid-template-columns: 46px 1fr; gap: 9px;
  padding: 9px 12px; border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.call:hover { background: var(--surface-2); }
.call.done { opacity: .5; }
.call.won { background: var(--green-soft); }
.call .slot { font-variant-numeric: tabular-nums; font-weight: 650; color: var(--accent-text); font-size: 12.5px; padding-top: 2px; }
.call .nm { font-weight: 570; font-size: 13px; }
.call .sub { font-size: 11.5px; color: var(--text-3); line-height: 1.45; }
.call .tel { font-family: var(--mono); font-size: 12px; }

.outcomes { display: flex; gap: 4px; margin-top: 6px; flex-wrap: wrap; }
.outcomes button {
  border: 1px solid var(--border-2); background: var(--surface);
  border-radius: 5px; padding: 2px 7px; font-size: 11px; cursor: pointer; color: var(--text-2);
}
.outcomes button:hover { border-color: var(--accent); color: var(--accent-text); }
.outcomes button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.outcomes button.won.on { background: var(--green); border-color: var(--green); }

.slider-row { display: flex; align-items: center; gap: 12px; }
.slider-row input[type=range] { flex: 1; accent-color: var(--accent); }
.slider-row .ends { font-size: 11.5px; color: var(--text-3); white-space: nowrap; }

.team-row {
  display: flex; align-items: center; gap: 9px;
  padding: 9px 0; border-bottom: 1px solid var(--border);
}
.team-row:last-child { border-bottom: 0; }

/* ------------------------------------------------------------------ *
 * Hosted CRM: sign-in, account, dialer, calls                          *
 * ------------------------------------------------------------------ */

/* Author rules like .app { display: grid } would otherwise beat [hidden]. */
[hidden] { display: none !important; }

.btn.block { width: 100%; justify-content: center; }
.linkbtn { background: none; border: 0; padding: 0; color: var(--accent-text); cursor: pointer; font: inherit; text-decoration: underline; }

/* Sign-in screens */
.auth-wrap {
  min-height: 100vh; display: grid; place-items: center; padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--accent-soft), transparent 70%), var(--bg);
}
.auth-card {
  width: min(400px, 100%); background: var(--surface); border: 1px solid var(--border);
  border-radius: 14px; box-shadow: var(--shadow-lg); padding: 28px 26px 24px;
}
.auth-card h1 { font-size: 21px; letter-spacing: -.015em; margin: 18px 0 6px; }
.auth-card .field { margin-bottom: 12px; }
.auth-card .btn.block { margin-top: 6px; padding: 10px 13px; }
.auth-brand { display: flex; align-items: center; gap: 11px; }
.auth-brand .logo {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: var(--accent); color: #fff; font-weight: 800; font-size: 19px;
}
.auth-brand .t { font-weight: 700; letter-spacing: -.01em; }
.auth-brand .s { font-size: 12.5px; color: var(--text-3); }
.auth-sub { color: var(--text-2); font-size: 13.5px; margin: 0 0 16px; }
.auth-foot { color: var(--text-3); font-size: 12.5px; text-align: center; margin: 14px 0 0; }
.auth-err { margin: 4px 0 8px; }

.user-btn {
  width: 34px; height: 34px; padding: 0; border-radius: 50%; justify-content: center;
  font-size: 12.5px; font-weight: 700; background: var(--accent-soft); color: var(--accent-text); border-color: transparent;
}

.linkbox { display: flex; gap: 8px; }
.linkbox .input { flex: 1; font-size: 12.5px; }

/* The dock: a softphone pinned bottom-right, above the contact drawer, below dialogs. */
.dock {
  position: fixed; right: 18px; bottom: 18px; z-index: 95;
  display: flex; flex-direction: column; align-items: flex-end; gap: 10px;
  pointer-events: none;
}
.dock > * { pointer-events: auto; }
.dock-pill {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 14px; border-radius: 999px;
  border: 1px solid var(--border-2); background: var(--surface); color: var(--text); font-weight: 600;
  box-shadow: var(--shadow); cursor: pointer;
}
.dock-pill.ready { border-color: var(--green); color: var(--green); }
.dock-pill.warn { border-color: var(--amber); color: var(--amber); background: var(--amber-soft); }
.dock-pill.off { color: var(--text-3); }
.dock-pill.loading { color: var(--text-2); }
.dock-panel {
  width: 300px; background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  box-shadow: var(--shadow-lg); overflow: hidden;
}
.dock-h {
  display: flex; align-items: center; gap: 8px; padding: 11px 14px;
  border-bottom: 1px solid var(--border); background: var(--surface-2); font-size: 13.5px;
}
.dock-h .btn { margin-left: auto; }
.dock-b { padding: 13px 14px 14px; }
.dock-who { font-size: 16px; font-weight: 650; letter-spacing: -.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dock-num { color: var(--text-3); font-family: var(--mono); font-size: 12.5px; margin-bottom: 12px; }
.dock-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 10px; }
.dock-actions .btn { flex: 1; justify-content: center; }
.dock-timer { margin-left: auto; font-size: 13px; color: var(--green); }
.dock .wrap-outcomes { margin: 6px 0 10px; }
.dock textarea { width: 100%; resize: vertical; font-size: 13px; }
.live-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--amber); flex: none; }
.live-dot.on { background: var(--green); animation: live-pulse 1.6s infinite; }
.live-dot.ring { background: var(--accent); animation: live-pulse .8s infinite; }
@keyframes live-pulse { 0%, 100% { opacity: 1; } 50% { opacity: .35; } }
.keypad { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.keypad .btn { justify-content: center; font-family: var(--mono); font-size: 15px; padding: 8px 0; }
.wrap-outcomes button { font-size: 12px; padding: 4px 9px; }

/* A contact's calls, in the contact panel */
.calls-box .dial-row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.calls-box .hours { font-size: 12.5px; margin-top: 7px; }
.calls-box .hours.ok { color: var(--green); }
.calls-box .hours.no { color: var(--amber); }
.call-list { margin-top: 10px; }
.call-item { border: 1px solid var(--border); border-radius: var(--radius-s); padding: 10px 12px; margin-bottom: 8px; background: var(--surface); }
.ci-h { display: flex; align-items: flex-start; gap: 10px; }
.ci-dir {
  width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; flex: none;
  font-size: 13px; background: var(--slate-soft); color: var(--text-2);
}
.ci-dir.in { background: var(--blue-soft); color: var(--blue); }
.ci-dir.out { background: var(--green-soft); color: var(--green); }
.ci-main { flex: 1; min-width: 0; }
.ci-t { font-weight: 600; font-size: 13.5px; }
.ci-t .chip { margin-left: 4px; }
.ci-sub { color: var(--text-3); font-size: 12px; margin-top: 2px; }
.ci-note { font-size: 13px; margin-top: 7px; padding: 6px 9px; border-radius: 6px; background: var(--surface-3); white-space: pre-wrap; }
.ci-audio { width: 100%; height: 34px; margin-top: 8px; }
.ci-tr { margin-top: 8px; font-size: 13px; }
.ci-tr summary { cursor: pointer; color: var(--accent-text); font-weight: 550; }
.tr-lines { margin-top: 8px; display: flex; flex-direction: column; gap: 6px; max-height: 360px; overflow-y: auto; }
.tr-line { padding: 6px 9px; border-radius: 8px; max-width: 92%; line-height: 1.45; }
.tr-line.agent { align-self: flex-end; background: var(--accent-soft); }
.tr-line.cust { align-self: flex-start; background: var(--surface-3); }
.tr-who { display: block; font-size: 10.5px; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--text-3); margin-bottom: 2px; }

.dial-btn { margin-left: 6px; padding: 1px 8px; font-size: 11.5px; }
.calls-page .call-item:last-child { margin-bottom: 0; }
.cl-pager { display: flex; align-items: center; justify-content: center; gap: 12px; margin-top: 12px; }

/* Communication timeline, in the contact panel: one closed row until opened */
.comm-box { margin-top: 16px; }
.comm-loading { padding: 10px 12px; border: 1px solid var(--border); border-radius: var(--radius-s); font-size: 13.5px; font-weight: 640; }
details.comm { border: 1px solid var(--border); border-radius: var(--radius-s); background: var(--surface); }
details.comm > summary {
  list-style: none; display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; cursor: pointer; user-select: none; border-radius: var(--radius-s);
}
details.comm > summary::-webkit-details-marker { display: none; }
details.comm > summary:hover { background: var(--surface-2); }
details.comm > summary:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
details.comm[open] > summary { border-bottom: 1px solid var(--border); border-radius: var(--radius-s) var(--radius-s) 0 0; }
.comm-t { font-weight: 640; font-size: 13.5px; }
.comm-s { flex: 1; min-width: 0; color: var(--text-3); font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.comm-chev { color: var(--text-3); font-size: 11px; transition: transform .15s; }
details.comm[open] > summary .comm-chev { transform: rotate(180deg); }
.comm-b { padding: 10px 12px 12px; }
.comm-filters { display: flex; gap: 6px; margin-bottom: 10px; }
.comm-filters button {
  font: inherit; font-size: 12px; padding: 3px 11px; border-radius: 100px; cursor: pointer;
  border: 1px solid var(--border); background: var(--surface); color: var(--text-2);
}
.comm-filters button:hover { border-color: var(--accent); color: var(--accent-text); }
.comm-filters button.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.comm-list { margin-top: 0; }
.comm-list .call-item:last-child { margin-bottom: 0; }
.comm-list + .btn { margin-top: 10px; }
.comm-mail .ci-dir { font-size: 12px; }
.comm-hint { font-size: 11.5px; color: var(--text-3); margin-top: 10px; }

/* Salesperson views */
.pl-cols.single { grid-template-columns: minmax(0, 760px); }
.pl-cols.single .rep-b { max-height: none; }
.row-actions { display: flex; gap: 5px; margin-top: 6px; flex-wrap: wrap; }
.row-actions .btn { padding: 2px 9px; font-size: 11.5px; }
.ms-won { margin-top: 5px; font-size: 12px; font-weight: 600; color: var(--green); }
table.my-book .nm { font-weight: 570; }
table.my-book .em { font-size: 12px; color: var(--text-3); }

/* Mad Smokes, in the contact panel */
.ms-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* Create a Mad Smokes order */
.om .hint { font-size: 12px; color: var(--text-3); margin-top: 6px; line-height: 1.45; }
.om .hint.good { color: var(--green); }
.om .hint.bad { color: var(--red); }
.om-grid { display: grid; gap: 10px; }
.om-grid.two { grid-template-columns: 1fr 1fr; }
.om-grid.three { grid-template-columns: 2fr 1fr 1fr; }
.om-grid.coupon { grid-template-columns: 1fr 2fr; margin-top: 12px; }
.om-search { position: relative; }
.om-results {
  margin-top: 6px; border: 1px solid var(--border); border-radius: var(--radius-s);
  background: var(--surface); max-height: 280px; overflow-y: auto;
}
.om-hit {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; width: 100%;
  padding: 8px 11px; border: 0; border-bottom: 1px solid var(--border); background: transparent;
  color: var(--text); font: inherit; font-size: 13px; text-align: left; cursor: pointer;
}
.om-hit:last-child { border-bottom: 0; }
.om-hit:hover:not(:disabled) { background: var(--accent-soft); }
.om-hit:disabled { opacity: .5; cursor: not-allowed; }
.om-hit .nm { min-width: 0; }
.om-hit .em { display: block; font-size: 11.5px; color: var(--text-3); }
.om-lines { margin-top: 10px; border: 1px solid var(--border); border-radius: var(--radius-s); }
.om-line { display: grid; grid-template-columns: minmax(0, 1fr) auto 84px auto; gap: 10px; align-items: center; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.om-line:last-child { border-bottom: 0; }
.om-nm .nm { font-weight: 570; font-size: 13px; }
.om-nm .em { font-size: 11.5px; color: var(--text-3); }
.om-qty { display: flex; align-items: center; gap: 4px; }
.om-qty .input { width: 58px; text-align: center; padding: 5px 4px; -moz-appearance: textfield; }
.om-qty .input::-webkit-outer-spin-button, .om-qty .input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.om-lt { text-align: right; font-size: 13px; }
.om-totals { margin-top: 12px; padding: 12px 14px; border-radius: var(--radius-s); background: var(--surface-2); border: 1px solid var(--border); font-size: 13px; }
.om-totals > div { display: flex; justify-content: space-between; gap: 12px; padding: 2px 0; }
.om-totals .good { color: var(--green); }
.om-totals .grand { font-weight: 680; font-size: 15px; border-top: 1px solid var(--border); margin-top: 6px; padding-top: 8px; }
.om-totals .pay { display: block; font-size: 12px; margin-top: 6px; }

@media (max-width: 560px) {
  .om-grid.two, .om-grid.three, .om-grid.coupon { grid-template-columns: 1fr; }
  .om-line { grid-template-columns: minmax(0, 1fr) auto; }
  .om-lt { text-align: left; }
}

@media (max-width: 720px) {
  .dock { right: 10px; bottom: 10px; }
  .dock-panel { width: calc(100vw - 20px); }
}
