:root {
  --bg: #eef1f0;
  --surface: #f7f8f8;
  --surface-hover: #e7ecea;
  --text: #1a2220;
  --muted: #5b6562;
  --line: #d5ddd9;
  --accent: #1f6b5c;
  --accent-hover: #18564a;
  --link: #1f6b5c;
  --link-hover: #18564a;
  --accent-soft: #d7ebe5;
  --header: #15201c;
  --header-text: #e7eeeb;
  --header-muted: #9eb0aa;
  --danger: #9b3a32;
  --danger-soft: #f3ddd9;
  --warn: #8a5a14;
  --warn-soft: #f3e6cc;
  --ok: #1d5c38;
  --ok-soft: #d7eadf;
  --radius: 8px;
  --radius-sm: 6px;
  --shadow: 0 1px 0 rgb(21 32 28 / 0.04), 0 10px 28px rgb(21 32 28 / 0.06);
  --z-header: 40;
  --focus: 0 0 0 3px rgb(31 107 92 / 0.22);
  --font: "Segoe UI", "Apple SD Gothic Neo", "Malgun Gothic", system-ui, sans-serif;
  --mono: ui-monospace, "Cascadia Mono", Consolas, monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121816;
    --surface: #1a221f;
    --surface-hover: #232c28;
    --text: #e6eeea;
    --muted: #9aa8a3;
    --line: #2c3834;
    --accent: #1f6b5c;
    --accent-hover: #18564a;
    --link: #7dceba;
    --link-hover: #b6eadc;
    --accent-soft: #1c3a34;
    --header: #101614;
    --header-text: #e6eeea;
    --header-muted: #8fa19b;
    --danger: #e08a82;
    --danger-soft: #3a2422;
    --warn: #d4a65a;
    --warn-soft: #3a3020;
    --ok: #7dbe98;
    --ok-soft: #1c3328;
    --shadow: 0 1px 0 rgb(0 0 0 / 0.2), 0 12px 32px rgb(0 0 0 / 0.28);
    --focus: 0 0 0 3px rgb(61 154 134 / 0.35);
  }
}

html {
  font-size: 15px;
  color-scheme: light dark;
}

body {
  margin: 0;
  min-height: 100dvh;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
}

a {
  color: var(--link);
}

a:hover {
  color: var(--link-hover);
}

.skip-link {
  position: absolute;
  left: 0.75rem;
  top: -3rem;
  z-index: calc(var(--z-header) + 1);
  padding: 0.45rem 0.8rem;
  background: var(--accent);
  color: #fff;
  border-radius: var(--radius-sm);
}

.skip-link:focus {
  top: 0.75rem;
  color: #fff;
}

.app-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: var(--header);
  color: var(--header-text);
  border-bottom: 1px solid rgb(255 255 255 / 0.06);
}

.app-header .navbar {
  min-height: 56px;
  padding-top: 0.35rem;
  padding-bottom: 0.35rem;
}

.app-header .navbar-brand,
.app-header .nav-link,
.app-header .navbar-text,
.app-header .btn-link {
  color: var(--header-text) !important;
}

.app-header .navbar-brand {
  font-weight: 650;
  letter-spacing: 0.01em;
  margin-right: 1.25rem;
}

.app-header .nav-link {
  border-radius: var(--radius-sm);
  padding: 0.35rem 0.65rem !important;
}

.app-header .nav-link:hover,
.app-header .btn-link:hover {
  color: #fff !important;
  background: rgb(255 255 255 / 0.08);
}

.app-header .nav-link.is-current {
  background: rgb(255 255 255 / 0.12);
  color: #fff !important;
}

.app-header .navbar-nav {
  flex-wrap: nowrap;
}

.app-header .navbar-toggler {
  border-color: rgb(255 255 255 / 0.28);
}

.app-header .navbar-toggler-icon {
  filter: invert(1);
}

.app-main {
  padding: 1.75rem 0 3.5rem;
}

.app-footer {
  border-top: 1px solid var(--line);
  color: var(--muted);
  padding: 1rem 0 1.75rem;
  font-size: 0.85rem;
}

body.is-guest {
  display: flex;
  flex-direction: column;
}

body.is-guest .app-main {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding-top: 2rem;
  padding-bottom: 2rem;
}

h1 {
  font-size: 1.55rem;
  font-weight: 650;
  letter-spacing: -0.02em;
  margin-bottom: 0.35rem;
}

.lead-copy {
  color: var(--muted);
  margin-bottom: 0;
  max-width: 62ch;
  line-height: 1.5;
}

.page-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
  margin-bottom: 1.35rem;
}

@media (max-width: 767.98px) {
  .page-head {
    flex-direction: column;
    align-items: stretch;
  }
}

.auth-card,
.form-narrow {
  max-width: 28rem;
}

.auth-card-wide {
  max-width: 36rem;
}

.auth-card {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.75rem;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
}

.stat-card {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  text-decoration: none;
  color: inherit;
  transition: transform 0.15s cubic-bezier(0.16, 1, 0.3, 1), border-color 0.15s ease;
}

.stat-card:hover {
  color: inherit;
  border-color: var(--accent);
}

.stat-card.muted {
  opacity: 0.7;
}

.stat-label {
  font-size: 0.8rem;
  color: var(--muted);
}

.stat-value {
  font-size: 1.7rem;
  font-weight: 650;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.03em;
}

.stat-hint {
  font-size: 0.8rem;
  color: var(--muted);
}

.empty-state {
  background: var(--surface);
  border: 1px dashed var(--line);
  border-radius: var(--radius);
  padding: 1.35rem 1.4rem;
  color: var(--muted);
}

.detail-list {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1.2rem;
}

.detail-list > div {
  display: grid;
  grid-template-columns: 7rem 1fr;
  gap: 0.75rem;
  padding: 0.55rem 0;
  border-bottom: 1px solid var(--line);
}

.detail-list > div:last-child {
  border-bottom: 0;
}

.detail-list dt {
  color: var(--muted);
  font-weight: 500;
}

.table {
  --bs-table-bg: var(--surface);
  --bs-table-color: var(--text);
  --bs-table-border-color: var(--line);
  --bs-table-hover-bg: var(--surface-hover);
  --bs-table-striped-bg: var(--surface-hover);
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
}

.table > :not(caption) > * > * {
  background-color: var(--surface);
  color: var(--text);
  border-bottom-color: var(--line);
}

.form-control,
.form-select {
  background: var(--surface);
  color: var(--text);
  border-color: var(--line);
  border-radius: var(--radius-sm);
}

.form-control::placeholder {
  color: var(--muted);
}

.form-control:focus,
.form-select:focus {
  background: var(--surface);
  color: var(--text);
  border-color: var(--accent);
  box-shadow: var(--focus);
}

.form-label {
  color: var(--text);
  font-weight: 550;
}

.form-hint {
  margin: 0.35rem 0 0;
  color: var(--muted);
  font-size: 0.85rem;
}

.btn {
  border-radius: var(--radius-sm);
}

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover,
.btn-primary:focus {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
}

.btn-outline-secondary {
  color: var(--text);
  border-color: var(--line);
  background: transparent;
}

.btn-outline-secondary:hover {
  color: var(--text);
  background: var(--surface-hover);
  border-color: var(--muted);
}

.btn-outline-light {
  color: var(--header-text);
  border-color: rgb(255 255 255 / 0.28);
}

.btn:active {
  transform: translateY(1px);
}

.alert {
  border-radius: var(--radius);
  border: 1px solid var(--line);
}

.alert-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: transparent;
}

.alert-info,
.alert-success {
  background: var(--accent-soft);
  color: var(--ok);
  border-color: transparent;
}

.user-meta {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex: 0 0 auto;
  color: var(--header-muted) !important;
  font-size: 0.85rem;
}

.user-meta form {
  display: flex;
  margin: 0;
}

.user-name {
  max-width: 11rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.app-header .user-logout {
  padding: 0.2rem 0.5rem !important;
  font-size: 0.85rem;
}

.token-once {
  background: var(--warn-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.2rem 1.35rem;
  margin-bottom: 1.5rem;
}

.token-once h2 {
  font-size: 1.1rem;
  font-weight: 650;
  margin-bottom: 0.4rem;
}

.token-row {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

.token-value {
  font-family: var(--mono);
  letter-spacing: 0.02em;
}

.token-meta {
  margin: 0.65rem 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.site-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
}

.site-card h3 {
  font-size: 1.05rem;
  font-weight: 650;
  margin: 0 0 0.25rem;
}

.site-meta {
  color: var(--muted);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

.thumbprint {
  font-family: var(--mono);
  font-size: 0.8rem;
  word-break: break-all;
}

.install-guide {
  min-height: 16rem;
  white-space: pre;
}

.status-pill {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
}

.status-pill.is-online {
  background: var(--ok-soft);
  color: var(--ok);
}

.status-pill.is-offline,
.status-pill.is-unknown {
  background: var(--surface-hover);
  color: var(--muted);
}

.status-pill.is-revoked {
  background: var(--danger-soft);
  color: var(--danger);
}

.site-badges {
  margin: 0 0 0.75rem;
}

.op-badge {
  display: inline-block;
  margin: 0 0.25rem 0.25rem 0;
  padding: 0.12rem 0.5rem;
  border-radius: var(--radius-sm);
  font-size: 0.75rem;
  font-weight: 600;
}

.op-badge.recommend,
.op-badge.is-warn {
  background: var(--warn-soft);
  color: var(--warn);
}

.op-badge.is-pass {
  background: var(--ok-soft);
  color: var(--ok);
}

.op-badge.is-fail {
  background: var(--danger-soft);
  color: var(--danger);
}

.stat-card.tone-green {
  box-shadow: inset 3px 0 0 var(--ok);
}

.stat-card.tone-yellow {
  box-shadow: inset 3px 0 0 var(--warn);
}

.stat-card.tone-red {
  box-shadow: inset 3px 0 0 var(--danger);
}

.dash-columns {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 1.5rem;
  margin-top: 1.75rem;
}

.dash-columns h2 {
  font-size: 1.05rem;
  font-weight: 650;
  margin-bottom: 0.75rem;
}

.plain-list {
  list-style: none;
  padding: 0;
  margin: 0;
}

.plain-list li {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.8rem 1rem;
  margin-bottom: 0.5rem;
}

.filter-row {
  margin-bottom: 1rem;
}

.filter-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 0.6rem;
  align-items: center;
  margin-bottom: 1.25rem;
}

.filter-bar .form-control,
.filter-bar .form-select {
  max-width: 16rem;
}

.nav-search {
  display: flex;
  flex: 0 1 16.5rem;
  align-items: stretch;
  min-width: 13.5rem;
  max-width: 18rem;
  height: 2.1rem;
  margin: 0 0.85rem 0 auto;
  overflow: hidden;
  border: 1px solid rgb(255 255 255 / 0.16);
  border-radius: var(--radius-sm);
  background: rgb(255 255 255 / 0.08);
}

.nav-search .form-control {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  height: 100%;
  padding: 0 0.7rem;
  border: 0;
  background: transparent;
  box-shadow: none;
  color: var(--header-text);
  font-size: 0.85rem;
}

.nav-search .form-control::placeholder {
  color: var(--header-muted);
}

.nav-search .form-control:focus {
  background: transparent;
  color: #fff;
  box-shadow: none;
}

.nav-search button {
  flex: 0 0 auto;
  padding: 0 0.85rem;
  border: 0;
  border-left: 1px solid rgb(255 255 255 / 0.16);
  background: rgb(255 255 255 / 0.1);
  color: var(--header-text);
  font-size: 0.85rem;
  line-height: 1;
  white-space: nowrap;
}

.nav-search button:hover {
  background: rgb(255 255 255 / 0.16);
  color: #fff;
}

.nav-search:focus-within {
  border-color: rgb(125 206 186 / 0.55);
}

.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.2rem 1.3rem 1.3rem;
  margin-bottom: 1rem;
}

.panel h2 {
  font-size: 1.05rem;
  font-weight: 650;
  margin-bottom: 0.3rem;
}

.panel .lead-copy {
  margin-bottom: 0;
}

.panel .detail-list {
  background: transparent;
  border: 0;
  padding: 0.4rem 0 0;
}

.panel .table {
  margin-bottom: 0;
}

.timeline {
  list-style: none;
  padding: 0;
  margin: 0 0 1.5rem;
}

.timeline li {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  margin-bottom: 0.5rem;
}

tr.is-resolved {
  opacity: 0.65;
}

.secret-key {
  font-family: var(--mono);
  letter-spacing: 0.06em;
  background: var(--surface-hover);
  padding: 0.2rem 0.45rem;
  border-radius: var(--radius-sm);
}

.mfa-qr {
  display: flex;
  justify-content: center;
  margin: 1.25rem 0 1rem;
}

.mfa-qr svg {
  width: min(14rem, 100%);
  height: auto;
  background: #fff;
  padding: 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
}

.mfa-fallback {
  margin: 0 0 1.25rem;
}

.mfa-fallback summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 0.9rem;
}

.mfa-fallback .detail-list {
  margin-top: 0.75rem;
}

.mfa-steps {
  padding-left: 1.2rem;
  color: var(--muted);
}

.recovery-codes {
  list-style: none;
  padding: 0.75rem 1rem;
  margin: 1rem 0 1.25rem;
  background: var(--surface-hover);
  border-radius: var(--radius-sm);
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.4rem 1rem;
}

.recovery-codes code {
  font-family: var(--mono);
}

@media (prefers-reduced-motion: reduce) {
  .stat-card,
  .btn {
    transition: none;
  }

  .btn:active,
  .stat-card:hover {
    transform: none;
  }
}

@media (prefers-reduced-transparency: reduce) {
  .app-header {
    background: #15201c;
  }
}

@media (max-width: 1199.98px) {
  .app-header .navbar-nav {
    flex-wrap: wrap;
  }

  .nav-search {
    flex: 1 1 auto;
    width: 100%;
    min-width: 0;
    max-width: none;
    margin: 0.65rem 0 0.35rem;
  }

  .user-meta {
    padding: 0.2rem 0 0.55rem;
  }

  .user-name {
    max-width: none;
  }
}
