:root {
  --bg: #0f1117;
  --bg-card: #1a1d27;
  --bg-card-hover: #222531;
  --bg-input: #252833;
  --border: #2e3244;
  --text: #e4e6ed;
  --text-muted: #8b8fa3;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --green: #22c55e;
  --green-bg: rgba(34, 197, 94, 0.12);
  --red: #ef4444;
  --red-bg: rgba(239, 68, 68, 0.12);
  --yellow: #eab308;
  --yellow-bg: rgba(234, 179, 8, 0.12);
  --blue: #3b82f6;
  --blue-bg: rgba(59, 130, 246, 0.12);
  --orange: #f97316;
}

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

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

/* Login */
.login-body {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}

.login-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 40px;
  width: 100%;
  max-width: 400px;
}

.login-header { text-align: center; margin-bottom: 32px; }
.login-header h1 { font-size: 24px; font-weight: 700; margin-bottom: 4px; }
.login-header p { color: var(--text-muted); font-size: 14px; }

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

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
}

input:focus {
  border-color: var(--primary);
}

.error-message {
  background: var(--red-bg);
  color: var(--red);
  padding: 10px 14px;
  border-radius: 8px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 16px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  color: var(--text);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn:hover { background: var(--bg-card-hover); border-color: var(--text-muted); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

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

.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-bg); border-color: var(--red); }

.btn-success { color: var(--green); }
.btn-success:hover { background: var(--green-bg); border-color: var(--green); }

.btn-setup { color: var(--orange); }
.btn-setup:hover { background: rgba(249, 115, 22, 0.12); border-color: var(--orange); }

.btn-full { width: 100%; padding: 12px; font-size: 14px; margin-top: 8px; }

.btn-sm { padding: 5px 10px; font-size: 12px; }

/* Layout */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-card);
}

.app-header h1 { font-size: 18px; font-weight: 700; }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-right span { color: var(--text-muted); font-size: 13px; }

.container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px;
}

/* Status bar */
.status-bar {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
  flex-wrap: wrap;
}

.status-chip {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 14px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 20px;
  font-size: 13px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}

.status-dot.active { background: var(--green); box-shadow: 0 0 6px var(--green); }
.status-dot.inactive { background: var(--red); }
.status-dot.unknown { background: var(--text-muted); }

/* Environment cards */
.env-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(560px, 1fr));
  gap: 20px;
}

.env-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  transition: border-color 0.2s;
}

.env-card:hover { border-color: var(--text-muted); }

.env-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.env-title {
  display: flex;
  align-items: center;
  gap: 10px;
}

.env-title h2 { font-size: 16px; font-weight: 600; }

.env-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 4px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.env-badge.active { background: var(--green-bg); color: var(--green); }
.env-badge.inactive { background: var(--red-bg); color: var(--red); }
.env-badge.healthy { background: var(--green-bg); color: var(--green); }
.env-badge.unhealthy { background: var(--yellow-bg); color: var(--yellow); }
.env-badge.self { background: rgba(99, 102, 241, 0.15); color: var(--primary); }

.env-card-self { border-color: rgba(99, 102, 241, 0.3); }
.env-card-self:hover { border-color: var(--primary); }

.env-meta {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 12px;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
}

.meta-item { font-size: 13px; }
.meta-item .meta-label { color: var(--text-muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: 2px; }
.meta-item .meta-value { font-weight: 500; font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; }

.env-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 16px 20px;
}

/* Panels */
.panel-area {
  border-top: 1px solid var(--border);
}

.panel {
  padding: 16px 20px;
  display: none;
}

.panel.active { display: block; }

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

.panel-header h3 { font-size: 14px; font-weight: 600; }

/* Logs */
.log-container {
  background: #0d0f14;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  max-height: 400px;
  overflow-y: auto;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 12px;
  line-height: 1.6;
  white-space: pre-wrap;
  word-break: break-all;
  color: var(--text-muted);
}

/* Params table */
.params-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.params-table th {
  text-align: left;
  padding: 8px 12px;
  background: var(--bg-input);
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  border-bottom: 1px solid var(--border);
}

.params-table td {
  padding: 8px 12px;
  border-bottom: 1px solid var(--border);
  font-family: 'SF Mono', 'Fira Code', monospace;
  font-size: 12px;
}

.params-table tr:hover td { background: var(--bg-card-hover); }

/* Credentials */
.cred-list { list-style: none; }
.cred-item {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 0;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}

.cred-icon { font-size: 16px; }
.cred-name { font-family: 'SF Mono', 'Fira Code', monospace; font-size: 12px; }
.cred-present { color: var(--green); }
.cred-missing { color: var(--red); }

/* Toast */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  padding: 12px 20px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  animation: slideIn 0.3s ease;
  max-width: 400px;
}

.toast.success { background: var(--green-bg); color: var(--green); border: 1px solid var(--green); }
.toast.error { background: var(--red-bg); color: var(--red); border: 1px solid var(--red); }
.toast.info { background: var(--blue-bg); color: var(--blue); border: 1px solid var(--blue); }

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

/* Spinner */
.spinner {
  display: inline-block;
  width: 14px;
  height: 14px;
  border: 2px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* Console */
.console-wrapper {
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 900;
  background: var(--bg-card);
  border-top: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  transition: height 0.25s ease;
}

.console-wrapper.collapsed .console-body {
  display: none;
}

.console-wrapper.collapsed .console-icon {
  transform: rotate(0deg);
}

.console-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 20px;
  cursor: pointer;
  border-bottom: 1px solid var(--border);
  user-select: none;
  flex-shrink: 0;
}

.console-header:hover {
  background: var(--bg-card-hover);
}

.console-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  font-weight: 600;
}

.console-icon {
  font-size: 10px;
  transition: transform 0.25s ease;
  transform: rotate(90deg);
  display: inline-block;
}

.console-count {
  background: var(--primary);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  padding: 1px 6px;
  border-radius: 10px;
  min-width: 18px;
  text-align: center;
}

.console-controls {
  display: flex;
  gap: 6px;
}

.console-body {
  overflow: hidden;
  flex: 1;
}

.console-output {
  height: 250px;
  overflow-y: auto;
  padding: 12px 20px;
  background: #0a0c10;
  font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
  font-size: 12px;
  line-height: 1.7;
}

.console-welcome {
  color: var(--text-muted);
  font-style: italic;
}

.console-entry {
  padding: 4px 0;
  border-bottom: 1px solid rgba(46, 50, 68, 0.4);
}

.console-entry:last-child {
  border-bottom: none;
}

.console-timestamp {
  color: var(--text-muted);
  margin-right: 8px;
  font-size: 11px;
}

.console-label {
  font-weight: 600;
  margin-right: 6px;
}

.console-label.action-start { color: var(--blue); }
.console-label.action-success { color: var(--green); }
.console-label.action-error { color: var(--red); }
.console-label.action-build { color: var(--orange); }

.console-message {
  color: var(--text);
}

.console-detail {
  margin-top: 4px;
  padding: 6px 10px;
  background: rgba(15, 17, 23, 0.6);
  border-radius: 4px;
  color: var(--text-muted);
  white-space: pre-wrap;
  word-break: break-all;
  max-height: 150px;
  overflow-y: auto;
}

.console-separator {
  border: none;
  border-top: 1px solid var(--border);
  margin: 6px 0;
}

#mainContainer {
  padding-bottom: 50px;
}

#mainContainer.console-open {
  padding-bottom: 310px;
}

/* Responsive */
@media (max-width: 640px) {
  .env-grid { grid-template-columns: 1fr; }
  .container { padding: 16px; }
  .env-meta { grid-template-columns: repeat(2, 1fr); }
  .console-output { height: 180px; }
}
