/* ==========================================================================
   Components — reusable primitives (buttons, pills, cards, form controls,
   keypad, toasts). View-specific composition lives in views.css.
   ========================================================================== */

/* ---------- status pill ---------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  max-width: 46vw;
  height: 32px;
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 12px;
  font-weight: 600;
  white-space: nowrap;
  box-shadow: var(--shadow-sm);
}
.pill > span:last-child { overflow: hidden; text-overflow: ellipsis; }
.pill-dot {
  width: 7px;
  height: 7px;
  flex: none;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 4px var(--ok-soft);
}
.pill-pending .pill-dot { background: var(--warn); box-shadow: 0 0 0 4px var(--warn-soft); animation: blink 1.3s infinite; }
.pill-error .pill-dot { background: var(--danger); box-shadow: 0 0 0 4px var(--danger-soft); }
@keyframes blink { 50% { opacity: .3; } }

/* ---------- icon button ---------- */
.icon-button {
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink-2);
  box-shadow: var(--shadow-sm);
  transition: color var(--fast), background var(--fast), border-color var(--fast);
}
.icon-button:hover { color: var(--ink); border-color: var(--line-strong); }
.icon-button .icon { width: 18px; height: 18px; }

/* theme toggle shows exactly one glyph, driven by the resolved preference */
#theme-toggle .icon { display: none; }
:root[data-theme-pref="light"] .icon-theme-light,
:root[data-theme-pref="dark"] .icon-theme-dark,
:root[data-theme-pref="system"] .icon-theme-system { display: block; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 9px;
  min-height: 46px;
  padding: 0 var(--s-5);
  border: 1px solid transparent;
  border-radius: var(--r-md);
  background: var(--surface-3);
  color: var(--ink);
  font-size: 15px;
  font-weight: 660;
  transition: transform var(--fast), background var(--fast), box-shadow var(--fast), opacity var(--fast);
}
.btn:active { transform: scale(.985); }
.btn:disabled { opacity: .45; transform: none; }
.btn .icon { width: 18px; height: 18px; }

.btn-sm { min-height: 36px; padding: 0 var(--s-3); font-size: 13px; border-radius: var(--r-sm); }
.btn-sm .icon { width: 15px; height: 15px; }

.btn-primary { background: var(--accent); color: var(--accent-on); box-shadow: 0 8px 20px var(--accent-ring); }
.btn-primary:hover:not(:disabled) { background: var(--accent-strong); }

.btn-ghost { border-color: var(--line); background: var(--surface); color: var(--ink-2); box-shadow: var(--shadow-sm); }
.btn-ghost:hover:not(:disabled) { color: var(--ink); border-color: var(--line-strong); }
.btn-danger-ghost { color: var(--danger); }

.btn-call {
  width: 100%;
  min-height: 58px;
  border-radius: var(--r-lg);
  background: var(--ok);
  background: linear-gradient(160deg, var(--ok), color-mix(in srgb, var(--ok) 78%, var(--accent)));
  color: var(--on-positive);
  font-size: 16px;
  font-weight: 700;
  letter-spacing: .02em;
  box-shadow: 0 10px 26px var(--ok-soft);
  box-shadow: 0 10px 26px color-mix(in srgb, var(--ok) 34%, transparent);
}
.btn-call:hover:not(:disabled) { filter: brightness(1.05); }

.btn-hangup {
  flex: 1;
  min-height: 58px;
  border-radius: var(--r-lg);
  background: var(--danger);
  color: var(--on-danger);
  font-weight: 700;
  box-shadow: 0 10px 26px var(--danger-soft);
}
.btn-hangup:hover { background: var(--danger-strong); }

.btn-answer {
  flex: 1;
  min-height: 58px;
  border-radius: var(--r-lg);
  background: var(--ok);
  color: var(--on-positive);
  font-weight: 700;
  box-shadow: 0 10px 26px var(--ok-soft);
}
.btn-answer:hover { filter: brightness(1.06); }

/* ---------- card ---------- */
.card {
  display: grid;
  gap: var(--s-4);
  padding: var(--s-5);
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}
.card-actions { display: flex; flex-wrap: wrap; gap: var(--s-2); }

/* ---------- form controls ---------- */
.input, .select {
  width: 100%;
  min-height: 44px;
  padding: 0 13px;
  border: 1px solid var(--line-strong);
  border-radius: var(--r-sm);
  background: var(--surface-inset);
  color: var(--ink);
  font-size: 15px;
  transition: border-color var(--fast), box-shadow var(--fast);
}
.input:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-ring);
}
.select {
  appearance: none;
  padding-right: 34px;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%),
                    linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 17px) 50%, calc(100% - 12px) 50%;
  background-size: 5px 5px, 5px 5px;
  background-repeat: no-repeat;
  cursor: pointer;
}

.field { display: grid; gap: 8px; }
.field > label { color: var(--ink-2); font-size: 13px; font-weight: 620; }
.field-row { display: flex; gap: var(--s-2); align-items: center; }
.field-row .input, .field-row .select { flex: 1; min-width: 0; }
.field-note { color: var(--ink-3); font-size: 12px; }

/* switch */
.switch {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  cursor: pointer;
}
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch-track {
  position: relative;
  flex: none;
  width: 42px;
  height: 25px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  border: 1px solid var(--line-strong);
  transition: background var(--fast), border-color var(--fast);
}
.switch-track i {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 17px;
  height: 17px;
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
  transition: transform var(--base);
}
.switch input:checked + .switch-track { background: var(--accent); border-color: transparent; }
.switch input:checked + .switch-track i { transform: translateX(17px); background: #fff; }
.switch input:focus-visible + .switch-track { outline: 2px solid var(--accent); outline-offset: 2px; }
.switch-text strong { display: block; font-size: 14px; font-weight: 620; }
.switch-text small { display: block; color: var(--ink-3); font-size: 12px; }

/* segmented control */
.segmented {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 1fr;
  gap: 4px;
  padding: 4px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface-inset);
}
.segmented button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  min-height: 38px;
  border-radius: var(--r-xs);
  color: var(--ink-3);
  font-size: 13px;
  font-weight: 620;
  transition: color var(--fast), background var(--fast), box-shadow var(--fast);
}
.segmented button .icon { width: 16px; height: 16px; }
.segmented button:hover { color: var(--ink); }
.segmented button[aria-checked="true"] {
  background: var(--surface);
  color: var(--ink);
  box-shadow: var(--shadow-sm);
}

/* level meter */
.meter {
  --level: 0;
  position: relative;
  height: 6px;
  border-radius: var(--r-pill);
  background: var(--surface-3);
  overflow: hidden;
}
.meter i {
  position: absolute;
  inset: 0;
  transform-origin: left center;
  transform: scaleX(var(--level));
  border-radius: inherit;
  background: linear-gradient(90deg, var(--ok), var(--accent));
  transition: transform .08s linear;
}

/* chips */
.chips { display: flex; flex-wrap: wrap; gap: var(--s-2); }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 36px;
  padding: 0 13px;
  border: 1px solid var(--line);
  border-radius: var(--r-pill);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13px;
  font-weight: 620;
  font-variant-numeric: tabular-nums;
  box-shadow: var(--shadow-sm);
  transition: color var(--fast), border-color var(--fast), transform var(--fast);
}
.chip:hover { color: var(--ink); border-color: var(--accent); transform: translateY(-1px); }
.chip .icon { width: 14px; height: 14px; color: var(--ink-4); }

/* ---------- keypad ---------- */
.keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: clamp(8px, 1.6vw, 12px);
}
.key {
  position: relative;
  display: grid;
  gap: 1px;
  place-items: center;
  align-content: center;
  min-height: 62px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: var(--surface);
  box-shadow: var(--shadow-key);
  transition: transform .1s var(--ease), background var(--fast), border-color var(--fast);
}
.key b {
  font-size: 25px;
  font-weight: 620;
  line-height: 1.05;
  letter-spacing: .02em;
  font-variant-numeric: tabular-nums;
}
.key small {
  color: var(--ink-4);
  font-size: 9px;
  font-weight: 700;
  letter-spacing: .12em;
  min-height: 11px;
}
.key:hover { background: var(--surface-2); border-color: var(--line-strong); }
.key:active, .key.is-pressed { transform: scale(.955); background: var(--accent-soft); border-color: var(--accent); }

.keypad-compact { gap: 7px; }
.keypad-compact .key { min-height: 44px; border-radius: var(--r-sm); }
.keypad-compact .key b { font-size: 18px; }
.keypad-compact .key small { display: none; }

/* ---------- toasts ---------- */
.toasts {
  position: fixed;
  z-index: 90;
  top: calc(var(--appbar-h) + env(safe-area-inset-top) + 10px);
  right: clamp(12px, 3vw, 28px);
  display: grid;
  gap: var(--s-2);
  width: min(360px, calc(100vw - 24px));
  pointer-events: none;
}
.toast {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-sm);
  background: var(--surface);
  color: var(--ink-2);
  font-size: 13.5px;
  line-height: 1.5;
  box-shadow: var(--shadow-md);
  pointer-events: auto;
  animation: toast-in .24s var(--ease) both;
}
.toast.is-out { animation: toast-out .2s var(--ease) both; }
.toast-error { border-left-color: var(--danger); }
.toast-success { border-left-color: var(--ok); }
.toast p { flex: 1; min-width: 0; overflow-wrap: anywhere; }
.toast button { color: var(--ink-4); }
.toast button:hover { color: var(--ink); }
.toast .icon { width: 15px; height: 15px; }
@keyframes toast-in { from { opacity: 0; transform: translateX(14px); } }
@keyframes toast-out { to { opacity: 0; transform: translateX(14px); } }

@media (max-width: 860px) {
  .toasts { left: clamp(12px, 3vw, 28px); right: clamp(12px, 3vw, 28px); width: auto; }
}
