:root {
  --bg: #0a0b0d;
  --bg-elev: #111317;
  --bg-elev-2: #16181d;
  --surface: #131519;
  --border: #23262d;
  --border-soft: #1b1e24;
  --text: #e8eaed;
  --text-dim: #9aa0aa;
  --text-faint: #6b7280;
  --white: #ffffff;
  --ok: #34d399;
  --warn: #fbbf24;
  --danger: #f87171;
  --info: #60a5fa;
  --accent: #e8eaed;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.35);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --mono: 'SF Mono', ui-monospace, 'JetBrains Mono', 'Fira Code', Menlo, Consolas, monospace;
  --nav-w: 232px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

a { color: inherit; text-decoration: none; }
button { font-family: inherit; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a2e36; border-radius: 8px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #363b45; }

/* ---------------- Layout ---------------- */
.app { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--nav-w);
  background: linear-gradient(180deg, #0d0f12 0%, #0a0b0d 100%);
  border-right: 1px solid var(--border-soft);
  padding: 20px 14px;
  position: fixed;
  inset: 0 auto 0 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 6px 10px 18px;
}
.brand .logo {
  width: 34px; height: 34px; border-radius: 10px;
  background: linear-gradient(135deg, #23262d, #0e0f12);
  border: 1px solid var(--border);
  display: grid; place-items: center;
  font-weight: 700; color: var(--white); font-size: 15px;
  letter-spacing: -0.5px;
}
.brand .name { font-weight: 650; letter-spacing: -0.2px; }
.brand .sub { font-size: 11.5px; color: var(--text-faint); margin-top: -2px; }

.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 10px 12px;
  border-radius: var(--radius-sm);
  color: var(--text-dim);
  font-weight: 500;
  font-size: 14px;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background .16s ease, color .16s ease, border-color .16s ease;
}
.nav-item:hover { background: var(--bg-elev); color: var(--text); }
.nav-item.active { background: var(--bg-elev-2); color: var(--white); border-color: var(--border); }
.nav-item .ico { width: 18px; height: 18px; flex: none; opacity: .85; }
.nav-spacer { flex: 1; }

.sidebar-foot { border-top: 1px solid var(--border-soft); padding-top: 12px; }
.user-line { display: flex; align-items: center; gap: 9px; padding: 6px 10px; font-size: 13px; color: var(--text-dim); }
.user-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--ok); box-shadow: 0 0 8px var(--ok); }

.main { flex: 1; margin-left: var(--nav-w); min-width: 0; display: flex; flex-direction: column; }

.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: center; gap: 14px;
  padding: 14px 26px;
  background: rgba(10, 11, 13, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border-soft);
}
.topbar h1 { font-size: 17px; font-weight: 620; margin: 0; letter-spacing: -0.2px; }
.topbar .meta { color: var(--text-faint); font-size: 12.5px; }
.topbar .right { margin-left: auto; display: flex; align-items: center; gap: 12px; }

.menu-btn {
  display: none; background: var(--bg-elev); border: 1px solid var(--border);
  color: var(--text); width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
  place-items: center;
}

.content { padding: 24px 26px 60px; max-width: 1240px; width: 100%; margin: 0 auto; }

/* ---------------- Cards / grid ---------------- */
.grid { display: grid; gap: 16px; }
.grid.cols-2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.cols-3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.cols-4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }

.card {
  background: linear-gradient(180deg, var(--bg-elev) 0%, var(--surface) 100%);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  padding: 18px;
  box-shadow: var(--shadow);
}
.card.tight { padding: 14px; }
.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.card-head h3 { margin: 0; font-size: 13px; font-weight: 600; color: var(--text-dim); text-transform: uppercase; letter-spacing: .6px; }
.card-head .right { margin-left: auto; }

.stat { display: flex; flex-direction: column; gap: 6px; }
.stat .label { font-size: 12px; color: var(--text-faint); text-transform: uppercase; letter-spacing: .5px; }
.stat .value { font-size: 26px; font-weight: 660; letter-spacing: -0.5px; }
.stat .value.sm { font-size: 19px; }
.stat .hint { font-size: 12px; color: var(--text-faint); }

/* ---------------- Status ---------------- */
.badge {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 5px 11px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  border: 1px solid var(--border); background: var(--bg-elev-2); color: var(--text-dim);
}
.badge .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-faint); }
.badge.online { color: var(--ok); border-color: rgba(52, 211, 153, .3); background: rgba(52, 211, 153, .08); }
.badge.online .dot { background: var(--ok); box-shadow: 0 0 10px var(--ok); animation: pulse 2s infinite; }
.badge.stopped { color: var(--text-dim); }
.badge.errored { color: var(--danger); border-color: rgba(248, 113, 113, .3); background: rgba(248, 113, 113, .08); }
.badge.errored .dot { background: var(--danger); }
.badge.starting, .badge.stopping, .badge.waiting_restart { color: var(--warn); border-color: rgba(251, 191, 36, .3); background: rgba(251, 191, 36, .08); }
.badge.starting .dot, .badge.stopping .dot, .badge.waiting_restart .dot { background: var(--warn); }
.badge.not_found { color: var(--warn); }

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

.hero-status { display: flex; align-items: center; gap: 18px; flex-wrap: wrap; }
.hero-status .big { font-size: 40px; font-weight: 700; letter-spacing: -1px; }

/* ---------------- Progress ---------------- */
.bar { height: 7px; border-radius: 999px; background: var(--bg-elev-2); overflow: hidden; border: 1px solid var(--border-soft); }
.bar > span { display: block; height: 100%; background: linear-gradient(90deg, #4b5563, #9ca3af); transition: width .5s ease; }
.bar.ok > span { background: linear-gradient(90deg, #10b981, #34d399); }
.bar.warn > span { background: linear-gradient(90deg, #d97706, #fbbf24); }
.bar.danger > span { background: linear-gradient(90deg, #b91c1c, #f87171); }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 10px 15px; border-radius: 10px; font-size: 14px; font-weight: 560;
  border: 1px solid var(--border); background: var(--bg-elev-2); color: var(--text);
  cursor: pointer; transition: transform .08s ease, background .16s ease, border-color .16s ease, opacity .16s;
  white-space: nowrap;
}
.btn:hover { background: #1c1f26; border-color: #2c313a; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--white); color: #0a0b0d; border-color: var(--white); font-weight: 640; }
.btn.primary:hover { background: #e2e4e8; }
.btn.danger { color: var(--danger); border-color: rgba(248,113,113,.3); background: rgba(248,113,113,.07); }
.btn.danger:hover { background: rgba(248,113,113,.14); }
.btn.ok { color: var(--ok); border-color: rgba(52,211,153,.3); background: rgba(52,211,153,.07); }
.btn.ok:hover { background: rgba(52,211,153,.14); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 7px 11px; font-size: 13px; border-radius: 9px; }
.btn.block { width: 100%; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

.spinner {
  width: 14px; height: 14px; border-radius: 50%;
  border: 2px solid rgba(255,255,255,.25); border-top-color: currentColor;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------------- Forms ---------------- */
.field { display: flex; flex-direction: column; gap: 7px; margin-bottom: 15px; }
.field label { font-size: 13px; color: var(--text-dim); font-weight: 550; }
.input {
  width: 100%; padding: 11px 13px; border-radius: 10px;
  background: #0c0d10; border: 1px solid var(--border); color: var(--text);
  font-size: 14.5px; font-family: inherit; outline: none; transition: border-color .16s, box-shadow .16s;
}
.input:focus { border-color: #3a4150; box-shadow: 0 0 0 3px rgba(96,165,250,.12); }

/* ---------------- Logs ---------------- */
.log-toolbar { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 13px; }
.seg { display: inline-flex; background: var(--bg-elev-2); border: 1px solid var(--border); border-radius: 10px; padding: 3px; }
.seg button {
  border: 0; background: transparent; color: var(--text-dim); padding: 7px 13px;
  border-radius: 8px; font-size: 13px; font-weight: 550; cursor: pointer;
}
.seg button.active { background: var(--bg); color: var(--white); }

.log-view {
  font-family: var(--mono); font-size: 12.5px; line-height: 1.55;
  background: #08090b; border: 1px solid var(--border-soft); border-radius: 12px;
  padding: 12px; height: 60vh; min-height: 320px; overflow: auto; white-space: pre-wrap; word-break: break-word;
}
.log-line { display: block; padding: 1px 4px; border-radius: 4px; }
.log-line .ts { color: var(--text-faint); }
.log-line.err { color: #fca5a5; background: rgba(248,113,113,.06); }
.log-line.empty { color: var(--text-faint); font-style: italic; }

/* ---------------- Table ---------------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th { text-align: left; color: var(--text-faint); font-weight: 600; font-size: 12px; text-transform: uppercase; letter-spacing: .5px; padding: 9px 12px; border-bottom: 1px solid var(--border); }
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border-soft); }
.table tr:last-child td { border-bottom: 0; }
.table .k { color: var(--text-dim); }
.mono { font-family: var(--mono); font-size: 12.5px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 320px; display: inline-block; vertical-align: bottom; }

/* ---------------- Toasts ---------------- */
.toasts { position: fixed; right: 18px; bottom: 18px; display: flex; flex-direction: column; gap: 10px; z-index: 90; max-width: min(92vw, 380px); }
.toast {
  background: var(--bg-elev-2); border: 1px solid var(--border); border-left: 3px solid var(--text-dim);
  border-radius: 12px; padding: 13px 15px; box-shadow: var(--shadow); animation: slideIn .22s ease;
  display: flex; gap: 11px; align-items: flex-start;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
.toast.warn { border-left-color: var(--warn); }
.toast.info { border-left-color: var(--info); }
.toast .t-title { font-weight: 620; font-size: 13.5px; margin-bottom: 2px; }
.toast .t-msg { font-size: 13px; color: var(--text-dim); }
@keyframes slideIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------- Modal ---------------- */
.modal-back {
  position: fixed; inset: 0; background: rgba(0,0,0,.6); backdrop-filter: blur(3px);
  display: grid; place-items: center; z-index: 100; padding: 18px; animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--bg-elev); border: 1px solid var(--border); border-radius: 16px;
  padding: 22px; max-width: 440px; width: 100%; box-shadow: var(--shadow);
}
.modal h3 { margin: 0 0 8px; font-size: 17px; }
.modal p { color: var(--text-dim); font-size: 14px; margin: 0 0 18px; }
.modal .actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---------------- Login ---------------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 20px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .brand { justify-content: center; padding-bottom: 10px; }
.login-err { color: var(--danger); font-size: 13px; min-height: 18px; margin: 4px 0 8px; }

/* ---------------- Misc ---------------- */
.muted { color: var(--text-faint); }
.row { display: flex; align-items: center; gap: 10px; }
.between { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.wrap { flex-wrap: wrap; }
.mt { margin-top: 16px; }
.mb { margin-bottom: 16px; }
.loading-box { display: grid; place-items: center; padding: 48px; color: var(--text-faint); gap: 12px; }
.offline-banner {
  background: rgba(251,191,36,.08); border: 1px solid rgba(251,191,36,.3); color: var(--warn);
  border-radius: 10px; padding: 10px 14px; font-size: 13px; margin-bottom: 16px; display: none;
}
.chip { display: inline-block; padding: 3px 9px; border-radius: 7px; background: var(--bg-elev-2); border: 1px solid var(--border-soft); font-size: 12px; color: var(--text-dim); }
.spark { width: 100%; height: 54px; display: block; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.5); z-index: 35; display: none; }

/* ---------------- Responsive ---------------- */
@media (max-width: 980px) {
  .grid.cols-4 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .grid.cols-3 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .sidebar { transform: translateX(-100%); transition: transform .22s ease; }
  .sidebar.open { transform: none; }
  .main { margin-left: 0; }
  .menu-btn { display: grid; }
  .overlay.show { display: block; }
  .content { padding: 18px 15px 60px; }
  .topbar { padding: 12px 15px; }
  .grid.cols-2, .grid.cols-3, .grid.cols-4 { grid-template-columns: 1fr; }
  .stat .value { font-size: 23px; }
  .hero-status .big { font-size: 32px; }
}
