/* Component library. One set of primitives used by every page. */

/* ------------------------------------------------------------ buttons -- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 40px; padding: 0 16px; border-radius: var(--r-2);
  font-size: 14px; font-weight: 600; line-height: 1; white-space: nowrap;
  border: 1px solid transparent; user-select: none;
  transition: background-color var(--fast) var(--ease), border-color var(--fast) var(--ease), color var(--fast) var(--ease), box-shadow var(--fast) var(--ease), transform var(--fast) var(--ease);
}
.btn svg { width: 16px; height: 16px; flex: none; }
.btn:active:not(:disabled) { transform: translateY(0.5px); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }

.btn--primary { background: var(--brand); color: var(--ink-inv); box-shadow: var(--shadow-1); }
.btn--primary:hover:not(:disabled) { background: var(--brand-hover); }
.btn--primary:active:not(:disabled) { background: var(--brand-active); }

.btn--secondary { background: var(--bg); color: var(--brand-ink); border-color: var(--line-2); }
.btn--secondary:hover:not(:disabled) { border-color: var(--brand-line); background: var(--brand-soft); }

.btn--neutral { background: var(--bg); color: var(--ink); border-color: var(--line-2); }
.btn--neutral:hover:not(:disabled) { background: var(--bg-hover); border-color: var(--line-strong); }

.btn--ghost { color: var(--ink-2); }
.btn--ghost:hover:not(:disabled) { background: var(--bg-hover); color: var(--ink); }

.btn--danger { background: var(--bg); color: var(--bad); border-color: var(--bad-line); }
.btn--danger:hover:not(:disabled) { background: var(--bad-soft); }

.btn--lg { height: 56px; padding: 0 28px; font-size: 17px; border-radius: 10px; letter-spacing: 0.01em; }
.btn--lg svg { width: 20px; height: 20px; }
.btn--sm { height: 32px; padding: 0 12px; font-size: 13px; border-radius: var(--r-1); }
.btn--sm svg { width: 14px; height: 14px; }
.btn--block { width: 100%; }

.btn .spinner { width: 16px; height: 16px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin 0.7s linear infinite; }

.icon-btn {
  display: inline-grid; place-items: center; width: 32px; height: 32px; border-radius: var(--r-1); color: var(--ink-3); flex: none;
  transition: background-color var(--fast) var(--ease), color var(--fast) var(--ease);
}
.icon-btn svg { width: 18px; height: 18px; }
.icon-btn:hover { background: var(--bg-hover); color: var(--ink); }
.icon-btn[aria-pressed="true"] { color: var(--brand-ink); background: var(--brand-soft); }
.icon-btn--lg { width: 40px; height: 40px; }

.link { color: var(--brand-ink); font-weight: 600; text-underline-offset: 3px; }
.link:hover { text-decoration: underline; }
.link--quiet { color: var(--ink-3); font-weight: 500; }
.link--quiet:hover { color: var(--ink); }
.link svg { display: inline-block; width: 14px; height: 14px; vertical-align: -2px; margin-left: 2px; }

/* ------------------------------------------------------------- inputs -- */
.input, .textarea, .select {
  width: 100%; height: 40px; padding: 0 12px; border-radius: var(--r-2);
  background: var(--bg); border: 1px solid var(--line-2); color: var(--ink);
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.textarea { height: auto; min-height: 76px; padding: 8px 12px; resize: vertical; line-height: 1.55; }
.input::placeholder, .textarea::placeholder { color: var(--ink-4); }
.input:hover, .textarea:hover, .select:hover { border-color: var(--line-strong); }
.input:focus, .textarea:focus, .select:focus { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft-2); outline: none; }
.input[aria-invalid="true"] { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.input--sm, .select--sm { height: 32px; font-size: 13px; padding: 0 10px; border-radius: var(--r-1); }
.select { appearance: none; padding-right: 32px; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='none' stroke='%235f6f68' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='m4 6 4 4 4-4'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 10px center; }

.field { display: flex; flex-direction: column; gap: 6px; }
.field > label, .label { font-size: 13px; font-weight: 600; color: var(--ink-2); }
.field .hint { font-size: 12px; color: var(--ink-3); }
.field .error { font-size: 12px; color: var(--bad); font-weight: 600; }

.check { display: inline-grid; place-items: center; width: 18px; height: 18px; border-radius: 5px; border: 1.5px solid var(--line-strong); background: var(--bg); color: transparent; flex: none; transition: all var(--fast) var(--ease); }
.check svg { width: 12px; height: 12px; }
.check[data-on="true"] { background: var(--brand); border-color: var(--brand); color: var(--ink-inv); }
.check--lg { width: 24px; height: 24px; border-radius: 6px; }
.check--lg svg { width: 16px; height: 16px; }

.switch { position: relative; width: 36px; height: 20px; border-radius: 999px; background: var(--line-strong); transition: background-color var(--base) var(--ease); flex: none; }
.switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 16px; height: 16px; border-radius: 50%; background: #fff; box-shadow: var(--shadow-1); transition: transform var(--base) var(--ease); }
.switch[aria-checked="true"] { background: var(--brand); }
.switch[aria-checked="true"]::after { transform: translateX(16px); }

/* ------------------------------------------------- segmented control -- */
.seg { display: inline-flex; padding: 4px; border-radius: 12px; background: var(--bg-subtle); border: 1px solid var(--line); }
.seg__opt { min-width: 132px; height: 44px; padding: 0 20px; border-radius: 9px; font-size: 16px; font-weight: 600; color: var(--ink-2); transition: all var(--base) var(--ease); }
.seg__opt:hover { color: var(--ink); }
.seg__opt[aria-pressed="true"] { background: var(--brand); color: var(--ink-inv); box-shadow: var(--shadow-1); }
.seg--sm { padding: 3px; border-radius: 9px; }
.seg--sm .seg__opt { min-width: 0; height: 30px; padding: 0 12px; font-size: 13px; border-radius: 6px; }
.seg--sm .seg__opt[aria-pressed="true"] { background: var(--bg); color: var(--ink); box-shadow: var(--shadow-1); }

/* ----------------------------------------------------- chips & tags -- */
.chip {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: var(--r-pill);
  border: 1px solid var(--line-2); background: var(--bg); color: var(--ink-2); font-size: 13px; font-weight: 600; white-space: nowrap;
  transition: all var(--fast) var(--ease);
}
button.chip:hover { border-color: var(--line-strong); color: var(--ink); }
.chip[aria-pressed="true"], .chip--on { background: var(--brand-soft); border-color: var(--brand-line); color: var(--brand-ink); }
.chip .count { font-variant-numeric: tabular-nums; color: var(--ink-3); font-weight: 600; }
.chip[aria-pressed="true"] .count { color: var(--brand-ink); }
.chip--static { cursor: default; }
.chip svg { width: 14px; height: 14px; }

.tag { display: inline-flex; align-items: center; gap: 4px; height: 22px; padding: 0 8px; border-radius: 6px; background: var(--bg-sunken); color: var(--ink-2); font-size: 12px; font-weight: 600; white-space: nowrap; }
.tag--brand { background: var(--brand-soft); color: var(--brand-ink); }
.tag--pending { background: var(--pending-soft); color: var(--pending); }
.tag--bad { background: var(--bad-soft); color: var(--bad); }
.tag--info { background: var(--info-soft); color: var(--info); }
.tag--outline { background: transparent; box-shadow: inset 0 0 0 1px var(--line-2); color: var(--ink-3); }

/* status = icon + text, never colour alone */
.status { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; font-weight: 600; line-height: 18px; }
.status svg { width: 14px; height: 14px; flex: none; }
.status--ok { color: var(--ok); }
.status--pending { color: var(--pending); }
.status--bad { color: var(--bad); }
.status--info { color: var(--info); }
.status--muted { color: var(--ink-3); }

.pill { display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 12px; border-radius: var(--r-pill); font-size: 13px; font-weight: 650; white-space: nowrap; }
.pill svg { width: 14px; height: 14px; }
.pill--ok { background: var(--ok-soft); color: var(--ok); }
.pill--pending { background: var(--pending-soft); color: var(--pending); }
.pill--bad { background: var(--bad-soft); color: var(--bad); }
.pill--info { background: var(--info-soft); color: var(--info); }
.pill--muted { background: var(--bg-sunken); color: var(--ink-2); }

.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--ink-4); flex: none; }
.dot--ok { background: var(--ok); } .dot--pending { background: var(--pending-fill); } .dot--bad { background: var(--bad); } .dot--info { background: var(--info); }
.dot--live { background: var(--info); animation: pulse-dot 1.2s var(--ease) infinite; }

/* platform glyph: neutral monogram, identity is always carried by the name next to it */
.glyph { display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 6px; background: var(--bg-sunken); color: var(--ink-2); font-size: 11px; font-weight: 700; letter-spacing: -0.02em; flex: none; box-shadow: inset 0 0 0 1px var(--line); }
.glyph--lg { width: 32px; height: 32px; border-radius: 8px; font-size: 13px; }

.kbd { display: inline-grid; place-items: center; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 5px; background: var(--bg-sunken); border: 1px solid var(--line-2); border-bottom-width: 2px; color: var(--ink-3); font-family: var(--font-mono); font-size: 11px; font-weight: 600; }

/* -------------------------------------------------------- popovers -- */
.menu-root { position: relative; }
.menu {
  position: absolute; z-index: 40; top: calc(100% + 6px); left: 0; min-width: 260px; max-height: min(70vh, 520px); overflow: auto;
  background: var(--bg); border: 1px solid var(--line-2); border-radius: var(--r-3); box-shadow: var(--shadow-2); padding: 6px;
  animation: rise var(--base) var(--ease);
}
.menu--right { left: auto; right: 0; }
.menu__group { padding: 8px 10px 4px; font-size: 12px; font-weight: 650; color: var(--ink-3); display: flex; align-items: center; justify-content: space-between; }
.menu__item { display: flex; align-items: center; gap: 10px; width: 100%; min-height: 38px; padding: 6px 10px; border-radius: var(--r-1); text-align: left; font-size: 14px; color: var(--ink); }
.menu__item:hover, .menu__item:focus-visible { background: var(--bg-hover); }
.menu__item[aria-checked="true"] { font-weight: 600; }
.menu__item .sub { margin-left: auto; font-size: 12px; color: var(--ink-3); font-weight: 500; }
.menu__item svg.tick { width: 16px; height: 16px; margin-left: auto; color: var(--brand-ink); flex: none; }
.menu__item[disabled], .menu__item[aria-disabled="true"] { opacity: 0.5; cursor: not-allowed; }
.menu__sep { height: 1px; background: var(--line); margin: 6px 4px; }
.menu__foot { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 10px 4px; border-top: 1px solid var(--line); margin-top: 6px; }

.dropdown {
  display: inline-flex; align-items: center; gap: 10px; height: 44px; padding: 0 12px 0 14px; border-radius: var(--r-2);
  background: var(--bg); border: 1px solid var(--line-2); font-size: 15px; color: var(--ink); white-space: nowrap;
  transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}
.dropdown:hover { border-color: var(--line-strong); }
.dropdown[aria-expanded="true"] { border-color: var(--brand); box-shadow: 0 0 0 3px var(--brand-soft-2); }
.dropdown .k { color: var(--ink); font-weight: 500; }
.dropdown .v { color: var(--ink); font-weight: 650; max-width: 220px; overflow: hidden; text-overflow: ellipsis; }
.dropdown svg { width: 16px; height: 16px; color: var(--ink-3); margin-left: 6px; transition: transform var(--base) var(--ease); }
.dropdown[aria-expanded="true"] svg { transform: rotate(180deg); }
.dropdown[aria-invalid="true"] { border-color: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }

/* ------------------------------------------------------------- tabs -- */
.tabs { display: flex; gap: 28px; border-bottom: 1px solid var(--line); }
.tab { position: relative; display: inline-flex; align-items: center; gap: 8px; height: 44px; font-size: 16px; font-weight: 600; color: var(--ink-3); white-space: nowrap; transition: color var(--fast) var(--ease); }
.tab:hover { color: var(--ink); }
.tab[aria-selected="true"] { color: var(--brand-ink); }
.tab[aria-selected="true"]::after { content: ""; position: absolute; left: 0; right: 0; bottom: -1px; height: 3px; border-radius: 3px 3px 0 0; background: var(--brand); }
.tab .count { font-size: 13px; font-weight: 650; font-variant-numeric: tabular-nums; padding: 1px 7px; border-radius: 999px; background: var(--bg-sunken); color: var(--ink-3); }
.tab[aria-selected="true"] .count { background: var(--brand-soft); color: var(--brand-ink); }
.tabs--sm .tab { height: 38px; font-size: 14px; }
.tabs--sm { gap: 20px; }

/* ------------------------------------------------------------ cards -- */
.card { background: var(--bg); border: 1px solid var(--line); border-radius: var(--r-3); }
.panel { background: var(--bg-subtle); border: 1px solid var(--line); border-radius: var(--r-3); }

.callout { display: flex; gap: 10px; padding: 12px 14px; border-radius: var(--r-2); font-size: 14px; line-height: 22px; border: 1px solid var(--line); background: var(--bg-subtle); color: var(--ink-2); }
.callout svg { width: 18px; height: 18px; flex: none; margin-top: 2px; }
.callout strong { color: var(--ink); }
.callout--info { background: var(--info-soft); border-color: var(--info-line); }
.callout--info svg { color: var(--info); }
.callout--pending { background: var(--pending-soft); border-color: var(--pending-line); }
.callout--pending svg { color: var(--pending); }
.callout--bad { background: var(--bad-soft); border-color: var(--bad-line); }
.callout--bad svg { color: var(--bad); }
.callout--ok { background: var(--brand-soft); border-color: var(--brand-line); }
.callout--ok svg { color: var(--brand-ink); }
.callout .actions { margin-left: auto; display: flex; gap: 8px; flex: none; align-items: flex-start; }

/* meter: fill carries state, track is a lighter step of the same ramp */
.meter { position: relative; height: 6px; border-radius: 999px; background: var(--brand-track); overflow: hidden; }
.meter > i { position: absolute; inset: 0 auto 0 0; border-radius: 999px; background: var(--brand); transition: width var(--slow) var(--ease); }
.meter--thin { height: 4px; }
.meter--pending { background: var(--pending-soft); } .meter--pending > i { background: var(--pending-fill); }
.meter--bad { background: var(--bad-soft); } .meter--bad > i { background: var(--bad); }
.meter--busy > i::after { content: ""; position: absolute; inset: 0; width: 40%; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, 0.55), transparent); animation: sweep 1.4s linear infinite; }

.skeleton { border-radius: 6px; background: linear-gradient(90deg, var(--bg-sunken) 0%, var(--bg-subtle) 40%, var(--bg-sunken) 80%); background-size: 800px 100%; animation: shimmer 1.4s linear infinite; }

.empty { display: flex; flex-direction: column; align-items: center; text-align: center; gap: 12px; padding: 64px 24px; color: var(--ink-3); }
.empty .art { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 16px; background: var(--brand-soft); color: var(--brand-ink); }
.empty .art svg { width: 26px; height: 26px; }
.empty .art--pending { background: var(--pending-soft); color: var(--pending); }
.empty .art--bad { background: var(--bad-soft); color: var(--bad); }
.empty h3 { font-size: 18px; font-weight: 650; color: var(--ink); }
.empty p { max-width: 520px; font-size: 14px; line-height: 22px; }

/* ----------------------------------------------------------- tables -- */
.table { width: 100%; font-size: 14px; }
.table th { text-align: left; font-size: 13px; font-weight: 650; color: var(--ink-3); padding: 10px 12px; background: var(--bg-subtle); border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; z-index: 1; }
.table td { padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
.table tr:hover td { background: var(--bg-subtle); }
.table .r { text-align: right; }
.table td.num, .table th.num { text-align: right; font-variant-numeric: tabular-nums; }
.table-wrap { border: 1px solid var(--line); border-radius: var(--r-3); overflow: auto; background: var(--bg); }
.table-wrap .table tr:last-child td { border-bottom: 0; }

/* ----------------------------------------------------------- overlay -- */
.scrim { position: fixed; inset: 0; z-index: 60; background: var(--bg-overlay); animation: fade var(--base) var(--ease); }
.modal {
  position: fixed; z-index: 70; top: 50%; left: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 32px)); max-height: calc(100vh - 64px); overflow: auto;
  background: var(--bg); border-radius: var(--r-4); box-shadow: var(--shadow-3); border: 1px solid var(--line); animation: rise var(--base) var(--ease);
}
.modal__head { display: flex; align-items: flex-start; gap: 12px; padding: 20px 24px 0; }
.modal__body { padding: 16px 24px 8px; display: flex; flex-direction: column; gap: 16px; }
.modal__foot { display: flex; justify-content: flex-end; gap: 8px; padding: 16px 24px 20px; }
.modal--wide { width: min(880px, calc(100vw - 32px)); }

.toasts { position: fixed; z-index: 90; left: 50%; bottom: 28px; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 8px; pointer-events: none; }
.toast { display: inline-flex; align-items: center; gap: 10px; min-height: 44px; padding: 10px 16px; border-radius: 12px; background: var(--ink); color: var(--bg); font-size: 14px; font-weight: 600; box-shadow: var(--shadow-2); pointer-events: auto; animation: rise var(--base) var(--ease); max-width: min(560px, calc(100vw - 32px)); }
.toast svg { width: 18px; height: 18px; flex: none; }
.toast--ok svg { color: #6ee0ad; }
.toast--bad svg { color: #ff9f97; }
.toast button { color: inherit; text-decoration: underline; text-underline-offset: 3px; font-weight: 650; }
:root[data-theme="dark"] .toast { background: #e7eeea; color: #111815; }
:root[data-theme="dark"] .toast--ok svg { color: #0a6b3d; }
:root[data-theme="dark"] .toast--bad svg { color: #b3261e; }

.tooltip { position: relative; }
.tooltip[data-tip]:hover::after, .tooltip[data-tip]:focus-visible::after {
  content: attr(data-tip); position: absolute; z-index: 50; bottom: calc(100% + 6px); left: 50%; transform: translateX(-50%);
  padding: 6px 10px; border-radius: 8px; background: var(--ink); color: var(--bg); font-size: 12px; font-weight: 600; line-height: 16px; white-space: nowrap; pointer-events: none; box-shadow: var(--shadow-2);
}
.tooltip--left[data-tip]:hover::after, .tooltip--left[data-tip]:focus-visible::after { left: auto; right: 0; transform: none; }

/* stat tiles: label · value (proportional figures) · note */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; }
.stat { padding: 16px 18px; border-radius: var(--r-3); border: 1px solid var(--line); background: var(--bg); display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.stat .label { font-size: 13px; font-weight: 600; color: var(--ink-3); }
.stat .value { font-size: 28px; line-height: 36px; font-weight: 650; color: var(--ink); letter-spacing: -0.01em; }
.stat .note { font-size: 12px; color: var(--ink-3); line-height: 18px; }
@media (max-width: 900px) { .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); } }

.def { display: grid; grid-template-columns: 120px minmax(0, 1fr); gap: 10px 16px; font-size: 14px; }
.def dt { color: var(--ink-3); }
.def dd { color: var(--ink); font-weight: 600; min-width: 0; }
.def dd .basis { display: block; font-weight: 500; color: var(--ink-3); font-size: 12px; line-height: 18px; margin-top: 2px; }
.def dd.is-empty { color: var(--ink-2); font-weight: 650; }

.copybox { display: flex; align-items: center; gap: 8px; padding: 8px 8px 8px 12px; border-radius: var(--r-2); background: var(--bg); border: 1px solid var(--line-2); }
.copybox .text { flex: 1; min-width: 0; font-size: 15px; font-weight: 600; user-select: all; overflow-wrap: anywhere; }

/* tooltips in the top edge of the screen open downwards so they are never clipped */
.drawer__head .tooltip[data-tip]:hover::after, .drawer__head .tooltip[data-tip]:focus-visible::after,
.topbar .tooltip[data-tip]:hover::after, .topbar .tooltip[data-tip]:focus-visible::after { bottom: auto; top: calc(100% + 6px); }
@media (hover: none) { .tooltip[data-tip]:hover::after { display: none; } }
