:root {
  --bg: #090d16;
  --surface: #111827;
  --surface-alt: #1a2335;
  --border: #243047;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --primary: #3b82f6;
  --primary-hover: #2563eb;
  --green: #10b981;
  --amber: #f59e0b;
  --red: #ef4444;
  --radius: 14px;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

.mono {
  font-family: "JetBrains Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

.hidden {
  display: none !important;
}

.muted {
  color: var(--muted);
  font-size: 0.875rem;
}

.text-green { color: var(--green); }
.text-blue { color: #60a5fa; }
.text-red { color: #f87171; }
.text-right { text-align: right; }

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 999;
  background: #1e293b;
  border: 1px solid #3b82f6;
  color: #f8fafc;
  padding: 12px 18px;
  border-radius: 12px;
  font-size: 0.875rem;
  font-weight: 500;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.45);
}

.login-wrapper {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: radial-gradient(circle at top, rgba(59, 130, 246, 0.14), transparent 55%);
}

.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 32px 28px;
  box-shadow: 0 24px 48px rgba(0, 0, 0, 0.45);
}

.login-card h1 {
  font-size: 1.5rem;
  margin-top: 14px;
  margin-bottom: 6px;
}

.badge-pill {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  background: rgba(59, 130, 246, 0.15);
  border: 1px solid rgba(59, 130, 246, 0.35);
  color: #93c5fd;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.04em;
}

.stack-md {
  display: flex;
  flex-direction: column;
  gap: 16px;
  margin-top: 22px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.field label {
  font-size: 0.8rem;
  font-weight: 600;
  color: #cbd5e1;
}

input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 13px;
  font-size: 0.9rem;
  outline: none;
  transition: border-color 0.15s;
}

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

.api-override {
  font-size: 0.78rem;
  color: var(--muted);
}

.api-override summary {
  cursor: pointer;
  margin-bottom: 8px;
  color: #93c5fd;
}

.api-override .hint {
  display: block;
  margin-top: 6px;
  font-size: 0.72rem;
}

.error-box {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.35);
  color: #fca5a5;
  padding: 10px 12px;
  border-radius: 10px;
  font-size: 0.84rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border: none;
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-full { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: 0.76rem; border-radius: 8px; }

.btn-primary {
  background: var(--primary);
  color: #fff;
}
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }

.btn-accent {
  background: rgba(16, 185, 129, 0.18);
  border: 1px solid rgba(16, 185, 129, 0.35);
  color: #6ee7b7;
}
.btn-accent:hover:not(:disabled) { background: rgba(16, 185, 129, 0.28); }

.btn-ghost {
  background: var(--surface-alt);
  border: 1px solid var(--border);
  color: #e2e8f0;
}
.btn-ghost:hover:not(:disabled) { background: #26324a; }

.btn-ghost-danger {
  background: rgba(239, 68, 68, 0.12);
  border: 1px solid rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}
.btn-ghost-danger:hover:not(:disabled) { background: rgba(239, 68, 68, 0.22); }

.btn-warn {
  background: rgba(245, 158, 11, 0.15);
  border: 1px solid rgba(245, 158, 11, 0.35);
  color: #fcd34d;
}
.btn-warn:hover:not(:disabled) { background: rgba(245, 158, 11, 0.25); }

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: rgba(9, 13, 22, 0.88);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  max-width: 1120px;
  margin: 0 auto;
  padding: 14px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-dot {
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 12px rgba(16, 185, 129, 0.7);
}

.brand-title {
  font-weight: 700;
  font-size: 1rem;
}

.brand-sub {
  font-size: 0.75rem;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 8px;
}

.container {
  max-width: 1120px;
  margin: 0 auto;
  padding: 24px 20px 60px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 14px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.stat-label {
  font-size: 0.78rem;
  color: var(--muted);
  font-weight: 500;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
}

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

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 18px;
}

.panel-header h2 {
  font-size: 1.05rem;
  margin-bottom: 2px;
}

.mode-switch {
  display: inline-flex;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 3px;
}

.switch-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 8px;
  cursor: pointer;
}

.switch-btn.active {
  background: var(--surface-alt);
  color: var(--text);
}

.form-row {
  display: flex;
  align-items: flex-end;
  gap: 12px;
  flex-wrap: wrap;
}

.form-row .field {
  min-width: 110px;
}

.field-grow {
  flex: 1 1 240px;
}

.field-action {
  min-width: auto !important;
}

.created-banner {
  margin-top: 16px;
  padding: 14px;
  background: rgba(16, 185, 129, 0.08);
  border: 1px solid rgba(16, 185, 129, 0.28);
  border-radius: 12px;
}

.created-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 10px;
  font-size: 0.85rem;
  font-weight: 600;
  color: #6ee7b7;
}

.created-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.code-chip {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.82rem;
  background: var(--bg);
  border: 1px solid rgba(16, 185, 129, 0.4);
  color: #d1fae5;
  padding: 5px 10px;
  border-radius: 8px;
  cursor: pointer;
}

.toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  margin-bottom: 16px;
}

.search-box {
  flex: 1 1 260px;
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.pill {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 13px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.pill.active {
  background: rgba(59, 130, 246, 0.16);
  border-color: var(--primary);
  color: #93c5fd;
}

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

.keys-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}

.keys-table th {
  text-align: left;
  font-size: 0.74rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  padding: 10px 12px;
  border-bottom: 1px solid var(--border);
}

.keys-table td {
  padding: 13px 12px;
  border-bottom: 1px solid #1b2436;
  vertical-align: middle;
}

.keys-table tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.code-cell {
  display: flex;
  align-items: center;
  gap: 8px;
}

.code-badge {
  font-family: "JetBrains Mono", monospace;
  font-weight: 600;
  font-size: 0.88rem;
  color: #f8fafc;
}

.status-badge {
  display: inline-block;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.73rem;
  font-weight: 600;
}

.status-available {
  background: rgba(16, 185, 129, 0.15);
  color: #6ee7b7;
  border: 1px solid rgba(16, 185, 129, 0.35);
}

.status-used {
  background: rgba(59, 130, 246, 0.15);
  color: #93c5fd;
  border: 1px solid rgba(59, 130, 246, 0.35);
}

.status-disabled {
  background: rgba(239, 68, 68, 0.14);
  color: #fca5a5;
  border: 1px solid rgba(239, 68, 68, 0.35);
}

.device-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.device-model {
  font-weight: 600;
  font-size: 0.83rem;
  color: #e2e8f0;
}

.device-id-sub {
  font-family: "JetBrains Mono", monospace;
  font-size: 0.72rem;
  color: var(--muted);
}

.actions-group {
  display: inline-flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 6px;
}

.empty-state {
  text-align: center;
  padding: 36px 16px;
  color: var(--muted);
  font-size: 0.9rem;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 90;
  background: rgba(0, 0, 0, 0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 6px;
}

@media (max-width: 820px) {
  .stats-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .keys-table thead {
    display: none;
  }

  .keys-table, .keys-table tbody, .keys-table tr, .keys-table td {
    display: block;
    width: 100%;
  }

  .keys-table tr {
    background: var(--surface-alt);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 12px;
    margin-bottom: 12px;
  }

  .keys-table td {
    padding: 6px 0;
    border-bottom: none;
    text-align: left !important;
  }

  .actions-group {
    justify-content: flex-start;
    margin-top: 6px;
  }
}