@import url('https://fonts.googleapis.com/css2?family=Space+Grotesk:wght@500;600;700&family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  --bg: #0B0D26;
  --surface: #161936;
  --surface-raised: #1D2145;
  --surface-hover: #232752;
  --border: #2C3061;
  --border-soft: #21254A;

  --accent: #4DD9E8;
  --accent-dim: #2C8A96;
  --accent-soft: rgba(77, 217, 232, 0.12);
  --accent-ink: #06222A;

  --success: #34D399;
  --success-soft: rgba(52, 211, 153, 0.12);
  --warning: #FBBF24;
  --warning-soft: rgba(251, 191, 36, 0.12);
  --danger: #F87171;
  --danger-soft: rgba(248, 113, 113, 0.12);
  --neutral: #8B90B8;
  --neutral-soft: rgba(139, 144, 184, 0.12);

  --text: #EDEFFB;
  --text-muted: #9498C0;
  --text-faint: #6A6F9E;

  --radius-sm: 7px;
  --radius: 9px;
  --radius-lg: 14px;

  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 6px 20px rgba(2, 3, 16, 0.35);
  --shadow-lg: 0 24px 60px rgba(2, 3, 16, 0.5);

  --ease: cubic-bezier(0.4, 0, 0.2, 1);

  --font-display: 'Space Grotesk', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-body);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

button {
  font-family: inherit;
  cursor: pointer;
}

input, select, textarea {
  font-family: inherit;
  font-size: 14px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

::selection { background: var(--accent); color: var(--accent-ink); }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 100px; }
::-webkit-scrollbar-thumb:hover { background: var(--accent-dim); }

:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
  border-radius: var(--radius-sm);
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ============================================================
   Login page
   ============================================================ */

.login-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background:
    radial-gradient(ellipse 900px 500px at 20% -10%, rgba(77,217,232,0.12), transparent),
    radial-gradient(ellipse 700px 500px at 100% 100%, rgba(77,217,232,0.07), transparent),
    var(--bg);
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-lg);
  padding: 32px 28px;
  box-shadow: var(--shadow-lg);
}

.login-mark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.login-mark svg { flex-shrink: 0; }

.login-mark .name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 19px;
  letter-spacing: -0.01em;
}

.login-mark .name span { color: var(--accent); }

.login-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 22px;
  margin: 0 0 6px;
  letter-spacing: -0.01em;
}

.login-sub {
  color: var(--text-muted);
  margin: 0 0 26px;
  font-size: 13.5px;
}

.field { margin-bottom: 16px; }

.field label {
  display: block;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.field input,
.field select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  outline: none;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.field input:hover { border-color: var(--text-faint); }

.field input:focus,
.field select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.field input::placeholder { color: var(--text-faint); }
.field input:disabled { color: var(--text-faint); cursor: not-allowed; opacity: 0.7; }

.btn-primary {
  width: 100%;
  background: var(--accent);
  color: var(--accent-ink);
  border: none;
  border-radius: var(--radius-sm);
  padding: 11px 16px;
  font-weight: 600;
  font-size: 14.5px;
  margin-top: 6px;
  transition: filter 0.15s var(--ease), transform 0.1s var(--ease);
}

.btn-primary:hover { filter: brightness(1.08); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: 0.55; cursor: not-allowed; filter: none; }

.login-error {
  background: var(--danger-soft);
  border: 1px solid rgba(248,113,113,0.35);
  color: var(--danger);
  padding: 9px 12px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  margin-bottom: 16px;
  display: none;
}

.login-error.show { display: block; }

/* ============================================================
   Dashboard layout
   ============================================================ */

.app-shell {
  display: grid;
  grid-template-columns: 220px 1fr;
  min-height: 100vh;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border-soft);
  padding: 20px 16px;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-mark {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 4px 8px 24px;
}

.sidebar-mark .name {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 15.5px;
}

.sidebar-mark .name span { color: var(--accent); }

.nav-group { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: none;
  background: none;
  text-align: left;
  width: 100%;
  position: relative;
  transition: background-color 0.15s var(--ease), color 0.15s var(--ease);
}

.nav-item:hover { background: var(--surface-raised); color: var(--text); }

.nav-item.active {
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 600;
}

.nav-item.active::before {
  content: "";
  position: absolute;
  left: -16px;
  top: 50%;
  transform: translateY(-50%);
  width: 3px;
  height: 18px;
  background: var(--accent);
  border-radius: 0 3px 3px 0;
}

.sidebar-footer {
  margin-top: auto;
  padding-top: 16px;
  border-top: 1px solid var(--border-soft);
}

.admin-chip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 12.5px;
  color: var(--text-muted);
  padding: 4px 10px;
  gap: 8px;
}

.admin-chip > span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.logout-link {
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 12.5px;
  text-decoration: underline;
  padding: 0;
  flex-shrink: 0;
  transition: color 0.15s var(--ease);
}
.logout-link:hover { color: var(--danger); }

.main {
  padding: 28px 32px 60px;
  max-width: 1180px;
  min-width: 0;
}

.page-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 24px;
  flex-wrap: wrap;
  gap: 10px;
}

.page-title {
  font-family: var(--font-display);
  font-weight: 600;
  font-size: 21px;
  margin: 0;
  letter-spacing: -0.01em;
}

.page-sub {
  color: var(--text-muted);
  font-size: 13px;
  margin: 4px 0 0;
}

/* ============================================================
   Stat strip
   ============================================================ */

.stat-strip {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 26px;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

.stat-cell {
  padding: 16px 18px;
  border-right: 1px solid var(--border-soft);
  transition: background-color 0.15s var(--ease);
}

.stat-cell:hover { background: var(--surface-raised); }
.stat-cell:last-child { border-right: none; }

.stat-num {
  font-family: var(--font-display);
  font-size: 25px;
  font-weight: 700;
  line-height: 1.1;
  font-variant-numeric: tabular-nums;
}

.stat-label {
  font-size: 11.5px;
  color: var(--text-muted);
  margin-top: 5px;
}

.stat-cell.accent { background: linear-gradient(180deg, var(--accent-soft), transparent); }
.stat-cell.accent .stat-num { color: var(--accent); }
.stat-cell.warn .stat-num { color: var(--warning); }

/* ============================================================
   Toolbar
   ============================================================ */

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.toolbar input[type="text"],
.toolbar select {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  outline: none;
  transition: border-color 0.15s var(--ease), box-shadow 0.15s var(--ease);
}

.toolbar input[type="text"] { flex: 1; min-width: 180px; }

.toolbar input::placeholder { color: var(--text-faint); }

.toolbar input[type="text"]:focus,
.toolbar select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
  background: var(--surface-raised);
  color: var(--text);
  padding: 8px 14px;
  font-size: 13.5px;
  font-weight: 500;
  white-space: nowrap;
  transition: border-color 0.15s var(--ease), background-color 0.15s var(--ease), transform 0.1s var(--ease);
}

.btn:hover { border-color: var(--accent-dim); background: var(--surface-hover); }
.btn:active { transform: translateY(1px); }

.btn.cyan {
  background: var(--accent);
  color: var(--accent-ink);
  border-color: var(--accent);
  font-weight: 600;
}
.btn.cyan:hover { filter: brightness(1.08); background: var(--accent); }

.btn.danger-outline { color: var(--danger); border-color: rgba(248,113,113,0.4); background: none; }
.btn.danger-outline:hover { background: var(--danger-soft); border-color: var(--danger); }

.btn.small { padding: 5px 10px; font-size: 12.5px; }

/* ============================================================
   Table
   ============================================================ */

.table-wrap {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--surface);
  box-shadow: var(--shadow-sm);
}

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

thead th {
  text-align: left;
  font-size: 11.5px;
  font-weight: 600;
  letter-spacing: 0.01em;
  color: var(--text-muted);
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft);
  background: var(--surface-raised);
  white-space: nowrap;
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr { transition: background-color 0.1s var(--ease); }
tbody tr:hover td { background: rgba(77, 217, 232, 0.03); }

.key-mono {
  font-family: var(--font-mono);
  font-size: 12.5px;
  letter-spacing: 0.01em;
  color: var(--accent);
}

.device-mono {
  font-family: var(--font-mono);
  font-size: 11.5px;
  color: var(--text-muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 100px;
  font-size: 11px;
  font-weight: 600;
}

.badge::before {
  content: "";
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  flex-shrink: 0;
}

.badge.unused { background: var(--neutral-soft); color: var(--neutral); }
.badge.active { background: var(--success-soft); color: var(--success); }
.badge.expired { background: var(--warning-soft); color: var(--warning); }
.badge.revoked { background: var(--danger-soft); color: var(--danger); }

.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.empty-state {
  padding: 48px 20px;
  text-align: center;
  color: var(--text-muted);
  font-size: 13px;
}

.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 14px;
  color: var(--text-muted);
  font-size: 12.5px;
  flex-wrap: wrap;
  gap: 10px;
}

.pagination .btns { display: flex; gap: 8px; }

/* ============================================================
   Modal
   ============================================================ */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 18, 0.65);
  backdrop-filter: blur(3px);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 50;
  padding: 20px;
}

.modal-overlay.show { display: flex; }

.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 420px;
  max-height: 88vh;
  overflow-y: auto;
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

.modal h3 {
  font-family: var(--font-display);
  font-size: 17px;
  margin: 0 0 4px;
}

.modal .modal-sub {
  color: var(--text-muted);
  font-size: 12.5px;
  margin: 0 0 18px;
}

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

.field-row { display: flex; gap: 10px; }
.field-row .field { flex: 1; }

.result-box {
  background: var(--bg);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent);
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  margin-top: 12px;
  display: none;
}

.result-box.show { display: block; }

/* ============================================================
   Toast
   ============================================================ */

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  background: var(--surface-raised);
  border: 1px solid var(--border);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  font-size: 13px;
  z-index: 100;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s var(--ease), transform 0.2s var(--ease);
  max-width: 320px;
  box-shadow: var(--shadow-md);
}

.toast.show { opacity: 1; transform: translateY(0); }
.toast.error { border-left-color: var(--danger); }

/* ============================================================
   Responsive — tablet
   ============================================================ */

@media (max-width: 1000px) {
  .stat-strip { grid-template-columns: repeat(3, 1fr); }
  .stat-cell:nth-child(3) { border-right: none; }
  .stat-cell:nth-child(n+4) { border-top: 1px solid var(--border-soft); }
}

/* ============================================================
   Responsive — mobile
   Sidebar becomes a horizontal top bar so nav stays reachable
   (no JS changes required).
   ============================================================ */

@media (max-width: 820px) {
  .app-shell { grid-template-columns: 1fr; }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 40;
    height: auto;
    flex-direction: row;
    align-items: center;
    flex-wrap: nowrap;
    gap: 14px;
    padding: 12px 16px;
    border-right: none;
    border-bottom: 1px solid var(--border-soft);
  }

  .sidebar-mark { padding: 0; flex-shrink: 0; }

  .nav-group {
    flex-direction: row;
    flex: 1;
    min-width: 0;
    overflow-x: auto;
    gap: 4px;
    scrollbar-width: none;
    -ms-overflow-style: none;
  }

  .nav-group::-webkit-scrollbar { display: none; }

  .nav-item {
    white-space: nowrap;
    width: auto;
    padding: 7px 12px;
  }

  .nav-item.active::before { display: none; }

  .sidebar-footer {
    margin-top: 0;
    padding-top: 0;
    border-top: none;
    flex-shrink: 0;
  }

  .admin-chip { padding: 0; }
  .admin-chip > span { display: none; }

  .main { padding: 20px 16px 48px; }

  .page-header { flex-direction: column; align-items: stretch; }
  .page-title { font-size: 19px; }

  .stat-strip {
    grid-template-columns: repeat(2, 1fr);
    border-radius: var(--radius);
  }

  .stat-cell { border-right: 1px solid var(--border-soft); }
  .stat-cell:nth-child(2n) { border-right: none; }
  .stat-cell:nth-child(n+3) { border-top: 1px solid var(--border-soft); }

  .stat-num { font-size: 20px; }

  .toolbar { flex-direction: column; align-items: stretch; }
  .toolbar select { width: 100%; }

  .table-wrap {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
  }

  table { min-width: 680px; }

  .pagination { justify-content: center; text-align: center; }

  .modal-overlay { padding: 0; align-items: flex-end; }

  .modal {
    max-width: 100%;
    width: 100%;
    max-height: 92vh;
    border-radius: var(--radius-lg) var(--radius-lg) 0 0;
    border-bottom: none;
    animation: sheet-up 0.22s var(--ease);
  }

  @keyframes sheet-up {
    from { transform: translateY(20px); opacity: 0; }
    to { transform: translateY(0); opacity: 1; }
  }

  .field-row { flex-direction: column; gap: 0; }

  .modal-actions { flex-direction: column-reverse; }
  .modal-actions .btn { width: 100%; text-align: center; }

  .toast {
    left: 16px;
    right: 16px;
    bottom: 16px;
    max-width: none;
  }
}

@media (max-width: 420px) {
  .stat-strip { grid-template-columns: repeat(2, 1fr); }
  .login-card { padding: 26px 20px; }
}