:root {
  color-scheme: light dark;
  --bg: #0f1420;
  --panel: #161d2e;
  --border: #2a3348;
  --text: #e6e9f0;
  --muted: #8b93a7;
  --accent: #4c8dff;
  font-family: -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
}

header h1 {
  font-size: 16px;
  margin: 0;
}

header nav a {
  color: var(--muted);
  text-decoration: none;
  margin-left: 16px;
  font-size: 13px;
}

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

main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 24px;
}

.toolbar {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

input, select, button, textarea {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 6px;
  padding: 8px 10px;
  font-size: 13px;
}

button {
  cursor: pointer;
  background: var(--accent);
  border: none;
  color: #08101f;
  font-weight: 600;
}

button.secondary {
  background: var(--panel);
  border: 1px solid var(--border);
  color: var(--text);
}

button.danger {
  background: #3a1420;
  border: 1px solid #7a2a3a;
  color: #ff9fb2;
}

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

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

th { color: var(--muted); font-weight: 600; }

tr:last-child td { border-bottom: none; }

tr.clickable { cursor: pointer; }
tr.clickable:hover { background: #1c2438; }

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
}

.badge-HEALTHY { background: #10331e; color: #6fe39a; }
.badge-UPDATE_REQUIRED { background: #3a2c10; color: #ffc266; }
.badge-OFFLINE { background: #2a2f3d; color: #9aa3b8; }
.badge-ERROR { background: #3a1420; color: #ff8fa3; }
.badge-PENDING { background: #16263a; color: #7fb4ff; }
.badge-REVOKED { background: #1c1c1c; color: #b0b0b0; }

.badge-QUEUED { background: #16263a; color: #7fb4ff; }
.badge-DELIVERED { background: #1c2a3a; color: #7fd4ff; }
.badge-RUNNING { background: #3a2c10; color: #ffc266; }
.badge-SUCCEEDED { background: #10331e; color: #6fe39a; }
.badge-FAILED { background: #3a1420; color: #ff8fa3; }
.badge-EXPIRED { background: #2a2f3d; color: #9aa3b8; }
.badge-CANCELLED { background: #1c1c1c; color: #b0b0b0; }

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  margin-bottom: 20px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px 24px;
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}

.modal {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 20px;
  width: 340px;
  max-width: calc(100vw - 32px);
}

.modal input {
  width: 100%;
}

.field label {
  display: block;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  margin-bottom: 4px;
}

.field .value { font-size: 14px; }

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

.code-box {
  background: #060a12;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 12px;
  font-family: "SF Mono", Consolas, monospace;
  font-size: 13px;
  word-break: break-all;
}

form .field { margin-bottom: 12px; }
form input, form textarea { width: 100%; }

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

/* --- Wi-Fi setup: QR panel on the dashboard and the device setup page --- */
.setup-panel {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

.setup-panel h3 { margin: 0 0 8px; font-size: 14px; }

.setup-qr {
  display: block;
  /* QR codes need dark-on-light with a quiet zone regardless of theme. */
  background: #ffffff;
  image-rendering: pixelated;
  max-width: 100%;
  height: auto;
  margin: 12px 0;
}

.setup-link-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.setup-link-row input { flex: 1 1 320px; min-width: 0; font-family: Consolas, monospace; font-size: 12px; }

.setup-warning { color: #f0b54a; }

.setup-error { border-color: #7a2a38; }

.small { font-size: 12px; }

.button-link {
  display: inline-block;
  background: var(--accent);
  color: #08101f;
  font-weight: 600;
  text-decoration: none;
  border-radius: 6px;
  padding: 12px 16px;
  font-size: 15px;
}

.setup-page main { max-width: 640px; padding: 16px; }
.setup-page .value { overflow-wrap: anywhere; }
.setup-page code { overflow-wrap: anywhere; }
.setup-panel a, .setup-page a:not(.button-link) { color: var(--accent); }
