:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #fff;
  --text: #1f2937;
  --muted: #667085;
  --line: #d9e0ea;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #dc2626;
  --ok: #059669;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

a {
  color: inherit;
  text-decoration: none;
}

button,
input,
select,
textarea {
  font: inherit;
}

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 236px minmax(0, 1fr);
}

.side {
  background: #111827;
  color: #e5e7eb;
  padding: 18px 14px;
}

.brand {
  display: grid;
  gap: 4px;
  padding: 8px 10px 20px;
}

.brand strong {
  font-size: 18px;
}

.brand span {
  color: #9ca3af;
  font-size: 12px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav a,
.logout-button {
  display: block;
  width: 100%;
  border: 0;
  border-radius: 7px;
  background: transparent;
  color: #d1d5db;
  cursor: pointer;
  padding: 10px;
  text-align: left;
}

.nav a.active,
.nav a:hover,
.logout-button:hover {
  background: #1f2937;
  color: #fff;
}

.main {
  min-width: 0;
}

.topbar {
  height: 62px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 0 24px;
  border-bottom: 1px solid var(--line);
  background: rgba(255, 255, 255, .92);
}

.content {
  padding: 24px;
}

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

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: 24px;
  line-height: 1.2;
}

h2 {
  font-size: 16px;
}

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

.panel {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
}

.panel-body {
  padding: 18px;
}

.grid {
  display: grid;
  gap: 16px;
}

.stats {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat {
  padding: 18px;
}

.stat strong {
  display: block;
  font-size: 28px;
}

.table {
  width: 100%;
  border-collapse: collapse;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
}

.table th,
.table td {
  border-bottom: 1px solid var(--line);
  padding: 11px 12px;
  text-align: left;
  vertical-align: top;
}

.table th {
  background: #f8fafc;
  color: #475467;
  font-size: 12px;
  font-weight: 650;
}

.table tr:last-child td {
  border-bottom: 0;
}

.actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.copy-link-row {
  display: flex;
  align-items: stretch;
  gap: 8px;
}

.copy-link-row .copy-link-input {
  flex: 1 1 auto;
  min-width: 0;
  font-family: "Cascadia Code", Consolas, monospace;
}

.copy-link-row .button {
  flex: 0 0 auto;
}

.button,
button.button {
  min-height: 34px;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 12px;
}

.button.primary {
  border-color: var(--primary);
  background: var(--primary);
  color: #fff;
}

.button.primary:hover {
  background: var(--primary-dark);
}

.button.danger {
  border-color: #fecaca;
  color: var(--danger);
}

.form {
  display: grid;
  gap: 16px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 16px;
}

.field {
  display: grid;
  gap: 7px;
}

.field label {
  color: #344054;
  font-size: 13px;
  font-weight: 650;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: #fff;
  color: var(--text);
  min-height: 38px;
  padding: 8px 10px;
  outline: none;
}

.field textarea {
  min-height: 180px;
  resize: vertical;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 13px;
  line-height: 1.5;
}

.field textarea.source-editor {
  min-height: 480px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37, 99, 235, .12);
}

.checks {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
}

.checks label {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  color: #344054;
  font-size: 13px;
}

.switch-line {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: #344054;
  font-size: 13px;
  font-weight: 650;
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  background: #eef2ff;
  color: #3730a3;
  font-size: 12px;
  padding: 3px 8px;
  white-space: nowrap;
}

.badge.off {
  background: #f3f4f6;
  color: #6b7280;
}

.badge.ok {
  background: #d1fae5;
  color: #065f46;
}

.badge.warn {
  background: #ffedd5;
  color: #9a3412;
}

.badge.info {
  background: #e0f2fe;
  color: #075985;
}

.badge.danger {
  background: #fee2e2;
  color: #991b1b;
}

.log-time {
  width: 168px;
  white-space: nowrap;
}

.log-event {
  width: 170px;
}

.log-event small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 12px;
}

.log-actor {
  width: 180px;
}

.log-script {
  width: 260px;
}

.log-detail {
  min-width: 360px;
}

.log-detail-item {
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 8px;
  margin: 0 0 7px;
  line-height: 1.45;
}

.log-detail-item:last-child {
  margin-bottom: 0;
}

.log-detail-item strong {
  color: #344054;
  font-size: 12px;
  white-space: nowrap;
}

.log-detail-item span {
  min-width: 0;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.log-detail-item.url span {
  color: #1d4ed8;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 12px;
}

.log-detail-item.code span {
  max-height: 110px;
  overflow: auto;
  border-radius: 7px;
  background: #111827;
  color: #e5e7eb;
  padding: 8px;
  white-space: pre-wrap;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 12px;
}

.flash {
  border-radius: 8px;
  margin-bottom: 14px;
  padding: 11px 12px;
}

.flash.success {
  background: #ecfdf3;
  border: 1px solid #abefc6;
  color: #067647;
}

.flash.error {
  background: #fef3f2;
  border: 1px solid #fecdca;
  color: #b42318;
}

.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth-card {
  width: min(460px, 100%);
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
}

.code {
  border-radius: 7px;
  background: #111827;
  color: #e5e7eb;
  font-family: "Cascadia Code", Consolas, monospace;
  font-size: 13px;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
}

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

.totp-cell {
  min-width: 310px;
}

.totp-control,
.totp-empty {
  display: grid;
  gap: 8px;
}

.totp-uri {
  display: block;
  max-width: 300px;
  overflow: hidden;
  border-radius: 6px;
  background: #f8fafc;
  color: #475467;
  padding: 6px 8px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.totp-actions {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px;
}

.totp-qr-wrap {
  position: relative;
  display: inline-flex;
}

.totp-qr-popover {
  position: absolute;
  z-index: 30;
  left: 50%;
  bottom: calc(100% + 10px);
  display: none;
  width: 228px;
  transform: translateX(-50%);
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  box-shadow: 0 16px 38px rgba(16, 24, 40, 0.18);
  padding: 15px;
  text-align: center;
}

.totp-qr-wrap.is-open .totp-qr-popover {
  display: grid;
  place-items: center;
  gap: 9px;
}

.totp-qr-popover::after {
  content: "";
  position: absolute;
  top: 100%;
  left: 50%;
  width: 10px;
  height: 10px;
  transform: translate(-50%, -5px) rotate(45deg);
  border-right: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: #fff;
}

.totp-qr-wrap.place-below .totp-qr-popover {
  top: calc(100% + 10px);
  bottom: auto;
}

.totp-qr-wrap.place-below .totp-qr-popover::after {
  top: auto;
  bottom: 100%;
  transform: translate(-50%, 5px) rotate(225deg);
}

.totp-qr-code {
  display: grid;
  place-items: center;
  min-width: 196px;
  min-height: 196px;
  color: var(--muted);
  font-size: 12px;
}

.totp-qr-code canvas,
.totp-qr-code img {
  display: block;
  max-width: 196px;
  height: auto;
}

.totp-qr-popover small {
  color: var(--muted);
  line-height: 1.4;
}

@media (max-width: 900px) {
  .shell {
    grid-template-columns: 1fr;
  }

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