:root {
  --bg-primary:   #0a0f1e;
  --bg-secondary: #111827;
  --bg-card:      #1a2235;
  --bg-hover:     #1e2940;
  --sidebar-w:    260px;
  --accent:       #4f6ef7;
  --accent-dark:  #3b5bdb;
  --success:      #10b981;
  --warning:      #f59e0b;
  --danger:       #ef4444;
  --text:         #e2e8f0;
  --text-muted:   #94a3b8;
  --border:       #2d3748;
  --border-light: #374151;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-primary);
  color: var(--text);
  min-height: 100vh;
  font-size: 14px;
}

/* ─── Layout ─────────────────────────────────── */
.layout { display: flex; min-height: 100vh; }

.sidebar {
  position: fixed; left: 0; top: 0; bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; z-index: 100;
}

.sidebar-brand {
  padding: 1.25rem 1.25rem 1rem;
  border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: .75rem;
}
.sidebar-brand .logo {
  width: 38px; height: 38px; background: var(--accent);
  border-radius: 10px; display: flex; align-items: center; justify-content: center;
  font-size: 1.1rem; flex-shrink: 0;
}
.brand-name { font-size: .95rem; font-weight: 700; line-height: 1.2; }
.brand-sub  { font-size: .68rem; color: var(--text-muted); }

.sidebar-nav { padding: .75rem 0; flex: 1; overflow-y: auto; }
.nav-section {
  padding: .6rem 1.25rem .3rem;
  font-size: .65rem; text-transform: uppercase;
  letter-spacing: .08em; color: var(--text-muted);
}
.nav-item a {
  display: flex; align-items: center; gap: .75rem;
  padding: .6rem 1.25rem;
  color: var(--text-muted); text-decoration: none;
  transition: all .15s; border-left: 3px solid transparent;
  font-size: .875rem;
}
.nav-item a:hover, .nav-item a.active {
  color: var(--text); background: var(--bg-card);
  border-left-color: var(--accent);
}
.nav-item a.active { color: #8ba4fa; }
.nav-item a .icon { width: 18px; text-align: center; flex-shrink: 0; }

.sidebar-footer {
  padding: .875rem 1.25rem;
  border-top: 1px solid var(--border);
  display: flex; align-items: center; gap: .75rem;
}
.sidebar-footer .user-info { flex: 1; min-width: 0; }
.sidebar-footer .username { font-size: .875rem; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-footer .user-role { font-size: .7rem; color: var(--text-muted); }
.sidebar-footer .logout-link {
  color: var(--danger); text-decoration: none; font-size: .75rem;
  padding: .25rem .5rem; border-radius: 6px; transition: background .15s; white-space: nowrap;
}
.sidebar-footer .logout-link:hover { background: rgba(239,68,68,.12); }

.main-wrapper { margin-left: var(--sidebar-w); flex: 1; display: flex; flex-direction: column; }

.topbar {
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  padding: 1rem 1.5rem;
  display: flex; align-items: center; justify-content: space-between;
  position: sticky; top: 0; z-index: 50;
}
.page-title    { font-size: 1.15rem; font-weight: 700; }
.page-subtitle { font-size: .75rem; color: var(--text-muted); margin-top: .1rem; }

.content { padding: 1.5rem; flex: 1; }

/* ─── Cards ──────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px; padding: 1.5rem; margin-bottom: 1.5rem;
}
.card-header {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 1.25rem; padding-bottom: .875rem;
  border-bottom: 1px solid var(--border);
}
.card-title    { font-size: 1rem; font-weight: 600; }
.card-subtitle { font-size: .78rem; color: var(--text-muted); margin-top: .15rem; }

/* ─── Stat cards ─────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem; margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 12px; padding: 1.25rem;
  display: flex; align-items: center; gap: 1rem;
}
.stat-icon {
  width: 46px; height: 46px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.15rem; flex-shrink: 0;
}
.stat-icon.blue   { background: rgba(79,110,247,.15); color: var(--accent); }
.stat-icon.green  { background: rgba(16,185,129,.15); color: var(--success); }
.stat-icon.yellow { background: rgba(245,158,11,.15); color: var(--warning); }
.stat-icon.red    { background: rgba(239,68,68,.15);  color: var(--danger); }
.stat-value { font-size: 1.75rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: .78rem; color: var(--text-muted); margin-top: .2rem; }

/* ─── Table ──────────────────────────────────── */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
thead th {
  text-align: left; padding: .75rem 1rem;
  font-size: .7rem; text-transform: uppercase;
  letter-spacing: .05em; color: var(--text-muted);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
tbody td {
  padding: .875rem 1rem; font-size: .875rem;
  border-bottom: 1px solid var(--border); vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--bg-hover); }

/* ─── Badges ─────────────────────────────────── */
.badge {
  display: inline-flex; align-items: center; gap: .3rem;
  padding: .28rem .75rem; border-radius: 9999px;
  font-size: .72rem; font-weight: 600;
}
.badge-active  { background: rgba(16,185,129,.15); color: var(--success); }
.badge-used    { background: rgba(79,110,247,.15);  color: var(--accent); }
.badge-revoked { background: rgba(239,68,68,.15);   color: var(--danger); }

/* ─── Buttons ────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; gap: .5rem;
  padding: .575rem 1.125rem; border-radius: 8px; border: none;
  cursor: pointer; font-size: .875rem; font-weight: 600;
  text-decoration: none; transition: all .15s; white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dark); color: #fff; }
.btn-danger  {
  background: rgba(239,68,68,.1); color: var(--danger);
  border: 1px solid rgba(239,68,68,.3);
}
.btn-danger:hover  { background: rgba(239,68,68,.2); }
.btn-secondary {
  background: var(--bg-secondary); color: var(--text-muted);
  border: 1px solid var(--border);
}
.btn-secondary:hover { color: var(--text); border-color: var(--border-light); }
.btn-sm { padding: .33rem .75rem; font-size: .8rem; }

/* ─── Forms ──────────────────────────────────── */
.form-row   { display: flex; gap: 1rem; flex-wrap: wrap; align-items: flex-end; }
.form-group { flex: 1; min-width: 180px; margin-bottom: .75rem; }
.form-label {
  display: block; margin-bottom: .4rem;
  font-size: .82rem; font-weight: 500; color: var(--text-muted);
}
.form-control {
  width: 100%; padding: .6rem .875rem;
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 8px; color: var(--text); font-size: .875rem;
  outline: none; transition: border-color .15s;
}
.form-control:focus { border-color: var(--accent); }
select.form-control option { background: var(--bg-secondary); }

/* ─── Alerts ─────────────────────────────────── */
.alert {
  padding: .75rem 1rem; border-radius: 8px;
  font-size: .875rem; margin-bottom: 1rem;
}
.alert-error   { background: rgba(239,68,68,.1);  color: var(--danger);  border: 1px solid rgba(239,68,68,.2); }
.alert-success { background: rgba(16,185,129,.1); color: var(--success); border: 1px solid rgba(16,185,129,.2); }
.alert-info    { background: rgba(79,110,247,.1); color: var(--accent);  border: 1px solid rgba(79,110,247,.2); }

/* ─── Login ──────────────────────────────────── */
.login-wrap {
  min-height: 100vh; display: flex;
  align-items: center; justify-content: center;
  background: radial-gradient(ellipse at 60% 20%, rgba(79,110,247,.12) 0%, transparent 60%), var(--bg-primary);
}
.login-card {
  background: var(--bg-card); border: 1px solid var(--border);
  border-radius: 18px; padding: 2.5rem;
  width: 100%; max-width: 400px; box-shadow: 0 25px 60px rgba(0,0,0,.5);
}
.login-logo {
  width: 58px; height: 58px; background: var(--accent); border-radius: 14px;
  display: flex; align-items: center; justify-content: center;
  font-size: 1.6rem; margin: 0 auto 1.5rem;
}
.login-title    { text-align: center; font-size: 1.35rem; font-weight: 700; margin-bottom: .2rem; }
.login-subtitle { text-align: center; font-size: .82rem; color: var(--text-muted); margin-bottom: 2rem; }

/* ─── Key display ────────────────────────────── */
.key-code {
  font-family: 'Courier New', monospace;
  font-size: .95rem; letter-spacing: .06em;
  color: #8ba4fa; background: rgba(79,110,247,.08);
  padding: .2rem .5rem; border-radius: 5px;
}

/* ─── Machine detail ─────────────────────────── */
.machine-detail {
  background: var(--bg-secondary); border: 1px solid var(--border);
  border-radius: 10px; padding: 1.25rem; margin-top: 1.5rem;
}
.machine-detail h3 { font-size: .95rem; margin-bottom: 1rem; color: var(--accent); }
.data-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: .75rem;
}
.data-item { display: flex; flex-direction: column; gap: .2rem; }
.data-item .di-label { font-size: .68rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); }
.data-item .di-value { font-size: .875rem; color: var(--text); word-break: break-all; }

.fingerprint-text {
  font-family: monospace; font-size: .75rem;
  color: var(--text-muted); word-break: break-all;
}

pre.json-view {
  background: var(--bg-primary); border: 1px solid var(--border);
  border-radius: 8px; padding: 1rem;
  font-size: .78rem; color: #7dd3fc;
  overflow-x: auto; max-height: 400px;
}

/* ─── Empty state ────────────────────────────── */
.empty-state {
  text-align: center; padding: 3rem 1rem; color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 2.5rem; margin-bottom: 1rem; opacity: .4; }
.empty-state p { font-size: .9rem; }

/* ─── Responsive ─────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { transform: translateX(-100%); }
  .main-wrapper { margin-left: 0; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}

::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: var(--bg-primary); }
::-webkit-scrollbar-thumb { background: var(--border-light); border-radius: 3px; }
