/* =========================================================================
   Router-SvcLabs Admin Dashboard — CSS
   ========================================================================= */

/* --- CSS Custom Properties ------------------------------------------- */
:root {
  /* Colors */
  --color-bg:          #f0f2f5;
  --color-surface:     #ffffff;
  --color-sidebar-bg:  #1a1d29;
  --color-sidebar-text:#a0a3b1;
  --color-sidebar-active: #ffffff;
  --color-sidebar-hover:  rgba(255,255,255,0.08);
  --color-sidebar-active-bg: rgba(99,102,241,0.2);
  --color-primary:     #6366f1;
  --color-primary-hover:#4f46e5;
  --color-primary-light:#eef2ff;
  --color-text:        #1f2937;
  --color-text-muted:  #6b7280;
  --color-text-light:  #9ca3af;
  --color-border:      #e5e7eb;
  --color-border-light:#f3f4f6;
  --color-success:     #10b981;
  --color-success-bg:  #ecfdf5;
  --color-warning:     #f59e0b;
  --color-warning-bg:  #fffbeb;
  --color-danger:      #ef4444;
  --color-danger-bg:   #fef2f2;
  --color-info:        #3b82f6;
  --color-info-bg:     #eff6ff;

  /* Typography */
  --font-sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Consolas', monospace;

  /* Spacing */
  --sidebar-width: 260px;
  --header-height: 60px;

  /* Shadows */
  --shadow-sm:  0 1px 2px rgba(0,0,0,0.05);
  --shadow-md:  0 4px 6px -1px rgba(0,0,0,0.07), 0 2px 4px -2px rgba(0,0,0,0.05);
  --shadow-lg:  0 10px 15px -3px rgba(0,0,0,0.08), 0 4px 6px -4px rgba(0,0,0,0.05);

  /* Radius */
  --radius-sm: 6px;
  --radius-md: 8px;
  --radius-lg: 12px;
}

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

html {
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

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

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

/* --- Login Page ------------------------------------------------------ */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  padding: 1rem;
}

.login-card {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  padding: 2.5rem;
  width: 100%;
  max-width: 420px;
}

.login-card .login-header {
  text-align: center;
  margin-bottom: 2rem;
}

.login-card .login-header h1 {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--color-text);
  margin-bottom: 0.25rem;
}

.login-card .login-header p {
  color: var(--color-text-muted);
  font-size: 0.9rem;
}

.login-card .login-logo {
  width: 48px;
  height: 48px;
  background: var(--color-primary);
  border-radius: var(--radius-md);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.4rem;
  font-weight: 700;
  margin-bottom: 1rem;
}

/* --- Form Elements --------------------------------------------------- */
.form-group {
  margin-bottom: 1.25rem;
}

.form-group label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--color-text);
  margin-bottom: 0.375rem;
}

.form-control {
  width: 100%;
  padding: 0.625rem 0.875rem;
  font-size: 0.925rem;
  font-family: var(--font-sans);
  color: var(--color-text);
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: border-color 0.2s, box-shadow 0.2s;
  outline: none;
}

.form-control:focus {
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,0.15);
}

.form-control::placeholder {
  color: var(--color-text-light);
}

textarea.form-control {
  resize: vertical;
  min-height: 80px;
}

select.form-control {
  appearance: none;
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3e%3cpath stroke='%236b7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3e%3c/svg%3e");
  background-position: right 0.5rem center;
  background-repeat: no-repeat;
  background-size: 1.5em 1.5em;
  padding-right: 2.5rem;
}

.form-row {
  display: flex;
  gap: 1rem;
}

.form-row .form-group {
  flex: 1;
}

.form-hint {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

.form-error {
  color: var(--color-danger);
  font-size: 0.85rem;
  margin-top: 0.5rem;
}

.form-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: 1.5rem;
}

/* --- Buttons --------------------------------------------------------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.625rem 1.25rem;
  font-size: 0.875rem;
  font-weight: 600;
  font-family: var(--font-sans);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.2s;
  line-height: 1.4;
  white-space: nowrap;
}

.btn:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--color-primary);
  color: white;
}
.btn-primary:hover:not(:disabled) {
  background: var(--color-primary-hover);
}

.btn-secondary {
  background: var(--color-surface);
  color: var(--color-text);
  border-color: var(--color-border);
}
.btn-secondary:hover:not(:disabled) {
  background: var(--color-bg);
}

.btn-danger {
  background: var(--color-danger);
  color: white;
}
.btn-danger:hover:not(:disabled) {
  background: #dc2626;
}

.btn-success {
  background: var(--color-success);
  color: white;
}
.btn-success:hover:not(:disabled) {
  background: #059669;
}

.btn-ghost {
  background: transparent;
  color: var(--color-text-muted);
  padding: 0.375rem 0.625rem;
}
.btn-ghost:hover:not(:disabled) {
  background: var(--color-bg);
  color: var(--color-text);
}

.btn-sm {
  padding: 0.375rem 0.75rem;
  font-size: 0.8rem;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  padding: 0.375rem;
  border-radius: var(--radius-sm);
  background: transparent;
  border: none;
  cursor: pointer;
  color: var(--color-text-muted);
  font-size: 0.875rem;
  transition: all 0.15s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
}

.btn-icon:hover {
  background: var(--color-bg);
  color: var(--color-text);
}

.btn-icon.btn-icon-danger:hover {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

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

/* --- Sidebar --------------------------------------------------------- */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-sidebar-bg);
  color: var(--color-sidebar-text);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 100;
  transition: transform 0.3s;
}

.sidebar-header {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 1.25rem 1.25rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
}

.sidebar-logo {
  width: 36px;
  height: 36px;
  background: var(--color-primary);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  color: white;
  font-size: 1.1rem;
  font-weight: 700;
  flex-shrink: 0;
}

.sidebar-title {
  font-size: 1rem;
  font-weight: 700;
  color: white;
}

.sidebar-subtitle {
  font-size: 0.7rem;
  opacity: 0.5;
}

.sidebar-nav {
  flex: 1;
  padding: 0.75rem 0;
  overflow-y: auto;
}

.sidebar-section-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: rgba(255,255,255,0.3);
  padding: 0.75rem 1.25rem 0.375rem;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.625rem 1.25rem;
  color: var(--color-sidebar-text);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  border-left: 3px solid transparent;
  text-decoration: none;
}

.nav-item:hover {
  background: var(--color-sidebar-hover);
  color: var(--color-sidebar-active);
  text-decoration: none;
}

.nav-item.active {
  background: var(--color-sidebar-active-bg);
  color: var(--color-sidebar-active);
  border-left-color: var(--color-primary);
}

.nav-item .nav-icon {
  width: 20px;
  text-align: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.sidebar-footer {
  padding: 1rem 1.25rem;
  border-top: 1px solid rgba(255,255,255,0.06);
  font-size: 0.75rem;
  opacity: 0.4;
}

/* --- Main Content Area ----------------------------------------------- */
.main-wrapper {
  flex: 1;
  margin-left: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* --- Top Header ------------------------------------------------------ */
.top-header {
  height: var(--header-height);
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 1.5rem;
  position: sticky;
  top: 0;
  z-index: 50;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-left h2 {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--color-text);
}

.mobile-menu-btn {
  display: none;
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--color-text);
  padding: 0.25rem;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.user-avatar {
  width: 32px;
  height: 32px;
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.8rem;
}

/* --- Page Content ---------------------------------------------------- */
.page-content {
  flex: 1;
  padding: 1.5rem;
}

/* --- Page Header ----------------------------------------------------- */
.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1.5rem;
  flex-wrap: wrap;
  gap: 0.75rem;
}

.page-header h3 {
  font-size: 1.25rem;
  font-weight: 700;
}

.page-header-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

/* --- Cards ----------------------------------------------------------- */
.card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border-light);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-header h4 {
  font-size: 0.95rem;
  font-weight: 600;
}

.card-body {
  padding: 1.25rem;
}

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

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  padding: 1.25rem;
  display: flex;
  align-items: flex-start;
  gap: 1rem;
  box-shadow: var(--shadow-sm);
}

.stat-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.25rem;
  flex-shrink: 0;
}

.stat-icon.purple  { background: #ede9fe; color: #7c3aed; }
.stat-icon.blue    { background: #dbeafe; color: #2563eb; }
.stat-icon.green   { background: #d1fae5; color: #059669; }
.stat-icon.orange  { background: #ffedd5; color: #ea580c; }

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

.stat-label {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  margin-bottom: 0.25rem;
}

.stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  line-height: 1.2;
  color: var(--color-text);
}

.stat-sub {
  font-size: 0.75rem;
  color: var(--color-text-muted);
  margin-top: 0.25rem;
}

/* --- Provider Cards (Grid Layout) ------------------------------------ */
.provider-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(360px, 1fr));
  gap: 1rem;
}

.provider-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-sm);
  transition: box-shadow 0.2s, border-color 0.2s;
  overflow: hidden;
}

.provider-card:hover {
  box-shadow: var(--shadow-md);
  border-color: var(--color-primary);
}

.provider-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--color-border-light);
  gap: 0.75rem;
}

.provider-card-name {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  min-width: 0;
}

.provider-card-name h4 {
  font-size: 1rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.provider-type-icon {
  width: 36px;
  height: 36px;
  border-radius: var(--radius-sm);
  background: var(--color-primary-light);
  color: var(--color-primary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.85rem;
  font-weight: 700;
  text-transform: uppercase;
  flex-shrink: 0;
}

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

.provider-card-body {
  padding: 1rem 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.provider-field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 0.85rem;
}

.provider-field-label {
  color: var(--color-text-muted);
  font-weight: 500;
  min-width: 72px;
  flex-shrink: 0;
}

.provider-field-value {
  color: var(--color-text);
  min-width: 0;
  word-break: break-all;
}

.provider-field-value a {
  color: var(--color-primary);
  text-decoration: none;
}

.provider-field-value a:hover {
  text-decoration: underline;
}

.provider-card-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1.25rem;
  border-top: 1px solid var(--color-border-light);
  background: var(--color-bg);
}

.provider-models-count {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  display: flex;
  align-items: center;
  gap: 0.375rem;
}

.provider-models-count strong {
  color: var(--color-text);
}

/* --- API Info Page --------------------------------------------------- */
.api-info-page {
  max-width: 860px;
}

.api-info-hero {
  background: linear-gradient(135deg, #6366f1 0%, #8b5cf6 100%);
  border-radius: var(--radius-lg);
  padding: 2rem;
  color: white;
  margin-bottom: 1.5rem;
}

.api-info-hero h3 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.api-info-hero p {
  opacity: 0.85;
  font-size: 0.95rem;
  margin-bottom: 1.25rem;
}

.base-url-box {
  display: flex;
  align-items: center;
  background: rgba(255,255,255,0.15);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  gap: 0.75rem;
}

.base-url-box code {
  flex: 1;
  font-family: var(--font-mono);
  font-size: 0.95rem;
  color: white;
  background: transparent;
  padding: 0;
  overflow-x: auto;
  white-space: nowrap;
}

.copy-btn {
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  color: white;
  padding: 0.375rem 0.75rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.8rem;
  font-weight: 600;
  font-family: var(--font-sans);
  transition: background 0.2s;
  white-space: nowrap;
}

.copy-btn:hover {
  background: rgba(255,255,255,0.3);
}

.copy-btn-dark {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  color: var(--color-text-muted);
  padding: 0.25rem 0.5rem;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 0.75rem;
  font-weight: 600;
  font-family: var(--font-sans);
  transition: all 0.2s;
  white-space: nowrap;
}

.copy-btn-dark:hover {
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-color: var(--color-primary);
}

.openai-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  background: rgba(255,255,255,0.2);
  border: 1px solid rgba(255,255,255,0.3);
  padding: 0.25rem 0.75rem;
  border-radius: 999px;
  font-size: 0.8rem;
  font-weight: 600;
  margin-top: 0.75rem;
}

.endpoints-list {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.endpoint-item {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.875rem 1rem;
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-sm);
  transition: border-color 0.15s;
}

.endpoint-item:hover {
  border-color: var(--color-primary);
}

.endpoint-method {
  font-family: var(--font-mono);
  font-size: 0.75rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  text-transform: uppercase;
  flex-shrink: 0;
}

.endpoint-method.method-post {
  background: #dbeafe;
  color: #2563eb;
}

.endpoint-method.method-get {
  background: #d1fae5;
  color: #059669;
}

.endpoint-path {
  font-family: var(--font-mono);
  font-size: 0.875rem;
  color: var(--color-text);
  flex: 1;
}

.endpoint-desc {
  font-size: 0.8rem;
  color: var(--color-text-muted);
  flex-shrink: 0;
}

.code-block {
  background: #1e293b;
  border-radius: var(--radius-md);
  overflow: hidden;
  margin-bottom: 1rem;
}

.code-block-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.625rem 1rem;
  background: rgba(255,255,255,0.05);
  border-bottom: 1px solid rgba(255,255,255,0.08);
}

.code-block-lang {
  font-size: 0.75rem;
  font-weight: 600;
  color: rgba(255,255,255,0.5);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.code-block-copy {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.15);
  color: rgba(255,255,255,0.7);
  padding: 0.25rem 0.5rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.7rem;
  font-weight: 600;
  font-family: var(--font-sans);
  transition: all 0.15s;
}

.code-block-copy:hover {
  background: rgba(255,255,255,0.2);
  color: white;
}

.code-block pre {
  padding: 1rem;
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  line-height: 1.6;
  color: #e2e8f0;
  margin: 0;
}

.code-block pre code {
  background: transparent;
  padding: 0;
  color: inherit;
  font-size: inherit;
}

/* Inline masked key with copy button */
.key-display {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--color-text-muted);
  background: var(--color-bg);
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
}

/* --- Tables ---------------------------------------------------------- */
.table-wrapper {
  overflow-x: auto;
  border-radius: var(--radius-md);
}

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

table thead {
  background: var(--color-bg);
}

table th {
  padding: 0.75rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--color-text-muted);
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--color-border);
  white-space: nowrap;
}

table td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--color-border-light);
  vertical-align: middle;
}

table tbody tr:hover {
  background: rgba(99,102,241,0.02);
}

table tbody tr:last-child td {
  border-bottom: none;
}

/* --- Status Badges --------------------------------------------------- */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.6rem;
  font-size: 0.75rem;
  font-weight: 600;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-success {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.badge-danger {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.badge-warning {
  background: var(--color-warning-bg);
  color: var(--color-warning);
}

.badge-info {
  background: var(--color-info-bg);
  color: var(--color-info);
}

.badge-neutral {
  background: #f3f4f6;
  color: #6b7280;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  display: inline-block;
}

.badge-success .badge-dot { background: var(--color-success); }
.badge-danger .badge-dot  { background: var(--color-danger); }
.badge-warning .badge-dot { background: var(--color-warning); }

/* --- Status Badge (Pill with dot) ------------------------------------ */
.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.3rem 0.75rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: 999px;
  white-space: nowrap;
}

.status-badge .status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-badge.status-enabled {
  background: var(--color-success-bg);
  color: var(--color-success);
}

.status-badge.status-enabled .status-dot {
  background: var(--color-success);
}

.status-badge.status-disabled {
  background: var(--color-danger-bg);
  color: var(--color-danger);
}

.status-badge.status-disabled .status-dot {
  background: var(--color-danger);
}

/* --- Toolbar (filters) ----------------------------------------------- */
.toolbar {
  display: flex;
  gap: 0.75rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
  align-items: center;
}

.toolbar .form-control {
  width: auto;
  min-width: 160px;
}

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

.modal-backdrop.show {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--color-surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
  transform: translateY(10px);
  transition: transform 0.2s;
}

.modal-backdrop.show .modal {
  transform: translateY(0);
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--color-border-light);
}

.modal-header h3 {
  font-size: 1.1rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--color-text-muted);
  padding: 0.25rem;
  border-radius: var(--radius-sm);
}
.modal-close:hover {
  background: var(--color-bg);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--color-border-light);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* --- Toast Notifications --------------------------------------------- */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.toast {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.85rem;
  font-weight: 500;
  box-shadow: var(--shadow-lg);
  display: flex;
  align-items: center;
  gap: 0.5rem;
  min-width: 280px;
  animation: slideIn 0.3s ease;
}

.toast.toast-success {
  background: #065f46;
  color: white;
}

.toast.toast-error {
  background: #991b1b;
  color: white;
}

.toast.toast-info {
  background: #1e40af;
  color: white;
}

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

/* --- Loading Spinner ------------------------------------------------- */
.spinner {
  display: inline-block;
  width: 20px;
  height: 20px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

.spinner-lg {
  width: 40px;
  height: 40px;
  border-width: 3px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem;
  color: var(--color-text-muted);
  gap: 1rem;
}

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

.empty-state .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 0.75rem;
  opacity: 0.5;
}

.empty-state p {
  font-size: 0.9rem;
  margin-bottom: 1rem;
}

/* --- Code / Mono ----------------------------------------------------- */
code, .mono {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  background: #f1f5f9;
  padding: 0.15em 0.4em;
  border-radius: 4px;
  color: #334155;
}

/* --- Fallback Chain -------------------------------------------------- */
.fallback-chain {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.fallback-node {
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  padding: 0.25rem 0.625rem;
  background: var(--color-primary-light);
  color: var(--color-primary);
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
}

.fallback-arrow {
  color: var(--color-text-light);
  font-size: 0.85rem;
}

/* --- Masked Key ------------------------------------------------------ */
.masked-key {
  font-family: var(--font-mono);
  font-size: 0.82rem;
  color: var(--color-text-muted);
  letter-spacing: 0.05em;
}

/* --- Pagination ------------------------------------------------------ */
.pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  font-size: 0.85rem;
  color: var(--color-text-muted);
}

.pagination-controls {
  display: flex;
  gap: 0.375rem;
}

/* --- Checkbox Toggle ------------------------------------------------- */
.toggle {
  position: relative;
  display: inline-block;
  width: 40px;
  height: 22px;
}

.toggle input {
  opacity: 0;
  width: 0;
  height: 0;
}

.toggle-slider {
  position: absolute;
  inset: 0;
  background: #cbd5e1;
  border-radius: 999px;
  cursor: pointer;
  transition: background 0.2s;
}

.toggle-slider::before {
  content: '';
  position: absolute;
  width: 16px;
  height: 16px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: var(--color-primary);
}

.toggle input:checked + .toggle-slider::before {
  transform: translateX(18px);
}

/* --- Horizontal Bar Chart -------------------------------------------- */
.h-bar-chart {
  display: flex;
  flex-direction: column;
  gap: 0.625rem;
}

.h-bar-row {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.h-bar-label {
  width: 120px;
  font-size: 0.82rem;
  color: var(--color-text-muted);
  text-align: right;
  flex-shrink: 0;
}

.h-bar-track {
  flex: 1;
  height: 24px;
  background: var(--color-bg);
  border-radius: var(--radius-sm);
  overflow: hidden;
}

.h-bar-fill {
  height: 100%;
  background: var(--color-primary);
  border-radius: var(--radius-sm);
  transition: width 0.5s ease;
  min-width: 2px;
}

.h-bar-value {
  width: 50px;
  font-size: 0.82rem;
  font-weight: 600;
  color: var(--color-text);
  flex-shrink: 0;
}

/* --- Add Provider Inline Form ---------------------------------------- */
.add-provider-form-wrapper {
  max-width: 640px;
}

/* --- Utilities ------------------------------------------------------- */
.text-muted   { color: var(--color-text-muted); }
.text-success { color: var(--color-success); }
.text-danger  { color: var(--color-danger); }
.text-warning { color: var(--color-warning); }
.text-primary { color: var(--color-primary); }
.text-sm      { font-size: 0.82rem; }
.text-xs      { font-size: 0.75rem; }
.text-center  { text-align: center; }
.fw-600       { font-weight: 600; }
.mt-1         { margin-top: 0.5rem; }
.mt-2         { margin-top: 1rem; }
.mb-1         { margin-bottom: 0.5rem; }
.mb-2         { margin-bottom: 1rem; }
.gap-1        { gap: 0.5rem; }
.hidden       { display: none !important; }

/* --- Responsive ------------------------------------------------------ */
@media (max-width: 768px) {
  .sidebar {
    transform: translateX(-100%);
  }
  .sidebar.open {
    transform: translateX(0);
  }
  .main-wrapper {
    margin-left: 0;
  }
  .mobile-menu-btn {
    display: block;
  }
  .stats-grid {
    grid-template-columns: 1fr 1fr;
  }
  .provider-cards-grid {
    grid-template-columns: 1fr;
  }
  .form-row {
    flex-direction: column;
    gap: 0;
  }
  .toolbar {
    flex-direction: column;
    align-items: stretch;
  }
  .toolbar .form-control {
    min-width: 100%;
  }
  .page-header {
    flex-direction: column;
    align-items: flex-start;
  }
  .endpoint-item {
    flex-direction: column;
    align-items: flex-start;
    gap: 0.375rem;
  }
  .endpoint-desc {
    font-size: 0.75rem;
  }
}

@media (max-width: 480px) {
  .stats-grid {
    grid-template-columns: 1fr;
  }
  .login-card {
    padding: 1.5rem;
  }
  .page-content {
    padding: 1rem;
  }
  .api-info-hero {
    padding: 1.25rem;
  }
  .base-url-box {
    flex-direction: column;
    align-items: stretch;
  }
  .base-url-box code {
    overflow-x: auto;
  }
}
