/* ---------- 7a. Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: var(--s2);
  min-height: 44px; padding: var(--s3) var(--s6);
  border-radius: var(--r-pill); border: 1px solid transparent;
  font-size: 16px; font-weight: 700; line-height: 1.2;
  cursor: pointer; white-space: nowrap;
  transition: background-color var(--d-micro) var(--ease), border-color var(--d-micro) var(--ease), opacity var(--d-micro) var(--ease);
}
.btn .ti { font-size: 20px; }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.btn-primary { background: var(--action); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--action-hover); }
.btn-primary:active:not(:disabled) { background: var(--action-active); }

.btn-secondary { background: var(--card); color: var(--ink); border-color: var(--line); }
.btn-secondary:hover:not(:disabled) { background: var(--panel); border-color: var(--line-hover); }
.btn-secondary:active:not(:disabled) { background: var(--panel-pressed); border-color: var(--line-hover); }


.btn-danger { background: var(--err); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--err-hover); }
.btn-danger:active:not(:disabled) { background: var(--err-pressed); }

.btn-block { width: 100%; }
.btn-sm { min-height: 32px; padding: 6px var(--s3); font-size: 13px; }

.link-btn {
  background: none; border: 0; padding: var(--s2) var(--s1); min-height: 44px;
  color: var(--action); font-weight: 700; cursor: pointer;
}
.link-btn:hover { color: var(--action-hover); }
.link-btn:active { color: var(--action-active); }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 44px; height: 44px; flex: none;
  border: 0; border-radius: var(--r-pill); background: transparent; color: var(--ink);
  cursor: pointer; transition: background-color var(--d-micro) var(--ease), color var(--d-micro) var(--ease);
}
.icon-btn .ti { font-size: 20px; }
.icon-btn:hover { background: var(--panel); }
.icon-btn:active { background: var(--panel-pressed); }
.icon-btn.muted { color: var(--gray); }
.icon-btn.muted:hover { color: var(--ink); }
.icon-btn.danger:hover { color: var(--err); background: var(--err-tint); }

/* Spinner inside a primary button */
.btn .spinner { width: 16px; height: 16px; border-color: rgba(255,255,255,.4); border-top-color: #fff; }

/* ---------- 7b. Inputs ---------- */
.field { display: flex; flex-direction: column; }
.field + .field { margin-top: var(--s4); }
.field-stack { display: flex; flex-direction: column; gap: var(--s3); }
.field-stack > .field + .field { margin-top: 0; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s4); }
.field-row > .field + .field { margin-top: 0; }
@media (max-width: 599px) { .field-row { grid-template-columns: 1fr; } }
.field-head { display: flex; align-items: baseline; justify-content: space-between; gap: var(--s2); margin-bottom: var(--s2); }
.field-label { font-size: 13px; line-height: 1.5; color: var(--ink); }
.field-req { color: var(--err-text); }
.field-opt { color: var(--gray-muted); }

.input, .textarea {
  width: 100%; min-height: 44px;
  background: var(--card); color: var(--ink);
  border: 1px solid var(--line); border-radius: var(--r-md);
  padding: 10px var(--s3);
  font-size: 16px; line-height: 1.4;
  transition: border-color var(--d-micro) var(--ease), box-shadow var(--d-micro) var(--ease);
}
.input::placeholder, .textarea::placeholder { color: var(--gray-muted); opacity: 1; }
.input:hover:not(:focus), .textarea:hover:not(:focus) { border-color: var(--line-hover); }
/* Focused: 2px Ink border, as on howardai.us */
.input:focus, .textarea:focus {
  border-color: var(--ink);
  box-shadow: inset 0 0 0 1px var(--ink);
  outline: none;
}
.input[aria-invalid="true"], .textarea[aria-invalid="true"] {
  border-color: var(--err); box-shadow: inset 0 0 0 1px var(--err);
}
.input:disabled, .textarea:disabled { opacity: 0.45; }

.textarea { min-height: 120px; resize: none; overflow: hidden; display: block; }

.input-wrap { position: relative; }
.input-wrap .lead {
  position: absolute; left: 14px; top: 12px; font-size: 20px; color: var(--gray-muted);
  pointer-events: none; transition: color var(--d-micro) var(--ease);
}
.input-wrap.has-lead .input { padding-left: 44px; }
.input-wrap:focus-within .lead { color: var(--ink); }
.input-wrap .input { padding-right: 44px; }
.input-wrap.has-action .input { padding-right: 52px; }
.input-wrap .reveal { position: absolute; right: 0; top: 0; color: var(--gray); }
.input-wrap .reveal:hover { background: transparent; color: var(--ink); }
.valid-mark {
  position: absolute; right: 14px; top: 12px; font-size: 20px; color: var(--ok);
  opacity: 0; transform: scale(.6); pointer-events: none;
  transition: opacity var(--d-micro) var(--ease), transform var(--d-short) var(--ease);
}
.field.is-valid .valid-mark { opacity: 1; transform: none; }
.textarea.compact { min-height: 88px; }
.input-wrap .prefix {
  position: absolute; left: 12px; top: 0; height: 44px; display: flex; align-items: center;
  color: var(--gray); pointer-events: none; font-variant-numeric: tabular-nums;
}
.input-wrap.has-prefix .input { padding-left: 40px; }
.field-divider { border: 0; border-top: 1px solid var(--line); margin: 0; width: 100%; }
.select {
  appearance: none; -webkit-appearance: none; cursor: pointer; padding-right: 40px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='20' height='20' viewBox='0 0 24 24' fill='none' stroke='%231C1C1C' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
}
input[type="date"].input { min-width: 0; }
input[type="date"].input::-webkit-calendar-picker-indicator { opacity: .6; cursor: pointer; }

.helper { margin-top: var(--s1); font-size: 13px; line-height: 1.5; color: var(--gray); }
.helper:empty { display: none; }
.helper-ok { display: inline-flex; align-items: center; gap: var(--s1); color: var(--ok-text); }
.helper-ok .ti { font-size: 16px; color: var(--ok); }

/* Password strength: red → orange → yellow → green */
.meter { display: flex; align-items: center; gap: var(--s3); margin-top: var(--s1); }
.meter-bar { flex: 1; display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s1); }
.meter-seg { height: 4px; border-radius: var(--r-pill); background: var(--line); transition: background-color var(--d-short) var(--ease); }
.meter-label { font-size: 13px; color: var(--gray); min-width: 64px; text-align: right; white-space: nowrap; }
.meter[data-level="weak"] .meter-seg.on { background: var(--err); }
.meter[data-level="fair"] .meter-seg.on { background: var(--warn); }
.meter[data-level="good"] .meter-seg.on { background: var(--caution); }
.meter[data-level="strong"] .meter-seg.on { background: var(--ok); }
.meter[data-level="weak"] .meter-label { color: var(--err-text); }
.meter[data-level="fair"] .meter-label { color: var(--warn-text); }
.meter[data-level="strong"] .meter-label { color: var(--ok-text); }

/* Communication style: three compact options */
.style-picker { border: 0; margin: 0; padding: 0; min-width: 0; }
.style-picker legend { padding: 0; margin-bottom: var(--s2); }
.style-options { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s2); }
.style-option {
  position: relative; display: flex; flex-direction: column; align-items: flex-start; gap: 2px;
  padding: var(--s3) var(--s4); min-height: 44px; border-radius: var(--r-md);
  background: var(--card); border: 1px solid var(--line); cursor: pointer;
  transition: border-color var(--d-micro) var(--ease), box-shadow var(--d-micro) var(--ease);
}
.style-option:hover { border-color: var(--line-hover); }
.style-option input { position: absolute; opacity: 0; pointer-events: none; }
.style-option .ti { font-size: 20px; color: var(--gray-muted); margin-bottom: var(--s1); transition: color var(--d-micro) var(--ease); }
.style-title { font-weight: 700; }
.style-desc { font-size: 13px; line-height: 1.35; color: var(--gray); }
.style-option:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.style-option:has(input:checked) .ti { color: var(--ink); }
.style-option:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; }
.error {
  display: flex; align-items: flex-start; gap: var(--s1);
  margin-top: var(--s1); font-size: 13px; line-height: 1.5; color: var(--err-text);
}
.error .ti { font-size: 16px; margin-top: 2px; flex: none; }
.error:empty { display: none; }

/* Radio choice rows */
.choices { display: flex; flex-direction: column; gap: var(--s2); border: 0; margin: 0; padding: 0; }
.choice {
  display: flex; align-items: flex-start; gap: var(--s3);
  padding: var(--s3) var(--s4); min-height: 44px;
  border: 1px solid var(--line); border-radius: var(--r-md); background: var(--card);
  cursor: pointer; transition: border-color var(--d-micro) var(--ease);
}
.choice:hover { border-color: var(--line-hover); }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice-dot {
  flex: none; width: 20px; height: 20px; margin-top: 1px;
  border: 2px solid var(--line); border-radius: 50%;
  display: grid; place-items: center;
  transition: border-color var(--d-instant) var(--ease);
}
.choice-dot::after {
  content: ""; width: 10px; height: 10px; border-radius: 50%;
  background: var(--ink); transform: scale(0);
  transition: transform var(--d-instant) var(--ease);
}
.choice input:checked + .choice-dot { border-color: var(--ink); }
.choice input:checked + .choice-dot::after { transform: scale(1); }
.choice:has(input:checked) { border-color: var(--ink); box-shadow: inset 0 0 0 1px var(--ink); }
.choice:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 2px; }
.choice-title { font-weight: 700; }
.choice-desc { font-size: 13px; line-height: 1.5; color: var(--gray); }

/* Segmented control (layout comparison) */
.segmented { display: inline-flex; padding: var(--s1); background: var(--panel); border-radius: var(--r-pill); gap: var(--s1); }
.segmented label { position: relative; }
.segmented input { position: absolute; opacity: 0; }
.segmented span {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 var(--s4);
  border-radius: var(--r-pill); font-weight: 700; font-size: 14px; color: var(--gray); cursor: pointer;
  transition: background-color var(--d-micro) var(--ease), color var(--d-micro) var(--ease);
}
.segmented input:checked + span { background: var(--card); color: var(--ink); box-shadow: var(--e1); }
.segmented input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 2px; }

/* ---------- 7c. Cards ---------- */
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s6);
}

/* ---------- 7g. Alerts ---------- */
.alert {
  display: flex; gap: var(--s3); align-items: flex-start;
  background: var(--card); border-radius: var(--r-md);
  padding: var(--s4) 20px;
  border: 1px solid; border-left-width: 4px;
}
.alert > .ti { font-size: 20px; flex: none; margin-top: 1px; }
.alert-body { flex: 1; min-width: 0; font-size: 14px; color: var(--gray); }
.alert-title { font-size: 14px; font-weight: 700; color: var(--ink); margin-bottom: 2px; }
.alert-actions { margin-top: var(--s2); }
.alert-actions .link-btn { padding-left: 0; min-height: 32px; }
.alert-info { border-color: rgba(62,110,140,.3); border-left-color: var(--action); }
.alert-info > .ti { color: var(--action); }
.alert-warning { border-color: rgba(255,159,10,.35); border-left-color: var(--warn); }
.alert-warning > .ti { color: var(--warn); }
.alert-error { border-color: rgba(255,59,48,.3); border-left-color: var(--err); }
.alert-error > .ti { color: var(--err); }
.alert-success { border-color: rgba(52,199,89,.35); border-left-color: var(--ok); }
.alert-success > .ti { color: var(--ok); }

/* ---------- 7g. Toasts ---------- */
.toasts {
  position: fixed; z-index: 90; right: var(--s6); bottom: var(--s6);
  display: flex; flex-direction: column; gap: var(--s2); align-items: flex-end;
  pointer-events: none;
}
.toast {
  background: var(--thunder); color: #fff; border-radius: var(--r-lg);
  padding: 14px 20px; box-shadow: 0 8px 24px rgba(0,0,0,.16);
  max-width: 420px; display: flex; align-items: center; gap: var(--s2);
  animation: toast-in var(--d-short) var(--ease) both;
}
.toast .ti { font-size: 20px; }
.toast[data-tone="ok"] .ti { color: var(--ok); }
.toast[data-tone="err"] .ti { color: #FF6961; }
.toast[data-tone="warn"] .ti { color: var(--warn); }
.toast.leaving { animation: toast-out var(--d-short) var(--ease) both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }
@keyframes toast-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(12px); } }
@media (max-width: 599px) {
  .toasts { left: 5%; right: 5%; bottom: var(--s4); align-items: center; }
  .toast { max-width: 100%; }
}

/* ---------- 7f. Modals ---------- */
.overlay {
  position: fixed; inset: 0; z-index: 100;
  background: var(--scrim);
  display: grid; place-items: center; padding: var(--s4);
  animation: fade-in var(--d-short) var(--ease) both;
}
.overlay.leaving { animation: fade-out var(--d-short) var(--ease) both; }
.modal {
  width: 100%; max-width: 480px;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r-lg);
  padding: var(--s8); box-shadow: var(--e3);
  animation: modal-in var(--d-medium) var(--ease) both;
}
.overlay.leaving .modal { animation: modal-out var(--d-short) var(--ease) both; }
.modal.modal-wide { max-width: 600px; }
.modal-head { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s4); padding-bottom: var(--s4); border-bottom: 1px solid var(--hairline); margin-bottom: var(--s6); }
.modal-head .icon-btn { margin: -10px -10px 0 0; color: var(--gray-muted); }
.modal-head .icon-btn:hover { color: var(--ink); }
.modal-body { color: var(--gray); max-height: 60vh; overflow-y: auto; }
.modal-foot { display: flex; justify-content: flex-end; gap: var(--s3); margin-top: var(--s6); flex-wrap: wrap; }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(16px); } to { opacity: 1; transform: none; } }
@keyframes modal-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: translateY(8px); } }
@media (max-width: 599px) {
  .modal { width: 90vw; padding: var(--s6); }
  .modal-foot .btn { flex: 1; }
}

/* ---------- 7h. Progress ---------- */
.progress-label { font-size: 13px; line-height: 1.5; color: var(--gray); margin-bottom: var(--s2); }
.progress { height: 4px; background: var(--hairline); border-radius: var(--r-pill); overflow: hidden; }
.progress-fill { height: 100%; width: 0; background: var(--ink); border-radius: var(--r-pill); transition: width var(--d-medium) linear; }

.steps { display: flex; align-items: flex-start; list-style: none; margin: 0; padding: 0; }
.step { display: flex; flex-direction: column; align-items: center; flex: none; width: 24px; position: relative; }
.step-node {
  width: 24px; height: 24px; border-radius: 50%;
  border: 2px solid var(--line); background: var(--card); color: var(--gray-muted);
  display: grid; place-items: center;
  transition: background-color var(--d-short) var(--ease), border-color var(--d-short) var(--ease), color var(--d-short) var(--ease);
}
.step-node .ti { font-size: 14px; }
.step.done .step-node { background: var(--ok); border-color: var(--ok); color: #fff; }
.step.current .step-node { border-color: var(--ink); }
.step.current .step-node::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--ink); }
.step-label { position: absolute; top: 32px; white-space: nowrap; color: var(--gray-muted); }
.step:not(:first-child):not(:last-child) .step-label { left: 50%; transform: translateX(-50%); }
.step:first-child .step-label { left: 0; }
.step:last-child .step-label { right: 0; }
.step.done .step-label { color: var(--gray); }
.step.current .step-label { color: var(--ink); }
.step-line { flex: 1; height: 2px; margin: 11px 6px 0; border-radius: 2px; background: var(--line); transition: background-color var(--d-medium) var(--ease); }
.step-line.done { background: var(--ok); }

.spinner {
  display: inline-block; flex: none;
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(62,110,140,.25); border-top-color: var(--action);
  animation: spin 800ms linear infinite;
}
.spinner.lg { width: 32px; height: 32px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) {
  .spinner { animation: none; border-color: var(--action); border-right-color: rgba(62,110,140,.25); }
}
.status { display: flex; align-items: center; gap: var(--s2); font-size: 13px; line-height: 1.5; color: var(--gray); }
.status .ti { font-size: 16px; }
.status.success { color: var(--ink); }
.status.success .ti { color: var(--ok); }

.skeleton {
  background: var(--hairline); border-radius: var(--r-md); position: relative; overflow: hidden;
}
.skeleton::after {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, rgba(255,255,255,.6), transparent);
  transform: translateX(-100%); animation: shimmer 1.5s linear infinite;
}
@keyframes shimmer { to { transform: translateX(100%); } }
@media (prefers-reduced-motion: reduce) { .skeleton::after { display: none; } }

/* ---------- 7i. Empty states ---------- */
.empty {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; min-height: 400px; padding: var(--s8) var(--s4);
}
.empty > .ti { font-size: 48px; color: var(--thunder-light); margin-bottom: var(--s4); }
.empty-title { max-width: 320px; margin-bottom: var(--s2); }
.empty-body { max-width: 360px; color: var(--gray); }
.empty .btn { margin-top: var(--s6); }

/* ---------- Toggle switch ---------- */
.switch {
  position: relative; flex: none; width: 51px; height: 31px; padding: 0;
  border: 0; border-radius: var(--r-pill); background: var(--line); cursor: pointer;
  transition: background-color var(--d-short) var(--ease);
}
.switch::before { content: ""; position: absolute; inset: -7px -2px; } /* 44px touch target */
.switch-knob {
  position: absolute; top: 2px; left: 2px; width: 27px; height: 27px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 4px rgba(0,0,0,.2);
  transition: transform var(--d-short) var(--ease);
}
.switch[aria-checked="true"] { background: var(--ok); }
.switch[aria-checked="true"] .switch-knob { transform: translateX(20px); }
.switch:disabled { opacity: .45; cursor: not-allowed; }

/* ---------- Action menu (IDL 7e) ---------- */
.menu {
  position: fixed; z-index: 120; min-width: 200px; padding: var(--s1);
  background: var(--card); border: 1px solid var(--hairline); border-radius: var(--r-md);
  box-shadow: 0 12px 32px rgba(0,0,0,.14);
  animation: menu-in var(--d-short) var(--ease) both;
}
@keyframes menu-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.menu-item {
  display: flex; align-items: center; gap: var(--s3); width: 100%; min-height: 40px;
  padding: 0 var(--s3); border: 0; border-radius: var(--r-sm); background: transparent;
  color: var(--ink); font-size: 15px; text-align: left; cursor: pointer;
}
.menu-item .ti { font-size: 18px; color: var(--gray); }
.menu-item:hover, .menu-item:focus-visible { background: var(--panel); outline: none; }
.menu-item.danger, .menu-item.danger .ti { color: var(--err-text); }
.menu-item.danger:hover, .menu-item.danger:focus-visible { background: var(--err-tint); }
.menu-divider { height: 1px; margin: var(--s1) 0; background: var(--hairline); }
