/* CRM — modern visual system + light/dark themes (static CSS only) */
:root,
html[data-theme="light"] {
  color-scheme: light;
  --font: "DM Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --bg: #f4f6fb;
  --bg-elevated: #ffffff;
  --bg-muted: #eef1f8;
  --bg-soft: #f8f9fd;

  --text: #0f172a;
  --text-secondary: #475569;
  --text-muted: #64748b;
  --text-inverse: #f8fafc;

  --border: #e2e8f0;
  --border-strong: #cbd5e1;

  --brand: #4f46e5;
  --brand-hover: #4338ca;
  --brand-soft: #eef2ff;
  --brand-glow: rgba(79, 70, 229, 0.18);

  --accent: #06b6d4;
  --success: #059669;
  --success-soft: #ecfdf5;
  --danger: #e11d48;
  --danger-soft: #fff1f2;
  --danger-hover: #be123c;
  --warning: #d97706;
  --warning-soft: #fffbeb;
  --info: #0284c8;
  --info-soft: #e0f2fe;

  --sidebar-w: 16.5rem;
  --radius: 12px;
  --radius-sm: 8px;
  --radius-pill: 999px;
  --shadow-sm: 0 1px 2px rgba(15, 23, 42, 0.05);
  --shadow: 0 4px 16px rgba(15, 23, 42, 0.06);
  --shadow-lg: 0 12px 40px rgba(15, 23, 42, 0.1);
  --focus: 0 0 0 3px var(--brand-glow);
  --transition: 150ms ease;

  --layout-glow-1: rgba(79, 70, 229, 0.08);
  --layout-glow-2: rgba(6, 182, 212, 0.07);
  --topbar-bg: rgba(255, 255, 255, 0.82);
  --sidebar-bg: linear-gradient(180deg, #0f172a 0%, #111827 45%, #0b1220 100%);
  --sidebar-border: rgba(148, 163, 184, 0.12);
  --sidebar-text: #cbd5e1;
  --sidebar-hover: rgba(148, 163, 184, 0.12);
  --sidebar-active: linear-gradient(90deg, rgba(99, 102, 241, 0.35), rgba(99, 102, 241, 0.12));
  --sidebar-active-bar: #818cf8;
  --auth-bg: linear-gradient(160deg, #0f172a 0%, #1e1b4b 50%, #0f172a 100%);
  --auth-glow-1: rgba(99, 102, 241, 0.2);
  --auth-glow-2: rgba(6, 182, 212, 0.15);
  --auth-card-border: rgba(255, 255, 255, 0.12);
  --input-shadow: inset 0 1px 2px rgba(15, 23, 42, 0.03);
  --row-hover: rgba(79, 70, 229, 0.04);
  --badge-pursuit-bg: #eff6ff;
  --badge-pursuit-text: #1d4ed8;
  --badge-pursuit-border: #bfdbfe;
  --badge-agreement-bg: #fdf2f8;
  --badge-agreement-text: #be185d;
  --badge-agreement-border: #fbcfe8;
  --deal-hover-border: #c7d2fe;
  --chip-bg: var(--bg-muted);
  --theme-icon-sun: none;
  --theme-icon-moon: inline;
}

html[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0b1220;
  --bg-elevated: #111827;
  --bg-muted: #1a2332;
  --bg-soft: #151d2b;

  --text: #e8eef9;
  --text-secondary: #b6c2d6;
  --text-muted: #8b9bb3;
  --text-inverse: #f8fafc;

  --border: #243044;
  --border-strong: #334155;

  --brand: #818cf8;
  --brand-hover: #a5b4fc;
  --brand-soft: rgba(99, 102, 241, 0.18);
  --brand-glow: rgba(129, 140, 248, 0.28);

  --accent: #22d3ee;
  --success: #34d399;
  --success-soft: rgba(16, 185, 129, 0.14);
  --danger: #fb7185;
  --danger-soft: rgba(244, 63, 94, 0.14);
  --danger-hover: #fda4af;
  --warning: #fbbf24;
  --warning-soft: rgba(245, 158, 11, 0.14);
  --info: #38bdf8;
  --info-soft: rgba(14, 165, 233, 0.14);

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.35);
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 48px rgba(0, 0, 0, 0.45);
  --focus: 0 0 0 3px var(--brand-glow);

  --layout-glow-1: rgba(99, 102, 241, 0.12);
  --layout-glow-2: rgba(34, 211, 238, 0.08);
  --topbar-bg: rgba(17, 24, 39, 0.86);
  --sidebar-bg: linear-gradient(180deg, #070b14 0%, #0b1220 50%, #0a0f1a 100%);
  --sidebar-border: rgba(148, 163, 184, 0.1);
  --sidebar-text: #94a3b8;
  --sidebar-hover: rgba(148, 163, 184, 0.1);
  --sidebar-active: linear-gradient(90deg, rgba(99, 102, 241, 0.4), rgba(99, 102, 241, 0.1));
  --sidebar-active-bar: #a5b4fc;
  --auth-bg: linear-gradient(160deg, #05080f 0%, #0f172a 45%, #111827 100%);
  --auth-glow-1: rgba(99, 102, 241, 0.22);
  --auth-glow-2: rgba(34, 211, 238, 0.12);
  --auth-card-border: rgba(148, 163, 184, 0.14);
  --input-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.25);
  --row-hover: rgba(129, 140, 248, 0.08);
  --badge-pursuit-bg: rgba(59, 130, 246, 0.16);
  --badge-pursuit-text: #93c5fd;
  --badge-pursuit-border: rgba(59, 130, 246, 0.28);
  --badge-agreement-bg: rgba(236, 72, 153, 0.14);
  --badge-agreement-text: #f9a8d4;
  --badge-agreement-border: rgba(236, 72, 153, 0.28);
  --deal-hover-border: #6366f1;
  --chip-bg: #1a2332;
  --theme-icon-sun: inline;
  --theme-icon-moon: none;
}

/* System preference only when no explicit theme is set yet (boot script sets data-theme) */
@media (prefers-color-scheme: dark) {
  html:not([data-theme]) {
    color-scheme: dark;
  }
}

*, *::before, *::after { box-sizing: border-box; }

html {
  font-family: var(--font);
  line-height: 1.55;
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body { margin: 0; min-height: 100vh; }

a {
  color: var(--brand);
  text-decoration: none;
  transition: color var(--transition);
}
a:hover { color: var(--brand-hover); text-decoration: none; }

h1, h2, h3, h4 {
  margin: 0 0 0.75rem;
  line-height: 1.25;
  letter-spacing: -0.02em;
  font-weight: 700;
  color: var(--text);
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.2rem; }
h3 { font-size: 1.05rem; }

p { margin: 0 0 0.75rem; }
ul { margin: 0.25rem 0 0.75rem; padding-left: 1.15rem; }

/* —— Layout —— */
.layout {
  display: flex;
  min-height: 100vh;
  background:
    radial-gradient(1200px 500px at 10% -10%, var(--layout-glow-1), transparent 55%),
    radial-gradient(900px 400px at 100% 0%, var(--layout-glow-2), transparent 50%),
    var(--bg);
}

.sidebar {
  width: var(--sidebar-w);
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--text-inverse);
  padding: 1.25rem 0.9rem 1.5rem;
  display: flex;
  flex-direction: column;
  border-right: 1px solid var(--sidebar-border);
  box-shadow: 4px 0 24px rgba(0, 0, 0, 0.12);
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  font-weight: 800;
  font-size: 1.15rem;
  letter-spacing: -0.03em;
  color: #fff;
  margin: 0.15rem 0.5rem 1.35rem;
  padding-bottom: 1rem;
  border-bottom: 1px solid rgba(148, 163, 184, 0.15);
}

.sidebar .brand-mark {
  width: 2rem;
  height: 2rem;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  box-shadow: 0 6px 16px rgba(99, 102, 241, 0.45);
  font-size: 0.85rem;
  font-weight: 800;
}

.sidebar .nav-section {
  font-size: 0.68rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #64748b;
  margin: 0.85rem 0.65rem 0.4rem;
}

.sidebar a {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  color: var(--sidebar-text);
  padding: 0.55rem 0.75rem;
  border-radius: 10px;
  margin-bottom: 0.15rem;
  text-decoration: none;
  font-size: 0.92rem;
  font-weight: 500;
  transition: background var(--transition), color var(--transition), transform var(--transition);
}

.sidebar a:hover {
  background: var(--sidebar-hover);
  color: #fff;
}

.sidebar a.active {
  background: var(--sidebar-active);
  color: #fff;
  box-shadow: inset 3px 0 0 var(--sidebar-active-bar);
}

.main {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.9rem 1.5rem;
  background: var(--topbar-bg);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.reminder-menu {
  position: relative;
}
.reminder-bell-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  position: relative;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
}
.reminder-bell-btn:hover,
.reminder-bell-btn.is-open {
  background: var(--bg-muted);
  color: var(--brand);
  border-color: var(--brand);
  transform: translateY(-1px);
}
.reminder-bell-btn svg {
  width: 1.15rem;
  height: 1.15rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.reminder-bell-badge {
  position: absolute;
  top: -0.2rem;
  right: -0.2rem;
  display: block;
  min-width: 0;
  pointer-events: none;
}
.reminder-bell-count {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.1rem;
  height: 1.1rem;
  padding: 0 0.28rem;
  border-radius: var(--radius-pill);
  background: var(--danger);
  color: #fff;
  font-size: 0.65rem;
  font-weight: 700;
  line-height: 1;
}
.reminder-dropdown {
  position: absolute;
  right: 0;
  top: calc(100% + 0.45rem);
  width: min(22.5rem, calc(100vw - 2rem));
  max-height: min(24rem, 70vh);
  overflow: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md, 0 12px 40px rgba(15, 23, 42, 0.16));
  z-index: 40;
  padding: 0.35rem 0 0.5rem;
}
.reminder-dropdown-head {
  font-size: 0.78rem;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.45rem 0.9rem 0.35rem;
}
.reminder-empty {
  margin: 0;
  padding: 0.65rem 0.9rem 0.85rem;
  font-size: 0.9rem;
}
.reminder-rows {
  list-style: none;
  margin: 0;
  padding: 0;
}
.reminder-row {
  display: flex;
  align-items: flex-start;
  gap: 0.5rem;
  padding: 0.55rem 0.75rem;
  border-top: 1px solid var(--border);
}
.reminder-row-link {
  flex: 1;
  min-width: 0;
  text-decoration: none;
  color: inherit;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.reminder-row-link:hover .reminder-row-excerpt {
  color: var(--brand);
}
.reminder-row-entity {
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--text-secondary);
}
.reminder-row-excerpt {
  font-size: 0.9rem;
  color: var(--text);
  word-break: break-word;
}
.reminder-row-when {
  font-size: 0.75rem;
}
.reminder-clear-form {
  margin: 0;
  flex-shrink: 0;
}

.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 2.25rem;
  height: 2.25rem;
  padding: 0;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border-strong);
  background: var(--bg-elevated);
  color: var(--text-secondary);
  cursor: pointer;
  box-shadow: var(--shadow-sm);
  transition: background var(--transition), border-color var(--transition), color var(--transition), transform var(--transition);
}
.theme-toggle:hover {
  background: var(--bg-muted);
  color: var(--brand);
  border-color: var(--brand);
  transform: translateY(-1px);
}
.theme-toggle .icon-sun { display: var(--theme-icon-sun); }
.theme-toggle .icon-moon { display: var(--theme-icon-moon); }
.theme-toggle svg {
  width: 1.1rem;
  height: 1.1rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 0.85rem;
  min-width: 0;
  flex: 1;
}

.topbar-logo {
  height: 1.85rem;
  max-width: 9.5rem;
  width: auto;
  object-fit: contain;
  flex-shrink: 0;
  border-radius: 6px;
}

.topbar-title {
  font-size: 1.05rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  color: var(--text);
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.sidebar .brand-logo {
  height: 2rem;
  max-width: 7.5rem;
  width: auto;
  object-fit: contain;
  border-radius: 8px;
  flex-shrink: 0;
  background: rgba(255, 255, 255, 0.06);
  padding: 0.15rem 0.25rem;
}

/* Appearance settings (color pickers + logo) */
.appearance-colors {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 1rem;
}
@media (max-width: 800px) {
  .appearance-colors { grid-template-columns: 1fr; }
}
.color-picker-row {
  display: flex;
  align-items: center;
  gap: 0.55rem;
}
.color-picker-row input[type="color"] {
  width: 2.75rem;
  height: 2.5rem;
  padding: 0.15rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  cursor: pointer;
  flex-shrink: 0;
}
.color-hex-input {
  flex: 1;
  min-width: 0;
  font-family: var(--font-mono);
  letter-spacing: 0.02em;
}
.appearance-logo-preview {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
  padding: 0.65rem 0.85rem;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.appearance-logo-img {
  height: 2.25rem;
  max-width: 10rem;
  object-fit: contain;
}

.user-chip {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.35rem 0.7rem 0.35rem 0.35rem;
  background: var(--chip-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  font-size: 0.85rem;
  color: var(--text-secondary);
}

.user-avatar {
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  color: #fff;
  font-size: 0.7rem;
  font-weight: 700;
}

.content {
  padding: 1.35rem 1.5rem 2.5rem;
  flex: 1;
  max-width: 1400px;
  width: 100%;
}

/* —— Cards —— */
.card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  margin-bottom: 1rem;
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), border-color var(--transition);
}

.card:hover {
  box-shadow: var(--shadow);
}

.card h2:first-child,
.card h3:first-child {
  margin-top: 0;
}

/* —— Flash / alerts —— */
.flash {
  display: flex;
  align-items: flex-start;
  gap: 0.6rem;
  padding: 0.85rem 1rem;
  border-radius: var(--radius-sm);
  margin-bottom: 1rem;
  font-size: 0.92rem;
  font-weight: 500;
  border: 1px solid transparent;
  box-shadow: var(--shadow-sm);
}
.flash-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 35%, transparent); }
.flash-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 35%, transparent); }
.flash-info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 35%, transparent); }

html[data-theme="light"] .flash-success { color: #065f46; border-color: #a7f3d0; }
html[data-theme="light"] .flash-error { color: #9f1239; border-color: #fecdd3; }
html[data-theme="light"] .flash-info { color: #075985; border-color: #bae6fd; }

/* —— Tables —— */
.card table,
table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  background: transparent;
}

th, td {
  text-align: left;
  padding: 0.75rem 0.9rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
  vertical-align: middle;
}

th {
  background: var(--bg-soft);
  font-weight: 650;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  white-space: nowrap;
}

th a {
  color: var(--text-muted);
  font-weight: 650;
}
th a:hover { color: var(--brand); }

tbody tr {
  transition: background var(--transition);
}
tbody tr:hover {
  background: var(--row-hover);
}
tbody tr:last-child td {
  border-bottom: none;
}

.card[style*="padding:0"] table th:first-child,
.card[style*="padding:0"] table td:first-child {
  padding-left: 1.1rem;
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  background: linear-gradient(180deg, #6366f1 0%, var(--brand) 100%);
  color: #fff !important;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  text-decoration: none !important;
  box-shadow: 0 1px 2px rgba(79, 70, 229, 0.25), inset 0 1px 0 rgba(255, 255, 255, 0.15);
  transition: transform var(--transition), box-shadow var(--transition), background var(--transition), border-color var(--transition);
  line-height: 1.25;
}

.btn:hover {
  background: linear-gradient(180deg, #4f46e5 0%, var(--brand-hover) 100%);
  box-shadow: 0 4px 12px rgba(79, 70, 229, 0.3);
  transform: translateY(-1px);
}

.btn:active { transform: translateY(0); }

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text) !important;
  border-color: var(--border-strong);
  box-shadow: var(--shadow-sm);
}
.btn-secondary:hover {
  background: var(--bg-muted);
  border-color: #94a3b8;
  box-shadow: var(--shadow-sm);
}

.btn-danger {
  background: linear-gradient(180deg, #f43f5e 0%, var(--danger) 100%);
  box-shadow: 0 1px 2px rgba(225, 29, 72, 0.25);
}
.btn-danger:hover {
  background: linear-gradient(180deg, #e11d48 0%, var(--danger-hover) 100%);
  box-shadow: 0 4px 12px rgba(225, 29, 72, 0.28);
}

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.8rem;
  border-radius: 7px;
}

/* —— Forms —— */
.form-row { margin-bottom: 1rem; }

label {
  display: block;
  font-size: 0.8rem;
  font-weight: 650;
  margin-bottom: 0.35rem;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

/* Text-like fields: include bare <input> (no type attr defaults to text but
   does NOT match input[type=text] in CSS — that made first name/phone look square). */
input:not([type]),
input[type="text"],
input[type="search"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="date"],
input[type="datetime-local"],
input[type="time"],
input[type="month"],
input[type="week"],
input[type="url"],
input[type="tel"],
input[type="color"],
select,
textarea {
  width: 100%;
  max-width: 32rem;
  min-height: 2.5rem;
  padding: 0.55rem 0.75rem;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  font: inherit;
  font-size: 0.925rem;
  line-height: 1.4;
  background: var(--bg-elevated);
  color: var(--text);
  transition: border-color var(--transition), box-shadow var(--transition);
  box-shadow: var(--input-shadow);
  appearance: none;
  -webkit-appearance: none;
  -moz-appearance: none;
}

select {
  cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%2364748b' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.65rem center;
  background-size: 1rem;
  padding-right: 2.25rem;
}

html[data-theme="dark"] select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238b9bb3' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'/%3E%3C/svg%3E");
}

select:disabled {
  cursor: not-allowed;
  opacity: 0.72;
  background-color: var(--bg-muted, #f1f5f9);
}

input:not([type]):focus,
input[type="text"]:focus,
input[type="search"]:focus,
input[type="email"]:focus,
input[type="password"]:focus,
input[type="number"]:focus,
input[type="date"]:focus,
input[type="datetime-local"]:focus,
input[type="time"]:focus,
input[type="month"]:focus,
input[type="week"]:focus,
input[type="url"]:focus,
input[type="tel"]:focus,
input[type="color"]:focus,
select:focus,
textarea:focus {
  outline: none;
  border-color: #818cf8;
  box-shadow: var(--focus);
}

input[type="color"] {
  max-width: 5rem;
  min-height: 2.5rem;
  padding: 0.25rem;
  cursor: pointer;
}

textarea {
  min-height: 5.5rem;
  resize: vertical;
  appearance: none;
  -webkit-appearance: none;
}

/* Type-to-search combobox (deal primary contact, reusable) */
.search-select {
  position: relative;
  max-width: 32rem;
}
.search-select-input {
  max-width: none;
}
.search-select-results {
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  top: calc(100% + 0.25rem);
  margin: 0;
  padding: 0.3rem;
  list-style: none;
  max-height: 18rem;
  overflow: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}
.search-select-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: 0.5rem 0.65rem;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--text);
  font: inherit;
  cursor: pointer;
}
.search-select-item:hover,
.search-select-item.is-active {
  background: var(--brand-soft);
}
.search-select-item-name {
  display: block;
  font-weight: 650;
  font-size: 0.9rem;
}
.search-select-item-meta {
  display: block;
  margin-top: 0.1rem;
  font-size: 0.78rem;
  color: var(--text-muted);
}
.search-select-empty,
.search-select-status {
  padding: 0.65rem 0.7rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Keep checkboxes/radios/native controls outside the “square vs rounded” field styles */
input[type="checkbox"],
input[type="radio"] {
  width: 1rem;
  height: 1rem;
  min-height: 0;
  max-width: none;
  padding: 0;
  border: none;
  border-radius: 0.25rem;
  box-shadow: none;
  appearance: auto;
  -webkit-appearance: auto;
  accent-color: var(--brand);
  vertical-align: middle;
  margin-right: 0.35rem;
  cursor: pointer;
}

input[type="hidden"],
input[type="submit"],
input[type="button"],
input[type="reset"],
input[type="image"],
input[type="file"],
input[type="range"] {
  appearance: auto;
  -webkit-appearance: auto;
  min-height: 0;
  max-width: none;
  box-shadow: none;
}

/* —— Auth —— */
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
  background:
    radial-gradient(800px 400px at 20% 10%, var(--auth-glow-1), transparent 50%),
    radial-gradient(700px 380px at 90% 80%, var(--auth-glow-2), transparent 45%),
    var(--auth-bg);
  position: relative;
}

.auth-page .theme-toggle {
  position: absolute;
  top: 1rem;
  right: 1rem;
}

html[data-theme="light"] .auth-page {
  --auth-bg: linear-gradient(160deg, #eef2ff 0%, #f8fafc 45%, #ecfeff 100%);
  --auth-glow-1: rgba(99, 102, 241, 0.18);
  --auth-glow-2: rgba(6, 182, 212, 0.12);
  --auth-card-border: var(--border);
}

html[data-theme="light"] .auth-wrap .card {
  border-color: var(--border);
}

.auth-wrap {
  width: 100%;
  max-width: 26rem;
  margin: 0 auto;
  padding: 0;
}

.auth-wrap .card {
  padding: 1.75rem 1.6rem;
  border: 1px solid var(--auth-card-border);
  box-shadow: var(--shadow-lg);
  border-radius: 16px;
  background: var(--bg-elevated);
}

.auth-wrap .card h1 {
  font-size: 1.45rem;
  margin-bottom: 0.25rem;
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  margin-bottom: 1.25rem;
  font-weight: 800;
  font-size: 1.1rem;
  color: var(--text);
}

.auth-brand span {
  width: 2.25rem;
  height: 2.25rem;
  border-radius: 10px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, #6366f1, #06b6d4);
  color: #fff;
  font-size: 0.85rem;
}

.auth-wrap .btn {
  width: 100%;
  max-width: 32rem;
  padding: 0.65rem 1rem;
  margin-top: 0.25rem;
}

.auth-wrap input {
  max-width: none;
}

/* —— Misc components —— */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.muted {
  color: var(--text-muted);
  font-size: 0.875rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.55rem;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 650;
  letter-spacing: 0.02em;
  background: var(--bg-muted);
  color: var(--text-secondary);
  border: 1px solid var(--border);
  white-space: nowrap;
}

.badge-pursuit {
  background: var(--badge-pursuit-bg);
  color: var(--badge-pursuit-text);
  border-color: var(--badge-pursuit-border);
}

.badge-agreement {
  background: var(--badge-agreement-bg);
  color: var(--badge-agreement-text);
  border-color: var(--badge-agreement-border);
}

.actions {
  display: flex;
  gap: 0.55rem;
  flex-wrap: wrap;
  align-items: center;
  margin: 0 0 1rem;
}

.pager {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-top: 1rem;
}

.mono {
  font-family: var(--font-mono);
  font-size: 0.8rem;
  word-break: break-all;
  background: var(--bg-muted);
  padding: 0.15rem 0.4rem;
  border-radius: 6px;
}

.tabs {
  display: flex;
  gap: 0.25rem;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1rem;
}

.tabs a {
  padding: 0.6rem 0.9rem;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.9rem;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tabs a:hover { color: var(--brand); }
.tabs a.active {
  color: var(--brand);
  border-bottom-color: var(--brand);
}

/* —— Kanban —— */
/* Board pages fill the viewport so the horizontal bar stays on screen.
   Columns scroll on their own instead of pushing that bar below the fold. */
.layout:has(.board) {
  height: 100vh;
  max-height: 100vh;
  overflow: hidden;
}
.layout:has(.board) .main {
  min-height: 0;
  overflow: hidden;
}
.layout:has(.board) .topbar {
  flex-shrink: 0;
}
.layout:has(.board) .content {
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
  padding-bottom: 0.75rem;
}
.layout:has(.board) .content > :not(#kanban-board):not(.grid-2) {
  flex-shrink: 0;
}
.layout:has(.board) .content > .card {
  flex-shrink: 1;
  min-height: 0;
  max-height: 34%;
  overflow: auto;
}
.layout:has(.board) .content > .grid-2 {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}
.layout:has(.board) .grid-2 > div {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.layout:has(.board) .grid-2 > div > h3 {
  flex-shrink: 0;
}
#kanban-board {
  flex: 1 1 auto;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.board {
  display: flex;
  gap: 1rem;
  flex: 1 1 auto;
  min-height: 0;
  min-width: 0;
  overflow-x: scroll;
  overflow-y: hidden;
  padding: 0.25rem 0.15rem 0.35rem;
  align-items: stretch;
  scrollbar-width: auto;
  scrollbar-color: var(--border-strong) var(--bg-muted);
}
.board::-webkit-scrollbar {
  height: 14px;
}
.board::-webkit-scrollbar-track {
  background: var(--bg-muted);
  border-radius: 999px;
}
.board::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 999px;
  border: 3px solid var(--bg-muted);
}

.stage {
  min-width: 17rem;
  max-width: 18.5rem;
  max-height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.65rem;
  box-shadow: var(--shadow-sm);
}
.stage [data-stage-list] {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.stage-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-shrink: 0;
  font-weight: 700;
  font-size: 0.88rem;
  margin-bottom: 0.65rem;
  padding: 0.35rem 0.3rem;
  color: var(--text);
}

.deal-card {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.8rem;
  margin-bottom: 0.55rem;
  box-shadow: var(--shadow-sm);
  cursor: grab;
  transition: box-shadow var(--transition), transform var(--transition), border-color var(--transition);
}

.deal-card:hover {
  border-color: var(--deal-hover-border);
  box-shadow: 0 6px 16px var(--brand-glow);
  transform: translateY(-1px);
}

.deal-card-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.35rem;
}
.deal-card-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin-top: 0.4rem;
}
.badge-parent {
  background: rgba(99, 102, 241, 0.15);
  color: #4f46e5;
  border-color: rgba(99, 102, 241, 0.35);
}
.badge-child {
  background: rgba(236, 72, 153, 0.12);
  color: #db2777;
  border-color: rgba(236, 72, 153, 0.3);
}
html[data-theme="dark"] .badge-parent {
  color: #a5b4fc;
}
html[data-theme="dark"] .badge-child {
  color: #f9a8d4;
}
.hierarchy-panel {
  margin-top: 0.55rem;
  padding: 0.45rem 0.5rem;
  border-radius: 8px;
  background: var(--bg-muted);
  border: 1px solid var(--border);
  font-size: 0.8rem;
}
.hierarchy-panel-title {
  font-weight: 700;
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.3rem;
}
.hierarchy-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 0.35rem;
  padding: 0.2rem 0;
}
.hierarchy-row + .hierarchy-row {
  border-top: 1px dashed var(--border);
}
.stage-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.1rem 0.45rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 650;
  background: color-mix(in srgb, var(--stage-color, #64748b) 18%, transparent);
  color: var(--text);
  border: 1px solid color-mix(in srgb, var(--stage-color, #64748b) 45%, transparent);
  max-width: 100%;
}
.stage-pill::before {
  content: "";
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: var(--stage-color, #64748b);
  flex-shrink: 0;
}
.board-combined .stage {
  min-width: 15.5rem;
}
.board-combined .stage-pipe {
  display: block;
  font-size: 0.7rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.1rem;
}
.board-combined .stage-name {
  font-weight: 700;
}
.board-mode-tabs {
  display: inline-flex;
  gap: 0.35rem;
  flex-wrap: wrap;
}
.board-toolbar {
  align-items: center;
}
.pipe-check-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1rem;
}
.pipe-check {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  font-weight: 500;
  margin: 0;
  padding: 0.35rem 0.55rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-elevated);
  cursor: pointer;
}
.hierarchy-legend {
  background: var(--bg-soft);
}
.deal-card.hierarchy-parent {
  background: linear-gradient(180deg, color-mix(in srgb, var(--brand) 6%, var(--bg-elevated)) 0%, var(--bg-elevated) 40%);
}
.deal-card.hierarchy-child {
  /* Nest under parent pursuits: slight indent + tint as hierarchy cue */
  background: linear-gradient(180deg, color-mix(in srgb, #ec4899 5%, var(--bg-elevated)) 0%, var(--bg-elevated) 45%);
  margin-left: 0.85rem;
  width: calc(100% - 0.85rem);
  box-sizing: border-box;
}

/* Board card density: titles (original simple card) vs full details */
.deal-card-title {
  font-weight: 650;
  color: var(--text);
  flex: 1;
  min-width: 0;
  line-height: 1.3;
}
.deal-card-title:hover { color: var(--brand); }
.deal-meta-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem 0.55rem;
  margin-top: 0.55rem;
}
.deal-meta-item { min-width: 0; }
.deal-meta-label {
  display: block;
  font-size: 0.65rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  line-height: 1.2;
}
.deal-meta-value {
  display: block;
  font-size: 0.8rem;
  font-weight: 550;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.deal-meta-value.amount {
  color: var(--success);
  font-weight: 700;
}
.board-density-toggle {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.2rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-pill);
  background: var(--bg-elevated);
}
.board-density-label {
  padding: 0 0.35rem 0 0.5rem;
  font-size: 0.78rem;
}
.board-density-toggle .density-btn {
  border-radius: var(--radius-pill);
  box-shadow: none;
}
html[data-board-density="titles"] .board-density-toggle .density-btn[data-board-density="titles"],
html[data-board-density="details"] .board-density-toggle .density-btn[data-board-density="details"] {
  background: linear-gradient(180deg, #6366f1 0%, var(--brand) 100%);
  color: #fff !important;
  border-color: transparent;
}

/* Default / titles: original simple card layout */
.deal-card-details-view { display: none; }
.deal-card-titles-view { display: block; }

html[data-board-density="details"] .deal-card-titles-view { display: none; }
html[data-board-density="details"] .deal-card-details-view { display: block; }

html[data-board-density="titles"] .deal-card-titles-view { display: block; }
html[data-board-density="titles"] .deal-card-details-view { display: none; }

.deal-card:active { cursor: grabbing; }

.deal-card .amount {
  font-weight: 700;
  font-size: 0.88rem;
  color: var(--success);
  margin: 0.2rem 0;
}

.deal-card a {
  font-weight: 650;
  color: var(--text);
}
.deal-card a:hover { color: var(--brand); }

/* —— Page polish —— */
.content > .actions + .card,
.content > .card:first-child {
  animation: fadeIn 0.25s ease;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: none; }
}

/* Dashboard list polish */
.card ul {
  list-style: none;
  padding: 0;
  margin: 0;
}
.card ul li {
  padding: 0.5rem 0;
  border-bottom: 1px solid var(--border);
}
.card ul li:last-child { border-bottom: none; }

/* —— Pipeline rename —— */
.pipeline-rename-form {
  display: flex;
  flex-direction: column;
  gap: 0;
  max-width: 36rem;
}
.pipeline-rename-name-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: flex-end;
}

/* —— Pipeline stage editor —— */
.stage-edit-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.stage-edit-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: flex-end;
  justify-content: space-between;
  padding: 0.65rem 0.75rem;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}
.stage-edit-form {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: flex-end;
  flex: 1;
  min-width: 0;
}
.stage-edit-fields {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 0.75rem;
  align-items: flex-end;
  flex: 1;
}
.stage-edit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
  align-items: center;
}
.stage-flag {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  user-select: none;
  margin: 0;
  padding-bottom: 0.35rem;
}
.stage-add-form .stage-flag {
  padding-bottom: 0.45rem;
}

/* —— OpenRouter model search picker —— */
.or-model-picker {
  position: relative;
}
.or-model-search {
  width: 100%;
}
.or-model-dropdown {
  position: absolute;
  z-index: 40;
  left: 0;
  right: 0;
  top: calc(100% + 4px);
  max-height: 16rem;
  overflow: auto;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
}
.or-model-option {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 0.1rem;
  width: 100%;
  text-align: left;
  padding: 0.55rem 0.75rem;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
  font: inherit;
}
.or-model-option:last-child { border-bottom: 0; }
.or-model-option:hover,
.or-model-option:focus {
  background: var(--row-hover);
  outline: none;
}
.or-model-option-name {
  font-weight: 600;
  font-size: 0.9rem;
}
.or-model-option-id {
  font-size: 0.75rem;
  color: var(--text-muted);
}
.or-model-empty {
  padding: 0.75rem;
  font-size: 0.85rem;
}

/* —— AI company name fix progress —— */
.ai-progress-track {
  height: 0.55rem;
  background: var(--bg-muted);
  border-radius: var(--radius-pill);
  overflow: hidden;
  border: 1px solid var(--border);
}
.ai-progress-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--brand), var(--accent));
  border-radius: var(--radius-pill);
  transition: width 0.25s ease;
  min-width: 0;
}
.ai-status-pill {
  display: inline-block;
  padding: 0.1rem 0.45rem;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border: 1px solid var(--border);
  background: var(--bg-muted);
  color: var(--text-secondary);
}
.ai-status-pill[data-status="renamed"] {
  background: var(--success-soft);
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 30%, transparent);
}
.ai-status-pill[data-status="skipped"] {
  background: var(--bg-muted);
  color: var(--text-muted);
}
.ai-status-pill[data-status="error"] {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, transparent);
}
.ai-stat-renamed { color: var(--success); font-weight: 600; }
.ai-stat-error { color: var(--danger); font-weight: 600; }
tr.ai-row-renamed td:first-child { box-shadow: inset 3px 0 0 var(--success); }
tr.ai-row-error td:first-child { box-shadow: inset 3px 0 0 var(--danger); }

/* —— Email timeline (contact / company) —— */
.email-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}
.email-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  overflow: hidden;
}
.email-item[open] {
  background: var(--bg-elevated);
  box-shadow: var(--shadow-sm);
}
.email-item-summary {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  padding: 0.75rem 0.9rem;
  cursor: pointer;
  list-style: none;
  user-select: none;
}
.email-item-summary::-webkit-details-marker { display: none; }
.email-item-summary::marker { content: ""; }
.email-item-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
}
.email-item-subject {
  font-weight: 650;
  color: var(--text);
  line-height: 1.35;
}
.email-item-meta,
.email-item-preview {
  font-size: 0.85rem;
  line-height: 1.35;
}
.email-item-preview {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
}
.email-item-chevron {
  flex-shrink: 0;
  color: var(--text-muted);
  transition: transform var(--transition);
  margin-top: 0.15rem;
}
.email-item[open] .email-item-chevron {
  transform: rotate(180deg);
}
.email-item[open] .email-item-preview {
  display: none;
}
.email-dir {
  flex-shrink: 0;
  display: inline-flex;
  align-items: center;
  padding: 0.15rem 0.5rem;
  border-radius: var(--radius-pill);
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border: 1px solid transparent;
  margin-top: 0.1rem;
}
.email-dir-in {
  background: var(--info-soft);
  color: var(--info);
  border-color: color-mix(in srgb, var(--info) 25%, transparent);
}
.email-dir-out {
  background: var(--success-soft);
  color: var(--success);
  border-color: color-mix(in srgb, var(--success) 25%, transparent);
}
.email-item-body {
  padding: 0 0.9rem 0.9rem;
  border-top: 1px solid var(--border);
}
.email-detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.55rem 1rem;
  margin: 0.75rem 0 0;
  padding: 0;
}
.email-detail-grid > div {
  min-width: 0;
}
.email-detail-grid .email-detail-full {
  grid-column: 1 / -1;
}
.email-detail-grid dt {
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0 0 0.15rem;
}
.email-detail-grid dd {
  margin: 0;
  color: var(--text);
  font-size: 0.9rem;
  word-break: break-word;
}
.email-mono {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-secondary);
}
.email-body-wrap {
  margin-top: 0.85rem;
}
.email-body-label {
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.email-body-text {
  margin: 0;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.9rem;
  line-height: 1.5;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 28rem;
  overflow: auto;
}
.email-body-frame {
  display: block;
  width: 100%;
  min-height: 16rem;
  height: 28rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: #fff;
}
html[data-theme="dark"] .email-body-frame {
  background: #0f172a;
}
.email-deal-chip {
  color: var(--brand);
  font-weight: 650;
}
.email-deal-assign {
  margin: 0 0 1rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
}
.email-deal-links {
  list-style: none;
  margin: 0 0 0.75rem;
  padding: 0;
}
.email-deal-links li {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem 0;
  border-bottom: 1px dashed var(--border);
  font-size: 0.9rem;
}
.email-deal-links li:last-child { border-bottom: none; }
.email-deal-unlink-form {
  display: inline;
  margin: 0 0 0 auto;
}
.email-deal-assign-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.email-deal-assign-row select {
  flex: 1;
  min-width: 12rem;
}
@media (max-width: 640px) {
  .email-detail-grid {
    grid-template-columns: 1fr;
  }
}

/* —— Notes feed (contact / company / deal) —— */
.notes-compose {
  margin-bottom: 1rem;
  padding: 0.75rem 0.85rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-muted);
}
.notes-compose textarea,
.notes-edit-form textarea {
  width: 100%;
  min-height: 4.5rem;
  resize: vertical;
}
.notes-feed {
  list-style: none;
  margin: 1rem 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
}
.notes-item {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-soft);
  padding: 0.75rem 0.9rem;
}
.notes-item-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.45rem 0.75rem;
  margin-bottom: 0.4rem;
  font-size: 0.88rem;
}
.notes-item-body {
  white-space: pre-wrap;
  word-break: break-word;
  line-height: 1.45;
  color: var(--text);
}
.notes-item-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.4rem;
  margin-top: 0.55rem;
}
.notes-edit-form {
  margin-top: 0.55rem;
  padding-top: 0.55rem;
  border-top: 1px dashed var(--border);
}
.notes-reminder {
  margin-top: 0.55rem;
}
.notes-reminder-toggle {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
}
.notes-reminder-when {
  margin-top: 0.45rem;
}
.notes-reminder-when input[type="datetime-local"] {
  max-width: 16rem;
}
.notes-reminder-locked {
  margin: 0.45rem 0 0;
  font-size: 0.85rem;
}
.note-reminder-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.75rem;
  font-weight: 600;
  padding: 0.12rem 0.45rem;
  border-radius: var(--radius-pill);
  background: var(--info-soft);
  color: var(--info);
}
.note-reminder-badge.is-due {
  background: var(--warning-soft);
  color: var(--warning);
}
.company-legacy-notes {
  margin-top: 0.75rem;
  padding: 0.65rem 0.75rem;
  border-left: 3px solid var(--border-strong);
  background: var(--bg-muted);
  border-radius: 0 var(--radius-sm) var(--radius-sm) 0;
}

/* —— Admin error log —— */
.error-log-stats {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.85rem;
  margin-bottom: 1rem;
}
.error-log-stat {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.95rem 1.05rem;
  box-shadow: var(--shadow-sm);
}
.error-log-stat.is-alert {
  border-color: color-mix(in srgb, var(--danger) 40%, var(--border));
  background: var(--danger-soft);
}
.error-log-stat.is-ok {
  border-color: color-mix(in srgb, var(--success) 35%, var(--border));
}
.error-log-stat-label {
  font-size: 0.75rem;
  font-weight: 650;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-muted);
  margin-bottom: 0.35rem;
}
.error-log-stat-value {
  font-size: 1.65rem;
  font-weight: 750;
  line-height: 1.15;
  color: var(--text);
}
.error-log-stat-value-sm {
  font-size: 1.05rem;
  font-weight: 700;
}
.error-log-stat-hint {
  margin-top: 0.3rem;
  font-size: 0.8rem;
  color: var(--text-muted);
}
.error-log-filters-row {
  display: flex;
  gap: 0.65rem;
  flex-wrap: wrap;
  align-items: end;
}
.error-log-empty {
  text-align: center;
  padding: 2.25rem 1.25rem;
}
.error-log-empty-icon {
  width: 2.75rem;
  height: 2.75rem;
  margin: 0 auto 0.85rem;
  border-radius: 999px;
  background: var(--success-soft);
  color: var(--success);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  font-weight: 800;
}
.error-log-item {
  padding: 1rem 1.15rem;
}
.error-log-item-head {
  display: flex;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
  align-items: flex-start;
  margin-bottom: 0.55rem;
}
.error-log-item-when {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.error-log-item-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}
.badge-error-class {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 30%, var(--border));
}
.badge-sql {
  background: var(--warning-soft);
  color: var(--warning);
  border-color: color-mix(in srgb, var(--warning) 30%, var(--border));
}
.error-log-message {
  margin: 0 0 0.75rem;
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.4;
  word-break: break-word;
}
.error-log-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(12rem, 1fr));
  gap: 0.65rem 1rem;
  margin: 0;
}
.error-log-meta dt {
  font-size: 0.72rem;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin-bottom: 0.15rem;
}
.error-log-meta dd {
  margin: 0;
  font-size: 0.9rem;
}
.error-log-stack {
  margin-top: 0.85rem;
  padding-top: 0.75rem;
  border-top: 1px dashed var(--border);
}
.error-log-stack summary {
  cursor: pointer;
  font-size: 0.85rem;
  font-weight: 650;
  color: var(--text-secondary);
}
.error-log-stack ol {
  margin: 0.55rem 0 0;
  padding-left: 1.25rem;
}
.error-log-stack li {
  margin: 0.2rem 0;
}
.error-log-stack code {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  word-break: break-all;
  color: var(--text);
}
@media (max-width: 900px) {
  .error-log-stats { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px) {
  .error-log-stats { grid-template-columns: 1fr; }
}

/* Alpine cloak */
[x-cloak] { display: none !important; }

/* —— Column picker —— */
.col-order-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  max-height: 22rem;
  overflow: auto;
}
.col-order-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-elevated);
  cursor: grab;
}
.col-order-item:last-child { border-bottom: none; }
.col-order-item.sortable-ghost {
  opacity: 0.55;
  background: var(--brand-soft);
}
.col-order-item.sortable-drag {
  box-shadow: var(--shadow);
  border-radius: var(--radius-sm);
}
.col-drag-handle {
  color: var(--text-muted);
  font-size: 0.85rem;
  letter-spacing: -0.08em;
  user-select: none;
  cursor: grab;
  padding: 0 0.15rem;
}
.col-pool {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
  max-height: 12rem;
  overflow: auto;
  padding: 0.35rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-elevated);
  margin-bottom: 0.75rem;
}
.col-pool-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-weight: 500;
  margin: 0;
  padding: 0.35rem 0.4rem;
  border-radius: 6px;
  cursor: pointer;
}
.col-pool-item:hover { background: var(--row-hover); }
.col-picker-section {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-muted);
  margin: 0.75rem 0 0.35rem;
}

/* Responsive */
@media (max-width: 900px) {
  .layout { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.15rem;
    padding: 0.85rem;
  }
  .sidebar .brand {
    width: 100%;
    margin: 0 0 0.5rem;
    padding-bottom: 0.65rem;
  }
  .sidebar .nav-section { display: none; }
  .sidebar a {
    margin: 0;
    padding: 0.4rem 0.65rem;
    font-size: 0.82rem;
  }
  .grid-2 { grid-template-columns: 1fr; }
  .content { padding: 1rem; }
  .topbar { padding: 0.75rem 1rem; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation: none !important;
    transition: none !important;
  }
}
