/* Bottle Serverless Admin UI - Styles */

:root {
  --color-bg: #0f1117;
  --color-surface: #1a1d27;
  --color-surface-alt: #22263a;
  --color-border: #2e3347;
  --color-primary: #6c63ff;
  --color-primary-hover: #5a52e0;
  --color-success: #22c55e;
  --color-warning: #f59e0b;
  --color-error: #ef4444;
  --color-muted: #6b7280;
  --color-info: #3b82f6;
  --color-text: #e2e8f0;
  --color-text-dim: #94a3b8;
  --radius: 8px;
  --radius-lg: 12px;
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.4);
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  line-height: 1.6;
  min-height: 100vh;
}

/* ============================================================
   Layout
   ============================================================ */

.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

header {
  background: var(--color-surface);
  border-bottom: 1px solid var(--color-border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 60px;
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 {
  font-size: 1.2rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
}

header h1 .logo {
  width: 28px;
  height: 28px;
  background: var(--color-primary);
  border-radius: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
}

.header-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--color-text-dim);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--color-muted);
}

.status-dot.online { background: var(--color-success); }
.status-dot.offline { background: var(--color-error); }

.layout {
  display: flex;
  flex: 1;
}

nav {
  width: 220px;
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  padding: 16px 0;
  position: sticky;
  top: 60px;
  height: calc(100vh - 60px);
  overflow-y: auto;
  flex-shrink: 0;
}

nav ul {
  list-style: none;
}

nav ul li a,
nav ul li button {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 20px;
  color: var(--color-text-dim);
  text-decoration: none;
  font-size: 0.875rem;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  cursor: pointer;
  border-radius: 0;
  transition: background 0.15s, color 0.15s;
}

nav ul li a:hover,
nav ul li button:hover {
  background: var(--color-surface-alt);
  color: var(--color-text);
}

nav ul li a.active,
nav ul li button.active {
  background: rgba(108, 99, 255, 0.15);
  color: var(--color-primary);
}

nav .nav-section {
  padding: 16px 20px 6px;
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--color-muted);
}

main {
  flex: 1;
  padding: 24px;
  max-width: 1200px;
  overflow-y: auto;
}

/* ============================================================
   Panels / Views
   ============================================================ */

.view {
  display: none;
}

.view.active {
  display: block;
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 24px;
}

.view-header h2 {
  font-size: 1.4rem;
  font-weight: 700;
}

/* ============================================================
   Cards & Stats
   ============================================================ */

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

.stat-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 20px;
}

.stat-card .stat-label {
  font-size: 0.75rem;
  color: var(--color-text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}

.stat-card .stat-value {
  font-size: 2rem;
  font-weight: 700;
  line-height: 1;
}

.stat-card .stat-value.success { color: var(--color-success); }
.stat-card .stat-value.error { color: var(--color-error); }
.stat-card .stat-value.warning { color: var(--color-warning); }
.stat-card .stat-value.info { color: var(--color-info); }

/* ============================================================
   Tables
   ============================================================ */

.table-container {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.table-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border-bottom: 1px solid var(--color-border);
}

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

th {
  padding: 12px 16px;
  text-align: left;
  font-weight: 600;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--color-text-dim);
  background: var(--color-surface-alt);
  border-bottom: 1px solid var(--color-border);
}

td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--color-border);
  vertical-align: middle;
}

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

tr:hover td {
  background: rgba(255, 255, 255, 0.02);
}

.cell-mono {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.8rem;
  color: var(--color-text-dim);
}

.table-pagination {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-top: 1px solid var(--color-border);
  font-size: 0.8rem;
  color: var(--color-text-dim);
}

/* ============================================================
   Badges / Pills
   ============================================================ */

.badge {
  display: inline-flex;
  align-items: center;
  padding: 2px 10px;
  border-radius: 100px;
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.badge-success { background: rgba(34, 197, 94, 0.15); color: var(--color-success); }
.badge-error { background: rgba(239, 68, 68, 0.15); color: var(--color-error); }
.badge-warning { background: rgba(245, 158, 11, 0.15); color: var(--color-warning); }
.badge-info { background: rgba(59, 130, 246, 0.15); color: var(--color-info); }
.badge-muted { background: rgba(107, 114, 128, 0.15); color: var(--color-muted); }

/* ============================================================
   Buttons
   ============================================================ */

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: var(--radius);
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  text-decoration: none;
}

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

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

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

.btn-secondary {
  background: var(--color-surface-alt);
  color: var(--color-text);
  border-color: var(--color-border);
}

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

.btn-danger {
  background: rgba(239, 68, 68, 0.15);
  color: var(--color-error);
  border-color: rgba(239, 68, 68, 0.3);
}

.btn-danger:hover:not(:disabled) {
  background: rgba(239, 68, 68, 0.25);
}

.btn-sm {
  padding: 4px 10px;
  font-size: 0.75rem;
}

/* ============================================================
   Forms
   ============================================================ */

.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--color-text-dim);
  margin-bottom: 6px;
}

.form-control {
  width: 100%;
  padding: 9px 12px;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  color: var(--color-text);
  font-size: 0.875rem;
  transition: border-color 0.15s;
}

.form-control:focus {
  outline: none;
  border-color: var(--color-primary);
}

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

select.form-control {
  cursor: pointer;
}

/* ============================================================
   Modal
   ============================================================ */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
}

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

.modal {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 28px;
  width: 100%;
  max-width: 520px;
  box-shadow: var(--shadow);
}

.modal h3 {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 20px;
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
  margin-top: 24px;
}

/* ============================================================
   Toast
   ============================================================ */

#toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.toast {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 12px 18px;
  font-size: 0.875rem;
  box-shadow: var(--shadow);
  animation: slideIn 0.2s ease;
  max-width: 360px;
}

.toast.success { border-left: 3px solid var(--color-success); }
.toast.error { border-left: 3px solid var(--color-error); }
.toast.info { border-left: 3px solid var(--color-info); }

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

/* ============================================================
   Detail Panel
   ============================================================ */

.detail-card {
  background: var(--color-surface);
  border: 1px solid var(--color-border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin-bottom: 16px;
}

.detail-card h3 {
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--color-text-dim);
  margin-bottom: 14px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.detail-row {
  display: flex;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 0.875rem;
}

.detail-row .key {
  width: 140px;
  flex-shrink: 0;
  color: var(--color-text-dim);
}

.detail-row .value {
  word-break: break-all;
}

pre.json-viewer {
  background: var(--color-bg);
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  padding: 14px;
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 0.78rem;
  color: var(--color-text-dim);
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin-top: 8px;
}

/* ============================================================
   Empty state
   ============================================================ */

.empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--color-text-dim);
}

.empty-state .empty-icon {
  font-size: 2.5rem;
  margin-bottom: 14px;
  opacity: 0.4;
}

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

/* ============================================================
   Loading
   ============================================================ */

.loading {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid var(--color-border);
  border-top-color: var(--color-primary);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}

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

/* ============================================================
   Toggle
   ============================================================ */

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

.toggle input { display: none; }

.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--color-surface-alt);
  border: 1px solid var(--color-border);
  border-radius: 100px;
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.toggle-slider::before {
  content: "";
  position: absolute;
  left: 3px;
  top: 50%;
  transform: translateY(-50%);
  width: 14px;
  height: 14px;
  background: var(--color-text-dim);
  border-radius: 50%;
  transition: transform 0.2s, background 0.2s;
}

.toggle input:checked + .toggle-slider {
  background: rgba(108, 99, 255, 0.3);
  border-color: var(--color-primary);
}

.toggle input:checked + .toggle-slider::before {
  transform: translate(18px, -50%);
  background: var(--color-primary);
}

/* ============================================================
   Key-Value Rows (modals)
   ============================================================ */

.kv-row {
  display: flex;
  gap: 8px;
  margin-bottom: 6px;
  align-items: center;
}

.kv-row .kv-name {
  flex: 2;
}

.kv-row .kv-value {
  flex: 3;
}

.kv-row .kv-remove {
  flex-shrink: 0;
  padding: 4px 8px;
  font-size: 1rem;
  line-height: 1;
}

/* ============================================================
   Responsive
   ============================================================ */

@media (max-width: 768px) {
  nav {
    display: none;
  }

  main {
    padding: 16px;
  }

  .stats-grid {
    grid-template-columns: repeat(2, 1fr);
  }
}
