/* mail2api dashboard — component layer.
   The shared building blocks every page draws with. The look follows Apple's Human Interface
   Guidelines (macOS controls: filled buttons, segmented controls, switches, translucent menus),
   informed by Puppertino (MIT, https://github.com/codedgar/Puppertino) and the earlier shadcn/ui
   port Basecoat (MIT); no code is copied and nothing loads from a CDN. Every colour, radius and
   size comes from the tokens at the top of styles.css, the single source for both themes.
   This file loads before styles.css, so a page rule may place a component (width, flex, margin)
   but should not restyle it. */

/* ---------- form controls ----------
   Native inputs, selects and textareas need no class. Size is inherited through --control-h /
   --control-fs; zero specificity (:where) keeps page layout rules in charge of width. */
:where(input:not([type="checkbox"], [type="radio"], [type="file"], [type="range"], [type="color"], [type="hidden"]), select, textarea) {
  font-family: inherit; font-weight: 400; height: var(--control-h); padding: 0 10px; border: 1px solid var(--line-strong); border-radius: var(--radius-control);
  background-color: var(--surface); color: var(--text); font-size: var(--control-fs); line-height: 1.4; box-shadow: var(--shadow-xs);
  transition: border-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease); }
/* textareas here always hold data (cookies, lists, URLs, JSON): monospace reads it best */
:where(textarea) { height: auto; padding: 8px 10px; font-family: var(--mono); font-size: 12.5px; line-height: 1.55; }
/* pop-up button: the macOS up/down chevron */
:where(select) { appearance: none; padding-right: 26px; cursor: pointer; background-repeat: no-repeat; background-position: right 8px center; background-size: 10px 14px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 10 14' fill='none' stroke='%238e8e93' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m2 5 3-3 3 3M2 9l3 3 3-3'/%3E%3C/svg%3E"); }
:where(input, textarea)::placeholder { color: var(--faint); opacity: 1; }
:where(input:not([type="checkbox"], [type="radio"]), select, textarea):focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3.5px var(--ring); }
:where(input[readonly], textarea[readonly]) { background-color: var(--surface-2); box-shadow: none; }
:where(input:not([type="checkbox"], [type="radio"]), select, textarea):disabled { cursor: not-allowed; opacity: .55; background-color: var(--surface-2); box-shadow: none; }
:where(input, select, textarea)[aria-invalid="true"] { border-color: var(--err); }
:where(input, select, textarea)[aria-invalid="true"]:focus { box-shadow: 0 0 0 3.5px color-mix(in srgb, var(--err) 30%, transparent); }
:where(input[type="checkbox"], input[type="radio"]) { flex: none; width: 15px; height: 15px; margin: 0; accent-color: var(--accent); cursor: pointer; }
:where(input[type="checkbox"], input[type="radio"]):disabled { cursor: not-allowed; }
:where(input[type="checkbox"], input[type="radio"]):focus-visible { outline: 3px solid var(--ring); outline-offset: 1px; }

/* switch: a settings toggle (<label class="fwd__check"><input type="checkbox"> text</label>) renders as an
   Apple switch; selection checkboxes in tables stay checkboxes. */
.fwd__check { display: inline-flex; align-items: center; gap: 8px; color: var(--text); font-size: 12.5px; font-weight: 500; cursor: pointer; }
.fwd__check > input[type="checkbox"] { appearance: none; position: relative; flex: none; width: 32px; height: 19px; margin: 0; border-radius: 999px; background: var(--fill-2);
  cursor: pointer; transition: background-color var(--dur) var(--ease); }
.fwd__check > input[type="checkbox"]::before { content: ""; position: absolute; top: 2px; left: 2px; width: 15px; height: 15px; border-radius: 50%; background: #fff;
  box-shadow: 0 1px 2px rgba(0,0,0,.2), 0 0 0 .5px rgba(0,0,0,.04); transition: transform var(--dur) var(--ease); }
.fwd__check > input[type="checkbox"]:checked { background: var(--ok); }
.fwd__check > input[type="checkbox"]:checked::before { transform: translateX(13px); }
.fwd__check > input[type="checkbox"]:disabled { opacity: .45; }

/* search field: the macOS rounded, filled search box */
.search { display: flex; align-items: center; gap: 6px; height: var(--control-h); padding: 0 10px; border: 1px solid transparent; border-radius: var(--radius-control);
  background: var(--fill); color: var(--faint); transition: background-color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), border-color var(--dur-fast) var(--ease); }
.search:hover { background: var(--fill-2); }
.search:focus-within { background: var(--surface); border-color: var(--accent); box-shadow: 0 0 0 3.5px var(--ring); color: var(--muted); }
.search > svg { flex: none; width: 14px; height: 14px; }
.search input { flex: 1; min-width: 0; height: auto; padding: 0; border: 0; border-radius: 0; background: transparent; box-shadow: none; outline: 0; }
.search input:focus { box-shadow: none; }

/* ---------- badge ----------
   One badge for every status, tag and count-like label. --b is the tone; state maps only set it. */
.badge { --b: var(--faint); display: inline-flex; align-items: center; gap: 5px; flex: none; height: 20px; padding: 0 8px; border: 0; border-radius: 999px;
  background: color-mix(in srgb, var(--b) 14%, transparent); color: color-mix(in srgb, var(--b) 78%, var(--text)); font-size: 11px; font-weight: 600; line-height: 1; white-space: nowrap; }
.badge.is-ok { --b: var(--ok); }
.badge.is-info { --b: var(--accent); }
.badge.is-warn { --b: var(--warn); }
.badge.is-err { --b: var(--err); }
.badge--dot::before { content: ""; flex: none; width: 6px; height: 6px; border-radius: 50%; background: var(--b); }
/* a capability that is absent: outline only */
.badge--off { background: transparent; box-shadow: inset 0 0 0 1px var(--line-strong); color: var(--faint); }
button.badge { cursor: pointer; transition: background-color var(--dur-fast) var(--ease); }
button.badge:hover { background: color-mix(in srgb, var(--b) 22%, transparent); }
button.badge:focus-visible { outline: 3px solid var(--ring); outline-offset: 1px; }

/* ---------- alert ----------
   Inline feedback: neutral by default, toned with is-ok / is-info / is-warn / is-err. */
.alert { --a: var(--faint); display: flex; align-items: flex-start; gap: 8px; margin: 0; padding: 9px 12px; border: 0; border-radius: var(--radius-sm);
  background: var(--fill); color: var(--text); font-size: 12.5px; line-height: 1.5; overflow-wrap: anywhere; }
.alert.is-ok { --a: var(--ok); }
.alert.is-info { --a: var(--accent); }
.alert.is-warn { --a: var(--warn); }
.alert.is-err { --a: var(--err); }
.alert:is(.is-ok, .is-info, .is-warn, .is-err) { background: color-mix(in srgb, var(--a) 11%, var(--surface)); color: color-mix(in srgb, var(--a) 80%, var(--text)); }

/* ---------- button ----------
   macOS push buttons: neutral ones are a soft fill, the primary one the accent. Heights follow the
   control scale (34 / 30 / 26px) so buttons and fields on one row line up. */
.btn { --btn-h: var(--control-h); display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: var(--btn-h); padding: 0 13px;
  border: 0; border-radius: var(--radius-control); background: var(--fill); color: var(--text); font-size: 13px; font-weight: 500; line-height: 1;
  white-space: nowrap; text-decoration: none; transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease), box-shadow var(--dur-fast) var(--ease), transform .12s var(--ease); }
.btn:hover { background: var(--fill-2); }
.btn:active { transform: scale(.97); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 3.5px var(--ring); }
.btn--primary { background: var(--accent); color: var(--accent-ink); box-shadow: 0 1px 2px color-mix(in srgb, var(--accent) 30%, transparent); }
.btn--primary:hover { background: color-mix(in srgb, var(--accent) 90%, black); }
.btn--ghost { background: transparent; color: var(--muted); }
.btn--ghost:hover { background: var(--fill); color: var(--text); }
.btn--danger { color: var(--err); }
.btn--danger:hover { background: color-mix(in srgb, var(--err) 12%, transparent); color: var(--err); }
.btn--sm { --btn-h: 30px; padding: 0 11px; font-size: 12.5px; }
.btn--xs { --btn-h: 26px; padding: 0 9px; gap: 4px; font-size: 12px; border-radius: 7px; }
.btn--xs .ico { width: 14px; height: 14px; }
.btn--icon { width: var(--btn-h); padding: 0; }
.btn[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.btn:disabled, .btn[disabled] { opacity: .45; cursor: not-allowed; transform: none; }
.btn[aria-busy="true"] { cursor: progress; }

/* ---------- tabs ----------
   A page's view switcher: capsule tabs on a quiet strip, the selected one a soft fill. */
.tabs { display: flex; gap: 4px; padding: 8px 12px; border-bottom: 1px solid var(--line); background: var(--surface); overflow-x: auto; scrollbar-width: none; }
.tab { position: relative; flex: none; display: inline-flex; align-items: center; gap: 6px; height: 28px; padding: 0 12px; border: 0; border-radius: 999px; background: transparent;
  color: var(--muted); font-size: 13px; font-weight: 500; transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); }
.tab:hover { color: var(--text); background: var(--fill); }
.tab.is-active, .tab[aria-selected="true"] { background: var(--fill-2); color: var(--text); font-weight: 600; }
.tab:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }

/* ---------- segmented control ---------- */
.seg { display: inline-flex; gap: 2px; padding: 2px; border-radius: var(--radius-control); background: var(--fill); }
.seg__b { display: inline-flex; align-items: center; justify-content: center; gap: 5px; height: 24px; padding: 0 11px; border: 0; border-radius: 6px; background: transparent;
  color: var(--text); font-size: 12px; font-weight: 500; transition: background-color var(--dur) var(--ease), box-shadow var(--dur) var(--ease); }
.seg__b:not(:disabled):not(.is-active):hover { background: color-mix(in srgb, var(--surface) 45%, transparent); }
.seg__b.is-active, .seg__b[aria-selected="true"] { background: var(--surface); font-weight: 600; box-shadow: 0 1px 3px rgba(0,0,0,.12), 0 0 0 .5px rgba(0,0,0,.04); }
.seg__b:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.seg__b:disabled { opacity: .4; cursor: not-allowed; }

/* ---------- table head ---------- */
.table-head { position: sticky; top: 0; z-index: 1; background: var(--material); backdrop-filter: saturate(180%) blur(16px); color: var(--muted); font-size: 12px; font-weight: 600; }

/* ---------- card ----------
   A grouped section: white on the grey page, separated by a hairline shadow rather than a border. */
.card { min-width: 0; padding: 16px 18px; border: 1px solid transparent; border-radius: var(--radius); background: var(--surface);
  box-shadow: 0 0 0 .5px color-mix(in srgb, var(--text) 9%, transparent), 0 1px 3px rgba(0,0,0,.04); }

/* ---------- dialog ----------
   Native <dialog> as a macOS sheet: large radius, deep soft shadow, light dimmed backdrop. */
.dialog { width: min(560px, 92vw); padding: 0; border: 0; border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.dialog::backdrop { background: rgba(0,0,0,.22); backdrop-filter: blur(2px); }
.dialog[open] { animation: pop var(--dur-enter) var(--ease); }
@keyframes pop { from { opacity: 0; transform: scale(.96); } }
.dialog__body { display: flex; flex-direction: column; gap: 10px; padding: 20px 22px; }
.dialog__body h2 { margin: 0; font-size: 16px; font-weight: 700; letter-spacing: -.01em; }
.dialog__body p { margin: 0; color: var(--muted); }
.dialog__actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }

/* ---------- chip ----------
   Filter toggles in a row (.chips); the active one carries .is-active. */
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip { display: inline-flex; align-items: center; gap: 5px; height: 26px; padding: 0 11px; border: 0; border-radius: 999px; background: var(--fill);
  color: var(--text); font-size: 12px; font-weight: 500; transition: background-color var(--dur-fast) var(--ease), color var(--dur-fast) var(--ease); }
.chip:hover { background: var(--fill-2); }
.chip.is-active { background: var(--accent); color: var(--accent-ink); }
.chip--warn.is-active { background: var(--warn); color: #fff; }
.chip--err.is-active { background: var(--err); color: #fff; }
.chip:focus-visible { outline: none; box-shadow: 0 0 0 3px var(--ring); }
.chip__n { font-size: 11px; font-variant-numeric: tabular-nums; opacity: .7; }

/* ---------- menu ----------
   <details class="menu"> + <summary class="btn …"> + .menu__list: a translucent macOS menu. */
.menu { position: relative; }
.menu > summary { list-style: none; }
.menu > summary::-webkit-details-marker { display: none; }
.menu__list { position: absolute; right: 0; top: calc(100% + 4px); z-index: 5; display: flex; flex-direction: column; min-width: 180px; padding: 5px; border-radius: var(--radius-sm);
  background: var(--material); backdrop-filter: saturate(180%) blur(24px); box-shadow: var(--shadow); animation: pop var(--dur-fast) var(--ease); transform-origin: top right; }
.menu__list button { height: 26px; padding: 0 9px; border: 0; border-radius: 5px; background: transparent; color: var(--text); font-size: 13px; text-align: left; }
.menu__list button:hover, .menu__list button:focus-visible { outline: none; background: var(--accent); color: var(--accent-ink); }
.menu__list .is-danger { color: var(--err); }
.menu__list .is-danger:hover { background: var(--err); color: #fff; }

/* ---------- empty state ---------- */
.empty-state { display: flex; flex-direction: column; align-items: center; gap: 8px; margin: 0; padding: 48px 16px; color: var(--muted); font-size: 13px; text-align: center; animation: rise var(--dur-enter) var(--ease) both; }
.empty-state > .ico { width: 30px; height: 30px; padding: 10px; box-sizing: content-box; border-radius: 14px; background: var(--fill); color: var(--faint); stroke-width: 1.5; }
.empty-state b, .empty-state h2 { color: var(--text); font-size: 14px; font-weight: 600; margin: 0; }
.empty-state p { margin: 0; max-width: 420px; }
.empty-state.is-err, .empty-state.is-err > .ico { color: var(--err); }
.empty-state--sm { padding: 18px 12px; font-size: 12.5px; }

/* ---------- toast ----------
   A manual popover (#toasts) above modal dialogs: a translucent notification with a tone dot. */
.toasts { position: fixed; inset: auto 16px 52px auto; z-index: 50; display: flex; flex-direction: column; gap: 8px; margin: 0; padding: 0; border: 0; background: transparent; color: inherit; overflow: visible; }
.toasts:not(:popover-open) { display: none; }
.toast { --t: var(--faint); display: flex; align-items: center; gap: 10px; max-width: 380px; padding: 11px 14px; border-radius: 12px; background: var(--material);
  backdrop-filter: saturate(180%) blur(24px); color: var(--text); box-shadow: var(--shadow); font-size: 13px; font-weight: 500; overflow-wrap: anywhere; animation: pop var(--dur-enter) var(--ease); }
.toast::before { content: ""; flex: none; width: 8px; height: 8px; border-radius: 50%; background: var(--t); }
.toast.ok { --t: var(--ok); }
.toast.err { --t: var(--err); }

/* ---------- field ---------- */
.field { display: flex; flex-direction: column; gap: 5px; min-width: 0; color: var(--text); font-size: 12.5px; font-weight: 500; }
.field > span small, .field > label small { color: var(--faint); font-weight: 400; }

/* ---------- list ---------- */
.list { list-style: none; margin: 0; padding: 0; }
.list > li { display: flex; align-items: center; gap: 10px; min-width: 0; padding: 8px 4px; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.list > li:last-child { border-bottom: 0; }

/* ---------- grid table row ----------
   Div-based tables: .trow gives the row rhythm, the page class only the column template. */
.trow { display: grid; align-items: center; border-bottom: 1px solid var(--line); font-size: 12.5px; }
.trow > span { min-width: 0; padding: 9px 10px; }
.trow > span:first-child { padding-left: 16px; }
.trow:not(.table-head):hover { background: var(--row-hover); }
.trow .btn--icon { --btn-h: 28px; }

.cache__dialog { width: min(820px, calc(100vw - 32px)); }
.cache__options { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; border: 0; padding: 0; margin: 16px 0; min-width: 0; }
.cache__toolbar, .cache__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cache__toolbar { margin: 16px 0; }
.cache__toolbar .field { flex: 1; min-width: 160px; }
.cache__row { grid-template-columns: minmax(0, 1fr) 64px 124px; }
.cache__list { max-height: 32vh; overflow-y: auto; }
.cache__domains { display: block; overflow-wrap: anywhere; color: var(--muted); margin-top: 4px; }
.cache__editor { display: grid; gap: 12px; margin: 16px 0; }
.cache__preview { display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 8px; margin: 16px 0; }
.cache__preview p { grid-column: 1 / -1; margin: 0; }
@media (max-width: 600px) {
  .cache__options { grid-template-columns: 1fr; }
  .cache__row { grid-template-columns: minmax(0, 1fr) 48px; }
  .cache__row > span:last-child { grid-column: 1 / -1; padding-top: 0; }
  .cache__row.table-head > span:last-child { display: none; }
}

@media (prefers-reduced-transparency: reduce) {
  .topbar, .menu__list, .toast, .table-head { backdrop-filter: none; background: var(--surface); }
}
