:root {
  --bg:     #0d1117;
  --surf:   #161b22;
  --surf2:  #21262d;
  --border: #30363d;
  --text:   #e6edf3;
  --muted:  #7d8590;
  --green:  #3fb950;
  --red:    #f85149;
  --yellow: #d29922;
  --blue:   #388bfd;
  --purple: #bc8cff;
  --orange: #f78166;
}

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

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

/* ── Login ── */
#login-screen {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
}

.login-card {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 2rem;
  width: 100%;
  max-width: 360px;
}

.login-logo {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: 1.1rem;
  font-weight: 600;
  margin-bottom: 1.75rem;
}
.login-logo svg { color: var(--blue); }

.login-card h2 {
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1.25rem;
}

.field { margin-bottom: .9rem; }
.field label {
  display: block;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .05em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: .3rem;
}
.field input {
  width: 100%;
  padding: .6rem .75rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--text);
  font-size: .875rem;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.field input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px #388bfd22; }
.field input.err  { border-color: var(--red); }

.login-err {
  font-size: .75rem;
  color: var(--red);
  min-height: 1rem;
  margin-bottom: .75rem;
}

.btn-login {
  width: 100%;
  padding: .65rem;
  border: none;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  font-size: .875rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
}
.btn-login:hover:not(:disabled) { opacity: .88; }
.btn-login:disabled { opacity: .5; cursor: not-allowed; }

/* ── App ── */
#app { display: none; flex-direction: column; min-height: 100vh; }

header {
  background: var(--surf);
  border-bottom: 1px solid var(--border);
  padding: 0 1.5rem;
  height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  display: flex;
  align-items: center;
  gap: .6rem;
  font-size: 1rem;
  font-weight: 600;
}
.logo svg { color: var(--blue); }

.header-right {
  display: flex;
  align-items: center;
  gap: .75rem;
}

.user-badge {
  display: flex;
  align-items: center;
  gap: .5rem;
  font-size: .78rem;
  color: var(--muted);
}

.group-tag {
  font-size: .68rem;
  font-weight: 600;
  padding: 2px 7px;
  border-radius: 4px;
  background: #388bfd22;
  color: var(--blue);
  text-transform: uppercase;
  letter-spacing: .04em;
}

.refresh-badge {
  display: flex;
  align-items: center;
  gap: .4rem;
  font-size: .72rem;
  color: var(--muted);
}

.pulse { width: 7px; height: 7px; border-radius: 50%; background: var(--green); }
.pulse.live { animation: blink 2.4s ease-in-out infinite; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:.35} }

.btn-logout {
  padding: .35rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: .75rem;
  cursor: pointer;
  transition: all .15s;
}
.btn-logout:hover { border-color: var(--red); color: var(--red); background: #f8514910; }


.lang-select {
  padding: .3rem .5rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surf2);
  color: var(--muted);
  font-size: .75rem;
  cursor: pointer;
  outline: none;
  transition: border-color .15s, color .15s;
}
.lang-select:hover, .lang-select:focus { border-color: var(--blue); color: var(--text); }

/* ── User menu ── */
.user-menu-wrap { position: relative; }

.user-clickable {
  cursor: pointer;
  border-bottom: 1px dotted var(--muted);
  transition: color .15s, border-color .15s;
}
.user-clickable:hover { color: var(--text); border-color: var(--text); }

.user-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .3rem;
  min-width: 170px;
  z-index: 30;
  box-shadow: 0 8px 24px rgba(0,0,0,.4);
  animation: pop .15s ease;
}

.user-menu button {
  display: flex;
  align-items: center;
  gap: .5rem;
  width: 100%;
  padding: .5rem .75rem;
  border: none;
  background: transparent;
  color: var(--text);
  font-size: .82rem;
  cursor: pointer;
  border-radius: 6px;
  text-align: left;
  transition: background .1s;
}
.user-menu button:hover { background: var(--surf2); }

/* ── Grid ── */
main {
  padding: 2rem 1.5rem;
  max-width: 1280px;
  margin: 0 auto;
  width: 100%;
}

.section-title {
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 1.25rem;
}

#grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 1rem;
}

/* ── Card ── */
.card {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  transition: border-color .2s, box-shadow .2s;
}
.card:hover { border-color: #388bfd55; box-shadow: 0 0 0 3px #388bfd18; }

.card-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: .5rem;
}

.vm-name { font-size: 1rem; font-weight: 600; word-break: break-word; }

.vm-meta {
  display: flex;
  align-items: center;
  gap: .35rem;
  margin-top: .25rem;
  flex-wrap: wrap;
}

.badge {
  font-size: .68rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 4px;
  text-transform: uppercase;
  letter-spacing: .04em;
}
.badge-qemu { background: #388bfd22; color: var(--blue); }
.badge-lxc  { background: #bc8cff22; color: var(--purple); }
.badge-id   { background: var(--surf2); color: var(--muted); }
.badge-node { background: var(--surf2); color: var(--muted); }

.status-pill {
  display: flex;
  align-items: center;
  gap: .35rem;
  font-size: .72rem;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
  flex-shrink: 0;
}
.status-pill.running   { background: #3fb95018; color: var(--green);  border: 1px solid #3fb95040; }
.status-pill.stopped   { background: #f8514918; color: var(--red);    border: 1px solid #f8514940; }
.status-pill.paused,
.status-pill.suspended { background: #d2992218; color: var(--yellow); border: 1px solid #d2992240; }
.status-pill.unknown   { background: var(--surf2); color: var(--muted); border: 1px solid var(--border); }
.status-pill .dot { width: 5px; height: 5px; border-radius: 50%; background: currentColor; flex-shrink: 0; }
.status-pill.running .dot { animation: blink 2s infinite; }

.metrics { margin-top: 1rem; display: flex; flex-direction: column; gap: .55rem; }
.metric-row { display: flex; flex-direction: column; gap: .2rem; }
.metric-label { display: flex; justify-content: space-between; font-size: .72rem; color: var(--muted); }
.bar { height: 3px; background: var(--surf2); border-radius: 999px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 999px; transition: width .6s ease; }
.bar-fill.cpu { background: var(--blue); }
.bar-fill.mem { background: var(--purple); }

.actions { display: flex; gap: .4rem; margin-top: 1.1rem; }

.btn-action {
  flex: 1;
  padding: .45rem .2rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surf2);
  color: var(--text);
  font-size: .75rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s, color .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .25rem;
}
.btn-action:disabled { opacity: .28; cursor: not-allowed; pointer-events: none; }
.btn-action.start:not(:disabled):hover   { border-color: var(--green);  background: #3fb95015; color: var(--green); }
.btn-action.stop:not(:disabled):hover    { border-color: var(--red);    background: #f8514915; color: var(--red); }
.btn-action.restart:not(:disabled):hover { border-color: var(--yellow); background: #d2992215; color: var(--yellow); }
.btn-action.reset:not(:disabled):hover   { border-color: var(--orange); background: #f7816615; color: var(--orange); }

.spin {
  display: inline-block;
  width: 10px; height: 10px;
  border: 2px solid currentColor;
  border-top-color: transparent;
  border-radius: 50%;
  animation: spin .6s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.placeholder { grid-column: 1/-1; padding: 3rem; text-align: center; color: var(--muted); }

/* ── Confirm modal ── */
.overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  backdrop-filter: blur(6px);
  z-index: 50;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.overlay.open { display: flex; }

.modal {
  background: var(--surf);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.75rem;
  width: 100%;
  max-width: 360px;
  animation: pop .18s ease;
}
@keyframes pop { from { transform: scale(.95); opacity: 0; } to { transform: scale(1); opacity: 1; } }

.modal-icon {
  width: 40px; height: 40px;
  border-radius: 8px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.2rem;
  margin-bottom: 1rem;
}
.modal-icon.start   { background: #3fb95018; }
.modal-icon.stop    { background: #f8514918; }
.modal-icon.restart { background: #d2992218; }
.modal-icon.reset   { background: #f7816618; }
.modal-icon.changepw { background: #388bfd18; }

.modal h2 { font-size: 1rem; font-weight: 600; margin-bottom: .3rem; }
.modal p  { font-size: .82rem; color: var(--muted); margin-bottom: 1.5rem; line-height: 1.5; }

.modal-err { font-size: .75rem; color: var(--red); min-height: 1rem; margin-bottom: .5rem; }

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

.btn-cancel {
  flex: 1;
  padding: .55rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  font-size: .82rem;
  cursor: pointer;
  transition: background .15s;
}
.btn-cancel:hover { background: var(--surf2); color: var(--text); }

.btn-confirm {
  flex: 2;
  padding: .55rem;
  border: none;
  border-radius: 6px;
  background: var(--blue);
  color: #fff;
  font-size: .82rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: .4rem;
}
.btn-confirm:disabled { opacity: .5; cursor: not-allowed; }
.btn-confirm:hover:not(:disabled) { opacity: .88; }

.modal-warning { color: var(--orange); margin-top: .3rem; display: block; }

/* Small inline-style replacements (kept out of markup for CSP) */
.mb-1  { margin-bottom: 1rem; }
.mb-05 { margin-bottom: .5rem; }
.spacer-sm { height: .75rem; }
.hidden { display: none; }
