:root {
  --bg: #0b0f17;
  --surface: #111827;
  --surface-2: #1a2234;
  --border: #263147;
  --text: #e5e7eb;
  --muted: #94a3b8;
  --accent: #10b981;
  --accent-2: #38bdf8;
  --warn: #f59e0b;
  --danger: #ef4444;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 0.875rem; }

.login-shell {
  min-height: 100%;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.login-card {
  width: 100%;
  max-width: 390px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1.75rem;
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
}
.brand-badge {
  display: inline-block;
  align-self: flex-start;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: rgba(16, 185, 129, 0.12);
  border: 1px solid rgba(16, 185, 129, 0.35);
  padding: 0.25rem 0.55rem;
  border-radius: 999px;
}
.login-card h1 { margin: 0; font-size: 1.35rem; }
.field { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.85rem; }
.field input, .cwd-input, .select-input {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.6rem 0.75rem;
  font-size: 0.92rem;
  outline: none;
}
.field input:focus, .cwd-input:focus { border-color: var(--accent); }
.error-banner {
  background: rgba(239, 68, 68, 0.14);
  border: 1px solid rgba(239, 68, 68, 0.45);
  color: #fca5a5;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  font-size: 0.85rem;
}

.btn {
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  border-radius: 8px;
  padding: 0.55rem 0.9rem;
  font-size: 0.86rem;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { border-color: #475569; }
.btn.sm { padding: 0.35rem 0.65rem; font-size: 0.78rem; }
.btn.full { width: 100%; }
.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #04120c;
}
.btn-danger {
  background: rgba(239, 68, 68, 0.16);
  border-color: rgba(239, 68, 68, 0.5);
  color: #fca5a5;
}
.btn-warn {
  background: rgba(245, 158, 11, 0.16);
  border-color: rgba(245, 158, 11, 0.5);
  color: #fcd34d;
}
.btn-ghost { background: transparent; }

.app-shell {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  overflow: hidden;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.55rem 0.9rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar-left { display: flex; align-items: center; gap: 0.55rem; min-width: 0; }
.dot-online {
  width: 9px; height: 9px; border-radius: 50%;
  background: var(--accent); box-shadow: 0 0 8px var(--accent);
  flex-shrink: 0;
}
.mini-stats {
  color: var(--muted);
  font-size: 0.78rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.desktop-tabs { display: flex; gap: 0.35rem; }
.tab-btn {
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 0.42rem 0.85rem;
  border-radius: 8px;
  font-weight: 600;
  font-size: 0.85rem;
  cursor: pointer;
}
.tab-btn.active {
  color: var(--text);
  background: var(--surface-2);
  border-color: var(--border);
}

.main-area { flex: 1; min-height: 0; position: relative; }
.tab-pane { display: none; height: 100%; }
.tab-pane.active { display: flex; flex-direction: column; }
.pane-scroll {
  height: 100%;
  overflow-y: auto;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
}

.term-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.45rem 0.7rem;
  background: #0d131f;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.term-tabs { display: flex; gap: 0.35rem; overflow-x: auto; }
.term-tab {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.3rem 0.6rem;
  border-radius: 6px;
  font-size: 0.78rem;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--muted);
  cursor: pointer;
}
.term-tab.active { color: var(--text); border-color: var(--accent); }
.term-tab-close { color: var(--muted); font-weight: 700; cursor: pointer; }
.term-actions { display: flex; gap: 0.35rem; }
.term-container {
  flex: 1;
  min-height: 0;
  background: #070a10;
  padding: 0.35rem;
  overflow: hidden;
}
.term-slot { width: 100%; height: 100%; display: none; }
.term-slot.active { display: block; }

.mobile-keys {
  display: flex;
  gap: 0.35rem;
  padding: 0.45rem 0.6rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  overflow-x: auto;
  flex-shrink: 0;
}
.key-pill {
  flex-shrink: 0;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 0.32rem 0.55rem;
  font-size: 0.76rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  cursor: pointer;
}
.key-pill.accent { border-color: rgba(16, 185, 129, 0.5); color: #6ee7b7; }
.key-pill.danger { border-color: rgba(239, 68, 68, 0.5); color: #fca5a5; }

.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  flex-wrap: wrap;
}
.section-head h2, .section-head h3, .panel-box h3 { margin: 0; font-size: 1rem; }
.sys-meta { color: var(--muted); font-size: 0.84rem; }
.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 0.85rem;
}
.stat-card, .panel-box, .pm2-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.95rem;
}
.stat-label { color: var(--muted); font-size: 0.8rem; }
.stat-value { font-size: 1.55rem; font-weight: 700; margin: 0.2rem 0 0.5rem; }
.stat-sub { color: var(--muted); font-size: 0.78rem; margin-top: 0.45rem; }
.progress {
  height: 7px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
}
.progress-fill {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.25s ease;
}
.progress-fill.warn { background: var(--warn); }
.progress-fill.danger { background: var(--danger); }

.pm2-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(270px, 1fr));
  gap: 0.85rem;
}
.pm2-card { display: flex; flex-direction: column; gap: 0.6rem; }
.pm2-top { display: flex; justify-content: space-between; align-items: center; gap: 0.5rem; }
.badge {
  font-size: 0.72rem;
  font-weight: 700;
  padding: 0.2rem 0.5rem;
  border-radius: 999px;
  text-transform: uppercase;
}
.badge.online { background: rgba(16, 185, 129, 0.16); color: #6ee7b7; }
.badge.stopped { background: rgba(239, 68, 68, 0.16); color: #fca5a5; }
.pm2-actions, .git-btns, .log-controls, .files-actions, .quick-dirs {
  display: flex; gap: 0.45rem; flex-wrap: wrap; align-items: center;
}

.log-pre {
  background: #070a10;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.76rem;
  line-height: 1.45;
  max-height: 360px;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 0.75rem 0 0;
}
.log-pre.compact { max-height: 140px; }

.table-wrap { overflow-x: auto; margin-top: 0.6rem; }
table { width: 100%; border-collapse: collapse; font-size: 0.84rem; }
th, td {
  text-align: left;
  padding: 0.55rem 0.5rem;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
th { color: var(--muted); font-weight: 600; font-size: 0.76rem; text-transform: uppercase; }

.files-toolbar, .path-bar {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  align-items: center;
}
.cwd-input { flex: 1; min-width: 180px; }
.upload-label { display: inline-flex; align-items: center; }
.upload-status {
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  background: rgba(56, 189, 248, 0.12);
  border: 1px solid rgba(56, 189, 248, 0.35);
  font-size: 0.83rem;
}
.file-link {
  background: none;
  border: none;
  color: var(--accent-2);
  font: inherit;
  cursor: pointer;
  padding: 0;
  text-align: left;
}
.file-link.is-file { color: var(--text); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.75);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 50;
}
.modal-card {
  width: 100%;
  max-width: 860px;
  height: 82vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.modal-head, .modal-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.5rem;
}
.editor-textarea {
  flex: 1;
  background: #070a10;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  resize: none;
  outline: none;
}

.mobile-bottom-nav { display: none; }

@media (max-width: 768px) {
  .desktop-tabs { display: none; }
  .mobile-bottom-nav {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    background: var(--surface);
    border-top: 1px solid var(--border);
    padding: 0.35rem;
    gap: 0.25rem;
    flex-shrink: 0;
  }
  .mobile-bottom-nav .tab-btn { text-align: center; padding: 0.5rem 0.25rem; font-size: 0.78rem; }
  .mini-stats { display: none; }
}
