:root {
  color-scheme: dark;
  --bg: #0f1011;
  --surface: #17191a;
  --surface-2: #1f2224;
  --surface-3: #121415;
  --line: #303436;
  --line-soft: rgba(148, 163, 184, .16);
  --text: #edf2f8;
  --muted: #96a3b4;
  --soft: #c8d2df;
  --green: #38c172;
  --yellow: #e8b339;
  --red: #ee5d5d;
  --cyan: #58c7d8;
  --ink: #080909;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

:focus-visible {
  outline: 2px solid rgba(88, 199, 216, .72);
  outline-offset: 2px;
}

.app-shell {
  display: grid;
  grid-template-columns: 264px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 24px;
  padding: 22px;
  border-right: 1px solid var(--line);
  background: #0b0c0d;
}

.brand-block,
.connection-card {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border: 1px solid #3b4758;
  border-radius: 8px;
  background: #141718;
  color: var(--cyan);
  font-weight: 900;
}

.brand-block b,
.connection-card b {
  display: block;
  font-size: 14px;
}

.brand-block span,
.connection-card small {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
}

.side-nav {
  display: grid;
  gap: 6px;
}

.nav-item,
.ghost-button {
  width: 100%;
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  color: var(--soft);
  padding: 11px 12px;
  text-align: left;
  font-weight: 750;
}

.nav-item:hover,
.ghost-button:hover {
  background: rgba(255, 255, 255, .04);
  border-color: var(--line-soft);
}

.nav-item.active {
  background: #202728;
  border-color: #344153;
  color: var(--text);
}

.sidebar-footer {
  margin-top: auto;
  display: grid;
  gap: 14px;
}

.connection-card {
  padding: 12px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(255, 255, 255, .03);
}

.main {
  min-width: 0;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 18px;
  margin-bottom: 18px;
}

.eyebrow {
  margin: 0 0 7px;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .12em;
  text-transform: uppercase;
}

h1,
h2,
h3,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: 25px;
  font-weight: 850;
}

h2 {
  margin-bottom: 0;
  font-size: 16px;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.operator-pill,
.live-pill,
.summary-badge {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 32px;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(255, 255, 255, .03);
  color: var(--soft);
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 800;
}

.summary-badge.danger {
  color: #ffd1d1;
  border-color: rgba(238, 93, 93, .35);
  background: rgba(238, 93, 93, .1);
}

.view { display: none; }
.view.active { display: block; }

.kpi-strip {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-bottom: 14px;
}

.kpi,
.panel,
.auth-panel,
.auth-status {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
}

.kpi {
  padding: 13px 14px;
}

.kpi span,
.repo-box span,
.last-action span,
.env-meta span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .09em;
  text-transform: uppercase;
}

.kpi b {
  display: block;
  margin-top: 8px;
  font-size: 22px;
}

.grid {
  display: grid;
  grid-template-columns: repeat(12, minmax(0, 1fr));
  gap: 14px;
}

.span-4 { grid-column: span 4; }
.span-5 { grid-column: span 5; }
.span-7 { grid-column: span 7; }
.span-12 { grid-column: span 12; }

.panel {
  min-width: 0;
  padding: 16px;
}

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

.status-row,
.metric-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  min-height: 42px;
  border-top: 1px solid var(--line-soft);
}

.status-row:first-of-type,
.metric-row:first-of-type {
  border-top: 0;
}

.status-row span,
.metric-row span {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
  color: var(--soft);
}

.status-row b,
.metric-row b,
#pm2-table td:nth-child(2),
#last-action-result,
#env-mode,
#problems-last-level {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 74px;
  max-width: 100%;
  padding: 5px 9px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 850;
  white-space: nowrap;
}

.status-ok {
  color: #b9f4d0;
  border: 1px solid rgba(56, 193, 114, .35);
  background: rgba(56, 193, 114, .12);
}

.status-warning {
  color: #ffe3a1;
  border: 1px solid rgba(232, 179, 57, .36);
  background: rgba(232, 179, 57, .12);
}

.status-error {
  color: #ffc3c3;
  border: 1px solid rgba(238, 93, 93, .4);
  background: rgba(238, 93, 93, .13);
}

.status-dot {
  width: 9px;
  height: 9px;
  flex: 0 0 auto;
  border-radius: 50%;
  background: #758296;
  box-shadow: 0 0 0 3px rgba(117, 130, 150, .12);
}

.status-dot-ok { background: var(--green); box-shadow: 0 0 0 3px rgba(56, 193, 114, .14); }
.status-dot-warn { background: var(--yellow); box-shadow: 0 0 0 3px rgba(232, 179, 57, .14); }
.status-dot-error { background: var(--red); box-shadow: 0 0 0 3px rgba(238, 93, 93, .14); }

.card-ok { border-color: rgba(56, 193, 114, .32); }
.card-warning { border-color: rgba(232, 179, 57, .44); }
.card-error { border-color: rgba(238, 93, 93, .55); }

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: 680px;
  border-collapse: collapse;
  font-size: 13px;
}

th,
td {
  padding: 10px 8px;
  border-top: 1px solid var(--line-soft);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 11px;
  font-weight: 850;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.repo-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
}

.repo-box,
.env-meta > div,
.env-backups,
.problem-last,
.last-action > div {
  min-width: 0;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-3);
  padding: 12px;
}

.repo-box b {
  display: block;
  margin-top: 8px;
}

.repo-box code,
.problem-last code,
.env-meta code {
  display: block;
  margin-top: 6px;
  overflow: hidden;
  color: var(--soft);
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.repo-box small {
  display: block;
  margin-top: 10px;
  color: var(--muted);
}

.problem-last {
  display: grid;
  gap: 8px;
  margin-top: 8px;
}

.problem-last code {
  white-space: normal;
  line-height: 1.4;
}

.action-list {
  display: grid;
  gap: 10px;
}

.action-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 12px;
  width: 100%;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  padding: 13px 14px;
  text-align: left;
}

.action-card::after {
  content: "Run";
  color: var(--cyan);
  font-size: 11px;
  font-weight: 900;
  letter-spacing: .08em;
  text-transform: uppercase;
}

.action-card:hover {
  border-color: rgba(88, 199, 216, .5);
  background: #25292b;
}

.action-card b,
.action-card span {
  display: block;
}

.action-card span {
  margin-top: 3px;
  color: var(--muted);
  font-size: 12px;
}

.primary-action {
  border-color: rgba(88, 199, 216, .38);
}

.danger-panel {
  border-color: rgba(238, 93, 93, .35);
}

.danger-action {
  border-color: rgba(238, 93, 93, .34);
  background: rgba(238, 93, 93, .08);
}

.danger-action::after {
  content: "Check";
  color: #ffb3b3;
}

.action-card:disabled,
.primary-button:disabled,
.secondary-button:disabled,
.tab:disabled {
  cursor: not-allowed;
  opacity: .55;
}

.last-action {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 180px;
  gap: 12px;
  margin-bottom: 12px;
}

.last-action b {
  display: block;
  margin-top: 6px;
}

pre {
  margin: 0;
  width: 100%;
  min-height: 360px;
  max-height: calc(100vh - 270px);
  overflow: auto;
  border: 1px solid #253141;
  border-radius: 8px;
  background: var(--ink);
  color: #d9f2df;
  padding: 14px;
  white-space: pre-wrap;
  word-break: break-word;
  font: 12.5px/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

#actionOutput {
  min-height: 220px;
  color: #d7ecff;
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 12px;
}

.tab,
.primary-button,
.secondary-button {
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  padding: 9px 11px;
  color: var(--text);
  font-weight: 800;
}

.tab {
  background: var(--surface-2);
  font-size: 12px;
}

.tab.active {
  border-color: rgba(88, 199, 216, .48);
  background: rgba(88, 199, 216, .12);
  color: #b9f6ff;
}

.primary-button {
  background: #1d6f7d;
}

.secondary-button {
  background: #292d30;
}

.env-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 330px;
  gap: 14px;
}

.env-meta {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 140px;
  gap: 10px;
  margin-bottom: 12px;
}

#env-editor {
  width: 100%;
  min-height: 520px;
  resize: vertical;
  border: 1px solid #253141;
  border-radius: 8px;
  background: var(--ink);
  color: #dbeafe;
  padding: 14px;
  font: 13px/1.45 ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

#env-editor:disabled {
  color: #93a4bd;
  opacity: .78;
}

.env-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.env-backups h3 {
  margin-bottom: 12px;
  font-size: 14px;
}

.backup-list {
  display: grid;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
}

.backup-item {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  border: 1px solid var(--line-soft);
  border-radius: 8px;
  background: rgba(255, 255, 255, .03);
  padding: 10px;
}

.backup-item b,
.backup-item small {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.backup-item small {
  margin-top: 4px;
  color: var(--muted);
}

.auth-page {
  display: grid;
  place-items: center;
  padding: 24px;
  background: #0b0c0d;
}

.auth-shell {
  display: grid;
  grid-template-columns: minmax(320px, 430px) 300px;
  gap: 14px;
  width: min(820px, 100%);
}

.auth-panel,
.auth-status {
  padding: 24px;
}

.auth-copy {
  color: var(--muted);
  line-height: 1.5;
}

.login-form {
  display: grid;
  gap: 13px;
  margin-top: 24px;
}

.login-form label span {
  display: block;
  margin-bottom: 7px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.login-form input {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #0d0f10;
  color: var(--text);
  padding: 12px;
  outline: none;
}

.login-form input:focus {
  border-color: rgba(88, 199, 216, .55);
}

.form-error {
  margin: 0;
  color: #ffc3c3;
  font-size: 13px;
}

.auth-status {
  display: grid;
  align-content: center;
  gap: 16px;
}

.auth-status > div {
  display: grid;
  grid-template-columns: auto minmax(0, 1fr);
  gap: 7px 10px;
}

.auth-status small {
  grid-column: 2;
  color: var(--muted);
  line-height: 1.45;
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: static;
    height: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
  }

  .side-nav {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .nav-item {
    text-align: center;
  }

  .sidebar-footer {
    grid-template-columns: 1fr auto;
    align-items: center;
  }

  .kpi-strip {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .span-4,
  .span-5,
  .span-7,
  .span-12 {
    grid-column: span 12;
  }

  .env-layout,
  .env-meta,
  .repo-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 680px) {
  .main,
  .sidebar,
  .auth-page {
    padding: 14px;
  }

  .topbar,
  .last-action,
  .sidebar-footer,
  .auth-shell {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .side-nav,
  .kpi-strip {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .auth-shell {
    display: grid;
  }
}
