/* Duet UI: the design tokens and shared components of the account surfaces, which are the
   sign-in family (views/auth-shell.html, plus duet-auth.css) and the account portal
   (pkg/portal/v2, plus duet-portal.css).

   The values are the post-login plans page's (views/plans-feature.html), so /plans, the
   upgrader, sign-in and the portal read as one product. The token names match the marketing
   site's copy of the same palette (DuetWeb/css/duet-tokens.css) so the two files can become
   one later.

   Scoped to .duet-ui, which sits on <html>, never bare :root: the portal still loads Bulma
   (static/css/main.css) and the already-redesigned pages beside it (the plan upgrader's
   .pu-*, the cancel flow's .gs-*) keep their own tokens.

   Light here. The portal redefines these tokens for its dark theme (duet-portal.css,
   html.dp-root); the sign-in pages stay light. Components therefore take every colour from a
   token, never a literal that only works on one background.

   Specificity rules, so this layer and Bulma never fight:
   - element defaults live in duet-auth.css / duet-portal.css under :where(), which adds
     no specificity, so any class (ours, Bulma's, .pu-*, .gs-*) still wins;
   - components are single classes with a dp- prefix (nothing in Bulma starts with it);
   - no bare rules on state classes (.active, .is-active, .valid, .expanded) — the upgrader
     and the cancel modal toggle those on their own elements. */

.duet-ui {
  color-scheme: light;

  /* surfaces */
  --duet-bg: #fbf9f5;
  --duet-bg-glow: radial-gradient(1150px 640px at 50% -12%, rgba(92, 152, 222, .20), transparent 70%);
  --duet-surface: #fff;
  /* Opaque even where --duet-surface is not (the portal's dark theme): for anything that
     overlaps content or must stay crisp — menus, inputs, buttons. */
  --duet-surface-solid: #fff;
  --duet-surface-2: #f4efe5;
  --duet-stroke: rgba(20, 24, 35, .11);
  --duet-stroke-strong: rgba(20, 24, 35, .18);
  --duet-stroke-hover: rgba(20, 24, 35, .3);
  --duet-hover: rgba(20, 24, 35, .06);
  --duet-row-hover: rgba(244, 239, 229, .45);
  --duet-switch-off: rgba(20, 24, 35, .2);

  /* type. --duet-faint is 2.9:1 on ivory: placeholders and decoration only, never text
     someone has to read — secondary text is --duet-muted (5.5:1). */
  --duet-text: #161b26;
  --duet-muted: #5c6678;
  --duet-faint: #8a93a3;
  --duet-font: "Nunito Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  --duet-heading: Montserrat, "Nunito Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;

  /* one accent: Duet blue. --duet-blue-ink is the brand blue darkened for type, where the
     brand blue itself fails AA at body sizes; -strong is for type on --duet-blue-soft. */
  --duet-accent: #5c98de;
  --duet-blue-ink: #2f6fbf;
  --duet-blue-ink-strong: #275fa6;
  --duet-blue-soft: rgba(92, 152, 222, .12);
  --duet-blue-grad: linear-gradient(135deg, #9cc8f7 0%, #5c98de 42%, #2f6fbf 100%);
  --duet-blue-line: linear-gradient(135deg, #7fb3ec, #2f6fbf 55%, #5c98de);
  --duet-cta-grad: linear-gradient(163deg, #82baf2 0%, #5c98de 48%, #3a6ec2 100%);
  --duet-cta-glow: 0 12px 30px -10px rgba(92, 152, 222, .75), inset 0 1px 0 rgba(255, 255, 255, .34);
  --duet-blue-on: #fff;
  --duet-neon-rgb: 76, 186, 240;

  /* status. Neither /plans nor the landing page has any; each gets a fill (icons, dots),
     an ink that passes AA as text on white and on its own tint, and that tint. */
  --duet-success: #2e9e6b;
  --duet-success-ink: #1f7a50;
  --duet-success-soft: rgba(46, 158, 107, .12);
  --duet-warning: #b7791f;
  --duet-warning-ink: #8a5a00;
  --duet-warning-soft: rgba(224, 164, 58, .16);
  --duet-danger: #d14343;
  --duet-danger-ink: #b3261e;
  --duet-danger-soft: rgba(179, 38, 30, .07);
  --duet-danger-solid: #b3261e;

  /* shape and depth. --duet-shadow is the plans page's card shadow, kept for the one
     card a page is about (the sign-in card); a dashboard shows many cards at once, so
     they get the quieter --duet-shadow-card. */
  --duet-r-sm: 10px;
  --duet-r-md: 16px;
  --duet-r-lg: 22px;
  --duet-r-pill: 999px;
  --duet-radius: 22px;
  --duet-shadow: 0 18px 50px -22px rgba(24, 20, 10, .32);
  --duet-shadow-pop: 0 30px 70px -26px rgba(47, 111, 191, .45);
  --duet-shadow-card: 0 1px 2px rgba(20, 24, 35, .04), 0 14px 34px -22px rgba(24, 20, 10, .28);
  --duet-shadow-sm: 0 1px 2px rgba(20, 24, 35, .06), 0 4px 14px -8px rgba(20, 24, 35, .16);
  --duet-seg-track: #f4efe5;
  --duet-seg-border: rgba(20, 24, 35, .11);
  --duet-seg-active: #fff;
  --duet-seg-ring: transparent;
  --duet-ease: cubic-bezier(.2, .7, .2, 1);
}

/* Focus is always visible for keyboard users and never for mouse clicks. The outline
   follows each element's own radius, so pills stay pills. */
:where(.duet-ui) :focus-visible {
  outline: 2.5px solid var(--duet-accent);
  outline-offset: 3px;
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

/* ---------------------------------------------------------------- type */

.dp-h1 {
  margin: 0;
  font-family: var(--duet-heading);
  font-size: clamp(26px, 2.4vw, 32px);
  font-weight: 800;
  line-height: 1.15;
  letter-spacing: -.025em;
  color: var(--duet-text);
  text-wrap: balance;
}

.dp-eyebrow {
  margin: 0;
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: .12em;
  text-transform: uppercase;
  color: var(--duet-muted);
}

.dp-muted {
  color: var(--duet-muted);
}

.dp-link {
  color: var(--duet-blue-ink);
  font-weight: 700;
  text-decoration: none;
  text-underline-offset: 3px;
  white-space: nowrap;
}

.dp-link:hover {
  color: var(--duet-blue-ink-strong);
  text-decoration: underline;
}

.dp-wordmark {
  font-family: var(--duet-font);
  font-weight: 700;
  font-size: 24px;
  line-height: 1;
  letter-spacing: -.02em;
  color: var(--duet-accent);
  text-decoration: none;
}

/* ------------------------------------------------------------- buttons */

.dp-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 44px;
  padding: 10px 20px;
  border: 1px solid transparent;
  border-radius: var(--duet-r-pill);
  background: none;
  font: inherit;
  font-size: 15px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  -webkit-user-select: none;
  user-select: none;
  transition: filter .18s ease, box-shadow .18s ease, background-color .18s ease, border-color .18s ease, color .18s ease, transform .18s ease;
}

.dp-btn:active {
  transform: translateY(1px);
}

.dp-btn svg {
  flex: none;
  width: 18px;
  height: 18px;
}

/* The primary action: the plans page's lit blue pill, minus its neon pulse — on a form
   the button waits for the user, it doesn't call out to them. */
.dp-btn--primary {
  background-image: var(--duet-cta-grad);
  color: var(--duet-blue-on);
  box-shadow: var(--duet-cta-glow);
  text-shadow: 0 1px 1px rgba(20, 50, 100, .22);
}

.dp-btn--primary:hover {
  filter: saturate(1.08) brightness(1.05);
}

.dp-btn--secondary {
  background: var(--duet-surface-solid);
  border-color: var(--duet-stroke-strong);
  color: var(--duet-text);
  box-shadow: var(--duet-shadow-sm);
}

.dp-btn--secondary:hover {
  border-color: var(--duet-stroke-hover);
}

.dp-btn--ghost {
  color: var(--duet-blue-ink);
}

.dp-btn--ghost:hover {
  background: var(--duet-blue-soft);
}

.dp-btn--danger {
  background: var(--duet-danger-solid);
  color: #fff;
  box-shadow: 0 10px 24px -12px rgba(179, 38, 30, .7);
}

.dp-btn--danger:hover {
  filter: brightness(1.08);
}

.dp-btn--danger-outline {
  background: var(--duet-surface-solid);
  border-color: rgba(179, 38, 30, .35);
  color: var(--duet-danger-ink);
}

.dp-btn--danger-outline:hover {
  background: var(--duet-danger-soft);
  border-color: rgba(179, 38, 30, .55);
}

.dp-btn--block {
  display: flex;
  width: 100%;
}

.dp-btn--lg {
  min-height: 48px;
  font-size: 16px;
}

.dp-btn--sm {
  min-height: 34px;
  padding: 6px 14px;
  font-size: 13.5px;
}

.dp-btn[disabled],
.dp-btn[aria-disabled="true"] {
  opacity: .55;
  cursor: default;
  pointer-events: none;
}

/* -------------------------------------------------------------- fields */

.dp-field {
  display: grid;
  gap: 6px;
  min-width: 0;
}

.dp-label {
  font-size: 13.5px;
  font-weight: 700;
  line-height: 1.3;
  color: var(--duet-text);
}

/* Label with an action on the same line ("Password" … "Forgot your password?"). */
.dp-label-row {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
}

.dp-label-row a {
  font-size: 13px;
}

/* 16px text on purpose: iOS Safari zooms the page into any smaller input on focus. */
.dp-input {
  display: block;
  width: 100%;
  height: 46px;
  margin: 0;
  padding: 0 14px;
  border: 1px solid var(--duet-stroke-strong);
  border-radius: 12px;
  background: var(--duet-surface-solid);
  box-shadow: inset 0 1px 1px rgba(20, 24, 35, .04);
  color: var(--duet-text);
  font: inherit;
  font-size: 16px;
  line-height: 1.3;
  -webkit-appearance: none;
  appearance: none;
  transition: border-color .15s ease, box-shadow .15s ease;
}

.dp-input::placeholder {
  color: var(--duet-faint);
  opacity: 1;
}

.dp-input:hover {
  border-color: var(--duet-stroke-hover);
}

.dp-input:focus {
  outline: none;
  border-color: var(--duet-accent);
  box-shadow: 0 0 0 3px rgba(92, 152, 222, .28);
}

.dp-input[readonly] {
  background: var(--duet-surface-2);
  border-color: var(--duet-stroke);
  color: var(--duet-muted);
}

textarea.dp-input {
  height: auto;
  min-height: 120px;
  padding: 12px 14px;
  line-height: 1.5;
  resize: vertical;
}

/* jquery.validate marks an invalid input with .error and inserts a label.error after it
   (after its .dp-control, see auth-scripts in views/auth-shell.html). */
.dp-input.error {
  border-color: var(--duet-danger);
}

.dp-input.error:focus {
  box-shadow: 0 0 0 3px rgba(209, 67, 67, .2);
}

.dp-field label.error,
.dp-field-error {
  display: block;
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  color: var(--duet-danger-ink);
}

/* An input with a button inside it: the password reveal. */
.dp-control {
  position: relative;
}

.dp-control .dp-input {
  padding-right: 50px;
}

.dp-reveal {
  position: absolute;
  top: 50%;
  right: 4px;
  display: grid;
  place-items: center;
  width: 40px;
  height: 38px;
  padding: 0;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--duet-muted);
  cursor: pointer;
  transform: translateY(-50%);
  transition: color .15s ease, background-color .15s ease;
}

.dp-reveal:hover {
  background: var(--duet-surface-2);
  color: var(--duet-text);
}

.dp-reveal svg {
  width: 20px;
  height: 20px;
}

.dp-reveal .dp-reveal__hide,
.dp-reveal[aria-pressed="true"] .dp-reveal__show {
  display: none;
}

.dp-reveal[aria-pressed="true"] .dp-reveal__hide {
  display: block;
}

.dp-check {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 14.5px;
  line-height: 1.45;
  cursor: pointer;
}

.dp-check input {
  flex: none;
  width: 18px;
  height: 18px;
  margin: 2px 0 0;
  accent-color: var(--duet-accent);
}

/* A toggle drawn on a real checkbox, so the existing change handlers keep working. */
.dp-switch {
  position: relative;
  flex: none;
  width: 44px;
  height: 26px;
  margin: 0;
  border-radius: var(--duet-r-pill);
  background: var(--duet-switch-off);
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  transition: background-color .2s ease;
}

.dp-switch::before {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(20, 24, 35, .3);
  transition: transform .2s var(--duet-ease);
}

.dp-switch:checked {
  background: var(--duet-blue-ink);
}

.dp-switch:checked::before {
  transform: translateX(18px);
}

.dp-switch:disabled {
  opacity: .5;
  cursor: default;
}

/* --------------------------------------------------------------- cards */

.dp-card {
  min-width: 0;
  padding: 24px;
  border: 1px solid var(--duet-stroke);
  border-radius: var(--duet-r-lg);
  background: var(--duet-surface);
  box-shadow: var(--duet-shadow-card);
}

.dp-card--flush {
  padding: 0;
  overflow: hidden;
}

.dp-card--quiet {
  background: transparent;
  box-shadow: none;
}

.dp-card__head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px 16px;
  margin-bottom: 18px;
}

.dp-card--flush .dp-card__head {
  margin: 0;
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--duet-stroke);
}

.dp-card__title {
  margin: 0;
  font-family: var(--duet-heading);
  font-size: 17px;
  font-weight: 800;
  line-height: 1.3;
  letter-spacing: -.01em;
  color: var(--duet-text);
}

.dp-card__sub {
  margin: 4px 0 0;
  font-size: 14px;
  line-height: 1.5;
  color: var(--duet-muted);
}

.dp-card__foot {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 16px;
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--duet-stroke);
}

/* -------------------------------------------------------------- badges */

.dp-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 24px;
  padding: 0 10px;
  border-radius: var(--duet-r-pill);
  background: var(--duet-surface-2);
  color: var(--duet-muted);
  font-size: 12px;
  font-weight: 800;
  line-height: 1;
  letter-spacing: .02em;
  white-space: nowrap;
  vertical-align: middle;
}

.dp-badge--blue {
  background: var(--duet-blue-soft);
  color: var(--duet-blue-ink-strong);
}

.dp-badge--success {
  background: var(--duet-success-soft);
  color: var(--duet-success-ink);
}

.dp-badge--warning {
  background: var(--duet-warning-soft);
  color: var(--duet-warning-ink);
}

.dp-badge--danger {
  background: var(--duet-danger-soft);
  color: var(--duet-danger-ink);
}

.dp-badge__dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: currentColor;
}

/* ------------------------------------------------------------- notices */

.dp-notice {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 16px;
  border: 1px solid var(--duet-stroke);
  border-radius: var(--duet-r-md);
  background: var(--duet-surface);
  color: var(--duet-text);
  font-size: 14.5px;
  line-height: 1.5;
}

.dp-notice > svg {
  flex: none;
  width: 20px;
  height: 20px;
  margin-top: 1px;
}

.dp-notice p {
  margin: 0;
}

.dp-notice--info {
  border-color: rgba(47, 111, 191, .22);
  background: var(--duet-blue-soft);
}

.dp-notice--info > svg {
  color: var(--duet-blue-ink);
}

.dp-notice--success {
  border-color: rgba(46, 158, 107, .28);
  background: var(--duet-success-soft);
}

.dp-notice--success > svg {
  color: var(--duet-success-ink);
}

.dp-notice--warning {
  border-color: rgba(183, 121, 31, .3);
  background: var(--duet-warning-soft);
}

.dp-notice--warning > svg {
  color: var(--duet-warning-ink);
}

.dp-notice--danger {
  border-color: rgba(179, 38, 30, .22);
  background: var(--duet-danger-soft);
}

.dp-notice--danger > svg {
  color: var(--duet-danger-ink);
}

/* ------------------------------------------------- segmented tabs (/plans) */

.dp-seg {
  display: inline-flex;
  max-width: 100%;
  padding: 4px;
  gap: 3px;
  border: 1px solid var(--duet-seg-border);
  border-radius: var(--duet-r-pill);
  background: var(--duet-seg-track);
  overflow-x: auto;
  scrollbar-width: none;
}

.dp-seg > a,
.dp-seg > button {
  flex: none;
  padding: 8px 18px;
  border: 0;
  border-radius: var(--duet-r-pill);
  background: transparent;
  color: var(--duet-muted);
  font: inherit;
  font-size: 14px;
  font-weight: 800;
  line-height: 1.2;
  text-decoration: none;
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .2s ease, color .2s ease, box-shadow .2s ease;
}

.dp-seg > a:hover,
.dp-seg > button:hover {
  color: var(--duet-text);
}

.dp-seg > [aria-current="page"],
.dp-seg > [aria-selected="true"] {
  background: var(--duet-seg-active);
  color: var(--duet-text);
  box-shadow: inset 0 0 0 1px var(--duet-seg-ring), 0 2px 10px rgba(0, 0, 0, .1);
}

/* -------------------------------------------------------------- tables */

.dp-table-wrap {
  overflow-x: auto;
}

.dp-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14.5px;
}

.dp-table th {
  padding: 12px 16px;
  border-bottom: 1px solid var(--duet-stroke);
  background: transparent;
  color: var(--duet-muted);
  font-family: var(--duet-heading);
  font-size: 11.5px;
  font-weight: 700;
  letter-spacing: .07em;
  text-align: left;
  text-transform: uppercase;
  white-space: nowrap;
}

.dp-table td {
  padding: 14px 16px;
  border-bottom: 1px solid var(--duet-stroke);
  vertical-align: middle;
}

.dp-table tbody tr:last-child td {
  border-bottom: 0;
}

.dp-table tbody tr:hover td {
  background: var(--duet-row-hover);
}

.dp-table .dp-num {
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* --------------------------------------------- key/value rows and stats */

.dp-dl {
  display: grid;
  grid-template-columns: minmax(130px, 210px) 1fr;
  margin: 0;
}

.dp-dl > dt,
.dp-dl > dd {
  margin: 0;
  padding: 14px 0;
  border-bottom: 1px solid var(--duet-stroke);
}

.dp-dl > dt {
  padding-right: 16px;
  color: var(--duet-muted);
  font-size: 14px;
  font-weight: 600;
}

.dp-dl > dd {
  min-width: 0;
  font-weight: 600;
  overflow-wrap: anywhere;
}

.dp-dl > dt:last-of-type,
.dp-dl > dd:last-of-type {
  border-bottom: 0;
}

@media (max-width: 560px) {
  .dp-dl {
    grid-template-columns: 1fr;
  }

  .dp-dl > dt {
    padding-bottom: 2px;
    border-bottom: 0;
  }

  .dp-dl > dd {
    padding-top: 0;
  }
}

.dp-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
}

.dp-stat {
  padding: 16px 18px;
  border: 1px solid var(--duet-stroke);
  border-radius: var(--duet-r-md);
  background: var(--duet-surface);
}

.dp-stat__label {
  font-size: 11.5px;
  font-weight: 800;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--duet-muted);
}

.dp-stat__value {
  margin-top: 6px;
  font-family: var(--duet-heading);
  font-size: 28px;
  font-weight: 700;
  line-height: 1.1;
  letter-spacing: -.02em;
  font-variant-numeric: tabular-nums;
  color: var(--duet-text);
}

/* -------------------------------------------------------------- spinner */

.dp-spinner {
  display: inline-block;
  width: 28px;
  height: 28px;
  border: 3px solid var(--duet-blue-soft);
  border-top-color: var(--duet-accent);
  border-radius: 50%;
  animation: dp-spin .8s linear infinite;
}

@keyframes dp-spin {
  to {
    transform: rotate(360deg);
  }
}

/* --------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
  :where(.duet-auth, .dp-shell, .dp-page) *,
  :where(.duet-auth, .dp-shell, .dp-page) *::before,
  :where(.duet-auth, .dp-shell, .dp-page) *::after {
    animation-duration: .01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: .01ms !important;
    scroll-behavior: auto !important;
  }

  .dp-spinner {
    animation-duration: 1.6s !important;
    animation-iteration-count: infinite !important;
  }
}
