/* the admin page (admin.html): a header, then panes beside a sidebar, as in Settings, each section a card */
body.admin-page { overflow: auto; }
.admin-page header { gap: 12px; }
.admin-page header a.btn { text-decoration: none; color: inherit; }
.admin-page .btn:disabled { opacity: .5; cursor: default; }
.admin-title { margin: 0; font-size: 15px; font-weight: 600; flex: 1; }
.admin-layout { display: flex; min-height: calc(100vh - var(--header)); }
.admin-layout .settings-nav { position: sticky; top: 0; align-self: flex-start; min-height: calc(100vh - var(--header)); }
.admin-main { flex: 1; min-width: 0; max-width: 1200px; padding: 18px 10px 32px; }
.admin-head { padding: 0 18px 12px; }
.admin-head h2 { margin: 0; font-size: 18px; }
#admin-note { margin-top: 3px; }
#admin-note:empty { display: none; }

/* a job's state: running, queued, failed, each a badge with a dot (the running one pulses) */
.state { display: inline-flex; align-items: center; gap: 5px; padding: 2px 8px; border-radius: 999px; font-size: 11.5px;
  color: var(--text-2); background: var(--raise); white-space: nowrap; }
.state::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--muted); }
.state.run { color: var(--accent); background: var(--accent-wash); }
.state.run::before { background: var(--accent); animation: pulse 1.4s ease-in-out infinite; }
.state.bad { color: var(--error); background: color-mix(in srgb, var(--error) 12%, transparent); }
.state.bad::before { background: var(--error); }
@keyframes pulse { 50% { opacity: .35; } }
@media (prefers-reduced-motion: reduce) { .state.run::before { animation: none; } }
.row.states { gap: 6px; margin-left: auto; }

/* the panes: each section a card; a row's main action a bordered accent link, the rest quieter */
.admin-page .settings-body { overflow: visible; padding: 0 18px 16px; display: flex; flex-direction: column; gap: 14px; }
.admin-page .settings-body > .pane-section {
  padding: 4px 16px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; min-width: 0; }
.admin-page .pane-section h3 { margin: 12px 0 8px; }
.admin-page .pane-section > p.muted { max-width: 820px; line-height: 1.5; }
.admin-page .pane-actions { margin: 12px 0 4px; gap: 10px; flex-wrap: wrap; }
.admin-page .table th { padding: 8px 12px 8px 0; }
.admin-page .table td { padding: 9px 12px 9px 0; }
.admin-page .table tr.sub-row td { padding: 0 12px 10px 0; }
.admin-page .table td:first-child { font-weight: 500; }
.admin-page .table td.actions { width: 1%; }
.admin-page td.actions .link {
  padding: 3px 10px; border: 1px solid var(--line); border-radius: 6px; color: var(--text-2); font-size: 12px; line-height: 1.4;
  white-space: nowrap; }
.admin-page td.actions .link + .link { margin-left: 6px; }
.admin-page td.actions .link:hover { background: var(--raise); color: var(--text); text-decoration: none; }
.admin-page td.actions .link.main { color: var(--accent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.admin-page td.actions .link.main:hover { background: var(--accent-wash); }
.admin-page td.actions .link.danger { color: var(--error); border-color: color-mix(in srgb, var(--error) 40%, transparent); }
.admin-page td.actions .link.danger:hover { background: color-mix(in srgb, var(--error) 12%, transparent); }
.admin-page td.actions .link:disabled { opacity: .45; cursor: default; }
.admin-page .btn { border-radius: 7px; padding: 5px 12px; }
/* a row that opens a dialog of its settings */
.admin-page tr.opens { cursor: pointer; }
.admin-page tr.opens:hover > td, .admin-page tr.opens:hover + tr.sub-row > td { background: var(--surface-2); }

/* an item's settings dialog: titled blocks, a schedule row, actions, and a history of runs */
dialog.item-dialog { width: min(640px, calc(100vw - 24px)); }
.item-dialog .modal-body { display: flex; flex-direction: column; gap: 4px; }
.item-dialog .modal-body > p { margin: 0 0 6px; }
.item-block { padding: 10px 0; border-top: 1px solid var(--border); }
.item-block:first-of-type { border-top: 0; padding-top: 0; }
.item-block h3 { margin: 0 0 8px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.item-block .kv { margin-top: 8px; gap: 4px 18px; }
.item-schedule { gap: 14px; flex-wrap: wrap; }
.item-schedule select { width: auto; }
.item-actions { gap: 10px; flex-wrap: wrap; align-items: center; }
.run-history { margin: 4px 0; max-height: 220px; overflow: auto; }
.run-history table { width: auto; }
.run-history td { padding: 2px 10px 2px 0; font-size: 12px; white-space: nowrap; }
.run-history td:last-child { white-space: normal; }

@media (max-width: 720px) {
  .admin-layout { flex-direction: column; }
  .admin-layout .settings-nav { position: static; min-height: 0; width: auto; flex-direction: row; flex-wrap: wrap; }
  .admin-main { padding: 12px 0 24px; }
  .admin-head { padding: 0 12px 10px; }
  .admin-page .settings-body { padding: 0 8px 12px; }
  .admin-page .settings-body > .pane-section { padding: 2px 12px 12px; }
  /* wide tables scroll sideways in their card rather than the page */
  .admin-page .settings-body .table { display: block; overflow-x: auto; min-width: 0; }
  /* a .stack table becomes a card per row: its first cell across, then the rest labelled by data-label */
  .admin-page .settings-body .table.stack { display: block; }
  .admin-page .table.stack thead { display: none; }
  .admin-page .table.stack tbody { display: block; }
  .admin-page .table.stack tr { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; padding: 10px 0;
    border-bottom: 1px solid var(--border); }
  .admin-page .table.stack tr:has(+ .sub-row) { border-bottom: 0; padding-bottom: 4px; }
  .admin-page .table.stack tr.sub-row { padding-top: 0; }
  .admin-page .table.stack td { display: block; border: 0; padding: 0; }
  .admin-page .table.stack tr > td:first-child, .admin-page .table.stack tr.sub-row > td { flex-basis: 100%; }
  .admin-page .table.stack td.actions { width: auto; min-width: 0; margin-left: auto; }
  .admin-page .table.stack td[data-label]::before { content: attr(data-label) " "; color: var(--muted); font-size: 11.5px; margin-right: 3px; }
}

/* a card inside a pane */
.boxed { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; min-width: 0; }
.gchip {
  display: inline-block; margin: 0 4px 2px 0; padding: 0 7px; border-radius: 4px; line-height: 18px; font-size: 11.5px;
  color: color-mix(in srgb, var(--c) 70%, white); background: color-mix(in srgb, var(--c) 18%, transparent);
}

/* groups: a ranked list on the left (higher ranks manage lower ones), the chosen group's permissions on the right */
.groups-layout { display: grid; grid-template-columns: minmax(260px, 320px) 1fr; gap: 20px; align-items: start; margin-top: 12px; }
.grank-list { display: flex; flex-direction: column; gap: 4px; }
.grank {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 8px; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); user-select: none;
}
.grank:hover { background: var(--surface-2); }
.grank.on { border-color: var(--accent); background: var(--accent-wash); }
.grank.dragging { opacity: .4; }
.grank.drop { box-shadow: 0 -2px 0 var(--accent) inset; }
.grank-n { width: 18px; text-align: right; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.grank-handle { color: var(--muted); font-size: 11px; width: 14px; text-align: center; }
.grank.movable .grank-handle { cursor: grab; letter-spacing: -2px; }
.grank-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.grank-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.grank-arrows { display: flex; flex-direction: column; visibility: hidden; }
.grank:hover .grank-arrows, .grank.on .grank-arrows { visibility: visible; }
.grank-arrows .icon-btn.sm { width: 20px; height: 16px; font-size: 12px; }
.gdot { width: 10px; height: 10px; border-radius: 50%; background: var(--c); flex: none; display: inline-block; }
.gchip {
  display: inline-block; margin: 0 4px 2px 0; padding: 0 7px; border-radius: 4px; line-height: 18px; font-size: 11.5px;
  color: color-mix(in srgb, var(--c) 70%, white); background: color-mix(in srgb, var(--c) 18%, transparent);
}
.gedit { padding: 14px 16px; }
.gedit-head { display: flex; align-items: center; gap: 10px; }
.gedit-head input[type=text] { font-size: 15px; font-weight: 600; }
.gedit-head .color-in { width: 34px; height: 30px; }
.gedit .notice { margin: 12px 0 0; }
.perm-sec h3 { margin: 18px 0 6px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.perm-row { display: flex; align-items: center; gap: 12px; padding: 7px 4px; border-bottom: 1px solid var(--border); cursor: pointer; }
.perm-row:last-child { border-bottom: 0; }
.perm-row:hover { background: var(--surface-2); }
.perm-row.ro { cursor: default; }
.perm-row .grow { display: flex; flex-direction: column; }
.perm-row code { font-size: 11px; color: var(--muted); }
.switch { position: relative; width: 30px; height: 17px; flex: none; }
.switch input { position: absolute; opacity: 0; inset: 0; margin: 0; cursor: inherit; }
/* the drawn track sits over the invisible checkbox, so it must let clicks through to it; otherwise a switch works only
   when wrapped in a <label> */
.switch i { pointer-events: none; position: absolute; inset: 0; border-radius: 9px; background: var(--raise); border: 1px solid var(--line); transition: background .12s; }
.switch i::after { content: ''; position: absolute; top: 2px; left: 2px; width: 11px; height: 11px; border-radius: 50%; background: var(--muted); transition: transform .12s, background .12s; }
.switch input:checked + i { background: var(--accent); border-color: transparent; }
.switch input:checked + i::after { transform: translateX(13px); background: #fff; }
.switch input:disabled + i { opacity: .55; }
.switch input:focus-visible + i { outline: 2px solid var(--accent); outline-offset: 2px; }
.gedit-foot { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; padding-top: 12px; border-top: 1px solid var(--border); }
@media (max-width: 760px) { .groups-layout { grid-template-columns: 1fr; } }

/* a settled, good state (an active account, a key in use): no pulse */
.state.ok { color: #57c79a; background: color-mix(in srgb, #199e70 16%, transparent); }
.state.ok::before { background: #199e70; }

/* the sign-in page's other ways in, under the button */
.signin-ways { display: flex; flex-direction: column; align-items: flex-start; gap: 6px; margin-top: 2px; font-size: 12px; }
.signin-ways:empty { display: none; }
.signin input[type=text], .signin input[type=password] { width: 100%; }

/* a scope's own rule in a group: allow, not set, or deny */
.perm-row .tier { margin-left: 6px; vertical-align: 1px; }
.perm-row.ro:hover { background: none; }
.segmented.tri { flex: none; }
.segmented.tri .seg { min-width: 52px; }
.segmented.tri .seg.on.allow { background: color-mix(in srgb, #199e70 26%, transparent); color: #7fe0b8; }
.segmented.tri .seg.on.deny { background: color-mix(in srgb, var(--error) 24%, transparent); color: #ff9c9c; }
.segmented.tri .seg:disabled { cursor: default; opacity: .55; }
/* rules that are wider or narrower than one whole scope */
.rule-chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 8px 0; }
.rule-chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 4px 2px 8px; border-radius: 6px; background: var(--raise); font-size: 12px; }
.rule-chip b { font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.rule-chip.allow b { color: #7fe0b8; }
.rule-chip.deny b { color: #ff9c9c; }
.rule-chip.inherited { background: none; outline: 1px dashed var(--line); outline-offset: -1px; padding-right: 8px; }
.rule-chip .chip-x { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 0 4px; font-size: 14px; line-height: 1; }
.rule-chip .chip-x:hover { color: var(--text); }
.rule-add { gap: 8px; }
.rule-add .rule-in { flex: 1; min-width: 0; font-family: ui-monospace, Menlo, monospace; font-size: 12px; }
.inherit-row { flex-wrap: wrap; gap: 14px; }
.gedit .perm-sec > p { margin: 0 0 6px; }

/* an account's dialog: its groups as buttons that are in or out */
.gtoggles { display: flex; flex-wrap: wrap; gap: 6px; }
.gtoggle { display: inline-flex; align-items: center; gap: 7px; padding: 4px 10px; border-radius: 999px; cursor: pointer; font-size: 12px;
  background: none; border: 1px solid var(--line); color: var(--text-2); }
.gtoggle:hover:not(:disabled) { background: var(--raise); color: var(--text); }
.gtoggle.on { background: color-mix(in srgb, var(--c) 20%, transparent); border-color: color-mix(in srgb, var(--c) 55%, transparent); color: var(--text); }
.gtoggle:not(.on) .gdot { opacity: .35; }
.gtoggle:disabled { cursor: default; opacity: .55; }
.form-grid.two { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px 14px; max-width: 560px; }
.form-grid.two input { width: 100%; }
.form-grid.two .error, .form-grid.two > div { grid-column: 1 / -1; }
.new-account { gap: 8px; flex-wrap: wrap; }
.new-account input { flex: 1; min-width: 150px; }
.setup-box { margin: 0 0 12px; }
.setup-code { font-size: 18px; letter-spacing: .08em; user-select: all; color: var(--text); }
.pane-wait { padding: 0 2px; }
@media (max-width: 560px) { .form-grid.two { grid-template-columns: 1fr; } .perm-row { flex-wrap: wrap; } }
