*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
[hidden] { display: none !important; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --border: #2a2d3a;
  --text: #e2e8f0;
  --muted: #8892a4;
  --green: #22c55e;
  --yellow: #f59e0b;
  --red: #ef4444;
  --blue: #3b82f6;
  --radius: 8px;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  font-size: 14px;
  min-height: 100vh;
}

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

header h1 { font-size: 18px; font-weight: 600; }

#header-actions { display: flex; align-items: center; gap: 12px; }

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

/* Login */
#login-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: calc(100vh - 60px);
}

.login-card {
  width: 100%;
  max-width: 360px;
}

.login-card h2 { margin-bottom: 20px; text-align: center; }

.login-card form { display: flex; flex-direction: column; gap: 12px; }

/* Card */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
}

/* Sections */
section { margin-bottom: 36px; }

section h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 16px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Table */
table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

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

th { font-weight: 500; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: 0.05em; }

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

tr:hover td { background: rgba(255,255,255,0.02); }

/* Inputs */
input[type=text], input[type=password] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 12px;
  width: 100%;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}

input:focus { border-color: var(--blue); }

/* Buttons */
.btn {
  padding: 8px 16px;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 13px;
  font-weight: 500;
  transition: opacity 0.15s;
}

.btn:hover { opacity: 0.85; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn-primary { background: var(--blue); color: #fff; }
.btn-success { background: var(--green); color: #fff; }
.btn-danger  { background: var(--red);  color: #fff; }
.btn-sm { padding: 5px 12px; font-size: 12px; }
.btn-terminal { background: #1e3a5f; color: #60a5fa; border: 1px solid #2563eb; }

/* Status indicators */
.indicator {
  width: 8px; height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.online  { background: var(--green); box-shadow: 0 0 6px var(--green); }
.offline { background: var(--muted); }
.pending-dot { background: var(--yellow); box-shadow: 0 0 6px var(--yellow); }

/* Status cell */
.status-cell { display: flex; align-items: center; gap: 6px; }

/* Port chip */
.port-chip {
  font-family: monospace;
  background: rgba(59,130,246,0.15);
  color: var(--blue);
  padding: 2px 8px;
  border-radius: 4px;
  cursor: pointer;
  user-select: none;
  font-size: 13px;
}

.port-chip:hover { background: rgba(59,130,246,0.3); }

/* Badge */
.badge {
  background: var(--yellow);
  color: #000;
  border-radius: 12px;
  padding: 1px 8px;
  font-size: 12px;
  font-weight: 700;
  min-width: 20px;
  text-align: center;
  display: none;
}

.badge.visible { display: inline-block; }

/* Empty state */
.empty-state {
  color: var(--muted);
  padding: 24px;
  text-align: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

/* Error */
.error { color: var(--red); font-size: 13px; text-align: center; }

/* Actions cell */
.actions { display: flex; gap: 6px; }

/* Relative time */
.rel-time { color: var(--muted); }

/* Groups */
tr.group-header td {
  background: rgba(255,255,255,0.03);
  padding: 7px 14px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  user-select: none;
  border-bottom: 1px solid var(--border);
}
tr.group-header:hover td { background: rgba(255,255,255,0.06); }
.group-chevron { margin-right: 6px; font-size: 11px; display: inline-block; width: 10px; }
.group-label { margin-right: 8px; }
.group-meta { color: var(--muted); font-weight: 400; font-size: 11px; }
.group-tag {
  background: rgba(168,85,247,0.15);
  color: #c084fc;
  border: 1px solid rgba(168,85,247,0.3);
  padding: 2px 8px;
  border-radius: 12px;
  font-size: 12px;
  cursor: pointer;
  white-space: nowrap;
}
.group-tag:hover { background: rgba(168,85,247,0.28); }
.group-add { color: var(--muted); font-size: 12px; cursor: pointer; }
.group-add:hover { color: var(--text); }
.group-input {
  background: var(--bg);
  border: 1px solid var(--blue);
  border-radius: 6px;
  color: var(--text);
  padding: 3px 8px;
  font-size: 12px;
  width: 120px;
  outline: none;
}

/* Serial */
.serial {
  font-family: monospace;
  font-size: 12px;
  color: var(--muted);
  letter-spacing: 0.05em;
}

/* Download card */
.download-card p { color: var(--muted); margin-bottom: 12px; font-size: 13px; }
.code-row {
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
}
.code-row code {
  flex: 1;
  font-family: monospace;
  font-size: 13px;
  word-break: break-all;
  color: var(--green);
}

/* ── Mobile ─────────────────────────────────────── */
@media (max-width: 768px) {
  main { padding: 12px; }
  header h1 { font-size: 15px; }

  /* Prevent any table from overflowing the viewport */
  table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  th, td { padding: 8px 10px; white-space: nowrap; }
  .btn-sm { padding: 4px 8px; font-size: 11px; }

  /* Devices table — hide Serial (3), Port (4), Registered (7) */
  #devices-table th:nth-child(3),
  #devices-table td:nth-child(3),
  #devices-table th:nth-child(4),
  #devices-table td:nth-child(4),
  #devices-table th:nth-child(7),
  #devices-table td:nth-child(7) { display: none; }

  /* Pending table — hide Serial (2), Registered (3) */
  #pending-table th:nth-child(2),
  #pending-table td:nth-child(2),
  #pending-table th:nth-child(3),
  #pending-table td:nth-child(3) { display: none; }
}
