/* DCRM brand-aligned admin UI */
:root {
  --purple: #5B21D0;
  --accent: #9126AE;
  --light-purple: #EDE9FF;
  --mid-purple: #C4B5FD;
  --dark: #1E1B4B;
  --gray: #6B7280;
  --light-gray: #F3F4F6;
  --border: #E8E9ED;
  --body: #374151;
  --green: #10B981;
  --red: #EF4444;
  --amber: #F59E0B;
  --grad: linear-gradient(90deg, #5E81FB 0%, #7329F9 46%, #BC34FF 69%, #FB00DD 100%);
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  font-family: 'Plus Jakarta Sans', system-ui, sans-serif;
  background: #FAFBFC;
  color: var(--body);
  font-size: 14px;
  line-height: 1.5;
}

button { font-family: inherit; cursor: pointer; }
input, select, textarea { font-family: inherit; font-size: 14px; }

/* ── Layout ──────────────────────────────────────────────────────────────── */
.topbar {
  height: 64px;
  background: var(--dark);
  color: white;
  display: flex;
  align-items: center;
  padding: 0 24px;
  border-bottom: 3px solid;
  border-image: var(--grad) 1;
}
.topbar h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 700;
  background: var(--grad);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}
.topbar h1 span {
  color: white;
  -webkit-text-fill-color: white;
  font-weight: 400;
  margin-left: 8px;
  font-size: 14px;
}
.topbar .actions { margin-left: auto; display: flex; gap: 12px; align-items: center; }
.topbar .actions span { font-size: 13px; color: var(--mid-purple); }
.topbar button {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  color: white;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
}
.topbar button:hover { background: rgba(255,255,255,0.2); }

.container {
  max-width: 1280px;
  margin: 0 auto;
  padding: 32px 24px;
}

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.page-header h2 {
  margin: 0;
  font-size: 24px;
  font-weight: 800;
  color: var(--dark);
}

/* ── Buttons ─────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 600;
  border: 1px solid transparent;
  text-decoration: none;
}
.btn-primary { background: var(--accent); color: white; }
.btn-primary:hover { background: var(--purple); }
.btn-secondary { background: white; color: var(--body); border-color: var(--border); }
.btn-secondary:hover { background: var(--light-gray); }
.btn-danger { background: var(--red); color: white; }
.btn-danger:hover { opacity: 0.9; }
.btn-grad {
  background: var(--grad);
  color: white;
}

/* ── Login ───────────────────────────────────────────────────────────────── */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--dark);
  background-image: radial-gradient(circle at 20% 50%, rgba(115,41,249,0.3) 0%, transparent 60%),
                    radial-gradient(circle at 80% 50%, rgba(251,0,221,0.25) 0%, transparent 60%);
}
.login-card {
  background: white;
  border-radius: 16px;
  padding: 40px 36px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 20px 40px rgba(0,0,0,0.3);
}
.login-card h2 {
  margin: 0 0 6px 0;
  font-size: 22px;
  font-weight: 800;
  color: var(--dark);
}
.login-card .grad-bar {
  width: 60px; height: 4px;
  background: var(--grad);
  margin: 12px 0 24px 0;
  border-radius: 2px;
}
.login-card p {
  color: var(--gray);
  font-size: 13px;
  margin: 0 0 24px 0;
}
.field {
  margin-bottom: 16px;
}
.field label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--dark);
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: white;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(145,38,174,0.15);
}
.login-card .btn { width: 100%; justify-content: center; padding: 12px; }
.error-msg {
  color: var(--red);
  font-size: 13px;
  background: rgba(239,68,68,0.08);
  padding: 8px 12px;
  border-radius: 6px;
  margin-bottom: 16px;
}

/* ── Locations table ─────────────────────────────────────────────────────── */
.card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  box-shadow: 0 1px 2px rgba(0,0,0,0.04);
}

table.locations {
  width: 100%;
  border-collapse: collapse;
}
table.locations th, table.locations td {
  padding: 14px 16px;
  text-align: left;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
table.locations th {
  background: var(--dark);
  color: white;
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.02em;
  text-transform: uppercase;
}
table.locations tbody tr:nth-child(even) { background: #F9F7FF; }
table.locations tbody tr:hover { background: var(--light-purple); }
table.locations td.actions { text-align: right; white-space: nowrap; }
table.locations td.actions .btn { padding: 6px 10px; font-size: 12px; margin-left: 4px; }
table.locations .loc-id {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  color: var(--gray);
}
table.locations .loc-name { font-weight: 600; color: var(--dark); }

.feature-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.feature-pill {
  background: var(--light-purple);
  color: var(--purple);
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 10px;
}
.feature-pill.off { background: var(--light-gray); color: var(--gray); }
.feature-count {
  font-weight: 700;
  color: var(--accent);
}

/* ── Detail screen ───────────────────────────────────────────────────────── */
.detail-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 24px;
}
.detail-section {
  background: white;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 24px;
}
.detail-section h3 {
  margin: 0 0 16px 0;
  font-size: 14px;
  font-weight: 700;
  color: var(--purple);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.toggle-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 0;
  border-bottom: 1px solid var(--border);
}
.toggle-row:last-child { border-bottom: none; }
.toggle-row .label {
  font-weight: 600;
  color: var(--dark);
  font-size: 13px;
}
.toggle-row .desc {
  font-size: 12px;
  color: var(--gray);
  margin-top: 2px;
}

/* Switch */
.switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.switch input { opacity: 0; width: 0; height: 0; }
.slider {
  position: absolute; cursor: pointer; inset: 0;
  background: #d1d5db;
  border-radius: 22px;
  transition: 0.2s;
}
.slider:before {
  content: '';
  position: absolute;
  width: 16px; height: 16px;
  left: 3px; bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: 0.2s;
}
.switch input:checked + .slider { background: var(--accent); }
.switch input:checked + .slider:before { transform: translateX(18px); }

/* Multi-select chips */
.chip-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 8px;
}
.chip {
  background: var(--light-purple);
  color: var(--purple);
  font-size: 12px;
  font-weight: 600;
  padding: 5px 10px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}
.chip button {
  background: transparent;
  border: none;
  color: var(--purple);
  cursor: pointer;
  padding: 0;
  font-size: 14px;
  line-height: 1;
}

.toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

/* ── Shortcut cards ──────────────────────────────────────────────────────── */
.shortcut-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
}
.shortcut-card {
  display: grid;
  grid-template-columns: 56px 1fr;
  gap: 16px;
  padding: 16px;
  background: #FAFBFC;
  border: 1px solid var(--border);
  border-radius: 8px;
  align-items: start;
}
.shortcut-icon-preview {
  width: 40px;
  height: 40px;
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--accent);
}
.shortcut-icon-preview svg {
  width: 22px;
  height: 22px;
}
.shortcut-fields .field { margin-bottom: 12px; }
.shortcut-fields .field:last-child { margin-bottom: 0; }
.field-row {
  display: flex;
  gap: 12px;
  align-items: stretch;
}
.shortcut-fields textarea {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  resize: vertical;
}

/* ── Search bar ──────────────────────────────────────────────────────────── */
.search-bar {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  align-items: center;
}
.search-bar input {
  flex: 1;
  max-width: 360px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 14px;
  background: white;
}
.search-bar input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(145,38,174,0.15);
}

/* ── Sticky save bar ─────────────────────────────────────────────────────── */
.sticky-bar {
  position: sticky;
  bottom: 0;
  background: white;
  border-top: 1px solid var(--border);
  padding: 14px 24px;
  margin: 24px -24px -32px -24px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  box-shadow: 0 -4px 12px rgba(0,0,0,0.04);
  z-index: 50;
}
.sticky-bar .dirty-flag {
  font-size: 12px;
  color: var(--amber);
  font-weight: 600;
  display: none;
}
.sticky-bar.dirty .dirty-flag { display: block; }

/* ── Validation ──────────────────────────────────────────────────────────── */
.field textarea.invalid, .field input.invalid {
  border-color: var(--red);
  background: rgba(239,68,68,0.04);
}
.field-error {
  color: var(--red);
  font-size: 12px;
  margin-top: 4px;
  font-weight: 500;
}

/* ── Live preview ────────────────────────────────────────────────────────── */
.preview-section { background: #FAFBFC; }
.preview-card {
  background: white;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 14px;
  font-family: Inter, system-ui, sans-serif;
  font-size: 13px;
  margin-top: 8px;
}
.preview-card .pc-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
}
.preview-card .pc-name { font-weight: 600; color: #000; flex: 1; }
.preview-card .pc-status {
  background: #DCFCE7; color: #15803D;
  font-size: 10px; font-weight: 700;
  padding: 2px 8px; border-radius: 10px;
}
.preview-card .pc-badge {
  font-size: 11px; font-weight: 700;
  padding: 2px 8px; border-radius: 8px;
  height: 18px; display: inline-flex; align-items: center;
}
.preview-card table.pc-fields {
  width: 100%; border-collapse: collapse;
  font-size: 12px; color: #374151;
}
.preview-card table.pc-fields td {
  padding: 2px 0; vertical-align: middle;
}
.preview-card .pc-actions {
  display: flex; gap: 10px; margin-top: 12px; padding-top: 10px;
  border-top: 1px solid #f3f4f6;
}
.preview-card .pc-actions svg { width: 14px; height: 14px; color: #6b7280; }
.preview-card .pc-icon { color: #374151; }

/* ── Modal ───────────────────────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.5);
  z-index: 200;
  display: flex; align-items: center; justify-content: center;
}
.modal-card {
  background: white; border-radius: 12px; padding: 24px;
  width: 100%; max-width: 420px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
}
.modal-card h3 { margin: 0 0 12px 0; color: var(--dark); font-size: 16px; }
.modal-card .toolbar { margin-top: 16px; }

/* ── Toast ───────────────────────────────────────────────────────────────── */
#toast-region {
  position: fixed;
  top: 80px; right: 24px;
  z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
}
.toast {
  background: white;
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.1);
  font-size: 13px;
  font-weight: 500;
  color: var(--dark);
  min-width: 240px;
  animation: slideIn 0.2s ease-out;
}
.toast.success { border-left-color: var(--green); }
.toast.error { border-left-color: var(--red); }
@keyframes slideIn {
  from { opacity: 0; transform: translateX(20px); }
  to { opacity: 1; transform: translateX(0); }
}

/* ── Top nav ─────────────────────────────────────────────────────────────── */
.topnav {
  display: flex;
  gap: 4px;
  margin-left: 32px;
}
.topnav a {
  color: var(--mid-purple);
  text-decoration: none;
  font-size: 13px;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 6px;
}
.topnav a:hover { color: white; background: rgba(255,255,255,0.08); }
.topnav a.active { color: white; background: rgba(255,255,255,0.12); }

/* ── Section headers with toggle ─────────────────────────────────────────── */
.section-head {
  justify-content: flex-start;
  margin-bottom: 8px;
}
.section-head h3 {
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-size: 14px;
  font-weight: 700;
  color: var(--purple);
}

/* ── Sub-checkboxes ──────────────────────────────────────────────────────── */
.sub-check {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 500;
  color: var(--dark);
  padding: 6px 0;
  cursor: pointer;
}
.sub-check input { accent-color: var(--accent); width: 15px; height: 15px; }

/* ── Avatar size slider ──────────────────────────────────────────────────── */
input[type="range"] { accent-color: var(--accent); cursor: pointer; }
.avatar-readout {
  font-size: 13px;
  font-weight: 700;
  color: var(--accent);
  min-width: 44px;
  text-align: right;
}

/* ── Preview avatar ──────────────────────────────────────────────────────── */
.preview-card .pc-avatar {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  background: var(--light-purple);
  color: var(--purple);
  font-weight: 700;
  flex-shrink: 0;
  transition: width 0.15s, height 0.15s, font-size 0.15s;
}

/* ── New lead alert preview ──────────────────────────────────────────────── */
.nla-flash {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 300;
  box-shadow: inset 0 0 0 4px var(--accent), inset 0 0 90px rgba(145,38,174,0.55);
  animation: nlaFlash 1.3s ease-out forwards;
}
@keyframes nlaFlash {
  from { opacity: 1; }
  to { opacity: 0; }
}
.nla-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(30,27,75,0.45);
  z-index: 310;
  display: flex;
  align-items: center;
  justify-content: center;
}
.nla-popup {
  background: white;
  border-top: 4px solid var(--accent);
  border-radius: 12px;
  padding: 28px 24px 24px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: 0 20px 50px rgba(0,0,0,0.3);
  text-align: center;
}
.nla-popup .nla-eyebrow {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--accent);
  margin-bottom: 8px;
}
.nla-popup .nla-name {
  font-size: 20px;
  font-weight: 800;
  color: var(--dark);
}
.nla-popup .nla-sub {
  font-size: 13px;
  color: var(--gray);
  margin: 8px 0 20px 0;
}
.nla-popup .nla-actions {
  display: flex;
  gap: 8px;
  justify-content: center;
}

/* ── Audit log ───────────────────────────────────────────────────────────── */
.audit-details summary {
  cursor: pointer;
  color: var(--accent);
  font-weight: 600;
  font-size: 12px;
}
.audit-details pre {
  background: #FAFBFC;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  font-size: 11px;
  max-width: 480px;
  max-height: 280px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 8px 0 0 0;
}

/* ── Helpers ─────────────────────────────────────────────────────────────── */
.empty {
  text-align: center;
  padding: 48px 24px;
  color: var(--gray);
}
.muted { color: var(--gray); font-size: 12px; }
.row-flex { display: flex; align-items: center; gap: 12px; }
.divider { height: 1px; background: var(--border); margin: 16px 0; }
