:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #242836;
  --border: #2e3345;
  --text: #e8eaf0;
  --text-muted: #8b90a0;
  --accent: #c9a96e;
  --accent-hover: #dbb97e;
  --danger: #e05c5c;
  --success: #5cc98a;
  --radius: 8px;
  --font: 'Segoe UI', system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.hidden { display: none !important; }

.screen { min-height: 100vh; }

.login-card {
  max-width: 400px;
  margin: 15vh auto;
  padding: 2.5rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.login-card h1 {
  font-size: 2rem;
  color: var(--accent);
  margin-bottom: 0.25rem;
}

.subtitle {
  color: var(--text-muted);
  margin-bottom: 2rem;
}

.login-card label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin: 1rem 0 0.4rem;
}

.login-card input {
  width: 100%;
  padding: 0.65rem 0.85rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 1rem;
}

.login-card button {
  width: 100%;
  margin-top: 1rem;
  padding: 0.7rem;
  background: var(--accent);
  color: #1a1208;
  border: none;
  border-radius: var(--radius);
  font-weight: 600;
  cursor: pointer;
  font-size: 0.95rem;
}

.login-card button:hover { background: var(--accent-hover); }

.message { margin-top: 1rem; font-size: 0.9rem; color: var(--text-muted); }
.message.error { color: var(--danger); }
.message.success { color: var(--success); }

.topbar {
  display: flex;
  align-items: center;
  gap: 2rem;
  padding: 0 1.5rem;
  height: 56px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}

.brand {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
}

.nav-tabs { display: flex; gap: 0.25rem; flex: 1; }

.tab {
  padding: 0.5rem 1rem;
  background: none;
  border: none;
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--radius);
  font-size: 0.9rem;
}

.tab:hover { color: var(--text); background: var(--surface-2); }
.tab.active { color: var(--accent); background: var(--surface-2); }

.user-info {
  display: flex;
  align-items: center;
  gap: 1rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

#logout-btn {
  padding: 0.35rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.85rem;
}

.main-content { padding: 1.5rem; max-width: 1400px; margin: 0 auto; }

.view-header {
  display: flex;
  align-items: center;
  gap: 1rem;
  margin-bottom: 1.5rem;
}

.view-header h2 { flex: 1; }

select {
  padding: 0.5rem 0.75rem;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
}

.btn-primary, .btn-secondary {
  padding: 0.5rem 1rem;
  border: none;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 0.9rem;
  font-weight: 500;
}

.btn-primary { background: var(--accent); color: #1a1208; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-secondary { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }

.btn-sm {
  padding: 0.35rem 0.65rem;
  font-size: 0.8rem;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
}

.site-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  cursor: pointer;
  transition: border-color 0.15s;
}

.site-card:hover { border-color: var(--accent); }
.site-card.selected { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }

.site-card h3 { margin-bottom: 0.25rem; }
.site-card .domain { color: var(--text-muted); font-size: 0.85rem; }
.site-card .sso-open-btn {
  margin-top: 0;
  width: 100%;
  font-size: 0.85rem;
}
.site-card-actions {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-top: 0.75rem;
}
.site-card .api-health {
  display: inline-block;
  margin-left: 0.4rem;
  margin-top: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  text-transform: uppercase;
}
.api-health.up { background: rgba(92, 201, 138, 0.15); color: var(--success); }
.api-health.down { background: rgba(224, 92, 92, 0.15); color: var(--danger); }
.api-health.degraded { background: rgba(201, 169, 110, 0.18); color: var(--accent); }
.api-health.unknown,
.api-health.skipped,
.api-health.unconfigured { background: rgba(139, 144, 160, 0.15); color: var(--text-muted); }
.site-card .status {
  display: inline-block;
  margin-top: 0.75rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.75rem;
  text-transform: uppercase;
}
.status.active { background: rgba(92, 201, 138, 0.15); color: var(--success); }
.status.draft { background: rgba(139, 144, 160, 0.15); color: var(--text-muted); }

.sitemap-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.sitemap-panel h3 { margin-bottom: 0.75rem; font-size: 0.95rem; }

#sitemap-editor textarea {
  width: 100%;
  height: 120px;
  padding: 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: monospace;
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
}

.result-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  font-size: 0.8rem;
  font-family: monospace;
  white-space: pre-wrap;
  max-height: 400px;
  overflow-y: auto;
  color: var(--text-muted);
}

.deploy-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.deploy-panel p { color: var(--text-muted); margin-bottom: 1rem; }

/* Versions */
.versions-layout {
  display: grid;
  grid-template-columns: 280px 1fr;
  gap: 1rem;
  margin-bottom: 1.5rem;
  align-items: start;
}

.versions-sidebar,
.create-version-panel,
.version-detail {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.75rem;
}

.panel-header h3,
.create-version-panel h3,
.version-detail h3 {
  font-size: 0.95rem;
}

.live-badge {
  font-size: 0.7rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  background: rgba(92, 201, 138, 0.15);
  color: var(--success);
  text-transform: uppercase;
}

.versions-list { display: flex; flex-direction: column; gap: 0.35rem; }

.version-card {
  padding: 0.65rem 0.75rem;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s;
}

.version-card:hover { border-color: var(--accent); }
.version-card.active { border-color: var(--accent); background: var(--surface-2); }
.version-card.is-live { border-color: var(--success); }

.version-card .v-num { font-weight: 600; color: var(--accent); }
.version-card .v-notes {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.25rem;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.version-card .v-meta { font-size: 0.7rem; color: var(--text-muted); margin-top: 0.35rem; }

.versions-main { display: flex; flex-direction: column; gap: 1rem; }

.create-version-panel label,
.version-detail label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0.75rem 0 0.35rem;
}

.create-version-panel textarea,
.version-detail textarea {
  width: 100%;
  padding: 0.65rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 0.9rem;
  resize: vertical;
}

.hidden-input {
  position: absolute;
  width: 0;
  height: 0;
  opacity: 0;
  pointer-events: none;
}

.upload-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0.25rem 0 0.5rem;
  line-height: 1.4;
}

.upload-hint code {
  font-size: 0.75rem;
  color: var(--accent);
}

.version-dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.25rem 1rem;
  text-align: center;
  background: var(--bg);
  transition: border-color 0.15s, background 0.15s;
  cursor: pointer;
}

.version-dropzone:focus {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.version-dropzone.is-dragover {
  border-color: var(--accent);
  background: var(--surface-2);
}

.dropzone-title {
  margin: 0;
  font-weight: 600;
  color: var(--text);
}

.dropzone-sub {
  margin: 0.5rem 0;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.dropzone-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: center;
  flex-wrap: wrap;
}

.file-names-list {
  list-style: none;
  margin: 0.75rem 0 0;
  padding: 0;
  max-height: 12rem;
  overflow-y: auto;
  font-family: ui-monospace, monospace;
  font-size: 0.75rem;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.file-names-list li {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid var(--border);
}

.file-names-list li:last-child {
  border-bottom: none;
}

.file-names-list .empty {
  padding: 0.5rem;
  font-style: italic;
}

.version-detail-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.5rem;
}

.files-heading {
  margin: 1rem 0 0.5rem;
  font-size: 0.85rem;
  color: var(--text-muted);
}

.version-files-list {
  list-style: none;
  font-family: monospace;
  font-size: 0.85rem;
}

.version-files-list li {
  padding: 0.35rem 0;
  border-bottom: 1px solid var(--border);
  color: var(--text-muted);
}

.version-files-list li:last-child { border-bottom: none; }

/* Users */
.users-layout {
  display: grid;
  grid-template-columns: 320px 1fr;
  gap: 1rem;
  align-items: start;
}

.users-list { display: flex; flex-direction: column; gap: 0.35rem; }

.user-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0.75rem 1rem;
  cursor: pointer;
}

.user-card:hover { border-color: var(--accent); }
.user-card.active { border-color: var(--accent); background: var(--surface-2); }
.user-card .u-name { font-weight: 600; }
.user-card .u-email { font-size: 0.8rem; color: var(--text-muted); }
.user-card .u-role {
  display: inline-block;
  margin-top: 0.4rem;
  font-size: 0.7rem;
  padding: 0.15rem 0.4rem;
  border-radius: 4px;
  background: var(--surface-2);
  color: var(--text-muted);
  text-transform: uppercase;
}
.user-card .u-sites { font-size: 0.75rem; color: var(--text-muted); margin-top: 0.35rem; }

.user-editor {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
}

.user-editor h3 { margin-bottom: 1rem; }
.user-editor label {
  display: block;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin: 0.75rem 0 0.35rem;
}

.user-editor input,
.user-editor select {
  width: 100%;
  padding: 0.55rem 0.75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 0.9rem;
}

.user-editor input:disabled { opacity: 0.6; }

.site-checkboxes {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  margin-top: 0.35rem;
  max-height: 200px;
  overflow-y: auto;
  padding: 0.5rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}

.site-checkboxes label {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin: 0;
  font-size: 0.85rem;
  color: var(--text);
  cursor: pointer;
}

.user-editor-actions { display: flex; gap: 0.75rem; margin-top: 1.25rem; }
