:root {
  --bg-0: #080a10;
  --bg-1: #0e1118;
  --bg-2: #151a24;
  --bg-3: #1c2231;
  --border: #1e2639;
  --border-bright: #2a3550;
  --text-1: #e4e8ef;
  --text-2: #8892a6;
  --text-3: #586174;
  --accent: #22d3a7;
  --accent-dim: rgba(34, 211, 167, 0.08);
  --accent-glow: rgba(34, 211, 167, 0.3);
  --success: #34d399;
  --warning: #fbbf24;
  --danger: #f87171;
  --danger-dim: rgba(248, 113, 113, 0.1);
  --warn-dim: rgba(251, 191, 36, 0.1);
  --font-ui: 'Outfit', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', monospace;
  --radius: 10px;
  --radius-sm: 6px;
}

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

html { font-size: 18px; }

body {
  font-family: var(--font-ui);
  background: var(--bg-0);
  color: var(--text-1);
  line-height: 1.55;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

/* Subtle depth gradient */
body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: radial-gradient(ellipse at 20% 0%, rgba(34,211,167,0.03) 0%, transparent 60%),
              radial-gradient(ellipse at 80% 100%, rgba(34,211,167,0.02) 0%, transparent 50%);
  pointer-events: none;
  z-index: 0;
}

.app {
  position: relative;
  z-index: 1;
  max-width: 1280px;
  margin: 0 auto;
  padding: 28px 32px;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { font-family: var(--font-mono); font-size: 0.88rem; }

/* === Header === */

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

.logo {
  display: flex;
  align-items: center;
  gap: 14px;
  text-decoration: none !important;
  color: inherit;
}
.logo svg { width: 40px; height: 40px; flex-shrink: 0; }
.logo h1 { font-size: 1.35rem; font-weight: 700; letter-spacing: -0.02em; }
.logo h1 span { color: var(--accent); }

.header-right {
  display: flex;
  align-items: center;
  gap: 14px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 5px 14px;
  border-radius: 20px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  background: var(--bg-2);
  color: var(--text-3);
  transition: all 0.3s;
}
.status-badge::before {
  content: '';
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-3);
  transition: all 0.3s;
}
.status-badge.connected {
  background: var(--accent-dim);
  color: var(--accent);
}
.status-badge.connected::before {
  background: var(--accent);
  box-shadow: 0 0 8px var(--accent-glow);
  animation: pulse 2s ease-in-out infinite;
}
.status-badge.disconnected {
  background: var(--danger-dim);
  color: var(--danger);
}
.status-badge.disconnected::before {
  background: var(--danger);
}

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

.version {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-3);
}

.hub-link {
  display: flex;
  align-items: center;
  color: var(--text-3);
  transition: color 0.2s;
}
.hub-link:hover { color: var(--accent); text-decoration: none; }

/* === Overview Stats === */

.overview {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 14px;
  margin-bottom: 28px;
}

.stat {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  text-align: center;
  transition: border-color 0.2s;
}
.stat:hover { border-color: var(--border-bright); }

.stat-label {
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-3);
  margin-bottom: 6px;
}

.stat-num {
  font-family: var(--font-mono);
  font-size: 2rem;
  font-weight: 700;
  line-height: 1.2;
}

.stat-value { color: var(--accent); }
.stat-detail {
  font-size: 1rem;
  color: var(--text-3);
  font-weight: 400;
}

/* === Navigation === */

nav {
  display: flex;
  gap: 2px;
  margin-bottom: 28px;
  border-bottom: 1px solid var(--border);
}

nav button {
  padding: 12px 22px;
  border: none;
  background: none;
  color: var(--text-3);
  font-family: var(--font-ui);
  font-size: 0.88rem;
  font-weight: 500;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: all 0.15s;
  margin-bottom: -1px;
}
nav button:hover { color: var(--text-1); }
nav button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* === Sections === */

.tab-content { display: none; animation: fadeIn 0.2s ease; }
.tab-content.active { display: block; }

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

/* === Toolbar === */

.toolbar {
  display: flex;
  gap: 10px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}

.toolbar input[type="text"],
.toolbar input[type="number"],
.toolbar select {
  padding: 10px 16px;
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-1);
  font-family: var(--font-ui);
  font-size: 0.88rem;
  outline: none;
  transition: border-color 0.2s;
}
.toolbar input:focus,
.toolbar select:focus {
  border-color: var(--accent);
}
.toolbar input[type="text"] { flex: 1; min-width: 180px; }
.toolbar input[type="number"] { width: 90px; }
.toolbar select { min-width: 260px; }

.btn-primary {
  padding: 10px 24px;
  background: var(--accent);
  color: #080a10;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-weight: 600;
  font-size: 0.88rem;
  cursor: pointer;
  transition: all 0.15s;
}
.btn-primary:hover { filter: brightness(1.1); transform: translateY(-1px); }

/* === Stack Grid === */

.stack-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 14px;
}

.stack-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border-bright);
  border-radius: var(--radius);
  padding: 20px;
  cursor: pointer;
  transition: all 0.2s;
}
.stack-card.running { border-left-color: var(--success); }
.stack-card.partial { border-left-color: var(--warning); }
.stack-card.stopped { border-left-color: var(--danger); }
.stack-card:hover {
  border-color: var(--border-bright);
  background: var(--bg-2);
}
.stack-card.expanded {
  border-color: var(--accent);
  background: var(--bg-2);
  box-shadow: 0 4px 20px rgba(0,0,0,0.3);
}

.stack-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0;
}
.stack-card.expanded .stack-header { margin-bottom: 10px; }

.stack-header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stack-chevron {
  color: var(--text-3);
  transition: transform 0.2s;
  flex-shrink: 0;
}
.stack-card.expanded .stack-chevron { transform: rotate(180deg); }

.stack-name {
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: -0.01em;
}

.stack-badge {
  padding: 3px 10px;
  border-radius: 12px;
  font-family: var(--font-mono);
  font-size: 0.76rem;
  font-weight: 500;
}
.stack-badge.running { background: rgba(52,211,153,0.12); color: var(--success); }
.stack-badge.stopped { background: rgba(248,113,113,0.12); color: var(--danger); }
.stack-badge.partial { background: var(--warn-dim); color: var(--warning); }

.stack-urls {
  display: none;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 12px;
}
.stack-card.expanded .stack-urls { display: flex; }
.stack-url {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--accent);
  background: var(--accent-dim);
  padding: 2px 8px;
  border-radius: 4px;
  transition: background 0.15s;
}
.stack-url:hover { background: rgba(34,211,167,0.15); text-decoration: none; }

.stack-services {
  display: none;
  flex-direction: column;
  gap: 4px;
  padding-top: 10px;
  border-top: 1px solid var(--border);
}
.stack-card.expanded .stack-services { display: flex; }

.stack-svc {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 0;
  font-size: 0.86rem;
}

.svc-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.svc-dot.running { background: var(--success); box-shadow: 0 0 5px rgba(52,211,153,0.4); }
.svc-dot.stopped { background: var(--danger); }
.svc-dot.partial { background: var(--warning); box-shadow: 0 0 5px rgba(251,191,36,0.3); }

.svc-name {
  font-family: var(--font-mono);
  font-size: 0.84rem;
  color: var(--text-1);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.svc-replicas {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-3);
  flex-shrink: 0;
}

.svc-image {
  font-family: var(--font-mono);
  font-size: 0.78rem;
  color: var(--text-3);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  flex-shrink: 0;
}

/* === Tables === */

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

table {
  width: 100%;
  border-collapse: collapse;
}

thead th {
  text-align: left;
  padding: 12px 14px;
  font-size: 0.76rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-3);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
thead th.sortable {
  cursor: pointer;
  user-select: none;
  transition: color 0.15s;
}
thead th.sortable:hover { color: var(--text-1); }
thead th.sortable::after {
  content: ' \2195';
  opacity: 0.3;
}
thead th.sort-asc::after { content: ' \2191'; opacity: 1; }
thead th.sort-desc::after { content: ' \2193'; opacity: 1; }

tbody td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
  font-size: 0.9rem;
}

tbody tr { transition: background 0.1s; }
tbody tr:hover { background: var(--bg-2); }

.text-muted { color: var(--text-3); }
.text-danger { color: var(--danger); }

.status-running { color: var(--success); }
.status-stopped { color: var(--danger); }
.status-partial { color: var(--warning); }

.pattern-tpl {
  display: block;
  max-width: 500px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.83rem;
}

.actions {
  display: flex;
  gap: 8px;
  white-space: nowrap;
}

.btn-action {
  padding: 6px 16px;
  font-family: var(--font-ui);
  font-size: 0.83rem;
  font-weight: 600;
  border: 1px solid var(--accent);
  border-radius: var(--radius-sm);
  background: var(--accent-dim);
  color: var(--accent);
  cursor: pointer;
  transition: all 0.15s;
  letter-spacing: 0.01em;
}
.btn-action:hover {
  background: var(--accent);
  color: var(--bg-0);
  box-shadow: 0 0 12px var(--accent-glow);
}
.btn-action.btn-warn {
  border-color: var(--warning);
  background: var(--warn-dim);
  color: var(--warning);
}
.btn-action.btn-warn:hover {
  background: var(--warning);
  color: var(--bg-0);
  box-shadow: 0 0 12px rgba(251, 191, 36, 0.3);
}
.btn-action.btn-sm {
  padding: 3px 10px;
  font-size: 0.75rem;
}

.btn-action.btn-danger {
  border-color: var(--danger);
  background: var(--danger-dim);
  color: var(--danger);
}
.btn-action.btn-danger:hover {
  background: var(--danger);
  color: #fff;
  box-shadow: 0 0 12px rgba(248, 113, 113, 0.3);
}

/* === Frequency Bar === */

.freq-bar {
  width: 100px;
  height: 5px;
  background: var(--bg-3);
  border-radius: 3px;
  overflow: hidden;
}
.freq-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 3px;
  transition: width 0.3s;
}

/* === Tags === */

.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 4px;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--bg-3);
  color: var(--text-2);
}
.tag-accent { background: var(--accent-dim); color: var(--accent); }
.tag-warn { background: var(--warn-dim); color: var(--warning); }

/* === Node Cards === */

.node-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(340px, 1fr));
  gap: 14px;
}

.node-card {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px;
  transition: border-color 0.2s;
}
.node-card:hover { border-color: var(--border-bright); }

.node-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
}
.node-hostname {
  font-weight: 700;
  font-size: 1.05rem;
  flex: 1;
}

.node-details {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}
.node-detail {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.node-label {
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-3);
}

/* === Log Output === */

.log-output {
  background: var(--bg-1);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 18px;
  font-family: var(--font-mono);
  font-size: 0.83rem;
  line-height: 1.7;
  max-height: 640px;
  overflow: auto;
  color: var(--text-2);
}

.log-line { white-space: pre-wrap; word-break: break-all; }
.log-ts { color: var(--text-3); }
.log-error { color: var(--danger); background: var(--danger-dim); margin: 0 -18px; padding: 0 18px; }
.log-warn { color: var(--warning); }

/* === States === */

.loading-state, .empty-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--text-3);
  font-size: 0.95rem;
}
.error-state {
  text-align: center;
  padding: 48px 24px;
  color: var(--danger);
  font-size: 0.95rem;
}

/* === Modal === */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 5, 8, 0.8);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  opacity: 0;
  transition: opacity 0.15s ease;
  pointer-events: none;
}
.modal-overlay.open {
  opacity: 1;
  pointer-events: auto;
}

.modal {
  background: var(--bg-1);
  border: 1px solid var(--border-bright);
  border-radius: var(--radius);
  padding: 28px 32px;
  max-width: 440px;
  width: 90%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.5), 0 0 0 1px var(--border);
  transform: translateY(8px) scale(0.98);
  transition: transform 0.15s ease;
}
.modal-overlay.open .modal {
  transform: translateY(0) scale(1);
}

.modal-icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 16px;
  font-size: 1.3rem;
}
.modal-icon.confirm {
  background: var(--warn-dim);
  border: 1px solid rgba(251, 191, 36, 0.2);
}
.modal-icon.success {
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.2);
}
.modal-icon.error {
  background: var(--danger-dim);
  border: 1px solid rgba(248, 113, 113, 0.2);
}

.modal-title {
  font-size: 1.1rem;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--text-1);
}

.modal-body {
  font-size: 0.9rem;
  color: var(--text-2);
  line-height: 1.6;
  margin-bottom: 24px;
}
.modal-body code {
  background: var(--bg-3);
  padding: 2px 6px;
  border-radius: 3px;
  font-size: 0.87rem;
  color: var(--text-1);
}

.modal-actions {
  display: flex;
  gap: 10px;
  justify-content: flex-end;
}

.modal-btn {
  padding: 9px 22px;
  border-radius: var(--radius-sm);
  font-family: var(--font-ui);
  font-size: 0.88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  border: 1px solid transparent;
}
.modal-btn-cancel {
  background: var(--bg-3);
  color: var(--text-2);
  border-color: var(--border);
}
.modal-btn-cancel:hover {
  background: var(--bg-2);
  color: var(--text-1);
  border-color: var(--border-bright);
}
.modal-btn-confirm {
  background: var(--warning);
  color: var(--bg-0);
}
.modal-btn-confirm:hover {
  filter: brightness(1.1);
}
.modal-btn-ok {
  background: var(--accent);
  color: var(--bg-0);
}
.modal-btn-ok:hover {
  filter: brightness(1.1);
}
.modal-btn-danger {
  background: var(--danger);
  color: #fff;
}
.modal-btn-danger:hover {
  filter: brightness(1.1);
}

/* === Toast === */

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

.toast {
  padding: 14px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 10px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.4);
  transform: translateX(120%);
  transition: transform 0.25s cubic-bezier(0.22, 1, 0.36, 1);
  max-width: 380px;
}
.toast.show { transform: translateX(0); }
.toast.success {
  background: #0b2922;
  border: 1px solid rgba(52, 211, 153, 0.25);
  color: var(--success);
}
.toast.error {
  background: #2a1015;
  border: 1px solid rgba(248, 113, 113, 0.25);
  color: var(--danger);
}
.toast-icon { font-size: 1.1rem; flex-shrink: 0; }

/* === Footer === */

footer {
  margin-top: 56px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  text-align: center;
  font-size: 0.78rem;
  color: var(--text-3);
}

/* === Responsive === */

@media (max-width: 768px) {
  html { font-size: 16px; }
  .app { padding: 16px; }
  .overview { grid-template-columns: repeat(2, 1fr); }
  .stack-grid { grid-template-columns: 1fr; }
  .node-grid { grid-template-columns: 1fr; }
  .node-details { grid-template-columns: 1fr; }
  nav { overflow-x: auto; flex-wrap: nowrap; }
  nav button { white-space: nowrap; padding: 10px 14px; }
}

@media (max-width: 480px) {
  .overview { grid-template-columns: 1fr 1fr; }
  .header-right { gap: 8px; }
}
