@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;650;700&display=swap');

:root {
  --bg: #313338;
  --bg-deep: #1e1f22;
  --sidebar: #2b2d31;
  --panel: #313338;
  --panel-alt: #2b2d31;
  --panel-hover: #3b3d44;
  --border: #1f2023;
  --text: #f2f3f5;
  --muted: #b5bac1;
  --muted-dim: #949ba4;
  --accent: #5865f2;
  --accent-hover: #4752c4;
  --accent-soft: rgba(88, 101, 242, .16);
  --ok: #23a559;
  --ok-soft: rgba(35, 165, 89, .16);
  --warn: #f0b232;
  --warn-soft: rgba(240, 178, 50, .16);
  --danger: #f23f42;
  --danger-soft: rgba(242, 63, 66, .16);
  --radius: 6px;
  --radius-sm: 4px;
  --mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
  --sans: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; min-height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
a { color: var(--accent); }
button, input, select, textarea { font-family: var(--sans); }
button { -webkit-tap-highlight-color: transparent; }

h1, h2, h3 { margin: 0; font-weight: 650; color: var(--text); }
p { color: var(--muted); line-height: 1.45; margin: 4px 0 0; font-size: 13px; }

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #1f2023; border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: #18191c; }

.hidden { display: none !important; }

/* Layout */
.app-shell { display: flex; min-height: 100vh; background: var(--bg); }

.sidebar {
  width: 240px;
  flex: 0 0 240px;
  min-height: 100vh;
  background: var(--sidebar);
  border-right: 1px solid rgba(0,0,0,.18);
  padding: 12px 10px;
  display: flex;
  flex-direction: column;
}

.brand {
  height: 52px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--text);
  font-size: 15px;
  font-weight: 700;
  border-bottom: 1px solid rgba(255,255,255,.04);
  margin-bottom: 10px;
}

.brand .mark,
.auth-logo .mark {
  position: relative;
  width: 30px;
  height: 30px;
  flex: 0 0 30px;
  border-radius: 9px;
  background: var(--accent);
  box-shadow: none;
}

.brand .mark::before,
.auth-logo .mark::before {
  content: '';
  position: absolute;
  width: 14px;
  height: 10px;
  left: 8px;
  top: 8px;
  border: 2px solid #fff;
  border-radius: 7px 7px 6px 6px;
}

.brand .mark::after,
.auth-logo .mark::after {
  content: '';
  position: absolute;
  width: 5px;
  height: 5px;
  left: 11px;
  top: 11px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 7px 0 #fff;
}

.nav-item {
  min-height: 38px;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 0 11px;
  margin: 2px 0;
  border-radius: var(--radius);
  color: var(--muted);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  cursor: pointer;
  border: 0;
  transition: background .12s ease, color .12s ease;
}

.nav-item::before {
  content: '';
  width: 3px;
  height: 16px;
  margin-left: -11px;
  border-radius: 0 3px 3px 0;
  background: transparent;
}

.nav-item:hover {
  background: rgba(255,255,255,.04);
  color: var(--text);
}

.nav-item.active {
  background: var(--panel-hover);
  color: #fff;
}

.nav-item.active::before { background: var(--accent); }

.sidebar-footer {
  margin-top: auto;
  padding: 10px 0 0;
  border-top: 1px solid rgba(255,255,255,.05);
}

.user-chip {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 8px;
  min-width: 0;
}

.user-chip > div:last-child { min-width: 0; }
.user-chip #sideUsername {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.avatar {
  width: 34px;
  height: 34px;
  flex: 0 0 34px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 650;
  font-size: 12px;
  border: 0;
}

.logout-btn {
  width: 100%;
  margin-top: 6px;
  justify-content: flex-start !important;
  padding-left: 10px !important;
}

.main {
  flex: 1;
  min-width: 0;
  padding: 32px 36px 70px;
}

.main > * {
  width: min(1180px, 100%);
  margin-left: auto;
  margin-right: auto;
}

.page-header {
  margin-bottom: 22px;
  padding-bottom: 16px;
  border-bottom: 1px solid rgba(255,255,255,.05);
}

.page-header .eyebrow {
  font-size: 11px;
  color: var(--muted-dim);
  text-transform: uppercase;
  letter-spacing: .06em;
  font-weight: 650;
  margin-bottom: 5px;
}

.page-header h1 { font-size: 24px; letter-spacing: -.02em; }
.page-header p { margin-top: 6px; max-width: 700px; }

.topbar {
  display: none;
  position: sticky;
  top: 0;
  z-index: 45;
  align-items: center;
  gap: 12px;
  background: var(--sidebar);
  border-bottom: 1px solid rgba(0,0,0,.2);
  padding: 10px 14px;
}

.hamburger-btn {
  width: 34px;
  height: 34px;
  border-radius: var(--radius);
  background: transparent;
  border: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 4px;
  cursor: pointer;
}
.hamburger-btn:hover { background: rgba(255,255,255,.05); }
.hamburger-btn span { width: 16px; height: 2px; background: var(--muted); border-radius: 1px; }

.drawer-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 49;
}
.drawer-backdrop.open { display: block; }

/* Panels / stats */
.card {
  background: var(--panel-alt);
  border: 0;
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: 0 1px 0 rgba(0,0,0,.2);
}

.grid { display: grid; gap: 12px; }
.grid-stats { grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); }

.stat-card {
  position: relative;
  min-height: 100px;
  background: var(--panel-alt);
  padding: 16px 18px;
  overflow: hidden;
}

.stat-card::after {
  content: '';
  position: absolute;
  right: 16px;
  bottom: -22px;
  width: 72px;
  height: 72px;
  border-radius: 50%;
  background: var(--accent-soft);
}

.stat-card .label {
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: .04em;
  font-weight: 650;
}

.stat-card .value {
  font-size: 24px;
  line-height: 1.1;
  font-weight: 700;
  margin-top: 9px;
  position: relative;
  z-index: 1;
}

/* Server cards */
.node-card {
  background: var(--panel-alt);
  border: 1px solid transparent;
  border-left: 3px solid #4e5058;
  border-radius: var(--radius);
  padding: 16px;
}
.node-card.status-running { border-left-color: var(--ok); }
.node-card.status-stopped { border-left-color: #4e5058; }
.node-card.status-suspended { border-left-color: var(--danger); }

.node-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}
.node-card-title { display: flex; align-items: center; gap: 9px; }
.node-card-title .name { font-weight: 650; font-size: 14px; }

.led {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.led.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.led.off { background: #747982; }
.led.bad { background: var(--danger); box-shadow: 0 0 0 3px var(--danger-soft); }

.badge {
  display: inline-flex;
  align-items: center;
  font-size: 11px;
  line-height: 1;
  min-height: 22px;
  padding: 0 8px;
  border-radius: 4px;
  border: 0;
  color: var(--muted);
  background: #1f2023;
  font-weight: 600;
}

.badge.lang-nodejs { color: #c9cdfd; background: var(--accent-soft); }
.badge.lang-python { color: #9fd6ff; background: rgba(52,152,219,.14); }
.badge.role-admin { color: #f5d18a; background: var(--warn-soft); }
.badge.state-ok { color: #8be1ad; background: var(--ok-soft); }
.badge.state-bad { color: #ff9b9d; background: var(--danger-soft); }

.meter-row { margin-top: 12px; }
.meter-label {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--muted);
  margin-bottom: 6px;
}
.meter {
  height: 6px;
  border-radius: 3px;
  background: #1f2023;
  overflow: hidden;
}
.meter-fill { height: 100%; background: var(--accent); }
.meter-fill.ok { background: var(--ok); }
.node-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* Buttons */
.btn {
  min-height: 36px;
  font-weight: 600;
  font-size: 13px;
  padding: 0 14px;
  border-radius: var(--radius);
  border: 0;
  background: #1e1f22;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  transition: background .12s ease, transform .05s ease;
}
.btn:hover { background: #191a1d; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-ok { background: var(--ok); color: #fff; }
.btn-danger { background: transparent; color: #ff8f91; }
.btn-danger:hover { background: var(--danger-soft); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: rgba(255,255,255,.05); color: var(--text); }
.btn-sm { min-height: 30px; padding: 0 10px; font-size: 12px; }
.btn-block { width: 100%; }

/* Inputs */
label {
  display: block;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 7px;
  font-weight: 600;
}

input[type=text],
input[type=password],
input[type=email],
input[type=number],
textarea,
select {
  width: 100%;
  background: #1e1f22;
  border: 1px solid #1e1f22;
  color: var(--text);
  padding: 10px 11px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 14px;
  outline: none;
  transition: border-color .12s ease, background .12s ease;
}

select {
  padding-right: 32px;
  appearance: none;
  -webkit-appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23b5bac1' stroke-width='1.4' fill='none' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 11px center;
}

input:hover, select:hover, textarea:hover { border-color: #404249; }
input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  background: #1e1f22;
  box-shadow: 0 0 0 1px var(--accent);
}

.field-row { display: flex; gap: 10px; }
.field-row > div { flex: 1; }
.field-hint { font-size: 11.5px; color: var(--muted-dim); margin: -8px 0 14px; }

.radio-lang { display: flex; gap: 8px; margin-bottom: 14px; }
.radio-lang label {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  background: #1e1f22;
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 12px;
  cursor: pointer;
  margin: 0;
  font-size: 12.5px;
  color: var(--text);
  transition: background .12s ease, border-color .12s ease;
}
.radio-lang label:hover { background: #191a1d; }
.radio-lang label.checked {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.radio-lang input { width: auto; margin: 0; accent-color: var(--accent); }

.preset-note {
  font-size: 12px;
  color: var(--muted);
  background: #1e1f22;
  border: 0;
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 12px;
  margin-bottom: 14px;
}

.search-bar { position: relative; margin-bottom: 16px; max-width: 360px; }
.search-bar input { margin-bottom: 0; padding-left: 34px; }
.search-bar::before {
  content: '';
  position: absolute;
  left: 11px;
  top: 50%;
  width: 12px;
  height: 12px;
  transform: translateY(-50%);
  border: 1.5px solid var(--muted-dim);
  border-radius: 50%;
  box-shadow: 3px 3px 0 -1.5px var(--muted-dim);
  z-index: 2;
}

.pin-chip {
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 650;
  color: var(--text);
  background: #1e1f22;
  border: 0;
  padding: 7px 10px;
  border-radius: var(--radius);
  display: inline-block;
}

/* Tables */
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--muted-dim);
  padding: 9px 10px;
  border-bottom: 1px solid rgba(255,255,255,.06);
}
td {
  padding: 11px 10px;
  border-bottom: 1px solid rgba(255,255,255,.05);
  vertical-align: middle;
}
tbody tr:hover { background: rgba(255,255,255,.025); }
tr:last-child td { border-bottom: 0; }
.table-wrap { overflow-x: auto; }

/* Console */
.console {
  background: #111214;
  border: 0;
  border-radius: var(--radius);
  padding: 12px;
  font-family: var(--mono);
  font-size: 12px;
  color: #b5bac1;
  height: 240px;
  overflow-y: auto;
  white-space: pre-wrap;
  word-break: break-word;
}
.console .line { color: #8be1ad; }

/* Toasts */
.toast-wrap {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: #111214;
  border: 0;
  border-left: 3px solid var(--accent);
  padding: 11px 14px;
  border-radius: var(--radius);
  font-size: 13px;
  min-width: 230px;
  box-shadow: 0 8px 24px rgba(0,0,0,.28);
}
.toast.error { border-left-color: var(--danger); }
.toast.success { border-left-color: var(--ok); }

/* Empty / modal */
.empty-state { text-align: center; padding: 44px 16px; color: var(--muted); }
.empty-state h3 { color: var(--text); margin-bottom: 6px; font-size: 15px; }

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.72);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 80;
  padding: 16px;
}

.modal {
  background: var(--sidebar);
  border: 1px solid #3a3c42;
  border-radius: 8px;
  padding: 20px;
  width: 100%;
  max-width: 430px;
  box-shadow: 0 18px 45px rgba(0,0,0,.4);
}
.modal h3 { margin-bottom: 16px; font-size: 16px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 8px; }

.account-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex-wrap: wrap;
}
.account-card .info h3 { font-size: 14px; margin-bottom: 4px; }
.account-card .info p { max-width: 620px; }

.slot-grid { display: grid; gap: 8px; }

.slot-card {
  background: var(--panel-alt);
  border: 1px solid transparent;
  border-radius: var(--radius);
  padding: 13px 14px;
  min-height: 68px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}
.slot-card:hover { border-color: #41434a; background: #303136; }
.slot-card.empty {
  border-style: dashed;
  border-color: #4a4c53;
  background: rgba(43,45,49,.55);
}
.slot-card .slot-left { display: flex; align-items: center; gap: 12px; }
.slot-card .slot-index {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  background: #1e1f22;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  color: var(--muted);
  flex-shrink: 0;
  font-weight: 650;
}
.slot-card .slot-name { font-weight: 650; font-size: 14px; }
.slot-card .slot-meta { font-size: 11.5px; color: var(--muted-dim); margin-top: 3px; }

.detail-back {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 12.5px;
  cursor: pointer;
  margin-bottom: 14px;
}
.detail-back:hover { color: #fff; }

.slots-input {
  width: 64px !important;
  margin-bottom: 0 !important;
  padding: 5px 7px !important;
  text-align: center;
}

/* Auth */
.auth-shell {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: var(--bg-deep);
}

.auth-card {
  width: 100%;
  max-width: 420px;
  background: var(--sidebar);
  padding: 26px;
  border-radius: 8px;
  box-shadow: 0 18px 45px rgba(0,0,0,.35);
}

.auth-logo {
  display: flex;
  align-items: center;
  gap: 10px;
  justify-content: center;
  margin-bottom: 14px;
}

.auth-logo .mark { width: 34px; height: 34px; flex-basis: 34px; border-radius: 10px; }
.auth-logo .mark::before { left: 9px; top: 9px; }
.auth-logo .mark::after { left: 12px; top: 12px; }

.auth-title {
  font-weight: 650;
  font-size: 20px;
  text-align: center;
  letter-spacing: -.02em;
}

.auth-sub {
  text-align: center;
  margin: 6px 0 22px;
  color: var(--muted);
}

.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: #1e1f22;
  border-radius: var(--radius);
  padding: 3px;
  margin-bottom: 20px;
}
.auth-tab {
  text-align: center;
  padding: 8px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  color: var(--muted);
  transition: background .12s ease, color .12s ease;
}
.auth-tab.active {
  background: var(--accent);
  color: #fff;
}

.auth-hint {
  font-size: 11.5px;
  color: var(--muted-dim);
  text-align: center;
  margin-top: 14px;
}

.pending-box { text-align: center; padding: 6px 4px 4px; }
.pending-box .icon {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  margin: 0 auto 14px;
  background: var(--accent-soft);
  display: flex;
  align-items: center;
  justify-content: center;
}
.pending-box .icon span {
  width: 18px;
  height: 12px;
  border: 1.5px solid var(--accent);
  border-top: none;
  border-radius: 0 0 2px 2px;
  position: relative;
}
.pending-box .icon span::before {
  content: '';
  position: absolute;
  top: -1.5px;
  left: -1.5px;
  right: -1.5px;
  height: 1.5px;
  background: var(--accent);
}

/* Responsive */
@media (max-width: 860px) {
  .topbar { display: flex; }
  .sidebar {
    display: flex;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 50;
    transform: translateX(-100%);
    transition: transform .16s ease;
    width: 260px;
  }
  .sidebar.open { transform: translateX(0); }
  .main { padding: 24px 16px 60px; }
}

@media (max-width: 560px) {
  .main { padding: 18px 12px 50px; }
  .page-header h1 { font-size: 21px; }
  .grid-stats { grid-template-columns: 1fr 1fr; gap: 8px; }
  .stat-card { min-height: 90px; padding: 13px; }
  .stat-card .value { font-size: 20px; }
  .field-row { flex-direction: column; gap: 0; }
  .radio-lang { flex-direction: column; }
  .auth-shell { padding: 14px; }
  .auth-card { padding: 20px 16px; }
}

@media (max-width: 860px) {
  table, thead, tbody, th, td, tr { display: block; }
  thead { display: none; }
  .table-wrap tr {
    border: 1px solid #3a3c42;
    border-radius: var(--radius);
    margin-bottom: 8px;
    padding: 8px 10px;
    background: #2b2d31;
  }
  .table-wrap td {
    border: none;
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 2px;
    font-size: 13px;
  }
  .table-wrap td::before {
    content: attr(data-label);
    color: var(--muted);
    font-size: 11px;
    font-weight: 600;
  }
}
