/* USG Update Server admin UI. One stylesheet, no inline styles anywhere (CSP: style-src 'self'). */

:root {
  color-scheme: light dark;
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #eef2f9;
  --line: #d9e0ec;
  --text: #17202e;
  --muted: #56667f;
  --accent: #2459d6;
  --accent-text: #ffffff;
  --ok: #17794f;
  --ok-bg: #dff5ea;
  --warn: #8a5a00;
  --warn-bg: #fdf0d2;
  --bad: #b3243f;
  --bad-bg: #fde3e8;
  --info: #1f4fb8;
  --info-bg: #e1eafc;
  --neutral-bg: #e6ebf3;
  --code-bg: #0c1220;
  --code-text: #d5ddec;
  --header-a: #0a1830;
  --header-b: #14305a;
  --header-text: #ffffff;
  --header-muted: #b4c5e3;
  --focus: #1d6bff;
  --radius: 10px;
  --shadow: 0 18px 48px rgba(10, 20, 40, 0.28);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1420;
    --surface: #171e2e;
    --surface-2: #1e2740;
    --line: #2c3654;
    --text: #e7ecf5;
    --muted: #a0adc6;
    --accent: #6c9dff;
    --accent-text: #08111f;
    --ok: #4fd6a0;
    --ok-bg: #12382b;
    --warn: #f6b94a;
    --warn-bg: #3b2d0e;
    --bad: #ff8fa3;
    --bad-bg: #44161f;
    --info: #9dbcff;
    --info-bg: #1a2b52;
    --neutral-bg: #262f47;
    --focus: #8fb4ff;
    --shadow: 0 18px 48px rgba(0, 0, 0, 0.55);
  }
}

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

[hidden] {
  display: none !important;
}

html {
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

h1 {
  font-size: 20px;
  margin: 0 0 14px;
  font-weight: 650;
}

h2 {
  font-size: 15px;
  margin: 0 0 10px;
  font-weight: 650;
}

h3 {
  font-size: 13px;
  margin: 14px 0 6px;
  font-weight: 650;
}

p {
  margin: 0 0 10px;
}

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

code,
.mono {
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

code {
  background: var(--surface-2);
  padding: 1px 5px;
  border-radius: 4px;
}

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

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

.small {
  font-size: 12px;
}

.nowrap {
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  left: -999px;
  top: 0;
  background: var(--surface);
  color: var(--text);
  padding: 8px 12px;
  z-index: 100;
}

.skip-link:focus {
  left: 8px;
  top: 8px;
}

/* --- header and navigation -------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
  padding: 10px 20px;
  background: linear-gradient(90deg, var(--header-a), var(--header-b));
  color: var(--header-text);
}

.topbar .logo {
  height: 26px;
  width: auto;
  display: block;
}

.brand-title {
  font-size: 15px;
  font-weight: 600;
  padding-left: 12px;
  border-left: 1px solid rgba(255, 255, 255, 0.3);
}

.spacer {
  flex: 1 1 auto;
}

.who {
  color: var(--header-muted);
  font-size: 12px;
}

.who strong {
  color: var(--header-text);
}

.inline-form {
  display: inline;
  margin: 0;
}

.nav {
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  padding: 0 12px;
  overflow-x: auto;
}

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

.nav a {
  display: block;
  padding: 11px 13px;
  color: var(--muted);
  text-decoration: none;
  font-weight: 550;
  white-space: nowrap;
  border-bottom: 3px solid transparent;
}

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

.nav a[aria-current="page"] {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.main {
  padding: 20px;
  max-width: 1400px;
  margin: 0 auto;
}

.main:focus {
  outline: none;
}

/* --- panels, cards, tables ---------------------------------------------- */

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-top: 16px;
}

.panel-head {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 10px;
}

.panel-head h2 {
  margin: 0;
}

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

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px;
  min-width: 0;
}

.card-label {
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.card-value {
  font-size: 22px;
  font-weight: 650;
  margin-top: 4px;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
}

.card-note {
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--line);
  font-size: 13px;
  vertical-align: middle;
}

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

td {
  overflow-wrap: anywhere;
}

.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

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

.actions .btn + .btn {
  margin-left: 4px;
}

.pill {
  display: inline-block;
  padding: 1px 9px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 650;
  background: var(--neutral-bg);
  color: var(--muted);
  white-space: nowrap;
}

.pill-ok {
  background: var(--ok-bg);
  color: var(--ok);
}

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

.pill-bad {
  background: var(--bad-bg);
  color: var(--bad);
}

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

.topbar .pill {
  background: rgba(255, 255, 255, 0.16);
  color: var(--header-text);
  margin-left: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  list-style: none;
  margin: 0 0 12px;
  padding: 0;
}

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--ok-bg);
  color: var(--ok);
  border-radius: 999px;
  padding: 2px 4px 2px 11px;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
}

.chip-plain {
  padding-right: 11px;
}

.chip button {
  border: 0;
  background: transparent;
  color: var(--bad);
  font: inherit;
  font-weight: 700;
  cursor: pointer;
  border-radius: 999px;
  padding: 0 7px;
}

.bars {
  display: grid;
  grid-template-columns: minmax(90px, 200px) 1fr minmax(60px, auto);
  gap: 6px 12px;
  align-items: center;
}

.bars progress {
  width: 100%;
  height: 8px;
  appearance: none;
  -webkit-appearance: none;
  border: 0;
  border-radius: 5px;
  background: var(--surface-2);
  overflow: hidden;
}

.bars progress::-webkit-progress-bar {
  background: var(--surface-2);
}

.bars progress::-webkit-progress-value {
  background: var(--accent);
}

.bars progress::-moz-progress-bar {
  background: var(--accent);
}

.kv {
  display: grid;
  grid-template-columns: minmax(120px, 220px) 1fr;
  gap: 4px 14px;
  margin: 0;
}

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

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

.plain-list {
  margin: 0;
  padding-left: 18px;
}

pre.log {
  background: var(--code-bg);
  color: var(--code-text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin: 10px 0 0;
  overflow: auto;
  max-height: 460px;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.detail {
  max-width: 420px;
  color: var(--muted);
  font: 12px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

.pager {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 12px;
}

/* --- forms -------------------------------------------------------------- */

.btn {
  font: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 7px 13px;
  cursor: pointer;
}

.btn:hover:not(:disabled) {
  border-color: var(--accent);
}

.btn:disabled {
  opacity: 0.55;
  cursor: default;
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-text);
  font-weight: 650;
}

.btn-danger {
  background: var(--bad);
  border-color: var(--bad);
  color: var(--surface);
  font-weight: 650;
}

.btn-small {
  padding: 4px 9px;
  font-size: 12px;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.12);
  border-color: rgba(255, 255, 255, 0.28);
  color: var(--header-text);
}

.btn-ghost:hover:not(:disabled) {
  border-color: var(--header-text);
}

.btn-block {
  width: 100%;
  padding: 11px;
}

.form-grid {
  display: grid;
  gap: 10px 12px;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  align-items: end;
  margin-top: 12px;
}

.form-stack {
  display: grid;
  gap: 12px;
  max-width: 460px;
}

.field {
  min-width: 0;
}

.field-wide {
  grid-column: 1 / -1;
}

label,
.label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 550;
  margin-bottom: 4px;
}

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

textarea {
  font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  resize: vertical;
}

input[type="checkbox"] {
  width: auto;
  margin: 0;
}

.check {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 400;
  margin: 0;
}

.help {
  color: var(--muted);
  font-size: 12px;
  margin: 4px 0 0;
}

.notice {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 9px 12px;
  margin: 0 0 14px;
  background: var(--info-bg);
  color: var(--info);
}

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

.form-error,
.notice-error {
  border: 1px solid var(--bad);
  border-radius: 8px;
  padding: 8px 11px;
  margin: 0 0 12px;
  background: var(--bad-bg);
  color: var(--bad);
  font-size: 13px;
  white-space: pre-line;
}

/* --- help popups (UI-3: help.js, _macros.html help(), ui.js helpTip()) ---- */

.page-head {
  position: relative;
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 14px;
}

.page-head h1 {
  margin: 0;
}

.panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

.help-tip {
  position: relative;
  display: inline-flex;
  flex: none;
}

.help-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  padding: 0;
  border: 1.5px solid var(--muted);
  border-radius: 50%;
  background: transparent;
  color: var(--muted);
  font: italic 700 13px/1 Georgia, "Times New Roman", serif;
  cursor: pointer;
}

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

.help-btn[aria-expanded="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--accent-text);
}

/* below the button, start-aligned; help.js flips it with -end / -up near the window edge */
.help-pop {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  z-index: 50;
  width: max-content;
  max-width: min(440px, calc(100vw - 32px));
  max-height: min(60vh, 440px);
  overflow-y: auto;
  padding: 10px 14px 12px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  font-size: 13px;
  font-weight: 400;
  text-align: left;
  overflow-wrap: break-word;
}

.help-pop-end {
  left: auto;
  right: 0;
}

.help-pop-up {
  top: auto;
  bottom: calc(100% + 6px);
}

.help-pop-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.help-pop-title {
  margin: 2px 0 0;
  font-weight: 650;
}

.help-close {
  flex: none;
  width: 24px;
  height: 24px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
}

.help-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.help-pop-body p {
  margin: 0 0 8px;
}

.help-pop-body p:last-child {
  margin-bottom: 0;
}

/* --- dialogs and toasts --------------------------------------------------- */

dialog.modal {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0;
  background: var(--surface);
  color: var(--text);
  width: 460px;
  max-width: calc(100vw - 32px);
  box-shadow: var(--shadow);
}

dialog.modal::backdrop {
  background: rgba(5, 9, 18, 0.6);
}

.modal-form {
  padding: 20px;
  margin: 0;
}

.modal-title {
  font-size: 16px;
  margin: 0 0 14px;
}

.modal-body {
  display: grid;
  gap: 12px;
  max-height: 62vh;
  overflow-y: auto;
  padding: 2px;
}

.modal-message {
  margin: 0;
  overflow-wrap: anywhere;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 16px;
}

.secret-row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.secret-value {
  flex: 1;
  min-width: 0;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 14px;
  letter-spacing: 0.04em;
}

.toasts {
  position: fixed;
  right: 16px;
  bottom: 16px;
  display: grid;
  gap: 8px;
  z-index: 60;
  max-width: min(420px, calc(100vw - 32px));
}

.toast {
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--line);
  border-left: 4px solid var(--ok);
  border-radius: 8px;
  padding: 10px 14px;
  box-shadow: var(--shadow);
  overflow-wrap: anywhere;
  white-space: pre-line;
}

.toast-error {
  border-left-color: var(--bad);
}

/* --- two-factor authentication (account page) ----------------------------- */

.steps {
  margin: 0 0 14px;
  padding-left: 20px;
  display: grid;
  gap: 10px;
}

/* the QR code is black on white whatever the theme: scanners need the contrast */
.qr {
  display: block;
  width: 220px;
  height: 220px;
  max-width: 100%;
  margin: 8px 0 0;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
}

.setup-key {
  display: inline-block;
  margin-top: 6px;
  padding: 6px 10px;
  font-size: 15px;
  letter-spacing: 0.06em;
  user-select: all;
  overflow-wrap: anywhere;
}

.recovery-codes {
  list-style: none;
  margin: 10px 0;
  padding: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 220px));
  gap: 6px 14px;
}

.recovery-codes code {
  font-size: 14px;
  user-select: all;
}

/* --- login ---------------------------------------------------------------- */

body.login {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(160deg, var(--header-a), #0a0f1c);
  color: #e7ecf5;
}

.login-wrap {
  width: 100%;
  max-width: 400px;
}

.login-brand {
  text-align: center;
  margin-bottom: 22px;
}

.login-brand img {
  height: 40px;
  width: auto;
}

.login-card {
  background: #121a2e;
  border: 1px solid #223154;
  border-radius: 16px;
  padding: 28px;
  box-shadow: var(--shadow);
  display: grid;
  gap: 14px;
}

.login-card h1 {
  text-align: center;
  margin: 0;
}

.login-card .login-sub {
  text-align: center;
  color: #a9b8d6;
  margin: 0;
}

.login-card label {
  color: #a9b8d6;
}

.login-card input {
  background: #0c1322;
  border-color: #2c3c63;
  color: #e7ecf5;
  padding: 10px 12px;
}

.login-card .form-error {
  background: #44161f;
  border-color: #ff8fa3;
  color: #ffb3c0;
  margin: 0;
}

.login-card .help,
.login-card a {
  color: #a9b8d6;
}

.login-card .btn-primary {
  background: #2d6cff;
  border-color: #2d6cff;
  color: #ffffff;
}

.login-foot {
  text-align: center;
  color: #8496bd;
  font-size: 11px;
  margin-top: 18px;
}

@media (max-width: 640px) {
  .main {
    padding: 14px;
  }

  .topbar {
    padding: 10px 14px;
  }

  .bars {
    grid-template-columns: 1fr 1fr auto;
  }

  .kv {
    grid-template-columns: 1fr;
  }

  /* help popups span the heading they belong to (.page-head / .panel-head) */
  .help-tip {
    position: static;
  }

  .help-pop,
  .help-pop.help-pop-end {
    left: 0;
    right: 0;
    width: auto;
    max-width: none;
  }
}

@media (prefers-reduced-motion: no-preference) {
  .btn,
  .nav a {
    transition: border-color 0.15s, color 0.15s;
  }
}
