/*
  Havoc web UI styles - this file is the "classic" look. themes.css adds the
  other themes and the modern look on top (scoped to attributes on <html>).
*/

:root {
  --bg: #f6f7f9;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --border: #e2e5ea;
  --text: #16181d;
  --muted: #616875;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-text: #ffffff;
  --danger: #c62828;
  --danger-bg: #fdecec;
  --ok: #1b7f4b;
  --ok-bg: #e6f5ec;
  --warn: #8a5a00;
  --warn-bg: #fff4dc;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 1px 3px rgba(16, 24, 40, 0.08);
  color-scheme: light;
}

/* Dark scheme: follows the system ("auto") unless light or dark was chosen
   under Settings (data-mode on <html>, set by boot.js). */
@media (prefers-color-scheme: dark) {
  :root:not([data-mode="light"]) {
    --bg: #0f1115;
    --surface: #171a21;
    --surface-2: #1f232c;
    --border: #2a2f3a;
    --text: #e8eaef;
    --muted: #9aa1ad;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-text: #0f1115;
    --danger: #f28b82;
    --danger-bg: #3a1d1d;
    --ok: #7dd3a0;
    --ok-bg: #15301f;
    --warn: #f5c26b;
    --warn-bg: #35280f;
    --shadow: none;
    color-scheme: dark;
  }
}

:root[data-mode="dark"] {
  --bg: #0f1115;
  --surface: #171a21;
  --surface-2: #1f232c;
  --border: #2a2f3a;
  --text: #e8eaef;
  --muted: #9aa1ad;
  --accent: #818cf8;
  --accent-hover: #a5b4fc;
  --accent-text: #0f1115;
  --danger: #f28b82;
  --danger-bg: #3a1d1d;
  --ok: #7dd3a0;
  --ok-bg: #15301f;
  --warn: #f5c26b;
  --warn-bg: #35280f;
  --shadow: none;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  /* Installed on a phone (viewport-fit=cover): keep clear of notch and home indicator. */
  padding: 0 env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

a {
  color: var(--accent-ink, var(--accent));
}

h1 {
  font-size: 24px;
  margin: 0;
}

h2 {
  font-size: 17px;
  margin: 0;
}

code {
  font: 13px/1.4 ui-monospace, "Cascadia Code", Consolas, monospace;
  background: var(--surface-2);
  padding: 2px 6px;
  border-radius: 4px;
  word-break: break-all;
}

.muted {
  color: var(--muted);
}

/* ---- Top bar ---- */

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand {
  font-weight: 700;
  font-size: 18px;
  letter-spacing: 0.02em;
  color: var(--text);
  text-decoration: none;
}

.topbar nav {
  display: flex;
  gap: 4px;
  flex: 1;
}

.topbar nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 6px 10px;
  border-radius: 6px;
  white-space: nowrap;
}

.topbar nav a:hover,
.topbar nav a.active {
  color: var(--text);
  background: var(--surface-2);
}

.topbar nav a.active {
  font-weight: 600;
}

.user {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--muted);
  font-size: 14px;
}

main {
  max-width: 1040px;
  margin: 0 auto;
  padding: 32px 24px 64px;
}

/* ---- Buttons & forms ---- */

button,
.button {
  font: inherit;
  font-weight: 500;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  cursor: pointer;
  text-decoration: none;
}

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

button:disabled {
  opacity: 0.6;
  cursor: default;
}

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

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

.danger {
  color: var(--danger);
}

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

.ghost {
  border-color: transparent;
  background: transparent;
  color: var(--muted);
  padding: 6px 8px;
}

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

.small {
  padding: 4px 10px;
  font-size: 13px;
}

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

.field .label {
  font-size: 13px;
  font-weight: 600;
}

.field .hint {
  font-size: 12px;
  color: var(--muted);
}

input,
select,
textarea {
  font: inherit;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface);
  color: var(--text);
  width: 100%;
}

input:focus,
select:focus,
textarea:focus,
button:focus-visible,
a:focus-visible {
  outline: 2px solid var(--accent-ink, var(--accent));
  outline-offset: 1px;
}

.form-error {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}

/* ---- Cards & layout ---- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.page-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.section-title {
  margin: 32px 0 12px;
  color: var(--muted);
  font-size: 14px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.back {
  display: inline-block;
  margin-bottom: 16px;
  text-decoration: none;
}

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

/* Auth pages */
.auth {
  max-width: 400px;
  margin: 48px auto 0;
  padding: 32px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.auth .brand-big {
  font-size: 28px;
  font-weight: 700;
  margin: 0;
}

.auth p {
  margin: 0;
}

/* Certificate grid */
.cert-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 16px;
}

.cert {
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding: 20px;
  color: inherit;
  text-decoration: none;
  border-top: 4px solid var(--accent);
  transition: transform 0.1s ease;
}

.cert:hover {
  transform: translateY(-2px);
}

.cert.revoked {
  border-top-color: var(--danger);
  opacity: 0.75;
}

.cert-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
}

.meta {
  display: grid;
  grid-template-columns: max-content 1fr;
  gap: 6px 16px;
  margin: 0;
  font-size: 14px;
}

.meta dt {
  color: var(--muted);
}

.meta dd {
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

/* Detail page */
.detail {
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.detail .meta {
  font-size: 15px;
  gap: 10px 24px;
}

/* Tags & badges */
.tag {
  font-size: 12px;
  font-weight: 600;
  color: var(--accent-ink, var(--accent));
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--surface-2);
  color: var(--muted);
}

.badge-published,
.badge-active {
  background: var(--ok-bg);
  color: var(--ok);
}

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

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

/* Tables */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

th,
td {
  text-align: left;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

th {
  font-size: 12px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  font-weight: 600;
}

tr:last-child td {
  border-bottom: none;
}

td.actions {
  text-align: right;
  white-space: nowrap;
}

td.actions button+button {
  margin-left: 6px;
}

details summary {
  cursor: pointer;
  color: var(--accent-ink, var(--accent));
  font-size: 13px;
}

pre {
  font: 12px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace;
  background: var(--surface-2);
  padding: 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0 0;
}

/* Issue form */
.form-card {
  padding: 28px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  max-width: 640px;
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.form-actions {
  display: flex;
  gap: 12px;
  justify-content: flex-end;
}

/* Toast: the message after an action - high contrast in every theme (the
   page's text colour as background), an icon, an optional action, ✕ to close. */
.toast {
  position: fixed;
  bottom: calc(20px + env(safe-area-inset-bottom));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: min(340px, calc(100% - 32px));
  max-width: min(640px, calc(100% - 32px));
  padding: 10px 8px 10px 14px;
  background: var(--text);
  color: var(--bg);
  border-radius: 10px;
  border-left: 5px solid var(--ok);
  font-size: 15px;
  font-weight: 500;
  line-height: 1.4;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
  z-index: 1000;
  animation: havoc-toast-in 0.18s ease-out;
}

.toast.error {
  background: var(--danger);
  color: #fff;
  border-left-color: rgba(0, 0, 0, 0.35);
}

.toast-icon {
  flex: none;
  display: inline-grid;
  place-items: center;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  font-size: 13px;
  font-weight: 800;
  background: var(--ok);
  color: var(--bg);
}

.toast.error .toast-icon {
  background: #fff;
  color: var(--danger);
}

.toast-text {
  flex: 1;
  min-width: 0;
}

.toast .toast-action,
.toast .toast-close {
  flex: none;
  min-height: 0;
  padding: 4px 10px;
  border: 1px solid currentColor;
  border-radius: 7px;
  background: transparent;
  color: inherit;
  font-size: 13.5px;
  font-weight: 650;
  box-shadow: none;
}

.toast .toast-action:hover,
.toast .toast-close:hover {
  background: color-mix(in srgb, currentColor 16%, transparent);
}

.toast .toast-close {
  border-color: transparent;
  padding: 4px 8px;
  opacity: 0.85;
}

@keyframes havoc-toast-in {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* ---- Console additions ---- */

textarea {
  resize: vertical;
  line-height: 1.45;
}

textarea.code {
  font: 13px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace;
}

.project-switch {
  width: auto;
  max-width: 180px;
  padding: 5px 8px;
  font-size: 14px;
}

.badge-draft {
  background: var(--surface-2);
  color: var(--muted);
}

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

.cert.draft,
.cert.in_review {
  border-top-color: var(--border);
}

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

.pad {
  padding: 16px 20px;
}

.filters,
.inline-form {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  margin-bottom: 20px;
}

.filters input[type="search"] {
  flex: 1 1 220px;
  width: auto;
}

.filters select,
.inline-form select,
.inline-select,
.new-select {
  width: auto;
}

.inline-form input {
  flex: 1 1 180px;
  width: auto;
}

.inline-form .form-error,
.inline-form .scopes {
  flex-basis: 100%;
}

.card .inline-form {
  margin-bottom: 0;
}

.table-wrap > .inline-form {
  border-top: 1px solid var(--border);
}

.inline-select {
  padding: 4px 8px;
  font-size: 13px;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.chip {
  font-size: 12px;
  padding: 2px 10px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  text-decoration: none;
  background: var(--surface);
}

.chip:hover {
  color: var(--accent-ink, var(--accent));
  border-color: var(--accent);
}

.notice {
  background: var(--warn-bg);
  color: var(--warn);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
}

.notice pre {
  color: var(--text);
  user-select: all;
  white-space: pre-wrap;
  word-break: break-all;
}

.subhead {
  font-size: 13px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 6px;
}

.plain-list,
.sources,
.timeline {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.timeline li {
  border-left: 2px solid var(--border);
  padding-left: 12px;
}

.timeline .comment {
  margin-top: 4px;
  font-size: 14px;
  color: var(--muted);
  font-style: italic;
}

.markdown {
  border-top: 1px solid var(--border);
  padding-top: 16px;
}

.markdown > :first-child {
  margin-top: 0;
}

.markdown p,
.markdown ul,
.markdown ol {
  margin: 0 0 12px;
}

.markdown h3,
.markdown h4,
.markdown h5,
.markdown h6 {
  margin: 16px 0 8px;
}

table.diff {
  margin-top: 8px;
  font-size: 13px;
}

table.diff td {
  padding: 4px 8px;
}

.diff .old {
  color: var(--danger);
  text-decoration: line-through;
}

.diff .new {
  color: var(--ok);
}

.diff-added .old,
.diff-removed .new {
  text-decoration: none;
}

.check {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 14px;
}

.check input {
  width: auto;
}

.scopes summary {
  margin-bottom: 6px;
}

.scopes .check {
  display: inline-flex;
  margin-right: 14px;
}

.load-more {
  display: block;
  margin: 20px auto 0;
}

.form-card.wide {
  max-width: none;
}

.verdict {
  margin-top: 16px;
  border-top: 4px solid var(--accent);
}

.verdict.valid {
  border-top-color: var(--ok);
}

.verdict.valid .brand-big {
  color: var(--ok);
}

.verdict.invalid {
  border-top-color: var(--danger);
}

.verdict.invalid .brand-big {
  color: var(--danger);
}

/* ---- Elements only the modern look shows ---- */

.ico,
.brand-mark {
  display: none;
}

.user .ghost {
  text-decoration: none;
  font-size: 14px;
}

.lang-switch a[aria-current="true"] {
  font-weight: 700;
  color: var(--text);
  text-decoration: none;
}

/* ---- Settings (all themes) ---- */

.fieldset {
  border: 0;
  margin: 0;
  padding: 0;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.fieldset legend {
  font-size: 13px;
  font-weight: 600;
  padding: 0;
  margin-bottom: 8px;
}

.theme-grid {
  display: grid;
  gap: 12px;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
}

.theme-card {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  cursor: pointer;
}

.theme-card input,
.swatch > input[type="radio"],
.segmented-radio input {
  position: absolute;
  opacity: 0;
  pointer-events: none;
}

.theme-card:has(input:checked) {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent);
}

.theme-card:has(input:focus-visible),
.swatch:has(input[type="radio"]:focus-visible) {
  outline: 2px solid var(--accent-ink, var(--accent));
  outline-offset: 2px;
}

.theme-preview {
  position: relative;
  display: block;
  height: 76px;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid rgba(127, 127, 127, 0.25);
  margin-bottom: 4px;
}

.tp-side { position: absolute; left: 0; top: 0; bottom: 0; width: 26%; border-right: 1px solid rgba(127, 127, 127, 0.2); }
.tp-top { position: absolute; left: 0; right: 0; top: 0; height: 16%; border-bottom: 1px solid rgba(127, 127, 127, 0.2); }
.tp-card { position: absolute; right: 10%; bottom: 14%; width: 56%; height: 48%; border-radius: 5px; padding: 6px; display: flex; flex-direction: column; gap: 4px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.12); }
.tp-line { display: block; height: 4px; width: 80%; border-radius: 2px; opacity: 0.7; }
.tp-line.short { width: 50%; opacity: 0.4; }
.tp-btn { display: block; margin-top: auto; height: 8px; width: 40%; border-radius: 3px; }

.theme-name { font-weight: 700; font-size: 14px; }
.theme-desc { font-size: 12px; color: var(--muted); }

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

.swatch {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 5px 10px 5px 6px;
  border: 1px solid var(--border);
  border-radius: 999px;
  cursor: pointer;
  font-size: 13px;
  background: var(--surface);
}

.swatch:has(input[type="radio"]:checked) { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); font-weight: 600; }
.swatch-dot { width: 20px; height: 20px; border-radius: 50%; display: inline-block; }
.swatch-theme { background: conic-gradient(#4f46e5, #8b85ff, #0b3fb3, #0d9488, #4f46e5); }
.swatch input[type="color"] { width: 26px; height: 22px; padding: 0; border: 0; border-radius: 50%; background: none; }

.segmented-radio { display: inline-flex; flex-wrap: wrap; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; align-self: flex-start; }
.segmented-radio label { position: relative; cursor: pointer; }
.segmented-radio span { display: block; padding: 7px 14px; font-size: 14px; border-right: 1px solid var(--border); }
.segmented-radio label:last-child span { border-right: 0; }
.segmented-radio input:checked + span { background: var(--accent); color: var(--accent-text); font-weight: 600; }
.segmented-radio input:focus-visible + span { outline: 2px solid var(--accent-ink, var(--accent)); outline-offset: -2px; }

/* ---- Density ---- */

[data-density="compact"] body { font-size: 14px; }
[data-density="compact"] main { padding-top: 20px; padding-bottom: 40px; }
[data-density="compact"] th,
[data-density="compact"] td { padding: 7px 12px; }
[data-density="compact"] .cert { padding: 14px; gap: 8px; }
[data-density="compact"] .detail,
[data-density="compact"] .form-card { padding: 18px; gap: 12px; }
[data-density="compact"] button,
[data-density="compact"] .button { padding: 6px 11px; }
[data-density="compact"] input,
[data-density="compact"] select,
[data-density="compact"] textarea { padding: 6px 9px; }

/* ---- Small screens ---- */

@media (max-width: 640px) {
  .topbar {
    flex-wrap: wrap;
    gap: 8px 16px;
    padding: 10px 16px;
  }

  .topbar nav {
    order: 3;
    flex-basis: 100%;
    overflow-x: auto;
  }

  .user {
    margin-left: auto;
  }

  main {
    padding: 20px 16px 48px;
  }

  .auth {
    margin-top: 16px;
    padding: 24px;
  }

  .form-row {
    grid-template-columns: 1fr;
  }

  .project-switch {
    max-width: 120px;
  }

  .detail,
  .form-card {
    padding: 20px;
  }

  th,
  td {
    padding: 10px 12px;
  }
}
/* Accounts: guest notice, credential list, sign-up choice */
.guest-banner,
.credentials,
.account-card {
  margin-bottom: 20px;
}

.account-card {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.account-card h2,
.account-card h3 {
  margin: 0;
}

.credentials {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.credentials table,
.import-preview table {
  color: var(--text);
}

.credentials code {
  user-select: all;
}

.choice {
  align-items: flex-start;
  padding: 4px 0;
}

.choice > span {
  display: flex;
  flex-direction: column;
}

.choice .muted {
  font-size: 13px;
}

.account-form h3 {
  margin: 0;
}

.account-form + .account-form {
  margin-top: 16px;
}

/* --- Console 2.0: navigation groups, tabs, dashboard, rights ------------- */

/* Group labels of the navigation only show in the sidebar layout. */
.nav-section {
  display: none;
}

#user-name a {
  color: inherit;
  text-decoration: none;
}

#user-name a:hover,
#user-name a.active {
  text-decoration: underline;
}

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

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

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

.tabs a.active {
  color: var(--text);
  font-weight: 600;
  border-bottom-color: var(--accent);
}

.section-head {
  margin: 28px 0 10px;
  align-items: center;
}

.section-head .section-title {
  margin: 0;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 12px;
  margin-bottom: 8px;
}

.stat {
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 16px 18px;
  color: var(--text);
  text-decoration: none;
}

.stat:hover {
  border-color: var(--accent);
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  line-height: 1.1;
}

.stat-label {
  font-size: 13px;
  color: var(--muted);
}

.stat.attention .stat-value {
  color: var(--accent-ink, var(--accent));
}

.stat.warn .stat-value {
  color: var(--warn);
}

.home-search {
  margin: 4px 0 20px;
}

.home .notice,
.two-factor .notice {
  margin-bottom: 16px;
}

.small-text {
  font-size: 12px;
}

.form-note {
  flex-basis: 100%;
  margin: 0;
  font-size: 13px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 14px 18px;
}

.permission-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 6px 18px;
  margin: 8px 0;
}

.permission-grid .check {
  align-items: flex-start;
}

.permission-grid .check span {
  display: flex;
  flex-direction: column;
}

.role-list {
  display: flex;
  flex-direction: column;
  gap: 14px;
  margin-bottom: 20px;
}

.role-card h3,
.form-card h3 {
  margin: 0;
}

.rights-details summary,
.more-actions summary {
  cursor: pointer;
  font-size: 13px;
  color: var(--muted);
}

.rights-table {
  margin: 8px 0;
  font-size: 13px;
}

.rights-table td,
.rights-table th {
  padding: 6px 8px;
}

.more-actions {
  display: inline-block;
  position: relative;
  vertical-align: middle;
}

.more-actions summary {
  list-style: none;
  display: inline-block;
}

.more-actions summary::-webkit-details-marker {
  display: none;
}

.more-actions .menu {
  position: absolute;
  right: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  gap: 6px;
  min-width: 200px;
  margin-top: 6px;
  padding: 10px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(16, 24, 40, 0.16);
}

.instance-permissions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  text-align: left;
}

/* Sign-in protection: an account's sign-in log, refused requests kept apart */
.sign-in-row > td {
  background: var(--surface);
}

.sign-in-log {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-top: 10px;
  text-align: left;
}

.set-aside {
  margin-top: 18px;
}

.set-aside > summary {
  font-weight: 600;
}

.two-factor-setup {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.two-factor-setup .qr svg {
  display: block;
  width: min(240px, 100%);
  height: auto;
  aspect-ratio: 1;
  background: #fff;
  border-radius: 8px;
}

.two-factor-setup .secret,
.codes {
  user-select: all;
  font-size: 15px;
  letter-spacing: 0.04em;
}

.steps {
  margin: 0;
  padding-left: 20px;
}

.steps li + li {
  margin-top: 4px;
}

/* The view gets focus after navigation (screen readers); no ring for that. */
main:focus {
  outline: none;
}

/* ---- Phones: tabs as one row to swipe, figures side by side ---- */
@media (max-width: 640px) {
  .tabs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; -webkit-overflow-scrolling: touch; }
  .tabs::-webkit-scrollbar { display: none; }
  .tabs a { flex: none; }
  .stat-grid { grid-template-columns: repeat(3, minmax(0, 1fr)) !important; gap: 8px !important; }
  .stat-grid .stat { padding: 12px !important; }
  .stat-grid .stat-value { font-size: 22px; }
  .stat-grid .stat-label { font-size: 12px; line-height: 1.3; }
  input, select, textarea { font-size: 16px; }
}

/* Actions that remove data for good: set apart, red edge. */
.danger-zone { border-color: color-mix(in srgb, var(--danger) 45%, var(--border)) !important; background: color-mix(in srgb, var(--danger) 4%, var(--surface)); }
.danger-zone > p strong { color: var(--danger); }
.erase-account { margin-top: 10px; display: flex; flex-direction: column; gap: 10px; text-align: left; white-space: normal; }

/* ---- Long words, ids and addresses never leave their box ---- */
.card, dd, .meta, .notice, .toast { overflow-wrap: break-word; }
td, th { overflow-wrap: break-word; }
.badge, td code, th code, .chip { white-space: nowrap; overflow-wrap: normal; word-break: normal; }
.card { min-width: 0; }
.grid-2 > *, .stat-grid > *, .form-row > * { min-width: 0; }
p code, dd code, li code { word-break: break-all; }
pre { max-width: 100%; overflow-x: auto; white-space: pre-wrap; word-break: break-word; }
td.nowrap, .nowrap { overflow-wrap: normal; }
.break { overflow-wrap: anywhere; }

/* ---- Record explorer ---- */
.explorer-filter { display: grid; gap: 8px; grid-template-columns: minmax(200px, 2fr) repeat(4, minmax(120px, 1fr)) minmax(140px, 1fr) auto; align-items: center; }
.explorer-filter > * { min-width: 0; width: 100%; }
@media (max-width: 1100px) { .explorer-filter { grid-template-columns: repeat(2, minmax(0, 1fr)); } .explorer-filter input[type="search"] { grid-column: 1 / -1; } }
.explorer-table tr.is-deleted td { opacity: 0.6; }
.explorer-title a { font-weight: 600; }
.explorer-table .chips { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.ref-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.ref-list li { padding: 6px 0; border-bottom: 1px solid var(--border); }
.ref-list li:last-child { border-bottom: 0; }
.version-row { border-top: 1px solid var(--border); padding: 10px 0; }
.version-row summary { cursor: pointer; }
.version-row pre { margin: 10px 0 0; padding: 12px; border-radius: 10px; background: var(--surface-2); font-size: 12.5px; max-height: 420px; }
.explorer-editor textarea.mono { font: 12.5px/1.5 ui-monospace, Consolas, monospace; }
.form-actions.start { justify-content: flex-start; flex-wrap: wrap; }

/* ======================================================================
   Console 2.x: dialogs, command palette, bulk actions, tables that sort
   and filter, file gallery, wider layouts. Colours only from the theme
   tokens, so every theme, light/dark and "more contrast" apply.
   ====================================================================== */

/* ---- Readability: no text below 12px, secondary text that stays legible ---- */
.small-text { font-size: 12.5px; }
th { font-size: 12px; }
.muted.small, .small.muted { font-size: 13px; }
.badge { line-height: 1.5; }
.empty { padding: 36px 24px; }
.empty-text { margin: 0; font-size: 15px; }
.empty-actions { justify-content: center; margin-top: 14px; }

/* Helpers some views use. */
.stack { display: flex; flex-direction: column; gap: 16px; }
.grid-2 { display: grid; gap: 16px; grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr)); }
.spread { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.num { text-align: right; font-variant-numeric: tabular-nums; }
.mono { font-family: ui-monospace, "Cascadia Code", Consolas, monospace; }
div.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.checks { border: 0; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.checks legend { font-size: 13px; font-weight: 600; padding: 0; margin-bottom: 4px; }
.copy-row { display: inline-flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.chip-group { display: inline-flex; align-items: center; gap: 2px; }
.chip-remove { padding: 0 6px !important; min-height: 22px !important; font-size: 12px; }
kbd {
  display: inline-block; min-width: 1.6em; padding: 1px 6px; border: 1px solid var(--border); border-bottom-width: 2px;
  border-radius: 5px; background: var(--surface-2); color: var(--text);
  font: 600 11.5px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace; text-align: center;
}
kbd + kbd { margin-left: 3px; }

/* Focus is always visible, also on summaries, rows to choose and table headers. */
summary:focus-visible,
[role="option"]:focus-visible,
.th-sort:focus-visible,
.view-switch button:focus-visible {
  outline: 2px solid var(--accent-ink, var(--accent));
  outline-offset: 2px;
}

/* A softer accent button (e.g. "Edit" next to the primary action). */
.primary-soft { border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); color: var(--accent-ink, var(--accent)); }
.primary-soft:hover { background: var(--accent-soft, var(--surface-2)); }

/* A filled red button for the destructive choice in a dialog. */
button.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
button.danger.solid:hover { background: color-mix(in srgb, var(--danger) 85%, #000); color: #fff; }

/* ---- Wide screens: more room for lists and tables (modern look: themes.css) ---- */
@media (min-width: 1500px) {
  main { max-width: 1400px; }
}
@media (min-width: 1900px) {
  main { max-width: 1680px; }
}

/* ---- Tables: the header stays visible while the table scrolls ---- */
.card.table-wrap { max-height: max(420px, calc(100vh - 180px)); overflow: auto; overscroll-behavior: contain; }
.card.table-wrap > table { border-collapse: separate; border-spacing: 0; }
.card.table-wrap > table > thead th { position: sticky; top: 0; z-index: 2; background: var(--surface-2); box-shadow: inset 0 -1px 0 var(--border); }
tbody tr[hidden] { display: none; }
th.nowrap { white-space: nowrap; }
td.nowrap { white-space: nowrap; }
/* (Selectors with "th >" etc. win over the modern look's general button style.) */
th > button.th-sort {
  all: unset; box-sizing: border-box; display: inline-flex; align-items: center; gap: 4px; cursor: pointer;
  font: inherit; color: inherit; text-transform: inherit; letter-spacing: inherit; border-radius: 4px;
}
.th-sort:hover { color: var(--text); }
.sort-mark { font-size: 11px; opacity: 0.55; }
th[aria-sort] { color: var(--text); }
th[aria-sort] .sort-mark { opacity: 1; color: var(--accent-ink, var(--accent)); }
.table-tools { display: flex; align-items: center; gap: 12px; margin: 0 0 10px; flex-wrap: wrap; }
.table-tools .table-filter { flex: 1 1 260px; width: auto; max-width: 480px; }
.select-cell { width: 36px; padding-right: 0 !important; }
.select-cell input,
.file-card-select input,
.gallery-head input { width: 18px; height: 18px; margin: 0; cursor: pointer; accent-color: var(--accent); }
tr.selected td { background: color-mix(in srgb, var(--accent) 9%, var(--surface)) !important; }
.content-table .content-title a { font-weight: 600; }
.tags-table .renamable .chip { font-size: 13px; }

/* ---- Lists: remembered filters, view switch ---- */
.filter-note {
  display: flex; flex-wrap: wrap; align-items: center; gap: 4px 10px; margin: -8px 0 16px; padding: 6px 12px;
  border-radius: 8px; background: var(--accent-soft, var(--surface-2)); color: var(--text); font-size: 13.5px;
}
.filter-note a { font-weight: 600; }
.view-switch { display: inline-flex; border: 1px solid var(--border); border-radius: 9px; overflow: hidden; margin-left: auto; flex: none; }
div.view-switch > button {
  border: 0; border-radius: 0; background: var(--surface); color: var(--muted); box-shadow: none;
  padding: 6px 11px; min-height: 0; font-size: 13.5px;
}
div.view-switch > button + button { border-left: 1px solid var(--border); }
div.view-switch > button.active { background: var(--accent-soft, var(--surface-2)); color: var(--accent-ink, var(--accent)); font-weight: 650; }

/* ---- Bulk actions: a bar that stays at the bottom of the window ---- */
.bulk-bar {
  position: sticky; bottom: calc(14px + env(safe-area-inset-bottom)); z-index: 30;
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px 16px; margin-top: 16px; padding: 10px 14px;
  border: 1px solid color-mix(in srgb, var(--accent) 45%, var(--border)); border-radius: 12px;
  background: var(--surface); box-shadow: 0 10px 30px rgba(16, 24, 40, 0.2);
}
.bulk-bar .button-row { flex: 1; }
.bulk-count { font-size: 14px; }

/* ---- Renaming in place ---- */
.renamable { display: inline-flex; align-items: center; gap: 4px; max-width: 100%; min-width: 0; }
.renamable > :first-child { min-width: 0; overflow-wrap: anywhere; }
.rename-button { flex: none; padding: 2px 7px !important; min-height: 0 !important; font-size: 14px; opacity: 0.65; }
.renamable:hover .rename-button,
.rename-button:focus-visible { opacity: 1; }
.inline-edit { display: inline-flex; flex-wrap: wrap; align-items: center; gap: 6px; max-width: 100%; }
.inline-edit-input { width: auto; min-width: min(320px, 70vw); flex: 1 1 220px; }
.page-head .renamable h1 { margin: 0; }

/* ---- Dialogs ---- */
dialog.modal {
  width: min(520px, calc(100vw - 24px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px); background: var(--surface); color: var(--text);
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.35); overflow: auto;
}
dialog.modal::backdrop { background: rgba(10, 12, 18, 0.5); }
dialog.modal[open] { animation: havoc-modal-in 0.16s ease-out; }
dialog.modal-danger { border-top: 4px solid var(--danger); }
.modal-box { display: flex; flex-direction: column; gap: 14px; padding: 22px 24px 20px; }
.modal-title { font-size: 18px; margin: 0; overflow-wrap: anywhere; }
.modal-text { margin: 0; font-size: 15px; line-height: 1.55; overflow-wrap: anywhere; }
.modal-box .form-actions { margin-top: 4px; }
.modal-value { margin: 0; user-select: all; white-space: pre-wrap; word-break: break-all; font-size: 14px; }
.modal-box .notice ul { margin: 6px 0 0; }
@keyframes havoc-modal-in {
  from { opacity: 0; transform: translateY(8px) scale(0.98); }
  to { opacity: 1; transform: none; }
}

/* Wide dialogs: a version shown like the entry, comparisons, backup previews. */
dialog.modal-wide { width: min(1100px, calc(100vw - 24px)); }
.modal-box .table-wrap { overflow: auto; max-height: 60vh; border: 1px solid var(--border); border-radius: var(--radius); }

/* ---- Versions side by side (fields and text) ---- */
table.sxs-fields, table.sxs-text { width: 100%; border-collapse: collapse; font-size: 14px; }
table.sxs-fields th, table.sxs-fields td { vertical-align: top; text-align: left; padding: 6px 10px; border-bottom: 1px solid var(--border); overflow-wrap: anywhere; }
table.sxs-fields td:first-child { width: 18%; color: var(--muted); }
table.sxs-fields td:not(:first-child) { width: 41%; }
table.sxs-fields pre { margin: 0; white-space: pre-wrap; font-size: 12.5px; }
table.sxs-text { table-layout: fixed; font: 13px/1.5 ui-monospace, "Cascadia Code", Consolas, monospace; }
table.sxs-text td { width: 50%; padding: 1px 8px; vertical-align: top; white-space: pre-wrap; overflow-wrap: anywhere; border-left: 1px solid var(--border); }
.sxs-old { background: var(--danger-bg); color: var(--text); }
.sxs-new { background: var(--ok-bg); color: var(--text); }
.sxs-changed-row td:first-child { font-weight: 600; color: var(--text); }
tr.sxs-skip td { text-align: center; color: var(--muted); background: var(--surface-2); font-family: inherit; font-size: 12px; padding: 3px; }
.version-view .markdown { border-top: 1px solid var(--border); }

/* ---- History browser, clean-up reports, backups ---- */
.history-filters input[type="date"] { width: auto; }
.history-filters .check { gap: 6px; }
.history-table td { vertical-align: top; }
.prune-form { display: flex; flex-direction: column; gap: 12px; }
.prune-report .badge { margin: 0 3px 3px 0; }
.retention-rules input[type="number"] { width: 7em; }
.retention-rules td .check { white-space: nowrap; }
table.compact-table td { padding: 2px 10px 2px 0; font-size: 13px; }

/* ---- Command palette (Ctrl+K) ---- */
dialog.palette { width: min(640px, calc(100vw - 24px)); margin-top: 12vh; margin-bottom: auto; }
.palette-box { display: flex; flex-direction: column; max-height: min(70vh, 620px); }
.palette-field { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-bottom: 1px solid var(--border); color: var(--muted); }
.palette-field .ico { display: inline-block; flex: none; }
.palette-field input { border: 0; box-shadow: none !important; padding: 6px 0; font-size: 17px; background: transparent; outline: none; }
.palette-list { list-style: none; margin: 0; padding: 6px; overflow-y: auto; flex: 1; }
.palette-group { padding: 10px 10px 4px; font-size: 12px; font-weight: 700; letter-spacing: 0.06em; text-transform: uppercase; color: var(--muted); }
.palette-item { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; padding: 9px 12px; border-radius: 8px; cursor: pointer; font-size: 15px; }
.palette-item[aria-selected="true"] { background: var(--accent-soft, var(--surface-2)); color: var(--accent-ink, var(--accent)); }
.palette-label { min-width: 0; overflow-wrap: anywhere; }
.palette-hint { flex: none; max-width: 45%; color: var(--muted); font-size: 13px; text-align: right; overflow-wrap: anywhere; }
.palette-empty { padding: 18px 12px; color: var(--muted); text-align: center; }
.palette-foot { display: flex; flex-wrap: wrap; gap: 14px; margin: 0; padding: 8px 14px; border-top: 1px solid var(--border); }
.palette-open {
  display: inline-flex; align-items: center; gap: 8px; padding: 6px 10px; color: var(--muted);
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; font-weight: 500;
}
.palette-open:hover { color: var(--text); border-color: color-mix(in srgb, var(--accent) 40%, var(--border)); }
.palette-open kbd { font-size: 11px; }
.shortcut-table td { padding: 6px 8px; border-bottom: 1px solid var(--border); }
.shortcut-table td:first-child { white-space: nowrap; width: 1%; }

/* ---- Content detail: entry and history left, relations and collections beside ---- */
.detail-layout { display: grid; gap: 0 28px; grid-template-columns: minmax(0, 1fr); align-items: start; }
.detail-layout > .back { justify-self: start; }
.detail-aside > div:first-child > .section-title { margin-top: 28px; }
@media (min-width: 1240px) {
  .detail-layout:not(.single) {
    grid-template-columns: minmax(0, 1fr) minmax(300px, 360px);
    grid-template-areas: "back back" "main aside" "history aside";
  }
  .detail-layout:not(.single) > .back { grid-area: back; }
  .detail-layout:not(.single) > .detail-main { grid-area: main; }
  .detail-layout:not(.single) > .detail-aside { grid-area: aside; }
  .detail-layout:not(.single) > .detail-history { grid-area: history; }
  .detail-aside > div:first-child > .section-title { margin-top: 0; }
}

/* ---- Editor: fields side by side where there is room ---- */
.form-card.editor-form { max-width: 980px; }
.editor-fields { display: grid; gap: 18px 20px; grid-template-columns: repeat(auto-fill, minmax(min(100%, 280px), 1fr)); }
.editor-fields > .field:has(textarea),
.editor-fields > .check { grid-column: 1 / -1; }
.form-actions { flex-wrap: wrap; }
.form-actions .form-hint { margin-right: auto; align-self: center; }

/* ---- Collections: adding entries on the collection's page ---- */
.adder { margin-top: 16px; display: flex; flex-direction: column; gap: 10px; }
.adder-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 6px 0; border-bottom: 1px solid var(--border); }
.adder-row:last-child { border-bottom: 0; }

/* ---- Files: drop zone, kind labels, gallery ---- */
.drop-zone { border: 2px dashed color-mix(in srgb, var(--accent) 35%, var(--border)); display: flex; flex-direction: column; gap: 10px; }
.drop-zone.dragging { border-color: var(--accent); background: var(--accent-soft, var(--surface-2)); }
.drop-zone .inline-form { margin: 0; }
.drop-zone p { margin: 0; }
.drop-hint { font-size: 15px; }
.upload-status { font-weight: 600; color: var(--text); }
.file-kind {
  display: inline-grid; place-items: center; width: 48px; height: 48px; border-radius: 8px;
  font: 700 11.5px/1 ui-monospace, "Cascadia Code", Consolas, monospace; letter-spacing: 0.02em;
  background: var(--surface-2); color: var(--text); border: 1px solid var(--border);
}
.file-kind.kind-image { background: color-mix(in srgb, var(--ok) 14%, var(--surface)); }
.file-kind.kind-application { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); }
.file-kind.kind-video,
.file-kind.kind-audio { background: color-mix(in srgb, var(--accent) 14%, var(--surface)); }
.file-kind.kind-text { background: color-mix(in srgb, var(--warn) 14%, var(--surface)); }
.files-table .file-main { min-width: 200px; }
.file-name { overflow-wrap: anywhere; }
.file-grid { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.file-card { position: relative; display: flex; flex-direction: column; overflow: hidden; }
.file-card.selected { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent); }
.file-card-select { position: absolute; top: 8px; left: 8px; z-index: 1; display: inline-flex; padding: 5px; border-radius: 7px; background: var(--surface); box-shadow: var(--shadow); }
.file-card > button.file-card-thumb {
  all: unset; box-sizing: border-box; display: grid; place-items: center; aspect-ratio: 4 / 3; width: 100%;
  background: var(--surface-2); cursor: pointer; border-bottom: 1px solid var(--border);
}
.file-card-thumb:focus-visible { outline: 2px solid var(--accent-ink, var(--accent)); outline-offset: -2px; }
.file-card-thumb img { width: 100%; height: 100%; object-fit: cover; }
.file-card-thumb .file-kind { width: 72px; height: 72px; font-size: 15px; }
.file-card-body { padding: 10px 12px 4px; display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.file-card-body p { margin: 0; }
.file-card-desc { color: var(--muted); }
.file-card-actions { padding: 8px 12px 12px; margin-top: auto; }
.gallery-head { margin: 0 0 10px; }

/* ---- "More" menus: placed by console-ui.js above everything ---- */
.more-actions .menu { z-index: 900; }
.more-actions[open] > summary { background: var(--surface-2); }

/* ---- Phones ---- */
@media (max-width: 640px) {
  .view-switch span { display: none; }
  .view-switch .ico { display: inline-block; }
  .toast { font-size: 14px; }
  .bulk-bar { padding: 8px 10px; }
  .palette-open .palette-open-label,
  .palette-open kbd { display: none; }
  .palette-open .ico { display: inline-block; }
  dialog.palette { margin-top: 8px; }
  .card.table-wrap { max-height: none; }
}

/* ---- Reduced motion ---- */
@media (prefers-reduced-motion: reduce) {
  .toast,
  dialog.modal[open] { animation: none; }
}
:root[data-motion="reduce"] .toast,
:root[data-motion="reduce"] dialog.modal[open] { animation: none; }

/* ---- More contrast ---- */
:root[data-contrast="more"] .toast { outline: 2px solid var(--bg); }
:root[data-contrast="more"] .palette-item[aria-selected="true"] { outline: 2px solid var(--accent); }
:root[data-contrast="more"] dialog.modal { border-width: 2px; }
