/* ── Contacts page (ct-*) + boot loader (boot-*) ─────────────────────── */

.ct-page {
  --ct-orange: #ea580c;
  --ct-orange-bg: #fff7ed;
  --ct-orange-border: #fdba74;
  --ct-row-hover: #f7f8f9;
  --ct-row-selected: #f0fdf4;
  display: flex; flex-direction: column; height: 100%; min-height: 0;
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
  background: var(--surface);
  color: var(--text);
}
:root[data-theme="dark"] .ct-page,
:root[data-theme="dark"] .ct-pop,
:root[data-theme="dark"] .ct-drawer {
  --ct-orange: #fb923c;
  --ct-orange-bg: rgba(251,146,60,.10);
  --ct-orange-border: rgba(251,146,60,.45);
  --ct-row-hover: #1c2029;
  --ct-row-selected: rgba(34,197,94,.08);
}

/* Toolbar */
.ct-toolbar {
  display: flex; align-items: center; gap: 8px;
  padding: 10px 16px; border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.ct-toolbar-right { margin-left: auto; display: flex; gap: 8px; }
.ct-search {
  display: flex; align-items: center; gap: 8px;
  height: 32px; width: 260px; max-width: 100%;
  padding: 0 10px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--text-3); cursor: text;
}
.ct-search:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.ct-search svg { width: 14px; height: 14px; flex: none; }
.ct-search input {
  border: 0; outline: 0; background: transparent; flex: 1; min-width: 0;
  font: inherit; font-size: 13px; color: var(--text); padding: 0;
}
.ct-search input::placeholder { color: var(--text-3); }
.ct-count { font-size: 12.5px; color: var(--text-3); margin-left: 4px; white-space: nowrap; }

.ct-btn {
  display: inline-flex; align-items: center; gap: 6px;
  height: 32px; padding: 0 12px; border-radius: 7px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; white-space: nowrap;
  transition: background .12s, border-color .12s;
}
.ct-btn:hover { background: var(--surface-2); border-color: #d1d5db; }
:root[data-theme="dark"] .ct-btn:hover { border-color: #3a4150; }
.ct-btn:focus-visible, .ct-icon-btn:focus-visible, .ct-add-label:focus-visible, .ct-menu-item:focus-visible, .boot-logout:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.ct-btn svg { width: 14px; height: 14px; flex: none; }
.ct-btn.is-active { border-color: var(--accent); color: var(--accent); }
.ct-btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.ct-btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
:root[data-theme="dark"] .ct-btn-primary { color: #06240f; }
.ct-btn-primary:disabled { opacity: .6; cursor: default; }
.ct-btn-danger-ghost { color: var(--danger); border-color: transparent; padding: 0 8px; }
.ct-btn-danger-ghost:hover { background: var(--danger-bg); border-color: transparent; }
.ct-badge {
  min-width: 17px; height: 17px; padding: 0 5px; border-radius: 9px;
  background: var(--accent); color: #fff; font-size: 10.5px; font-weight: 600;
  display: inline-flex; align-items: center; justify-content: center;
}
.ct-link {
  display: inline-flex; align-items: center; gap: 4px;
  background: none; border: 0; padding: 0; cursor: pointer;
  font: inherit; font-size: 12.5px; color: var(--accent); font-weight: 500;
}
.ct-link svg { width: 12px; height: 12px; }
.ct-link:hover { text-decoration: underline; }

/* Table */
.ct-scroll { flex: 1; min-height: 0; overflow: auto; }
.ct-table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13px; min-width: 980px; }
.ct-table thead th {
  position: sticky; top: 0; z-index: 2;
  background: var(--surface-2); color: var(--text-2);
  font-weight: 500; font-size: 12.5px; text-align: left; white-space: nowrap;
  padding: 0 12px; height: 38px; border-bottom: 1px solid var(--border);
}
.ct-table td {
  padding: 0 12px; height: 48px; border-bottom: 1px solid var(--border-light);
  vertical-align: middle; white-space: nowrap; max-width: 320px; overflow: hidden; text-overflow: ellipsis;
}
.ct-table .ct-cb { width: 40px; padding: 0 0 0 16px; }
.ct-table input[type="checkbox"] { width: 15px; height: 15px; accent-color: var(--accent); cursor: pointer; vertical-align: middle; }
.ct-row { cursor: pointer; transition: background .08s; }
.ct-row:hover td { background: var(--ct-row-hover); }
.ct-row.is-selected td { background: var(--ct-row-selected); }

.ct-name-cell { display: flex; align-items: center; gap: 10px; min-width: 0; }
.ct-name { font-weight: 500; overflow: hidden; text-overflow: ellipsis; max-width: 220px; }
.ct-avatar {
  position: relative; flex: none; width: 28px; height: 28px; border-radius: 50%;
  background: #e5e7eb; color: #fff; overflow: hidden;
  display: inline-flex; align-items: flex-end; justify-content: center;
}
:root[data-theme="dark"] .ct-avatar { background: #3a4150; color: #aab2c0; }
.ct-avatar > svg { width: 78%; height: 78%; }
.ct-avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; z-index: 1; }
.ct-avatar.lg { width: 52px; height: 52px; }

.ct-phone { font-variant-numeric: tabular-nums; color: var(--text); }
.ct-dash { color: var(--text-3); }
.ct-push { color: var(--text-3); }
.ct-masked { display: inline-flex; align-items: center; gap: 4px; color: var(--text-3); font-size: 12.5px; }
.ct-masked svg { width: 12px; height: 12px; }

.ct-labels { display: flex; align-items: center; gap: 4px; flex-wrap: nowrap; overflow: hidden; max-width: 300px; }
.ct-chip { flex: none; max-width: 110px; }
.ct-more { flex: none; font-size: 12px; color: var(--text-3); font-weight: 500; }
.ct-chip-txt { overflow: hidden; text-overflow: ellipsis; }
.ct-add-label { flex: none; }
.ct-chip {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 8px;
  border-radius: 11px; font-size: 12px; font-weight: 500; white-space: nowrap;
  color: var(--text);
  background: color-mix(in srgb, var(--chip) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--chip) 35%, transparent);
}
.ct-chip-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--chip, var(--text-3)); flex: none; }
.ct-add-label {
  display: inline-flex; align-items: center; gap: 3px; height: 22px; padding: 0 8px;
  border: 1px dashed var(--border); border-radius: 11px; background: transparent;
  color: var(--text-3); font: inherit; font-size: 12px; cursor: pointer; white-space: nowrap;
}
.ct-add-label svg { width: 11px; height: 11px; }
.ct-add-label:hover { border-color: var(--accent); color: var(--accent); }
.ct-chip + .ct-add-label { padding: 0 5px; }

.ct-type {
  display: inline-flex; align-items: center; gap: 5px; height: 22px; padding: 0 9px;
  border-radius: 11px; font-size: 12px; font-weight: 500; border: 1px solid;
}
.ct-type svg { width: 10px; height: 10px; }
.ct-external { color: var(--ct-orange); border-color: var(--ct-orange-border); background: var(--ct-orange-bg); }
.ct-internal { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); background: var(--accent-light); }

.ct-foot { min-height: 1px; }
.ct-sentinel { height: 1px; }
.ct-loading { display: flex; justify-content: center; padding: 20px; }
.ct-empty {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 64px 16px; text-align: center; color: var(--text-3); font-size: 13px;
}
.ct-empty strong { color: var(--text); font-size: 15px; font-weight: 600; }
.ct-empty .ct-btn { margin-top: 10px; }
.ct-empty-ic { width: 44px; height: 44px; border-radius: 50%; background: var(--surface-3); color: var(--text-3); display: flex; align-items: flex-end; justify-content: center; overflow: hidden; margin-bottom: 4px; }
.ct-empty-ic svg { width: 34px; height: 34px; }

/* Popovers (filter / actions) */
.ct-pop {
  position: fixed; z-index: 1200; min-width: 220px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border); border-radius: 9px; box-shadow: var(--shadow-lg);
  font-family: Inter, system-ui, sans-serif; font-size: 13px;
}
.ct-filter { width: 300px; padding: 4px 0 8px; }
.ct-pop-head { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px 6px; }
.ct-pop-sec { padding: 8px 14px 4px; }
.ct-pop-title { font-size: 11.5px; font-weight: 600; color: var(--text-3); text-transform: uppercase; letter-spacing: .03em; margin-bottom: 6px; }
.ct-pop-list { max-height: 150px; overflow: auto; margin: 0 -4px; }
.ct-pop-empty { color: var(--text-3); font-size: 12.5px; }
.ct-opt { display: flex; align-items: center; gap: 8px; padding: 5px 4px; border-radius: 5px; cursor: pointer; }
.ct-opt:hover { background: var(--surface-2); }
.ct-opt input { accent-color: var(--accent); margin: 0; }
.ct-seg { display: flex; border: 1px solid var(--border); border-radius: 7px; overflow: hidden; }
.ct-seg-opt { flex: 1; position: relative; cursor: pointer; }
.ct-seg-opt input { position: absolute; opacity: 0; pointer-events: none; }
.ct-seg-opt span { display: block; text-align: center; padding: 6px 4px; font-size: 12.5px; color: var(--text-2); }
.ct-seg-opt + .ct-seg-opt span { border-left: 1px solid var(--border); }
.ct-seg-opt input:checked + span { background: var(--accent-light); color: var(--accent); font-weight: 600; }
.ct-seg-opt input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -2px; }
.ct-select {
  width: 100%; height: 32px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px; padding: 0 8px;
}
.ct-menu { padding: 5px; min-width: 230px; }
.ct-menu-item {
  display: flex; align-items: center; gap: 9px; width: 100%;
  padding: 7px 10px; border: 0; border-radius: 6px; background: none;
  color: var(--text); font: inherit; font-size: 13px; cursor: pointer; text-align: left;
}
.ct-menu-item svg { width: 14px; height: 14px; color: var(--text-2); flex: none; }
.ct-menu-item:hover:not([disabled]) { background: var(--surface-2); }
.ct-menu-item[disabled] { opacity: .45; cursor: not-allowed; }
.ct-menu-item.is-danger, .ct-menu-item.is-danger svg { color: var(--danger); }
.ct-menu-sep { height: 1px; background: var(--border); margin: 4px 2px; }

/* Details drawer */
.ct-drawer-wrap { position: fixed; inset: 0; z-index: 1100; }
.ct-drawer-scrim { position: absolute; inset: 0; background: rgba(15,17,21,.28); animation: ct-fade .15s ease-out; }
.ct-drawer {
  position: absolute; top: 0; right: 0; bottom: 0; width: 420px; max-width: 100vw;
  background: var(--surface); color: var(--text); border-left: 1px solid var(--border);
  box-shadow: var(--shadow-lg); display: flex; flex-direction: column;
  font-family: Inter, system-ui, sans-serif; font-size: 13px;
  animation: ct-slide .18s ease-out;
}
@keyframes ct-fade { from { opacity: 0; } }
@keyframes ct-slide { from { transform: translateX(24px); opacity: 0; } }
.ct-dr-head { display: flex; align-items: center; gap: 12px; padding: 18px 18px 14px; border-bottom: 1px solid var(--border); }
.ct-dr-id { flex: 1; min-width: 0; }
.ct-dr-id h3 { margin: 0 0 4px; font-size: 16px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ct-dr-sub { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; color: var(--text-2); }
.ct-icon-btn {
  width: 30px; height: 30px; flex: none; border-radius: 7px; border: 0; background: none;
  color: var(--text-3); display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
}
.ct-icon-btn:hover { background: var(--surface-2); color: var(--text); }
.ct-icon-btn svg { width: 15px; height: 15px; }
.ct-dr-body { flex: 1; overflow: auto; padding: 6px 18px 18px; }
.ct-facts { padding: 8px 0; border-bottom: 1px solid var(--border-light); }
.ct-fact { display: flex; justify-content: space-between; gap: 12px; padding: 5px 0; }
.ct-fact > span:first-child { color: var(--text-3); }
.ct-fact > span:last-child { text-align: right; overflow: hidden; text-overflow: ellipsis; }
.ct-tag { display: inline-block; padding: 1px 7px; margin-left: 4px; border-radius: 9px; background: var(--surface-3); font-size: 11.5px; color: var(--text-2); }
.ct-dr-sec { padding: 14px 0 0; }
.ct-dr-sec .ct-labels { flex-wrap: wrap; max-width: none; }
.ct-form { display: flex; flex-direction: column; gap: 12px; }
.ct-form > label { display: flex; flex-direction: column; gap: 5px; font-size: 12.5px; font-weight: 500; color: var(--text-2); }
.ct-form input[type="text"], .ct-form input[type="email"], .ct-form textarea, .ct-prop input {
  width: 100%; box-sizing: border-box; border: 1px solid var(--border); border-radius: 7px;
  background: var(--surface); color: var(--text); font: inherit; font-size: 13px; font-weight: 400;
  padding: 7px 10px; outline: 0;
}
.ct-form textarea { resize: vertical; min-height: 64px; }
.ct-form input:focus, .ct-form textarea:focus, .ct-prop input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-light); }
.ct-form > label.ct-inline { flex-direction: row; align-items: center; gap: 8px; font-weight: 400; }
.ct-inline input { accent-color: var(--accent); }
.ct-prop { display: flex; gap: 6px; margin-bottom: 6px; align-items: center; }
.ct-prop .ct-prop-k { flex: 0 0 38%; }
.ct-dr-foot { display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-top: 1px solid var(--border); }

@media (max-width: 720px) {
  .ct-toolbar { padding: 10px 12px; }
  .ct-search { width: 100%; order: -1; }
  .ct-count { display: none; }
  .ct-drawer { width: 100vw; }
}

/* ── Boot loader: shown while the session is restored / first view renders ── */
.boot-loader {
  position: fixed; inset: 0; z-index: 3000;
  display: flex; align-items: center; justify-content: center;
  background: var(--bg, #f5f5f5);
  font-family: Inter, system-ui, -apple-system, 'Segoe UI', sans-serif;
}
.boot-loader[hidden] { display: none; }
.boot-inner { display: flex; flex-direction: column; align-items: center; gap: 18px; }
.boot-logo {
  width: 52px; height: 52px; border-radius: 13px; overflow: hidden;
  display: flex; align-items: center; justify-content: center;
  background: #15803d; box-shadow: 0 4px 14px rgba(21,128,61,.30);
}
.boot-logo svg { width: 38px; height: 38px; display: block; }
.boot-logo.has-img { background: var(--surface, #fff); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.boot-logo img { width: 100%; height: 100%; object-fit: cover; display: block; }
.boot-text { font-size: 14px; color: var(--text-3, #9ca3af); margin: 0; }
.boot-bar {
  position: relative; width: 190px; height: 4px; border-radius: 4px; overflow: hidden;
  background: color-mix(in srgb, var(--accent, #15803d) 16%, transparent);
}
.boot-bar::before {
  content: ""; position: absolute; top: 0; bottom: 0; left: 0; width: 40%;
  border-radius: 4px; background: var(--accent, #15803d);
  animation: boot-slide 1.15s cubic-bezier(.45,.05,.55,.95) infinite;
}
@keyframes boot-slide { 0% { transform: translateX(-100%); } 100% { transform: translateX(250%); } }
@media (prefers-reduced-motion: reduce) {
  .boot-bar::before { animation: boot-pulse 1.6s ease-in-out infinite; width: 100%; transform: none; }
  @keyframes boot-pulse { 0%, 100% { opacity: .35; } 50% { opacity: 1; } }
  .ct-drawer, .ct-drawer-scrim { animation: none; }
}
.boot-logout {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 6px;
  height: 30px; padding: 0 12px; border-radius: 7px;
  border: 1px solid var(--border, #e5e7eb); background: var(--surface, #fff); color: var(--text-2, #4b5563);
  font: inherit; font-size: 12.5px; font-weight: 500; cursor: pointer;
}
.boot-logout:hover { background: var(--surface-2, #f9fafb); color: var(--text, #141414); }
.boot-logout svg { width: 13px; height: 13px; }
.boot-slow { font-size: 12.5px; color: var(--text-3, #9ca3af); margin: -6px 0 0; }
.boot-slow[hidden] { display: none; }
.ct-badge[hidden] { display: none; }
