/* Nubury palette: Nubury Blue #2563EB, Charcoal #0F172A, Cloud #F1F5F9 */
:root {
  --bg: #f1f5f9;
  --surface: #ffffff;
  --surface-2: #e2e8f0;
  --ink: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --personal: #2563eb;        /* fills: buttons, icon tiles */
  --personal-text: #2563eb;   /* blue used as text or line colour */
  --on-personal: #ffffff;
  --business: #0f172a;
  --business-text: #0f172a;
  --on-business: #ffffff;
  --accent: var(--personal);
  --accent-text: var(--personal-text);
  --on-accent: var(--on-personal);
  --wa: #179848;
  --danger: #c2372b;
  --paper-shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 8px 24px rgba(15, 23, 42, .07);
  --radius: 16px;
  --tap: 48px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0f172a;
    --surface: #1e293b;
    --surface-2: #334155;
    --ink: #f1f5f9;
    --muted: #94a3b8;
    --line: #334155;
    --personal-text: #60a5fa;
    --business: #e2e8f0;
    --business-text: #e2e8f0;
    --on-business: #0f172a;
    --wa: #22a45a;
    --paper-shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0f172a;
  --surface: #1e293b;
  --surface-2: #334155;
  --ink: #f1f5f9;
  --muted: #94a3b8;
  --line: #334155;
  --personal-text: #60a5fa;
  --business: #e2e8f0;
  --business-text: #e2e8f0;
  --on-business: #0f172a;
  --wa: #22a45a;
  --paper-shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 8px 24px rgba(0, 0, 0, .35);
  color-scheme: dark;
}

:root { --mark: #2563eb; }
body[data-wing="business"] { --mark: #0f172a; }
body[data-wing="business"] { --accent: var(--business); --accent-text: var(--business-text); --on-accent: var(--on-business); }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  height: calc(56px + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) 16px 0;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid transparent;
}
.brand { display: block; line-height: 0; }
.brand img { height: 26px; width: auto; }
.wing-pill {
  margin-left: auto; padding: 4px 10px; border-radius: 999px;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent-text);
  font-size: 13px; font-weight: 650; text-transform: capitalize;
}
.icon-btn {
  width: 40px; height: 40px; margin-left: -8px; display: grid; place-items: center;
  border: 0; border-radius: 12px; background: transparent;
}
.icon-btn:active { background: var(--surface-2); }

/* ---------- screens ---------- */
main { max-width: 560px; margin: 0 auto; }
.screen { padding: 8px 16px calc(112px + env(safe-area-inset-bottom)); }
#screen-home, #screen-docs, #screen-done { padding-bottom: calc(32px + env(safe-area-inset-bottom)); }
h2 { font-size: 22px; letter-spacing: -.01em; margin: 12px 0 12px; }
h2.mt { margin-top: 32px; }
.hero { font-size: clamp(32px, 9.5vw, 44px); line-height: 1.06; letter-spacing: -.03em; font-weight: 800; margin: 20px 0 12px; }
.hero span { color: var(--personal-text); }
.lede { color: var(--muted); margin: 0 0 24px; }
.muted { color: var(--muted); }
.center { text-align: center; }
.hint { color: var(--muted); font-size: 14px; margin: 4px 0 12px; }

/* ---------- home cards ---------- */
.wing-card {
  width: 100%; display: flex; align-items: center; gap: 14px;
  padding: 18px 16px; margin-bottom: 12px; text-align: left;
  background: var(--surface); border: 1px solid var(--line); border-radius: 20px;
  box-shadow: var(--paper-shadow);
  transition: transform .12s ease;
}
.wing-card:active { transform: scale(.985); }
.wing-card .wing-icon {
  width: 52px; height: 52px; border-radius: 14px; display: grid; place-items: center; flex: none;
}
.wing-card.personal .wing-icon { background: var(--personal); color: var(--on-personal); }
.wing-card.business .wing-icon { background: var(--business); color: var(--on-business); }
.wing-card .wing-icon svg { width: 30px; height: 30px; }
.wing-text { display: flex; flex-direction: column; min-width: 0; flex: 1; }
.wing-text b { font-size: 18px; }
.wing-text small { color: var(--muted); font-size: 14px; }
.wing-status { font-style: normal; font-size: 13px; margin-top: 4px; font-weight: 600; }
.wing-card.personal .wing-status { color: var(--personal-text); }
.wing-card.business .wing-status { color: var(--business-text); }
.chev { color: var(--muted); }

/* brand essence: Simple · Fast · Trusted · Everywhere */
.essence {
  list-style: none; margin: 24px 0 0; padding: 0;
  display: grid; grid-template-columns: 1fr 1fr; gap: 18px 12px;
}
@media (min-width: 520px) { .essence { grid-template-columns: repeat(4, 1fr); } }
.essence li { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 2px; }
.essence-icon {
  width: 48px; height: 48px; border-radius: 50%; display: grid; place-items: center; margin-bottom: 6px;
  background: color-mix(in srgb, var(--personal) 9%, var(--surface)); color: var(--personal-text);
}
.essence b { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; }
.essence small { color: var(--muted); font-size: 13px; line-height: 1.35; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 18px; border-radius: 14px;
  background: var(--surface); border: 1px solid var(--line); font-weight: 650;
  transition: transform .1s ease, opacity .15s;
}
.btn:active { transform: scale(.98); }
.btn:disabled { opacity: .45; pointer-events: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.ghost { background: transparent; }
.btn.whatsapp { background: var(--wa); border-color: var(--wa); color: #fff; }
.btn.full { width: 100%; }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }
.link { border: 0; background: none; color: var(--accent-text); font-weight: 650; padding: 10px 4px; }
.center-block { display: block; margin: 20px auto 0; }

.big-btn {
  width: 100%; display: flex; align-items: center; gap: 16px;
  padding: 20px 18px; margin-bottom: 12px; text-align: left;
  background: var(--surface); border: 1.5px dashed color-mix(in srgb, var(--accent-text) 45%, var(--line));
  border-radius: 20px;
}
.big-btn:active { background: var(--surface-2); }
.big-btn svg { width: 28px; height: 28px; color: var(--accent-text); }
.big-btn span { display: flex; flex-direction: column; }
.big-btn small { color: var(--muted); font-size: 14px; }

/* ---------- segmented / chips ---------- */
.seg {
  display: flex; padding: 4px; gap: 4px; margin-bottom: 12px;
  background: var(--surface-2); border-radius: 14px;
}
.seg button {
  flex: 1; min-height: 40px; border: 0; border-radius: 10px; background: transparent;
  font-weight: 600; font-size: 15px; color: var(--muted);
}
.seg button[aria-selected="true"] { background: var(--surface); color: var(--ink); box-shadow: 0 1px 3px rgba(0,0,0,.12); }
.seg.compact button { font-size: 13px; min-height: 36px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips button {
  display: inline-flex; align-items: center; gap: 6px;
  min-height: 40px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--surface); font-size: 14px; font-weight: 600;
}
.chips button[aria-pressed="true"] { border-color: var(--accent-text); box-shadow: inset 0 0 0 1px var(--accent-text); color: var(--accent-text); }
.dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); display: inline-block; box-shadow: 0 0 0 1.5px color-mix(in srgb, var(--muted) 45%, transparent); }

/* ---------- form ---------- */
.field { display: block; margin: 14px 0; }
.label { display: block; font-size: 13px; font-weight: 650; color: var(--muted); margin-bottom: 6px; }
input, select {
  width: 100%; min-height: var(--tap); padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--line); background: var(--surface);
  font-size: 16px; /* 16px stops iOS zooming on focus */
}
input:focus, select:focus { outline: 2px solid color-mix(in srgb, var(--accent-text) 55%, transparent); outline-offset: 1px; }
.business-only { display: none; }
body[data-wing="business"] .business-only { display: block; }
body[data-wing="business"] .seg.business-only { display: flex; }

/* ---------- previews ---------- */
.preview {
  min-height: 120px; margin: 14px 0; padding: 16px; border-radius: var(--radius);
  display: grid; place-items: center; border: 1px solid var(--line);
}
.preview img, .preview canvas { max-width: 100%; max-height: 220px; display: block; }
.preview .empty { color: #8a8f99; font-size: 14px; text-align: center; }
.checker {
  background-color: #fff;
  background-image: conic-gradient(#f0eee9 25%, transparent 0 50%, #f0eee9 0 75%, transparent 0);
  background-size: 16px 16px;
}
.paper { background: #fff; }

/* ---------- draw pad ---------- */
.pad-wrap { position: relative; border-radius: var(--radius); background: #fff; border: 1px solid var(--line); margin-bottom: 10px; }
#pad { display: block; width: 100%; height: 200px; touch-action: none; border-radius: var(--radius); }
.pad-line { position: absolute; left: 24px; right: 24px; bottom: 48px; border-bottom: 1.5px dashed #c9c4b8; pointer-events: none; }
#padClear { position: absolute; top: 4px; right: 8px; }

/* ---------- docs screen ---------- */
.me-chip {
  width: 100%; display: flex; align-items: center; gap: 12px; padding: 10px; margin: 8px 0 8px;
  background: var(--surface); border: 1px solid var(--line); border-radius: 16px; text-align: left;
}
.me-img { width: 96px; height: 56px; border-radius: 10px; display: grid; place-items: center; overflow: hidden; flex: none; }
.me-img img { max-width: 90%; max-height: 90%; }
.me-text { display: flex; flex-direction: column; }
.me-text small { color: var(--muted); font-size: 13px; }

/* ---------- scan thumbs ---------- */
.thumbs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.thumb { position: relative; background: #fff; border-radius: 12px; box-shadow: var(--paper-shadow); overflow: hidden; }
.thumb canvas { display: block; width: 100%; height: auto; }
.thumb .no {
  position: absolute; left: 8px; top: 8px; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px;
  background: rgba(20,22,28,.75); color: #fff; font-size: 13px; font-weight: 700; display: grid; place-items: center;
}
.thumb .tools { position: absolute; right: 6px; bottom: 6px; display: flex; gap: 6px; }
.thumb .tools button {
  width: 36px; height: 36px; border-radius: 10px; border: 0; display: grid; place-items: center;
  background: rgba(20,22,28,.75); color: #fff;
}
.thumb .tools svg { width: 18px; height: 18px; }
.add-tile {
  min-height: 160px; border-radius: 12px; border: 1.5px dashed color-mix(in srgb, var(--accent-text) 45%, var(--line));
  background: transparent; color: var(--accent-text); font-weight: 650;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
}

/* ---------- sign screen ---------- */
.sign-hint { color: var(--muted); font-size: 14px; margin: 4px 0 10px; }
.pages { display: flex; flex-direction: column; gap: 34px; padding-bottom: 20px; }
.page { position: relative; background: #fff; box-shadow: var(--paper-shadow); border-radius: 4px; }
.page canvas { display: block; width: 100%; height: 100%; border-radius: 4px; }
.page .layer { position: absolute; inset: 0; }
.page .pno { position: absolute; right: 8px; bottom: -22px; font-size: 12px; color: var(--muted); }
.mark {
  position: absolute; touch-action: none; user-select: none; -webkit-user-select: none;
  outline: 1.5px dashed color-mix(in srgb, var(--mark) 70%, transparent); outline-offset: 2px;
}
.mark img { display: block; width: 100%; height: auto; pointer-events: none; mix-blend-mode: multiply; }
.mark .x, .mark .grip {
  position: absolute; width: 30px; height: 30px; border-radius: 50%;
  background: var(--mark); color: #fff; border: 2px solid #fff; display: grid; place-items: center;
  box-shadow: 0 2px 6px rgba(0,0,0,.25); padding: 0;
}
.mark .x { top: -17px; right: -17px; }
.mark .x svg { width: 14px; height: 14px; stroke-width: 3; }
.mark .grip { bottom: -17px; right: -17px; touch-action: none; }
.mark .grip svg { width: 14px; height: 14px; stroke-width: 2.6; }
.mark .x::before, .mark .grip::before { content: ""; position: absolute; inset: -8px; } /* bigger hit area */

/* ---------- action bar ---------- */
.actionbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 15;
  padding: 12px 16px calc(12px + env(safe-area-inset-bottom));
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-top: 1px solid var(--line);
}
.actionbar > * { max-width: 528px; }
.actionbar .btn.full { display: flex; margin: 0 auto; }
.actionbar.two { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.actionbar.two .btn { white-space: nowrap; padding: 0 12px; }
@media (min-width: 560px) {
  .actionbar.two { grid-template-columns: 210px 300px; justify-content: center; }
}

/* ---------- done ---------- */
.done-badge {
  width: 84px; height: 84px; margin: 36px auto 8px; border-radius: 50%;
  background: color-mix(in srgb, var(--accent) 14%, transparent); color: var(--accent-text);
  display: grid; place-items: center;
}
.done-badge svg { width: 44px; height: 44px; stroke-width: 2.6; }
#doneName { word-break: break-all; margin-top: -4px; margin-bottom: 2px; }
.small { font-size: 13px; margin-top: 0; }
.share-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 24px; }
.share-grid .full { grid-column: 1 / -1; }

/* ---------- busy + toast ---------- */
.busy {
  position: fixed; inset: 0; z-index: 50; display: grid; place-content: center; justify-items: center; gap: 14px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px);
}
.busy p { margin: 0; font-weight: 600; }
.spinner {
  width: 40px; height: 40px; border-radius: 50%;
  border: 4px solid color-mix(in srgb, var(--accent-text) 20%, transparent); border-top-color: var(--accent-text);
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.toast {
  position: fixed; left: 50%; bottom: calc(96px + env(safe-area-inset-bottom)); z-index: 60;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  width: max-content; max-width: calc(100vw - 32px); padding: 12px 16px; border-radius: 12px; text-align: center;
  background: #1c1f26; color: #fff; font-size: 14px; font-weight: 550; box-shadow: 0 8px 24px rgba(0,0,0,.25);
  transition: opacity .2s, transform .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; animation-duration: 0s !important; }
}
