:root {
  --bg: #f5f6fa; --card: #fff; --text: #181b26; --muted: #6b7185; --line: #e6e8f0;
  --accent: #5b5bf0; --accent-2: #8b5cf6; --accent-soft: #eeeeff; --danger: #e5484d;
  --shadow: 0 1px 2px rgba(20,24,40,.05), 0 8px 24px rgba(20,24,40,.06);
}
/* dark: follows the device unless the visitor chose a theme (html[data-theme]) */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #0d0f17; --card: #151824; --text: #eceef6; --muted: #8b91a8; --line: #232738; --accent-soft: #1f2140; --shadow: 0 8px 28px rgba(0,0,0,.4); color-scheme: dark; }
}
:root[data-theme="dark"] { --bg: #0d0f17; --card: #151824; --text: #eceef6; --muted: #8b91a8; --line: #232738; --accent-soft: #1f2140; --shadow: 0 8px 28px rgba(0,0,0,.4); color-scheme: dark; }
:root[data-theme="light"] { color-scheme: light; }
* { box-sizing: border-box; }
body { margin: 0; font: 15px/1.5 Inter, system-ui, -apple-system, "Segoe UI", sans-serif; background: var(--bg); color: var(--text); -webkit-font-smoothing: antialiased; }
.hidden { display: none !important; }
h1 { font-size: 24px; margin: 18px 0 4px; } h2 { font-size: 22px; margin: 0; } h3 { font-size: 15px; margin: 0 0 12px; }
a { color: var(--accent); text-decoration: none; } a:hover { text-decoration: underline; }
.muted { color: var(--muted); } .small { font-size: 13px; } .mono, code { font-family: ui-monospace, Consolas, monospace; }
code { background: var(--accent-soft); padding: 1px 6px; border-radius: 6px; font-size: 12px; }
.center { min-height: 100vh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(900px 500px at 15% -10%, rgba(91,91,240,.18), transparent), radial-gradient(700px 400px at 100% 100%, rgba(139,92,246,.14), transparent), var(--bg); }
.center-text { text-align: center; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 22px; box-shadow: var(--shadow); }
.auth-card { width: 100%; max-width: 400px; padding: 30px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -.01em; }
.logo { width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center; color: #fff; font-weight: 800; background: linear-gradient(135deg, var(--accent), var(--accent-2)); }

label, .lbl { display: block; font-size: 13px; font-weight: 600; margin: 14px 0 0; color: var(--text); }
input, textarea, select { width: 100%; margin-top: 6px; padding: 10px 12px; font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 10px; outline: none; transition: .15s; }
input:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(91,91,240,.18); background: var(--card); }
textarea { resize: vertical; }
.error { color: var(--danger); font-size: 13px; min-height: 18px; margin-top: 10px; }

.btn { border: 0; cursor: pointer; font: inherit; font-weight: 600; padding: 10px 16px; border-radius: 10px; transition: .15s; color: var(--text); background: var(--accent-soft); display: inline-block; }
.btn:hover { filter: brightness(.96); text-decoration: none; } .btn:disabled { opacity: .5; cursor: default; }
.btn.primary { color: #fff; background: linear-gradient(135deg, var(--accent), var(--accent-2)); box-shadow: 0 4px 14px rgba(91,91,240,.35); }
.btn.ghost { background: transparent; border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.small { padding: 6px 12px; font-size: 13px; } .btn.wide { width: 100%; margin-top: 8px; }
.icon { border: 0; background: transparent; color: var(--muted); font-size: 16px; cursor: pointer; padding: 6px 10px; border-radius: 8px; } .icon:hover { background: var(--accent-soft); }

.topbar { display: flex; align-items: center; gap: 24px; padding: 12px 28px; background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.topbar nav { display: flex; gap: 4px; flex: 1; }
.tab { border: 0; background: transparent; font: inherit; font-weight: 600; color: var(--muted); padding: 8px 14px; border-radius: 10px; cursor: pointer; }
.tab.active { color: var(--accent); background: var(--accent-soft); }
.user { display: flex; align-items: center; gap: 12px; font-size: 13px; }
.view { max-width: 1100px; margin: 0 auto; padding: 28px; }
.page-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 16px; margin-bottom: 18px; } .page-head p { margin: 4px 0 0; }
.toolbar { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-bottom: 16px; } .toolbar.tight { margin-bottom: 10px; }
.search { max-width: 320px; margin: 0; }

.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--card); color: var(--muted); font: inherit; font-size: 12.5px; font-weight: 600; padding: 4px 11px; border-radius: 999px; cursor: pointer; }
.chip.on { color: #fff; border-color: transparent; background: var(--c, var(--accent)); }
.tag { display: inline-block; font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.client { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 16px; cursor: pointer; transition: .15s; }
.client:hover { transform: translateY(-2px); box-shadow: var(--shadow); border-color: var(--accent); }
.client .top { display: flex; gap: 12px; align-items: center; }
.avatar { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; font-weight: 700; color: #fff; flex: none; background: var(--c, var(--accent)); }
.client .nm { font-weight: 650; } .client .sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.client .meta { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; font-size: 12.5px; color: var(--muted); }
.empty { grid-column: 1/-1; text-align: center; padding: 60px 20px; color: var(--muted); border: 2px dashed var(--line); border-radius: 16px; }

.email-layout { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; margin-bottom: 16px; }
.recipients { max-height: 340px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }
.recip { display: flex; gap: 10px; align-items: center; padding: 9px 12px; border-bottom: 1px solid var(--line); cursor: pointer; margin: 0; font-weight: 500; }
.recip:last-child { border-bottom: 0; } .recip:hover { background: var(--accent-soft); }
.recip input { width: auto; margin: 0; } .recip .e { color: var(--muted); font-size: 13px; margin-left: auto; }
.queue-head { display: flex; justify-content: space-between; align-items: center; }
.progress { height: 8px; background: var(--accent-soft); border-radius: 99px; overflow: hidden; margin: 6px 0 16px; }
#bar { height: 100%; width: 0; background: linear-gradient(90deg, var(--accent), var(--accent-2)); transition: width .3s; }
.queue-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin-bottom: 14px; }
.queue-list { max-height: 260px; overflow: auto; }
.q { display: flex; justify-content: space-between; padding: 7px 4px; border-bottom: 1px solid var(--line); font-size: 14px; }
.q.next { font-weight: 700; color: var(--accent); } .q.done { color: var(--muted); } .q.skipped { color: var(--muted); text-decoration: line-through; }

.scrim { position: fixed; inset: 0; background: rgba(10,12,20,.45); z-index: 20; backdrop-filter: blur(2px); }
.drawer { position: fixed; top: 0; right: 0; bottom: 0; width: min(480px, 100%); background: var(--card); z-index: 21; overflow: auto; box-shadow: -20px 0 50px rgba(0,0,0,.2); animation: slide .2s ease-out; }
@keyframes slide { from { transform: translateX(40px); opacity: 0; } }
.drawer-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); } .drawer-head h3 { margin: 0; font-size: 17px; }
.drawer-body { padding: 8px 22px 22px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; } .row.end { display: flex; justify-content: space-between; margin-top: 12px; }
.notes { border-top: 1px solid var(--line); padding-top: 18px; }
.note-add { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; margin-bottom: 14px; } .note-add textarea { margin: 0; }
.note { background: var(--bg); border-radius: 12px; padding: 11px 14px; margin-bottom: 10px; white-space: pre-wrap; word-break: break-word; }
.note .when { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); margin-top: 6px; white-space: normal; }
.note .when button { border: 0; background: none; color: var(--muted); cursor: pointer; font-size: 12px; } .note .when button:hover { color: var(--danger); }

.toast { position: fixed; bottom: 24px; left: 50%; transform: translate(-50%, 20px); background: var(--text); color: var(--bg); padding: 10px 18px; border-radius: 12px; font-weight: 600; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.dlg { border: 1px solid var(--line); border-radius: 16px; padding: 24px; width: min(420px, 92vw); background: var(--card); color: var(--text); box-shadow: var(--shadow); }
.dlg::backdrop { background: rgba(10,12,20,.5); backdrop-filter: blur(2px); } .dlg h3 { font-size: 17px; } .dlg .row.end { margin-top: 18px; }
.wide-dlg { width: min(480px, 94vw); } .check { display: flex; gap: 10px; align-items: flex-start; font-weight: 500; font-size: 13px; margin-top: 16px; } .check input { width: auto; margin-top: 3px; }
.hint { background: var(--accent-soft); border-radius: 10px; padding: 10px 12px; font-size: 13px; margin: 14px 0 0; }
.set-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; align-items: start; } hr { border: 0; border-top: 1px solid var(--line); margin: 20px 0; }
.set-grid .btn { margin-top: 14px; } @media (max-width: 760px) { .set-grid { grid-template-columns: 1fr; } }
.acct { margin-bottom: 16px; display: flex; justify-content: space-between; align-items: center; gap: 14px; flex-wrap: wrap; }
.acct .who { display: flex; align-items: center; gap: 12px; } .acct .dot { width: 10px; height: 10px; border-radius: 50%; background: #10b981; box-shadow: 0 0 0 4px rgba(16,185,129,.18); }
.acct .dot.off { background: var(--muted); box-shadow: none; } .acct p { margin: 2px 0 0; }
#view-admin .card { margin-bottom: 16px; }
.gen { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; } .gen label { margin: 0; } .gen input { width: 160px; }
.keys { background: var(--bg); border: 1px solid var(--line); border-radius: 10px; padding: 12px; font-family: ui-monospace, Consolas, monospace; user-select: all; margin: 14px 0 0; }
.tbl-wrap { overflow: auto; max-height: 380px; }
table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th { text-align: left; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--card); }
td { padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td .btn { margin-right: 4px; }
@media (max-width: 760px) {
  .email-layout { grid-template-columns: 1fr; } .topbar { padding: 10px 14px; gap: 10px; flex-wrap: wrap; } .user .muted { display: none; } .view { padding: 18px 14px; }
}
.links { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 10px; } .links a { background: var(--card); border: 1px solid var(--line); padding: 5px 11px; border-radius: 999px; font-weight: 600; font-size: 12.5px; }
.legal { max-width: 760px; margin: 0 auto; padding: 36px 20px 80px; } .legal h1 { font-size: 30px; margin: 18px 0 4px; } .legal h2 { font-size: 17px; margin: 28px 0 6px; } .legal p, .legal li { color: var(--text); opacity: .88; } .legal ul { padding-left: 20px; } .back { font-weight: 600; font-size: 14px; } .terms-check { margin-top: 16px; } .terms-check a { text-decoration: underline; }

/* ---- smoother transitions ---- */
:root { --ease: cubic-bezier(.22, .8, .3, 1); }
.view, #auth, #licence, #app { animation: viewIn .38s var(--ease) both; }
@keyframes viewIn { from { opacity: 0; transform: translateY(10px); } }
.scrim { animation: fadeIn .22s ease both; }
@keyframes fadeIn { from { opacity: 0; } }
.drawer { animation: slide .32s var(--ease) both; }
@keyframes slide { from { transform: translateX(48px); opacity: 0; } }
.drawer.closing { animation: slideOut .2s ease-in forwards; } .scrim.closing { animation: fadeOut .2s ease forwards; }
@keyframes slideOut { to { transform: translateX(48px); opacity: 0; } } @keyframes fadeOut { to { opacity: 0; } }
dialog.dlg[open] { animation: pop .28s var(--ease); } dialog.dlg[open]::backdrop { animation: fadeIn .25s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(.97); } }
.client, .btn, .chip, .tab, input, textarea, .recip { transition: transform .25s var(--ease), box-shadow .25s var(--ease), border-color .2s ease, background-color .2s ease, color .2s ease, filter .2s ease, opacity .2s ease; }
.client:hover { transform: translateY(-3px); } .btn:active { transform: scale(.97); }
.toast { transition: opacity .3s var(--ease), transform .35s var(--ease); }
#bar { transition: width .5s var(--ease); }
/* reduced motion: from the device setting, unless the visitor chose "play animations" (html.motion-on); or when they chose "pause" (html.motion-off) */
@media (prefers-reduced-motion: reduce) { html:not(.motion-on) *, html:not(.motion-on) *::before, html:not(.motion-on) *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; } }
html.motion-off *, html.motion-off *::before, html.motion-off *::after { animation-duration: .001ms !important; animation-iteration-count: 1 !important; transition-duration: .001ms !important; scroll-behavior: auto !important; }

.banner { background: #7f1d1d; color: #fff; text-align: center; padding: 10px 16px; font-size: 14px; font-weight: 600; } .banner a { color: #fff; text-decoration: underline; }

/* phones: the tab bar scrolls sideways instead of stretching the whole page */
.topbar nav { min-width: 0; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
.topbar nav::-webkit-scrollbar { display: none; }
.tab { white-space: nowrap; flex: none; }
@media (max-width: 760px) { .topbar nav { flex: 1 1 100%; order: 3; } }
body { overflow-x: clip; }
dialog.dlg, dialog.cdlg { max-width: calc(100vw - 24px); }

/* keyboard focus: always show where you are */
a:focus-visible, button:focus-visible, summary:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible, [tabindex]:focus-visible { outline: 2px solid #818cf8; outline-offset: 2px; }

/* bulk email: template picker and email preview */
.tplrow { display: flex; gap: 8px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; } .tplrow select { flex: 1; min-width: 160px; margin: 0; }
#mVars { margin: 4px 0 8px; }
.pvbody { display: block; width: 100%; min-height: 360px; max-height: 70vh; border: 1px solid var(--line); border-radius: 12px; background: #f2f4f8; }
#previewDialog { width: 680px; }

/* ---- phones (Android + iPhone): everything below is scoped to body.ap so the marketing pages don't change ---- */
body.ap { -webkit-text-size-adjust: 100%; }
body.ap button, body.ap a, body.ap label, body.ap select, body.ap input { touch-action: manipulation; }
body.ap input[type=search] { -webkit-appearance: none; appearance: none; }
@media (max-width: 760px) {
  body.ap { --muted: #5d6479; }
  :root[data-theme="dark"] body.ap { --muted: #8b91a8; }
  @media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) body.ap { --muted: #8b91a8; } }

  /* header: brand row on top, one scrolling tab row under it */
  body.ap .topbar { padding: 8px max(14px, env(safe-area-inset-right)) 0 max(14px, env(safe-area-inset-left)); gap: 0 10px; row-gap: 0; }
  body.ap .topbar .brand { min-height: 40px; }
  body.ap .topbar .user { display: none; }
  body.ap .topbar nav { margin: 0 calc(-1 * max(14px, env(safe-area-inset-right))) 0 calc(-1 * max(14px, env(safe-area-inset-left))); padding: 0 max(10px, env(safe-area-inset-right)) 0 max(10px, env(safe-area-inset-left)); gap: 2px; overscroll-behavior-x: contain; border-top: 1px solid var(--line); }
  body.ap .tab { min-height: 46px; padding: 0 14px; border-radius: 0; background: transparent; box-shadow: inset 0 -3px 0 transparent; }
  body.ap .tab.active { background: transparent; box-shadow: inset 0 -3px 0 var(--accent); }
  body.ap .view { padding: 16px max(14px, env(safe-area-inset-right)) calc(28px + env(safe-area-inset-bottom)) max(14px, env(safe-area-inset-left)); }
  body.ap .banner { padding-top: max(10px, env(safe-area-inset-top)); }

  /* inputs: 16px stops iPhone zooming in on focus */
  html body.ap input:not([type=checkbox]):not([type=radio]), html body.ap select, html body.ap textarea { font-size: 16px; }
  html body.ap input:not([type=checkbox]):not([type=radio]):not([type=hidden]), html body.ap select { min-height: 46px; }
  body.ap input[type=checkbox], body.ap input[type=radio] { width: 22px; height: 22px; flex: none; accent-color: var(--accent); }
  body.ap .check, body.ap .checkline { min-height: 44px; align-items: center; }
  body.ap .check input { margin-top: 0; }
  body.ap input[type=date], body.ap input[type=time] { -webkit-appearance: none; appearance: none; text-align: left; }

  /* buttons and other tap targets */
  body.ap .btn { min-height: 46px; padding: 11px 16px; display: inline-flex; align-items: center; justify-content: center; text-align: center; }
  body.ap .btn.small { min-height: 44px; padding: 10px 14px; }
  body.ap .btn.wide { margin-top: 10px; }
  body.ap .icon { min-width: 44px; min-height: 44px; font-size: 18px; }
  body.ap .chips { gap: 8px; }
  body.ap .chip { min-height: 44px; padding: 0 16px; font-size: 14px; }
  body.ap .linkbtn, body.ap .more { min-height: 44px; padding-inline: 8px; }
  body.ap a[data-pay]:not(.btn), body.ap .center-text a { display: inline-block; padding: 12px 6px; }
  body.ap .note .when button { min-height: 44px; padding-inline: 12px; }
  body.ap .recip { min-height: 52px; padding: 8px 12px; flex-wrap: wrap; row-gap: 0; }
  body.ap .recip .e { min-width: 0; overflow-wrap: anywhere; }
  body.ap .recipients { max-height: 300px; }

  /* sign in + licence */
  body.ap .center { min-height: 100vh; min-height: 100dvh; padding: max(20px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right)) max(20px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); }
  body.ap .auth-card { padding: 22px 18px; }

  /* page heads and toolbars */
  body.ap .page-head { flex-direction: column; align-items: stretch; gap: 12px; }
  body.ap .page-head > .btn { width: 100%; }
  body.ap .toolbar { gap: 10px; }
  body.ap .search { max-width: none; width: 100%; flex: 1 1 100%; }
  body.ap #labelFilter { flex: 1 1 100%; min-width: 0; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; margin: 0 -14px; padding: 0 14px; }
  body.ap #labelFilter::-webkit-scrollbar { display: none; }
  body.ap #labelFilter .chip { flex: none; }
  body.ap .grid { grid-template-columns: 1fr; }
  body.ap .client { padding: 14px 16px; }
  body.ap .client .meta span { min-width: 0; overflow-wrap: anywhere; }
  body.ap .client:hover, body.ap .jcard:hover, body.ap .ag-ev:hover { transform: none; }
  body.ap .row { grid-template-columns: 1fr; gap: 0; }
  body.ap .row.end { gap: 10px; }

  /* client drawer = full-screen sheet */
  body.ap .drawer { width: 100%; padding-bottom: env(safe-area-inset-bottom); }
  body.ap .drawer-head { padding: 8px max(12px, env(safe-area-inset-right)) 8px max(18px, env(safe-area-inset-left)); min-height: 56px; z-index: 2; }
  body.ap .drawer-body { padding: 8px max(18px, env(safe-area-inset-right)) 22px max(18px, env(safe-area-inset-left)); }
  body.ap #clientForm > .row.end { position: sticky; bottom: 0; z-index: 1; background: var(--card); margin: 16px -18px 0; padding: 12px 18px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--line); }
  body.ap #clientForm > .row.end .btn.primary { flex: 1; }
  body.ap .note-add .btn { width: 100%; }
  body.ap .locrow { flex-wrap: wrap; } body.ap .locrow input { flex: 1 1 100%; } body.ap .locrow .btn { width: 100%; }
  body.ap .geo-results .geo { min-height: 48px; padding: 12px; }

  /* dialogs = bottom sheets that fit the screen */
  body.ap dialog.dlg, body.ap dialog.cdlg { width: 100%; max-width: 100vw; margin: auto 0 0; border-radius: 18px 18px 0 0; border-bottom: 0; max-height: 92vh; max-height: 92dvh; padding: 20px max(16px, env(safe-area-inset-right)) calc(20px + env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left)); overscroll-behavior: contain; }
  body.ap dialog.docdlg, body.ap dialog.evdlg { padding: 0; }
  body.ap dialog.dlg .row.end { gap: 10px; }
  body.ap dialog.dlg .row.end .btn { flex: 1; }
  body.ap #previewDialog { width: 100%; }
  body.ap .pvbody { min-height: 280px; }
  body.ap .tplrow select { min-width: 0; flex: 1 1 100%; }
  body.ap .queue-actions .btn { flex: 1 1 auto; }

  body.ap .toast { bottom: calc(20px + env(safe-area-inset-bottom)); max-width: calc(100vw - 32px); text-align: center; }
  body.ap .notif-btns .btn { width: 100%; }
  body.ap .set-grid .btn { margin-top: 12px; }
  body.ap .set-grid .card { padding: 18px 16px; }
}
@media (hover: none) { body.ap .client:hover { transform: none; } }
