:root {
  color-scheme: dark;
  --bg: #0f0e0d; --surface: #1a1816; --line: #2e2a26;
  --text: #f2ede6; --muted: #b3aaa0; --accent: #ff5a36; --warn: #ffb020;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--text); text-decoration-color: var(--accent); }
a:hover { color: var(--accent); }
.top { display: flex; align-items: center; gap: 20px; flex-wrap: wrap; padding: 12px 20px; border-bottom: 1px solid var(--line); }
.logo { font-weight: 900; text-transform: uppercase; text-decoration: none; letter-spacing: .02em; }
.logo span { color: var(--accent); }
.top nav { display: flex; gap: 16px; flex: 1; }
.top nav a { color: var(--muted); text-decoration: none; }
.user { color: var(--muted); font-size: 13px; }
main { max-width: 1100px; margin: 0 auto; padding: 20px; }
h1 { font-size: 26px; margin: 0 0 6px; }
h2 { font-size: 18px; margin: 0 0 12px; }
h3 { font-size: 15px; margin: 18px 0 8px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; }
.muted { color: var(--muted); font-size: 14px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }
.filters input[type=search] { flex: 1; min-width: 200px; }
input, select, textarea, button { font: inherit; color: var(--text); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; }
textarea { min-height: 90px; resize: vertical; width: 100%; }
button { background: var(--accent); color: var(--bg); border: 0; font-weight: 700; cursor: pointer; }
table.leads { width: 100%; border-collapse: collapse; }
.leads th, .leads td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: top; }
.leads th { color: var(--muted); font-size: 13px; font-weight: 600; }
.overdue { color: var(--warn); font-weight: 700; }
.stage { display: inline-block; font-size: 12px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: var(--line); vertical-align: middle; }
.stage-new { background: var(--accent); color: var(--bg); }
.stage-won { background: #2f7d4a; }
.stage-lost { color: var(--muted); }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; padding: 18px; margin: 16px 0; }
.narrow { max-width: 560px; }
.cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.cols .panel { margin: 0; }
.stack { display: grid; gap: 10px; }
.stack label { display: grid; gap: 4px; font-size: 14px; color: var(--muted); }
.message { white-space: pre-wrap; margin: 6px 0 0; }
.note { border-top: 1px solid var(--line); padding: 10px 0; }
.empty { color: var(--muted); padding: 40px 0; text-align: center; }
@media (max-width: 640px) {
  .leads thead { display: none; }
  .leads tr { display: block; border-bottom: 1px solid var(--line); padding: 8px 0; }
  .leads td { display: block; border: 0; padding: 2px 0; }
}

/* Flash messages */
.flash { padding: 10px 14px; border-radius: 8px; margin: 0 0 16px; }
.flash.ok { background: #1f3a29; border: 1px solid #2f7d4a; }
.flash.err { background: #3a1f1a; border: 1px solid var(--accent); }

/* Sorting */
.leads th a.sort { color: var(--muted); text-decoration: none; white-space: nowrap; }
.leads th a.sort:hover, .leads th a.sort.active { color: var(--text); }
.leads th a.sort span { font-size: 10px; }

/* Lead page panels */
.stack-panels { display: grid; gap: 16px; align-content: start; }
.item { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; padding: 10px 0; border-top: 1px solid var(--line); }
.item:first-of-type { border-top: 0; }
.item.past { opacity: .7; }
.item.cancelled { opacity: .5; }
.item.cancelled strong { text-decoration: line-through; }
.tag { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 7px; border-radius: 999px; background: var(--line); color: var(--muted); vertical-align: middle; }
.row3 { display: grid; grid-template-columns: 2fr 1fr 1fr; gap: 8px; }
.row3 label { min-width: 0; }
.row3 input, .row3 select { width: 100%; }
fieldset.address { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; display: grid; gap: 10px; margin: 0; }
fieldset.address legend { color: var(--muted); font-size: 14px; padding: 0 4px; }
.check { display: flex !important; align-items: center; gap: 8px; grid-template-columns: none; color: var(--text) !important; }
.check input { width: 18px; height: 18px; accent-color: var(--accent); }
details.add { margin-top: 12px; border-top: 1px solid var(--line); padding-top: 12px; }
details > summary { cursor: pointer; color: var(--accent); font-weight: 700; }
details.add[open] > summary { margin-bottom: 12px; }
.inline-action { flex-shrink: 0; text-align: right; }
.inline-action > summary { font-weight: 400; font-size: 14px; color: var(--muted); }
.inline-action form { margin-top: 8px; min-width: 220px; text-align: left; }
button.secondary { background: var(--surface); color: var(--text); border: 1px solid var(--line); }
button.danger { background: #b3261e; color: #fff; }
button.link { background: none; border: 0; padding: 0; font-weight: 400; font-size: 14px; color: var(--muted); text-decoration: underline; }
button.link.danger:hover { color: var(--accent); }
.button-row { display: flex; gap: 8px; flex-wrap: wrap; }
.title-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
h2.spaced { margin-top: 32px; }
.leads.past { opacity: .75; }
code { background: var(--bg); border: 1px solid var(--line); border-radius: 4px; padding: 1px 5px; font-size: 13px; word-break: break-all; }
@media (max-width: 640px) {
  .row3 { grid-template-columns: 1fr 1fr; }
  .row3 label:first-child { grid-column: 1 / -1; }
}

/* Panel headers with an action button */
.panel-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 8px; }
.panel-head h2 { margin: 0; }
.panel-head button { padding: 6px 12px; font-size: 14px; }

/* Modals */
dialog.modal { width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 32px); overflow: auto; padding: 22px; border: 1px solid var(--line); border-radius: 14px; background: var(--surface); color: var(--text); }
dialog.modal::backdrop { background: rgba(0, 0, 0, .65); backdrop-filter: blur(2px); }
.modal-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.modal-head h2 { margin: 0; }
.modal .close { background: none; color: var(--muted); font-size: 26px; line-height: 1; padding: 0 4px; font-weight: 400; }
.modal .close:hover { color: var(--text); }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.modal input[type=file] { padding: 8px; }
.modal input, .modal select, .modal textarea { background: var(--bg); }
button:disabled { opacity: .6; cursor: progress; }

/* Autosave */
.hint { margin: 4px 0 0; }
.field-saving { border-color: var(--muted) !important; }
.field-saved { border-color: #2f7d4a !important; transition: border-color .3s; }
.field-error { border-color: var(--accent) !important; }

/* Guest replies */
.rsvp { font-size: 14px; margin-top: 4px; }
.rsvp .tag { margin-right: 4px; }
.rsvp-accepted { background: #2f7d4a; color: #fff; }
.rsvp-declined { background: #b3261e; color: #fff; }
.rsvp-tentative { background: var(--warn); color: var(--bg); }
.rsvp-comment { display: block; color: var(--muted); font-style: italic; margin: 2px 0 0 2px; white-space: pre-wrap; }

/* Toasts */
.toasts { position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%); z-index: 1000; display: grid; gap: 8px; justify-items: center; width: max-content; max-width: calc(100vw - 32px); pointer-events: none; }
.toast { pointer-events: auto; cursor: pointer; padding: 10px 16px; border-radius: 10px; background: #2a2622; border: 1px solid var(--line); color: var(--text); font-size: 15px; box-shadow: 0 8px 24px rgba(0,0,0,.45); animation: toast-in .2s ease-out; }
.toast.ok { border-color: #2f7d4a; }
.toast.ok::before { content: "✓ "; color: #6fcf8f; font-weight: 700; }
.toast.error { border-color: var(--accent); background: #3a1f1a; }
.toast.leaving { opacity: 0; transform: translateY(6px); transition: opacity .25s, transform .25s; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
@media (prefers-reduced-motion: reduce) { .toast { animation: none; } .toast.leaving { transition: none; } }

/* Maps */
.map { margin-top: 14px; }
.map iframe { width: 100%; height: 220px; border: 1px solid var(--line); border-radius: 10px; display: block; background: var(--bg); }
.map a { display: inline-block; margin-top: 6px; }
.places-host { position: relative; }
.places-list { position: absolute; left: 0; right: 0; top: 100%; z-index: 50; margin: 4px 0 0; padding: 4px 0; list-style: none; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.places-list li { padding: 8px 12px; cursor: pointer; display: grid; color: var(--text); }
.places-list li span { color: var(--muted); font-size: 13px; }
.places-list li.active, .places-list li:hover { background: var(--line); }
.places-list li.credit { cursor: default; font-size: 11px; color: var(--muted); text-align: right; padding: 4px 12px; }
.places-list li.credit:hover { background: none; }

/* Lead and Contact tiles */
.fields { display: grid; gap: 12px; }
.fields label { display: grid; gap: 3px; min-width: 0; }
.fields label > span { font-size: 12px; font-weight: 600; color: var(--muted); letter-spacing: .03em; }
.fields input, .fields select { width: 100%; min-width: 0; background: var(--bg); }
.fields input::placeholder { color: #6f675f; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.row-wide { display: grid; grid-template-columns: 1fr 160px; gap: 10px; }
.fields .row3 { margin-top: -4px; }
.head-links { display: flex; gap: 14px; }
.small { font-size: 13px; }
.sub { margin-top: 16px; border-top: 1px solid var(--line); }
.sub h3 { margin-top: 12px; }
.sub ul { margin: 0; padding-left: 18px; }
@media (max-width: 420px) {
  .row2, .row-wide { grid-template-columns: 1fr; }
}
@media (max-width: 640px) {
  .fields .row3 { grid-template-columns: 2fr 1fr 1fr; }
}

/* Buttons for links: no underlined text links in the CRM */
a { text-decoration: none; }
a.title-link { font-weight: 600; }
a.title-link:hover { color: var(--accent); }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 5px 12px; border: 1px solid var(--line); border-radius: 8px;
       background: var(--bg); color: var(--text); font: inherit; font-size: 14px; font-weight: 600; line-height: 1.4;
       text-decoration: none; white-space: nowrap; cursor: pointer; }
.btn:hover { border-color: var(--muted); color: var(--text); }
button.btn { background: var(--bg); color: var(--text); }
.btn.danger, button.btn.danger { color: #ff8a7a; }
.btn.danger:hover { border-color: #ff8a7a; }
.btn-row { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.btn-row form { margin: 0; }
.item .btn-row { margin-top: 8px; }
.item > .btn-row { margin-top: 0; flex-shrink: 0; }
.panel > .btn { margin-top: 4px; }
summary.btn { list-style: none; color: var(--text); font-weight: 600; font-size: 14px; }
summary.btn::-webkit-details-marker { display: none; }
.flash .btn { margin-left: 8px; }

/* Sign-in */
.top form { margin: 0; }
.login-body { min-height: 100vh; display: grid; place-items: center; }
.login { max-width: 360px; width: 100%; padding: 32px 20px; text-align: center; display: grid; gap: 14px; justify-items: center; }
.login h1 { margin: 0; font-weight: 900; text-transform: uppercase; letter-spacing: .02em; }
.login h1 span { color: var(--accent); }
.login-logo { border-radius: 14px; }
.login .flash { margin: 0; width: 100%; text-align: left; }
.google-btn { display: inline-flex; align-items: center; gap: 10px; background: #fff; color: #1f1f1f; padding: 10px 18px; border-radius: 999px; font-weight: 600; }
.google-btn:hover { background: #f1f1f1; }
.inline-add { display: flex; gap: 8px; margin-top: 12px; }
.inline-add input { flex: 1; min-width: 0; background: var(--bg); }
