:root {
  --bg: #000; --panel: #0d0d0d; --line: #262626; --text: #f2f2f2; --muted: #8a8a8a;
  --up: #3ecf8e; --down: #ff5c5c; --warn: #f5b942; --off: #555;
  color-scheme: dark;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); font: 14px/1.45 ui-sans-serif, system-ui, -apple-system, "Segoe UI", sans-serif; padding: 24px 16px; }
body.narrow { display: grid; place-items: center; min-height: 100vh; }
a { color: inherit; }
h1 { font-size: 22px; font-weight: 600; margin: 8px 0 12px; }
h2 { font-size: 15px; font-weight: 600; margin: 0; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.brand { font-weight: 700; letter-spacing: -.01em; font-size: 15px; }
.brand span { font-weight: 400; color: var(--muted); }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
.auth { width: 100%; max-width: 380px; }
label { display: block; margin: 12px 0; color: var(--muted); font-size: 13px; }
input { display: block; width: 100%; margin-top: 6px; padding: 10px 12px; background: #000; color: var(--text); border: 1px solid var(--line); border-radius: 8px; font: inherit; }
input:focus { outline: 2px solid #fff; outline-offset: -1px; }
input.code { font-size: 20px; letter-spacing: .2em; font-variant-numeric: tabular-nums; }
button, .button { display: inline-block; padding: 8px 14px; border-radius: 999px; border: 1px solid var(--line); background: transparent; color: var(--text); font: inherit; cursor: pointer; text-decoration: none; }
button:hover, .button:hover { border-color: #555; }
button:disabled { opacity: .5; cursor: wait; }
.primary { background: #fff; color: #000; border-color: #fff; font-weight: 600; }
.primary:hover { background: #ddd; }
.auth .primary { width: 100%; margin-top: 8px; padding: 11px; text-align: center; }
.danger { background: var(--down); border-color: var(--down); color: #000; font-weight: 600; }
.error { color: var(--down); }
.qr { background: #fff; border-radius: 10px; padding: 8px; width: 200px; margin: 12px auto; }
.qr svg { display: block; width: 100%; height: auto; }
.secret { display: block; word-break: break-all; padding: 8px; background: #000; border-radius: 6px; margin-top: 6px; }
details summary { cursor: pointer; color: var(--muted); }
.codes { list-style: none; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0; }
.codes code { display: block; padding: 8px; background: #000; border: 1px solid var(--line); border-radius: 6px; text-align: center; }

/* dashboard */
body.wide main, header.top { max-width: 1100px; margin: 0 auto; }
header.top { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.top-actions { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.menu { position: relative; }
.menu summary { list-style: none; padding: 8px 14px; border: 1px solid var(--line); border-radius: 999px; color: var(--text); }
.menu summary::-webkit-details-marker { display: none; }
.menu-body { position: absolute; right: 0; top: calc(100% + 6px); background: var(--panel); border: 1px solid var(--line); border-radius: 10px; padding: 8px; z-index: 5; display: grid; gap: 6px; min-width: 180px; }
.menu-body button { width: 100%; text-align: left; border-radius: 6px; }
.summary { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 16px; }
.stat { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 14px 16px; }
.stat b { display: block; font-size: 26px; font-weight: 600; font-variant-numeric: tabular-nums; }
.banner { border: 1px solid var(--down); color: var(--down); border-radius: 10px; padding: 10px 14px; margin-bottom: 12px; }
.apps { display: grid; gap: 14px; margin-bottom: 16px; }
.app-head { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.app-head h2 { font-size: 17px; }
.app-head .spacer { flex: 1; }
.pill { font-size: 12px; padding: 2px 10px; border-radius: 999px; border: 1px solid currentColor; white-space: nowrap; }
.pill.up { color: var(--up); } .pill.down { color: var(--down); } .pill.warn { color: var(--warn); } .pill.off { color: var(--muted); }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--off); margin-right: 8px; vertical-align: middle; flex: none; }
.dot.up { background: var(--up); box-shadow: 0 0 8px var(--up); } .dot.down { background: var(--down); } .dot.warn { background: var(--warn); }
.rows { margin-top: 14px; border-top: 1px solid var(--line); }
.row { display: grid; grid-template-columns: minmax(0, 2.2fr) minmax(0, 2fr) auto; gap: 12px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--line); }
.row:last-child { border-bottom: 0; }
.row .name { overflow-wrap: anywhere; }
.row .meta { color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
.row .meta span + span::before { content: "·"; margin: 0 6px; color: #444; }
.sub { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 16px 0 0; }
.tag { font-size: 11px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 5px; margin-left: 6px; }
.meta .bad { color: var(--down); } .meta .warn { color: var(--warn); }

/* toggle switch */
.switch { position: relative; width: 44px; height: 24px; flex: none; padding: 0; border: 0; border-radius: 999px; background: #333; transition: background .15s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch[aria-checked="true"] { background: var(--up); }
.switch[aria-checked="true"]::after { transform: translateX(20px); }
.switch[aria-checked="mixed"] { background: var(--warn); }
.switch[aria-checked="mixed"]::after { transform: translateX(10px); }
.switch:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.lock { font-size: 12px; color: var(--muted); }

.log-head { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.log table { width: 100%; border-collapse: collapse; font-size: 13px; }
.log td { padding: 6px 8px 6px 0; border-top: 1px solid var(--line); vertical-align: top; }
.log td:first-child { color: var(--muted); white-space: nowrap; }
.log-wrap { overflow-x: auto; }

dialog { background: var(--panel); color: var(--text); border: 1px solid var(--line); border-radius: 14px; max-width: 420px; width: calc(100% - 32px); }
dialog::backdrop { background: rgba(0,0,0,.7); }
.dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 16px; }

@media (max-width: 640px) {
  .row { grid-template-columns: minmax(0, 1fr) auto; }
  .row .meta { grid-column: 1; grid-row: 2; }
  .row > :last-child { grid-column: 2; grid-row: 1 / span 2; }
}

/* collapsible app cards */
.collapse { display: flex; align-items: center; gap: 0; padding: 4px 8px 4px 2px; margin: -4px 0 -4px -2px; border: 0; border-radius: 8px; background: none; text-align: left; }
.collapse:hover { background: #1a1a1a; }
.collapse:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }
.collapse h2 { font-size: 17px; }
.chev { width: 16px; height: 16px; margin-right: 8px; flex: none; position: relative; }
.chev::before { content: ""; position: absolute; left: 4px; top: 3px; width: 6px; height: 6px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); transition: transform .15s; }
.is-collapsed .chev::before { transform: translate(-1px, 3px) rotate(-45deg); }
.card.is-collapsed { padding-block: 14px; }
