:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --border: #e4e7ec;
  --text: #1a1d23;
  --muted: #667085;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --danger: #dc2626;
  --green: #16a34a;
  --shadow: 0 1px 3px rgba(16,24,40,.08), 0 1px 2px rgba(16,24,40,.06);
  --radius: 10px;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}
.hidden { display: none !important; }

/* Topbar */
.topbar {
  height: 56px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
  padding: 0 20px; position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; font-size: 17px; }
.brand span { color: var(--primary); }
.topbar-meta { color: var(--muted); font-size: 13px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }
.topbar-user { color: var(--text); font-size: 13px; font-weight: 600; }

/* Login */
.login-screen {
  position: fixed; inset: 0; z-index: 100; background: var(--bg);
  display: flex; align-items: center; justify-content: center;
}
.login-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 32px; width: 340px; box-shadow: var(--shadow); display: flex; flex-direction: column; gap: 10px;
}
.login-error { color: var(--danger); font-size: 13px; margin: 4px 0 0; min-height: 16px; }

/* Site keys list */
.key-row {
  display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 10px 12px; border: 1px solid var(--border); border-radius: 8px; margin-bottom: 8px;
}
.key-row.revoked { opacity: .55; }
.key-mono { font-family: ui-monospace, "SF Mono", Menlo, monospace; font-size: 12px; }
.key-reveal {
  background: #f0fdf4; border: 1px solid #bbf7d0; border-radius: 8px; padding: 12px;
  margin: 10px 0; font-family: ui-monospace, Menlo, monospace; font-size: 12px; word-break: break-all;
}
.key-warn { color: #854d0e; background: #fef9c3; border: 1px solid #fde68a; padding: 8px 10px; border-radius: 8px; font-size: 12px; margin-bottom: 10px; }

/* Layout */
.layout { display: flex; height: calc(100vh - 56px); }
.sidebar {
  width: 240px; background: var(--surface); border-right: 1px solid var(--border);
  padding: 16px 12px; overflow-y: auto; flex-shrink: 0;
}
.sidebar-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.sidebar-head h2 { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 0; }
.site-list { list-style: none; margin: 0; padding: 0; }
.site-list li {
  padding: 9px 11px; border-radius: 8px; cursor: pointer; margin-bottom: 2px;
  display: flex; justify-content: space-between; align-items: center; gap: 8px;
}
.site-list li:hover { background: #f1f2f4; }
.site-list li.active { background: #eef2ff; color: var(--primary-dark); font-weight: 600; }
.site-list .site-badge {
  background: #e4e7ec; color: var(--muted); border-radius: 10px;
  padding: 1px 7px; font-size: 11px; font-weight: 600;
}
.site-list li.active .site-badge { background: var(--primary); color: #fff; }

/* Main */
.main { flex: 1; overflow-y: auto; padding: 24px 28px; }
.empty-state { color: var(--muted); text-align: center; margin-top: 80px; }
.site-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 18px; }
.site-header h1 { margin: 0 0 4px; font-size: 22px; }
.site-sub { margin: 0; color: var(--muted); }
.site-actions { display: flex; gap: 8px; }

/* Toolbar */
.toolbar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  margin-bottom: 14px; background: var(--surface); padding: 10px 12px;
  border: 1px solid var(--border); border-radius: var(--radius);
}
.toolbar input[type=search] { flex: 1; min-width: 180px; }
.toolbar .inline { display: flex; align-items: center; gap: 6px; color: var(--muted); }
.count { color: var(--muted); margin-left: auto; font-size: 13px; }

input, select, textarea {
  font: inherit; padding: 7px 10px; border: 1px solid var(--border);
  border-radius: 8px; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid #c7d2fe; border-color: var(--primary); }

/* Table */
.table-wrap { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
table.leads { width: 100%; border-collapse: collapse; }
.leads th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--muted); padding: 11px 14px; border-bottom: 1px solid var(--border); background: #fafafb;
}
.leads td { padding: 12px 14px; border-bottom: 1px solid var(--border); vertical-align: top; }
.leads tr:last-child td { border-bottom: none; }
.leads tr:hover td { background: #fafbff; }
.lead-name { font-weight: 600; cursor: pointer; }
.lead-name:hover { color: var(--primary); text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.kv { font-size: 12px; color: var(--muted); }
.info-badge {
  display: inline-block; min-width: 22px; text-align: center;
  background: #eef2ff; color: var(--primary-dark); border-radius: 10px;
  padding: 2px 8px; font-weight: 600; font-size: 12px;
}

/* Status pills */
.pill { display: inline-block; padding: 2px 9px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.pill.new { background: #e0f2fe; color: #0369a1; }
.pill.contacted { background: #fef9c3; color: #854d0e; }
.pill.qualified { background: #ede9fe; color: #6d28d9; }
.pill.complete { background: #dcfce7; color: #166534; }
.pill.archived { background: #f1f2f4; color: #667085; }

/* Buttons */
.btn {
  font: inherit; cursor: pointer; border: 1px solid var(--primary); background: var(--primary);
  color: #fff; padding: 8px 14px; border-radius: 8px; font-weight: 600;
}
.btn:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-ghost { background: transparent; color: var(--muted); border-color: var(--border); }
.btn-ghost:hover { background: #f1f2f4; color: var(--text); }
.btn-danger { background: var(--danger); border-color: var(--danger); }
.btn-danger:hover { background: #b91c1c; border-color: #b91c1c; }
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }
.icon-btn {
  cursor: pointer; border: 1px solid var(--border); background: #fff; border-radius: 7px;
  padding: 4px 8px; font-size: 12px; color: var(--muted);
}
.icon-btn:hover { background: #f1f2f4; color: var(--text); }
.icon-btn.danger:hover { color: var(--danger); border-color: #fecaca; background: #fef2f2; }
.icon-btn.good:hover { color: var(--green); border-color: #bbf7d0; background: #f0fdf4; }

/* Drawer */
.drawer-overlay { position: fixed; inset: 0; background: rgba(16,24,40,.35); z-index: 20; }
.drawer {
  position: fixed; top: 0; right: 0; width: 420px; max-width: 92vw; height: 100vh;
  background: var(--surface); box-shadow: -4px 0 24px rgba(16,24,40,.12);
  z-index: 21; overflow-y: auto; padding: 22px;
}
.drawer h2 { margin: 0 0 2px; }
.drawer .close { position: absolute; top: 16px; right: 18px; cursor: pointer; font-size: 20px; color: var(--muted); border: none; background: none; }
.field-grid { display: grid; grid-template-columns: 90px 1fr; gap: 8px 12px; margin: 16px 0; align-items: center; }
.field-grid label { color: var(--muted); font-size: 13px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); margin: 20px 0 8px; }
.notes-list { list-style: none; padding: 0; margin: 0; }
.note { background: #f9fafb; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; margin-bottom: 8px; }
.note .meta { color: var(--muted); font-size: 11px; margin-top: 6px; display: flex; justify-content: space-between; }
.note .del { cursor: pointer; color: var(--muted); }
.note .del:hover { color: var(--danger); }
.note-form { display: flex; gap: 8px; margin-top: 10px; }
.note-form textarea { flex: 1; resize: vertical; min-height: 38px; }
.data-rows { display: flex; flex-direction: column; gap: 6px; }
.data-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(16,24,40,.35); z-index: 30; display: flex; align-items: center; justify-content: center; }
.modal { background: var(--surface); border-radius: 12px; padding: 24px; width: 460px; max-width: 92vw; box-shadow: var(--shadow); }
.modal h3 { margin: 0 0 16px; }
.modal .field-grid { margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; }
.toast {
  position: fixed; bottom: 22px; left: 50%; transform: translateX(-50%);
  background: #1a1d23; color: #fff; padding: 10px 18px; border-radius: 8px; z-index: 50;
  box-shadow: var(--shadow); opacity: 0; transition: opacity .2s; font-size: 13px;
}
.toast.show { opacity: 1; }
