:root {
  --bg: #ffffff;
  --bg-card: #f8f9fa;
  --bg-hover: #f0f1f3;
  --text: #1a1a1a;
  --text-secondary: #6b7280;
  --text-muted: #9ca3af;
  --border: #e5e7eb;
  --accent: #4f46e5;
  --accent-hover: #4338ca;
  --accent-light: #eef2ff;
  --success: #10b981;
  --warning: #f59e0b;
  --danger: #ef4444;
  --radius: 12px;
  --radius-sm: 8px;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", "Fira Code", monospace;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f0f0f;
    --bg-card: #1a1a1a;
    --bg-hover: #252525;
    --text: #e5e5e5;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;
    --border: #2a2a2a;
    --accent: #818cf8;
    --accent-hover: #6366f1;
    --accent-light: #1e1b4b;
    --shadow: 0 1px 3px rgba(0,0,0,0.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,0.4);
  }
}

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

html { font-size: 16px; -webkit-text-size-adjust: 100%; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  min-height: 100vh;
}

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

button {
  font-family: var(--font);
  cursor: pointer;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 500;
  padding: 0.5rem 1rem;
  transition: all 0.15s ease;
}

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

.btn-secondary {
  background: var(--bg-card);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--bg-hover); }

.btn-danger {
  background: var(--danger);
  color: #fff;
}
.btn-danger:hover { opacity: 0.9; }

.btn-sm { padding: 0.25rem 0.625rem; font-size: 0.8125rem; }
.btn-block { width: 100%; padding: 0.75rem; font-size: 1rem; }

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

.sidebar {
  width: 200px;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 1.5rem 0;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

.sidebar-logo {
  padding: 0 1.25rem 1.5rem;
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text);
  border-bottom: 1px solid var(--border);
  margin-bottom: 0.75rem;
}

.sidebar-nav { flex: 1; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.625rem 1.25rem;
  color: var(--text-secondary);
  font-size: 0.875rem;
  transition: all 0.15s;
  cursor: pointer;
}
.nav-item:hover { color: var(--text); background: var(--bg-hover); }
.nav-item.active { color: var(--accent); background: var(--accent-light); font-weight: 500; }
.nav-item svg { width: 18px; height: 18px; flex-shrink: 0; }

.sidebar-footer {
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--border);
}

.main-content {
  flex: 1;
  padding: 2rem;
  max-width: 960px;
  overflow-y: auto;
}

/* Mobile bottom tab */
.bottom-tab {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  z-index: 100;
  padding: 0.5rem 0;
  padding-bottom: env(safe-area-inset-bottom, 0.5rem);
}

.bottom-tab-inner {
  display: flex;
  justify-content: space-around;
}

.tab-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.25rem;
  padding: 0.625rem 1rem;
  min-height: 52px;
  color: var(--text-muted);
  font-size: 0.75rem;
  cursor: pointer;
  transition: color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
.tab-item svg { width: 26px; height: 26px; }
.tab-item.active { color: var(--accent); }

/* Cards */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  box-shadow: var(--shadow);
}

.card-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 1rem;
  margin-bottom: 1.5rem;
}

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

.stat-label {
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-top: 0.25rem;
}

/* Tables */
.table-wrap { overflow-x: auto; }

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

th {
  text-align: left;
  padding: 0.625rem 0.75rem;
  color: var(--text-secondary);
  font-weight: 500;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid var(--border);
}

tr:hover td { background: var(--bg-hover); }

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  border-bottom: 1px solid var(--border);
  margin-bottom: 1.25rem;
}

.tab-btn {
  padding: 0.625rem 1rem;
  background: none;
  color: var(--text-secondary);
  border-radius: 0;
  border-bottom: 2px solid transparent;
  font-size: 0.875rem;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--accent); border-bottom-color: var(--accent); }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  padding: 1rem;
}

.modal {
  background: var(--bg);
  border-radius: var(--radius);
  padding: 1.5rem;
  width: 100%;
  max-width: 440px;
  box-shadow: var(--shadow-lg);
}

.modal h3 {
  font-size: 1.125rem;
  margin-bottom: 1rem;
}

.modal-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
  margin-top: 1.25rem;
}

/* Form */
input[type="text"], input[type="number"], select {
  width: 100%;
  padding: 0.5rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-size: 0.875rem;
  font-family: var(--font);
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

label {
  display: block;
  font-size: 0.8125rem;
  color: var(--text-secondary);
  margin-bottom: 0.25rem;
}

.form-group { margin-bottom: 0.875rem; }

/* Badge */
.badge {
  display: inline-block;
  padding: 0.125rem 0.5rem;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 500;
}
.badge-active { background: #d1fae5; color: #065f46; }
.badge-revoked { background: #fee2e2; color: #991b1b; }

@media (prefers-color-scheme: dark) {
  .badge-active { background: #064e3b; color: #6ee7b7; }
  .badge-revoked { background: #7f1d1d; color: #fca5a5; }
}

/* Pagination */
.pagination {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  margin-top: 1rem;
  font-size: 0.875rem;
  color: var(--text-secondary);
}

/* Copy box */
.copy-box {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  word-break: break-all;
}
.copy-box button { flex-shrink: 0; }

/* Login page */
.login-container {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1.5rem;
}

.login-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
  max-width: 380px;
  text-align: center;
  min-height: 80vh;
}

.login-card h1 {
  font-size: 1.75rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
  margin-top: auto;
}

.login-card p {
  color: var(--text-secondary);
  font-size: 0.9375rem;
  margin-bottom: auto;
  line-height: 1.6;
}

.oauth-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.625rem;
  width: 100%;
  align-self: stretch;
  padding: 0.875rem;
  margin-bottom: 0.875rem;
  border-radius: var(--radius-sm);
  font-size: 0.9375rem;
  font-weight: 500;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  transition: all 0.15s;
}
.oauth-btn:hover { background: var(--bg-hover); box-shadow: var(--shadow); }
.oauth-btn svg { width: 20px; height: 20px; }

.divider {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  margin: 1.25rem 0;
  color: var(--text-muted);
  font-size: 0.8125rem;
}
.divider::before, .divider::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* Section header */
.section-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}
.section-header h2 { font-size: 1.25rem; font-weight: 600; }

/* Chart */
.chart-container {
  height: 160px;
  position: relative;
  margin-top: 0.75rem;
}

.chart-bar-group {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  height: 100%;
  gap: 4px;
  padding-bottom: 1.5rem;
}

.chart-bar-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
}

.chart-bar {
  width: 100%;
  max-width: 40px;
  background: var(--accent);
  border-radius: 4px 4px 0 0;
  min-height: 2px;
  transition: height 0.3s ease;
  opacity: 0.8;
}
.chart-bar:hover { opacity: 1; }

.chart-label {
  font-size: 0.6875rem;
  color: var(--text-muted);
  margin-top: 0.375rem;
}

/* Toast */
.toast {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  padding: 1rem 1.75rem;
  border-radius: var(--radius);
  background: rgba(0, 0, 0, 0.8);
  color: #fff;
  font-size: 1rem;
  font-weight: 500;
  z-index: 300;
  text-align: center;
  max-width: 80vw;
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  animation: toast-in 0.25s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -50%) scale(0.9); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }

/* Loading */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin: 2rem auto;
}
@keyframes spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

/* Key cards */
.keys-page { max-width: 720px; }

.keys-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 1.5rem;
}
.keys-header h2 { font-size: 1.25rem; font-weight: 600; margin-bottom: 0.25rem; }
.keys-desc { font-size: 0.8125rem; color: var(--text-secondary); }

.key-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  margin-bottom: 0.625rem;
  transition: border-color 0.15s;
}
.key-card:hover { border-color: var(--text-muted); }

.key-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.key-card-info { flex: 1; min-width: 0; }

.key-card-name {
  font-weight: 500;
  font-size: 0.9375rem;
  margin-bottom: 0.125rem;
}

.key-card-prefix {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
}
.key-card-prefix code {
  font-family: var(--font-mono);
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

.key-card-actions {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  flex-shrink: 0;
}

.key-card-bottom { }

.key-card-usage {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: 0.375rem;
}
.key-card-usage-text {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text);
}
.key-card-meta {
  font-size: 0.75rem;
  color: var(--text-muted);
}

.key-card-bar-wrap {
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
}
.key-card-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width 0.3s;
}

/* Deploy to Vault button */
.btn-deploy-vault {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  width: 100%;
  padding: 0.625rem;
  margin-top: 0.75rem;
  border-radius: var(--radius-sm);
  font-size: 0.875rem;
  font-weight: 600;
  background: var(--success);
  color: #fff;
  border: none;
  cursor: pointer;
  transition: opacity 0.15s;
}
.btn-deploy-vault:hover { opacity: 0.9; }
.btn-deploy-vault:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-deploy-vault svg { flex-shrink: 0; }

/* Limit selector */
.limit-options {
  display: flex;
  gap: 0.5rem;
}
.limit-btn {
  flex: 1;
  padding: 0.5rem 0;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
}
.limit-btn:hover { border-color: var(--text-muted); color: var(--text); }
.limit-btn.active {
  border-color: var(--accent);
  color: var(--accent);
  background: var(--accent-light);
}

.btn-icon-sm { width: 24px; height: 24px; }

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  padding: 0;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-secondary);
  border: none;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-icon svg { flex-shrink: 0; }
.btn-icon:hover { background: var(--bg-hover); color: var(--text); }
.btn-icon-danger:hover { background: #fee2e2; color: var(--danger); }

@media (prefers-color-scheme: dark) {
  .btn-icon-danger:hover { background: #7f1d1d; color: #fca5a5; }
}

/* Billing actions */
.billing-actions {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.btn-action {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  flex: 1;
  padding: 0.875rem 1.25rem;
  font-size: 1rem;
  font-weight: 600;
  border-radius: var(--radius);
  border: none;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-action-primary {
  background: var(--accent);
  color: #fff;
}
.btn-action-primary:hover { background: var(--accent-hover); box-shadow: var(--shadow-lg); }

.btn-action-accent {
  background: var(--success);
  color: #fff;
}
.btn-action-accent:hover { opacity: 0.9; box-shadow: var(--shadow-lg); }

.redeem-inline-box {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  padding: 0.75rem 0;
  margin-bottom: 1rem;
}
.redeem-inline-box input { max-width: 300px; }

/* Responsive */
@media (max-width: 768px) {
  .sidebar { display: none; }
  .bottom-tab { display: block; }
  .main-content { padding: 1rem 1rem 5rem; max-width: 100%; }
  .card-row { grid-template-columns: repeat(2, 1fr); }
  .section-header h2 { font-size: 1.125rem; }
}

@media (max-width: 480px) {
  .card-row { grid-template-columns: repeat(2, 1fr); }
}

.card-row.overview-stats {
  grid-template-columns: repeat(4, 1fr);
}
.overview-stats .card { padding: 0.75rem; }
.overview-stats .stat-label { white-space: nowrap; font-size: 0.75rem; }
.overview-stats .stat-value { font-size: 1.5rem; }
@media (max-width: 768px) {
  .overview-stats .stat-label { font-size: 0.6875rem; }
  .overview-stats .stat-value { font-size: 1.125rem; }
}
