/* ============================================================
   REV&REFINE CRM styles (same colors as the website)
   ============================================================ */
:root {
  --red: #dc1c3a; --red-dark: #b3122c; --red-soft: #fff1f3;
  --ink: #121214; --ink-2: #2b2b30; --muted: #64646d;
  --line: #e1e1e5; --mist: #f4f4f6; --paper: #fff;
  --green: #1f8a4c; --green-soft: #e9f7ef; --amber: #a86400; --amber-soft: #fff5e1; --blue: #2459c8; --blue-soft: #eaf0ff;
  --radius: 12px; --shadow: 0 6px 20px rgba(18,18,20,.08);
  --head: "Oswald", "Arial Narrow", system-ui, sans-serif;
  --body: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light;
}
*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--mist); color: var(--ink); font: 15px/1.5 var(--body); }
a { color: inherit; }
h1, h2, h3 { font-family: var(--head); line-height: 1.15; margin: 0 0 .4em; letter-spacing: .01em; }
h1 { font-size: 1.7rem; text-transform: uppercase; }
h2 { font-size: 1.15rem; text-transform: uppercase; letter-spacing: .04em; }
p { margin: 0 0 .8em; }
.muted { color: var(--muted); }
.small { font-size: .86rem; }
.hidden { display: none !important; }
:focus-visible { outline: 3px solid var(--red); outline-offset: 2px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 42px; padding: 0 16px; border-radius: 10px; border: 2px solid var(--red);
  background: var(--red); color: #fff; font: 600 .95rem/1 var(--body); text-decoration: none; cursor: pointer;
  transition: background-color .15s, transform .1s, border-color .15s, color .15s; white-space: nowrap;
}
.btn:hover { background: var(--red-dark); border-color: var(--red-dark); }
.btn:active { transform: scale(.97); }
.btn[disabled] { opacity: .55; cursor: not-allowed; }
.btn-ghost { background: #fff; color: var(--ink); border-color: var(--line); }
.btn-ghost:hover { background: var(--mist); border-color: var(--ink); color: var(--ink); }
.btn-dark { background: var(--ink); border-color: var(--ink); }
.btn-dark:hover { background: var(--ink-2); border-color: var(--ink-2); }
.btn-danger { background: #fff; color: var(--red-dark); border-color: #f2c4cc; }
.btn-danger:hover { background: var(--red-soft); color: var(--red-dark); border-color: var(--red); }
.btn-sm { min-height: 34px; padding: 0 11px; font-size: .85rem; border-radius: 8px; }
.btn-block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 8px; }
.icon-btn { display: inline-grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; border: 2px solid var(--line); background: #fff; text-decoration: none; font-size: 1.05rem; cursor: pointer; }
.icon-btn:hover { border-color: var(--ink); }
.linkish { background: none; border: 0; padding: 0; color: var(--red-dark); font: inherit; font-weight: 600; cursor: pointer; text-decoration: underline; }

/* ---------- Auth screens ---------- */
.auth { min-height: 100vh; min-height: 100svh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(ellipse at 50% 30%, #f6f6f7, #dcdce0 60%, #bdbdc2); }
.auth-card { width: min(400px, 100%); background: #fff; border-radius: 18px; padding: 28px 24px; box-shadow: 0 20px 50px rgba(0,0,0,.15); border-top: 5px solid var(--red); }
.auth-card img { width: 220px; margin: 0 auto 6px; display: block; }
.auth-card h1 { text-align: center; font-size: 1.35rem; margin-bottom: 18px; }
.auth-card .msg { margin: 12px 0 0; font-weight: 600; text-align: center; }
.auth-card .msg.bad { color: var(--red-dark); }
.auth-card .msg.good { color: var(--green); }
.auth-foot { text-align: center; margin-top: 14px; }
.qr { display: block; width: 200px; height: 200px; margin: 6px auto 10px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px; }
.secret { font-family: ui-monospace, Consolas, monospace; font-size: .85rem; word-break: break-all; background: var(--mist); padding: 8px 10px; border-radius: 8px; }

/* ---------- Forms ---------- */
.field { margin: 0 0 14px; min-width: 0; }
.field > label, .label { display: block; font-weight: 600; font-size: .88rem; margin-bottom: 5px; }
input, select, textarea {
  width: 100%; min-height: 42px; padding: 8px 12px; border: 2px solid var(--line); border-radius: 9px;
  background: #fff; color: var(--ink); font: 16px/1.35 var(--body);
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--ink); box-shadow: 0 0 0 3px rgba(220,28,58,.14); }
input[type="checkbox"], input[type="radio"] { width: 20px; height: 20px; min-height: 0; accent-color: var(--red); margin: 0; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 12px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; cursor: pointer; }
.choice { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 2px solid var(--line); border-radius: 10px; margin-bottom: 8px; cursor: pointer; }
.choice:has(input:checked) { border-color: var(--ink); background: var(--mist); }
.choice input { margin-top: 2px; }

/* ---------- App shell ---------- */
.topbar { position: sticky; top: 0; z-index: 30; background: var(--ink); color: #fff; border-bottom: 3px solid var(--red); }
.topbar-inner { max-width: 1060px; margin: 0 auto; height: 56px; padding: 0 16px; display: flex; align-items: center; gap: 22px; }
.brand { font: 700 1.25rem/1 var(--head); letter-spacing: .04em; text-decoration: none; color: #fff; }
.brand span { color: var(--red); }
.brand small { font: 600 .7rem/1 var(--head); letter-spacing: .18em; color: #a8a8b0; margin-left: 6px; }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a { position: relative; display: flex; align-items: center; gap: 6px; padding: 8px 12px; border-radius: 8px; text-decoration: none; color: #cfcfd5; font-weight: 600; }
.nav a:hover { color: #fff; background: rgba(255,255,255,.08); }
.nav a.active { color: #fff; background: rgba(255,255,255,.12); }
.nav .ico { font-size: 1.05rem; }
.badge-count { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--red); color: #fff; font: 700 .72rem/1 var(--body); }
.badge-count:empty { display: none; }
.main { max-width: 1060px; margin: 0 auto; padding: 20px 16px 40px; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 16px; }
.page-head h1 { margin: 0; }
.back { display: inline-block; margin-bottom: 8px; color: var(--muted); text-decoration: none; font-weight: 600; }
.back:hover { color: var(--ink); }

/* ---------- Cards & lists ---------- */
.card { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card > h2 { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 14px; }
.stat { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; text-decoration: none; display: block; }
.stat b { display: block; font: 700 1.6rem/1.1 var(--head); }
.stat span { color: var(--muted); font-size: .82rem; text-transform: uppercase; letter-spacing: .06em; font-weight: 600; }
a.stat:hover { border-color: var(--ink); }
.stat.hot b { color: var(--red); }
.cols { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; align-items: start; }
.list { list-style: none; margin: 0; padding: 0; }
.item { display: flex; align-items: center; gap: 12px; padding: 12px 0; border-top: 1px solid var(--line); }
.list > .item:first-child { border-top: 0; padding-top: 4px; }
.item-main { flex: 1; min-width: 0; text-decoration: none; }
.item-main strong { display: block; }
.item-main .sub { color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; }
.item-side { display: flex; gap: 6px; align-items: center; flex-shrink: 0; }
a.item-main:hover strong { color: var(--red-dark); }
.empty { color: var(--muted); padding: 10px 0; margin: 0; }
.when { font: 700 .95rem/1 var(--head); min-width: 64px; color: var(--ink-2); }
.group-head { margin: 18px 0 6px; font: 600 .8rem/1 var(--head); letter-spacing: .14em; text-transform: uppercase; color: var(--muted); }

/* pills */
.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font: 700 .72rem/1.4 var(--body); text-transform: uppercase; letter-spacing: .05em; background: var(--mist); color: var(--ink-2); }
.pill-booked { background: var(--blue-soft); color: var(--blue); }
.pill-done { background: var(--green-soft); color: var(--green); }
.pill-cancelled { background: #eee; color: #777; text-decoration: line-through; }
.pill-lead, .pill-new { background: var(--amber-soft); color: var(--amber); }
.pill-unpaid { background: var(--red-soft); color: var(--red-dark); }
.pill-paid { background: var(--green-soft); color: var(--green); }
.pill-converted { background: var(--green-soft); color: var(--green); }
.pill-dismissed { background: #eee; color: #777; }
.pill-dark { background: var(--ink); color: #fff; }

/* chips / filters */
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { padding: 7px 13px; border-radius: 999px; border: 2px solid var(--line); background: #fff; font-weight: 600; font-size: .88rem; text-decoration: none; cursor: pointer; }
.chip:hover { border-color: var(--ink); }
.chip.active { background: var(--ink); border-color: var(--ink); color: #fff; }
.search { flex: 1; min-width: 200px; }
.seg { display: inline-flex; border: 2px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg a { padding: 7px 14px; text-decoration: none; font-weight: 600; font-size: .88rem; }
.seg a.active { background: var(--ink); color: #fff; }

/* detail rows */
.kv { display: grid; grid-template-columns: 130px 1fr; gap: 6px 14px; margin: 0; }
.kv dt { color: var(--muted); font-weight: 600; font-size: .88rem; }
.kv dd { margin: 0; overflow-wrap: anywhere; }
.contact { display: flex; gap: 6px; flex-wrap: wrap; }

/* money table */
.lines { width: 100%; border-collapse: collapse; }
.lines th, .lines td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); vertical-align: top; }
.lines th { font-size: .78rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.lines .num { text-align: right; white-space: nowrap; }
.totals { margin-left: auto; width: min(320px, 100%); margin-top: 10px; }
.totals div { display: flex; justify-content: space-between; padding: 4px 6px; }
.totals .grand { border-top: 2px solid var(--ink); margin-top: 4px; padding-top: 8px; font: 700 1.25rem/1.2 var(--head); }

/* service editor */
.svc-row { display: grid; grid-template-columns: 26px 1fr 70px 100px 34px; gap: 8px; align-items: center; padding: 6px 0; border-bottom: 1px dashed var(--line); }
.svc-row input[type="number"] { padding: 6px 8px; min-height: 38px; }
.svc-row .nm { font-weight: 600; }
.svc-row .nm small { display: block; font-weight: 400; color: var(--muted); }
.svc-row.off .qty, .svc-row.off .price { opacity: .45; }
.adj-row { display: grid; grid-template-columns: 1fr 110px 34px; gap: 8px; align-items: center; padding: 6px 0; }
.mini-head { display: grid; grid-template-columns: 26px 1fr 70px 100px 34px; gap: 8px; font-size: .74rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 700; }
.x { width: 34px; height: 34px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; color: var(--muted); font-size: 1rem; }
.x:hover { color: var(--red-dark); border-color: var(--red); }

/* customer picker */
.picker { position: relative; }
.picker-results { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; margin-top: 4px; background: #fff; border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); max-height: 260px; overflow: auto; }
.picker-results button { display: block; width: 100%; text-align: left; padding: 10px 12px; border: 0; background: none; cursor: pointer; font: inherit; }
.picker-results button:hover, .picker-results button:focus { background: var(--mist); }
.picked { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 12px; border: 2px solid var(--ink); border-radius: 10px; background: var(--mist); }

/* calendar */
.cal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal .dow { text-align: center; font-size: .72rem; font-weight: 700; color: var(--muted); text-transform: uppercase; padding: 4px 0; }
.cal button { position: relative; aspect-ratio: 1 / .9; min-height: 44px; border: 1px solid var(--line); background: #fff; border-radius: 8px; cursor: pointer; font: 600 .9rem/1 var(--body); padding: 6px; text-align: left; display: flex; flex-direction: column; justify-content: space-between; }
.cal button.out { opacity: .35; }
.cal button.today { border: 2px solid var(--red); }
.cal button.sel { background: var(--ink); color: #fff; border-color: var(--ink); }
.cal .n { display: inline-grid; place-items: center; min-width: 20px; height: 20px; border-radius: 999px; background: var(--red); color: #fff; font-size: .72rem; align-self: flex-end; }

/* ---------- Modal, toast ---------- */
.modal { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 16px; background: rgba(18,18,20,.55); animation: fade .15s ease; }
.modal-box { width: min(520px, 100%); max-height: calc(100vh - 32px); overflow: auto; background: #fff; border-radius: 16px; padding: 20px; box-shadow: 0 24px 60px rgba(0,0,0,.3); }
.modal-box h2 { margin-bottom: 14px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
@keyframes fade { from { opacity: 0; } }
.toast { position: fixed; left: 50%; bottom: 24px; z-index: 80; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-weight: 600; box-shadow: 0 10px 30px rgba(0,0,0,.3); max-width: calc(100% - 32px); animation: rise .2s ease; }
.toast.bad { background: var(--red-dark); }
@keyframes rise { from { opacity: 0; transform: translate(-50%, 10px); } }
.loading { padding: 40px 0; text-align: center; color: var(--muted); }

/* ---------- Invoice ---------- */
.invoice { background: #fff; max-width: 800px; margin: 0 auto; padding: 40px; border: 1px solid var(--line); border-radius: 12px; }
.inv-top { display: flex; justify-content: space-between; gap: 20px; align-items: flex-start; border-bottom: 3px solid var(--red); padding-bottom: 18px; margin-bottom: 18px; }
.inv-top img { width: 210px; }
.inv-title { text-align: right; }
.inv-title h1 { font-size: 2rem; margin: 0; }
.inv-cols { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-bottom: 20px; }
.inv-label { font: 700 .74rem/1 var(--body); letter-spacing: .1em; text-transform: uppercase; color: var(--muted); margin-bottom: 6px; }
.stamp { display: inline-block; border: 3px solid currentColor; border-radius: 8px; padding: 6px 14px; font: 700 1.3rem/1 var(--head); letter-spacing: .1em; transform: rotate(-4deg); }
.stamp.paid { color: var(--green); }
.stamp.due { color: var(--red); }
.inv-foot { margin-top: 30px; padding-top: 14px; border-top: 1px solid var(--line); color: var(--muted); font-size: .9rem; text-align: center; }

/* ---------- Phone ---------- */
@media (max-width: 760px) {
  body { font-size: 15px; }
  .topbar-inner { height: 52px; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; margin: 0; gap: 0;
    display: grid; grid-template-columns: repeat(5, 1fr);
    background: var(--ink); border-top: 3px solid var(--red); padding: 4px 4px calc(4px + env(safe-area-inset-bottom));
  }
  .nav a { flex-direction: column; gap: 2px; padding: 6px 2px; font-size: .7rem; border-radius: 8px; }
  .nav .ico { font-size: 1.25rem; }
  .nav .badge-count { position: absolute; top: 2px; right: calc(50% - 22px); min-width: 18px; height: 18px; font-size: .66rem; }
  .main { padding: 16px 12px 96px; }
  h1 { font-size: 1.4rem; }
  .stats { grid-template-columns: 1fr 1fr; }
  .cols, .grid-2, .grid-3, .inv-cols { grid-template-columns: 1fr; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dd { margin-bottom: 8px; }
  .svc-row { grid-template-columns: 24px 1fr 56px 84px 30px; gap: 6px; }
  .mini-head { grid-template-columns: 24px 1fr 56px 84px 30px; gap: 6px; }
  .adj-row { grid-template-columns: 1fr 92px 30px; }
  .x { width: 30px; height: 30px; }
  .cal { gap: 3px; }
  .cal button { aspect-ratio: auto; min-height: 48px; min-width: 0; padding: 4px; font-size: .82rem; }
  .cal .n { min-width: 16px; height: 16px; font-size: .66rem; }
  .invoice { padding: 20px 16px; }
  .inv-top { flex-direction: column; }
  .inv-title { text-align: left; }
  .modal { place-items: end center; padding: 0; }
  .modal-box { border-radius: 16px 16px 0 0; max-height: 92vh; padding-bottom: calc(20px + env(safe-area-inset-bottom)); }
  .toast { bottom: 84px; }
  .item { flex-wrap: wrap; }
}

/* ---------- Print (invoices) ---------- */
@media print {
  @page { margin: 14mm; }
  body { background: #fff; }
  .topbar, .no-print, .toast { display: none !important; }
  .main { padding: 0; max-width: none; }
  .invoice { border: 0; padding: 0; max-width: none; }
  .stamp { transform: none; }
}
