/* ===========================================================
   Jusa — ON THE DAY · the embeddable widget

   This file has NO :root palette. The widget is embedded on
   third-party pages, so every colour is written as
   var(--token, #fallback): it inherits the host page's tokens
   when static/airtime.css is present, and self-hosts when it
   is not. Do not add a :root block here — that is how three
   drifting palettes happened last time.

   Class names are preserved exactly as templates/buy/_widget.html
   and static/widget.js emit them. They are restyled, not renamed.
   The Now | Later toggle (.when-toggle / .when-btn) is the
   system's segmented control and is an alias of .seg / .seg-btn.
   =========================================================== */

@import url('https://fonts.googleapis.com/css2?family=Fraunces:ital,opsz,wght,SOFT,WONK@0,9..144,300..700,0..60,0..1;1,9..144,400..600,0..60,0..1&family=IBM+Plex+Mono:ital,wght@0,400;0,500;0,600;1,400&family=Instrument+Sans:ital,wght@0,400..700;1,400..700&display=swap');

*, *::before, *::after { box-sizing: border-box; }

body {
  margin: 0;
  font-family: var(--f-body, "Instrument Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", system-ui, sans-serif);
  font-size: 1.0625rem;
  background: var(--ground, #F2F3F0);
  color: var(--ink, #171C1A);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

code, pre, kbd, samp {
  font-family: var(--f-num, "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace);
  font-variant-numeric: tabular-nums;
}
code {
  font-size: 0.86em;
  background: var(--ground-2, #E8EAE5);
  padding: 0.1rem 0.32rem;
  border-radius: 5px;
}

/* One focus treatment, matching airtime.css. Never outline: none. */
:focus-visible {
  outline: 2px solid var(--accent, #B4431F);
  outline-offset: 2px;
  border-radius: 2px;
}

/* ---- Test-mode notice -------------------------------------- */
.widget-test {
  font-family: var(--f-num, "IBM Plex Mono", ui-monospace, Menlo, monospace);
  font-size: 0.6875rem; line-height: 1.5;
  font-weight: 600; letter-spacing: .14em; text-transform: uppercase;
  color: var(--warning, #8A5F0F);
  background: var(--warning-soft, rgba(178, 122, 21, 0.13));
  border: 0; border-left: 3px solid var(--warning-fill, #B27A15);
  padding: 0.6rem 0.75rem;
  border-radius: 0 var(--r-ctl, 9px) var(--r-ctl, 9px) 0;
  margin-bottom: 1rem;
}

/* ---- Category tabs — a 2px accent underline. Not pill-shaped. */
.cat-tabs {
  display: flex; gap: 1.5rem;
  margin: 0 0 1.25rem; padding: 0;
  background: none; border: 0;
  border-bottom: 1px solid var(--line, #E0E2DC);
}
.cat-tab {
  display: inline-flex; align-items: center; gap: 0.4rem;
  padding: 0 0 10px; min-height: 44px;
  border: 0; border-bottom: 2px solid transparent; margin-bottom: -1px;
  background: transparent;
  color: var(--muted, #66716C);
  font-family: inherit; font-size: 0.875rem; font-weight: 500; line-height: 1.2;
  cursor: pointer;
  transition: color 160ms cubic-bezier(.2,.7,.3,1), border-color 160ms cubic-bezier(.2,.7,.3,1);
}
.cat-tab:hover { color: var(--ink, #171C1A); }
.cat-tab[data-active="1"] {
  background: none; box-shadow: none; font-weight: 600;
  color: var(--ink, #171C1A);
  border-bottom-color: var(--accent, #B4431F);
}
.cat-emoji { font-size: 1rem; line-height: 1; }
.cat-label { font-size: 0.875rem; }

/* ---- Currency toggle --------------------------------------- */
.ccy-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: 1rem; margin-bottom: 1rem;
}
.ccy-label, .field-label {
  font-family: var(--f-num, "IBM Plex Mono", ui-monospace, Menlo, monospace);
  font-size: 0.6875rem; line-height: 1;
  font-weight: 600; letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted, #66716C);
}
.field-label { display: block; margin: 0.9rem 0 0.4rem; }
.ccy-toggle {
  display: inline-flex; gap: 4px; padding: 4px;
  background: var(--ground-2, #E8EAE5);
  border-radius: var(--r-ctl, 9px);
}
.ccy-btn {
  padding: 0 0.85rem; min-height: 34px;
  border: 0; background: transparent;
  color: var(--muted, #66716C);
  font-family: inherit; font-size: 0.875rem; font-weight: 500;
  border-radius: 6px; cursor: pointer;
  transition: background 160ms cubic-bezier(.2,.7,.3,1), color 160ms cubic-bezier(.2,.7,.3,1);
}
.ccy-btn:hover { color: var(--ink, #171C1A); }
.ccy-btn[data-active="1"] {
  background: var(--surface, #FFFFFF);
  color: var(--ink, #171C1A);
  font-weight: 600;
  box-shadow: var(--shadow-lift, 0 1px 2px -1px rgba(23,28,26,.10), 0 10px 24px -14px rgba(23,28,26,.20));
}

/* ---- Inputs ------------------------------------------------ */
input.text, select.text, textarea.text {
  width: 100%; height: 44px; padding: 0 12px;
  background: var(--surface, #FFFFFF);
  color: var(--ink, #171C1A);
  border: 1px solid var(--line-strong, #C6CAC1);
  border-radius: var(--r-ctl, 9px);
  font-family: inherit; font-size: 1.0625rem; font-weight: 400; line-height: 1.2;
  transition: border-color 160ms cubic-bezier(.2,.7,.3,1);
}
textarea.text { height: auto; padding: 10px 12px; line-height: 1.5; }
input.text:focus, select.text:focus, textarea.text:focus {
  outline: 2px solid var(--accent, #B4431F);
  outline-offset: 2px;
  border-color: var(--accent, #B4431F);
  box-shadow: none;
}
input.text::placeholder { color: var(--muted, #66716C); }
/* Every phone, meter and amount input is a numeral field. */
input.text[type="tel"], input.text[type="number"],
input.text[inputmode="numeric"], input.text[inputmode="tel"],
input.text[inputmode="decimal"], input.text.is-num,
input[type="date"].text, input[type="time"].text,
input[type="datetime-local"].text {
  font-family: var(--f-num, "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1, 'zero' 1;
}

.input-wrap { position: relative; }
.detect-pill {
  position: absolute; right: 0.5rem; top: 50%; transform: translateY(-50%);
  background: var(--accent-soft, rgba(180, 67, 31, 0.09));
  color: var(--accent, #B4431F);
  font-family: var(--f-num, "IBM Plex Mono", ui-monospace, Menlo, monospace);
  font-size: 0.6875rem; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase;
  padding: 6px 12px; border-radius: var(--r-round, 999px);
  pointer-events: none;
}
.product-meta {
  font-size: 0.8125rem; line-height: 1.45;
  color: var(--muted, #66716C);
  margin-top: 0.4rem;
}

/* ---- Pills — a choice, not a state. Never a filled accent
        block, which would read as a button. ------------------- */
.pill {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 44px; padding: 0 0.6rem;
  border: 1px solid var(--line-strong, #C6CAC1);
  border-radius: var(--r-ctl, 9px);
  background: var(--surface, #FFFFFF);
  color: var(--ink, #171C1A);
  font-family: inherit; font-size: 0.875rem; font-weight: 500;
  letter-spacing: 0; text-transform: none;
  cursor: pointer;
  transition: border-color 160ms cubic-bezier(.2,.7,.3,1),
              background 160ms cubic-bezier(.2,.7,.3,1),
              color 160ms cubic-bezier(.2,.7,.3,1);
}
.pill:hover { border-color: var(--accent, #B4431F); transform: none; }
.pill[data-active="1"] {
  background: var(--accent-soft, rgba(180, 67, 31, 0.09));
  border-color: var(--accent, #B4431F);
  color: var(--accent, #B4431F);
  font-weight: 600; box-shadow: none;
}

.net-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 0.45rem; margin-bottom: 0.5rem; }
@media (max-width: 380px) { .net-grid { grid-template-columns: repeat(2, 1fr); } }

/* Amount tiles — every figure is mono tabular. */
.amount-grid {
  display: grid; grid-template-columns: repeat(5, 1fr);
  gap: 0.45rem; margin-bottom: 0.6rem;
}
.amount-grid .pill {
  font-family: var(--f-num, "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace);
  font-size: 0.9375rem; font-weight: 500;
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1, 'zero' 1;
  letter-spacing: -.005em;
  padding: 0 0.35rem;
}
.amount-grid .pill[data-amount="custom"] {
  font-family: inherit; font-size: 0.8125rem; font-weight: 500; letter-spacing: 0;
}
@media (max-width: 480px) {
  .amount-grid { gap: 0.35rem; }
  .amount-grid .pill { font-size: 0.875rem; padding: 0 0.2rem; }
}
@media (max-width: 360px) { .amount-grid { grid-template-columns: repeat(3, 1fr); } }

/* ---- "When should it go out?" — the segmented control.
        Full width. This is the only .seg in the system. ------- */
.when-toggle, .seg {
  display: grid; grid-auto-flow: column; grid-auto-columns: 1fr;
  width: 100%; gap: 4px; padding: 4px;
  background: var(--ground-2, #E8EAE5);
  border-radius: var(--r-ctl, 9px);
  margin-bottom: 0.55rem;
}
.when-btn, .seg-btn {
  min-height: 40px; padding: 0 14px;
  border: 0; background: transparent;
  color: var(--muted, #66716C);
  font-family: inherit; font-size: 0.875rem; font-weight: 500;
  border-radius: 6px; cursor: pointer;
  transition: background 160ms cubic-bezier(.2,.7,.3,1), color 160ms cubic-bezier(.2,.7,.3,1);
}
.when-btn:hover, .seg-btn:hover { color: var(--ink, #171C1A); }
.when-btn[data-active="1"], .seg-btn[data-active="1"] {
  background: var(--surface, #FFFFFF);
  color: var(--ink, #171C1A);
  font-weight: 600;
  box-shadow: var(--shadow-lift, 0 1px 2px -1px rgba(23,28,26,.10), 0 10px 24px -14px rgba(23,28,26,.20));
}
.when-input { margin-top: 0.25rem; }

/* ---- The day picker ---------------------------------------- */
.when-picker { margin-top: 0.5rem; }
.when-presets {
  display: grid; grid-template-columns: repeat(2, 1fr);
  gap: 0.45rem; margin-bottom: 0.55rem;
}
@media (max-width: 380px) { .when-presets { grid-template-columns: 1fr; } }
.when-preset {
  min-height: 44px; padding: 0.55rem 0.75rem;
  background: var(--surface, #FFFFFF);
  color: var(--ink, #171C1A);
  border: 1px solid var(--line-strong, #C6CAC1);
  border-radius: var(--r-ctl, 9px);
  font-family: inherit; font-size: 0.875rem; font-weight: 500;
  text-align: left; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
  transition: border-color 160ms cubic-bezier(.2,.7,.3,1),
              background 160ms cubic-bezier(.2,.7,.3,1),
              color 160ms cubic-bezier(.2,.7,.3,1);
}
.when-preset:hover { border-color: var(--accent, #B4431F); color: var(--accent, #B4431F); }
.when-preset[data-active="1"] {
  background: var(--accent-soft, rgba(180, 67, 31, 0.09));
  border-color: var(--accent, #B4431F);
  color: var(--accent, #B4431F);
  font-weight: 600; box-shadow: none;
}
.when-custom {
  background: var(--surface-2, #FAFBF9);
  border: 1px solid var(--line, #E0E2DC);
  border-radius: var(--r-card, 14px);
  padding: 0.75rem 0.85rem;
  margin-bottom: 0.55rem;
}
.when-custom .field-label { margin: 0 0 0.35rem; }
.when-custom .text { height: 40px; font-size: 0.9375rem; }

/* The summary is a statement of what happens to the money, so it
   is never decorative. Set state uses the logo green as a fill
   on the tick only — green is a state, never an action. */
.when-summary {
  font-size: 0.9375rem; line-height: 1.5;
  color: var(--muted, #66716C);
  background: var(--surface-2, #FAFBF9);
  border: 0; border-left: 3px solid var(--line-strong, #C6CAC1);
  border-radius: 0 var(--r-ctl, 9px) var(--r-ctl, 9px) 0;
  padding: 0.6rem 0.75rem;
}
.when-summary.set {
  color: var(--ink-soft, #47514E);
  background: var(--live-soft, rgba(55, 172, 52, 0.11));
  border-left-color: var(--live, #2A323B);
  font-weight: 500;
}
.when-summary.set::before { content: "✓ "; color: var(--live-ink, #2A323B); font-weight: 600; }

/* ---- Rate Watch nudge — sits between the amount pills and the
        pay button on a ZESA purchase. Never blocks the buy. ---- */
.nudge {
  display: flex; flex-direction: column; gap: 0.5rem;
  background: var(--surface-2, #FAFBF9);
  border-left: 3px solid var(--line-strong, #C6CAC1);
  border-radius: 0 var(--r-ctl, 9px) var(--r-ctl, 9px) 0;
  padding: 0.75rem 0.9rem;
  margin-top: 0.75rem;
}
.nudge p { margin: 0; font-size: 0.9375rem; line-height: 1.5; color: var(--ink-soft, #47514E); }
.nudge b, .nudge strong { color: var(--ink, #171C1A); font-weight: 600; }
.nudge small {
  display: block; font-size: 0.8125rem; line-height: 1.45;
  color: var(--muted, #66716C);
}
.nudge.is-good     { border-left-color: var(--live, #2A323B); }
.nudge.is-info     { border-left-color: var(--info, #2A323B); }
.nudge.is-warn     { border-left-color: var(--warning-fill, #B27A15); }
.nudge.is-learning { border-left-color: var(--muted, #66716C); }

/* ---- Summary + submit -------------------------------------- */
.summary {
  margin-top: 1.25rem; padding: 0.9rem 1rem;
  background: var(--surface-2, #FAFBF9);
  border: 1px solid var(--line, #E0E2DC);
  border-radius: var(--r-card, 14px);
  font-size: 0.9375rem;
}
.summary-row {
  display: flex; justify-content: space-between; gap: 1rem;
  padding: 0.2rem 0;
}
.summary-row .lbl {
  font-family: var(--f-num, "IBM Plex Mono", ui-monospace, Menlo, monospace);
  font-size: 0.6875rem; font-weight: 600;
  letter-spacing: .14em; text-transform: uppercase;
  color: var(--muted, #66716C);
  align-self: center;
}
.summary-row span:not(.lbl) {
  font-family: var(--f-num, "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace);
  font-variant-numeric: tabular-nums;
  font-feature-settings: 'tnum' 1, 'zero' 1;
  letter-spacing: -.005em;
  font-weight: 500; text-align: right;
  color: var(--ink, #171C1A);
}
.summary-row.total {
  border-top: 1px solid var(--line, #E0E2DC);
  margin-top: 0.5rem; padding-top: 0.6rem;
}
.summary-row.total span:not(.lbl) { font-size: 1.0625rem; font-weight: 600; }

.submit {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  width: 100%; height: 52px; min-height: 52px; padding: 0 24px;
  background: var(--accent, #B4431F);
  color: var(--on-accent, #FFFFFF);
  border: 1px solid transparent;
  border-radius: var(--r-ctl, 9px);
  font-family: inherit; font-size: 0.9375rem; font-weight: 500; line-height: 1.2;
  cursor: pointer; margin-top: 1.25rem;
  box-shadow: none;
  transition: background 160ms cubic-bezier(.2,.7,.3,1);
}
.submit:hover { background: var(--accent-hover, #8F3317); transform: none; box-shadow: none; }
.submit:disabled { opacity: 0.45; cursor: not-allowed; transform: none; }

.widget-foot {
  font-size: 0.8125rem; line-height: 1.45;
  color: var(--muted, #66716C);
  text-align: center; margin-top: 0.9rem;
}
.widget-foot a {
  color: var(--accent, #B4431F); font-weight: 500;
  text-decoration: underline; text-underline-offset: 3px;
  text-decoration-color: var(--accent-line, rgba(180, 67, 31, 0.28));
}
.widget-foot a:hover { color: var(--accent-hover, #8F3317); }

/* ---- Motion ------------------------------------------------ */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: .001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .001ms !important;
  }
}

/* ---- Small phones ------------------------------------------ */
@media (max-width: 560px) {
  .cat-tabs { gap: 1rem; }
  .ccy-row { flex-wrap: wrap; gap: 0.5rem; }
  .summary-row { gap: 0.5rem; }
  .submit { width: 100%; }
}

/* ---- Remembered targets + inline field errors ---------------------------
   Nobody should have to go and find an 11-digit meter number every month.
   The chips are the last few meters or numbers this browser bought for; the
   name, if there is one, comes from the receipt page. Nothing leaves the
   device. */
.recall {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 8px 0 0;
}
.recall-chip {
  display: inline-flex; align-items: stretch;
  border: 1px solid var(--line, #E0E2DC);
  border-radius: 999px;
  background: var(--surface-2, #FAFBF9);
  overflow: hidden;
  max-width: 100%;
}
.recall-use {
  border: 0; background: none; cursor: pointer;
  font: inherit; font-size: 12px; line-height: 1.2;
  color: var(--ink, #171C1A);
  padding: 5px 4px 5px 11px;
  display: inline-flex; flex-direction: column; gap: 1px;
  text-align: left; min-width: 0;
}
.recall-use:hover { color: var(--accent, #B4431F); }
.recall-sub {
  font-family: var(--f-mono, ui-monospace, monospace);
  font-size: 10px; color: var(--muted, #66716C);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.recall-drop {
  border: 0; background: none; cursor: pointer;
  color: var(--muted, #66716C); font-size: 14px; line-height: 1;
  padding: 0 9px 0 5px;
}
.recall-drop:hover { color: var(--danger, #97213B); }
.recall-chip:focus-within { border-color: var(--accent, #B4431F); }

/* A correction under the field, not a modal in the middle of paying. */
.field-error {
  margin: 6px 0 0;
  font-size: 12.5px; line-height: 1.35;
  color: var(--danger, #97213B);
}
.text[aria-invalid="true"] { border-color: var(--danger, #97213B); }


/* ── Meter confirmation ──────────────────────────────────────────────────
   Sits under the meter input. Same voice as the Rate Watch nudge: one line,
   left rule coloured by state. The Pay button will not fire until it is
   .is-good for the meter currently typed. */
.meter-card { margin-top: 0.5rem; }
.meter-card .nudge { margin: 0; }
.meter-card .who { display: block; color: var(--ink, #171C1A); font-weight: 600; }
.meter-card .addr { display: block; color: var(--ink-soft, #47514E); font-size: 0.875rem; }
.meter-card .spin { display: inline-block; width: 0.75em; height: 0.75em; border: 2px solid currentColor;
  border-right-color: transparent; border-radius: 50%; vertical-align: -0.1em; margin-right: 0.35em;
  animation: meter-spin 0.7s linear infinite; }
@keyframes meter-spin { to { transform: rotate(360deg); } }
.nudge.is-bad { border-left-color: var(--danger, #B3261E); }

/* Pay waits for the meter. Dimmed, not hidden: the amount is still readable
   and the label says what would make it live. */
.submit[data-waiting] { opacity: 0.55; cursor: not-allowed; }
