:root {
  --navy: #1f3864;
  --blue: #2e75b6;
  --blue-light: #bdd7ee;
  --bg: #f4f6f9;
  --card-bg: #ffffff;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --border: #e2e6ec;
  --danger: #c00000;
  --success: #1a7f37;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  background: linear-gradient(135deg, var(--navy), var(--blue));
  color: #fff;
  padding: 18px 24px;
}

.topbar-inner {
  max-width: 1000px;
  margin: 0 auto;
  display: flex;
  align-items: baseline;
  gap: 10px;
}

.brand { font-size: 22px; font-weight: 700; }
.brand-sub { font-size: 15px; opacity: 0.85; }

.brand-version {
  margin-left: auto;
  font-size: 12px;
  font-family: "SF Mono", "Courier New", monospace;
  background: rgba(255, 255, 255, 0.15);
  padding: 3px 8px;
  border-radius: 12px;
  opacity: 0.9;
}

main {
  max-width: 1000px;
  margin: 24px auto;
  padding: 0 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 20px 24px 24px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.04);
}

.card h2 {
  margin: 0 0 8px;
}

.card-hint {
  margin: 0 0 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.status-text {
  font-size: 13px;
  color: var(--text-muted);
}
.status-text.error { color: var(--danger); }
.status-text.ok { color: var(--success); }

.patterns-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.patterns-table th {
  text-align: left;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  color: var(--text-muted);
  border-bottom: 2px solid var(--border);
  padding: 8px 10px;
}

.patterns-table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  font-family: "SF Mono", "Courier New", monospace;
}

.patterns-table td.status-text {
  font-family: inherit;
  text-align: center;
}

/* A row the logged-in SpaceBox user owns. */
.patterns-table tr.row-yours {
  background: #e8f4ea;
  box-shadow: inset 4px 0 0 var(--success);
}

.yours-badge {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  font-size: 10px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  font-weight: 700;
  letter-spacing: 0.03em;
  background: var(--success);
  color: #fff;
  border-radius: 4px;
  vertical-align: middle;
}

/* Holds SpaceBox Lite's whole invite payload -- ~200 characters of JSON --
   so it takes the row's spare width rather than a fixed min-width, and
   shrinks instead of pushing the buttons onto their own line. */
#spacebox_code_input {
  font-family: "SF Mono", "Courier New", monospace;
  flex: 1 1 320px;
  min-width: 0;
}

code {
  font-family: "SF Mono", "Courier New", monospace;
  font-size: 0.92em;
  background: var(--bg);
  padding: 1px 5px;
  border-radius: 4px;
}

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

input[type="text"],
input[type="number"] {
  font: inherit;
  padding: 6px 10px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
}

button {
  font: inherit;
  padding: 8px 16px;
  border-radius: 6px;
  cursor: pointer;
}

.btn-primary {
  background: var(--blue);
  color: #fff;
  border: none;
}
.btn-primary:hover { background: var(--navy); }

.btn-secondary {
  background: #fff;
  color: var(--blue);
  border: 1px solid var(--blue);
}
.btn-secondary:hover { background: var(--blue-light); }

.btn-secondary.small,
.btn-primary.small {
  padding: 4px 10px;
  font-size: 13px;
}

/* Download buttons live inside a table cell (one per row that's "mine"),
   so they need to sit side by side without wrapping the row taller than
   the rest of the table. */
.row-download-actions {
  display: flex;
  gap: 6px;
  flex-wrap: nowrap;
}

.qr-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
/* An unconditional `display` on a class always beats the browser's own
   [hidden] rule (author styles win over UA styles regardless of
   selector specificity) -- so setting `.hidden = true` via JS did
   nothing visually, even though the DOM property really was true. This
   is what actually broke Cancel: stopQrScanner() worked correctly the
   whole time, but the overlay stayed on screen (and kept covering the
   topbar/version badge/Scan button) regardless. */
.qr-overlay[hidden] {
  display: none;
}

.qr-overlay-inner {
  background: var(--card-bg);
  border-radius: 10px;
  padding: 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  max-width: 90vw;
}

.qr-overlay video {
  width: 320px;
  max-width: 80vw;
  aspect-ratio: 1 / 1;
  object-fit: cover;
  border-radius: 8px;
  background: #000;
}
