:root {
  --navy: #16213a; --ink: #1d2433; --muted: #667085; --bg: #f3f5f8; --paper: #fff;
  --line: #e3e7ee; --accent: #e8a33d; --accent-soft: #fdf3e2;
  --new: #2563eb; --replied: #7c3aed; --scheduled: #0891b2; --won: #16a34a; --lost: #9ca3af;
  --display: 'Archivo', 'Arial Narrow', system-ui, sans-serif; --sans: 'Public Sans', system-ui, Segoe UI, sans-serif;
}
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 var(--sans); color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { font-family: var(--display); margin: 0; letter-spacing: -.01em; }
[hidden] { display: none !important; }

.logo { display: flex; align-items: center; gap: 10px; font: 700 1.15rem var(--display); }
.logo em { font-style: normal; color: var(--accent); }
.logo-mark { width: 24px; height: 24px; border-radius: 7px 7px 7px 2px; background: conic-gradient(from 200deg, var(--accent), #f5c56f, #9db4a0, var(--accent)); }
.tag { font: 600 .7rem var(--sans); text-transform: uppercase; letter-spacing: .1em; background: rgba(255,255,255,.12); padding: 3px 8px; border-radius: 6px; }

.btn { font: 600 .92rem var(--sans); border: 0; border-radius: 10px; padding: 10px 16px; cursor: pointer; transition: background-color .15s, transform .1s; }
.btn:active { transform: scale(.97); }
.btn.primary { background: var(--accent); color: var(--navy); }
.btn.primary:hover { background: #f0b14f; }
.btn.ghost { background: transparent; color: inherit; box-shadow: inset 0 0 0 1.5px currentColor; opacity: .85; }
.btn.subtle { background: var(--bg); color: var(--ink); }
.btn.subtle:hover { background: #e6eaf0; }
.btn.danger { background: transparent; color: #b42318; }
.btn.danger:hover { background: #fef3f2; }
.btn.sm { padding: 7px 12px; font-size: .85rem; }
.btn[disabled] { opacity: .6; cursor: wait; }

/* Login */
.login { min-height: 100vh; display: grid; place-items: center; background: radial-gradient(800px 400px at 70% 0%, #2a3c64, transparent 60%), var(--navy); padding: 16px; }
.login-card { background: var(--paper); border-radius: 18px; padding: 36px; width: min(380px, 100%); display: flex; flex-direction: column; gap: 16px; box-shadow: 0 30px 60px -20px rgba(0,0,0,.5); }
.login-card h1 { font-size: 1.6rem; }
.login-card label { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .9rem; }
.login-card input { font: 1rem var(--sans); padding: 11px 13px; border-radius: 10px; border: 1.5px solid var(--line); }
.login-card input:focus { outline: 0; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(232,163,61,.18); }
.err { color: #b42318; margin: 0; font-size: .9rem; }
.back { color: var(--muted); font-size: .88rem; text-decoration: none; text-align: center; }

/* Top */
.top { background: var(--navy); color: #fff; display: flex; justify-content: space-between; align-items: center; padding: 14px 24px; gap: 16px; flex-wrap: wrap; }
.top-right { display: flex; align-items: center; gap: 16px; font-size: .88rem; }
.link { color: #cbd3e3; text-decoration: none; }
.link:hover { color: #fff; }
.mail-status { display: inline-flex; align-items: center; gap: 6px; color: #cbd3e3; }
.mail-status::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: var(--mail, #9ca3af); }

/* Stats */
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; padding: 20px 24px 0; }
.stat { background: var(--paper); border-radius: 14px; padding: 16px 18px; }
.stat span { color: var(--muted); font-size: .82rem; font-weight: 500; }
.stat b { display: block; font: 700 1.7rem var(--display); font-variant-numeric: tabular-nums; margin-top: 2px; }

/* Layout */
.layout { display: grid; grid-template-columns: 380px 1fr; gap: 16px; padding: 16px 24px 24px; height: calc(100vh - 170px); min-height: 520px; }
.list-pane, .detail { background: var(--paper); border-radius: 16px; overflow: hidden; display: flex; flex-direction: column; min-height: 0; }
.list-tools { padding: 14px; border-bottom: 1px solid var(--line); display: flex; flex-direction: column; gap: 10px; }
#search { font: .95rem var(--sans); padding: 9px 12px; border-radius: 10px; border: 1.5px solid var(--line); width: 100%; }
#search:focus { outline: 0; border-color: var(--accent); }
.filters { display: flex; gap: 4px; flex-wrap: wrap; }
.filters button { font: 600 .8rem var(--sans); border: 0; background: transparent; padding: 6px 10px; border-radius: 8px; cursor: pointer; color: var(--muted); }
.filters button:hover { background: var(--bg); }
.filters button.on { background: var(--navy); color: #fff; }
.filters button .n { opacity: .7; margin-left: 4px; font-variant-numeric: tabular-nums; }

.list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.list li { padding: 14px 16px; border-bottom: 1px solid var(--line); cursor: pointer; display: grid; grid-template-columns: 1fr auto; gap: 2px 12px; transition: background-color .12s; }
.list li:hover { background: #f7f9fb; }
.list li.sel { background: var(--accent-soft); box-shadow: inset 3px 0 0 var(--accent); }
.list .name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.list .unread { width: 8px; height: 8px; border-radius: 50%; background: var(--new); }
.list .when { color: var(--muted); font-size: .8rem; text-align: right; }
.list .svc { color: var(--muted); font-size: .85rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.list .amt { font-weight: 600; font-size: .85rem; font-variant-numeric: tabular-nums; text-align: right; }
.list .none { cursor: default; color: var(--muted); text-align: center; display: block; padding: 40px 16px; }

.badge { display: inline-block; font: 600 .72rem var(--sans); text-transform: capitalize; padding: 3px 9px; border-radius: 999px; color: #fff; background: var(--c); }

/* Detail */
.detail { overflow-y: auto; }
.empty { margin: auto; text-align: center; color: var(--muted); padding: 40px; }
.empty-icon { font-size: 2rem; width: 64px; height: 64px; border-radius: 50%; background: var(--bg); display: grid; place-items: center; margin: 0 auto 14px; }
.empty h2 { color: var(--ink); font-size: 1.3rem; margin-bottom: 6px; }

.d-head { padding: 22px 26px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.d-head h2 { font-size: 1.6rem; }
.d-head .sub { color: var(--muted); font-size: .9rem; margin-top: 4px; }
.d-head .sub a { color: inherit; }
.d-actions { display: flex; gap: 8px; align-items: center; }
.d-actions select { font: 600 .88rem var(--sans); padding: 8px 10px; border-radius: 10px; border: 1.5px solid var(--line); background: #fff; }

.d-body { display: grid; grid-template-columns: 1fr 320px; gap: 0; flex: 1; }
.d-main { padding: 22px 26px; border-right: 1px solid var(--line); min-width: 0; }
.d-side { padding: 22px; display: flex; flex-direction: column; gap: 18px; }
.sec-title { font: 700 .75rem var(--sans); text-transform: uppercase; letter-spacing: .1em; color: var(--muted); margin: 0 0 10px; }

.info { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px 20px; margin-bottom: 22px; font-size: .9rem; }
.info dt { color: var(--muted); font-size: .78rem; }
.info dd { margin: 0; font-weight: 500; overflow-wrap: anywhere; }

.est-card { background: var(--navy); color: #fff; border-radius: 14px; padding: 18px; }
.est-card .range { font: 700 1.6rem var(--display); font-variant-numeric: tabular-nums; }
.est-card ul { list-style: none; padding: 0; margin: 10px 0 0; font-size: .82rem; color: #cbd3e3; }
.est-card li { display: flex; justify-content: space-between; gap: 10px; padding: 6px 0; border-top: 1px solid rgba(255,255,255,.1); }
.est-card li b { color: #fff; font-weight: 600; white-space: nowrap; }
.side-field { display: flex; flex-direction: column; gap: 6px; font-size: .85rem; font-weight: 600; }
.side-field input, .side-field textarea { font: 400 .95rem var(--sans); padding: 9px 11px; border-radius: 10px; border: 1.5px solid var(--line); width: 100%; resize: vertical; }
.side-field input:focus, .side-field textarea:focus { outline: 0; border-color: var(--accent); }
.money-input { position: relative; }
.money-input::before { content: '$'; position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.money-input input { padding-left: 22px; font-variant-numeric: tabular-nums; }
.quick-prices { display: flex; gap: 6px; flex-wrap: wrap; }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.photos a { display: block; aspect-ratio: 1; border-radius: 8px; overflow: hidden; background: var(--bg); }
.photos img { width: 100%; height: 100%; object-fit: cover; }

.thread { display: flex; flex-direction: column; gap: 12px; margin-bottom: 22px; }
.msg { border-radius: 14px; padding: 14px 16px; max-width: 88%; white-space: pre-wrap; overflow-wrap: anywhere; font-size: .93rem; }
.msg.in { background: var(--bg); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { background: var(--accent-soft); align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .meta { font-size: .76rem; color: var(--muted); margin-bottom: 6px; white-space: normal; display: flex; gap: 8px; flex-wrap: wrap; }
.msg .meta b { color: var(--ink); }
.msg .sent { color: var(--won); } .msg .logged { color: #b45309; } .msg .failed { color: #b42318; }

.composer { border: 1.5px solid var(--line); border-radius: 14px; overflow: hidden; }
.composer:focus-within { border-color: var(--accent); }
.composer input, .composer textarea { width: 100%; border: 0; font: .95rem var(--sans); padding: 12px 14px; color: var(--ink); }
.composer input { border-bottom: 1px solid var(--line); font-weight: 600; }
.composer textarea { min-height: 180px; resize: vertical; display: block; }
.composer input:focus, .composer textarea:focus { outline: 0; }
.composer-bar { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px; background: #f7f9fb; border-top: 1px solid var(--line); flex-wrap: wrap; }
.templates { display: flex; gap: 6px; flex-wrap: wrap; }
.composer-note { font-size: .8rem; color: var(--muted); margin: 8px 2px 0; }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%); background: var(--navy); color: #fff; padding: 12px 18px; border-radius: 12px; font-size: .92rem; box-shadow: 0 12px 30px -10px rgba(0,0,0,.4); z-index: 99; animation: up .25s ease; }
.toast.bad { background: #b42318; }
@keyframes up { from { opacity: 0; transform: translate(-50%, 8px); } }

@media (max-width: 1100px) {
  .d-body { grid-template-columns: 1fr; }
  .d-main { border-right: 0; border-bottom: 1px solid var(--line); }
}
@media (max-width: 820px) {
  .stats { grid-template-columns: 1fr 1fr; padding: 16px 16px 0; }
  .layout { grid-template-columns: 1fr; height: auto; padding: 16px; }
  .list { max-height: 360px; }
  .top { padding: 12px 16px; }
  .mail-status { display: none; }
}

/* Keyboard focus */
a:focus-visible, button:focus-visible, select:focus-visible, .list li:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

/* ---------- Auth forms ---------- */
.login-card form { display: flex; flex-direction: column; gap: 14px; }
.login-card .logo { color: var(--navy); }
.tag.dark { background: var(--navy); color: #fff; }
.link-btn { background: none; border: 0; color: var(--muted); font: 500 .88rem var(--sans); cursor: pointer; padding: 4px; align-self: center; }
.link-btn:hover { color: var(--ink); text-decoration: underline; }
.muted { color: var(--muted); }
.small { font-size: .8rem; }
.hint { color: var(--muted); font-size: .8rem; margin: 0; }
.hint a, .notice a, .composer-note a { color: inherit; font-weight: 600; }
.ok { color: #15803d; margin: 0; font-size: .9rem; }

/* ---------- Header tabs ---------- */
.tabs { display: flex; gap: 4px; }
.tabs a { color: #cbd3e3; text-decoration: none; font-weight: 600; font-size: .9rem; padding: 7px 14px; border-radius: 9px; transition: background-color .15s, color .15s; }
.tabs a:hover { color: #fff; background: rgba(255,255,255,.08); }
.tabs a.on { color: var(--navy); background: var(--accent); }
.who { color: #cbd3e3; }

/* ---------- Banners ---------- */
#notices:empty { display: none; }
#notices { padding: 14px 24px 0; display: flex; flex-direction: column; gap: 8px; }
.notice { padding: 11px 16px; border-radius: 12px; font-size: .9rem; }
.notice.tone-warn { background: #fef3c7; color: #92400e; }
.notice.tone-info { background: #e0f2fe; color: #075985; }

/* ---------- Pages ---------- */
.page { padding: 20px 24px 40px; }
.page-head { margin-bottom: 16px; }
.page-head h1 { font-size: 1.8rem; margin-bottom: 4px; }
.page-head p { margin: 0; }
.page .stats { padding: 0 0 16px; }
.card { background: var(--paper); border-radius: 16px; }
.table-card { overflow-x: auto; }
.inv-table { width: 100%; border-collapse: collapse; font-size: .92rem; }
.inv-table th { text-align: left; font-size: .75rem; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 14px 16px; border-bottom: 1px solid var(--line); }
.inv-table td { padding: 14px 16px; border-bottom: 1px solid var(--line); vertical-align: top; }
.inv-table tr:last-child td { border-bottom: 0; }
.inv-table .num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.inv-table a { color: inherit; }
.inv-table .none { text-align: center; color: var(--muted); padding: 40px; }

/* ---------- Settings ---------- */
.settings-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; align-items: start; }
.setting { padding: 22px 24px; display: flex; flex-direction: column; gap: 12px; }
.setting h2 { font-size: 1.25rem; display: flex; align-items: center; gap: 8px; }
.setting p { margin: 0; }
.status-line { font-weight: 600; color: var(--muted); }
.status-line.ok { color: #15803d; }
.status-line.bad { color: #b45309; }
.checks { list-style: none; margin: 0; padding: 0; font-size: .9rem; display: flex; flex-direction: column; gap: 4px; }
.checks .ok { color: #15803d; }
.checks .bad { color: #b45309; }
.row-btns { display: flex; gap: 8px; flex-wrap: wrap; }
.btn.google, .btn.stripe { display: inline-flex; align-items: center; justify-content: center; gap: 10px; text-decoration: none; padding: 12px 18px; font-size: .95rem; align-self: flex-start; }
.btn.google { background: #fff; color: #1f1f1f; box-shadow: inset 0 0 0 1.5px #dadce0; }
.btn.google:hover { background: #f8f9fa; }
.g-icon { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; font-weight: 800; color: #fff; background: conic-gradient(#ea4335 0 25%, #fbbc05 0 50%, #34a853 0 75%, #4285f4 0); font-size: .75rem; }
.btn.stripe { background: #635bff; color: #fff; }
.btn.stripe:hover { background: #5249f5; }
a.btn.subtle { text-decoration: none; display: inline-block; }
.tag.test { background: #fef3c7; color: #92400e; }
.tag.light { background: var(--bg); color: var(--muted); }
.admin-list { list-style: none; margin: 0; padding: 0; }
.admin-list li { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.inline-form { display: flex; gap: 8px; flex-wrap: wrap; }
.inline-form input { flex: 1 1 140px; font: .95rem var(--sans); padding: 9px 11px; border-radius: 10px; border: 1.5px solid var(--line); min-width: 0; }
.inline-form input:focus, .stack input:focus, .stack textarea:focus { outline: 0; border-color: var(--accent); }
.stack { display: flex; flex-direction: column; gap: 12px; }

/* ---------- Invoice box (request sidebar) ---------- */
.sec-title.light { color: #9aa6bd; }
.invoice-box { border: 1.5px solid var(--line); border-radius: 14px; padding: 14px; display: flex; flex-direction: column; gap: 10px; }
.invoice-box .sec-title { margin: 0; }
.seg-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { font: 600 .8rem var(--sans); border: 0; border-radius: 999px; padding: 6px 11px; background: var(--bg); color: var(--ink); cursor: pointer; }
.chip:hover { background: #e6eaf0; }
.chip.on { background: var(--navy); color: #fff; }
.inv-list { list-style: none; margin: 4px 0 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.inv { background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.inv-top { display: flex; align-items: center; gap: 8px; }
.inv-amt { margin-left: auto; font-variant-numeric: tabular-nums; }
.inv-sub { font-size: .8rem; color: var(--muted); margin: 4px 0 8px; }
.inv-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.badge.inv-sent { --c: #b45309; }
.badge.inv-processing { --c: #0369a1; }
.badge.inv-paid { --c: #15803d; }
.badge.inv-void { --c: #9ca3af; }
.badge[class*="inv-"] { background: var(--c); }
.msg .received { color: var(--muted); }

@media (max-width: 1100px) { .settings-grid { grid-template-columns: 1fr; } }
@media (max-width: 820px) {
  .tabs { order: 3; width: 100%; }
  .who { display: none; }
  .page, #notices { padding-left: 16px; padding-right: 16px; }
}

/* ---------- In-page setup guides ---------- */
.setting.wide { grid-column: 1 / -1; }
.guide-progress { display: flex; align-items: center; gap: 12px; font-size: .82rem; color: var(--muted); }
.guide-progress .bar { flex: 1; height: 6px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.guide-progress .bar i { display: block; height: 100%; background: var(--accent); border-radius: inherit; transition: width .3s ease; }
.guide { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.g-step details { border: 1.5px solid var(--line); border-radius: 12px; background: #fff; transition: border-color .15s; }
.g-step details[open] { border-color: var(--accent); }
.g-step.done details:not([open]) { background: #f3faf5; }
.g-step summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px; padding: 12px 14px; font-weight: 600; }
.g-step summary::-webkit-details-marker { display: none; }
.g-step summary::after { content: '▾'; margin-left: auto; color: var(--muted); transition: transform .2s; }
.g-step details[open] summary::after { transform: rotate(180deg); }
.g-num { width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; background: var(--bg); font-size: .8rem; flex: none; }
.g-step.done .g-num { background: #15803d; color: #fff; }
.g-body { padding: 0 14px 14px 52px; display: flex; flex-direction: column; gap: 10px; font-size: .92rem; }
.g-body p { margin: 0; }
.copy-row { display: grid; grid-template-columns: 120px 1fr auto; gap: 10px; align-items: center; background: var(--bg); border-radius: 10px; padding: 8px 10px; }
.copy-row span { font-size: .78rem; color: var(--muted); font-weight: 600; }
.copy-row code { font-size: .82rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.btn.ext { align-self: flex-start; text-decoration: none; }
.g-check { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: .88rem; cursor: pointer; align-self: flex-start; padding: 6px 0; }
.g-check input { width: 18px; height: 18px; accent-color: #15803d; }
.key-form { max-width: 520px; }
.key-form input { font: .95rem ui-monospace, Consolas, monospace; }
.keys-box { border-top: 1px solid var(--line); padding-top: 10px; }
.keys-box summary { cursor: pointer; font-weight: 600; font-size: .88rem; color: var(--muted); }
.keys-box[open] { display: flex; flex-direction: column; gap: 10px; }
.keys-box code { font-size: .8rem; overflow-wrap: anywhere; }
@media (max-width: 640px) {
  .g-body { padding-left: 14px; }
  .copy-row { grid-template-columns: 1fr auto; }
  .copy-row span { grid-column: 1 / -1; }
}

/* ---------- Photo viewer ---------- */
body.no-scroll { overflow: hidden; }
.lightbox { position: fixed; inset: 0; z-index: 200; background: rgba(10, 15, 28, .82); backdrop-filter: blur(4px); display: flex; align-items: center; justify-content: center; gap: 12px; padding: 56px 16px 24px; animation: lbIn .18s ease; }
.lightbox[hidden] { display: none; }
@keyframes lbIn { from { opacity: 0; } }
.lb-frame { margin: 0; display: flex; flex-direction: column; align-items: center; gap: 10px; max-width: min(1100px, 100%); min-width: 0; }
.lb-frame img { max-width: 100%; max-height: calc(100vh - 140px); border-radius: 12px; box-shadow: 0 30px 80px -20px rgba(0,0,0,.7); background: #222; opacity: 0; transform: scale(.98); transition: opacity .2s ease, transform .2s ease; }
.lb-frame img.in { opacity: 1; transform: none; }
.lb-frame figcaption { display: flex; gap: 16px; align-items: center; color: #cbd3e3; font-size: .85rem; }
.lb-full { color: #fff; }
.lb-btn { border: 0; background: rgba(255,255,255,.12); color: #fff; width: 48px; height: 48px; border-radius: 50%; font-size: 1.8rem; line-height: 1; cursor: pointer; display: grid; place-items: center; flex: none; transition: background-color .15s, transform .1s; }
.lb-btn:hover { background: rgba(255,255,255,.24); }
.lb-btn:active { transform: scale(.94); }
.lb-btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.lb-close { position: absolute; top: 14px; right: 16px; width: 44px; height: 44px; font-size: 1.7rem; }
.photos a { cursor: zoom-in; transition: transform .15s, box-shadow .15s; }
.photos a:hover { transform: scale(1.03); box-shadow: 0 6px 16px -6px rgba(0,0,0,.35); }
@media (max-width: 640px) {
  .lb-prev, .lb-next { position: absolute; bottom: 20px; }
  .lb-prev { left: calc(50% - 60px); }
  .lb-next { right: calc(50% - 60px); }
  .lightbox { padding-bottom: 84px; }
}
