/* ── Reset & base ──────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  /* Brand gradient: #7D2AE7 → #4A4FEE → #00D9E3 */
  --grad:    linear-gradient(135deg, #7D2AE7, #4A4FEE);
  --accent:  #4A4FEE;
  --accent2: #3b3fd4;
  --cyan:    #00D9E3;
  --purple:  #7D2AE7;

  /* Surface */
  --bg:      #f8fafc;
  --bg2:     #ffffff;
  --bg3:     #f1f5f9;
  --border:  #e2e8f0;
  --border2: #cbd5e1;

  /* Text */
  --text:    #0f172a;
  --muted:   #64748b;

  /* Status */
  --green:   #16a34a;
  --red:     #dc2626;
  --yellow:  #b45309;

  --radius:  7px;
  --font-ui:   'Inter', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-ui);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* ── Screens ───────────────────────────────────────────────────────────────── */
.screen { min-height: 100vh; }
.hidden { display: none !important; }

/* ── Login ─────────────────────────────────────────────────────────────────── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(ellipse 60% 40% at 50% 0%, rgba(74,79,238,.08) 0%, transparent 70%),
    var(--bg);
}

.login-box {
  width: 340px;
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 36px 28px 28px;
  box-shadow: 0 2px 12px rgba(74,79,238,.08);
}

.login-logo {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  margin-bottom: 28px;
}

.logo-img-login {
  height: 88px;
  width: auto;
}

.login-sub {
  font-size: 12px;
  color: var(--muted);
  font-weight: 500;
  letter-spacing: .04em;
}

#login-form { display: flex; flex-direction: column; gap: 10px; }

.field input {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 12px;
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 13px;
  outline: none;
  transition: border-color .15s;
}
.field input:focus { border-color: var(--accent); }
.field input::placeholder { color: var(--border2); }

.btn-primary {
  background: var(--grad);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 10px;
  font-family: var(--font-ui);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.btn-primary:hover  { opacity: .9; }
.btn-primary:active { opacity: .8; }

.error-msg {
  font-size: 12px;
  color: var(--red);
  text-align: center;
  font-family: var(--font-mono);
}

/* ── Header ────────────────────────────────────────────────────────────────── */
header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--bg2);
  position: sticky;
  top: 0;
  z-index: 10;
}

.header-left  { display: flex; align-items: center; gap: 10px; }

.logo-img-header {
  height: 30px;
  width: auto;
}

.header-sep   { color: var(--border2); }
.header-label { color: var(--muted); font-size: 12px; font-weight: 500; }
.header-right { display: flex; align-items: center; gap: 8px; }

.btn-ghost {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 10px;
  cursor: pointer;
  transition: border-color .15s, color .15s;
}
.btn-ghost:hover       { border-color: var(--border2); color: var(--text); }
.btn-ghost.muted       { color: var(--border2); }
.btn-ghost.muted:hover { color: var(--muted); }

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}
.status-dot.idle      { background: var(--border2); }
.status-dot.deploying { background: var(--yellow); animation: pulse 1.2s infinite; }

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

/* ── Main layout ───────────────────────────────────────────────────────────── */
main {
  max-width: 760px;
  margin: 0 auto;
  padding: 28px 20px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

/* ── Env list ──────────────────────────────────────────────────────────────── */
.env-list {
  border: 1px solid var(--border);
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  /* No overflow:hidden — it clips the absolutely positioned dropdown */
}

/* ── Env item ──────────────────────────────────────────────────────────────── */
.env-item {
  background: var(--bg2);
  padding: 14px 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: background .1s;
  border-bottom: 1px solid var(--border);
  position: relative; /* so its own stacking context doesn't clip children */
}
.env-item:last-child  { border-bottom: none; }
.env-item:first-child { border-radius: 10px 10px 0 0; }
.env-item:last-child  { border-radius: 0 0 10px 10px; }
.env-item:only-child  { border-radius: 10px; }

.env-item.deploying-state { background: #fffbeb; }
.env-item.success-state   { background: #f0fdf4; }
.env-item.error-state     { background: #fef2f2; }

/* top row: info + badge */
.env-row-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.env-info {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  min-width: 0;
}

.env-name       { font-size: 13px; font-weight: 600; white-space: nowrap; }
.env-sep        { color: var(--border2); font-size: 12px; }
.env-subdomain  { font-family: var(--font-mono); font-size: 11px; color: var(--muted); white-space: nowrap; }

.env-current-branch {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--accent);
  white-space: nowrap;
}

/* badge */
.deploy-badge {
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
  letter-spacing: .04em;
  border: 1px solid;
  white-space: nowrap;
  flex-shrink: 0;
}
.deploy-badge.idle      { color: var(--muted);   border-color: var(--border2); background: var(--bg3); }
.deploy-badge.deploying { color: var(--yellow);  border-color: #fcd34d;        background: #fef9c3; animation: pulse 1.2s infinite; }
.deploy-badge.success   { color: var(--green);   border-color: #86efac;        background: #f0fdf4; }
.deploy-badge.error     { color: var(--red);     border-color: #fca5a5;        background: #fef2f2; }

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

/* ── Custom searchable branch selector ─────────────────────────────────────── */
.branch-selector-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
}

.selector-trigger {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 6px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: var(--font-mono);
  font-size: 12px;
  padding: 7px 10px;
  cursor: pointer;
  text-align: left;
  transition: border-color .15s;
  min-width: 0;
}
.selector-trigger:hover:not(:disabled) { border-color: var(--border2); }
.selector-trigger:disabled             { opacity: .5; cursor: not-allowed; }

.selector-display {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex: 1;
  min-width: 0;
}

.selector-caret {
  width: 10px;
  height: 6px;
  flex-shrink: 0;
  color: var(--border2);
  transition: transform .15s;
}

.branch-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  background: var(--bg2);
  border: 1px solid var(--border2);
  border-radius: var(--radius);
  box-shadow: 0 4px 16px rgba(15,23,42,.12);
  z-index: 1000;   /* high enough to clear sibling env items */
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 200px;
}

.dropdown-search-wrap {
  padding: 8px 8px 6px;
  border-bottom: 1px solid var(--border);
}

.dropdown-search {
  width: 100%;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 10px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
}
.dropdown-search:focus    { border-color: var(--accent); }
.dropdown-search::placeholder { color: var(--border2); }

.dropdown-options {
  max-height: 200px;
  overflow-y: auto;
}
.dropdown-options::-webkit-scrollbar       { width: 4px; }
.dropdown-options::-webkit-scrollbar-track { background: transparent; }
.dropdown-options::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.branch-option {
  padding: 7px 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  transition: background .1s;
}
.branch-option:hover      { background: var(--bg3); }
.branch-option.selected   { color: var(--accent); background: rgba(74,79,238,.06); }
.branch-option.is-current { font-weight: 500; }

.btn-fetch {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color .15s, color .15s;
}
.btn-fetch:hover    { color: var(--text); border-color: var(--border2); }
.btn-fetch:disabled { opacity: .4; cursor: not-allowed; }

.btn-action-sep {
  width: 1px;
  height: 20px;
  background: var(--border);
  flex-shrink: 0;
}

.btn-deploy {
  background: var(--grad);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 7px 14px;
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: opacity .15s;
}
.btn-deploy:hover:not(:disabled)  { opacity: .88; }
.btn-deploy:disabled              { opacity: .35; cursor: not-allowed; }

.btn-view-log {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
  font-family: var(--font-ui);
  font-size: 12px;
  font-weight: 500;
  padding: 7px 12px;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
  transition: border-color .15s, color .15s;
}
.btn-view-log:hover { color: var(--text); border-color: var(--border2); }

/* footer row */
.env-row-footer { display: flex; align-items: center; justify-content: space-between; }

.footer-meta          { font-family: var(--font-mono); font-size: 11px; color: var(--border2); }
.footer-meta strong   { color: var(--muted); }

/* ── Log panel ─────────────────────────────────────────────────────────────── */
.log-panel {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
}

.log-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  letter-spacing: .04em;
  text-transform: uppercase;
}

.log-output {
  font-family: var(--font-mono);
  font-size: 12px;
  line-height: 1.7;
  padding: 14px 16px;
  max-height: 320px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-all;
  background: var(--bg3);
}

.log-output::-webkit-scrollbar       { width: 4px; }
.log-output::-webkit-scrollbar-track { background: transparent; }
.log-output::-webkit-scrollbar-thumb { background: var(--border2); border-radius: 2px; }

.log-line-ok    { color: var(--green); }
.log-line-err   { color: var(--red); }
.log-line-step  { color: var(--accent); }
.log-line-plain { color: var(--muted); }

/* ── Env delete button ─────────────────────────────────────────────────────── */
.btn-remove-env {
  background: transparent;
  border: 1px solid transparent;
  border-radius: 5px;
  color: var(--border2);
  font-size: 13px;
  line-height: 1;
  padding: 3px 6px;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color .15s, color .15s, background .15s;
}
.btn-remove-env:hover { border-color: #fca5a5; color: var(--red); background: #fef2f2; }

/* ── Modal ─────────────────────────────────────────────────────────────────── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(15,23,42,.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 200;
  backdrop-filter: blur(2px);
}

.modal-box {
  background: var(--bg2);
  border: 1px solid var(--border);
  border-radius: 12px;
  width: 420px;
  max-width: calc(100vw - 32px);
  box-shadow: 0 8px 32px rgba(15,23,42,.18);
}

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

.modal-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
}

.modal-close {
  background: none;
  border: none;
  font-size: 18px;
  line-height: 1;
  color: var(--border2);
  cursor: pointer;
  padding: 0 2px;
  transition: color .15s;
}
.modal-close:hover { color: var(--text); }

.modal-body {
  padding: 18px 20px 4px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-warn {
  font-size: 13px;
  color: var(--muted);
  line-height: 1.5;
}
.modal-warn strong { color: var(--text); }

.modal-footer {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 16px 20px;
}

.field-group {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field-label {
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

.field-input {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 9px 12px;
  font-family: var(--font-mono);
  font-size: 13px;
  color: var(--text);
  outline: none;
  transition: border-color .15s;
  width: 100%;
}
.field-input:focus { border-color: var(--accent); }
.field-input::placeholder { color: var(--border2); }

.field-hint {
  font-size: 11px;
  color: var(--border2);
}

.btn-danger {
  background: var(--red);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  padding: 8px 16px;
  font-family: var(--font-ui);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
}
.btn-danger:hover  { opacity: .88; }
.btn-danger:disabled { opacity: .4; cursor: not-allowed; }

/* ── Env vars button ───────────────────────────────────────────────────────── */
.btn-env-vars {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--border2);
  font-size: 12px;
  font-family: var(--font-mono);
  line-height: 1;
  padding: 3px 7px;
  cursor: pointer;
  flex-shrink: 0;
  transition: border-color .15s, color .15s, background .15s;
}
.btn-env-vars:hover { border-color: var(--accent); color: var(--accent); background: rgba(74,79,238,.06); }

/* ── Env vars modal ────────────────────────────────────────────────────────── */
.modal-box-wide {
  width: 620px;
  max-width: calc(100vw - 32px);
}

.env-vars-tabs {
  display: flex;
  gap: 4px;
}

.env-tab {
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: var(--radius) var(--radius) 0 0;
  color: var(--muted);
  font-family: var(--font-mono);
  font-size: 12px;
  font-weight: 500;
  padding: 5px 14px;
  cursor: pointer;
  transition: color .15s, background .15s, border-color .15s;
  border-bottom-color: transparent;
  position: relative;
  top: 1px;
}
.env-tab.active {
  background: var(--bg2);
  color: var(--accent);
  border-color: var(--border);
  border-bottom-color: var(--bg2);
}

.env-vars-textarea {
  width: 100%;
  min-height: 220px;
  background: var(--bg3);
  border: 1px solid var(--border);
  border-radius: 0 var(--radius) var(--radius) var(--radius);
  padding: 12px;
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text);
  line-height: 1.6;
  resize: vertical;
  outline: none;
  transition: border-color .15s;
}
.env-vars-textarea:focus { border-color: var(--accent); }

.env-vars-log-wrap {
  border-top: 1px solid var(--border);
  padding: 0 20px 8px;
}

.env-vars-log {
  max-height: 180px;
  margin-top: 10px;
  border-radius: var(--radius);
}

/* ── Responsive ────────────────────────────────────────────────────────────── */
@media (max-width: 600px) {
  header    { padding: 10px 14px; }
  main      { padding: 16px 12px; }
  .env-item { padding: 12px 14px; }
}
