/* Reusable components */

/* ---- Buttons ------------------------------------------------------------ */
.btn {
  --btn-bg: var(--surface-2);
  --btn-fg: var(--text);
  --btn-border: var(--border);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 46px;
  padding: 0 20px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--btn-border);
  background: var(--btn-bg);
  color: var(--btn-fg);
  font-weight: 650;
  font-size: .95rem;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  position: relative;
  transition: transform var(--dur) var(--ease), background-color var(--dur), border-color var(--dur), box-shadow var(--dur), opacity var(--dur);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.btn:hover { text-decoration: none; border-color: var(--border-strong); }
.btn:active { transform: scale(.98); }
.btn[disabled], .btn[aria-disabled="true"] { opacity: .55; cursor: not-allowed; transform: none; }

.btn-primary {
  --btn-bg: var(--primary);
  --btn-fg: var(--on-primary);
  --btn-border: transparent;
  box-shadow: 0 6px 16px -8px var(--primary);
}
.btn-primary:hover { background: var(--primary-hover); border-color: transparent; transform: translateY(-1px); }
.btn-primary:active { transform: scale(.98); }

.btn-secondary { --btn-bg: var(--surface); --btn-border: var(--border-strong); }
.btn-secondary:hover { background: var(--surface-2); }

.btn-ghost { --btn-bg: transparent; --btn-border: transparent; }
.btn-ghost:hover { background: var(--surface-2); border-color: transparent; }

.btn-soft { --btn-bg: var(--primary-soft); --btn-fg: var(--primary-ink); --btn-border: color-mix(in srgb, var(--primary) 45%, transparent); }
.btn-soft:hover {
  --btn-bg: var(--primary);
  --btn-fg: var(--on-primary);
  --btn-border: transparent;
  transform: translateY(-1px);
  box-shadow: 0 8px 18px -10px var(--primary);
}
.btn-soft:active { transform: scale(.98); }
.btn-soft.is-loading::after { border-color: var(--primary-ink); border-right-color: transparent; }

.btn-danger { --btn-bg: var(--danger-soft); --btn-fg: var(--danger); --btn-border: transparent; }
.btn-danger:hover { filter: brightness(.96); border-color: transparent; }
.btn-danger-solid { --btn-bg: var(--danger); --btn-fg: #fff; --btn-border: transparent; }

.btn-sm { min-height: 38px; padding: 0 14px; font-size: .86rem; border-radius: 9px; }
.btn-lg { min-height: 54px; padding: 0 28px; font-size: 1rem; border-radius: 13px; }
.btn-block { width: 100%; }
.btn-icon { width: 44px; min-height: 44px; padding: 0; }
.btn-icon.btn-sm { width: 38px; min-height: 38px; }

.btn.is-loading { color: transparent !important; pointer-events: none; }
.btn.is-loading::after {
  content: "";
  position: absolute;
  width: 20px; height: 20px;
  border-radius: 50%;
  border: 2.5px solid var(--btn-fg);
  border-right-color: transparent;
  animation: spin .7s linear infinite;
  color: var(--btn-fg);
}
.btn.is-loading::after { border-color: currentColor; border-right-color: transparent; }
.btn-primary.is-loading::after { border-color: var(--on-primary); border-right-color: transparent; }
.btn-secondary.is-loading::after, .btn-ghost.is-loading::after, .btn.is-loading:not(.btn-primary)::after { border-color: var(--text); border-right-color: transparent; }

/* ---- Forms -------------------------------------------------------------- */
.form { display: flex; flex-direction: column; gap: 18px; }
.field { display: flex; flex-direction: column; gap: 7px; min-width: 0; }
.field > label, .label {
  font-size: .86rem;
  font-weight: 600;
  color: var(--text-2);
}
.field .hint { font-size: .8rem; color: var(--text-muted); }
.field .error {
  display: none;
  align-items: flex-start;
  gap: 6px;
  font-size: .82rem;
  font-weight: 550;
  color: var(--danger);
}
.field.has-error .error { display: flex; }

.input-wrap {
  position: relative;
  display: flex;
  align-items: center;
  background: var(--surface-2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  transition: border-color var(--dur), box-shadow var(--dur), background-color var(--dur);
}
.input-wrap:hover { border-color: var(--border-strong); }
.input-wrap:focus-within {
  background: var(--surface);
  border-color: var(--primary);
  box-shadow: 0 0 0 4px var(--primary-soft);
}
.field.has-error .input-wrap { border-color: var(--danger); background: var(--surface); }
.field.has-error .input-wrap:focus-within { box-shadow: 0 0 0 4px var(--danger-soft); }

.input-wrap > .icon-lead {
  position: absolute;
  left: 8px;
  top: 50%;
  width: 34px; height: 34px;
  transform: translateY(-50%);
  display: grid; place-items: center;
  border-radius: 9px;
  background: var(--surface);
  color: var(--primary-ink);
  pointer-events: none;
  box-shadow: var(--shadow-sm);
}
.input-wrap > .icon-lead .icon { width: 18px; height: 18px; }
.input-wrap > .prefix {
  padding-left: 16px;
  font-weight: 700;
  color: var(--text-muted);
  font-size: 1.1rem;
}

.input, .select, .textarea {
  width: 100%;
  min-width: 0;
  min-height: 50px;
  padding: 0 16px;
  border: 0;
  background: transparent;
  color: var(--text);
  font: inherit;
  font-size: 1rem; /* 16px prevents iOS zoom on focus */
  border-radius: var(--radius-sm);
}
.input::placeholder, .textarea::placeholder { color: var(--text-muted); opacity: .75; }
.input-wrap.has-icon .input { padding-left: 54px; }
.input-wrap.has-toggle .input { padding-right: 52px; }
.input:focus, .select:focus, .textarea:focus { outline: none; }
.input:disabled { opacity: .6; cursor: not-allowed; }
.input[readonly] { color: var(--text-muted); }
.input-lg { min-height: 60px; font-size: 1.5rem; font-weight: 700; letter-spacing: -0.02em; }

.textarea { padding: 14px 16px; min-height: 120px; resize: vertical; line-height: 1.5; }
.select {
  appearance: none;
  -webkit-appearance: none;
  padding-right: 42px;
  cursor: pointer;
}
.select option { color: #111; background: #fff; }
.input-wrap.is-select::after {
  content: "";
  position: absolute;
  right: 18px; top: 50%;
  width: 8px; height: 8px;
  border-right: 2px solid var(--text-muted);
  border-bottom: 2px solid var(--text-muted);
  transform: translateY(-70%) rotate(45deg);
  pointer-events: none;
}
.input-wrap.has-icon .select { padding-left: 54px; }

.toggle-vis {
  position: absolute;
  right: 6px; top: 50%;
  transform: translateY(-50%);
  width: 42px; height: 42px;
  display: grid; place-items: center;
  border: 0; background: transparent;
  color: var(--text-muted);
  border-radius: 10px;
}
.toggle-vis:hover { color: var(--text); background: var(--surface-3); }

/* checkbox & radio */
.check {
  display: flex;
  align-items: flex-start;
  gap: 11px;
  cursor: pointer;
  font-size: .92rem;
  color: var(--text-2);
  line-height: 1.45;
  position: relative;
}
.check input { position: absolute; opacity: 0; width: 22px; height: 22px; margin: 0; cursor: pointer; }
.check .box {
  flex: none;
  width: 22px; height: 22px;
  border-radius: 7px;
  border: 1.5px solid var(--border-strong);
  background: var(--surface);
  display: grid; place-items: center;
  transition: all var(--dur) var(--ease);
  margin-top: 1px;
}
.check .box .icon { width: 14px; height: 14px; stroke-width: 3; color: var(--on-primary); transform: scale(0); transition: transform var(--dur) var(--ease); }
.check input:checked + .box { background: var(--primary); border-color: var(--primary); }
.check input:checked + .box .icon { transform: scale(1); }
.check input:focus-visible + .box { outline: 2px solid var(--focus); outline-offset: 2px; }
.field.has-error > .check .box { border-color: var(--danger); }

/* switch */
.switch { position: relative; display: inline-block; flex: none; width: 48px; height: 28px; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; width: 100%; height: 100%; }
.switch .track {
  position: absolute; inset: 0;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  transition: background-color var(--dur), border-color var(--dur);
}
.switch .track::after {
  content: "";
  position: absolute;
  top: 3px; left: 3px;
  width: 20px; height: 20px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, .3);
  transition: transform var(--dur) var(--ease);
}
.switch input:checked + .track { background: var(--primary); border-color: var(--primary); }
.switch input:checked + .track::after { transform: translateX(20px); }
.switch input:focus-visible + .track { outline: 2px solid var(--focus); outline-offset: 2px; }

/* selectable option cards (radio-style) */
.option-grid { display: grid; gap: 10px; grid-template-columns: 1fr; }
.option {
  position: relative;
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 14px;
  border-radius: var(--radius-sm);
  border: 1.5px solid var(--border);
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--dur), background-color var(--dur), box-shadow var(--dur);
}
.option:hover { border-color: var(--border-strong); }
.option input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: pointer; width: 100%; height: 100%; }
.option .opt-icon {
  width: 40px; height: 40px; flex: none;
  display: grid; place-items: center;
  border-radius: 12px;
  background: var(--primary-soft);
  color: var(--primary-ink);
}
.option .opt-title { font-weight: 650; }
.option .opt-sub { font-size: .82rem; color: var(--text-muted); }
.option .opt-check {
  margin-left: auto; flex: none;
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1.5px solid var(--border-strong);
  display: grid; place-items: center;
  color: transparent;
}
.option .opt-check .icon { width: 13px; height: 13px; stroke-width: 3; }
.option:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); box-shadow: 0 0 0 3px var(--primary-soft); }
.option:has(input:checked) .opt-check { background: var(--primary); border-color: var(--primary); color: var(--on-primary); }
.option:has(input:focus-visible) { outline: 2px solid var(--focus); outline-offset: 2px; }

/* password strength */
.strength { display: flex; gap: 6px; align-items: center; margin-top: 2px; }
.strength .bars { display: grid; grid-template-columns: repeat(4, 1fr); gap: 4px; flex: 1; }
.strength .bars span { height: 5px; border-radius: 4px; background: var(--surface-3); transition: background-color var(--dur); }
.strength[data-score="1"] .bars span:nth-child(-n+1) { background: var(--danger); }
.strength[data-score="2"] .bars span:nth-child(-n+2) { background: var(--warning); }
.strength[data-score="3"] .bars span:nth-child(-n+3) { background: var(--info); }
.strength[data-score="4"] .bars span:nth-child(-n+4) { background: var(--success); }
.strength .txt { font-size: .78rem; font-weight: 600; color: var(--text-muted); min-width: 52px; text-align: right; }

/* form-level alert */
.alert {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  padding: 13px 15px;
  border-radius: var(--radius-sm);
  font-size: .9rem;
  line-height: 1.45;
  border: 1px solid transparent;
}
.alert .icon { margin-top: 1px; }
.alert-error { background: var(--danger-soft); color: var(--danger); border-color: color-mix(in srgb, var(--danger) 25%, transparent); }
.alert-success { background: var(--success-soft); color: var(--success); border-color: color-mix(in srgb, var(--success) 25%, transparent); }
.alert-info { background: var(--info-soft); color: var(--info); border-color: color-mix(in srgb, var(--info) 25%, transparent); }
.alert-warn { background: var(--warning-soft); color: var(--warning); border-color: color-mix(in srgb, var(--warning) 25%, transparent); }
.alert strong { color: inherit; }
.alert a { color: inherit; font-weight: 700; text-decoration: underline; }

/* ---- Cards -------------------------------------------------------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  min-width: 0;
}
.card-pad { padding: 18px; }
.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 18px 18px 0;
  flex-wrap: wrap;
}
.card-head h2, .card-head h3 { font-size: 1.05rem; }
.card-head .sub { font-size: .84rem; color: var(--text-muted); margin-top: 2px; }
.card-body { padding: 18px; }
.card-hover { transition: transform var(--dur) var(--ease), box-shadow var(--dur) var(--ease), border-color var(--dur); }
.card-hover:hover { transform: translateY(-3px); box-shadow: var(--shadow); border-color: var(--border-strong); }

@media (min-width: 768px) {
  .card-pad, .card-body { padding: 22px; }
  .card-head { padding: 22px 22px 0; }
}

/* ---- Badges ------------------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: var(--radius-pill);
  font-size: .75rem;
  font-weight: 700;
  line-height: 1.5;
  background: var(--surface-3);
  color: var(--text-2);
  white-space: nowrap;
}
.badge .icon { width: 13px; height: 13px; }
.badge-success { background: var(--success-soft); color: var(--success); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-warning { background: var(--warning-soft); color: var(--warning); }
.badge-info { background: var(--info-soft); color: var(--info); }
.badge-primary { background: var(--primary-soft); color: var(--primary-ink); }

/* ---- Tabs / segmented --------------------------------------------------- */
.tabs {
  display: flex;
  gap: 4px;
  overflow-x: auto;
  scrollbar-width: none;
  border-bottom: 1px solid var(--border);
  -webkit-overflow-scrolling: touch;
}
.tabs::-webkit-scrollbar { display: none; }
.tab {
  position: relative;
  flex: none;
  min-height: 46px;
  padding: 0 14px;
  border: 0;
  background: transparent;
  color: var(--text-muted);
  font-weight: 650;
  font-size: .92rem;
  white-space: nowrap;
  transition: color var(--dur);
}
.tab::after {
  content: "";
  position: absolute;
  left: 10px; right: 10px; bottom: -1px;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: var(--primary);
  transform: scaleX(0);
  transition: transform var(--dur) var(--ease);
}
.tab:hover { color: var(--text); }
.tab[aria-selected="true"] { color: var(--text); }
.tab[aria-selected="true"]::after { transform: scaleX(1); }
.tab .count { margin-left: 6px; font-size: .74rem; padding: 1px 7px; border-radius: 99px; background: var(--surface-3); color: var(--text-2); }

.seg {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 12px;
  max-width: 100%;
  overflow-x: auto;
  scrollbar-width: none;
}
.seg::-webkit-scrollbar { display: none; }
.seg button {
  flex: none;
  min-height: 34px;
  padding: 0 12px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--text-muted);
  font-weight: 650;
  font-size: .82rem;
  transition: background-color var(--dur), color var(--dur), box-shadow var(--dur);
}
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"], .seg button[aria-selected="true"] {
  background: var(--surface);
  color: var(--text);
  box-shadow: var(--shadow-sm);
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  min-height: 38px;
  padding: 0 14px;
  border-radius: var(--radius-pill);
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-2);
  font-weight: 600;
  font-size: .86rem;
  transition: all var(--dur) var(--ease);
}
.chip:hover { border-color: var(--border-strong); }
.chip[aria-pressed="true"] { background: var(--primary); color: var(--on-primary); border-color: var(--primary); }

/* ---- Progress ----------------------------------------------------------- */
.progress { height: 8px; border-radius: 99px; background: var(--surface-3); overflow: hidden; }
.progress > span {
  display: block;
  height: 100%;
  width: var(--p, 0%);
  border-radius: 99px;
  background: var(--primary);
  transition: width .9s var(--ease);
}

/* ---- Lists -------------------------------------------------------------- */
.list > li + li { border-top: 1px solid var(--border); }
.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 13px 0;
  min-width: 0;
}
.list-item .grow { flex: 1 1 auto; min-width: 0; }
.list-item .title { font-weight: 650; font-size: .95rem; }
.list-item .meta { font-size: .8rem; color: var(--text-muted); }
.list-item .end { text-align: right; flex: none; }
button.list-item, a.list-item {
  width: 100%;
  background: transparent;
  border: 0;
  text-align: left;
  color: inherit;
  text-decoration: none;
  cursor: pointer;
  border-radius: var(--radius-sm);
}
button.list-item:hover, a.list-item:hover { background: var(--surface-2); text-decoration: none; }

.avatar-icon {
  width: 42px; height: 42px; flex: none;
  display: grid; place-items: center;
  border-radius: 13px;
  background: var(--surface-3);
  color: var(--text-2);
}
.avatar-icon.pos-bg { background: var(--success-soft); color: var(--success); }
.avatar-icon.neg-bg { background: var(--danger-soft); color: var(--danger); }
.avatar-icon.pri-bg { background: var(--primary-soft); color: var(--primary-ink); }
.avatar-icon.info-bg { background: var(--info-soft); color: var(--info); }
.avatar-icon.warn-bg { background: var(--warning-soft); color: var(--warning); }

.avatar {
  --size: 40px;
  width: var(--size); height: var(--size);
  border-radius: 50%;
  display: grid; place-items: center;
  flex: none;
  font-weight: 800;
  font-size: calc(var(--size) * .38);
  color: #fff;
  background: var(--avatar-bg, var(--primary));
  letter-spacing: .02em;
  user-select: none;
}

/* ---- Empty state / skeleton -------------------------------------------- */
.empty {
  text-align: center;
  padding: 36px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.empty .empty-icon {
  width: 60px; height: 60px;
  display: grid; place-items: center;
  border-radius: 20px;
  background: var(--primary-soft);
  color: var(--primary-ink);
  margin-bottom: 6px;
}
.empty .empty-icon .icon { width: 28px; height: 28px; }
.empty h3 { font-size: 1.05rem; }
.empty p { color: var(--text-muted); max-width: 40ch; font-size: .92rem; }
.empty .btn { margin-top: 10px; }

.skeleton {
  border-radius: var(--radius-sm);
  background: linear-gradient(90deg, var(--surface-2) 25%, var(--surface-3) 50%, var(--surface-2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.3s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- Modal -------------------------------------------------------------- */
.modal-backdrop {
  position: fixed; inset: 0;
  z-index: 200;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: var(--scrim);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: fade-in .2s ease;
  padding: 0;
}
.modal {
  width: 100%;
  max-width: 520px;
  max-height: 92dvh;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg) var(--radius-lg) 0 0;
  box-shadow: var(--shadow-lg);
  animation: sheet-up .32s var(--ease);
  padding-bottom: var(--safe-bottom);
}
.modal-lg { max-width: 680px; }
@keyframes sheet-up { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  padding: 20px 20px 0;
}
.modal-head h2 { font-size: 1.2rem; }
.modal-head .sub { font-size: .86rem; color: var(--text-muted); margin-top: 3px; }
.modal-body { padding: 18px 20px; overflow-y: auto; overscroll-behavior: contain; }
.modal-foot {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  padding: 14px 20px 20px;
  flex-wrap: wrap;
}
.modal-foot .btn { flex: 1 1 auto; }

@media (min-width: 640px) {
  .modal-backdrop { align-items: center; padding: 24px; }
  .modal { border-radius: var(--radius-lg); animation: pop .28s var(--ease); }
  .modal-foot .btn { flex: 0 0 auto; }
}

/* ---- Toasts ------------------------------------------------------------- */
.toast-root {
  position: fixed;
  z-index: 300;
  left: 12px; right: 12px;
  top: calc(12px + var(--safe-top));
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
  align-items: center;
}
.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: min(100%, 420px);
  padding: 13px 14px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border);
  border-left: 4px solid var(--info);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  animation: pop .3s var(--ease);
  font-size: .9rem;
}
.toast.out { opacity: 0; transform: translateY(-8px); transition: all .25s ease; }
.toast .icon { margin-top: 1px; color: var(--info); }
.toast-success { border-left-color: var(--success); } .toast-success .icon { color: var(--success); }
.toast-error { border-left-color: var(--danger); } .toast-error .icon { color: var(--danger); }
.toast-warning { border-left-color: var(--warning); } .toast-warning .icon { color: var(--warning); }
.toast .t-title { font-weight: 700; }
.toast .t-msg { color: var(--text-2); }
.toast button { margin-left: auto; border: 0; background: transparent; color: var(--text-muted); padding: 2px; border-radius: 6px; }
@media (min-width: 768px) {
  .toast-root { left: auto; right: 20px; top: 20px; align-items: flex-end; }
}

/* ---- Popover / dropdown ------------------------------------------------- */
.popover-wrap { position: relative; display: inline-flex; }
.popover {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 80;
  min-width: 220px;
  padding: 8px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-lg);
  animation: pop .2s var(--ease);
}
.popover[hidden] { display: none; }
.popover .pop-head { padding: 10px 12px 12px; border-bottom: 1px solid var(--border); margin-bottom: 6px; }
.pop-item {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  min-height: 44px;
  padding: 0 12px;
  border: 0;
  background: transparent;
  border-radius: var(--radius-sm);
  color: var(--text);
  font-weight: 600;
  font-size: .92rem;
  text-align: left;
  text-decoration: none;
}
.pop-item:hover { background: var(--surface-2); text-decoration: none; }
.pop-item .icon { color: var(--text-muted); }
.pop-item.danger, .pop-item.danger .icon { color: var(--danger); }
.pop-item .swatch { margin-left: auto; }

/* ---- Theme swatches ----------------------------------------------------- */
.theme-dot {
  width: 22px; height: 22px;
  border-radius: 50%;
  border: 1px solid var(--border-strong);
  flex: none;
  background: var(--dot-bg);
  position: relative;
}
.theme-dot::after {
  content: "";
  position: absolute;
  inset: 5px;
  border-radius: 50%;
  background: var(--dot-fg);
}
.theme-dot[data-t="lemon"] { --dot-bg: #F4F9E4; --dot-fg: #8DC21F; }
.theme-dot[data-t="black"] { --dot-bg: #0B0B0C; --dot-fg: #E2C16B; }
.theme-dot[data-t="white"] { --dot-bg: #FFFFFF; --dot-fg: #1F6FEB; }

.theme-switch {
  display: inline-flex;
  padding: 3px;
  gap: 2px;
  border-radius: var(--radius-pill);
  background: var(--surface-2);
  border: 1px solid var(--border);
}
.theme-switch button {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  border: 2px solid transparent;
  background: transparent;
  border-radius: 50%;
  padding: 0;
  transition: border-color var(--dur), background-color var(--dur);
}
.theme-switch button[aria-pressed="true"] { border-color: var(--primary); background: var(--surface); }
.theme-switch button:hover { background: var(--surface); }

/* ---- Accordion ---------------------------------------------------------- */
.accordion { display: flex; flex-direction: column; gap: 10px; }
.acc-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color var(--dur);
}
.acc-item[data-open="true"] { border-color: var(--border-strong); }
.acc-trigger {
  display: flex; align-items: center; gap: 12px;
  width: 100%;
  min-height: 56px;
  padding: 12px 16px;
  border: 0; background: transparent;
  text-align: left;
  font-weight: 650;
  font-size: .96rem;
}
.acc-trigger .icon { margin-left: auto; transition: transform var(--dur) var(--ease); color: var(--text-muted); }
.acc-item[data-open="true"] .acc-trigger .icon { transform: rotate(180deg); }
.acc-panel { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .3s var(--ease); }
.acc-item[data-open="true"] .acc-panel { grid-template-rows: 1fr; }
.acc-panel > div { overflow: hidden; }
.acc-panel p { padding: 0 16px 16px; color: var(--text-2); font-size: .94rem; }

/* ---- Key/value ---------------------------------------------------------- */
.kv { display: flex; justify-content: space-between; gap: 16px; padding: 10px 0; font-size: .92rem; }
.kv + .kv { border-top: 1px solid var(--border); }
.kv dt, .kv .k { color: var(--text-muted); }
.kv dd, .kv .v { margin: 0; font-weight: 650; text-align: right; min-width: 0; overflow-wrap: anywhere; }
dl.kv-list { margin: 0; }

/* ---- Chart bits --------------------------------------------------------- */
.chart { position: relative; width: 100%; min-width: 0; }
.chart svg { display: block; overflow: visible; }
.chart-tip {
  position: absolute;
  z-index: 5;
  pointer-events: none;
  min-width: 130px;
  padding: 9px 11px;
  border-radius: 10px;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  box-shadow: var(--shadow);
  font-size: .8rem;
  opacity: 0;
  transform: translateY(4px);
  transition: opacity .12s, transform .12s;
}
.chart-tip.show { opacity: 1; transform: none; }
.chart-tip .tt-head { color: var(--text-muted); font-size: .74rem; font-weight: 600; margin-bottom: 3px; }
.chart-tip .tt-row { display: flex; align-items: center; gap: 8px; }
.chart-tip .tt-key { width: 10px; height: 3px; border-radius: 2px; flex: none; }
.chart-tip .tt-val { font-weight: 800; color: var(--text); font-variant-numeric: tabular-nums; }
.chart-tip .tt-name { color: var(--text-2); margin-left: auto; padding-left: 8px; }

.legend { display: flex; flex-direction: column; gap: 4px; }
.legend-row {
  display: grid;
  grid-template-columns: 12px minmax(0, 1fr) auto auto;
  gap: 10px;
  align-items: center;
  padding: 8px 8px;
  border-radius: 10px;
  font-size: .88rem;
  transition: background-color var(--dur);
}
.legend-row:hover, .legend-row.on { background: var(--surface-2); }
.legend-row .key { width: 12px; height: 12px; border-radius: 4px; }
.legend-row .nm { font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.legend-row .val { font-weight: 700; font-variant-numeric: tabular-nums; }
.legend-row .pc { color: var(--text-muted); min-width: 44px; text-align: right; font-variant-numeric: tabular-nums; font-size: .82rem; }

.donut-center {
  position: absolute;
  inset: 0;
  display: grid;
  place-content: center;
  text-align: center;
  pointer-events: none;
}
.donut-center .dc-label { font-size: .75rem; color: var(--text-muted); font-weight: 600; }
.donut-center .dc-value { font-size: 1.15rem; font-weight: 800; letter-spacing: -0.02em; }
