/* ==========================================================================
   Ingate Dashboard — Command Console
   Enterprise-grade LLM gateway administration
   Typography: JetBrains Mono (data/code) + Plus Jakarta Sans (UI)
   Palette: Deep slate with electric blue accents — trust, clarity, precision
   ========================================================================== */

/* ======================== DESIGN TOKENS ======================== */

:root {
  /* Surfaces — deep slate progression */
  --bg-base: #090b10;
  --bg-surface: #0f1117;
  --bg-raised: #151820;
  --bg-hover: #1a1e2a;
  --bg-input: #0c0e14;
  --bg-overlay: rgba(5, 6, 10, 0.82);

  /* Borders */
  --border: #1c2030;
  --border-subtle: #14171f;
  --border-focus: #4f8ff7;
  --border-active: #3b7be8;

  /* Text */
  --text-primary: #e8eaf0;
  --text-secondary: #8b92a8;
  --text-muted: #4a5068;
  --text-faint: #333848;

  /* Accent — electric blue */
  --accent: #4f8ff7;
  --accent-hover: #6ba1ff;
  --accent-dim: rgba(79, 143, 247, 0.08);
  --accent-glow: rgba(79, 143, 247, 0.03);
  --accent-text: #7db4ff;
  --accent-solid: #3b7be8;

  /* Semantic */
  --success: #34d399;
  --success-dim: rgba(52, 211, 153, 0.08);
  --success-border: rgba(52, 211, 153, 0.2);
  --error: #f87171;
  --error-dim: rgba(248, 113, 113, 0.08);
  --error-border: rgba(248, 113, 113, 0.2);
  --info: #60a5fa;
  --info-dim: rgba(96, 165, 250, 0.08);
  --info-border: rgba(96, 165, 250, 0.2);
  --warn: #fbbf24;
  --warn-dim: rgba(251, 191, 36, 0.08);
  --warn-border: rgba(251, 191, 36, 0.2);

  /* Typography */
  --mono: 'JetBrains Mono', 'Cascadia Code', 'Fira Code', 'SF Mono', monospace;
  --sans: 'Plus Jakarta Sans', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;

  /* Radii */
  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;
  --radius-xl: 16px;

  /* Motion */
  --ease: cubic-bezier(0.25, 0.46, 0.45, 0.94);
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --transition: 160ms var(--ease);
  --transition-slow: 280ms var(--ease-out);

  /* Elevation */
  --shadow-sm: 0 1px 2px rgba(0,0,0,0.2), 0 0 1px rgba(0,0,0,0.1);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.25), 0 1px 4px rgba(0,0,0,0.15);
  --shadow-lg: 0 12px 48px rgba(0,0,0,0.35), 0 2px 8px rgba(0,0,0,0.2);
  --shadow-glow: 0 0 24px rgba(79, 143, 247, 0.06);
}

/* ======================== RESET ======================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
}

body {
  font-family: var(--sans);
  background: var(--bg-base);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.6;
}

a { color: var(--accent-text); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-hover); }

/* Scrollbar */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

::selection { background: rgba(79, 143, 247, 0.25); color: var(--text-primary); }

/* ======================== HEADER ======================== */

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  height: 48px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
  backdrop-filter: blur(16px) saturate(1.4);
  background: rgba(15, 17, 23, 0.92);
}

.header-left { display: flex; align-items: center; }

.logo {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  text-decoration: none;
  color: var(--text-primary);
}

.logo:hover { color: var(--text-primary); }

.logo-mark {
  display: block;
  width: 20px;
  height: 20px;
  background: linear-gradient(135deg, var(--accent) 0%, var(--accent-solid) 100%);
  border-radius: 5px;
  position: relative;
  box-shadow: 0 0 12px rgba(79, 143, 247, 0.2);
}

.logo-mark::after {
  content: '';
  position: absolute;
  top: 4px;
  left: 6px;
  width: 2.5px;
  height: 12px;
  background: rgba(255,255,255,0.9);
  border-radius: 1.5px;
}

.logo-text {
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.03em;
}

/* Nav — center-aligned horizontal */
.app-nav {
  display: flex;
  gap: 1px;
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  background: var(--bg-base);
  border-radius: var(--radius);
  padding: 3px;
}

.nav-link {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--text-muted);
  padding: 0.32rem 0.75rem;
  border-radius: var(--radius-sm);
  transition: all var(--transition);
  display: flex;
  align-items: center;
  gap: 0.35rem;
  text-decoration: none;
  white-space: nowrap;
}

.nav-link:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.nav-link.active {
  color: var(--text-primary);
  background: var(--bg-raised);
  box-shadow: var(--shadow-sm);
}

.nav-icon { width: 13px; height: 13px; flex-shrink: 0; opacity: 0.7; }
.nav-link.active .nav-icon { opacity: 1; }

.header-right {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.refresh-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: all var(--transition);
}

.refresh-btn:hover { color: var(--text-secondary); background: var(--bg-hover); border-color: var(--border); }

.refresh-btn.spinning .refresh-icon { animation: spin 0.5s var(--ease); }

.refresh-icon { width: 13px; height: 13px; }

@keyframes spin { from { transform: rotate(0deg); } to { transform: rotate(360deg); } }

.auto-refresh-toggle {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.5rem;
  background: none;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.68rem;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: 0.02em;
}

.auto-refresh-toggle:hover { color: var(--text-secondary); background: var(--bg-hover); border-color: var(--border); }

.auto-refresh-toggle.active {
  color: var(--success);
  border-color: var(--success-border);
  background: var(--success-dim);
}

.auto-refresh-dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: currentColor;
  transition: background var(--transition);
}

.auto-refresh-toggle.active .auto-refresh-dot { animation: pulse-dot 2s ease-in-out infinite; }

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

/* ======================== MAIN ======================== */

.app-main {
  flex: 1;
  padding: 2rem 2.5rem 4rem;
  max-width: 1240px;
  width: 100%;
  margin: 0 auto;
  animation: fadeUp 300ms var(--ease-out);
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ======================== LOADING & EMPTY ======================== */

.loading-state {
  text-align: center;
  padding: 6rem 1rem;
  color: var(--text-muted);
  font-family: var(--mono);
  font-size: 0.8rem;
  letter-spacing: 0.04em;
}

.loading-state::before {
  content: '';
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  margin-right: 0.6rem;
  vertical-align: middle;
  animation: loader-spin 0.7s linear infinite;
}

@keyframes loader-spin { to { transform: rotate(360deg); } }

.empty-state {
  text-align: center;
  padding: 5rem 1rem;
  max-width: 380px;
  margin: 0 auto;
}

.empty-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  margin: 0 auto 1.25rem;
  border-radius: var(--radius-lg);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.empty-icon svg { width: 22px; height: 22px; }

.empty-title {
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.3rem;
}

.empty-description {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.55;
  margin-bottom: 1.25rem;
}

.error-state {
  text-align: center;
  padding: 5rem 1rem;
  color: var(--error);
  font-family: var(--mono);
  font-size: 0.82rem;
}

/* ======================== PAGE HEADER ======================== */

.page-header {
  margin-bottom: 2rem;
}

.page-header-row {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
}

.page-title {
  font-family: var(--sans);
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--text-primary);
  letter-spacing: -0.03em;
  line-height: 1.2;
  margin-bottom: 0.25rem;
}

.page-description {
  font-size: 0.82rem;
  color: var(--text-muted);
  line-height: 1.5;
}

.page-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-shrink: 0;
}

.page-breadcrumb {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  margin-bottom: 0.2rem;
  letter-spacing: 0.01em;
}

.page-breadcrumb a { color: var(--text-secondary); }
.page-breadcrumb a:hover { color: var(--accent-text); }
.page-breadcrumb .sep { margin: 0 0.35rem; opacity: 0.4; }

/* ======================== SECTION HEADER ======================== */

.section-header {
  margin-top: 2.25rem;
  margin-bottom: 1rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.section-title {
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-muted);
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.section-count {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  background: var(--bg-raised);
  padding: 0.12rem 0.45rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border);
}

/* ======================== STATS GRID ======================== */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
  margin-bottom: 2rem;
}

.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.15rem 1.25rem;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.stat-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: var(--stat-accent, var(--border));
  opacity: 0.5;
  transition: opacity var(--transition);
}

.stat-card:hover { border-color: var(--text-faint); }
.stat-card:hover::before { opacity: 1; }

.stat-label {
  font-family: var(--mono);
  font-size: 0.64rem;
  font-weight: 500;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 0.5rem;
}

.stat-value {
  font-family: var(--mono);
  font-size: 1.65rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.15;
  letter-spacing: -0.03em;
}

.stat-card.stat-success { --stat-accent: var(--success); }
.stat-card.stat-success .stat-value { color: var(--success); }
.stat-card.stat-error { --stat-accent: var(--error); }
.stat-card.stat-error .stat-value { color: var(--error); }
.stat-card.stat-info { --stat-accent: var(--info); }
.stat-card.stat-info .stat-value { color: var(--info); }
.stat-card.stat-warn { --stat-accent: var(--warn); }
.stat-card.stat-warn .stat-value { color: var(--warn); }
.stat-card.stat-accent { --stat-accent: var(--accent); }
.stat-card.stat-accent .stat-value { color: var(--accent-text); }

.stat-sub {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-top: 0.3rem;
}

/* ======================== PROVIDER CARDS ======================== */

.provider-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}

.provider-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem 1.25rem;
  transition: border-color var(--transition);
}

.provider-card:hover { border-color: var(--text-faint); }

.provider-name {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--accent-text);
  margin-bottom: 0.6rem;
}

.provider-stats {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.5rem 1rem;
}

.provider-stat-label {
  font-family: var(--mono);
  font-size: 0.62rem;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.provider-stat-value {
  font-family: var(--mono);
  font-size: 0.85rem;
  font-weight: 500;
  color: var(--text-secondary);
}

/* ======================== FILTER BAR ======================== */

.filter-bar {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

.filter-bar .filter-input {
  font-family: var(--mono);
  font-size: 0.78rem;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.4rem 0.65rem;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
  min-width: 0;
}

.filter-bar .filter-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.filter-bar .filter-input::placeholder { color: var(--text-faint); }

.filter-input-search {
  flex: 1;
  min-width: 160px;
  max-width: 300px;
}

.filter-select {
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='%234a5068'%3E%3Cpath d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.5rem center;
  padding-right: 1.5rem !important;
}

.filter-divider {
  width: 1px;
  height: 18px;
  background: var(--border);
  flex-shrink: 0;
}

.filter-count {
  font-family: var(--mono);
  font-size: 0.68rem;
  color: var(--text-muted);
  margin-left: auto;
}

/* ======================== DATA TABLE ======================== */

.data-table {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
}

.data-table thead th {
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  padding: 0.6rem 0.85rem;
  text-align: left;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 48px;
  background: var(--bg-base);
  z-index: 10;
}

.data-table tbody td {
  font-family: var(--mono);
  font-size: 0.78rem;
  padding: 0.65rem 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  vertical-align: middle;
}

.data-table tbody tr {
  transition: background var(--transition);
}

.data-table tbody tr:hover td {
  background: var(--bg-hover);
}

.data-table tbody tr.clickable { cursor: pointer; }

.data-table tbody tr.row-active td {
  background: var(--bg-raised);
  border-bottom-color: transparent;
}

/* ======================== LOG DETAIL ======================== */

.log-detail {
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  animation: slideDown 220ms var(--ease-out);
}

@keyframes slideDown {
  from { opacity: 0; max-height: 0; }
  to { opacity: 1; max-height: 800px; }
}

.log-detail-inner {
  padding: 1.1rem 1.25rem 1.25rem;
  display: grid;
  gap: 0.75rem;
}

.log-detail-section { position: relative; }

.log-detail-label {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.35rem;
}

.log-detail-label span {
  font-family: var(--mono);
  font-size: 0.64rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.log-detail-text {
  font-family: var(--mono);
  font-size: 0.78rem;
  line-height: 1.65;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-sm);
  padding: 0.75rem;
  white-space: pre-wrap;
  word-break: break-word;
  max-height: 200px;
  overflow-y: auto;
}

.log-detail-text.muted { color: var(--text-muted); font-style: italic; }

.log-detail-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem 1.5rem;
  padding-top: 0.5rem;
  border-top: 1px solid var(--border-subtle);
}

.log-meta-item {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

.log-meta-item strong {
  color: var(--text-secondary);
  font-weight: 500;
}

/* ======================== BADGES ======================== */

.badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--mono);
  font-size: 0.65rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 4px;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

.badge-default { background: var(--bg-raised); color: var(--text-secondary); border: 1px solid var(--border); }
.badge-success { background: var(--success-dim); color: var(--success); border: 1px solid var(--success-border); }
.badge-error   { background: var(--error-dim); color: var(--error); border: 1px solid var(--error-border); }
.badge-info    { background: var(--info-dim); color: var(--info); border: 1px solid var(--info-border); }
.badge-warn    { background: var(--warn-dim); color: var(--warn); border: 1px solid var(--warn-border); }
.badge-muted   { background: var(--bg-raised); color: var(--text-muted); border: 1px solid var(--border); }
.badge-accent  { background: var(--accent-dim); color: var(--accent-text); border: 1px solid rgba(79, 143, 247, 0.2); }

/* ======================== DETAIL GRID ======================== */

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.5rem;
}

.detail-item {
  padding: 0.8rem 0.95rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.detail-label {
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 0.3rem;
}

.detail-value {
  font-family: var(--mono);
  font-size: 0.85rem;
  color: var(--text-primary);
  word-break: break-all;
}

/* ======================== CODE BLOCKS ======================== */

.code-block {
  font-family: var(--mono);
  font-size: 0.76rem;
  line-height: 1.65;
  color: var(--text-secondary);
  background: var(--bg-input);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin-bottom: 1rem;
}

.code-block-sm {
  font-size: 0.73rem;
  padding: 0.75rem;
  max-height: 180px;
  overflow-y: auto;
}

/* ======================== VERSION CARDS ======================== */

.version-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 0.75rem;
  overflow: hidden;
}

.version-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.6rem 0.85rem;
  border-bottom: 1px solid var(--border-subtle);
}

.version-number {
  font-family: var(--mono);
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--accent-text);
}

.version-time {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-muted);
}

/* ======================== FORMS ======================== */

.form-grid { max-width: 640px; }
.form-group { margin-bottom: 1.25rem; }

.form-group-inline {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.form-label {
  display: block;
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.form-input, .form-textarea, .form-select-input {
  width: 100%;
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.55rem 0.8rem;
  transition: border-color var(--transition), box-shadow var(--transition);
  outline: none;
}

.form-input:focus, .form-textarea:focus, .form-select-input:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.form-input::placeholder, .form-textarea::placeholder { color: var(--text-faint); }

.form-textarea {
  min-height: 180px;
  resize: vertical;
  line-height: 1.65;
  tab-size: 2;
}

.form-checkbox {
  accent-color: var(--accent);
  width: 16px;
  height: 16px;
}

.form-hint {
  font-family: var(--mono);
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.35rem;
}

.form-actions {
  display: flex;
  gap: 0.5rem;
  margin-top: 1.75rem;
}

/* ======================== BUTTONS ======================== */

.btn {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 0.48rem 1rem;
  border: 1px solid transparent;
  border-radius: var(--radius);
  cursor: pointer;
  transition: all var(--transition);
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  text-decoration: none;
  line-height: 1.4;
  white-space: nowrap;
}

.btn:disabled { opacity: 0.45; cursor: not-allowed; pointer-events: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  box-shadow: 0 0 16px rgba(79, 143, 247, 0.15);
}

.btn-secondary {
  background: transparent;
  color: var(--text-secondary);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  color: var(--text-primary);
  border-color: var(--text-muted);
  background: var(--bg-raised);
}

.btn-danger {
  background: transparent;
  color: var(--error);
  border-color: var(--error-border);
}

.btn-danger:hover:not(:disabled) {
  background: var(--error-dim);
  border-color: var(--error);
}

.btn-sm {
  font-size: 0.73rem;
  padding: 0.28rem 0.6rem;
}

.btn-ghost {
  background: none;
  border: none;
  color: var(--text-muted);
  padding: 0.2rem 0.45rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all var(--transition);
  font-family: var(--sans);
  font-size: 0.78rem;
}

.btn-ghost:hover { color: var(--text-primary); background: var(--bg-hover); }
.btn-ghost.danger:hover { color: var(--error); background: var(--error-dim); }

.btn-copy {
  font-family: var(--mono);
  font-size: 0.63rem;
  font-weight: 600;
  color: var(--text-muted);
  background: none;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.15rem 0.4rem;
  cursor: pointer;
  transition: all var(--transition);
  letter-spacing: 0.02em;
}

.btn-copy:hover { color: var(--text-secondary); border-color: var(--text-muted); }
.btn-copy.copied { color: var(--success); border-color: var(--success-border); }

/* ======================== TOAST ======================== */

.toast-container {
  position: fixed;
  bottom: 1.25rem;
  right: 1.25rem;
  z-index: 1000;
  display: flex;
  flex-direction: column-reverse;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  font-family: var(--sans);
  font-size: 0.8rem;
  font-weight: 500;
  padding: 0.65rem 1rem;
  border-radius: var(--radius);
  pointer-events: auto;
  max-width: 380px;
  word-break: break-word;
  opacity: 0;
  transform: translateY(8px);
  transition: all 200ms var(--ease-out);
  box-shadow: var(--shadow-md);
  backdrop-filter: blur(12px);
}

.toast-show { opacity: 1; transform: translateY(0); }

.toast-success { background: rgba(52, 211, 153, 0.12); color: var(--success); border: 1px solid var(--success-border); }
.toast-error   { background: rgba(248, 113, 113, 0.12); color: var(--error); border: 1px solid var(--error-border); }
.toast-info    { background: rgba(96, 165, 250, 0.12); color: var(--info); border: 1px solid var(--info-border); }

/* ======================== MODAL ======================== */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: var(--bg-overlay);
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  animation: fadeIn 180ms var(--ease);
}

.modal-backdrop[hidden] { display: none; }

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  padding: 1.75rem;
  max-width: 440px;
  width: 90%;
  box-shadow: var(--shadow-lg);
  animation: scaleIn 220ms var(--ease-out);
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes scaleIn { from { opacity: 0; transform: scale(0.97) translateY(4px); } to { opacity: 1; transform: scale(1) translateY(0); } }

.modal-title {
  font-family: var(--sans);
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--text-primary);
  margin-bottom: 0.5rem;
  letter-spacing: -0.02em;
}

.modal-body {
  font-size: 0.85rem;
  color: var(--text-secondary);
  line-height: 1.55;
  margin-bottom: 1.5rem;
}

.modal-body code {
  font-family: var(--mono);
  font-size: 0.78rem;
  background: var(--bg-raised);
  padding: 0.12rem 0.4rem;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 0.5rem;
}

/* ======================== LOGIN PAGE ======================== */

.login-card {
  max-width: 400px;
  margin: 12vh auto 0;
  padding: 2.75rem 2.25rem 2.5rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-xl);
  box-shadow: var(--shadow-lg), var(--shadow-glow);
  text-align: center;
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent 0%, var(--accent) 50%, transparent 100%);
  opacity: 0.6;
}

.login-logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  margin-bottom: 0.5rem;
}

.logo-mark-lg {
  width: 28px;
  height: 28px;
  border-radius: 7px;
}

.logo-mark-lg::after {
  top: 5px;
  left: 8px;
  width: 3px;
  height: 18px;
}

.login-title {
  font-family: var(--sans);
  font-size: 1.5rem;
  font-weight: 800;
  color: var(--text-primary);
  letter-spacing: -0.04em;
}

.login-subtitle {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 2rem;
  line-height: 1.5;
}

.login-form { text-align: left; }

.login-field { margin-bottom: 1.5rem; }

.login-field .form-input {
  padding: 0.7rem 0.85rem;
  font-size: 0.85rem;
}

.login-submit {
  width: 100%;
  padding: 0.65rem 1rem;
  font-size: 0.88rem;
  font-weight: 700;
}

.login-submit:disabled { opacity: 0.5; cursor: wait; }

/* ======================== NAV DROPDOWN ======================== */

.nav-dropdown {
  position: relative;
  display: inline-flex;
}

.nav-caret {
  width: 8px;
  height: 8px;
  margin-left: 1px;
  opacity: 0.4;
  transition: transform var(--transition), opacity var(--transition);
}

.nav-dropdown:hover .nav-caret,
.nav-dropdown:focus-within .nav-caret {
  transform: rotate(180deg);
  opacity: 0.7;
}

.nav-dropdown-menu {
  display: none;
  position: absolute;
  top: calc(100% + 4px);
  left: 50%;
  transform: translateX(-50%);
  min-width: 150px;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-md);
  padding: 0.3rem;
  z-index: 200;
}

.nav-dropdown:hover .nav-dropdown-menu,
.nav-dropdown:focus-within .nav-dropdown-menu {
  display: block;
  animation: dropIn 160ms var(--ease-out);
}

@keyframes dropIn {
  from { opacity: 0; transform: translateX(-50%) translateY(-4px); }
  to { opacity: 1; transform: translateX(-50%) translateY(0); }
}

.nav-dropdown-item {
  display: block;
  font-family: var(--sans);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-secondary);
  padding: 0.4rem 0.75rem;
  border-radius: var(--radius-sm);
  text-decoration: none;
  transition: all var(--transition);
}

.nav-dropdown-item:hover {
  color: var(--text-primary);
  background: var(--bg-hover);
}

/* ======================== ORG CONTEXT ======================== */

.org-context {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.18rem 0.55rem 0.18rem 0.65rem;
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: 20px;
  margin-right: 0.25rem;
}

.org-name {
  font-family: var(--sans);
  font-size: 0.72rem;
  font-weight: 600;
  color: var(--text-secondary);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.org-role-badge {
  font-family: var(--mono);
  font-size: 0.58rem;
  font-weight: 700;
  color: var(--accent-text);
  background: var(--accent-dim);
  padding: 0.05rem 0.4rem;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

/* ======================== LOGOUT BUTTON ======================== */

.logout-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  transition: all var(--transition);
}

.logout-btn:hover {
  color: var(--error);
  background: var(--error-dim);
}

.logout-btn .nav-icon { width: 14px; height: 14px; }

/* ======================== QUICK LINK CARDS ======================== */

.quick-link {
  transition: border-color var(--transition), background var(--transition);
  cursor: pointer;
}

.quick-link:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

.quick-link .detail-value { color: var(--text-secondary); }
.quick-link:hover .detail-value { color: var(--text-primary); }

/* ======================== USAGE DASHBOARD ======================== */

.usage-filter-bar {
  display: flex;
  align-items: center;
  gap: 1.5rem;
  margin-bottom: 1.75rem;
  flex-wrap: wrap;
  padding: 0.65rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.filter-section {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.filter-label {
  font-family: var(--mono);
  font-size: 0.62rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.btn-group {
  display: inline-flex;
  background: var(--bg-base);
  border-radius: var(--radius-sm);
  padding: 2px;
  gap: 1px;
}

.btn-group-item {
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 500;
  color: var(--text-muted);
  background: transparent;
  border: none;
  padding: 0.3rem 0.65rem;
  border-radius: 4px;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-group-item:hover {
  color: var(--text-secondary);
  background: var(--bg-hover);
}

.btn-group-item.active {
  color: var(--text-primary);
  background: var(--bg-raised);
  box-shadow: var(--shadow-sm);
  font-weight: 600;
}

.chart-section { margin-bottom: 2rem; }

.chart-canvas-wrapper {
  position: relative;
  width: 100%;
  height: 320px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.chart-canvas-wrapper-bar {
  height: auto;
  min-height: 250px;
  max-height: 500px;
}

.usage-chart-canvas {
  width: 100% !important;
  height: 100% !important;
}

.chart-empty {
  text-align: center;
  padding: 3rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.chart-empty .empty-title { margin-bottom: 0.25rem; }

/* ======================== OVERVIEW ======================== */

.quick-links-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.75rem;
}

.quick-link-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
  padding: 1.35rem 1rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  text-decoration: none;
  text-align: center;
  transition: all var(--transition);
  cursor: pointer;
}

.quick-link-card:hover {
  border-color: var(--accent);
  background: var(--accent-dim);
  transform: translateY(-1px);
  box-shadow: var(--shadow-glow);
}

.quick-link-icon {
  width: 28px;
  height: 28px;
  color: var(--text-muted);
  transition: color var(--transition);
}

.quick-link-icon svg { width: 100%; height: 100%; }

.quick-link-card:hover .quick-link-icon { color: var(--accent-text); }

.quick-link-label {
  font-family: var(--mono);
  font-size: 0.68rem;
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.quick-link-desc {
  font-size: 0.76rem;
  color: var(--text-muted);
}

.quick-link-card:hover .quick-link-label { color: var(--text-primary); }

/* ======================== MANAGEMENT PAGES ======================== */

.role-select {
  font-family: var(--mono);
  font-size: 0.73rem;
  color: var(--text-secondary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.22rem 1.4rem 0.22rem 0.45rem;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6' fill='%234a5068'%3E%3Cpath d='M0 0l5 6 5-6z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 0.35rem center;
}

.role-select:focus { border-color: var(--border-focus); }

.table-actions {
  display: flex;
  align-items: center;
  gap: 0.4rem;
}

.invite-form, .create-team-form, .add-member-form, .team-edit-form {
  padding: 1.15rem 1.25rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
}

.invite-form-row {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
}

.invite-form-row .form-group {
  display: flex;
  flex-direction: column;
}

.invite-form-row .form-group:last-child {
  flex-direction: row;
  gap: 0.4rem;
}

.mono-cell {
  font-family: var(--mono);
  font-size: 0.72rem;
  color: var(--text-muted);
  letter-spacing: -0.01em;
}

/* ======================== APP & KEY MANAGEMENT ======================== */

.tag-badge {
  display: inline-flex;
  align-items: center;
  font-family: var(--mono);
  font-size: 0.63rem;
  font-weight: 600;
  padding: 0.1rem 0.45rem;
  border-radius: 10px;
  color: var(--text-secondary);
  background: var(--bg-raised);
  border: 1px solid var(--border);
  white-space: nowrap;
  letter-spacing: 0.01em;
}

.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  align-items: center;
}

.key-prefix {
  font-family: var(--mono);
  font-size: 0.75rem;
  color: var(--text-secondary);
  background: var(--bg-raised);
  padding: 0.12rem 0.45rem;
  border-radius: 4px;
  letter-spacing: -0.01em;
  border: 1px solid var(--border);
}

.key-creation-alert {
  background: var(--bg-surface);
  border: 1px solid var(--warn-border);
  border-left: 3px solid var(--warn);
  border-radius: var(--radius);
  padding: 1.25rem 1.5rem;
  margin-bottom: 1.5rem;
  position: relative;
}

.key-creation-header {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.5rem;
}

.key-creation-icon { font-size: 1.2rem; }

.key-creation-title {
  font-family: var(--sans);
  font-size: 0.95rem;
  font-weight: 700;
  color: var(--text-primary);
}

.key-creation-warning {
  font-family: var(--sans);
  font-size: 0.8rem;
  color: var(--warn);
  margin-bottom: 0.75rem;
  font-weight: 600;
}

.key-creation-value {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.key-raw-display {
  font-family: var(--mono);
  font-size: 0.8rem;
  color: var(--text-primary);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 0.5rem 0.75rem;
  word-break: break-all;
  flex: 1;
  min-width: 200px;
  user-select: all;
}

.create-app-form, .edit-app-form {
  padding: 1.15rem 1.25rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 1.25rem;
}

/* ======================== OVERVIEW EMPTY CTA ======================== */

.overview-empty-cta {
  text-align: center;
  padding: 1.75rem;
  margin-bottom: 2.25rem;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.overview-empty-text {
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 0.75rem;
}

/* ======================== TABLE SCROLL WRAPPER ======================== */

.table-scroll-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

/* ======================== RESPONSIVE ======================== */

@media (max-width: 1024px) {
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .quick-links-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .app-header { padding: 0 1rem; }
  .app-main { padding: 1.5rem 1rem 2.5rem; }
  .app-nav {
    position: static;
    transform: none;
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    background: transparent;
    padding: 0;
    gap: 2px;
  }
  .app-nav::-webkit-scrollbar { display: none; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .detail-grid { grid-template-columns: 1fr; }
  .page-header-row { flex-direction: column; gap: 0.75rem; }
  .provider-grid { grid-template-columns: 1fr; }
  .filter-bar { flex-direction: column; align-items: stretch; }
  .filter-input-search { max-width: none; }
  .filter-count { margin-left: 0; }
  .org-context { display: none; }
  .login-card { margin-top: 6vh; padding: 2.25rem 1.75rem; }
  .usage-filter-bar { flex-direction: column; align-items: stretch; gap: 0.75rem; }
  .filter-section { flex-wrap: wrap; }
  .chart-canvas-wrapper { height: 260px; }
  .data-table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; min-width: 0; }
  .invite-form-row { flex-direction: column; }
  .invite-form-row .form-group:last-child { flex-direction: column; }
  .table-actions { flex-direction: column; gap: 0.25rem; }
  .key-creation-value { flex-direction: column; }
  .key-raw-display { min-width: 0; width: 100%; }
  .create-app-form, .edit-app-form { padding: 0.75rem; }
  .nav-dropdown-menu { left: 0; transform: none; min-width: 160px; }
  .detail-grid + .detail-label,
  .detail-grid + div { margin-top: 1rem; }
}

@media (max-width: 480px) {
  .app-header {
    flex-direction: column;
    height: auto;
    padding: 0.6rem 0.75rem;
    gap: 0.45rem;
  }
  .app-nav { flex-wrap: wrap; justify-content: center; gap: 2px; }
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .quick-links-grid { grid-template-columns: 1fr 1fr; }
  .data-table { font-size: 0.73rem; }
  .data-table thead th, .data-table tbody td { padding: 0.45rem 0.55rem; }
  .nav-link { font-size: 0.75rem; padding: 0.3rem 0.55rem; }
  .login-card { margin-top: 4vh; padding: 1.75rem 1.25rem; }
  .header-right .refresh-btn,
  .header-right .auto-refresh-toggle { display: none; }
  .chart-canvas-wrapper { height: 220px; padding: 0.65rem; }
  .btn-group-item { padding: 0.28rem 0.5rem; font-size: 0.68rem; }
  .invite-form, .create-team-form, .add-member-form, .team-edit-form { padding: 0.75rem; }
  .role-select { font-size: 0.68rem; }
  .nav-dropdown-menu {
    position: fixed;
    left: 0.5rem;
    right: 0.5rem;
    top: auto;
    transform: none;
    width: auto;
    min-width: 0;
  }
  .filter-bar .filter-input { width: 100%; }
  .filter-bar .filter-select { width: 100%; }
  .page-actions { width: 100%; justify-content: flex-start; }
  .page-title { font-size: 1.2rem; }
}
