:root {
  --bg: #0f1419;
  --surface: #1a2332;
  --surface-2: #243044;
  --text: #e8edf4;
  --muted: #8b9cb3;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --success: #22c55e;
  --danger: #ef4444;
  --border: #2d3a4f;
  --radius: 12px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

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

.auth-card, .panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.auth-card {
  width: 100%;
  max-width: 400px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 1.5rem;
  display: grid;
  gap: 1.5rem;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 1rem;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
}

.stat-card h3 {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  font-weight: 500;
}

.stat-card p {
  margin: 0.5rem 0 0;
  font-size: 1.75rem;
  font-weight: 700;
}

.two-col {
  display: grid;
  grid-template-columns: 1.2fr 0.8fr;
  gap: 1.5rem;
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}

.panel h2 {
  margin: 0;
  font-size: 1.1rem;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th, td {
  text-align: left;
  padding: 0.75rem 0.5rem;
  border-bottom: 1px solid var(--border);
  font-size: 0.9rem;
}

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

label {
  display: block;
  margin-bottom: 0.35rem;
  color: var(--muted);
  font-size: 0.85rem;
}

input, button, select {
  font: inherit;
}

input {
  width: 100%;
  padding: 0.65rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  margin-bottom: 0.9rem;
}

button {
  padding: 0.7rem 1rem;
  border: none;
  border-radius: 8px;
  background: var(--primary);
  color: white;
  cursor: pointer;
  font-weight: 600;
}

button:hover { background: var(--primary-hover); }
button.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
button.danger { background: var(--danger); }
button.small {
  padding: 0.35rem 0.6rem;
  font-size: 0.8rem;
}

.form-grid { max-width: 420px; }

.muted { color: var(--muted); }
.muted.small { font-size: 0.85rem; margin: 0; }
.error { color: var(--danger); }
.success { color: var(--success); }
.warning { color: #f59e0b; font-weight: 500; }
.hidden { display: none !important; }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: grid;
  place-items: center;
  z-index: 1000;
  padding: 1rem;
}

.modal.hidden {
  display: none !important;
}

.modal-content {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 560px;
}

.modal-content h2 { margin: 0 0 0.5rem; }

.modal-close {
  position: absolute;
  top: 0.75rem;
  right: 0.75rem;
  width: 2rem;
  height: 2rem;
  padding: 0;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: 1.5rem;
  line-height: 1;
  cursor: pointer;
}

.modal-close:hover {
  background: var(--surface-2);
  color: var(--text);
}

.key-display {
  display: flex;
  gap: 0.5rem;
  align-items: stretch;
  margin: 1rem 0;
}

.key-display code {
  flex: 1;
  padding: 0.75rem;
  background: var(--surface-2);
  border-radius: 8px;
  word-break: break-all;
  font-size: 0.85rem;
}

button.primary { background: var(--primary); }
button.full-width { width: 100%; margin-top: 0.5rem; }

.actions-cell {
  display: flex;
  flex-wrap: wrap;
  gap: 0.35rem;
}

.badge {
  display: inline-block;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}
.badge.ok { background: rgba(34, 197, 94, 0.15); color: var(--success); }
.badge.off { background: rgba(239, 68, 68, 0.15); color: var(--danger); }

.key-box {
  margin-top: 1rem;
  padding: 1rem;
  border-radius: 8px;
  background: var(--surface-2);
  border: 1px dashed var(--primary);
  word-break: break-all;
}

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