* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --primary: #6c5ce7;
  --primary-dark: #5a4bd1;
  --success: #00b894;
  --warning: #fdcb6e;
  --danger: #e17055;
  --info: #74b9ff;
  --bg: #0f0f23;
  --bg-card: #1a1a2e;
  --bg-input: #16213e;
  --text: #f0f0f0;
  --text-muted: #a0a0b0;
  --border: #2d2d44;
  --radius: 12px;
}

body {
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

.container {
  max-width: 900px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
}

/* Header */
header {
  text-align: center;
  margin-bottom: 2.5rem;
  position: relative;
}

header h1 {
  font-size: 2rem;
  background: linear-gradient(135deg, var(--primary), #a29bfe);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  margin-bottom: 0.5rem;
}

.subtitle {
  color: var(--text-muted);
  font-size: 1rem;
}

.back-link {
  display: inline-block;
  margin-top: 0.75rem;
  color: var(--primary);
  text-decoration: none;
  font-size: 0.85rem;
  transition: opacity 0.2s;
}

.back-link:hover {
  opacity: 0.8;
}

/* Stats Grid */
.stats-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-top: 1rem;
}

.stat-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  text-align: center;
}

.stat-value {
  display: block;
  font-size: 1.8rem;
  font-weight: 700;
  color: var(--text);
}

.stat-label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
}

.stat-active .stat-value { color: var(--success); }
.stat-disabled .stat-value { color: var(--danger); }
.stat-current .stat-value { color: var(--info); font-size: 1.4rem; }

/* Sections */
section {
  margin-bottom: 2rem;
}

section h2 {
  font-size: 1.2rem;
  margin-bottom: 1rem;
}

/* Settings */
.settings-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--border);
}

.setting-row:last-of-type {
  border-bottom: none;
  margin-bottom: 1rem;
}

.setting-info label {
  font-weight: 600;
  font-size: 0.9rem;
  display: block;
  margin-bottom: 0;
}

.setting-info small {
  color: var(--text-muted);
  font-size: 0.75rem;
}

.setting-input {
  width: 120px;
  padding: 0.5rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: 0.9rem;
}

.setting-input:focus {
  outline: none;
  border-color: var(--primary);
}

/* Toggle Switch */
.toggle-switch {
  position: relative;
}

.toggle-switch input {
  display: none;
}

.toggle-label {
  display: block;
  width: 48px;
  height: 26px;
  background: var(--border);
  border-radius: 13px;
  cursor: pointer;
  position: relative;
  transition: background 0.3s;
}

.toggle-label::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  transition: transform 0.3s;
}

.toggle-switch input:checked + .toggle-label {
  background: var(--success);
}

.toggle-switch input:checked + .toggle-label::after {
  transform: translateX(22px);
}

/* Add Key Section */
.add-key-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.add-key-form {
  margin-bottom: 1.5rem;
}

.form-group {
  margin-bottom: 1rem;
}

.form-group label {
  display: block;
  font-weight: 600;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
}

.required {
  color: var(--danger);
}

input, textarea, select {
  width: 100%;
  padding: 0.75rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.95rem;
  transition: border-color 0.2s;
}

input:focus, textarea:focus, select:focus {
  outline: none;
  border-color: var(--primary);
}

textarea {
  resize: vertical;
  font-family: "Courier New", monospace;
}

.key-input-wrapper {
  position: relative;
  display: flex;
  gap: 0.5rem;
}

.key-input-wrapper input {
  flex: 1;
  font-family: "Courier New", monospace;
}

.btn-toggle-visibility {
  padding: 0.5rem 0.75rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  transition: background 0.2s;
}

.btn-toggle-visibility:hover {
  background: var(--border);
}

.divider-text {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  position: relative;
}

.divider-text::before,
.divider-text::after {
  content: "";
  position: absolute;
  top: 50%;
  width: 30%;
  height: 1px;
  background: var(--border);
}

.divider-text::before { left: 0; }
.divider-text::after { right: 0; }

/* Buttons */
.btn-primary {
  width: 100%;
  padding: 0.75rem;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.1s, opacity 0.2s;
}

.btn-primary:hover {
  transform: translateY(-1px);
  opacity: 0.95;
}

.btn-secondary {
  padding: 0.5rem 1rem;
  background: var(--bg-input);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-secondary:hover {
  background: var(--border);
}

.btn-sm {
  padding: 0.4rem 0.8rem;
  font-size: 0.8rem;
}

.btn-danger {
  border-color: rgba(225, 112, 85, 0.3);
  color: var(--danger);
}

.btn-danger:hover {
  background: rgba(225, 112, 85, 0.1);
}

/* Keys Toolbar */
.keys-toolbar {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
  flex-wrap: wrap;
}

/* Keys List */
.keys-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.key-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1rem 1.25rem;
  display: flex;
  align-items: center;
  gap: 1rem;
  transition: border-color 0.2s;
}

.key-card:hover {
  border-color: rgba(108, 92, 231, 0.4);
}

.key-card.active {
  border-color: rgba(0, 184, 148, 0.4);
}

.key-card.disabled {
  border-color: rgba(225, 112, 85, 0.3);
  opacity: 0.7;
}

.key-card.current {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.key-index {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-input);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 0.85rem;
  flex-shrink: 0;
}

.key-card.current .key-index {
  background: var(--primary);
  color: white;
}

.key-info {
  flex: 1;
  min-width: 0;
}

.key-name {
  font-size: 0.85rem;
  font-weight: 600;
  margin-bottom: 0.15rem;
}

.key-value {
  font-family: "Courier New", monospace;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.key-meta {
  font-size: 0.7rem;
  color: var(--text-muted);
  margin-top: 0.2rem;
}

.key-status {
  padding: 0.2rem 0.6rem;
  border-radius: 6px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  white-space: nowrap;
}

.key-status.active {
  background: rgba(0, 184, 148, 0.15);
  color: var(--success);
}

.key-status.disabled {
  background: rgba(225, 112, 85, 0.15);
  color: var(--danger);
}

.key-status.testing {
  background: rgba(116, 185, 255, 0.15);
  color: var(--info);
}

.key-actions {
  display: flex;
  gap: 0.4rem;
  flex-shrink: 0;
}

.key-actions button {
  width: 30px;
  height: 30px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg-input);
  color: var(--text);
  cursor: pointer;
  font-size: 0.8rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.key-actions button:hover {
  background: var(--border);
}

.key-actions button.btn-delete:hover {
  background: rgba(225, 112, 85, 0.2);
  border-color: var(--danger);
}

/* Activity Log */
.log-toolbar {
  margin-bottom: 0.75rem;
}

.activity-log {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  max-height: 300px;
  overflow-y: auto;
  font-family: "Courier New", monospace;
  font-size: 0.8rem;
}

.log-entry {
  padding: 0.4rem 0;
  border-bottom: 1px solid rgba(45, 45, 68, 0.5);
  display: flex;
  gap: 0.75rem;
}

.log-entry:last-child {
  border-bottom: none;
}

.log-time {
  color: var(--text-muted);
  white-space: nowrap;
  font-size: 0.7rem;
}

.log-message {
  flex: 1;
}

.log-message.success { color: var(--success); }
.log-message.error { color: var(--danger); }
.log-message.warning { color: var(--warning); }
.log-message.info { color: var(--info); }

.empty-state {
  text-align: center;
  color: var(--text-muted);
  padding: 2rem;
  font-style: italic;
}

/* Footer */
footer {
  text-align: center;
  padding-top: 2rem;
  border-top: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 0.85rem;
}

/* Toast Notification */
.toast {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  padding: 0.75rem 1.25rem;
  border-radius: 8px;
  font-size: 0.9rem;
  font-weight: 500;
  z-index: 1000;
  animation: slideIn 0.3s ease;
  max-width: 350px;
}

.toast.success {
  background: rgba(0, 184, 148, 0.9);
  color: white;
}

.toast.error {
  background: rgba(225, 112, 85, 0.9);
  color: white;
}

.toast.info {
  background: rgba(108, 92, 231, 0.9);
  color: white;
}

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* Responsive */
@media (max-width: 600px) {
  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .key-card {
    flex-wrap: wrap;
  }

  .key-actions {
    width: 100%;
    justify-content: flex-end;
    margin-top: 0.5rem;
  }

  .container {
    padding: 1rem;
  }

  header h1 {
    font-size: 1.5rem;
  }
}
