*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
.hidden { display: none !important; }

:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface-2: #22253a;
  --border: #2e3148;
  --text: #e2e6f0;
  --text-muted: #7b82a0;
  --primary: #6c63ff;
  --primary-hover: #5a52e0;
  --success: #22c55e;
  --warning: #f59e0b;
  --danger: #ef4444;
  --danger-hover: #dc2626;
  --radius: 8px;
  --shadow: 0 4px 24px rgba(0,0,0,0.4);
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  min-height: 100vh;
}

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 100;
}
.header-inner {
  max-width: 1100px;
  margin: 0 auto;
  padding: 14px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
}
.header-brand { display: flex; align-items: center; gap: 10px; }
.header-icon { font-size: 20px; }
.header-title { font-size: 18px; font-weight: 600; letter-spacing: -0.3px; }

/* Main */
.main {
  max-width: 1100px;
  margin: 0 auto;
  padding: 32px 24px;
}

.env-list-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
}
.section-title { font-size: 16px; font-weight: 600; }
.env-count {
  display: inline-block;
  background: var(--surface-2);
  color: var(--text-muted);
  border-radius: 12px;
  padding: 1px 8px;
  font-size: 12px;
  margin-left: 8px;
}
.docker-status { font-size: 12px; color: var(--text-muted); }
.docker-status.ok { color: var(--success); }
.docker-status.degraded { color: var(--danger); }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border: none;
  border-radius: var(--radius);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--primary-hover); }
.btn-ghost { background: var(--surface-2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover:not(:disabled) { background: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-sm { padding: 4px 10px; font-size: 12px; }

/* Table */
.env-table-wrap { overflow-x: auto; }
.env-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}
.env-table th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}
.env-table td {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.env-table tr:last-child td { border-bottom: none; }
.env-table tr:hover td { background: rgba(108,99,255,0.04); }

.env-name { font-weight: 600; }
.env-meta { color: var(--text-muted); font-size: 12px; }
.env-url a { color: var(--primary); text-decoration: none; font-size: 12px; }
.env-url a:hover { text-decoration: underline; }

/* Actions */
.actions { display: flex; gap: 6px; align-items: center; }

/* Actions dropdown */
.action-dropdown { position: relative; display: inline-block; }
.action-toggle {
  background: var(--surface-2);
  border: 1px solid var(--border);
  color: var(--text);
  border-radius: var(--radius);
  padding: 4px 10px;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
  letter-spacing: 1px;
}
.action-toggle:hover { border-color: var(--primary); color: var(--primary); }
.action-menu {
  display: none;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  min-width: 148px;
  z-index: 9000;
  overflow: hidden;
}
.action-menu.open { display: block; }
.action-menu-item {
  display: block;
  width: 100%;
  padding: 9px 14px;
  text-align: left;
  background: none;
  border: none;
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  white-space: nowrap;
}
.action-menu-item:hover { background: var(--surface-2); }
.action-menu-item.danger { color: var(--danger); }
.action-menu-divider { height: 1px; background: var(--border); margin: 3px 0; }

/* Searchable branch select */
.branch-select-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  width: 130px;
  padding: 6px 10px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-size: 13px;
  cursor: pointer;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
}
.branch-select-btn:hover { border-color: var(--primary); }
.branch-select-btn .arrow { opacity: 0.5; font-size: 10px; flex-shrink: 0; }
.branch-dropdown-portal {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  z-index: 9999;
  width: 220px;
  overflow: hidden;
}
.branch-dropdown-portal .branch-search-input {
  width: 100%;
  padding: 8px 12px;
  background: var(--surface-2);
  border: none;
  border-bottom: 1px solid var(--border);
  color: var(--text);
  font-size: 13px;
  outline: none;
}
.branch-dropdown-portal ul {
  list-style: none;
  max-height: 200px;
  overflow-y: auto;
  margin: 0;
  padding: 4px 0;
}
.branch-dropdown-portal li {
  padding: 7px 14px;
  cursor: pointer;
  font-size: 13px;
}
.branch-dropdown-portal li:hover { background: var(--surface-2); }
.branch-dropdown-portal li.selected { color: var(--primary); font-weight: 600; }

/* GitHub repo suggestions portal */
.repo-suggestions-portal {
  position: fixed;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  list-style: none;
  padding: 4px 0;
  z-index: 9999;
  max-height: 220px;
  overflow-y: auto;
  box-shadow: var(--shadow);
  min-width: 280px;
}
.repo-suggestions-portal li {
  padding: 8px 14px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
}
.repo-suggestions-portal li:last-child { border-bottom: none; }
.repo-suggestions-portal li:hover { background: var(--surface-2); }

/* Status badge */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.4px;
}
.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
}
.badge-running { background: rgba(34,197,94,0.12); color: var(--success); }
.badge-running .badge-dot { background: var(--success); animation: pulse 2s infinite; }
.badge-stopped { background: rgba(123,130,160,0.12); color: var(--text-muted); }
.badge-stopped .badge-dot { background: var(--text-muted); }
.badge-error { background: rgba(239,68,68,0.12); color: var(--danger); }
.badge-error .badge-dot { background: var(--danger); }
.badge-creating { background: rgba(245,158,11,0.12); color: var(--warning); }
.badge-creating .badge-dot { background: var(--warning); animation: pulse 1s infinite; }
.badge-deleting { background: rgba(239,68,68,0.07); color: var(--danger); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Empty state */
.empty-state {
  text-align: center;
  padding: 64px 24px;
  color: var(--text-muted);
}
.empty-state-icon { font-size: 48px; margin-bottom: 16px; }
.empty-state h3 { font-size: 18px; color: var(--text); margin-bottom: 8px; }
.empty-state p { margin-bottom: 24px; }

/* Loading */
.loading { color: var(--text-muted); padding: 40px 0; text-align: center; }

/* Modal */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 500;
  padding: 20px;
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow);
}
.modal-sm { max-width: 420px; }
.modal-wide { max-width: 780px; }
.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px 0;
  margin-bottom: 20px;
}
.modal-header h2 { font-size: 16px; font-weight: 600; }
.modal-close {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
  padding: 4px;
}
.modal-close:hover { color: var(--text); }
.modal-body { padding: 0 24px 24px; }

/* Form */
.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 6px;
}
.form-group input[type="text"],
.form-group select {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.form-group input:focus,
.form-group select:focus { border-color: var(--primary); }
.form-group small { display: block; color: var(--text-muted); font-size: 11px; margin-top: 4px; }
.optional { font-weight: 400; color: var(--text-muted); }

.radio-group { display: flex; flex-direction: column; gap: 8px; }
.radio-option {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  cursor: pointer;
  transition: border-color 0.15s;
}
.radio-option:has(input:checked) { border-color: var(--primary); }
.radio-option input { accent-color: var(--primary); }

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

/* Delete confirm input */
.delete-confirm-input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 9px 12px;
  font-size: 14px;
  outline: none;
  margin-top: 12px;
  transition: border-color 0.15s;
}
.delete-confirm-input:focus { border-color: var(--danger); }

/* Log output */
.log-output {
  background: #0a0c12;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: #a8b2c8;
  font-family: 'Menlo', 'Consolas', monospace;
  font-size: 12px;
  line-height: 1.6;
  padding: 16px;
  max-height: 60vh;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
}

/* Progress bar (SSE creation) */
.progress-wrap { margin-bottom: 20px; }
.progress-steps { list-style: none; display: flex; flex-direction: column; gap: 10px; }
.progress-step {
  display: flex;
  align-items: center;
  gap: 12px;
  font-size: 13px;
}
.step-icon { width: 20px; text-align: center; }
.step-pending { color: var(--text-muted); }
.step-active { color: var(--warning); }
.step-done { color: var(--success); }
.step-error { color: var(--danger); }

/* Toast */
.toast-container {
  position: fixed;
  bottom: 24px;
  right: 24px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  z-index: 1000;
}
.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 16px;
  min-width: 260px;
  max-width: 380px;
  box-shadow: var(--shadow);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  animation: slideIn 0.2s ease;
}
.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--primary); }
.toast-icon { font-size: 16px; flex-shrink: 0; margin-top: 1px; }
.toast-msg { flex: 1; font-size: 13px; }
.toast-close { background: none; border: none; color: var(--text-muted); cursor: pointer; font-size: 16px; padding: 0; }
@keyframes slideIn {
  from { transform: translateX(40px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* Plugin rows in create form */
.plugin-input-header {
  display: flex;
  gap: 8px;
  margin-bottom: 4px;
  padding: 0 2px;
}
.plugin-col-label {
  font-size: 11px;
  color: var(--text-muted);
  flex: 1;
}
.plugin-col-label:last-child { flex: 0 0 110px; }

.plugin-row { margin-bottom: 6px; }
.plugin-row-fields {
  display: flex;
  gap: 8px;
  align-items: center;
}
.plugin-row-fields input[type="text"] {
  flex: 1;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
  transition: border-color 0.15s;
}
.plugin-row-fields input[type="text"]:focus { border-color: var(--primary); }
.btn-remove-plugin {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 14px;
  cursor: pointer;
  padding: 6px;
  line-height: 1;
  flex-shrink: 0;
}
.btn-remove-plugin:hover { color: var(--danger); }

/* Plugin badge in env table */
.plugin-badge {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 600;
  padding: 3px 10px;
  cursor: pointer;
  transition: border-color 0.15s, color 0.15s;
}
.plugin-badge:hover { border-color: var(--primary); color: var(--primary); }

.php-version-select {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--text);
  font-size: 11px;
  padding: 2px 4px;
  cursor: pointer;
}

/* Plugin list in manage modal */
.plugin-list-row {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 12px 14px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.plugin-list-info {
  width: 100%;
  min-width: 0;
}
.plugin-list-info .env-name {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-size: 13px;
  font-weight: 600;
  color: var(--text);
  margin-bottom: 2px;
}
.plugin-list-info .env-meta {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.plugin-list-actions {
  display: flex;
  gap: 6px;
  align-items: center;
}
.plugin-list-actions .branch-select-btn {
  flex: 1;
  width: auto;
  min-width: 0;
  max-width: 280px;
}

.plugin-add-row {
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
}

/* ── Auth pages ─────────────────────────────────────────────────────── */
.auth-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 20px;
}
.auth-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow);
}
.auth-logo { font-size: 36px; text-align: center; margin-bottom: 12px; }
.auth-title { font-size: 22px; font-weight: 700; text-align: center; margin-bottom: 6px; }
.auth-subtitle { color: var(--text-muted); text-align: center; margin-bottom: 28px; font-size: 14px; }
.auth-form .form-group { margin-bottom: 16px; }
.auth-form .form-group input {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 10px 14px;
  font-size: 14px;
  outline: none;
  transition: border-color 0.15s;
}
.auth-form .form-group input:focus { border-color: var(--primary); }
.auth-error {
  color: var(--danger);
  font-size: 13px;
  min-height: 18px;
  margin-bottom: 12px;
}
.btn-block { width: 100%; justify-content: center; padding: 11px; font-size: 15px; }

/* ── Header right ───────────────────────────────────────────────────── */
.header-right { display: flex; align-items: center; gap: 12px; }

/* ── User menu ──────────────────────────────────────────────────────── */
.user-menu { position: relative; }
.user-menu-trigger {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  padding: 6px 10px;
  border-radius: var(--radius);
  transition: background 0.15s;
}
.user-menu-trigger:hover { background: var(--surface-2); }
.user-avatar {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
}
.user-info { display: flex; flex-direction: column; line-height: 1.2; }
.user-name { font-size: 13px; font-weight: 600; }
.user-role { font-size: 11px; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.4px; }
.user-chevron { color: var(--text-muted); font-size: 12px; }
.user-dropdown {
  position: absolute;
  top: calc(100% + 6px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  min-width: 180px;
  box-shadow: var(--shadow);
  z-index: 200;
  overflow: hidden;
}
.dropdown-item {
  padding: 10px 14px;
  font-size: 13px;
  cursor: pointer;
  transition: background 0.12s;
}
.dropdown-item:hover { background: var(--surface-2); }
.dropdown-item-danger { color: var(--danger); }
.dropdown-item-danger:hover { background: rgba(239,68,68,0.1); }
.dropdown-divider { height: 1px; background: var(--border); margin: 4px 0; }

/* ── Side panel (user management) ──────────────────────────────────── */
.side-panel {
  position: fixed;
  top: 0;
  right: 0;
  width: 480px;
  max-width: 95vw;
  height: 100vh;
  background: var(--surface);
  border-left: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  z-index: 300;
  box-shadow: -4px 0 24px rgba(0,0,0,0.4);
}
.side-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 20px 24px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.side-panel-header h2 { font-size: 16px; font-weight: 600; }
.side-panel-body { flex: 1; overflow-y: auto; padding: 20px 24px; }

/* ── User list rows ─────────────────────────────────────────────────── */
.user-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 8px;
}
.user-row-info { flex: 1; min-width: 0; }
.user-row-actions { display: flex; gap: 6px; flex-shrink: 0; }

.role-badge { font-weight: 600; font-size: 11px; text-transform: uppercase; letter-spacing: 0.4px; }
.role-admin     { color: var(--primary); }
.role-developer { color: var(--success); }
.role-viewer    { color: var(--warning); }

.badge-self {
  display: inline-block;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 1px 6px;
  font-size: 10px;
  color: var(--text-muted);
  font-weight: 400;
  margin-left: 6px;
}

/* ── Create user form ───────────────────────────────────────────────── */
.section-divider {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--text-muted);
  border-top: 1px solid var(--border);
  padding-top: 16px;
  margin-top: 20px;
  margin-bottom: 16px;
}
.form-row { display: flex; gap: 12px; }
.form-row .form-group { flex: 1; }
.create-user-form .form-group input,
.create-user-form .form-group select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  padding: 8px 10px;
  font-size: 13px;
  outline: none;
}
.create-user-form .form-group input:focus { border-color: var(--primary); }

.checkbox-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  color: var(--text-muted);
  cursor: pointer;
}
.checkbox-label input { accent-color: var(--primary); }

/* ── Info banner ────────────────────────────────────────────────────── */
.info-banner {
  background: rgba(245,158,11,0.12);
  border: 1px solid rgba(245,158,11,0.3);
  border-radius: var(--radius);
  color: var(--warning);
  font-size: 13px;
  padding: 10px 14px;
  margin-bottom: 16px;
}

/* ── Responsive */
@media (max-width: 640px) {
  .header-inner { padding: 12px 16px; }
  .main { padding: 20px 16px; }
  .env-table th:nth-child(3),
  .env-table td:nth-child(3) { display: none; }
}
