:root {
  color-scheme: light;
  --ink: #181614;
  --muted: #6c625a;
  --paper: #f4f1ec;
  --card: #ffffff;
  --charcoal: #211f1d;
  --red: #df3e4c;
  --red-dark: #b92533;
  --green: #2e7d4c;
  --amber: #a76519;
  --line: rgba(24, 22, 20, 0.12);
  --shadow: 0 18px 50px rgba(24, 22, 20, 0.16);
}

* { box-sizing: border-box; }
html { min-height: 100%; background: var(--paper); }
body { min-height: 100vh; margin: 0; color: var(--ink); background: var(--paper); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
.hidden { display: none !important; }
.eyebrow { margin: 0 0 9px; color: var(--red-dark); font-size: .74rem; font-weight: 850; letter-spacing: .1em; text-transform: uppercase; }
.primary, .secondary { min-height: 48px; padding: 0 18px; border-radius: 5px; font-weight: 800; }
.primary { color: white; background: var(--red); border: 1px solid var(--red); }
.primary:hover { background: var(--red-dark); }
.secondary { color: var(--ink); background: var(--card); border: 1px solid var(--line); }

.auth-shell { min-height: 100vh; display: grid; place-items: center; padding: max(22px, env(safe-area-inset-top)) 18px max(22px, env(safe-area-inset-bottom)); background: linear-gradient(150deg, #161412 0%, #2a2521 52%, #171513 100%); }
.auth-card { width: min(100%, 420px); padding: clamp(24px, 7vw, 38px); background: var(--card); border-radius: 8px; box-shadow: 0 30px 80px rgba(0,0,0,.38); }
.auth-brand { display: flex; align-items: center; gap: 14px; margin-bottom: 38px; }
.auth-brand img { border-radius: 6px; }
.auth-brand strong, .auth-brand span { display: block; }
.auth-brand strong { font-size: 1.1rem; }
.auth-brand span { margin-top: 2px; color: var(--muted); font-size: .86rem; }
.auth-card h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: 2.35rem; }
.supporting { margin: 13px 0 24px; color: var(--muted); line-height: 1.55; }
.auth-card form { display: grid; gap: 15px; }
.auth-card label, .lead-edit-form label { display: grid; gap: 7px; color: var(--muted); font-size: .84rem; font-weight: 750; }
input, select, textarea { width: 100%; min-height: 48px; padding: 12px 13px; color: var(--ink); background: #fbfaf8; border: 1px solid #d5cdc4; border-radius: 5px; }
textarea { resize: vertical; }
.text-button, .danger-text { width: 100%; margin-top: 15px; padding: 10px; background: transparent; border: 0; font-weight: 700; }
.text-button { color: var(--muted); }
.danger-text { color: var(--red-dark); }
.trap { position: absolute !important; left: -10000px !important; width: 1px !important; height: 1px !important; overflow: hidden !important; }
.message { min-height: 20px; margin: 13px 0 0; color: var(--muted); font-size: .84rem; text-align: center; }
.message.error { color: var(--red-dark); }
.message.success { color: var(--green); }

.app-shell { min-height: 100vh; padding-bottom: env(safe-area-inset-bottom); }
.topbar { position: sticky; top: 0; z-index: 10; display: flex; align-items: center; justify-content: space-between; min-height: 70px; padding: max(10px, env(safe-area-inset-top)) clamp(16px, 4vw, 34px) 10px; color: white; background: rgba(30, 28, 26, .97); box-shadow: 0 1px 0 rgba(255,255,255,.08); }
.topbar-brand { display: flex; align-items: center; gap: 11px; }
.topbar-brand img { border-radius: 4px; }
.topbar-brand strong, .topbar-brand span { display: block; }
.topbar-brand strong { font-size: 1rem; }
.topbar-brand span { margin-top: 2px; color: rgba(255,255,255,.62); font-size: .76rem; }
.topbar-actions { display: flex; align-items: center; gap: 8px; }
.icon-button, .avatar-button { display: grid; place-items: center; width: 42px; height: 42px; padding: 0; border: 1px solid rgba(255,255,255,.13); border-radius: 50%; color: inherit; background: rgba(255,255,255,.07); font-size: 1.3rem; }
.avatar-button { color: white; background: var(--red); border-color: var(--red); font-size: .88rem; font-weight: 850; }
.inbox-main { width: min(920px, 100%); margin: 0 auto; padding: 28px clamp(16px, 4vw, 32px) 60px; }
.inbox-heading { display: flex; align-items: end; justify-content: space-between; gap: 20px; }
.inbox-heading h1 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-size: clamp(2.5rem, 9vw, 4.2rem); }
.new-count { display: grid; min-width: 74px; padding: 11px 14px; color: white; background: var(--charcoal); border-radius: 6px; text-align: center; }
.new-count strong { font-size: 1.35rem; }
.new-count span { color: rgba(255,255,255,.62); font-size: .7rem; text-transform: uppercase; }
.toolbar { margin: 26px 0 18px; }
.search-field { display: block; }
.search-field span { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }
.search-field input { min-height: 52px; padding-left: 16px; background: white; box-shadow: 0 7px 22px rgba(24,22,20,.06); }
.filter-row { display: flex; gap: 8px; margin-top: 12px; padding-bottom: 4px; overflow-x: auto; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.filter-button { flex: 0 0 auto; min-height: 38px; padding: 0 13px; color: var(--muted); background: transparent; border: 1px solid var(--line); border-radius: 19px; font-size: .8rem; font-weight: 750; }
.filter-button.active { color: white; background: var(--charcoal); border-color: var(--charcoal); }
.lead-list { display: grid; gap: 11px; }
.lead-card { width: 100%; display: grid; grid-template-columns: auto 1fr auto; gap: 13px; align-items: center; min-height: 92px; padding: 15px; color: inherit; background: white; border: 1px solid var(--line); border-radius: 7px; box-shadow: 0 7px 20px rgba(24,22,20,.055); text-align: left; }
.lead-card.unread { border-left: 4px solid var(--red); padding-left: 12px; }
.lead-initial { display: grid; place-items: center; width: 48px; height: 48px; color: white; background: var(--charcoal); border-radius: 5px; font-family: Georgia, serif; font-size: 1.25rem; }
.lead-card-main { min-width: 0; }
.lead-card-main strong, .lead-card-main span { display: block; }
.lead-card-main strong { overflow: hidden; font-size: 1rem; text-overflow: ellipsis; white-space: nowrap; }
.lead-card-main span { margin-top: 5px; overflow: hidden; color: var(--muted); font-size: .82rem; text-overflow: ellipsis; white-space: nowrap; }
.lead-card-side { display: grid; justify-items: end; gap: 8px; }
.lead-card-side time { color: var(--muted); font-size: .72rem; }
.status-chip, .project-pill { display: inline-flex; align-items: center; min-height: 25px; padding: 0 9px; color: #6a3120; background: #f8e6db; border-radius: 13px; font-size: .68rem; font-weight: 800; text-transform: capitalize; }
.status-chip[data-status="new"] { color: #8b2530; background: #fbe2e5; }
.status-chip[data-status="won"] { color: #1f693c; background: #dff2e6; }
.status-chip[data-status="lost"], .status-chip[data-status="archived"] { color: #665f59; background: #ece8e3; }
.empty-state { display: grid; justify-items: center; gap: 7px; padding: 70px 20px; color: var(--muted); text-align: center; }
.empty-state strong { color: var(--ink); }

dialog { width: min(100% - 24px, 650px); max-height: calc(100dvh - 24px); padding: 0; color: var(--ink); background: var(--card); border: 0; border-radius: 9px; box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(17,15,14,.7); backdrop-filter: blur(3px); }
.dialog-header { display: flex; align-items: start; gap: 13px; padding: 21px 21px 16px; border-bottom: 1px solid var(--line); }
.dialog-header .icon-button { flex: 0 0 auto; color: var(--ink); border-color: var(--line); background: #f6f2ed; }
.dialog-header h2 { margin: 6px 0 0; font-family: Georgia, serif; font-size: 1.9rem; }
.contact-actions { display: grid; grid-template-columns: repeat(3, 1fr); gap: 9px; padding: 17px 21px; }
.contact-action { display: grid; place-items: center; min-height: 52px; color: white; background: var(--charcoal); border-radius: 5px; font-size: .82rem; font-weight: 800; text-decoration: none; }
.contact-action.disabled { color: #aaa39d; background: #e9e4df; pointer-events: none; }
.detail-section { padding: 5px 21px 19px; }
.detail-section h3 { margin: 0 0 8px; font-size: .78rem; color: var(--muted); text-transform: uppercase; letter-spacing: .07em; }
.detail-section p { margin: 0; line-height: 1.62; white-space: pre-wrap; }
.detail-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; padding: 0 21px 18px; }
.detail-grid div { padding: 13px; background: #f5f1ec; border-radius: 5px; }
.detail-grid span, .detail-grid strong { display: block; }
.detail-grid span { color: var(--muted); font-size: .7rem; text-transform: uppercase; }
.detail-grid strong { margin-top: 4px; font-size: .86rem; }
.lead-edit-form { display: grid; gap: 15px; padding: 20px 21px max(22px, env(safe-area-inset-bottom)); background: #f8f5f1; border-top: 1px solid var(--line); }
.lead-edit-form .message { margin: -5px 0 0; }
.account-dialog { padding-bottom: 20px; }
.account-dialog .dialog-header { justify-content: space-between; }
.account-dialog > button, .account-section > button { width: 100%; margin-top: 12px; }
.account-dialog > button { width: calc(100% - 42px); margin: 16px 21px 0; }
.account-section { margin: 0 21px; padding: 18px 0; border-bottom: 1px solid var(--line); }
.account-section h3 { margin: 0 0 11px; font-size: .78rem; color: var(--muted); letter-spacing: .07em; text-transform: uppercase; }
.passkey-list { display: grid; gap: 8px; }
.passkey-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 11px 12px; background: #f5f1ec; border-radius: 5px; }
.passkey-row strong, .passkey-row span { display: block; }
.passkey-row span { margin-top: 3px; color: var(--muted); font-size: .72rem; }
.passkey-row button { padding: 8px; color: var(--red-dark); background: transparent; border: 0; font-weight: 750; }
.codes-dialog { padding: 25px; }
.codes-dialog h2 { margin: 0; font-family: Georgia, serif; font-size: 2rem; }
.codes-dialog p { color: var(--muted); line-height: 1.5; }
.codes-dialog pre { padding: 18px; overflow: auto; color: white; background: var(--charcoal); border-radius: 5px; font: 700 1rem/1.65 ui-monospace, SFMono-Regular, Consolas, monospace; }
.codes-dialog button { width: 100%; margin-top: 10px; }
.toast { position: fixed; z-index: 50; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); max-width: calc(100% - 34px); padding: 12px 16px; color: white; background: var(--charcoal); border-radius: 5px; box-shadow: var(--shadow); opacity: 0; pointer-events: none; transform: translate(-50%, 12px); transition: opacity .18s ease, transform .18s ease; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (max-width: 560px) {
  .inbox-main { padding-top: 22px; }
  .lead-card { grid-template-columns: auto 1fr; }
  .lead-card-side { grid-column: 2; grid-row: 2; display: flex; justify-content: space-between; width: 100%; }
  dialog { width: 100%; max-width: none; max-height: 94dvh; margin: auto 0 0; border-radius: 12px 12px 0 0; }
  .contact-actions { position: sticky; top: 0; z-index: 2; background: white; }
}

@media (prefers-reduced-motion: reduce) { * { scroll-behavior: auto !important; transition: none !important; } }
