:root {
  --brand: #1e3a8a;
  --brand-2: #2563eb;
  --bg: #f4f6fb;
  --card: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --border: #e5e7eb;
  --danger: #dc2626;
  --success: #059669;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h2 { font-size: 17px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 0 0 8px; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12.5px; }
pre { background: #0f172a; color: #e2e8f0; padding: 12px 14px; border-radius: 8px; overflow: auto; margin: 8px 0; }
code.inline { background: #eef2ff; color: #3730a3; padding: 1px 6px; border-radius: 4px; }
.boot { padding: 40px; color: var(--muted); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

/* Layout */
.layout { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--brand); color: #fff; display: flex; flex-direction: column; flex-shrink: 0; position: sticky; top: 0; height: 100vh; }
.logo { padding: 20px 18px; font-weight: 700; font-size: 17px; letter-spacing: .3px; display: flex; align-items: center; gap: 10px; }
.logo .mark { width: 32px; height: 32px; border-radius: 8px; background: #fff; color: var(--brand); display: grid; place-items: center; font-weight: 800; }
.logo small { display: block; font-weight: 400; opacity: .7; font-size: 11px; }
.nav a { display: flex; align-items: center; gap: 10px; color: #c7d2fe; padding: 10px 18px; font-weight: 500; }
.nav a:hover { background: rgba(255,255,255,.06); text-decoration: none; color: #fff; }
.nav a.active { background: rgba(255,255,255,.12); color: #fff; border-left: 3px solid #fff; padding-left: 15px; }
.sidebar .foot { margin-top: auto; padding: 14px 18px; font-size: 12px; color: #c7d2fe; border-top: 1px solid rgba(255,255,255,.1); }
.sidebar .foot button { margin-top: 6px; }
.main { flex: 1; min-width: 0; padding: 24px 28px 60px; }
.page-head { display: flex; align-items: center; gap: 12px; margin-bottom: 18px; flex-wrap: wrap; }

/* Cards */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 18px; margin-bottom: 18px; }
.card.flush { padding: 0; overflow: hidden; }

/* Buttons & inputs */
button, .btn { font: inherit; border: 1px solid var(--border); background: #fff; color: var(--text); padding: 7px 14px; border-radius: 8px; cursor: pointer; display: inline-flex; align-items: center; gap: 6px; font-weight: 500; white-space: nowrap; }
button:hover, .btn:hover { background: #f9fafb; text-decoration: none; }
button:disabled { opacity: .55; cursor: default; }
.btn-primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn-primary:hover { background: #1d4ed8; }
.btn-danger { color: var(--danger); border-color: #fecaca; }
.btn-danger:hover { background: #fef2f2; }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-sm { padding: 4px 10px; font-size: 12.5px; }
.sidebar .btn-ghost { color: #c7d2fe; padding: 0; }
input, select, textarea { font: inherit; border: 1px solid #d1d5db; border-radius: 8px; padding: 7px 10px; background: #fff; color: var(--text); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid #bfdbfe; border-color: var(--brand-2); }
textarea { resize: vertical; min-height: 70px; }
label { display: block; font-size: 12px; font-weight: 600; color: #374151; margin-bottom: 4px; }
.field { margin-bottom: 12px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 14px; }
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; padding: 14px; border-bottom: 1px solid var(--border); }
.toolbar input, .toolbar select { width: auto; }
.toolbar input[type=search] { min-width: 240px; }

/* Tables */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); background: #fafbfc; font-weight: 600; }
tbody tr.clickable { cursor: pointer; }
tbody tr.clickable:hover { background: #f8faff; }
td .sub { color: var(--muted); font-size: 12px; }
.empty { padding: 40px; text-align: center; color: var(--muted); }
.pager { display: flex; align-items: center; gap: 10px; padding: 12px 14px; justify-content: flex-end; color: var(--muted); }

/* Badges */
.badge { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge .dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 6px; background: #f3f4f6; font-size: 12px; color: #374151; }
.method { display: inline-block; min-width: 62px; text-align: center; padding: 2px 8px; border-radius: 6px; font-weight: 700; font-size: 12px; color: #fff; }
.method.GET { background: #059669; } .method.POST { background: #2563eb; } .method.PATCH { background: #d97706; } .method.DELETE { background: #dc2626; }

/* Status picker */
.status-picker { display: flex; flex-wrap: wrap; gap: 8px; }
.status-picker button { border-radius: 999px; font-size: 12.5px; }
.status-picker button.on { color: #fff; }

/* Lead detail */
.detail-grid { display: grid; grid-template-columns: minmax(340px, 440px) 1fr; gap: 18px; align-items: start; }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 4px 10px; font-size: 13px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; word-break: break-word; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); margin: 16px 0 8px; font-weight: 700; }

/* Communication timeline */
.timeline { position: relative; }
.email { border: 1px solid var(--border); border-radius: 10px; margin-bottom: 12px; background: #fff; overflow: hidden; }
.email.incoming { border-left: 4px solid #8b5cf6; }
.email.outgoing { border-left: 4px solid #2563eb; }
.email-head { padding: 12px 14px; cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 4px 12px; }
.email-head:hover { background: #fafbff; }
.email-subject { font-weight: 600; }
.email-meta { font-size: 12.5px; color: var(--muted); }
.email-meta b { color: #374151; font-weight: 600; }
.email-date { font-size: 12px; color: var(--muted); text-align: right; white-space: nowrap; }
.email-snippet { grid-column: 1 / -1; color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.email-body { padding: 0 14px 14px; white-space: pre-wrap; word-break: break-word; font-size: 13.5px; border-top: 1px dashed var(--border); padding-top: 12px; }
.email-quoted { color: var(--muted); border-left: 3px solid var(--border); padding-left: 10px; margin-top: 10px; font-size: 12.5px; }
.dir { font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 999px; text-transform: uppercase; letter-spacing: .4px; }
.dir.incoming { background: #f3e8ff; color: #6d28d9; }
.dir.outgoing { background: #dbeafe; color: #1d4ed8; }
.date-sep { font-size: 12px; font-weight: 700; color: var(--muted); margin: 18px 0 8px; text-transform: uppercase; letter-spacing: .5px; }

/* Settings */
.steps { counter-reset: step; list-style: none; padding: 0; margin: 0; }
.steps li { counter-increment: step; position: relative; padding: 0 0 14px 38px; }
.steps li::before { content: counter(step); position: absolute; left: 0; top: 0; width: 26px; height: 26px; border-radius: 50%; background: #e0e7ff; color: var(--brand); font-weight: 700; display: grid; place-items: center; font-size: 13px; }
.notice { padding: 10px 14px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.notice.warn { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.notice.ok { background: #ecfdf5; border: 1px solid #a7f3d0; color: #065f46; }
.notice.err { background: #fef2f2; border: 1px solid #fecaca; color: #991b1b; }
.notice.info { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }
.copy-field { display: flex; gap: 6px; }
.copy-field input { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 12.5px; background: #f9fafb; }

/* Docs */
.endpoint { border-top: 1px solid var(--border); padding: 18px 0; }
.endpoint:first-of-type { border-top: 0; }
.endpoint-title { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 6px; }
.endpoint-title code { font-size: 14px; font-weight: 600; }

/* Modal */
.modal-backdrop { position: fixed; inset: 0; background: rgba(15, 23, 42, .45); display: flex; align-items: flex-start; justify-content: center; padding: 60px 16px; z-index: 50; overflow: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.modal-head { display: flex; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border); }
.modal-head h2 { margin: 0; }
.modal-body { padding: 18px; }
.modal-foot { padding: 14px 18px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

/* Toasts */
#toasts { position: fixed; bottom: 20px; right: 20px; display: flex; flex-direction: column; gap: 8px; z-index: 100; }
.toast { background: #111827; color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 380px; animation: pop .15s ease-out; }
.toast.error { background: var(--danger); }
.toast.success { background: var(--success); }
@keyframes pop { from { transform: translateY(8px); opacity: 0; } }

/* Login */
.login-wrap { min-height: 100vh; display: grid; place-items: center; background: linear-gradient(135deg, #1e3a8a, #2563eb); }
.login-card { background: #fff; padding: 32px; border-radius: 14px; width: 360px; box-shadow: 0 20px 50px rgba(0,0,0,.25); }
.login-card .logo { color: var(--brand); padding: 0 0 20px; }
.login-card .logo .mark { background: var(--brand); color: #fff; }

.spinner { width: 16px; height: 16px; border: 2px solid #cbd5e1; border-top-color: var(--brand-2); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; vertical-align: middle; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 1000px) {
  .detail-grid { grid-template-columns: 1fr; }
}
@media (max-width: 760px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; flex-direction: row; align-items: center; flex-wrap: wrap; }
  .nav { display: flex; }
  .sidebar .foot { display: none; }
  .main { padding: 16px; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .hide-sm { display: none; }
}
