/*
  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);
}

a {
  color: 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);
  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;
}

/* Set by console-auth.js once a project's own sign-in image has loaded. */
.auth[style*="--login-image"] {
  background-image: var(--login-image);
  background-size: cover;
  background-position: center;
}

.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);
  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);
  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 */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: var(--bg);
  padding: 10px 18px;
  border-radius: 8px;
  font-size: 14px;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.2);
  max-width: calc(100% - 32px);
  z-index: 20;
}

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

/* ---- 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);
  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);
  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); 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);
}

.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;
}

.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;
}
