@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap');

/* ============================================================
   DESIGN TOKENS
   ============================================================ */
:root {
  --primary:        #2563EB;
  --primary-dark:   #1D4ED8;
  --primary-subtle: #EFF6FF;
  --danger:         #EF4444;
  --danger-subtle:  #FEF2F2;
  --success:        #22C55E;
  --success-subtle: #F0FDF4;
  --warning:        #F59E0B;
  --warning-subtle: #FFFBEB;

  --n-50:  #F9FAFB;
  --n-100: #F3F4F6;
  --n-200: #E5E7EB;
  --n-300: #D1D5DB;
  --n-400: #9CA3AF;
  --n-500: #6B7280;
  --n-600: #4B5563;
  --n-700: #374151;
  --n-900: #111827;

  --bg:      var(--n-50);
  --card-bg: #FFFFFF;
  --text:    var(--n-900);
  --muted:   var(--n-500);
  --border:  var(--n-200);

  --r-sm: 6px;
  --r:    8px;
  --r-lg: 12px;

  --shadow-xs: 0 1px 2px rgba(0,0,0,.05);
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
  --shadow-lg: 0 20px 48px rgba(0,0,0,.14), 0 8px 16px rgba(0,0,0,.06);
}

/* ============================================================
   RESET
   ============================================================ */
*, *::before, *::after { box-sizing: border-box; }
body, h1, h2, h3, h4, p { margin: 0; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  font-size: 14px;
  line-height: 1.6;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--primary); text-decoration: none; }

/* ============================================================
   AUTH — LOGIN PAGE
   ============================================================ */
.auth-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: #0F172A;
  padding: 24px;
}

.auth-wrapper { width: 100%; max-width: 360px; }

.auth-card {
  background: var(--card-bg);
  border-radius: var(--r-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-lg);
}

.auth-logo {
  width: 42px;
  height: 42px;
  background: var(--primary);
  border-radius: var(--r);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 20px;
}

.auth-logo svg {
  width: 20px; height: 20px;
  stroke: #fff; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

.auth-card h1 {
  font-size: 20px;
  font-weight: 700;
  letter-spacing: -.3px;
  margin-bottom: 4px;
}

.auth-subtitle {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 28px;
}

/* ============================================================
   FORMS
   ============================================================ */
.form-group { margin-bottom: 16px; }

.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--n-600);
  letter-spacing: .02em;
  margin-bottom: 6px;
}

.form-group input,
.form-group select {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 13px;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text);
  transition: border-color .15s, box-shadow .15s;
  outline: none;
  appearance: none;
}

.form-group select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236B7280' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 32px;
}

.form-group input::placeholder { color: var(--n-400); }

.form-group input:focus,
.form-group select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,.12);
}

.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: inherit;
  cursor: pointer;
  line-height: 1;
  white-space: nowrap;
  transition: background .12s, border-color .12s, box-shadow .12s;
  text-decoration: none;
}

.btn:hover { text-decoration: none; }
.btn:active { transform: translateY(1px); }

.btn-primary {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary-dark);
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-danger  { background: var(--danger);  color: #fff; border-color: #DC2626; }
.btn-danger:hover  { background: #DC2626; }

.btn-warning { background: var(--warning); color: #fff; border-color: #D97706; }
.btn-warning:hover { background: #D97706; }

.btn-secondary {
  background: var(--card-bg);
  color: var(--n-700);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--n-50); border-color: var(--n-300); }

.btn-sm   { padding: 5px 10px; font-size: 12px; }
.btn-block { width: 100%; justify-content: center; padding: 10px 16px; font-size: 14px; }

/* ============================================================
   ALERTS
   ============================================================ */
.alert {
  padding: 11px 14px;
  border-radius: var(--r-sm);
  font-size: 13px;
  font-weight: 500;
  margin-bottom: 20px;
  border: 1px solid;
}

.alert-error   { background: var(--danger-subtle);  color: #B91C1C; border-color: #FECACA; }
.alert-success { background: var(--success-subtle); color: #15803D; border-color: #BBF7D0; }

/* ============================================================
   APP SHELL
   ============================================================ */
.app-shell { display: flex; min-height: 100vh; }

/* ============================================================
   SIDEBAR
   ============================================================ */
.sidebar {
  width: 220px;
  background: #0F172A;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

/* Brand */
.sidebar .brand {
  padding: 18px 16px 14px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}

.brand-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 4px;
}

.brand-icon {
  width: 30px; height: 30px;
  background: var(--primary);
  border-radius: 7px;
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}

.brand-icon svg {
  width: 15px; height: 15px;
  stroke: #fff; fill: none;
  stroke-width: 2.5; stroke-linecap: round; stroke-linejoin: round;
}

.brand-title {
  font-size: 13px;
  font-weight: 700;
  color: #F1F5F9;
  letter-spacing: -.1px;
}

.brand-sub {
  font-size: 11px;
  color: #475569;
  padding-left: 40px;
  margin-top: 1px;
}

/* Nav */
.sidebar nav {
  padding: 10px 8px;
  flex: 1;
  overflow-y: auto;
}

.sidebar nav a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 6px;
  color: #94A3B8;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background .1s, color .1s;
  margin-bottom: 1px;
}

.sidebar nav a svg {
  width: 15px; height: 15px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
  opacity: .8;
}

.sidebar nav a:hover { background: rgba(255,255,255,.06); color: #E2E8F0; }
.sidebar nav a:hover svg { opacity: 1; }

.sidebar nav a.active { background: rgba(37,99,235,.2); color: #93C5FD; }
.sidebar nav a.active svg { opacity: 1; }

/* Sidebar Footer (logout) */
.sidebar-footer {
  padding: 10px 8px 16px;
  border-top: 1px solid rgba(255,255,255,.05);
}

.sidebar-footer a {
  display: flex;
  align-items: center;
  gap: 9px;
  padding: 7px 10px;
  border-radius: 6px;
  color: #475569;
  font-size: 13px;
  font-weight: 500;
  text-decoration: none;
  transition: background .1s, color .1s;
}

.sidebar-footer a svg {
  width: 15px; height: 15px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
  flex-shrink: 0;
}

.sidebar-footer a:hover { background: rgba(255,255,255,.05); color: #94A3B8; }

/* ============================================================
   MAIN CONTENT
   ============================================================ */
.main { flex: 1; display: flex; flex-direction: column; min-width: 0; overflow: auto; }

/* Topbar */
.topbar {
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  padding: 0 28px;
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.topbar h1 {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  letter-spacing: -.1px;
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 7px;
  font-size: 12px;
  font-weight: 500;
  color: var(--n-600);
  background: var(--n-100);
  border: 1px solid var(--border);
  padding: 5px 11px;
  border-radius: 999px;
}

.user-chip svg {
  width: 13px; height: 13px;
  stroke: currentColor; fill: none;
  stroke-width: 2; stroke-linecap: round; stroke-linejoin: round;
}

/* Content */
.content { padding: 24px 28px; flex: 1; }

/* ============================================================
   STAT CARDS
   ============================================================ */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(175px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  padding: 16px 18px;
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0; bottom: 0;
  width: 3px;
}

.stat-card.c-primary::before { background: var(--primary); }
.stat-card.c-success::before { background: var(--success); }
.stat-card.c-danger::before  { background: var(--danger); }
.stat-card.c-warning::before { background: var(--warning); }

.stat-label {
  font-size: 11px;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .06em;
  margin-bottom: 8px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
  letter-spacing: -.5px;
  line-height: 1;
}

.stat-card.c-primary .stat-value { color: var(--primary); }
.stat-card.c-success .stat-value { color: #16A34A; }
.stat-card.c-danger  .stat-value { color: var(--danger); }
.stat-card.c-warning .stat-value { color: var(--warning); }

/* ============================================================
   PANEL / CARD
   ============================================================ */
.panel {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--r);
  overflow: hidden;
}

.panel + .panel { margin-top: 20px; }

.panel-header {
  padding: 12px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--n-50);
}

.panel-header h2 {
  font-size: 12px;
  font-weight: 600;
  color: var(--n-600);
  text-transform: uppercase;
  letter-spacing: .05em;
}

.panel-body { padding: 20px; }

/* ============================================================
   TABLE
   ============================================================ */
table { width: 100%; border-collapse: collapse; font-size: 13px; }

th {
  padding: 9px 16px;
  text-align: left;
  background: var(--n-50);
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 600;
  color: var(--n-500);
  text-transform: uppercase;
  letter-spacing: .06em;
  white-space: nowrap;
}

td {
  padding: 10px 16px;
  border-bottom: 1px solid var(--n-100);
  vertical-align: middle;
  color: var(--n-700);
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: var(--n-50); }

/* ============================================================
   BADGES
   ============================================================ */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 7px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: .03em;
  text-transform: uppercase;
}

.badge-success { background: #DCFCE7; color: #15803D; }
.badge-danger  { background: #FEE2E2; color: #B91C1C; }
.badge-muted   { background: var(--n-100); color: var(--n-500); }

/* ============================================================
   KEY CODE & DEVICE INFO
   ============================================================ */
.key-code {
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
  font-size: 12px;
  font-weight: 600;
  color: var(--n-900);
  letter-spacing: .03em;
}

.device-info { font-size: 12px; color: var(--n-700); }

.device-id-only {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  font-size: 11px;
  color: var(--n-400);
}

/* ============================================================
   SEARCH BOX & ACTIONS
   ============================================================ */
.search-box { display: flex; gap: 8px; margin-bottom: 16px; }

.search-box input {
  flex: 1;
  max-width: 300px;
  padding: 8px 12px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  font-size: 13px;
  font-family: inherit;
  background: var(--card-bg);
  color: var(--text);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.search-box input::placeholder { color: var(--n-400); }
.search-box input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(37,99,235,.1); }

.actions { display: flex; gap: 6px; flex-wrap: wrap; }

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--muted);
  font-size: 13px;
}

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(3px);
  -webkit-backdrop-filter: blur(3px);
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  width: 100%;
  max-width: 420px;
  padding: 24px;
  box-shadow: var(--shadow-lg);
}

.modal h3 {
  font-size: 15px;
  font-weight: 700;
  letter-spacing: -.2px;
  margin-bottom: 8px;
}

.modal p {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.65;
  margin-bottom: 6px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ============================================================
   CODE / PRE
   ============================================================ */
code.inline {
  font-family: 'SF Mono', 'Fira Code', 'Consolas', monospace;
  background: var(--n-100);
  border: 1px solid var(--border);
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12px;
  color: var(--n-700);
}

pre {
  border-radius: var(--r) !important;
  font-size: 12px !important;
  line-height: 1.65 !important;
}

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .content { padding: 16px; }
  .form-row { flex-direction: column; gap: 0; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .topbar { padding: 0 16px; }
}
