/*
 * Groovin Admin. Colors are tokens: never hard-code a color below :root.
 * Text tokens pass WCAG AA (4.5:1) on --bg and --surface in both schemes; the
 * chart tokens (--series-*, --ordinal-*, --chart-*) are the validated dataviz palette
 * (series in fixed order: 1 = MCP, a single series or succeeded; 2 = REST API
 * or failed; --ordinal-* is
 * one blue ramp for ordered series, p50 then p90 then p95: darker with the
 * percentile in light, lighter in dark, each step at least 3:1 on --surface).
 */
:root {
  color-scheme: light dark;
  --bg: #f3f3f0;
  --surface: #fcfcfb;
  --surface-sunken: #efeee9;
  --border: #e1e0d9;
  --border-strong: #c3c2b7;
  --text: #0b0b0b;
  --text-secondary: #52514e;
  --text-muted: #6b6a65;
  --accent: #1d5fb0;
  --accent-text: #ffffff;
  --danger: #b42318;
  --danger-bg: #fdecea;
  --warning: #8a5a00;
  --warning-bg: #fdf3dc;
  --success: #176c30;
  --success-bg: #e7f5ec;
  --series-1: #2a78d6;
  --series-2: #eb6834;
  --ordinal-1: #3987e5;
  --ordinal-2: #256abf;
  --ordinal-3: #104281;
  --chart-grid: #e1e0d9;
  --chart-baseline: #c3c2b7;
  --radius: 8px;
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121211;
    --surface: #1a1a19;
    --surface-sunken: #222220;
    --border: #2c2c2a;
    --border-strong: #383835;
    --text: #f0efec;
    --text-secondary: #c3c2b7;
    --text-muted: #898781;
    --accent: #6ea8f0;
    --accent-text: #0b0b0b;
    --danger: #f97066;
    --danger-bg: #3a1714;
    --warning: #f5b544;
    --warning-bg: #33260b;
    --success: #4ac26b;
    --success-bg: #12301b;
    --series-1: #3987e5;
    --series-2: #d95926;
    --ordinal-1: #256abf;
    --ordinal-2: #5598e7;
    --ordinal-3: #9ec5f4;
    --chart-grid: #2c2c2a;
    --chart-baseline: #383835;
  }
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
}

h1,
h2,
h3 {
  margin: 0;
  line-height: 1.25;
}

h1 {
  font-size: 1.6rem;
  font-weight: 650;
}

h2 {
  font-size: 1.1rem;
  font-weight: 600;
}

p {
  margin: 0;
}

a {
  color: var(--accent);
  text-underline-offset: 2px;
}

code,
.mono {
  font-family: var(--mono);
  font-size: 0.92em;
}

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.visually-hidden {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Long untrusted names: wrap anywhere, at most three lines. */
.clamp {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
  overflow-wrap: anywhere;
}

.boot {
  padding: 48px 16px;
  text-align: center;
  color: var(--text-secondary);
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

/* Buttons and fields */

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 34px;
  padding: 6px 14px;
  font: inherit;
  font-weight: 550;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  white-space: nowrap;
  cursor: pointer;
}

.button:hover {
  background: var(--surface-sunken);
}

.button:disabled {
  opacity: 0.6;
  cursor: progress;
}

.button-primary {
  color: var(--accent-text);
  background: var(--accent);
  border-color: var(--accent);
}

.button-primary:hover {
  background: var(--accent);
  filter: brightness(1.08);
}

.button-quiet {
  border-color: transparent;
  background: transparent;
  color: var(--accent);
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label,
.field-inline > span {
  font-weight: 550;
  color: var(--text-secondary);
}

.field-inline {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  max-width: 100%;
}

/* A select is as wide as its longest option: let it shrink to the line instead. */
.field-inline select {
  min-width: 0;
}

.field-hint {
  font-size: 0.9rem;
  color: var(--text-muted);
}

input,
select {
  max-width: 100%;
  min-height: 34px;
  padding: 5px 8px;
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 6px;
}

input:user-invalid {
  border-color: var(--danger);
}

#totp-code {
  font-family: var(--mono);
  font-size: 1.3rem;
  letter-spacing: 0.3em;
  max-width: 12ch;
}

.form-status:empty {
  display: none;
}

/* Notices */

.notice {
  padding: 8px 12px;
  border: 1px solid currentColor;
  border-radius: 6px;
  overflow-wrap: anywhere;
}

.notice-error {
  color: var(--danger);
  background: var(--danger-bg);
}

.notice-warning {
  color: var(--warning);
  background: var(--warning-bg);
}

.notice-info {
  color: var(--success);
  background: var(--success-bg);
}

.request-id {
  font-family: var(--mono);
  font-size: 0.85em;
}

.banner {
  padding: 8px 24px;
}

.banner-warning {
  color: var(--warning);
  background: var(--warning-bg);
  border-bottom: 1px solid var(--border);
}

.loading,
.empty-state,
.footnote,
.panel-hint {
  color: var(--text-muted);
}

.footnote {
  margin-top: 8px;
  font-size: 0.9rem;
}

/* Signed-out screens */

.auth {
  display: grid;
  place-items: center;
  min-height: 100vh;
  padding: 24px 16px;
}

.auth-card {
  display: flex;
  flex-direction: column;
  gap: 16px;
  width: min(100%, 400px);
  padding: 28px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

.auth-brand {
  font-weight: 650;
  color: var(--accent);
}

.qr-frame {
  align-self: center;
  padding: 12px;
  background: #ffffff; /* QR codes need a light quiet zone in both schemes. */
  border-radius: var(--radius);
}

.qr {
  display: block;
  width: 200px;
  height: 200px;
}

.secret summary {
  cursor: pointer;
  color: var(--accent);
}

.secret-key {
  display: block;
  margin-top: 8px;
  padding: 8px;
  overflow-wrap: anywhere;
  background: var(--surface-sunken);
  border-radius: 6px;
  user-select: all;
}

/* App shell */

.topbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 24px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.nav-link {
  display: block;
  padding: 6px 10px;
  color: var(--text-secondary);
  text-decoration: none;
  border-radius: 6px;
}

.nav-link:hover {
  background: var(--surface-sunken);
}

.nav-link.is-current {
  color: var(--text);
  font-weight: 600;
  background: var(--surface-sunken);
}

.account {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-left: auto;
  color: var(--text-secondary);
  min-width: 0;
}

.account-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.main {
  display: flex;
  flex-direction: column;
  gap: 20px;
  max-width: 1440px;
  margin: 0 auto;
  padding: 24px;
}

.main:focus {
  outline: none;
}

.main > * {
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.breadcrumb a {
  color: var(--text-secondary);
}

.page-header {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.page-meta {
  color: var(--text-secondary);
}

/* Section links of a page (Domain finder): one route each, the current one marked. */

.subnav {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 8px;
  margin: 0;
  padding: 0;
  list-style: none;
  border-bottom: 1px solid var(--border);
}

.subnav-link {
  display: block;
  margin-bottom: -1px;
  padding: 8px 4px;
  color: var(--text-secondary);
  text-decoration: none;
  border-bottom: 2px solid transparent;
}

.subnav-link:hover {
  color: var(--text);
}

.subnav-link[aria-current="page"] {
  color: var(--text);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.org-id-input {
  /* With its label, it fits a 390 px screen (342 px of content). */
  width: min(24rem, 55vw);
}

.metric-hint {
  min-width: 16rem;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Panels */

.panel {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 0;
}

.panel-header {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 4px 16px;
}

.panel-header .filters {
  margin-left: auto;
}

.filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 20px;
}

.facts {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr));
  gap: 12px 24px;
  margin: 0;
}

.facts dt {
  font-size: 0.9rem;
  color: var(--text-secondary);
}

.facts dd {
  margin: 2px 0 0;
  overflow-wrap: anywhere;
}

.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px;
}

.inline-form .button {
  margin-top: 22px;
}

/* KPI tiles */

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(11rem, 1fr));
  gap: 12px;
}

.kpi {
  display: flex;
  flex-direction: column;
  gap: 2px;
  height: 100%;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.kpi-label {
  color: var(--text-secondary);
}

.kpi-value {
  font-size: 1.8rem;
  font-weight: 650;
  line-height: 1.2;
}

.kpi-hint {
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Charts: a sized box (Chart.js fills it), one row per bar for horizontal bars. */

.chart {
  position: relative;
  width: 100%;
  height: 260px;
}

.chart-stacked-bars {
  height: calc(var(--rows, 1) * 30px + 72px);
}

.table-twin summary {
  cursor: pointer;
  color: var(--accent);
}

.table-twin[open] summary {
  margin-bottom: 8px;
}

/* Tables */

.table-toolbar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
  margin-bottom: 8px;
}

.table-search {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--text-secondary);
  font-weight: 550;
}

.table-search-input {
  width: min(18rem, 60vw);
}

.table-count {
  color: var(--text-muted);
}

.table-wrap {
  overflow-x: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-variant-numeric: tabular-nums;
}

th,
td {
  padding: 7px 10px;
  text-align: start;
  vertical-align: top;
  border-bottom: 1px solid var(--border);
}

/*
 * Long words wrap inside the 28rem cap (break-word; `anywhere` would let a squeezed
 * column shrink to one character). overflow: hidden keeps what a cell paints inside
 * it, so stacked combining marks in untrusted names cannot cover other rows; focus
 * rings (4px) fit in the cell padding.
 */
td {
  max-width: 28rem;
  overflow-wrap: break-word;
  overflow: hidden;
}

/* The same in a cell's clamped names (links to a user or an org). */
td .clamp {
  overflow-wrap: break-word;
}

tbody tr:last-child > * {
  border-bottom: 0;
}

thead th {
  background: var(--surface-sunken);
  white-space: nowrap;
}

.num {
  text-align: end;
  white-space: nowrap;
}

.nowrap {
  white-space: nowrap;
}

.sort {
  padding: 0;
  font: inherit;
  font-weight: 600;
  color: var(--text-secondary);
  background: none;
  border: 0;
  cursor: pointer;
}

.sort-mark {
  margin-left: 4px;
  font-size: 0.75em;
}

.empty {
  color: var(--text-muted);
  text-align: center;
}

.table-note,
.table-more {
  margin-top: 8px;
  color: var(--text-muted);
}

.table-more {
  padding: 8px 10px;
}

/* Performance: verdict badges (text tokens on their tinted backgrounds) and variant links */

.badge {
  display: inline-block;
  padding: 1px 8px;
  font-size: 0.85rem;
  font-weight: 550;
  white-space: nowrap;
  border: 1px solid currentColor;
  border-radius: 999px;
}

.badge-danger {
  color: var(--danger);
  background: var(--danger-bg);
}

.badge-warning {
  color: var(--warning);
  background: var(--warning-bg);
}

.badge-success {
  color: var(--success);
  background: var(--success-bg);
}

.badge-muted {
  color: var(--text-secondary);
  background: var(--surface-sunken);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin: 0;
  padding: 0;
  list-style: none;
}

.tab-link {
  display: inline-flex;
  align-items: baseline;
  gap: 6px;
  max-width: 100%;
  padding: 4px 10px;
  color: var(--text-secondary);
  text-decoration: none;
  overflow-wrap: anywhere;
  border: 1px solid var(--border);
  border-radius: 6px;
}

a.tab-link:hover {
  background: var(--surface-sunken);
}

.tab-link[aria-current="page"] {
  color: var(--text);
  font-weight: 600;
  background: var(--surface-sunken);
  border-color: var(--border-strong);
}

.tab-count {
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* A second, quieter line in a table cell (a label's variant) */
.cell-meta {
  display: block;
  font-size: 0.85rem;
  color: var(--text-secondary);
}

/* Audit log */

/* The filter bar wraps at any width: a long option (an actor's email) shrinks its field. */
.audit-filters .field-inline {
  min-width: 0;
  max-width: 100%;
}

.audit-filters .field-slot {
  display: inline-flex;
  min-width: 0;
  max-width: 100%;
}

.audit-filters select,
.audit-filters input {
  min-width: 0;
  max-width: 100%;
}

.audit-meta {
  display: block;
  margin-top: 2px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

/* Names and keys stay readable next to the wide Changes column. */
.audit-target {
  min-width: 12rem;
}

.audit-changes {
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 14rem;
}

.diff {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin: 0;
  padding: 0;
  list-style: none;
}

/* Holds the visually hidden "changed to": absolutely positioned, it would otherwise
   sit where the scrolled table puts it and widen the page. */
.diff li {
  position: relative;
}

.diff-field {
  color: var(--text-secondary);
}

.diff-before,
.diff-after {
  padding: 0 3px;
  border-radius: 3px;
  overflow-wrap: anywhere;
}

.diff-before {
  background: var(--danger-bg);
}

.diff-after {
  background: var(--success-bg);
}

.diff-null,
.diff-absent,
.diff-none {
  color: var(--text-muted);
  font-style: italic;
}

.diff-more summary {
  cursor: pointer;
  color: var(--accent);
}

.diff-unchanged {
  display: grid;
  grid-template-columns: max-content minmax(0, 1fr);
  gap: 2px 8px;
  margin: 6px 0;
}

.diff-unchanged div {
  display: contents;
}

.diff-unchanged dd {
  margin: 0;
  overflow-wrap: anywhere;
}

.diff-label {
  margin-top: 6px;
  font-size: 0.85rem;
  color: var(--text-muted);
}

pre.json {
  margin: 2px 0 0;
  padding: 6px 8px;
  font-family: var(--mono);
  font-size: 0.85rem;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--surface-sunken);
  border-radius: 6px;
}

/* Confirmation dialog */

dialog.confirm {
  width: min(40rem, calc(100vw - 32px));
  padding: 20px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
}

dialog.confirm::backdrop {
  background: rgb(0 0 0 / 0.45);
}

dialog.confirm > * + * {
  margin-top: 14px;
}

.subject-name {
  font-weight: 600;
}

.subject-meta {
  color: var(--text-secondary);
}

.changes th[scope="row"] {
  font-weight: 550;
  color: var(--text-secondary);
}

.confirm-notes {
  margin: 0;
  padding: 8px 12px 8px 28px;
  color: var(--warning);
  background: var(--warning-bg);
  border: 1px solid currentColor;
  border-radius: 6px;
  overflow-wrap: anywhere;
}

.confirm-notes li + li {
  margin-top: 6px;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* Logs */

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border-bottom: 1px solid var(--border);
}

.tab {
  margin-bottom: -1px;
  padding: 8px 12px;
  color: var(--text-secondary);
  text-decoration: none;
  border-bottom: 2px solid transparent;
}

.tab:hover {
  color: var(--text);
}

.tab[aria-current="page"] {
  color: var(--text);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.status {
  display: inline-block;
  padding: 1px 8px;
  font-size: 0.9em;
  font-weight: 550;
  white-space: nowrap;
  border-radius: 999px;
}

.status-failure {
  color: var(--danger);
  background: var(--danger-bg);
}

.status-success {
  color: var(--success);
  background: var(--success-bg);
}

/* Log text in a table cell: kept on its lines, at most three of them (.clamp). */
.log-text {
  font-family: var(--mono);
  font-size: 0.85em;
  white-space: pre-wrap;
}

.log-count {
  display: block;
  color: var(--text-muted);
  font-size: 0.9em;
}

.log-entries {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 0;
  padding-left: 2.5em;
}

/* Log text in a detail page: every line, wrapped anywhere, scrolled past 32rem. */
.log-block {
  max-height: 32rem;
  margin: 0;
  padding: 8px 10px;
  overflow: auto;
  font-family: var(--mono);
  font-size: 0.85em;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  background: var(--surface-sunken);
  border-radius: 6px;
}

@media (max-width: 640px) {
  .topbar,
  .main {
    padding-left: 16px;
    padding-right: 16px;
  }

  .banner {
    padding-left: 16px;
    padding-right: 16px;
  }

  .account {
    margin-left: 0;
  }

  .panel-header .filters {
    margin-left: 0;
  }
}

@media (forced-colors: active) {
  .notice,
  .kpi,
  .panel,
  .table-wrap {
    border-color: CanvasText;
  }
}
