/*
 * ui.css — Hearth component layer ("Home Map" direction).
 *
 * Reusable, token-driven components. Consumes tokens.css only; never hardcodes a
 * color or size that a token already names. Section sheets (app.css,
 * marketing.css, styleguide.css…) compose these.
 *
 * Dual-surface: components default to the light "paper" surface. Wrap a section
 * in `.stage` to flip it to the warm-dark signature surface; stage-aware
 * overrides live beside each component.
 */

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

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: var(--leading-normal);
  color: var(--color-text);
  background:
    radial-gradient(1200px 560px at 50% -240px, var(--cream-glow), transparent),
    var(--color-bg);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3,
h4 {
  font-family: var(--font-display);
  font-weight: var(--weight-bold);
  line-height: var(--leading-snug);
  letter-spacing: var(--tracking-tight);
  margin: 0;

  /* Even out multi-line headings (and absorb EN/ES length variance). */
  text-wrap: balance;
}

p {
  margin: 0;
  text-wrap: pretty; /* avoid orphans / ragged single-word last lines */
}

img {
  display: block;
  max-width: 100%;
}

a {
  color: var(--color-primary-ink);
  text-decoration-thickness: 1px;
  text-underline-offset: 2px;
}

:focus-visible {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

/* ===== Icons ============================================================
   Inline SVG (see IconHelper#icon). currentColor + em sizing so an icon takes
   the color and scale of whatever text or control it sits in. */
.icon {
  width: 1.1em;
  height: 1.1em;
  flex: none;
  vertical-align: -0.18em;
}

.btn .icon {
  width: 1.15em;
  height: 1.15em;
}

/* ===== Layout =========================================================== */
.container {
  max-width: var(--container);
  margin-inline: auto;
  padding-inline: var(--page-gutter);
}

.container--narrow {
  max-width: var(--container-narrow);
}

.container--wide {
  max-width: var(--container-wide);
}

.stack > * + * {
  margin-top: var(--space-4);
}

.stack--tight > * + * {
  margin-top: var(--space-2);
}

.stack--loose > * + * {
  margin-top: var(--space-8);
}

.cluster {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--space-3);
}

.divider {
  height: 1px;
  background: var(--color-border);
  border: 0;
  margin-block: var(--space-6);
}

/* Visually hidden but available to screen readers and keyboard focus. */
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
  border: 0;
}

/* ===== Stage (the warm-dark signature surface) ========================== */
.stage {
  background: var(--color-stage);
  color: var(--color-on-stage);
  border-radius: var(--radius-xl);
}

.stage h1,
.stage h2,
.stage h3,
.stage h4 {
  color: var(--color-on-stage);
}

/* Plain links on the stage go ember; button-styled anchors (.btn*) keep their
   own component color so a .btn--primary never renders ember-on-ember. */
.stage a:not(.btn) {
  color: var(--ember);
}

.stage .eyebrow {
  color: var(--ember);
}

.stage .divider {
  background: var(--color-stage-border);
}

.stage .text-muted {
  color: var(--color-on-stage-muted);
}

/* ===== Typographic helpers ============================================= */
.eyebrow {
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-eyebrow);
  text-transform: uppercase;
  color: var(--color-eyebrow);
}

.display {
  font-family: var(--font-display);
  font-size: var(--text-display);
  font-weight: var(--weight-bold);
  line-height: var(--leading-tight);
  letter-spacing: var(--tracking-display);
}

.lead {
  font-size: var(--text-md);
  line-height: var(--leading-normal);
  color: var(--color-text-muted);
}

.text-muted {
  color: var(--color-text-muted);
}

/* ===== Buttons ========================================================== */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--space-2);
  font-family: var(--font-sans);
  font-size: var(--text-base);
  font-weight: var(--weight-semibold);
  line-height: 1;
  padding: var(--space-3) var(--space-5);
  border: 1px solid transparent;
  border-radius: var(--radius-pill);
  text-decoration: none; /* button-styled anchors (link_to) never underline */
  cursor: pointer;
  transition: var(--transition-fast);
  transition-property: transform, background-color, border-color, box-shadow;
}

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

.btn:active {
  transform: translateY(0);
}

.btn--primary {
  background: var(--color-primary);
  color: var(--color-on-primary);
  box-shadow: var(--shadow-primary);
}

.btn--primary:hover {
  background: color-mix(in srgb, var(--color-primary) 88%, white);
}

.btn--ghost {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}

.btn--ghost:hover {
  background: var(--color-surface-sunk);
}

.btn--quiet {
  background: transparent;
  color: var(--color-primary-ink);
  padding-inline: var(--space-3);
}

.btn--quiet:hover {
  background: color-mix(in srgb, var(--color-primary) 12%, transparent);
}

.btn--danger {
  background: var(--color-danger);
  color: #fff;
}

.btn--lg {
  font-size: var(--text-md);
  padding: var(--space-4) var(--space-8);
}

.btn--sm {
  font-size: var(--text-sm);
  padding: var(--space-2) var(--space-4);
}

.btn--block {
  width: 100%;
}

/* Ghost button on the dark stage */
.stage .btn--ghost {
  background: transparent;
  color: var(--color-on-stage);
  border-color: var(--color-stage-border);
}

.stage .btn--ghost:hover {
  background: color-mix(in srgb, var(--color-on-stage) 8%, transparent);
}

/* ===== Cards ============================================================ */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: var(--space-6);
}

.card--sunk {
  background: var(--color-surface-sunk);
  box-shadow: none;
}

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

.stage .card {
  background: var(--color-stage-raised);
  border-color: var(--color-stage-border);
  box-shadow: var(--shadow-stage);
  color: var(--color-on-stage);
}

/* ===== Fields =========================================================== */
.field {
  display: block;
}

.field__label {
  display: block;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  margin-bottom: var(--space-2);
}

.field__control {
  width: 100%;
  font: inherit;
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
  transition: var(--transition-fast);
  transition-property: border-color, box-shadow;
}

.field__control::placeholder {
  color: var(--color-text-faint);
}

.field__control:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--color-primary) 28%, transparent);
}

.field__hint {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
  margin-top: var(--space-2);
}

.field__error {
  font-size: var(--text-sm);
  color: var(--color-danger-ink);
  margin-top: var(--space-2);
}

/* ===== Chips (the Home-map item selector) =============================== */
.chip {
  display: inline-flex;
  align-items: center;
  gap: var(--space-2);
  font: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-medium);
  color: var(--color-text);
  background: var(--color-surface-sunk);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-pill);
  padding: var(--space-2) var(--space-4);
  cursor: pointer;
  transition: var(--transition-fast);
  transition-property: transform, background-color, border-color, color;
}

.chip:hover {
  transform: translateY(-1px);
}

.chip[aria-pressed="true"],
.chip--on {
  background: var(--color-primary);
  border-color: var(--color-primary);
  color: var(--color-on-primary);
  font-weight: var(--weight-bold);
}

.stage .chip {
  background: var(--color-stage-raised);
  border-color: var(--color-stage-border);
  color: var(--color-on-stage);
}

.stage .chip[aria-pressed="true"],
.stage .chip--on {
  background: var(--color-primary);
  color: var(--color-on-primary);
}

/* Touch targets: on coarse pointers (phones/tablets) every button and chip is
   at least 44px tall — the one-handed-at-360px comfort target — without
   inflating the dense, mouse-driven layouts on the light working surface. */
@media (pointer: coarse) {
  .btn,
  .chip {
    min-height: 44px;
  }
}

/* ===== Badges (status) ================================================= */
.badge {
  display: inline-flex;
  align-items: center;
  gap: var(--space-1);
  font-size: var(--text-xs);
  font-weight: var(--weight-semibold);
  border-radius: var(--radius-pill);
  padding: var(--space-1) var(--space-3);
}

.badge--scheduled,
.badge--done {
  color: var(--color-success-ink);
  background: var(--color-success-bg);
}

.badge--due {
  color: var(--color-primary-ink);
  background: var(--color-due-bg);
}

.badge--attention,
.badge--overdue {
  color: var(--color-attention-ink);
  background: var(--color-attention-bg);
}

/* ===== Callouts ======================================================== */
.callout {
  display: flex;
  gap: var(--space-3);
  border-radius: var(--radius-md);
  padding: var(--space-4) var(--space-5);
  background: var(--color-surface-sunk);
  border-left: 3px solid var(--color-border);
}

.callout--attention {
  background: var(--color-attention-bg);
  border-left-color: var(--color-accent);
  color: var(--color-attention-ink);
}

.callout--success {
  background: var(--color-success-bg);
  border-left-color: var(--color-success);
  color: var(--color-success-ink);
}

.callout--danger {
  background: color-mix(in srgb, var(--color-danger) 12%, transparent);
  border-left-color: var(--color-danger);
  color: var(--color-danger-ink);
}

/* ===== Task row (maintenance dashboard) ================================ */
.task {
  display: flex;
  align-items: center;
  gap: var(--space-3);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: var(--space-3) var(--space-4);
}

.task__check {
  width: 22px;
  height: 22px;
  flex: none;
  border: 2px solid color-mix(in srgb, var(--color-text-faint) 60%, transparent);
  border-radius: var(--radius-sm);
  background: transparent;
  cursor: pointer;
}

.task__check--done {
  background: var(--color-success);
  border-color: var(--color-success);
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.task__body {
  flex: 1;
  min-width: 0;
}

.task__title {
  font-weight: var(--weight-semibold);
  font-size: var(--text-sm);
}

.task__meta {
  font-size: var(--text-xs);
  color: var(--color-text-muted);
}

/* ===== Stat (big display number) ====================================== */
.stat__num {
  font-family: var(--font-display);
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  color: var(--color-primary-ink);
  line-height: 1;
}

.stage .stat__num {
  color: var(--color-primary);
}

.stat__label {
  font-size: var(--text-sm);
  color: var(--color-text-muted);
}

/* ===== Switch (per-channel notification toggle) ======================= */
.switch {
  position: relative;
  display: inline-flex;
  width: 44px;
  height: 26px;
}

.switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}

.switch__track {
  flex: 1;
  border-radius: var(--radius-pill);
  background: var(--color-surface-sunk);
  border: 1px solid var(--color-border);
  transition: var(--transition-fast);
  transition-property: background-color, border-color;
}

.switch__track::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: var(--radius-pill);
  background: #fff;
  box-shadow: var(--shadow-sm);
  transition: transform var(--transition-fast);
}

.switch input:checked + .switch__track {
  background: var(--color-primary);
  border-color: var(--color-primary);
}

.switch input:checked + .switch__track::after {
  transform: translateX(18px);
}

.switch input:focus-visible + .switch__track {
  outline: 3px solid var(--color-primary);
  outline-offset: 2px;
}
