/* Contacts directory — Google AI Studio inspired light theme
   Matches /docs/ palette (slate + blue) for cross-page consistency. */

:root {
  color-scheme: light;

  /* Surfaces */
  --bg:          #f1f5f9;   /* slate-100 — page */
  --surface:     #ffffff;   /* white — content area / cards */
  --surface-2:   #f8fafc;   /* slate-50 — sidebar / hovers */
  --surface-3:   #f1f5f9;   /* slate-100 — pill backgrounds */

  /* Text */
  --text:        #1e293b;   /* slate-800 */
  --text-strong: #0f172a;   /* slate-900 */
  --muted:       #475569;   /* slate-600 */
  --subtle:      #94a3b8;   /* slate-400 */

  /* Accents */
  --accent:        #2563eb; /* blue-600 */
  --accent-hover:  #1d4ed8; /* blue-700 */
  --accent-soft:   #dbeafe; /* blue-100 */
  --accent-softer: #eff6ff; /* blue-50 */
  --accent-fg:     #ffffff;

  /* Category colors */
  --retailer-bg:  #d1fae5; /* emerald-100 */
  --retailer-fg:  #065f46; /* emerald-800 */
  --retailer-bd:  #a7f3d0; /* emerald-200 */
  --vendor-bg:    #dbeafe; /* blue-100 */
  --vendor-fg:    #1e40af; /* blue-800 */
  --vendor-bd:    #bfdbfe; /* blue-200 */
  --other-bg:     #f1f5f9; /* slate-100 */
  --other-fg:     #334155; /* slate-700 */
  --other-bd:     #e2e8f0; /* slate-200 */

  /* Semantic */
  --danger:      #dc2626;
  --danger-bg:   #fee2e2;
  --warn:        #b45309;
  --warn-bg:     #fef3c7;
  --ok:          #047857;
  --ok-bg:       #d1fae5;

  /* Lines */
  --border:        #e2e8f0; /* slate-200 */
  --border-strong: #cbd5e1; /* slate-300 */

  /* Layout */
  --radius:    4px;
  --radius-sm: 2px;
  --header-h:  56px;
  --footer-h:  32px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.06);
  --shadow-md: 0 4px 14px rgba(15, 23, 42, 0.08);

  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Inter", Roboto, system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.35;
  -webkit-font-smoothing: antialiased;
  height: 100%;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ===================== Login overlay ===================== */
.login-overlay {
  position: fixed; inset: 0;
  background: var(--bg);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 24px;
}
.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 32px 32px;
  width: 100%; max-width: 380px;
  box-shadow: var(--shadow-md);
}
.login-card h1 { margin: 0 0 6px; font-size: 22px; font-weight: 700; color: var(--text-strong); }
.login-card p  { margin: 0 0 22px; color: var(--muted); font-size: 13px; }
.login-card label {
  display: block; font-size: 11px; color: var(--muted);
  margin-bottom: 6px; text-transform: uppercase; letter-spacing: 0.6px; font-weight: 600;
}
.login-card input {
  width: 100%; padding: 11px 14px; font-size: 14px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  outline: none; transition: border-color 0.15s, box-shadow 0.15s;
}
.login-card input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.login-card .error { color: var(--danger); font-size: 12px; min-height: 18px; margin-top: 6px; }
.login-card button[type="submit"] {
  width: 100%; margin-top: 14px; padding: 11px 14px;
  background: var(--accent); color: var(--accent-fg);
  border: none; border-radius: var(--radius-sm); font-weight: 600; font-size: 14px;
  cursor: pointer; transition: background 0.15s;
}
.login-card button[type="submit"]:hover { background: var(--accent-hover); }

/* ===================== App shell ===================== */
.app { display: none; }
body.authed .app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}
body.authed .login-overlay { display: none; }

/* Cross-page x-nav pill is fully styled by /shared/theme.css; no overrides here
   so /contacts/ and /docs/ render identically. */

/* ===================== Top header bar ===================== */
.cmd-bar {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px;
  padding: 0 18px 0 220px; /* leaves room for x-nav pill on left */
  flex-shrink: 0;
}
.brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; font-size: 15px; color: var(--text-strong);
  letter-spacing: -0.01em;
}
.brand-mark {
  width: 28px; height: 28px; border-radius: 7px;
  background: var(--surface-3);
  color: var(--text-strong); display: grid; place-items: center;
  font-weight: 700; font-size: 14px;
  border: 1px solid var(--border-strong);
}
.brand-text { color: var(--text-strong); }
.brand-sub  { font-size: 11px; color: var(--subtle); font-weight: 500; margin-left: 2px; }

.divider-v { width: 1px; height: 22px; background: var(--border); margin: 0 4px; }

/* Grid/List view toggle */
.view-toggle {
  display: inline-flex; gap: 2px;
  background: var(--surface-2);
  padding: 2px; border: 1px solid var(--border); border-radius: var(--radius-sm);
}
.view-toggle button {
  background: transparent; border: 0;
  padding: 5px 12px; font-size: 12px; font-weight: 600;
  color: var(--muted); cursor: pointer;
  border-radius: 5px; transition: all 0.12s;
}
.view-toggle button.active {
  background: var(--text-strong); color: var(--surface);
  box-shadow: none;
}
.view-toggle button:hover:not(.active) { color: var(--text-strong); }

/* Search input */
.search-wrap { position: relative; flex: 1; max-width: 320px; }
.search-wrap input {
  width: 100%; padding: 7px 12px 7px 32px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: var(--radius-sm); font-size: 13px; color: var(--text);
  outline: none; transition: all 0.15s;
}
.search-wrap input:focus { border-color: var(--accent); background: var(--surface); box-shadow: 0 0 0 3px var(--accent-soft); }
.search-wrap::before {
  content: '';
  position: absolute; left: 10px; top: 50%; transform: translateY(-50%);
  width: 14px; height: 14px;
  background: no-repeat center/contain url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' fill='none' stroke='%2394a3b8' stroke-width='2' viewBox='0 0 24 24'><circle cx='11' cy='11' r='8'/><line x1='21' y1='21' x2='16.65' y2='16.65'/></svg>");
}

/* Buttons */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 7px 12px; font-size: 12px; font-weight: 700;
  border-radius: var(--radius-sm); border: 1px solid transparent;
  cursor: pointer; transition: all 0.12s; line-height: 1;
}
.btn-primary { background: var(--text-strong); color: var(--surface); border-color: var(--text-strong); }
.btn-primary:hover { background: var(--surface-3); color: var(--text-strong); border-color: var(--border-strong); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text-strong); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; }

.role-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 10px; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 999px; font-size: 11px; color: var(--muted); font-weight: 600;
}

.cmd-bar .right { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* Hide admin-only buttons for viewer role */
body:not(.role-admin) .admin-only { display: none !important; }

/* ===================== Main split (sidebar + content) ===================== */
.main-split { flex: 1; display: flex; overflow: hidden; }

/* Sidebar */
.dir-rail {
  width: 224px; flex-shrink: 0;
  background: var(--surface-2);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column;
  padding: 16px 12px;
  overflow-y: auto;
}
.dir-rail h6 {
  margin: 0 0 10px 4px;
  font-size: 10px; font-weight: 700;
  color: var(--subtle); text-transform: uppercase; letter-spacing: 0.12em;
}
.dir-rail .seg {
  display: flex; flex-direction: column; gap: 2px;
}
.dir-rail .seg button {
  display: flex; align-items: center; justify-content: space-between;
  width: 100%; padding: 8px 10px;
  background: transparent; border: 0; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500; color: var(--muted);
  cursor: pointer; transition: all 0.12s; text-align: left;
}
.dir-rail .seg button:hover { background: var(--surface-3); color: var(--text-strong); }
.dir-rail .seg button.active {
  background: var(--text-strong);
  box-shadow: none;
  color: var(--surface);
  font-weight: 700;
}
.dir-rail .seg button.active .count { color: var(--warn); opacity: 1; }
.dir-rail .seg button .count {
  font-size: 11px; font-family: ui-monospace, SFMono-Regular, monospace;
  opacity: 0.85; font-weight: 600;
}

.dir-rail .rail-footer {
  margin-top: auto; padding-top: 14px;
  border-top: 1px solid var(--border);
  font-size: 11px; color: var(--subtle);
}
.dir-rail .rail-footer .status {
  display: flex; align-items: center; gap: 6px;
  font-family: ui-monospace, SFMono-Regular, monospace;
}
.dir-rail .rail-footer .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--ok);
  box-shadow: 0 0 0 3px rgba(4, 120, 87, 0.15);
  animation: pulse 2s infinite;
}
.dir-rail .rail-footer .dot.warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(180, 83, 9, 0.15); }
.dir-rail .rail-footer .dot.err  { background: var(--danger); box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.15); }
.dir-rail .rail-footer .rail-tip { margin-top: .4rem; }
@keyframes pulse {
  0%,100% { opacity: 1; }
  50%     { opacity: 0.45; }
}

/* Content area */
.dir-main {
  flex: 1; overflow-y: auto;
  padding: 0 16px 16px;
  background: var(--surface);
}
.dir-toolbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex; align-items: center; justify-content: space-between;
  flex-wrap: wrap; gap: 12px;
  padding: 10px 0 9px;
  margin-bottom: 10px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  -webkit-backdrop-filter: saturate(140%) blur(6px);
  backdrop-filter: saturate(140%) blur(6px);
}
.dir-toolbar h2 {
  margin: 0; font-size: 13px; font-weight: 800;
  color: var(--text-strong); display: flex; align-items: baseline; gap: 8px;
}
.dir-toolbar h2 .count {
  font-size: 12px; color: var(--muted); font-weight: 500;
}
.toolbar-controls {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.sort-by {
  display: flex;
  align-items: center;
  gap: 8px;
}
.sort-by label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
}
.sort-by select {
  min-width: 210px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 700;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
}
.sort-by select:hover { border-color: var(--border-strong); background: var(--surface); }
.sort-by select:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.group-by { display: flex; align-items: center; gap: 8px; position: relative; }
.group-by > span { font-size: 11px; font-weight: 600; color: var(--muted); }
.company-filter { position: relative; }
.company-filter-btn {
  min-width: 168px; max-width: 240px;
  padding: 5px 30px 5px 10px; font-size: 12px; font-weight: 700;
  background: var(--surface-2); color: var(--text);
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  cursor: pointer; outline: none; text-align: left;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  position: relative;
}
.company-filter-btn::after {
  content: '⌄'; position: absolute; right: 10px; top: 50%; transform: translateY(-52%);
  color: var(--subtle); font-size: 13px;
}
.company-filter-btn:hover { background: var(--surface); border-color: var(--border-strong); }
.company-filter-btn:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.company-filter-menu {
  position: absolute; right: 0; top: calc(100% + 6px);
  width: min(360px, calc(100vw - 32px));
  max-height: min(440px, calc(100vh - 160px));
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  z-index: 90;
  overflow: hidden;
}
.company-filter-actions {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 8px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.company-filter-actions button {
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  border-radius: 999px; padding: 4px 9px; font-size: 11px; font-weight: 700;
  cursor: pointer;
}
.company-filter-actions button:hover { color: var(--text-strong); border-color: var(--border-strong); background: var(--surface-3); }
.company-filter-hint {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.35;
}
.company-filter-options {
  max-height: 330px;
  overflow-y: auto;
  padding: 6px;
}
.company-option {
  display: grid; grid-template-columns: 18px minmax(0, 1fr) auto;
  align-items: center; gap: 8px;
  padding: 7px 8px;
  border-radius: var(--radius-sm);
  color: var(--text);
  cursor: pointer;
}
.company-option:hover { background: var(--surface-2); }
.company-option input { accent-color: var(--accent); margin: 0; }
.company-option-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; font-weight: 600; }
.company-option-count {
  font-family: ui-monospace, SFMono-Regular, monospace;
  font-size: 11px; color: var(--muted);
  border: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: 999px;
  padding: 1px 6px;
}
.empty-option { display: block; color: var(--subtle); cursor: default; }
.empty-option:hover { background: transparent; }

/* ===================== Cards (grid view) ===================== */
.dir-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 8px;
}
.contact-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 11px;
  cursor: pointer;
  transition: background-color 0.12s, border-color 0.12s, box-shadow 0.12s;
  display: flex; flex-direction: column;
  min-height: 132px;
  box-shadow: none;
}
.contact-card:hover {
  border-color: var(--border-strong);
  background: var(--surface-2);
  box-shadow: none;
}
.contact-card.has-note { box-shadow: inset 3px 0 0 var(--warn); }
.contact-card.has-flag.flag-red { box-shadow: inset 3px 0 0 var(--danger); }
.contact-card.has-flag.flag-yellow { box-shadow: inset 3px 0 0 var(--warn); }
.contact-card.has-flag.flag-green { box-shadow: inset 3px 0 0 var(--ok); }
.card-head {
  display: flex; align-items: flex-start; justify-content: space-between;
  margin-bottom: 7px; gap: 10px;
}
.card-identity {
  min-width: 0;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.card-badges {
  display: inline-flex;
  align-items: flex-start;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: flex-end;
  flex-shrink: 0;
  max-width: 134px;
}
.avatar {
  width: 26px; height: 26px; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--muted);
  display: grid; place-items: center;
  font-weight: 800; font-size: 10px;
  border: 1px solid var(--border-strong);
  flex-shrink: 0;
}
.card-name {
  font-size: 14px; font-weight: 850; color: var(--text-strong);
  line-height: 1.18; margin: 0;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.card-sub {
  font-size: 10px; color: var(--subtle); margin: 1px 0 0;
  text-transform: uppercase;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.card-company-line {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  margin-top: 2px;
  flex-wrap: wrap;
}
.card-company {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  min-width: 0;
  max-width: 100%;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  line-height: 1.2;
}
.card-company span {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.card-company svg { flex: 0 0 auto; opacity: 0.7; }
.card-contact {
  margin: auto -11px -10px; padding: 6px 10px;
  border-top: 1px solid var(--border);
  background: color-mix(in srgb, var(--surface-2) 68%, transparent);
  display: flex; flex-direction: row; align-items: center; gap: 10px; flex-wrap: wrap;
}
.card-contact a, .card-contact span {
  font-size: 10.5px; color: var(--muted);
  display: inline-flex; align-items: center; gap: 6px;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  text-decoration: none;
}
.card-contact a:hover { color: var(--text-strong); text-decoration: underline; }
.card-contact .phone { font-family: ui-monospace, SFMono-Regular, monospace; }

.contact-insights {
  display: flex; align-items: center; gap: 6px; flex-wrap: wrap;
  margin: 0 0 6px;
}
.store-count,
.website-link {
  display: inline-flex; align-items: center; gap: 5px;
  min-width: 0;
  padding: 2px 6px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--muted);
  font-size: 11px;
  line-height: 1.2;
  white-space: nowrap;
}
.store-count {
  background: var(--surface-2);
  color: var(--text-strong);
  border-color: var(--border-strong);
  font-weight: 700;
}
.website-link {
  max-width: 100%;
  text-decoration: none;
}
.card-website {
  max-width: 150px;
  padding: 1px 5px;
  font-size: 10.5px;
  background: transparent;
}
.website-link span {
  overflow: hidden;
  text-overflow: ellipsis;
}
.website-link:hover {
  background: var(--surface-3);
  color: var(--text-strong);
  border-color: var(--border-strong);
  text-decoration: none;
}
.store-count svg,
.website-link svg { flex-shrink: 0; opacity: 0.7; }

.flag-control {
  --flag-color: var(--subtle);
  --flag-bg: var(--surface-2);
  --flag-bd: var(--border);
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 5px;
  border: 1px solid var(--flag-bd);
  border-radius: var(--radius-sm);
  background: var(--flag-bg);
  color: var(--flag-color);
  line-height: 1;
  max-width: 150px;
}
.flag-control.flag-red { --flag-color: var(--danger); --flag-bg: var(--danger-bg); --flag-bd: var(--danger); }
.flag-control.flag-yellow { --flag-color: var(--warn); --flag-bg: var(--warn-bg); --flag-bd: var(--warn); }
.flag-control.flag-green { --flag-color: var(--ok); --flag-bg: var(--ok-bg); --flag-bd: var(--ok); }
.flag-icon { display: inline-flex; align-items: center; color: var(--flag-color); }
.flag-icon svg { opacity: 1; }
.flag-control select {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--flag-color);
  font-size: 10px;
  font-weight: 800;
  max-width: 92px;
  outline: none;
  cursor: pointer;
  padding: 1px 10px 1px 0;
}
.flag-control:hover { filter: brightness(0.98); }
.company-flag-control { padding: 3px 7px; }
.company-flag-control select { font-size: 11px; max-width: 110px; }
.card-flag-control select,
.row-flag-control select { width: 54px; }

.note-preview {
  display: flex;
  align-items: flex-start;
  gap: 5px;
  margin: 0 0 7px;
  padding: 6px 7px;
  border: 1px solid var(--border);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius-sm);
  background: color-mix(in srgb, var(--warn-bg) 35%, var(--surface));
  color: var(--text);
  font-size: 11px;
  line-height: 1.35;
}
.note-preview svg { flex: 0 0 auto; margin-top: 2px; opacity: 0.7; color: var(--warn); }
.note-preview span {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.note-preview strong { text-transform: uppercase; letter-spacing: 0.04em; font-size: 10px; margin-right: 4px; color: var(--warn); }
.row-note-preview {
  margin: 0;
  padding: 3px 7px;
  border-left-width: 2px;
  border-radius: 999px;
  max-width: 180px;
  white-space: normal;
}
.row-note-preview span { -webkit-line-clamp: 1; }

/* ===================== Grouped company drawers ===================== */
.company-groups {
  display: flex;
  flex-direction: column;
  gap: 10px;
}
.company-group {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  box-shadow: none;
  overflow: hidden;
}
.company-group-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 10px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.company-group-title {
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}
.company-name {
  font-size: 13px;
  font-weight: 800;
  color: var(--text-strong);
  max-width: 360px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.company-meta {
  font-family: ui-monospace, SFMono-Regular, monospace;
  color: var(--muted);
  font-size: 11px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 2px 6px;
}
.company-highlights {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
  flex-wrap: wrap;
}
.company-highlights .website-link { max-width: 220px; }
.company-group-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
}
.company-bulk-actions {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.company-bulk-move {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 800;
  padding: 5px 9px;
  cursor: pointer;
  white-space: nowrap;
}
.company-bulk-move:hover { background: var(--surface-2); color: var(--text-strong); }
.company-bulk-move.move-retailer:hover,
.company-bulk-move.move-vendor:hover,
.company-bulk-move.move-other:hover { background: var(--text-strong); color: var(--surface); border-color: var(--text-strong); }
.company-overflow-toggle {
  border: 1px solid var(--border-strong);
  background: var(--surface);
  color: var(--text-strong);
  border-radius: var(--radius-sm);
  font-size: 11px;
  font-weight: 800;
  padding: 5px 10px;
  cursor: pointer;
}
.company-overflow-toggle:hover { background: var(--surface-3); text-decoration: none; }
.company-group .company-visible,
.company-overflow-list {
  padding: 8px;
}
.company-overflow {
  border-top: 1px dashed var(--border-strong);
  background: var(--surface-2);
}
.company-overflow-note {
  padding: 10px 12px 0;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.company-overflow .contact-card,
.company-overflow .contact-row {
  background: var(--surface);
}

/* Category pill */
.category-pill {
  font-size: 10px; font-weight: 700; text-transform: uppercase;
  padding: 3px 7px; border-radius: var(--radius-sm);
  border: 1px solid; letter-spacing: 0.04em; line-height: 1; white-space: nowrap;
}
.category-pill.retailer,
.category-pill.vendor,
.category-pill.other { background: var(--surface-2); color: var(--text-strong); border-color: var(--border-strong); }

/* Quick actions row (move/edit/del) — shown on hover for grid; always for list */
.card-actions {
  display: flex; align-items: center; gap: 4px; flex-wrap: wrap;
  opacity: 0;
  transition: opacity 0.12s;
}
.contact-card:hover .card-actions,
.contact-row:hover .card-actions { opacity: 1; }
.card-actions button {
  font-size: 10px; font-weight: 600;
  padding: 3px 7px; border-radius: var(--radius-sm);
  background: var(--surface-2); color: var(--muted);
  border: 1px solid var(--border);
  cursor: pointer; transition: all 0.1s; line-height: 1;
}
.card-actions button:hover { background: var(--surface); color: var(--text-strong); }
.card-actions .move-retailer:hover,
.card-actions .move-vendor:hover,
.card-actions .move-other:hover    { background: var(--text-strong); color: var(--surface); border-color: var(--text-strong); }
.card-actions .danger:hover        { background: var(--danger-bg);   color: var(--danger);      border-color: #fecaca; }

/* ===================== List view rows ===================== */
.dir-list { display: flex; flex-direction: column; gap: 4px; }
.contact-row {
  display: grid;
  grid-template-columns: 38px minmax(140px, 1.25fr) minmax(120px, 1fr) minmax(150px, 1fr) minmax(160px, 1.25fr) minmax(110px, 0.75fr) auto;
  align-items: center; gap: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 10px;
  cursor: pointer; transition: all 0.12s;
}
.contact-row:hover { border-color: var(--border-strong); background: var(--surface-2); box-shadow: none; }
.contact-row.has-note { box-shadow: inset 3px 0 0 var(--warn); }
.contact-row.has-flag.flag-red { box-shadow: inset 3px 0 0 var(--danger); }
.contact-row.has-flag.flag-yellow { box-shadow: inset 3px 0 0 var(--warn); }
.contact-row.has-flag.flag-green { box-shadow: inset 3px 0 0 var(--ok); }
.contact-row .avatar { width: 24px; height: 24px; font-size: 10px; }
.contact-row .col-name { display: flex; flex-direction: column; min-width: 0; }
.contact-row .col-name .name {
  font-size: 13px; font-weight: 800; color: var(--text-strong); line-height: 1.15;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.contact-row .col-name .sub {
  font-size: 10px; color: var(--subtle); margin-top: 1px; text-transform: uppercase;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.contact-row .col-company,
.contact-row .col-insights,
.contact-row .col-email,
.contact-row .col-phone {
  font-size: 12px; color: var(--muted);
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  display: inline-flex; align-items: center; gap: 6px;
}
.contact-row .col-insights {
  gap: 6px;
  flex-wrap: wrap;
  white-space: normal;
}
.contact-row .col-insights .website-link { max-width: 160px; }
.contact-row .col-phone { font-family: ui-monospace, SFMono-Regular, monospace; font-size: 11px; }
.contact-row svg { opacity: 0.78; flex-shrink: 0; }
.contact-row .col-right {
  display: flex; align-items: center; gap: 8px; justify-content: flex-end;
}
.contact-row .row-flag-control { flex-shrink: 0; }

/* ===================== Company group header (when "Group by: Company") ===================== */
.group-header {
  display: flex; align-items: center; gap: 8px;
  margin: 18px 0 8px;
  padding: 0 4px;
  font-size: 11px; font-weight: 700; color: var(--muted);
  text-transform: uppercase; letter-spacing: 0.08em;
}
.group-header .line { flex: 1; height: 1px; background: var(--border); }
.group-header .gcount {
  font-family: ui-monospace, SFMono-Regular, monospace;
  background: var(--surface-2); padding: 2px 6px; border-radius: 4px;
  border: 1px solid var(--border); color: var(--subtle);
}
.group-header:first-child { margin-top: 0; }

/* ===================== Empty state ===================== */
.empty {
  text-align: center; padding: 60px 20px;
  background: var(--surface-2);
  border: 1px dashed var(--border-strong);
  border-radius: var(--radius);
}
.empty h3 { margin: 0 0 6px; font-size: 14px; color: var(--text-strong); }
.empty p  { margin: 0; font-size: 12px; color: var(--muted); }

/* ===================== Footer ===================== */
.dir-footer {
  height: var(--footer-h);
  background: #1e293b;
  color: #cbd5e1;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 18px;
  font-size: 11px; font-family: ui-monospace, SFMono-Regular, monospace;
  flex-shrink: 0;
}
.dir-footer .left, .dir-footer .right { display: flex; align-items: center; gap: 14px; }
.dir-footer .dot {
  width: 7px; height: 7px; border-radius: 50%; background: #10b981;
  animation: pulse 2s infinite;
}
.dir-footer .accent { color: #fff; font-weight: 600; }

/* ===================== Slide-over panel (Add/Edit) ===================== */
.scrim {
  position: fixed; inset: 0; background: rgba(15, 23, 42, 0.35);
  z-index: 100; display: none;
}
body.panel-open .scrim { display: block; }
.panel {
  position: fixed; top: 0; right: 0; bottom: 0;
  width: 420px; max-width: 100%;
  background: var(--surface);
  border-left: 1px solid var(--border);
  box-shadow: -10px 0 30px rgba(15, 23, 42, 0.1);
  z-index: 101;
  display: none;
  flex-direction: column;
}
body.panel-open .panel { display: flex; }
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 18px; border-bottom: 1px solid var(--border);
}
.panel-head h2 { margin: 0; font-size: 15px; font-weight: 700; color: var(--text-strong); }
.panel-body { flex: 1; overflow-y: auto; padding: 16px 18px; }
.panel-mode-hint {
  margin: 0 0 14px;
  padding: 10px 12px;
  border: 1px solid #bfdbfe;
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent-softer);
  color: var(--accent-hover);
  font-size: 12px;
  font-weight: 650;
  line-height: 1.35;
}
.panel-foot {
  display: flex; align-items: center; gap: 8px; justify-content: flex-end;
  padding: 12px 18px; border-top: 1px solid var(--border);
  background: var(--surface-2);
}
.panel-delete { margin-right: auto; }
.field { margin-bottom: 12px; }
.field label {
  display: block; font-size: 11px; font-weight: 600;
  color: var(--muted); margin-bottom: 4px;
  text-transform: uppercase; letter-spacing: 0.04em;
}
.field input, .field select, .field textarea {
  width: 100%; padding: 8px 10px; font-size: 13px;
  background: var(--surface); color: var(--text);
  border: 1px solid var(--border-strong); border-radius: var(--radius-sm);
  outline: none; transition: all 0.12s;
  font-family: inherit;
}
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft);
}
.panel.readonly .field input:disabled,
.panel.readonly .field select:disabled,
.panel.readonly .field textarea:disabled {
  background: var(--surface-2);
  color: var(--muted);
  border-color: var(--border);
  opacity: 0.85;
  cursor: not-allowed;
}
.panel.readonly #f-flag,
.panel.readonly #f-notes {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border-strong);
  opacity: 1;
  cursor: text;
}
.panel.readonly #f-flag { cursor: pointer; }

/* ===================== Toast ===================== */
.toast {
  position: fixed; bottom: 50px; left: 50%; transform: translateX(-50%) translateY(20px);
  background: var(--text-strong); color: #fff;
  padding: 10px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-md);
  opacity: 0; pointer-events: none;
  transition: all 0.2s;
  z-index: 200;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error   { background: var(--danger); }
.toast.warn    { background: var(--warn); }
.toast.success { background: var(--ok); }

/* ===================== Responsive ===================== */
@media (max-width: 880px) {
  .cmd-bar { padding-left: 18px; flex-wrap: wrap; height: auto; padding-top: 8px; padding-bottom: 8px; }
  .x-nav { position: static; margin: 8px 0 0 8px; }
  .dir-rail { width: 180px; }
  .search-wrap { max-width: 100%; flex: 1 1 100%; order: 99; }
}
@media (max-width: 640px) {
  .dir-rail { display: none; }
  .dir-toolbar { align-items: stretch; }
  .toolbar-controls { width: 100%; }
  .sort-by { width: 100%; justify-content: space-between; }
  .sort-by select { min-width: 0; width: 100%; }
  .group-by { width: 100%; justify-content: space-between; }
  .company-filter { flex: 1; }
  .company-filter-btn { width: 100%; max-width: none; }
  .company-filter-menu { left: 0; right: auto; }
  .company-group-head { align-items: flex-start; flex-direction: column; }
  .company-group-actions { width: 100%; flex-direction: column; align-items: stretch; }
  .company-bulk-actions { width: 100%; justify-content: stretch; }
  .company-bulk-move { flex: 1 1 100%; }
  .company-overflow-toggle { width: 100%; }
  .contact-row {
    grid-template-columns: 32px 1fr auto;
  }
  .contact-row .col-company, .contact-row .col-insights, .contact-row .col-email, .contact-row .col-phone { display: none; }
}
