:root {
  --bg: var(--tg-theme-bg-color, #0d1017);
  --surface: var(--tg-theme-secondary-bg-color, #161b26);
  --text: var(--tg-theme-text-color, #f3f4f6);
  --muted: var(--tg-theme-hint-color, #9ca3af);
  --accent: var(--tg-theme-button-color, #3b82f6);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --border: rgba(255, 255, 255, 0.08);
  --green: #22c55e;
  --red: #ef4444;
  --yellow: #eab308;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

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

.app {
  max-width: 680px;
  margin: 0 auto;
  padding: 16px 14px 40px;
}

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

.header-top h1 {
  font-size: 20px;
  font-weight: 700;
}

.refresh-btn {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 10px;
  width: 36px;
  height: 36px;
  font-size: 16px;
  cursor: pointer;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
}

.stat-label {
  font-size: 11px;
  color: var(--muted);
  margin-bottom: 4px;
}

.stat-val {
  font-size: 13px;
  font-weight: 700;
  margin-bottom: 6px;
}

.bar {
  height: 4px;
  background: rgba(255, 255, 255, 0.08);
  border-radius: 999px;
  overflow: hidden;
}

.bar-fill {
  height: 100%;
  background: var(--accent);
  width: 0%;
  transition: width 0.3s ease;
}

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

.tab {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
  border-radius: 999px;
  padding: 6px 14px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}

.tab.active {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.unit-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
}

.unit-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 6px;
}

.unit-title-wrap {
  display: flex;
  align-items: center;
  gap: 8px;
  min-width: 0;
}

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

.dot.running { background: var(--green); box-shadow: 0 0 8px rgba(34, 197, 94, 0.5); }
.dot.failed { background: var(--red); box-shadow: 0 0 8px rgba(239, 68, 68, 0.5); }
.dot.stopped { background: var(--muted); }
.dot.other { background: var(--yellow); }

.unit-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.kind-badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: 999px;
  border: 1px solid var(--border);
  color: var(--muted);
  flex-shrink: 0;
}

.unit-meta {
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 10px;
}

.unit-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.act-btn {
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  border-radius: 9px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 500;
  cursor: pointer;
}

.act-btn:disabled {
  opacity: 0.4;
  cursor: wait;
}

.empty {
  text-align: center;
  color: var(--muted);
  padding: 40px 16px;
  font-size: 14px;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.78);
}

.modal-content {
  position: relative;
  width: 100%;
  max-width: 600px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 12px;
  z-index: 1;
}

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

.modal-title {
  font-size: 14px;
  font-weight: 600;
}

.modal-btns {
  display: flex;
  gap: 6px;
}

.btn-sm {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  cursor: pointer;
}

.logs-body {
  background: #090b10;
  color: #d1d5db;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  line-height: 1.45;
  max-height: 62vh;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
}

.env-editor {
  width: 100%;
  height: 50vh;
  background: #090b10;
  color: #e5e7eb;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 12px;
  resize: none;
  outline: none;
  margin-bottom: 10px;
}

.env-actions {
  display: flex;
  gap: 8px;
}

.btn-primary,
.btn-accent {
  flex: 1;
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary {
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
}

.btn-accent {
  background: var(--accent);
  color: var(--accent-text);
  border-color: transparent;
}

.hidden {
  display: none !important;
}
