:root {
  --bg: #0a0e17;
  --bg-secondary: #0f1520;
  --surface: #141b2a;
  --surface-hover: #1a2236;
  --surface-active: #1e2740;
  --text: #e4e8f1;
  --text-secondary: #8892a8;
  --text-muted: #5a6478;
  --border: #1e2740;
  --border-light: #252f45;
  --accent: #3b82f6;
  --accent-dim: rgba(59, 130, 246, 0.12);
  --accent-glow: rgba(59, 130, 246, 0.25);
  --ok: #10b981;
  --ok-dim: rgba(16, 185, 129, 0.12);
  --warn: #f59e0b;
  --warn-dim: rgba(245, 158, 11, 0.12);
  --danger: #ef4444;
  --danger-dim: rgba(239, 68, 68, 0.12);
  --radius: 12px;
  --radius-sm: 8px;
  --transition: 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html, body {
  min-height: 100vh;
}

body {
  font-family: -apple-system, "PingFang SC", "Microsoft YaHei", "Segoe UI", "Inter", "Helvetica Neue", sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* --- Ambient background --- */
.aurora {
  position: fixed;
  border-radius: 50%;
  filter: blur(100px);
  opacity: 0.07;
  pointer-events: none;
  z-index: 0;
}

.a1 {
  width: 600px;
  height: 600px;
  left: -200px;
  top: -200px;
  background: var(--accent);
}

.a2 {
  width: 500px;
  height: 500px;
  right: -150px;
  top: 30vh;
  background: var(--ok);
}

.a3 {
  width: 450px;
  height: 450px;
  left: 30vw;
  bottom: -200px;
  background: #8b5cf6;
}

/* --- Page layout --- */
.page {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 24px 20px 40px;
}

/* --- Card --- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

/* --- Hero header --- */
.hero {
  padding: 28px 28px 24px;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(135deg, var(--surface) 0%, var(--bg-secondary) 100%);
}

.hero-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 20px;
}

.add-btn {
  flex-shrink: 0;
  height: 40px;
  padding: 0 20px;
  font-size: 14px;
}

.kicker {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 12px;
  padding: 4px 12px;
  border-radius: 999px;
  background: var(--accent-dim);
  border: 1px solid rgba(59, 130, 246, 0.2);
  color: var(--accent);
  font-weight: 600;
  font-size: 12px;
  letter-spacing: 0.5px;
  text-transform: uppercase;
}

h1 {
  font-size: clamp(22px, 3vw, 30px);
  font-weight: 700;
  line-height: 1.3;
  letter-spacing: -0.3px;
  color: var(--text);
}

.subtitle {
  margin-top: 10px;
  color: var(--text-secondary);
  font-size: 14px;
  line-height: 1.7;
}

code {
  font-family: "JetBrains Mono", "Cascadia Mono", "Fira Code", monospace;
  background: var(--accent-dim);
  color: var(--accent);
  padding: 2px 7px;
  border-radius: 5px;
  font-size: 12px;
  border: 1px solid rgba(59, 130, 246, 0.15);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 16px;
  margin-top: 16px;
  color: var(--text-muted);
  font-size: 12px;
}

.dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  margin-right: 6px;
  vertical-align: middle;
}

.dot.green { background: var(--ok); box-shadow: 0 0 8px var(--ok-dim); }
.dot.blue { background: var(--accent); box-shadow: 0 0 8px var(--accent-dim); }
.dot.amber { background: var(--warn); box-shadow: 0 0 8px var(--warn-dim); }

/* --- Panel --- */
.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-secondary);
}

.panel-head h2 {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.badge {
  display: inline-flex;
  align-items: center;
  height: 26px;
  padding: 0 10px;
  border-radius: 999px;
  background: var(--accent-dim);
  border: 1px solid rgba(59, 130, 246, 0.15);
  color: var(--accent);
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.3px;
}

/* --- Modal --- */
.modal-overlay {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0);
  backdrop-filter: blur(0);
  transition: background 0.25s ease, backdrop-filter 0.25s ease;
}

.modal-overlay.visible {
  display: flex;
}

.modal-overlay.open {
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(6px);
}

.modal {
  width: 480px;
  max-width: calc(100vw - 32px);
  max-height: calc(100vh - 64px);
  overflow-y: auto;
  opacity: 0;
  transform: translateY(20px) scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.modal-overlay.open .modal {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.modal-close {
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  border-radius: 50%;
  flex-shrink: 0;
}

/* --- Form --- */
.form {
  padding: 20px;
}

.field {
  display: block;
  margin-bottom: 16px;
}

.field span {
  display: block;
  margin-bottom: 6px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.2px;
}

input[type="text"] {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

input[type="text"]::placeholder {
  color: var(--text-muted);
}

input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

select {
  width: 100%;
  height: 42px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 0 14px;
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  font-family: inherit;
  outline: none;
  cursor: pointer;
  transition: border-color var(--transition), box-shadow var(--transition);
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238892a8' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
}

select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

select option {
  background: var(--surface);
  color: var(--text);
}

.check {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 12px 0;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  padding: 8px 10px;
  border-radius: var(--radius-sm);
  transition: background var(--transition);
}

.check:hover {
  background: var(--surface-hover);
}

.check input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
  flex-shrink: 0;
}

.form-actions {
  display: flex;
  gap: 10px;
  margin-top: 20px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* --- Buttons --- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  height: 36px;
  padding: 0 16px;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  transition: all var(--transition);
  font-family: inherit;
}

.btn:hover {
  transform: translateY(-1px);
}

.btn:active {
  transform: translateY(0);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
  transform: none;
}

.btn.primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 8px var(--accent-dim);
  min-width: 80px;
}

.btn.primary:hover {
  background: #2563eb;
  box-shadow: 0 4px 16px var(--accent-glow);
}

.btn.ghost {
  background: transparent;
  border-color: var(--border-light);
  color: var(--text-secondary);
}

.btn.ghost:hover {
  background: var(--surface-hover);
  color: var(--text);
  border-color: var(--border-light);
}

.btn.soft {
  background: var(--accent-dim);
  border-color: rgba(59, 130, 246, 0.2);
  color: var(--accent);
}

.btn.soft:hover {
  background: rgba(59, 130, 246, 0.18);
}

.btn.danger {
  background: var(--danger-dim);
  border-color: rgba(239, 68, 68, 0.2);
  color: var(--danger);
}

.btn.danger:hover {
  background: rgba(239, 68, 68, 0.18);
}

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

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

th, td {
  text-align: left;
  border-bottom: 1px solid var(--border);
  padding: 12px 14px;
  vertical-align: top;
}

th {
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  background: var(--bg-secondary);
}

tr {
  transition: background var(--transition);
}

tbody tr:hover {
  background: var(--surface-hover);
}

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

.name-cell {
  font-weight: 600;
  color: var(--text);
}

.mono {
  font-family: "JetBrains Mono", "Cascadia Mono", "Fira Code", monospace;
  font-size: 12px;
  word-break: break-all;
  color: var(--text-secondary);
  line-height: 1.8;
}

/* --- Chips --- */
.chip {
  display: inline-flex;
  align-items: center;
  height: 22px;
  border-radius: 999px;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
  letter-spacing: 0.2px;
}

.chip.cache-on {
  background: var(--accent-dim);
  color: var(--accent);
  border: 1px solid rgba(59, 130, 246, 0.2);
}

.chip.cache-off {
  background: rgba(90, 100, 120, 0.1);
  color: var(--text-muted);
  border: 1px solid var(--border);
}

.chip.type-claude {
  background: rgba(139, 92, 246, 0.12);
  color: #a78bfa;
  border: 1px solid rgba(139, 92, 246, 0.2);
}

.chip.type-openai {
  background: rgba(16, 185, 129, 0.12);
  color: var(--ok);
  border: 1px solid rgba(16, 185, 129, 0.2);
}

/* --- Operations --- */
.ops {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.empty {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 12px;
  font-size: 13px;
}

/* --- Toast --- */
.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  min-width: 240px;
  max-width: 380px;
  border-radius: var(--radius);
  padding: 14px 18px;
  background: var(--surface);
  color: var(--text);
  border: 1px solid var(--border-light);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.4);
  opacity: 0;
  transform: translateY(16px) scale(0.96);
  transition: opacity 0.25s ease, transform 0.25s ease;
  pointer-events: none;
  font-size: 13px;
  font-weight: 500;
  z-index: 100;
  backdrop-filter: blur(12px);
}

.toast.show {
  opacity: 1;
  transform: translateY(0) scale(1);
}

.toast.error {
  background: var(--danger-dim);
  border-color: rgba(239, 68, 68, 0.3);
  color: #fca5a5;
}

/* --- Scrollbar --- */
::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--border-light);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: var(--text-muted);
}

/* --- Responsive --- */
@media (max-width: 768px) {
  .hero {
    padding: 20px;
  }

  .hero-top {
    flex-direction: column;
    gap: 16px;
  }

  .add-btn {
    align-self: stretch;
  }

  .page {
    padding: 16px 12px 32px;
  }

  .modal {
    width: 100%;
    max-width: calc(100vw - 24px);
  }
}

/* --- Login Gate --- */
.login-gate {
  position: fixed;
  inset: 0;
  z-index: 200;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  opacity: 1;
  transition: opacity 0.4s ease;
}

.login-gate.hidden {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.35s ease;
}

.login-card {
  width: 420px;
  max-width: calc(100vw - 32px);
  border: 1px solid var(--border-light);
  box-shadow:
    0 0 0 1px rgba(59, 130, 246, 0.05),
    0 8px 40px rgba(0, 0, 0, 0.4),
    0 0 80px -20px rgba(59, 130, 246, 0.12);
  animation: loginCardIn 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;
}

@keyframes loginCardIn {
  from {
    opacity: 0;
    transform: translateY(24px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.login-header {
  padding: 32px 28px 0;
  text-align: center;
}

.login-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border-radius: 16px;
  background: var(--accent-dim);
  border: 1px solid rgba(59, 130, 246, 0.15);
  color: var(--accent);
  margin-bottom: 20px;
}

.login-header .kicker {
  margin-bottom: 10px;
}

.login-header h1 {
  font-size: 22px;
  margin-top: 8px;
}

.login-header .subtitle {
  margin-top: 8px;
  font-size: 13px;
}

/* Input group with toggle */
.input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.input-group input {
  width: 100%;
  height: 44px;
  border: 1px solid var(--border-light);
  border-radius: var(--radius-sm);
  padding: 0 42px 0 14px;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color var(--transition), box-shadow var(--transition);
}

.input-group input::placeholder {
  color: var(--text-muted);
}

.input-group input:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-dim);
}

.input-icon-btn {
  position: absolute;
  right: 4px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border: none;
  border-radius: 6px;
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  transition: color var(--transition), background var(--transition);
}

.input-icon-btn:hover {
  color: var(--text-secondary);
  background: var(--surface-hover);
}

/* Login button */
.login-btn {
  width: 100%;
  height: 44px;
  font-size: 14px;
  gap: 8px;
  position: relative;
}

/* Spinner */
.spinner {
  animation: spin 0.7s linear infinite;
}

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

/* Remember key checkbox */
.remember-key {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-top: 12px;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
  user-select: none;
}

.remember-key input[type="checkbox"] {
  accent-color: var(--primary);
  cursor: pointer;
}

/* Error state */
.login-error {
  margin-top: 12px;
  text-align: center;
  color: var(--danger);
  font-size: 13px;
  font-weight: 500;
  animation: fadeIn 0.25s ease;
}

/* Shake animation for invalid key */
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  15% { transform: translateX(-6px); }
  30% { transform: translateX(5px); }
  45% { transform: translateX(-4px); }
  60% { transform: translateX(3px); }
  75% { transform: translateX(-2px); }
}

.input-group.shake {
  animation: shake 0.45s ease;
}

.input-group.shake input {
  border-color: var(--danger);
  box-shadow: 0 0 0 3px var(--danger-dim);
}

/* --- Animations --- */
@keyframes fadeIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.card {
  animation: fadeIn 0.4s ease both;
}
