/* Minimal black & white UI in the spirit of the ChatGPT web app, on a WhatsApp-style doodle wallpaper. */
:root {
  --fg: #0d0d0d;
  --muted: #5d5d5d;
  --line: rgb(0 0 0 / .1);
  --surface: #fff;
  --sidebar: #f9f9f9;
  --hover: #ececec;
  --wa: #efeae2; /* WhatsApp chat wallpaper color */
  --radius: 12px;
  --radish: #c9305c;
  --radish-dark: #a8244a;
  --out: #d9fdd3; /* outgoing message bubble */
  --shadow: 0 1px 2px rgb(0 0 0 / .05), 0 4px 14px rgb(0 0 0 / .05);
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0; min-height: 100vh; display: flex; flex-direction: column;
  font: 16px/1.5 ui-sans-serif, -apple-system, system-ui, "Segoe UI", Helvetica, "Apple Color Emoji", Arial, sans-serif;
  color: var(--fg); background: var(--wa);
}
/* Doodles: the SVG has a white backdrop, so multiply keeps only the black drawing, faintly, over the wallpaper color. */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: url(/doodle.svg) 0 0 / 700px auto repeat; opacity: .055; mix-blend-mode: multiply;
}
a { color: inherit; }
h1 { font-size: 1.5rem; font-weight: 600; margin: 0 0 1rem; }
h2 { font-size: 1.125rem; font-weight: 600; margin: 0 0 1rem; }
.muted { color: var(--muted); }
.small { font-size: .875rem; }
.error { font-weight: 600; }

/* OAuth consent / error: a single centered card */
main.consent { display: flex; align-items: center; justify-content: center; padding: 1.5rem 1rem 4rem; }
.card { width: 100%; max-width: 26rem; margin: 0 auto; padding: 1.75rem; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); }
.card h1 { font-size: 1.375rem; margin-bottom: .75rem; }
.card p { margin: 0 0 .75rem; }
.card .small { margin-bottom: 1.25rem; }
.card form.inline { justify-content: flex-end; margin: 0; }
.card form.inline button { padding: .55rem 1.25rem; font-size: .9375rem; }

/* buttons & inputs */
button, .button {
  display: inline-flex; align-items: center; justify-content: center; gap: .5rem;
  padding: .5rem 1rem; border: 1px solid transparent; border-radius: var(--radius);
  background: var(--fg); color: #fff; font: inherit; font-size: .875rem; font-weight: 500;
  text-decoration: none; cursor: pointer; white-space: nowrap;
}
button:hover, .button:hover { background: #2f2f2f; }
button.secondary, .button.google { background: var(--surface); color: var(--fg); border-color: var(--line); }
button.secondary:hover, .button.google:hover { background: var(--hover); }
button.danger { background: var(--radish); color: #fff; }
button.danger:hover { background: var(--radish-dark); }
.button.google { padding: .65rem 1.25rem; font-size: 1rem; font-weight: 500; gap: .6rem; }
input {
  flex: 1; min-width: 0; padding: .5rem .85rem; border: 1px solid var(--line); border-radius: var(--radius);
  background: var(--surface); color: var(--fg); font: inherit; font-size: .9375rem;
}
input:focus { outline: 2px solid var(--fg); outline-offset: -1px; }

/* landing page: a quiet WhatsApp-style conversation */
.bar { display: flex; align-items: center; padding: 1rem 1.5rem; }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 600; text-decoration: none; }
main { flex: 1; width: 100%; }
/* The page is one size container: every length below is in --u, one cqh (capped by cqw on narrow screens). */
main.chat { container-type: size; height: calc(100dvh - 6.5rem); flex: none; max-width: none; margin: 0; padding: 0;
  --u: min(1cqh, .6cqw); display: flex; flex-direction: column; align-items: center; justify-content: flex-start; gap: calc(1.2 * var(--u)); padding-top: calc(.8 * var(--u)); overflow: hidden; }
.day + .row { margin-top: auto; } .row:last-child { margin-bottom: auto; }
.day { padding: .1em .8em; border-radius: 8px; background: rgb(255 255 255 / .8); color: var(--muted); font-size: calc(2 * var(--u)); line-height: 1.3; box-shadow: 0 1px 1px rgb(0 0 0 / .05); }
.row { position: relative; display: flex; width: min(78 * var(--u), 92cqw); }
.row.in { justify-content: flex-start; }
.row.out { justify-content: flex-end; }
.msg { --bubble: var(--surface); position: relative; background: var(--bubble); border-radius: 0 calc(1.4 * var(--u)) calc(1.4 * var(--u)) calc(1.4 * var(--u)); box-shadow: 0 1px 1px rgb(0 0 0 / .13);
  font-size: calc(2.6 * var(--u)); line-height: 1.3; padding-bottom: calc(1.2 * var(--u)); }
.msg::before { content: ""; position: absolute; top: 0; left: -8px; border: 4px solid transparent; border-top-color: var(--bubble); border-right-color: var(--bubble); }
.row.out .msg { --bubble: var(--out); background: var(--bubble); border-radius: calc(1.4 * var(--u)) 0 calc(1.4 * var(--u)) calc(1.4 * var(--u)); }
.row.out .msg::before { left: auto; right: -8px; border-top-color: var(--out); border-right-color: transparent; border-left-color: var(--out); }
.w-ai { width: calc(56 * var(--u)); } .w-phone { width: calc(52 * var(--u)); } .w-go { width: calc(48 * var(--u)); }
.msg > p, .msg > h1, .msg > .button { margin: 0; padding: calc(1 * var(--u)) calc(1.6 * var(--u)) 0; }
.msg b { font-weight: 600; }
.msg .pic { display: block; width: 100%; height: auto; border: calc(.4 * var(--u)) solid var(--bubble); border-bottom: 0; background-clip: padding-box; border-radius: calc(1.4 * var(--u)) calc(1.4 * var(--u)) 0 0; }
.row.in .pic { border-top-left-radius: 0; }
.row.out .pic { border-top-right-radius: 0; }
.msg .pic.ai { display: flex; justify-content: space-around; align-items: center; background: #f7f8f8; padding: calc(1 * var(--u)) 0; box-sizing: border-box; }
.msg .pic.ai img { width: calc(6 * var(--u)); height: calc(6 * var(--u)); }
.msg p.big { font-size: calc(3.1 * var(--u)); font-weight: 500; }
.msg .button { display: flex; width: fit-content; margin: calc(1 * var(--u)) auto 0; padding: calc(1 * var(--u)) calc(2 * var(--u)); font-size: calc(2.4 * var(--u)); }
.msg .button svg { width: calc(2.6 * var(--u)); height: calc(2.6 * var(--u)); }
.msg .meta { display: block; text-align: right; margin: calc(.5 * var(--u)) calc(1.2 * var(--u)) 0 0; font-size: calc(1.6 * var(--u)); color: var(--muted); line-height: 1; }
.msg .meta.ticks::after { content: " ✓✓"; color: #53bdeb; }
/* hero: the largest card */
.msg.hero { width: calc(70 * var(--u)); display: flex; flex-direction: row; align-items: center; gap: calc(2.5 * var(--u)); text-align: start; padding: calc(2.2 * var(--u)) calc(2.5 * var(--u)) calc(3 * var(--u)); }
.msg.hero .pic.logo { flex: none; border: 0; width: calc(13 * var(--u)); height: calc(13 * var(--u)); border-radius: calc(2.6 * var(--u)); }
.msg.hero h1 { font-size: calc(4.4 * var(--u)); line-height: 1.15; padding: 0; }
.msg.hero p { font-size: calc(3 * var(--u)); padding: calc(.9 * var(--u)) 0 0; color: var(--muted); }
.msg.hero .meta { position: absolute; right: calc(1.2 * var(--u)); bottom: calc(.8 * var(--u)); margin: 0; }

/* typing indicator + reveal animation (only when home.js is running) */
.typing { display: none; padding: calc(1.6 * var(--u)) calc(2 * var(--u)); background: var(--surface); border-radius: 0 calc(1.4 * var(--u)) calc(1.4 * var(--u)) calc(1.4 * var(--u)); box-shadow: 0 1px 1px rgb(0 0 0 / .13); gap: calc(.7 * var(--u)); }
.row.out .typing { background: var(--out); border-radius: calc(1.4 * var(--u)) 0 calc(1.4 * var(--u)) calc(1.4 * var(--u)); }
.typing i { width: calc(1.2 * var(--u)); height: calc(1.2 * var(--u)); border-radius: 50%; background: #8696a0; animation: blink 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .2s; } .typing i:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 60%, 100% { opacity: .3; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }
@keyframes pop { from { opacity: 0; transform: translateY(18px) scale(.94); } to { opacity: 1; transform: none; } }
/* rows keep their space (visibility), so showing a message never moves the earlier ones */
.js .row .msg { visibility: hidden; }
.js .row.shown .msg { visibility: visible; animation: pop .9s cubic-bezier(.22,1,.36,1); }
.js .row .typing { position: absolute; top: 0; left: 0; }
.js .row.out .typing { left: auto; right: 0; }
.js .row.typing-now .typing { display: flex; }
@media (prefers-reduced-motion: reduce) { .js .row.shown .msg { animation: none; } }
footer { height: 6.5rem; padding: .75rem 1.5rem; display: flex; flex-direction: column; gap: .4rem; justify-content: center; color: var(--muted); font-size: .875rem; }
footer .brand { color: var(--fg); }
footer nav { display: grid; grid-template-columns: 8rem 8rem; gap: .1rem 0; }
footer nav a { text-decoration: none; }
footer nav a:hover { color: var(--fg); text-decoration: underline; }
/* grid fills row by row: privacy/about, terms/pricing */

/* text pages */
main.doc { padding: 1.5rem 1rem 3rem; }
main.doc article { max-width: 44rem; margin: 0 auto; padding: 1.75rem 2rem; background: var(--surface); border-radius: 16px; box-shadow: var(--shadow); }
main.doc h2 { margin: 1.75rem 0 .5rem; }
main.doc p, main.doc li { margin: 0 0 .75rem; }
main.doc ul, main.doc ol { padding-left: 1.4rem; margin: 0 0 .75rem; }
main.doc table { border-collapse: collapse; margin: 0 0 1rem; }
main.doc th, main.doc td { text-align: left; padding: .4rem 1.5rem .4rem 0; border-bottom: 1px solid var(--line); }

/* dashboard shell: menu on the left, content on the right */
.shell { display: flex; min-height: 100vh; width: 100%; }
.sidebar {
  position: sticky; top: 0; height: 100vh; width: 16rem; flex: none; display: flex; flex-direction: column;
  padding: .75rem; background: var(--sidebar); border-right: 1px solid var(--line);
}
.sidebar .brand { padding: .5rem .75rem; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; margin: 1rem 0; flex: 1; }
.sidebar nav a {
  display: flex; align-items: center; gap: .75rem; padding: .5rem .75rem; border-radius: 10px;
  font-size: .9375rem; text-decoration: none;
}
.sidebar nav a:hover, .sidebar nav a.active { background: var(--hover); }
.sidebar nav a.active { font-weight: 600; }
.sidebar nav img { flex: none; }
.content { flex: 1; min-width: 0; display: flex; padding: 2rem 2rem; }
.tab {
  width: 100%; align-self: flex-start; padding: 1.5rem 1.75rem;
  background: rgb(255 255 255 / .82); border: 1px solid rgb(0 0 0 / .06); border-radius: 16px;
  box-shadow: var(--shadow); backdrop-filter: blur(6px);
}

/* devices */
.group { padding: 1.25rem 0; border-top: 1px solid var(--line); }
.group:first-of-type { border-top: 0; padding-top: 0; }
.group h2 { margin: 0 0 .6rem; }
.group p { margin: 0; }
.devices { list-style: none; margin: 0; padding: 0; width: fit-content; max-width: 100%; border-radius: var(--radius); overflow: hidden; }
.device {
  display: grid; grid-template-columns: 9.5rem 14rem auto; align-items: center; gap: .75rem;
  padding: .2rem .5rem .2rem .75rem; font-size: .9375rem;
}
.device.app { grid-template-columns: 14rem auto; }
.device .phone { color: var(--muted); font-variant-numeric: tabular-nums; }
.device .rename { margin: 0; }
.device .rename input {
  width: 100%; padding: .2rem .5rem; border-color: transparent; background: transparent; font-weight: 600; cursor: text;
}
.device .rename input:hover { border-color: var(--line); }
.device .rename input:focus { background: var(--surface); border-color: var(--line); outline: 2px solid var(--fg); outline-offset: -1px; }
.device button { padding: .25rem .7rem; font-size: .8125rem; }
.actions { display: flex; align-items: center; justify-content: flex-end; gap: .4rem; }
.actions form { margin: 0; }
form.inline { display: flex; gap: .5rem; }
form.inline.add { max-width: 28rem; }

/* contacts */
.contacts { width: 100%; max-width: 52rem; }
.contact {
  display: grid; grid-template-columns: 1fr 1fr 11rem 6.5rem auto; align-items: center; gap: .5rem;
  padding: .2rem .5rem .2rem .5rem; font-size: .9375rem;
}
.contact input, .contact select { width: 100%; padding: .2rem .5rem; border-color: transparent; background: transparent; }
.contact input:first-child { font-weight: 600; }
.contact .phone { color: var(--muted); font-variant-numeric: tabular-nums; }
.contact input:hover, .contact select:hover { border-color: var(--line); }
.contact input:focus, .contact select:focus { background: var(--surface); border-color: var(--line); outline: 2px solid var(--fg); outline-offset: -1px; }
.contact button { padding: .25rem .7rem; font-size: .8125rem; }
form.inline.add.wide { max-width: 52rem; }
#contact-status { margin-top: .5rem; min-height: 1.2em; }
@media (max-width: 640px) { .contact { grid-template-columns: 1fr 1fr; } }

/* alternating row backgrounds for every list */
.devices > li:nth-child(even), .zebra > :nth-child(even) { background: rgb(0 0 0 / .045); }

/* pairing dialog */
dialog { border: 1px solid var(--line); border-radius: 16px; padding: 1.5rem; max-width: 22rem; width: 90%; text-align: center; box-shadow: 0 10px 40px rgb(0 0 0 / .2); }
dialog .row { display: flex; justify-content: center; gap: .5rem; margin-top: 1rem; }
dialog::backdrop { background: rgb(0 0 0 / .4); }
.qr { min-height: 14rem; display: grid; place-items: center; }
.qr svg { width: 100%; height: auto; }

@media (max-width: 720px) {
  .shell { flex-direction: column; }
  .sidebar { position: static; height: auto; width: auto; flex-direction: row; align-items: center; gap: .5rem; overflow-x: auto; border-right: 0; border-bottom: 1px solid var(--line); }
  .sidebar { scrollbar-width: none; }
  .sidebar nav { flex-direction: row; margin: 0; flex: none; }
  .sidebar form { margin-left: auto; }
  .content { padding: 1rem; }
  .devices { width: 100%; }
  .device { grid-template-columns: 1fr auto; }
  .device .phone { grid-column: 1 / -1; }
  .tab { padding: 1.25rem; }
}

/* Settings */
div.inline.copy input { font-family: ui-monospace, monospace; font-size: .8125rem; }
div.inline.copy { max-width: 48rem; }
div.inline { display: flex; gap: .5rem; align-items: center; }
div.inline form { margin: 0; }
select { padding: .55rem .75rem; border: 1px solid var(--line); border-radius: var(--radius); background: var(--surface); font: inherit; max-width: 100%; }
#tz-form { align-items: center; }
.group ol { margin: 0 0 .5rem; padding-left: 1.25rem; }

/* Usage tab */
.usage { margin-bottom: 1rem; }
.usage-head { display: flex; justify-content: space-between; margin-bottom: .3rem; text-transform: capitalize; }
.bar { height: 8px; border-radius: 4px; background: var(--hover); overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--radish); }

/* templates: WhatsApp-style previews (Helvetica Neue / Segoe UI stack, light theme colors) */
.tpl-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(18rem, 1fr)); gap: 1.25rem; }
.tpl { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); overflow: hidden; display: flex; flex-direction: column; }
.tpl-head { display: flex; flex-direction: column; align-items: stretch; gap: .4rem; padding: .5rem .75rem; }
.tpl-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tpl-head .actions { flex-wrap: wrap; justify-content: flex-start; }
.tpl-head button { padding: .2rem .6rem; font-size: .8125rem; }
.tpl-foot { padding: .5rem .75rem; }
.tpl-foot .actions { justify-content: flex-start; }
.tpl-foot button { padding: .2rem .6rem; font-size: .8125rem; }
.tpl .tpl-form { padding: .75rem; }
.tpl-form { display: flex; flex-direction: column; gap: .5rem; max-width: 36rem; }
.tpl-new { display: flex; gap: 1.5rem; align-items: flex-start; flex-wrap: wrap; width: 100%; }
.tpl-new .tpl-form { flex: 2 1 22rem; max-width: none; }
.cheat { flex: 1 1 18rem; padding: .75rem 1rem; border: 1px solid var(--line); border-radius: 8px; font-size: .875rem; }
.cheat h3 { margin: 0 0 .5rem; font-size: .9375rem; }
.cheat dl { margin: 0; display: grid; grid-template-columns: auto 1fr; gap: .25rem .75rem; }
.cheat dt, .cheat dd { margin: 0; }
.cheat p { margin: .75rem 0 0; }
.cheat code { color: #027eb5; }
.tpl-form textarea { font: inherit; padding: .5rem .75rem; border: 1px solid var(--line); border-radius: 8px; resize: vertical; }
.wa-chat {
  flex: 1; padding: .75rem .75rem 1rem; background: var(--wa); display: flex; align-items: flex-start; justify-content: flex-end;
}
.wa-bubble {
  position: relative; max-width: 92%; padding: 6px 7px 8px 9px; background: var(--out); color: #111b21;
  border-radius: 7.5px 0 7.5px 7.5px; box-shadow: 0 1px .5px rgb(11 20 26 / .13);
  font: 14.2px/19px "Segoe UI", "Helvetica Neue", Helvetica, "Lucida Grande", Arial, Ubuntu, Cantarell, "Fira Sans", sans-serif;
}
.wa-bubble::after { content: ""; position: absolute; top: 0; right: -8px; border: 4px solid transparent; border-top-color: var(--out); border-left-color: var(--out); }
.wa-text { white-space: pre-wrap; overflow-wrap: anywhere; display: inline; }
.wa-text .ph { color: #027eb5; }
.wa-meta { float: right; margin: 6px 0 -5px 12px; display: inline-flex; align-items: center; gap: 3px; font-size: 11px; line-height: 15px; color: #667781; }
.wa-ticks { display: inline-flex; }

/* credits */
.dot { display: inline-block; width: .5rem; height: .5rem; margin-left: auto; border-radius: 50%; background: var(--radish); }
.balance { margin: 0 0 .25rem; font-size: 2rem; font-weight: 600; font-variant-numeric: tabular-nums; }
.balance.low { color: var(--radish); }
.packs { display: flex; flex-wrap: wrap; gap: .5rem; margin: .75rem 0; }
.packs form { margin: 0; }
.history { margin-top: .75rem; }

.wa-img { display: block; max-width: 100%; max-height: 14rem; border-radius: 6px; margin-bottom: .25rem; }

/* scheduling: title on top, everything else on one line below, aligned to the bottom */
/* the list owns the columns and every row uses them (subgrid), so the fields line up across rows */
.schedules { width: 100%; max-width: 52rem; display: grid; grid-template-columns: minmax(0, 1fr) auto auto auto; column-gap: 1rem; }
.schedule { display: grid; grid-column: 1 / -1; grid-template-columns: subgrid; align-items: end; row-gap: .35rem; padding: .6rem .9rem; }
.schedule .title { grid-column: 1 / -1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.schedule .what { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.schedule .actions { align-self: end; }
.badge { padding: .15rem .55rem; border-radius: 999px; font-size: .75rem; white-space: nowrap; background: rgb(0 0 0 / .06); }
.badge.next { background: #e6f4ea; color: #1e6b34; }
.badge.paused { background: #fff3d6; color: #8a5a00; }
@media (max-width: 40rem) { .schedules { grid-template-columns: minmax(0, 1fr) auto; } .schedule .when { grid-column: 1 / -1; } }
