/* =========================================================
   KeyVault Admin Dashboard – Dark Mode
   ========================================================= */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@300;400;500;600;700&family=JetBrains+Mono:wght@400;500&display=swap');

/* ── CSS Variables ──────────────────────────────────────── */
:root {
  --bg-base:      #0a0c12;
  --bg-surface:   #111320;
  --bg-elevated:  #181b2e;
  --bg-card:      #1e2235;
  --bg-hover:     #242843;
  --border:       rgba(255,255,255,0.07);
  --border-focus: rgba(124,106,247,0.6);

  --primary:      #7c6af7;
  --primary-soft: rgba(124,106,247,0.15);
  --primary-glow: rgba(124,106,247,0.3);
  --secondary:    #06b6d4;
  --success:      #10b981;
  --warning:      #f59e0b;
  --danger:       #ef4444;
  --danger-soft:  rgba(239,68,68,0.15);

  --text-primary:   #e8eaed;
  --text-secondary: #8b92a5;
  --text-muted:     #4b5563;
  --text-link:      #a78bfa;

  --font:      'Inter', sans-serif;
  --font-mono: 'JetBrains Mono', monospace;

  --radius-sm: 6px;
  --radius:    10px;
  --radius-lg: 16px;
  --radius-xl: 24px;

  --shadow: 0 4px 24px rgba(0,0,0,0.4);
  --shadow-glow: 0 0 32px rgba(124,106,247,0.15);
  --transition: all 0.2s cubic-bezier(0.4,0,0.2,1);
}

/* ── Reset & Base ───────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; scroll-behavior: smooth; }

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--text-link); text-decoration: none; }
a:hover { color: #c4b5fd; }
button { cursor: pointer; border: none; outline: none; font-family: var(--font); }
input, select, textarea { font-family: var(--font); }

/* ── Scrollbar ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: var(--bg-base); }
::-webkit-scrollbar-thumb { background: #2d3148; border-radius: 99px; }
::-webkit-scrollbar-thumb:hover { background: var(--primary); }

/* ── Layout ─────────────────────────────────────────────── */
.app-wrapper { display: flex; height: 100vh; overflow: hidden; }

/* ── Sidebar ─────────────────────────────────────────────── */
.sidebar {
  width: 240px;
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: var(--transition);
  z-index: 50;
}

.sidebar-logo {
  padding: 20px 20px 16px;
  display: flex;
  align-items: center;
  gap: 10px;
  border-bottom: 1px solid var(--border);
}

.logo-icon {
  width: 36px; height: 36px;
  background: linear-gradient(135deg, var(--primary), #4f46e5);
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 18px;
  box-shadow: 0 0 16px var(--primary-glow);
}

.logo-text { font-size: 1.15rem; font-weight: 700; color: var(--text-primary); }
.logo-version { font-size: 0.65rem; color: var(--text-muted); margin-top: 1px; font-family: var(--font-mono); }

.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }

.nav-section-label {
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 12px 10px 6px;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 9px 12px;
  border-radius: var(--radius);
  color: var(--text-secondary);
  font-size: 0.88rem;
  font-weight: 500;
  transition: var(--transition);
  margin-bottom: 2px;
  cursor: pointer;
  user-select: none;
}

.nav-item:hover { background: var(--bg-hover); color: var(--text-primary); }
.nav-item.active {
  background: var(--primary-soft);
  color: var(--text-link);
  box-shadow: inset 2px 0 0 var(--primary);
}
.nav-item .icon { font-size: 1rem; width: 20px; text-align: center; flex-shrink: 0; }
.nav-badge {
  margin-left: auto;
  background: var(--primary-soft);
  color: var(--primary);
  font-size: 0.68rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 99px;
}

.sidebar-footer {
  padding: 12px 10px;
  border-top: 1px solid var(--border);
}

.user-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: var(--radius);
  transition: var(--transition);
  cursor: pointer;
}
.user-card:hover { background: var(--bg-hover); }
.user-avatar {
  width: 32px; height: 32px;
  background: linear-gradient(135deg, var(--primary), #4f46e5);
  border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 0.85rem; font-weight: 700; color: white; flex-shrink: 0;
}
.user-name  { font-size: 0.85rem; font-weight: 600; color: var(--text-primary); }
.user-role  { font-size: 0.72rem; color: var(--text-muted); }

/* ── Main Content ────────────────────────────────────────── */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

/* ── Topbar ──────────────────────────────────────────────── */
.topbar {
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-surface);
  flex-shrink: 0;
}

.topbar-title { font-size: 1rem; font-weight: 600; color: var(--text-primary); }
.topbar-right { display: flex; align-items: center; gap: 12px; }

/* ── Page Content ────────────────────────────────────────── */
.page { flex: 1; overflow-y: auto; padding: 24px; display: none; }
.page.active { display: block; }

/* ── Cards ───────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 16px;
}
.card-title { font-size: 0.95rem; font-weight: 600; color: var(--text-primary); }
.card-subtitle { font-size: 0.8rem; color: var(--text-muted); margin-top: 2px; }

/* ── Stat Cards ──────────────────────────────────────────── */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  transition: var(--transition);
  position: relative;
  overflow: hidden;
}
.stat-card::before {
  content: '';
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 2px;
  background: var(--accent-color, var(--primary));
}
.stat-card:hover { border-color: var(--primary-glow); transform: translateY(-1px); }

.stat-icon {
  width: 40px; height: 40px;
  border-radius: var(--radius);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.2rem;
  background: var(--primary-soft);
}
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-label { font-size: 0.8rem; color: var(--text-secondary); }
.stat-change {
  font-size: 0.75rem;
  color: var(--success);
  font-weight: 500;
}

/* ── Table ───────────────────────────────────────────────── */
.table-container {
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border);
}

table { width: 100%; border-collapse: collapse; }
thead tr { border-bottom: 1px solid var(--border); }
thead th {
  text-align: left;
  padding: 12px 16px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  background: var(--bg-elevated);
  white-space: nowrap;
}

tbody tr {
  border-bottom: 1px solid var(--border);
  transition: var(--transition);
}
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: var(--bg-hover); }

tbody td {
  padding: 12px 16px;
  font-size: 0.85rem;
  color: var(--text-primary);
  vertical-align: middle;
}

.key-display {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--primary);
  background: var(--primary-soft);
  padding: 3px 8px;
  border-radius: var(--radius-sm);
}

/* ── Badges/Status ───────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 0.73rem;
  font-weight: 600;
  white-space: nowrap;
}
.badge::before { content: ''; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.badge-active   { background: rgba(16,185,129,.15); color: #10b981; }
.badge-inactive { background: rgba(107,114,128,.15); color: #9ca3af; }
.badge-expired  { background: rgba(239,68,68,.15);  color: #ef4444; }
.badge-revoked  { background: rgba(239,68,68,.15);  color: #ef4444; }
.badge-suspended{ background: rgba(245,158,11,.15); color: #f59e0b; }

/* ── Buttons ─────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.85rem;
  font-weight: 500;
  transition: var(--transition);
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
}

.btn-primary {
  background: var(--primary);
  color: white;
  border-color: var(--primary);
}
.btn-primary:hover { background: #6d5ce6; box-shadow: 0 0 16px var(--primary-glow); }

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); color: var(--text-primary); }

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
  border-color: rgba(239,68,68,0.3);
}
.btn-danger:hover { background: rgba(239,68,68,0.25); }

.btn-success {
  background: rgba(16,185,129,0.15);
  color: var(--success);
  border-color: rgba(16,185,129,0.3);
}
.btn-sm { padding: 5px 10px; font-size: 0.78rem; }
.btn-icon { width: 32px; height: 32px; padding: 0; justify-content: center; border-radius: var(--radius-sm); }

/* ── Forms ───────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 6px; margin-bottom: 16px; }
.form-label { font-size: 0.82rem; font-weight: 500; color: var(--text-secondary); }
.form-required { color: var(--danger); margin-left: 2px; }

.form-control {
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 13px;
  color: var(--text-primary);
  font-size: 0.88rem;
  transition: var(--transition);
  width: 100%;
}
.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--primary-soft);
}
.form-control::placeholder { color: var(--text-muted); }

select.form-control { cursor: pointer; }
.form-control.mono { font-family: var(--font-mono); font-size: 0.82rem; }

.form-hint { font-size: 0.75rem; color: var(--text-muted); }
.form-error { font-size: 0.75rem; color: var(--danger); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }

.checkbox-group { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.checkbox-group input[type="checkbox"] { width: 16px; height: 16px; accent-color: var(--primary); cursor: pointer; }

/* ── Modal ───────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(4px);
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s;
}
.modal-backdrop.open { opacity: 1; pointer-events: all; }

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 28px;
  width: 90%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(20px) scale(0.97);
  transition: transform 0.2s cubic-bezier(0.4,0,0.2,1), opacity 0.2s;
  box-shadow: var(--shadow), var(--shadow-glow);
}
.modal-backdrop.open .modal { transform: translateY(0) scale(1); }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}
.modal-title { font-size: 1.05rem; font-weight: 700; }
.modal-close {
  width: 32px; height: 32px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  display: flex; align-items: center; justify-content: center;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
  font-size: 1rem;
}
.modal-close:hover { background: var(--bg-hover); color: var(--text-primary); }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; margin-top: 24px; padding-top: 20px; border-top: 1px solid var(--border); }

/* ── Alerts / Toasts ─────────────────────────────────────── */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  border-radius: var(--radius-lg);
  font-size: 0.85rem;
  font-weight: 500;
  min-width: 280px;
  max-width: 400px;
  box-shadow: var(--shadow);
  animation: slideIn 0.3s cubic-bezier(0.4,0,0.2,1);
  border: 1px solid transparent;
}
.toast-success { background: rgba(16,185,129,0.15); color: #10b981; border-color: rgba(16,185,129,0.3); }
.toast-error   { background: rgba(239,68,68,0.15);  color: #ef4444; border-color: rgba(239,68,68,0.3); }
.toast-info    { background: var(--primary-soft);   color: var(--primary); border-color: var(--primary-glow); }
.toast-warn    { background: rgba(245,158,11,0.15); color: #f59e0b; border-color: rgba(245,158,11,0.3); }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ── Search / Filter Bar ─────────────────────────────────── */
.filter-bar {
  display: flex;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.search-input {
  flex: 1;
  min-width: 200px;
  position: relative;
}
.search-input input { padding-left: 36px; }
.search-icon {
  position: absolute;
  left: 11px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--text-muted);
  font-size: 0.9rem;
  pointer-events: none;
}

/* ── Pagination ──────────────────────────────────────────── */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  font-size: 0.82rem;
  color: var(--text-secondary);
  border-top: 1px solid var(--border);
}
.pagination-btns { display: flex; gap: 4px; }
.page-btn {
  width: 30px; height: 30px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  font-size: 0.82rem;
  background: transparent;
  color: var(--text-secondary);
  transition: var(--transition);
  cursor: pointer;
  border: 1px solid transparent;
}
.page-btn:hover { background: var(--bg-hover); color: var(--text-primary); }
.page-btn.active { background: var(--primary-soft); color: var(--primary); border-color: var(--primary-glow); }

/* ── Login Page ──────────────────────────────────────────── */
#login-page {
  position: fixed; inset: 0;
  background: var(--bg-base);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
}
.login-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 40px;
  box-shadow: var(--shadow), var(--shadow-glow);
}
.login-logo {
  display: flex; align-items: center; gap: 12px;
  margin-bottom: 32px;
  justify-content: center;
}
.login-logo .logo-icon { width: 48px; height: 48px; font-size: 24px; }
.login-logo .logo-text { font-size: 1.5rem; font-weight: 700; }
.login-title { text-align: center; font-size: 1.1rem; font-weight: 600; margin-bottom: 8px; }
.login-sub   { text-align: center; font-size: 0.85rem; color: var(--text-muted); margin-bottom: 28px; }

/* ── Chart ───────────────────────────────────────────────── */
.chart-bar {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 80px;
}
.chart-bar-item {
  flex: 1;
  background: var(--primary-soft);
  border-radius: 4px 4px 0 0;
  min-height: 4px;
  transition: height 0.4s cubic-bezier(0.4,0,0.2,1);
  cursor: pointer;
  position: relative;
}
.chart-bar-item:hover { background: var(--primary); }
.chart-bar-item .tooltip {
  position: absolute;
  bottom: calc(100% + 6px);
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 8px;
  font-size: 0.7rem;
  white-space: nowrap;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.15s;
}
.chart-bar-item:hover .tooltip { opacity: 1; }

/* ── Empty state ─────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 48px;
  color: var(--text-muted);
  gap: 8px;
}
.empty-state .icon { font-size: 2.5rem; opacity: 0.4; }
.empty-state .title { font-size: 0.9rem; font-weight: 600; }
.empty-state .desc  { font-size: 0.8rem; }

/* ── Code block ──────────────────────────────────────────── */
.code-block {
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: #a6e3a1;
  overflow-x: auto;
  white-space: pre;
  position: relative;
}
.code-copy-btn {
  position: absolute;
  top: 8px; right: 8px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 10px;
  font-size: 0.72rem;
  color: var(--text-secondary);
  cursor: pointer;
  transition: var(--transition);
}
.code-copy-btn:hover { color: var(--text-primary); background: var(--bg-hover); }

/* ── Utility ─────────────────────────────────────────────── */
.text-primary   { color: var(--text-primary); }
.text-secondary { color: var(--text-secondary); }
.text-muted     { color: var(--text-muted); }
.text-success   { color: var(--success); }
.text-danger    { color: var(--danger); }
.text-warning   { color: var(--warning); }
.text-link      { color: var(--text-link); }
.mono           { font-family: var(--font-mono); }
.bold           { font-weight: 600; }
.flex           { display: flex; }
.flex-col       { flex-direction: column; }
.items-center   { align-items: center; }
.justify-between{ justify-content: space-between; }
.gap-2          { gap: 8px; }
.gap-3          { gap: 12px; }
.gap-4          { gap: 16px; }
.mt-4           { margin-top: 16px; }
.mb-4           { margin-bottom: 16px; }
.grid-2         { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.grid-3         { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 16px; }
.w-full         { width: 100%; }
.truncate       { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.spin           { animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Responsive ──────────────────────────────────────────── */
@media (max-width: 768px) {
  .sidebar { width: 200px; }
  .form-row, .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
}
/* =========================================
   Show Password Toggle
   ========================================= */
.password-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}
.password-wrapper .form-control {
  padding-right: 40px;
}
.btn-toggle-password {
  position: absolute;
  right: 10px;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.btn-toggle-password:hover {
  color: var(--text-light);
}
