/* ═══════════════════════════════════════════════════════════════════════
   WGN ERP — app.css  (v3 — unified design system)
   ═══════════════════════════════════════════════════════════════════════ */

/* ── Design Tokens ────────────────────────────────────────────────────── */
:root {
  /* ---- Palette ---- */
  --blue-50:  #eff6ff; --blue-100: #dbeafe; --blue-200: #bfdbfe;
  --blue-500: #3b82f6; --blue-600: #2563eb; --blue-700: #1d4ed8;
  --blue-800: #1e40af; --blue-900: #1e3a8a;

  --slate-50:  #f8fafc; --slate-100: #f1f5f9; --slate-200: #e2e8f0;
  --slate-300: #cbd5e1; --slate-400: #94a3b8; --slate-500: #64748b;
  --slate-600: #475569; --slate-700: #334155; --slate-800: #1e293b;
  --slate-900: #0f172a;

  --red-50:  #fef2f2; --red-100: #fee2e2; --red-200: #fecaca;
  --red-600: #dc2626; --red-700: #b91c1c; --red-800: #991b1b;

  --amber-50: #fffbeb; --amber-100: #fef3c7; --amber-200: #fde68a;
  --amber-600: #d97706; --amber-700: #b45309; --amber-800: #92400e;

  --green-50:  #f0fdf4; --green-100: #dcfce7; --green-200: #bbf7d0;
  --green-600: #16a34a; --green-700: #15803d; --green-800: #166534;

  --purple-50:  #f5f3ff; --purple-100: #ede9fe; --purple-200: #ddd6fe;
  --purple-600: #7c3aed; --purple-700: #6d28d9;

  --teal-50: #f0fdfa; --teal-100: #ccfbf1; --teal-200: #99f6e4;
  --teal-600: #0d9488; --teal-700: #0f766e;

  --sky-100: #e0f2fe; --sky-700: #0369a1;

  /* ---- Semantic ---- */
  --color-bg:              #f2f4f7;
  --color-surface:         #ffffff;
  --color-surface-raised:  #f8fafc;
  --color-border:          #e2e8f0;
  --color-border-light:    #f1f5f9;
  --color-text:            #0f172a;
  --color-text-secondary:  #475569;
  --color-text-muted:      #94a3b8;
  --color-primary:         #1d4ed8;
  --color-primary-hover:   #1e40af;
  --color-primary-active:  #1e3a8a;
  --color-danger:          #dc2626;

  /* ---- Spacing ---- */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px;
  --sp-4: 16px; --sp-5: 20px; --sp-6: 24px;

  /* ---- Typography ---- */
  --text-2xs: 10px; --text-xs: 11px; --text-sm: 12px;
  --text-base: 13px; --text-md: 14px; --text-lg: 16px;
  --text-xl: 18px; --text-2xl: 20px;

  /* ---- Radius ---- */
  --r-xs: 3px; --r-sm: 4px; --r-md: 6px;
  --r-lg: 8px; --r-xl: 10px; --r-2xl: 12px; --r-full: 9999px;

  /* ---- Shadows ---- */
  --shadow-xs:    0 1px 2px rgba(15,23,42,.05);
  --shadow-sm:    0 1px 4px rgba(15,23,42,.08);
  --shadow-md:    0 2px 8px rgba(15,23,42,.10);
  --shadow-lg:    0 6px 18px rgba(15,23,42,.12);
  --shadow-xl:    0 12px 32px rgba(15,23,42,.15);
  --shadow-panel: -10px 0 40px rgba(15,23,42,.14);

  /* ---- Transitions ---- */
  --t-fast: 80ms ease;
  --t-base: 150ms ease;
  --t-slow: 250ms ease;

  /* ---- Chips ---- */
  --chip-lead-bg: #eef2ff; --chip-lead-border: #c7d2fe; --chip-lead-text: #1d4ed8;
  --chip-owner-bg: #ecfdf5; --chip-owner-border: #a7f3d0; --chip-owner-text: #047857;
  --chip-task-bg: #f5f3ff; --chip-task-border: #ddd6fe; --chip-task-text: #6d28d9;
  --chip-comm-bg: #fff7ed; --chip-comm-border: #fed7aa; --chip-comm-text: #b45309;
  --chip-contact-bg: #f8fafc; --chip-contact-border: #e2e8f0; --chip-contact-text: #475569;
}

/* ── Reset & Base ─────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; overflow: hidden; }
body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--color-bg);
  font-size: 18px;
  color: var(--color-text);
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
[x-cloak] { display: none !important; }

/* ── Scrollbar ────────────────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--slate-300); border-radius: var(--r-full); }
::-webkit-scrollbar-thumb:hover { background: var(--slate-400); }

/* ── App Header ───────────────────────────────────────────────────────── */
.app-header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 var(--sp-4);
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 50px;
  position: sticky;
  top: 0;
  z-index: 200;
  box-shadow: 0 1px 0 var(--color-border), var(--shadow-xs);
  flex-shrink: 0;
}
.logo { height: 34px; object-fit: contain; cursor: pointer; }
.header-left { display: flex; align-items: center; gap: var(--sp-2); }
.header-right { display: flex; align-items: center; gap: var(--sp-2); }
.user-chip { position: relative; }
.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: var(--text-sm);
  font-weight: 600;
  color: var(--slate-800);
  background: var(--color-surface-raised);
  border: 1px solid var(--color-border);
  border-radius: var(--r-full);
  padding: 3px 10px 3px 4px;
  cursor: pointer;
  transition: background var(--t-fast), border-color var(--t-fast), box-shadow var(--t-fast);
}
.user-pill:hover { background: var(--blue-50); border-color: var(--blue-200); }
.user-pill.open {
  background: var(--blue-50);
  border-color: var(--blue-500);
  color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}
.user-pill-avatar {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-700), var(--blue-500));
  color: #fff;
  font-weight: 700;
  font-size: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.user-pill-caret { font-size: var(--text-2xs); opacity: .55; margin-left: 1px; }
.user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: 14px;
  box-shadow: 0 8px 24px rgba(15,23,42,.13), 0 2px 6px rgba(15,23,42,.07);
  width: 252px;
  overflow: hidden;
  z-index: 250;
  transform-origin: top right;
}
.user-menu-enter { transition: opacity 120ms ease, transform 120ms ease; }
.user-menu-enter-start { opacity: 0; transform: scale(.95) translateY(-4px); }
.user-menu-enter-end   { opacity: 1; transform: scale(1) translateY(0); }
.user-menu-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  background: linear-gradient(135deg, var(--blue-50) 0%, #eef2ff 100%);
  border-bottom: 1px solid var(--blue-100);
}
.user-monogram {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--blue-700), var(--blue-500));
  color: #fff;
  font-weight: 700;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(29,78,216,.30);
}
.user-menu-info { min-width: 0; }
.user-menu-name  { font-size: var(--text-md); font-weight: 700; color: var(--color-text); line-height: 1.3; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-menu-email { font-size: var(--text-sm); color: var(--slate-500); margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.user-menu-actions { padding: 8px; }
.user-menu-item {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: var(--text-md);
  font-weight: 600;
  color: var(--color-danger);
  text-decoration: none;
  padding: 8px 10px;
  border-radius: var(--r-lg);
  transition: background var(--t-fast), color var(--t-fast);
}
.user-menu-item:hover { background: var(--red-50); color: var(--red-700); }
.btn-settings {
  font-size: var(--text-base);
  background: var(--blue-50);
  color: var(--blue-700);
  border: 1px solid var(--blue-200);
  padding: 4px 10px;
  border-radius: var(--r-md);
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
  transition: background var(--t-fast);
}
.btn-settings:hover { background: var(--blue-100); }

/* ── Tab Nav ──────────────────────────────────────────────────────────── */
.main-tabs {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 var(--sp-4);
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  flex-shrink: 0;
  gap: 2px;
}
.main-tabs::-webkit-scrollbar { display: none; }
.tab {
  padding: 10px 14px;
  font-size: var(--text-sm);
  cursor: pointer;
  background: none;
  border: none;
  border-bottom: 3px solid transparent;
  color: var(--slate-500);
  font-weight: 500;
  white-space: nowrap;
  font-family: inherit;
  transition: color var(--t-base), border-color var(--t-base);
  margin-bottom: -1px;
  letter-spacing: .01em;
}
.tab:hover { color: var(--color-text); }
.tab-active { color: var(--blue-700) !important; border-bottom-color: var(--blue-700) !important; font-weight: 700; }
.tab-red.tab-active { color: var(--red-600) !important; border-bottom-color: var(--red-600) !important; }

/* ── Main Content ─────────────────────────────────────────────────────── */
.main-content {
  flex: 1;
  overflow-y: auto;
  overflow-x: hidden;
  padding: var(--sp-3) var(--sp-4);
  min-height: 0;
}
.tab-toolbar { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; flex-wrap: wrap; gap: 7px; }
.toolbar-left { display: flex; gap: 7px; align-items: center; }

/* ── Badges & Chips ───────────────────────────────────────────────────── */
.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: var(--r-full);
  font-size: var(--text-xs);
  font-weight: 700;
  margin-left: 4px;
  border: 1px solid transparent;
  background: var(--color-surface-raised);
  color: var(--slate-700);
  line-height: 1.4;
}
.badge-xs { font-size: var(--text-2xs); padding: 0 5px; }
.badge-red    { background: var(--red-50);    color: var(--red-600);    border-color: var(--red-200); }
.badge-amber  { background: var(--amber-50);  color: var(--amber-700);  border-color: var(--amber-200); }
.badge-slate  { background: var(--slate-50);  color: var(--slate-600);  border-color: var(--slate-200); }
.badge-success { background: var(--green-50); color: var(--green-700);  border-color: var(--green-200); }

.chip-lead    { background: var(--chip-lead-bg);    border-color: var(--chip-lead-border);    color: var(--chip-lead-text); }
.chip-owner   { background: var(--chip-owner-bg);   border-color: var(--chip-owner-border);   color: var(--chip-owner-text); }
.chip-task    { background: var(--chip-task-bg);    border-color: var(--chip-task-border);    color: var(--chip-task-text); }
.chip-comm    { background: var(--chip-comm-bg);    border-color: var(--chip-comm-border);    color: var(--chip-comm-text); }
.chip-contact { background: var(--chip-contact-bg); border-color: var(--chip-contact-border); color: var(--chip-contact-text); }

/* ── Buttons ──────────────────────────────────────────────────────────── */
.btn-primary {
  background: var(--color-primary);
  color: #fff;
  border: none;
  padding: 6px 13px;
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  letter-spacing: .01em;
}
.btn-primary:hover { background: var(--color-primary-hover); }

.btn-secondary {
  background: var(--color-surface);
  color: var(--slate-600);
  border: 1px solid var(--color-border);
  padding: 5px 11px;
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  cursor: pointer;
  font-family: inherit;
  font-weight: 500;
}
.btn-secondary:hover { background: var(--color-surface-raised); color: var(--color-text); }

.btn-danger {
  background: var(--red-50);
  color: var(--red-600);
  border: 1px solid var(--red-200);
  padding: 4px 9px;
  border-radius: var(--r-md);
  font-size: var(--text-sm);
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
}
.btn-open {
  background: var(--blue-50);
  color: var(--blue-700);
  border: none;
  padding: 4px 10px;
  border-radius: var(--r-md);
  font-size: var(--text-base);
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  white-space: nowrap;
}
.btn-icon {
  background: var(--slate-100);
  color: var(--slate-600);
  border: 1px solid var(--color-border);
  padding: 4px var(--sp-2);
  border-radius: var(--r-sm);
  font-size: var(--text-base);
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}

/* Thud click effect on all buttons */
.btn-primary, .btn-secondary, .btn-danger,
button.btn-primary, button.btn-secondary, button.btn-danger {
  transition: transform 60ms cubic-bezier(.3,0,.5,1), background var(--t-fast);
}
.btn-primary:active, button.btn-primary:active {
  transform: scale(0.94); background: var(--color-primary-active) !important;
}
.btn-secondary:active, button.btn-secondary:active {
  transform: scale(0.94); background: var(--slate-200) !important;
}
.btn-danger:active, button.btn-danger:active {
  transform: scale(0.94); background: var(--red-100) !important;
}

/* ── Tables ───────────────────────────────────────────────────────────── */
.tbl-wrap { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--r-lg); overflow-x: auto; box-shadow: var(--shadow-xs); }
table { width: 100%; border-collapse: collapse; min-width: 600px; }
thead tr { background: var(--color-surface-raised); }
th {
  padding: 8px 10px;
  font-size: var(--text-xs);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .6px;
  color: var(--slate-500);
  text-align: left;
  white-space: nowrap;
  border-bottom: 1px solid var(--color-border);
  vertical-align: top;
  position: sticky; top: 0; z-index: 5; background: var(--color-surface-raised);
}
th:hover { background: var(--slate-100); }
/* Sort button inside th */
.sort-btn {
  background: none; border: none; padding: 0; cursor: pointer;
  font-family: inherit; font-size: var(--text-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: .6px; color: var(--slate-500);
  display: flex; align-items: center; gap: 3px; white-space: nowrap;
}
.sort-btn:hover { color: var(--slate-700); }
.sort-icon { font-size: 9px; opacity: .55; }
td {
  padding: 8px 10px;
  font-size: var(--text-md);
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
  overflow: visible;
}
tr { overflow: visible; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--slate-50); }
tr.overdue td { background: var(--red-50); }
tr.overdue:hover td { background: var(--red-100); }
tr.overdue .field-select { background: #fff !important; }
table td select { height: 28px !important; overflow: hidden !important; }
.th-search {
  font-size: var(--text-sm);
  padding: 3px 6px;
  border: 1px solid var(--slate-300);
  border-radius: var(--r-sm);
  outline: none;
  font-family: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  width: 100%;
  min-width: 120px;
  margin-top: 4px;
  display: block;
  box-sizing: border-box;
  height: 26px;
  transition: border-color var(--t-base);
}
.th-search:focus { border-color: var(--color-primary); }
.th-search::placeholder { color: var(--slate-400); }
select.th-search {
  padding-right: 28px;
  appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--slate-500) 50%),
    linear-gradient(135deg, var(--slate-500) 50%, transparent 50%);
  background-position: calc(100% - 14px) 50%, calc(100% - 8px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}

table.data-table { table-layout: fixed; }
table.data-table th, table.data-table td { min-width: 120px; }
table.data-table th { cursor: default; }
table.data-table td { word-break: break-word; }

.table-field {
  width: 140px;
  font-size: var(--text-sm);
  border: none;
  border-bottom: 1px solid transparent;
  border-radius: 0;
  padding: 2px 0;
  font-family: inherit;
  color: var(--color-text);
  background: transparent;
  transition: border-color var(--t-base), box-shadow var(--t-base), background var(--t-base);
  min-height: 24px;
}
.table-field:focus {
  outline: none;
  border-bottom-color: var(--color-primary);
  background: #fff;
  box-shadow: inset 0 -1px 0 var(--color-primary);
}
.table-field--date { width: 140px; }
.table-field--date::-webkit-calendar-picker-indicator {
  opacity: 0; transition: opacity var(--t-base);
}
.table-field--date:focus::-webkit-calendar-picker-indicator { opacity: 1; }
.table-field--select {
  width: 150px; min-height: 26px; cursor: pointer;
  padding-right: 0; appearance: none; background-image: none;
}
.table-field--select:focus {
  padding-right: 22px;
  background-image: linear-gradient(45deg, transparent 50%, var(--color-primary) 50%),
    linear-gradient(135deg, var(--color-primary) 50%, transparent 50%);
  background-position: calc(100% - 12px) 55%, calc(100% - 6px) 55%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
}
.table-field--wide   { width: 180px; }
.table-field--narrow { width: 120px; }
.table-field--linker { width: 100%; min-width: 0; padding: 2px 0; font-size: var(--text-sm); }
.table-field--overdue { color: var(--red-700); border-bottom-color: #f87171; background: transparent; }
select.table-field { padding: 0; }
.lead-title-wrap {
  display: inline-flex; align-items: center; gap: 6px; max-width: 220px;
}
.lead-title-text {
  font-weight: 600; font-size: var(--text-base);
  min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.owner-link-btn {
  width: 26px; height: 26px;
  border-radius: var(--r-md);
  border: 1px solid var(--chip-owner-border);
  background: var(--chip-owner-bg);
  color: var(--chip-owner-text);
  display: inline-flex; align-items: center; justify-content: center;
  padding: 0; cursor: pointer; line-height: 1; font-family: inherit;
  transition: background var(--t-base), border-color var(--t-base), transform var(--t-base);
}
.owner-link-btn svg { width: 14px; height: 14px; }
.owner-link-btn:hover { background: #d1fae5; border-color: #34d399; }
.owner-link-btn:active { transform: scale(0.9); }
.owner-link-btn:focus-visible { outline: 2px solid #10b981; outline-offset: 2px; }
.owner-link-btn--sm { width: 22px; height: 22px; }
.col-count { font-size: var(--text-base); color: var(--slate-500); }
.td-muted  { font-size: var(--text-sm); color: var(--slate-500); }
.contacts-inline-hint { font-size: var(--text-sm); color: var(--slate-500); margin-bottom: 6px; }
.contacts-table td { font-size: var(--text-sm); color: var(--slate-800); }
.contacts-inline-input,
.contacts-inline-select,
.contacts-inline-notes {
  width: 100%; font-size: var(--text-sm); border: none;
  border-bottom: 1px solid transparent; padding: 2px 0;
  font-family: inherit; background: transparent; color: var(--color-text);
  transition: background var(--t-base), border-color var(--t-base);
}
.contacts-inline-input::placeholder, .contacts-inline-notes::placeholder { color: var(--slate-400); }
.contacts-inline-input:focus, .contacts-inline-select:focus, .contacts-inline-notes:focus {
  outline: none;
  border-bottom-color: var(--color-primary);
  background: #fff;
  box-shadow: inset 0 -1px 0 var(--color-primary);
}
.contacts-inline-select {
  min-height: 26px; padding-right: 14px; appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, var(--slate-500) 50%),
    linear-gradient(135deg, var(--slate-500) 50%, transparent 50%);
  background-position: calc(100% - 10px) 45%, calc(100% - 6px) 45%;
  background-size: 4px 4px, 4px 4px;
  background-repeat: no-repeat;
}
.contacts-inline-notes { min-height: 36px; resize: vertical; }
.contact-inline-row td:first-child input { font-weight: 600; }
.contact-inline-row td:nth-child(7) textarea { max-height: 80px; }
.contact-row-actions-cell { text-align: right; width: 170px; }
.contact-row-actions { display: inline-flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.btn-xs { font-size: var(--text-xs); padding: 4px var(--sp-2); line-height: 1.2; }
.contact-row-indicator {
  display: none; margin-top: 6px; font-size: var(--text-xs);
  color: var(--teal-700); gap: 6px; align-items: center; justify-content: flex-end;
}
.contact-row-indicator .spinner { width: 14px; height: 14px; border-width: 2px; }
.contact-row-indicator.htmx-request { display: inline-flex; }
.contact-inline-row.htmx-request td { background: var(--blue-50) !important; }

/* ── Status Pill ──────────────────────────────────────────────────────── */
.status-pill {
  display: inline-block; padding: 2px 9px; border-radius: var(--r-full);
  font-size: var(--text-sm); font-weight: 700; white-space: nowrap; border: 1px solid;
}
.status-select-inline {
  font-size: var(--text-sm); border: none; background: transparent;
  cursor: pointer; font-weight: 700; font-family: inherit; padding: 0;
}

/* ── Panel Stack ──────────────────────────────────────────────────────── */
.panel-stack { position: fixed; inset: 0; pointer-events: none; z-index: 300; }
.panel-backdrop {
  position: absolute; inset: 0; background: rgba(15,23,42,.4);
  display: flex; justify-content: flex-end; pointer-events: all;
  backdrop-filter: blur(1px);
}
.panel-inner {
  background: var(--color-surface); height: 100vh; overflow: hidden;
  box-shadow: var(--shadow-panel); position: relative;
  display: flex; flex-direction: row; max-width: 98vw;
}
@supports (height: 100dvh) { .panel-inner { height: 100dvh; } }
.panel-inner.panel-mobile {
  width: 100vw !important; max-width: 100vw !important;
  height: 100% !important; max-height: 100% !important;
  border-radius: 0; box-shadow: none;
}
.panel-inner.panel-mobile .panel-vtab-bar,
.panel-inner.panel-mobile .panel-drag-handle { display: none !important; }
.panel-inner.panel-mobile .panel-header {
  position: sticky; top: 0; z-index: 10;
  padding-top: calc(10px + env(safe-area-inset-top));
  flex-wrap: wrap;
}
.panel-inner.panel-mobile .panel-header > div:first-child {
  padding-right: 40px;
}
.panel-inner.panel-mobile .panel-header-actions {
  width: 100%; margin-top: 8px;
  justify-content: flex-start; flex-wrap: wrap;
}
.panel-inner.panel-mobile .btn-panel-close {
  position: absolute; top: calc(8px + env(safe-area-inset-top)); right: 10px;
}
.panel-inner.panel-mobile .panel-content {
  flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch;
  padding-bottom: env(safe-area-inset-bottom, 16px);
  scroll-padding-bottom: 60px;
}
.panel-content {
  flex: 1; overflow-y: auto; display: block; min-width: 0; min-height: 0;
}
.panel-content > form {
  display: flex; flex-direction: column; min-height: 100%; height: auto; padding-bottom: 48px;
}
.panel-form { display: flex; flex-direction: column; height: 100%; }

/* ── Panel Vertical Tab Rail ──────────────────────────────────────────── */
.panel-vtab-bar {
  width: 40px; flex-shrink: 0;
  background: var(--slate-900); border-right: 1px solid var(--slate-800);
  display: flex; flex-direction: column;
  overflow-y: auto; overflow-x: hidden;
  position: relative; z-index: 30;
}
.panel-vtab-bar::-webkit-scrollbar { width: 2px; }
.pvtab {
  display: flex; flex-direction: column; align-items: center;
  padding: 12px 0 8px; flex-shrink: 0; min-height: 72px;
  cursor: pointer; border: none; background: none;
  font-family: inherit; position: relative;
  border-right: 3px solid transparent;
  transition: background var(--t-base);
}
.pvtab:hover { background: rgba(255,255,255,.07); }
.pvtab.active { border-right-color: var(--blue-500); background: rgba(59,130,246,.14); }
.pvtab-label {
  writing-mode: vertical-rl; transform: rotate(180deg);
  font-size: var(--text-sm); font-weight: 600; color: var(--slate-500);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  max-height: 116px; transition: color var(--t-base);
}
.pvtab.active .pvtab-label { color: var(--slate-200); }
.pvtab:hover .pvtab-label { color: var(--slate-400); }
.pvtab-close {
  position: absolute; top: 4px; right: 3px;
  font-size: var(--text-xs); line-height: 1; color: var(--slate-600);
  opacity: 0; transition: opacity var(--t-base);
}
.pvtab:hover .pvtab-close { opacity: .65; }
.pvtab-close:hover { opacity: 1 !important; color: var(--slate-200); }

/* ── Panel Drag Handle ────────────────────────────────────────────────── */
.panel-drag-handle {
  position: absolute; left: 0; top: 0; bottom: 0; width: 8px;
  cursor: col-resize; z-index: 20; background: transparent;
}
.panel-drag-handle:hover { background: rgba(29,78,216,.2); }

/* ── Panel Header — Dark Navy ─────────────────────────────────────────── */
.panel-header {
  background: var(--slate-800);
  border-bottom: 1px solid var(--slate-700);
  padding: 13px 18px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}
.panel-title    { font-size: var(--text-lg); font-weight: 700; color: var(--slate-50); }
.panel-subtitle { font-size: var(--text-sm); color: var(--slate-400); margin-top: 2px; }
.panel-subtitle a { color: var(--blue-400, #60a5fa); text-decoration: none; }
.panel-subtitle a:hover { text-decoration: underline; }
.panel-subtitle-hint { font-size: var(--text-xs); color: #34d399; margin-top: 2px; }
.panel-entity-type { color: var(--slate-300); }
.panel-id { color: var(--slate-500); }
.panel-header-actions { display: flex; gap: 6px; align-items: center; }

.btn-panel-close {
  background: rgba(255,255,255,.1); color: var(--slate-300); border: none;
  padding: 5px 10px; border-radius: var(--r-md); cursor: pointer;
  font-family: inherit; font-size: var(--text-lg);
  transition: background var(--t-fast);
}
.btn-panel-close:hover { background: rgba(255,255,255,.18); color: var(--slate-100); }
.btn-panel-close:active { transform: scale(0.94); }

.btn-panel-save {
  background: var(--blue-500); color: #fff; border: none;
  padding: 5px 15px; border-radius: var(--r-md); font-size: var(--text-sm);
  font-weight: 700; cursor: pointer; font-family: inherit;
  transition: transform 60ms cubic-bezier(.3,0,.5,1), background var(--t-fast);
}
.btn-panel-save:hover { background: var(--blue-600); }
.btn-panel-save:active { transform: scale(0.94); background: var(--blue-700) !important; }

.btn-panel-delete {
  background: rgba(220,38,38,.12); color: #fca5a5;
  border: 1px solid rgba(220,38,38,.3); padding: 4px var(--sp-2);
  border-radius: var(--r-sm); font-size: var(--text-base); font-weight: 700;
  cursor: pointer; font-family: inherit;
  transition: transform 60ms cubic-bezier(.3,0,.5,1), background var(--t-fast);
}
.btn-panel-delete:hover { background: rgba(220,38,38,.22); }
.btn-panel-delete:active { transform: scale(0.94); background: rgba(220,38,38,.35) !important; }

/* Secondary actions in panel header (e.g. Email link) */
.panel-header .btn-secondary {
  background: rgba(255,255,255,.1);
  color: var(--slate-300);
  border-color: rgba(255,255,255,.15);
  font-size: var(--text-xs);
}
.panel-header .btn-secondary:hover {
  background: rgba(255,255,255,.18);
  color: var(--slate-100);
}

.panel-header button:active { transform: scale(0.94); }

/* ── Panel Two-Col Layout ─────────────────────────────────────────────── */
.panel-two-col {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 575px;
  min-height: 100%;
  overflow: visible;
}
.panel-main {
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  overflow-y: visible;
}
.panel-sidebar {
  padding: var(--sp-3);
  display: flex;
  flex-direction: column;
  gap: var(--sp-3);
  background: var(--color-surface-raised);
  border-left: 1px solid var(--color-border);
  overflow-y: visible;
}

@media (max-width: 820px) {
  .panel-two-col { grid-template-columns: 1fr !important; }
  .panel-sidebar {
    display: flex; flex-direction: column; width: 100%;
    border-left: none; border-top: 1px solid var(--color-border);
    margin-top: 10px; padding-top: var(--sp-3); padding-bottom: 6px;
  }
  .panel-main { padding-bottom: 0; }
}

/* ── Mini Map ─────────────────────────────────────────────────────────── */
.panel-mini-map {
  isolation: isolate; position: relative; contain: layout paint;
  border: 1px solid var(--color-border); border-radius: var(--r-lg);
  overflow: hidden; height: 180px; flex-shrink: 0;
}
.panel-mini-map .leaflet-pane { z-index: 1 !important; }
.panel-mini-map .leaflet-top, .panel-mini-map .leaflet-bottom { z-index: 2 !important; }

/* ── Main map ─────────────────────────────────────────────────────────── */
#map-container { position: relative; z-index: 0; }

/* ── Custom map popup ─────────────────────────────────────────────────── */
.erp-popup .leaflet-popup-content-wrapper {
  padding: 0; border-radius: var(--r-xl); overflow: hidden;
  box-shadow: var(--shadow-xl);
}
.erp-popup .leaflet-popup-content { margin: 0; width: auto !important; }
.erp-popup .leaflet-popup-tip-container { margin-top: -1px; }

/* ── Map filters overlay ──────────────────────────────────────────────── */
.map-filter-bar {
  position: absolute; top: 10px; left: 50px; right: 10px; z-index: 800;
  display: flex; gap: 6px; align-items: center;
}
.map-filter-select {
  flex: 1; min-width: 0;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--r-md); padding: 5px 10px;
  font-size: var(--text-sm); font-weight: 500; color: var(--slate-800);
  box-shadow: var(--shadow-sm); cursor: pointer; outline: none;
}
.map-filter-select:focus { border-color: var(--color-primary); box-shadow: 0 0 0 3px rgba(29,78,216,.12); }
.map-filter-badge {
  background: var(--color-primary); color: #fff; border-radius: var(--r-full);
  padding: 3px 10px; font-size: var(--text-xs); font-weight: 600; white-space: nowrap;
}
.map-filter-clear {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--r-md); padding: 5px 8px;
  font-size: var(--text-xs); color: var(--slate-500); cursor: pointer;
  box-shadow: var(--shadow-sm);
}
.map-filter-clear:hover { background: var(--color-surface-raised); color: var(--slate-800); }

/* ── Field Groups ─────────────────────────────────────────────────────── */
.field-group { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--r-lg); overflow: visible; }

.collapsible-hdr {
  display: flex !important; align-items: center; justify-content: space-between;
  padding: 8px 14px; border-bottom: 1px solid var(--color-border);
  font-size: var(--text-xs); font-weight: 700;
  text-transform: uppercase; letter-spacing: .8px;
  color: var(--slate-500); background: var(--color-surface-raised);
  cursor: pointer; user-select: none;
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  transition: background var(--t-base);
}
.collapsible-hdr:hover { background: var(--slate-100); }
.collapsible-hdr.closed { border-bottom: none; border-radius: var(--r-lg); }
.collapsible-body { padding: 10px 12px; }

.field-grid   { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: var(--sp-2); }
.field-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-2); }
.field-grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: var(--sp-2); }
.field-full   { grid-column: 1 / -1; }

/* ── Form Fields ──────────────────────────────────────────────────────── */
.field-label {
  font-size: var(--text-xs); font-weight: 700; color: var(--slate-500);
  display: flex; align-items: center; gap: 3px;
  margin-bottom: 2px; text-transform: uppercase; letter-spacing: .5px;
}
.field-label .req { color: var(--color-danger); }
.field-input {
  background: transparent; border: none; border-bottom: 1px solid var(--slate-300);
  color: var(--color-text); padding: 5px 2px; border-radius: 0;
  font-size: var(--text-md); width: 100%; outline: none; font-family: inherit;
  transition: border-color var(--t-base), box-shadow var(--t-base);
}
.field-input[type="date"],
.field-input[type="datetime-local"],
.field-input[type="time"] { width: 100%; min-width: 0; max-width: 100%; box-sizing: border-box; }
.field-input:focus { border-bottom-color: var(--color-primary); box-shadow: inset 0 -1px 0 var(--color-primary); }
.field-input:disabled { background: transparent; color: var(--slate-400); }
.field-textarea {
  background: var(--slate-50); border: 1px solid var(--slate-200);
  color: var(--color-text); padding: 6px var(--sp-2); border-radius: var(--r-sm);
  font-size: var(--text-base); width: 100%; outline: none; resize: vertical;
  font-family: inherit; min-height: 80px;
  transition: border-color var(--t-base);
}
.field-textarea:focus { border-color: var(--color-primary); }
.field-select {
  background: transparent; border: none; border-bottom: 1px solid var(--slate-300);
  color: var(--color-text); padding: 5px 2px; border-radius: 0;
  font-size: var(--text-md); width: 100%; outline: none; cursor: pointer;
  font-family: inherit; height: auto;
  transition: border-color var(--t-base);
}
.field-select:focus { border-bottom-color: var(--color-primary); outline: none; }
.date-input-wrap { display: flex; align-items: center; gap: 6px; width: 100%; }
.date-input-wrap .field-input { flex: 1; }
.date-clear-btn {
  background: var(--slate-100); border: 1px solid var(--slate-300); color: var(--slate-600);
  border-radius: var(--r-md); padding: 5px var(--sp-2); font-size: var(--text-base);
  font-weight: 600; cursor: pointer; flex-shrink: 0;
  transition: background var(--t-base);
}
.date-clear-btn:hover { background: var(--slate-200); }
.date-clear-btn:active { transform: scale(0.94); }
.sched-wrap { background: var(--sky-100); border: 1px solid #7dd3fc; border-radius: var(--r-md); padding: 7px var(--sp-2); }
.sched-wrap .field-label { color: var(--sky-700) !important; }

/* ── Top Bar (pinned fields) ──────────────────────────────────────────── */
.top-bar { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--r-lg); overflow: visible; }
.top-bar-row { padding: 8px 12px; display: grid; gap: var(--sp-2); align-items: end; }
.top-bar-row + .top-bar-row { border-top: 1px solid var(--color-border); }

/* ── Comm Card ────────────────────────────────────────────────────────── */
.comm-card { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--r-lg); overflow: hidden; }
.comm-card-hdr { display: flex; align-items: center; gap: var(--sp-2); padding: 8px 12px; cursor: pointer; transition: background var(--t-base); }
.comm-card-hdr:hover { background: var(--color-surface-raised); }
.comm-channel-icon {
  width: 26px; height: 26px; border-radius: var(--r-md);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-md); flex-shrink: 0;
}
.comm-card-body {
  padding: 10px 12px; border-top: 1px solid var(--color-border);
  background: var(--color-surface-raised); font-size: var(--text-md); line-height: 1.6;
}
.comm-card, .comm-card-hdr, .comm-card-body { width: 100%; max-width: 100%; }
.comm-card-hdr > * { min-width: 0; }
.comm-card-body { overflow-x: auto; }
.comm-body-html { max-width: 100%; overflow-wrap: anywhere; word-break: break-word; }
.comm-body-html img,
.comm-body-html table,
.comm-body-html iframe,
.comm-body-html pre { max-width: 100%; width: 100%; }
.comm-body-html pre { white-space: pre-wrap; }
.comm-ai { background: #fdf4ff; border: 1px solid var(--purple-200); border-radius: var(--r-md); padding: 8px 10px; margin-top: 8px; font-size: var(--text-base); }
.comm-ai-label { font-size: var(--text-sm); font-weight: 700; color: var(--purple-600); text-transform: uppercase; letter-spacing: .5px; margin-bottom: 5px; }

/* ── File Manager ─────────────────────────────────────────────────────── */
.attachments-block {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--r-xl);
  padding: var(--sp-3);
  display: flex; flex-direction: column; gap: var(--sp-3);
}
.att-block-hdr { display: flex; justify-content: space-between; align-items: flex-start; gap: var(--sp-3); }
.att-block-title { font-size: 15px; font-weight: 700; color: var(--slate-900); }
.att-block-subtitle { font-size: var(--text-base); color: var(--slate-500); }
.att-hdr-actions { display: flex; gap: 6px; }
.att-list { display: flex; flex-direction: column; gap: 6px; }
.att-row {
  display: flex; align-items: center; gap: var(--sp-3);
  padding: 9px 12px; border: 1px solid var(--color-border);
  border-radius: var(--r-lg); background: var(--color-surface-raised);
  transition: border-color var(--t-base);
}
.att-row:hover { border-color: var(--slate-300); }
.att-icon-chip {
  width: 36px; height: 36px; border-radius: var(--r-lg);
  background: #e0e7ff; color: #312e81;
  display: flex; align-items: center; justify-content: center;
  font-size: var(--text-xl); flex-shrink: 0;
}
.att-info { flex: 1; min-width: 0; }
.att-name {
  font-size: 15px; font-weight: 700; color: var(--color-text);
  background: none; border: none; padding: 0; cursor: pointer;
  text-align: left; font-family: inherit; width: 100%;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  transition: color var(--t-base);
}
.att-name:hover { color: var(--color-primary); }
.att-name-unavailable { opacity: .5; cursor: default; }
.att-name-unavailable:hover { color: inherit; }
.att-meta { font-size: var(--text-sm); color: var(--slate-500); margin-top: 2px; }
.att-actions { display: flex; gap: 6px; align-items: center; }
.att-btn {
  border: 1px solid var(--blue-100); background: var(--blue-50); color: var(--blue-700);
  padding: 4px 9px; border-radius: var(--r-md); font-size: var(--text-sm); font-weight: 700;
  cursor: pointer; font-family: inherit;
  display: inline-flex; align-items: center; gap: 4px; text-decoration: none;
  transition: background var(--t-fast);
}
.att-btn:hover { background: #e0e7ff; }
.att-btn.ghost { background: var(--color-surface); border-color: var(--color-border); color: var(--slate-600); }
.att-btn.ghost:hover { background: var(--color-surface-raised); }
.att-btn.danger { background: var(--red-50); border-color: var(--red-200); color: var(--red-600); }
.att-btn.danger:hover { background: var(--red-100); }
.att-btn-cover-on { background: var(--amber-50); border-color: var(--amber-200); color: var(--amber-800); }
.att-btn-cover-on:hover { background: var(--amber-100); }
.att-row-cover { background: var(--amber-50); border-radius: var(--r-md); }
.att-cover-preview { margin-bottom: 8px; }
.att-empty {
  border: 1px dashed var(--slate-300); border-radius: var(--r-lg);
  padding: 16px; font-size: var(--text-md); color: var(--slate-400); text-align: center;
}
.att-drop-wrap { border: 1px dashed var(--color-border); border-radius: var(--r-xl); padding: 6px; background: var(--color-surface-raised); }
.drop-zone {
  border: 2px dashed var(--slate-300); border-radius: var(--r-lg);
  padding: 14px; text-align: center; cursor: pointer;
  transition: all var(--t-base); font-size: var(--text-md); color: var(--slate-600); background: var(--color-surface);
}
.drop-zone:hover, .drop-zone.dragover { border-color: var(--color-primary); background: var(--blue-50); color: var(--color-primary); }
.att-uploading { display: flex; align-items: center; justify-content: center; gap: var(--sp-2); font-weight: 600; color: var(--color-primary); }
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid var(--slate-300); border-top-color: var(--color-primary);
  animation: spin 0.8s linear infinite;
}
@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }
.att-table { width: 100%; border-collapse: collapse; font-size: var(--text-md); }
.att-table th { padding: 5px var(--sp-2); font-size: var(--text-sm); font-weight: 700; text-transform: uppercase; color: var(--slate-500); background: var(--color-surface-raised); border-bottom: 1px solid var(--color-border); text-align: left; }
.att-table td { padding: 6px var(--sp-2); border-bottom: 1px solid var(--color-border-light); vertical-align: middle; }
.att-table tr:last-child td { border-bottom: none; }

/* ── File Viewer ──────────────────────────────────────────────────────── */
.file-viewer {
  position: fixed; inset: 0; z-index: 1200;
  background: rgba(15,23,42,.88);
  display: flex; align-items: center; justify-content: center; padding: 30px;
}
.file-viewer-panel {
  width: min(960px, 96vw); height: min(85vh, 900px);
  background: var(--color-surface); border-radius: var(--r-2xl);
  box-shadow: 0 28px 64px rgba(15,23,42,.45);
  display: flex; flex-direction: column; overflow: hidden;
}
.file-viewer-bar {
  display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3);
  padding: 12px 18px; background: var(--slate-900); color: var(--slate-100);
}
.file-viewer-title { font-size: 15px; font-weight: 700; }
.file-viewer-actions { display: flex; gap: var(--sp-2); }
.file-viewer-frame { flex: 1; border: none; background: var(--color-surface); }

/* ── Autocomplete ─────────────────────────────────────────────────────── */
.ac-wrap { position: relative; }
.ac-dropdown {
  position: absolute; top: 100%; left: 0; right: 0; min-width: 180px;
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--r-lg); box-shadow: var(--shadow-lg); z-index: 100;
  max-height: 200px; overflow-y: auto;
}
.ac-item { padding: 7px 10px; font-size: 15px; cursor: pointer; transition: background var(--t-fast); }
.ac-item:hover { background: var(--blue-50); }

/* ── WYSIWYG ──────────────────────────────────────────────────────────── */
.wysiwyg-wrap { border: 1px solid var(--color-border); border-radius: var(--r-md); overflow: hidden; }
.wysiwyg-toolbar { display: flex; gap: 2px; padding: 4px 6px; border-bottom: 1px solid var(--color-border); background: var(--color-surface-raised); flex-wrap: wrap; }
.wysiwyg-toolbar button { background: none; border: 1px solid transparent; border-radius: var(--r-xs); padding: 2px 5px; cursor: pointer; font-size: var(--text-base); color: var(--slate-600); font-family: inherit; transition: background var(--t-fast); }
.wysiwyg-toolbar button:hover { background: var(--slate-200); border-color: var(--slate-300); }
.wysiwyg-toolbar button.active { background: var(--blue-100); color: var(--blue-700); border-color: var(--blue-200); }
.wysiwyg-editor { min-height: 100px; padding: 8px 10px; font-size: var(--text-lg); line-height: 1.6; color: var(--color-text); outline: none; overflow-y: auto; }
.wysiwyg-editor:empty::before { content: attr(data-placeholder); color: var(--slate-400); }
.wysiwyg-editor p { margin: 0 0 0.6em 0; }
.wysiwyg-editor p:last-child { margin-bottom: 0; }

/* ── Related Items ────────────────────────────────────────────────────── */
.related-table { width: 100%; border-collapse: collapse; font-size: var(--text-md); margin-top: 6px; min-width: auto; }
.related-table th { padding: 4px 6px; font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; color: var(--slate-500); background: var(--color-bg); border-bottom: 1px solid var(--color-border); text-align: left; overflow: hidden; text-overflow: ellipsis; }
.related-table td { padding: 5px 6px; border-bottom: 1px solid var(--color-border-light); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.related-table th:last-child, .related-table td:last-child { width: 50px; min-width: 50px; max-width: 50px; overflow: visible; white-space: normal; text-align: center; padding: 5px 2px; }
.related-table tr:last-child td { border-bottom: none; }
.related-table tr:hover td { background: var(--color-surface-raised); }

/* × button in related tables */
.related-table td:last-child button, .btn-unlink {
  background: none; border: none; color: var(--slate-400);
  cursor: pointer; font-size: 20px; font-weight: 700;
  line-height: 1; padding: 4px 6px; transition: color var(--t-base);
  display: inline-block !important; min-width: 24px; text-align: center;
}
.related-table td:last-child button:hover, .related-table tr:hover td:last-child button,
.btn-unlink:hover, .related-table tr:hover .btn-unlink { color: #ef4444; }
.related-link { color: var(--color-primary); font-weight: 600; cursor: pointer; text-decoration: none; }
.related-link:hover { text-decoration: underline; }

/* ── Toast ────────────────────────────────────────────────────────────── */
.toast { position: fixed; bottom: 24px; right: 24px; background: var(--slate-900); color: var(--slate-100); padding: 10px 18px; border-radius: var(--r-lg); font-size: 15px; font-weight: 600; z-index: 9999; box-shadow: var(--shadow-xl); }
.save-toast { background: var(--green-50); color: var(--green-700); border: 1px solid var(--green-200); border-radius: var(--r-sm); padding: 5px 10px; font-size: var(--text-base); font-weight: 600; display: inline-block; }
.error-msg { color: var(--color-danger); font-size: var(--text-base); font-weight: 600; margin-top: 4px; }

/* ── Type Badges ──────────────────────────────────────────────────────── */
.type-badge { display: inline-block; padding: 2px 7px; border-radius: var(--r-full); font-size: var(--text-xs); font-weight: 700; border: 1px solid; }
.type-task  { background: var(--purple-50);  color: var(--purple-700); border-color: var(--purple-200); }
.type-lead  { background: var(--green-50);   color: var(--green-700);  border-color: var(--green-200); }
.type-owner { background: var(--teal-50);    color: var(--teal-700);   border-color: var(--teal-200); }

/* ── Settings Panel ───────────────────────────────────────────────────── */
.settings-panel { width: min(900px, calc(100vw - 10px)); overflow-y: auto; }
.settings-section { background: var(--color-surface); border: 1px solid var(--color-border); border-radius: var(--r-lg); margin-bottom: var(--sp-3); overflow: hidden; }
.settings-hdr { padding: 10px 14px; border-bottom: 1px solid var(--color-border); font-size: var(--text-base); font-weight: 700; color: var(--color-text); background: var(--color-surface-raised); }
.settings-body { padding: 14px; }

/* ── Overdue Dashboard ────────────────────────────────────────────────── */
.od-cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: var(--sp-3); }
.od-card {
  background: var(--color-surface); border-radius: var(--r-lg); padding: 12px 14px;
  cursor: pointer; border: 2px solid; transition: border-color var(--t-base), box-shadow var(--t-base);
  box-shadow: var(--shadow-xs);
}
.od-card:hover { box-shadow: var(--shadow-md); }
.od-card-num { font-size: 28px; font-weight: 900; line-height: 1; }
.od-card-label { font-size: var(--text-xs); font-weight: 700; text-transform: uppercase; letter-spacing: .5px; margin-top: 3px; }
.od-card-clear { font-size: var(--text-2xs); color: var(--green-700); margin-top: 2px; }
.od-card--task  .od-card-num, .od-card--task  .od-card-label { color: var(--red-600); }
.od-card--lead  .od-card-num, .od-card--lead  .od-card-label { color: #c2410c; }
.od-card--owner .od-card-num, .od-card--owner .od-card-label { color: var(--amber-700); }
.od-load-more td { padding: var(--sp-2); text-align: center; color: var(--slate-400); font-size: var(--text-xs); }
.od-empty-state {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--r-lg); padding: 40px; text-align: center;
}
.od-empty-state-icon { font-size: 32px; margin-bottom: 8px; }
.od-empty-state-text { font-size: var(--text-lg); font-weight: 700; color: var(--color-text); }
.od-filters { display: flex; gap: 7px; margin-bottom: 10px; flex-wrap: wrap; }
.od-search { width: 200px; }
.od-filter-btn-active { background: var(--blue-50) !important; color: var(--blue-700) !important; border-color: var(--blue-200) !important; font-weight: 700 !important; }
.od-subject  { font-weight: 600; font-size: var(--text-sm); }
.od-due-date { color: var(--red-600); font-weight: 700; font-size: var(--text-xs); }
.od-status-item {
  padding: 7px 14px; cursor: pointer; font-size: var(--text-sm); color: var(--slate-700);
  transition: background var(--t-fast);
}
.od-status-item:hover { background: var(--slate-100); }

/* ── Login ────────────────────────────────────────────────────────────── */
.login-wrap {
  min-height: 100vh; display: flex; align-items: center; justify-content: center;
  background: linear-gradient(135deg, var(--slate-100) 0%, #eef2ff 100%);
}
.login-box {
  background: var(--color-surface); border: 1px solid var(--color-border);
  border-radius: var(--r-2xl); padding: 36px 32px;
  width: 380px; box-shadow: var(--shadow-xl);
}
.login-logo { text-align: center; margin-bottom: 22px; }
.login-logo img { height: 48px; }
.login-title { font-size: var(--text-2xl); font-weight: 700; color: var(--color-text); text-align: center; margin-bottom: 22px; }
.login-error {
  background: var(--red-50); border: 1px solid var(--red-200);
  border-radius: var(--r-md); padding: 10px 12px; margin-bottom: 14px;
  color: var(--red-600); font-size: var(--text-sm); font-weight: 600;
}
.login-form-field { margin-bottom: 14px; }
.login-form-field-last { margin-bottom: 22px; }
.login-submit { width: 100%; padding: 11px; font-size: var(--text-md); }

/* ── Leaflet Overrides ────────────────────────────────────────────────── */
.leaflet-container { border-radius: 0 !important; }
.leaflet-popup-content-wrapper { border-radius: var(--r-xl) !important; padding: 0 !important; overflow: hidden; box-shadow: 0 8px 30px rgba(0,0,0,.18) !important; }
.leaflet-popup-content { margin: 0 !important; min-width: 200px; }
.leaflet-popup-tip { display: none; }

/* ── Mobile ───────────────────────────────────────────────────────────── */
@media (max-width: 768px) {
  .hide-mobile { display: none !important; }
  .app-header { height: 44px; padding: 0 10px; }
  .logo { height: 28px; }
  .header-right { gap: 5px; }
  .main-tabs { padding: 0 var(--sp-2); }
  .tab { padding: 8px 9px; font-size: var(--text-base); }
  .main-content { padding: var(--sp-2); }
  .tab-toolbar { margin-bottom: 6px; }
  .btn-primary, .btn-secondary, .btn-open { font-size: var(--text-base); padding: 4px var(--sp-2); }
  th { padding: 6px; font-size: var(--text-xs); }
  td { padding: 6px; font-size: var(--text-base); }
  .th-search { width: 64px; font-size: var(--text-xs); padding: 2px 4px; }
  .col-count { font-size: var(--text-sm); }

  .panel-backdrop { justify-content: stretch; align-items: stretch; padding: 0; }
  .panel-inner { width: 100vw !important; max-width: 100vw !important; height: 100% !important; border-radius: 0; }
  .panel-vtab-bar { display: none !important; }
  .panel-header { padding: 8px 10px; flex-wrap: wrap; gap: 6px; }
  .panel-title { font-size: 15px; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
  .panel-subtitle { font-size: var(--text-xs); }
  .panel-header-actions { gap: 4px; flex-shrink: 0; }
  .btn-panel-save { padding: 4px 9px; font-size: var(--text-base); }
  .btn-panel-close { padding: 3px 7px; font-size: var(--text-md); }
  .btn-panel-delete { padding: 3px 6px; font-size: var(--text-sm); }
  .panel-main { padding: var(--sp-2); gap: var(--sp-2); }
  .panel-sidebar { padding: var(--sp-2); gap: var(--sp-2); }

  .tbl-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
  table { min-width: 0; }
  table.data-table { table-layout: auto; }
  table.data-table th, table.data-table td { min-width: 0; }
  .contacts-table { min-width: 460px; }
  .contacts-table th:nth-child(1), .contacts-table td:nth-child(1) { min-width: 110px; }
  .contacts-table th:nth-child(4), .contacts-table td:nth-child(4) { min-width: 140px; }
  .contacts-table th:nth-child(5), .contacts-table td:nth-child(5) { min-width: 120px; }
  .contacts-table th:last-child, .contacts-table td:last-child { min-width: 80px; }
  .table-field { width: 100%; }
  .table-field--date { width: 110px; }
  .table-field--select { width: 100%; }
  .table-field--wide { width: 100%; }
  .th-search { min-width: 0; }
  .lead-title-wrap { max-width: 130px; min-width: 60px; }
  .lead-title-text { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  td.open-col { width: 1%; white-space: nowrap; }
  .panel-content > form { min-width: 0; overflow-x: clip; }
  .panel-two-col { min-width: 0; overflow-x: clip; }
  .panel-main { min-width: 0; overflow-x: clip; }
  .panel-sidebar { min-width: 0; overflow-x: clip; }
  .related-table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 -2px; padding: 0 2px; }
  .related-table { min-width: 420px; }
  .od-cards { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
  .od-card { padding: 5px 6px; min-height: 56px; }
  .od-card-num { font-size: 18px; }
  .od-card-label { font-size: 9px; margin-top: 1px; letter-spacing: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .od-card-clear { display: none; }
  .od-filters { gap: 6px; flex-wrap: nowrap !important; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .od-search { width: 145px !important; min-width: 145px; }
  .od-filters .btn-secondary { padding: 4px var(--sp-2); font-size: var(--text-base); white-space: nowrap; }

  .top-bar-row { padding: 6px var(--sp-2); gap: 6px; }
  .collapsible-hdr { padding: 6px var(--sp-2); font-size: var(--text-xs); }
  .collapsible-body { padding: var(--sp-2); }
  .field-grid, .field-grid-2, .field-grid-4 { grid-template-columns: 1fr !important; }
  .field-label { font-size: var(--text-sm); margin-bottom: 3px; }
  .field-input, .field-select, .field-textarea { font-size: var(--text-md); padding: 6px var(--sp-2); }
  .field-select { height: 30px; }
  .comm-card-hdr { padding: 6px var(--sp-2); gap: 6px; }
  .comm-card-body { padding: var(--sp-2); font-size: var(--text-base); }
  .top-bar-row { grid-template-columns: 1fr !important; }
  .date-clear-btn { padding: 4px 6px; font-size: var(--text-sm); }
  .panel-content > form { padding-bottom: calc(80px + env(safe-area-inset-bottom, 16px)); }

  .login-box { width: calc(100vw - 32px); padding: 28px 20px; }
}

/* ── Silent HTMX swap transitions (API-driven background refreshes) ─────── */
.htmx-swapping { opacity: 0; transition: opacity 150ms ease-out; }
.htmx-settling  { opacity: 0; }
.htmx-added     { opacity: 0; }
.htmx-added.htmx-settling { opacity: 1; transition: opacity 150ms ease-in; }

/* ── Pill-link styles for comm panel related items ────────────────────── */
.pill-link {
  display: inline-flex; align-items: center; gap: 4px;
  background: var(--color-surface-raised); color: var(--slate-800);
  border: 1px solid transparent; padding: 3px var(--sp-2);
  border-radius: var(--r-full); font-size: var(--text-base); font-weight: 600;
}
.pill-link button, button.pill-link { cursor: pointer; }
.pill-link.pill-xs { font-size: var(--text-xs); padding: 2px 6px; }
.pill-link .related-link { cursor: pointer; }
.pill-link .related-link:hover { text-decoration: underline; }
.btn-unlink-pill {
  background: none; border: none; color: var(--slate-400);
  cursor: pointer; font-weight: 800; font-size: 15px;
  line-height: 1; padding: 0 2px; transition: color var(--t-base);
}
.btn-unlink-pill:hover { color: #ef4444; }
