:root {
  --bg:          #0f172a;
  --surface:     #1e293b;
  --surface2:    #273548;
  --border:      #334155;
  --accent:      #06b6d4;
  --accent-dark: #0891b2;
  --green:       #22c55e;
  --red:         #ef4444;
  --yellow:      #f59e0b;
  --text:        #f1f5f9;
  --muted:       #94a3b8;
  --radius:      12px;
}

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

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

.view { min-height: 100vh; }
.hidden { display: none !important; }

/* ===== LOGIN ===== */
#login-view {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: radial-gradient(ellipse 80% 50% at 50% -10%, rgba(6,182,212,0.12), transparent);
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2.5rem;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 25px 50px rgba(0,0,0,0.5);
}

.logo {
  text-align: center;
  margin-bottom: 2rem;
}
.logo svg { margin-bottom: 0.75rem; }
.logo h1 {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.025em;
}
.logo p {
  color: var(--muted);
  font-size: 0.8125rem;
  margin-top: 0.25rem;
}

.login-footer {
  text-align: center;
  color: var(--muted);
  font-size: 0.75rem;
  margin-top: 1.5rem;
}

/* ===== FORMS ===== */
.field { margin-bottom: 1rem; }
.field label {
  display: block;
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 0.375rem;
}
.field input,
.field select {
  width: 100%;
  padding: 0.625rem 0.875rem;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 0.9375rem;
  transition: border-color 0.15s;
  font-family: inherit;
}
.field input::placeholder { color: #475569; }
.field input:focus,
.field select:focus { outline: none; border-color: var(--accent); }

.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem 1rem;
}

.error-msg {
  color: var(--red);
  font-size: 0.8125rem;
  padding: 0.5rem 0.75rem;
  background: rgba(239,68,68,0.08);
  border: 1px solid rgba(239,68,68,0.2);
  border-radius: 6px;
  margin-bottom: 1rem;
}

/* ===== BUTTONS ===== */
.btn {
  padding: 0.5625rem 1.125rem;
  border-radius: 8px;
  font-size: 0.875rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: background 0.15s, border-color 0.15s, opacity 0.15s;
  font-family: inherit;
  display: inline-flex;
  align-items: center;
  gap: 0.375rem;
  white-space: nowrap;
}
.btn-primary { background: var(--accent); color: #0a0a0a; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); border-color: var(--accent-dark); }
.btn-ghost { background: transparent; border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface2); }
.btn-danger { background: rgba(239,68,68,0.15); border-color: rgba(239,68,68,0.3); color: var(--red); }
.btn-danger:hover { background: rgba(239,68,68,0.25); }
.btn-warn { background: rgba(245,158,11,0.12); border-color: rgba(245,158,11,0.25); color: var(--yellow); }
.btn-warn:hover { background: rgba(245,158,11,0.22); }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 0.8125rem; }
.btn-full { width: 100%; justify-content: center; }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ===== HEADER ===== */
.header {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1.5rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.header-left { display: flex; align-items: center; gap: 0.75rem; }
.header-title { font-size: 1rem; font-weight: 600; color: var(--accent); }
.header-right { display: flex; align-items: center; gap: 0.75rem; }
.user-name { font-size: 0.8125rem; color: var(--muted); }

/* ===== MAIN ===== */
.main { padding: 2rem 1.5rem; max-width: 1440px; margin: 0 auto; }
.devices-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(540px, 1fr));
  gap: 1.5rem;
}

/* ===== DEVICE CARD ===== */
.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  transition: border-color 0.3s;
}
.device-card.online  { border-color: #1e4d5a; }
.device-card.offline { border-color: #4a1a1a; }

.device-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.875rem 1rem;
  border-bottom: 1px solid var(--border);
}
.device-title-group {}
.device-title {
  display: flex;
  align-items: center;
  gap: 0.375rem;
  font-weight: 600;
  font-size: 0.9375rem;
}
.device-id {
  font-family: 'SFMono-Regular', 'Consolas', monospace;
  font-size: 0.6875rem;
  color: var(--muted);
  margin-top: 0.125rem;
}
.status-dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-dot.online  { background: var(--green); box-shadow: 0 0 6px var(--green); animation: pulse 2s infinite; }
.status-dot.offline { background: var(--red); }
.status-dot.unknown { background: var(--yellow); }

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

.uptime-badge {
  font-size: 0.6875rem;
  color: var(--muted);
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.2rem 0.5rem;
  font-variant-numeric: tabular-nums;
}

/* ===== SCREENSHOT ===== */
.screenshot-wrap {
  background: #000;
  position: relative;
  width: 100%;
  padding-bottom: 56.25%; /* 16:9 via padding trick — ensures height is always computed */
  height: 0;
  overflow: hidden;
  cursor: default;
}
.screenshot-img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  display: block;
}
.screenshot-overlay {
  position: absolute;
  inset: 0;
  z-index: 2;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.75rem;
  background: rgba(15,23,42,0.9);
  color: var(--muted);
  font-size: 0.8125rem;
}
.spinner {
  width: 28px; height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ===== SERVICES ===== */
.svc-row {
  display: flex;
  flex-wrap: wrap;
  gap: 0.375rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  align-items: center;
}
.svc-label {
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-right: 0.25rem;
}
.svc-badge {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  padding: 0.2rem 0.5rem;
  border-radius: 4px;
  font-size: 0.6875rem;
  font-weight: 500;
  background: var(--bg);
  border: 1px solid var(--border);
}
.svc-badge .dot { width: 5px; height: 5px; border-radius: 50%; flex-shrink: 0; }
.svc-badge.active   { border-color: rgba(34,197,94,0.25); }
.svc-badge.active .dot   { background: var(--green); }
.svc-badge.inactive { border-color: rgba(239,68,68,0.25); }
.svc-badge.inactive .dot { background: var(--red); }
.svc-badge.unknown  .dot { background: var(--yellow); }

/* ===== RESOURCES ===== */
.res-row {
  display: flex;
  gap: 1.5rem;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.res-item { display: flex; flex-direction: column; gap: 0.3rem; min-width: 80px; }
.res-item-label {
  font-size: 0.625rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.res-item-value {
  font-weight: 600;
  font-size: 0.8125rem;
  font-variant-numeric: tabular-nums;
}
.res-bar {
  height: 3px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  width: 72px;
}
.res-bar-fill { height: 100%; border-radius: 2px; transition: width 0.4s ease; }
.res-bar-fill.low    { background: var(--green); }
.res-bar-fill.medium { background: var(--yellow); }
.res-bar-fill.high   { background: var(--red); }

/* ===== ACTIONS ===== */
.actions-row {
  display: flex;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  flex-wrap: wrap;
}

/* ===== VITRINE URL ===== */
.vitrine-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.5rem 1rem 0.625rem;
  font-size: 0.75rem;
  color: var(--muted);
  border-top: 1px solid var(--border);
}
.vitrine-url {
  color: var(--accent);
  font-family: 'SFMono-Regular', 'Consolas', monospace;
  font-size: 0.6875rem;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 380px;
}

/* ===== EMPTY STATE ===== */
.empty-state {
  grid-column: 1 / -1;
  text-align: center;
  color: var(--muted);
  padding: 4rem 0;
  font-size: 0.9375rem;
}

/* ===== MODAL ===== */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  width: 100%;
  max-width: 480px;
  box-shadow: 0 25px 50px rgba(0,0,0,0.5);
}
.modal-wide { max-width: 620px; }
.modal h2 { font-size: 1.0625rem; font-weight: 600; margin-bottom: 0.25rem; }
.modal-subtitle { color: var(--muted); font-size: 0.8125rem; margin-bottom: 1.5rem; }
.modal-actions { display: flex; gap: 0.75rem; justify-content: flex-end; margin-top: 1.5rem; }

/* ===== TOASTS ===== */
.toast-container {
  position: fixed;
  top: 1rem;
  right: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  z-index: 200;
  pointer-events: none;
}
.toast {
  padding: 0.75rem 1.125rem;
  border-radius: 8px;
  font-size: 0.8125rem;
  font-weight: 500;
  min-width: 220px;
  border-left: 3px solid;
  animation: slideIn 0.2s ease;
}
.toast.success { background: #0d2219; border-color: var(--green); color: var(--green); }
.toast.error   { background: #280f0f; border-color: var(--red);   color: var(--red);   }
.toast.info    { background: #081929; border-color: var(--accent); color: var(--accent); }
@keyframes slideIn {
  from { transform: translateX(110%); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}

/* ===== VNC CONTAINER (embedded in card) ===== */
.vnc-container {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 1;
}
.vnc-container canvas {
  display: block;
}

/* ===== RENAME ===== */
.device-name-wrap {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-width: 0;
}
.btn-icon {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--muted);
  font-size: 0.8125rem;
  padding: 0.1rem 0.25rem;
  border-radius: 4px;
  line-height: 1;
  transition: color 0.15s, background 0.15s;
  flex-shrink: 0;
}
.btn-icon:hover { color: var(--text); background: var(--border); }
.btn-icon.ok    { color: var(--green); }
.btn-icon.ok:hover { color: #16a34a; }
.rename-input {
  background: var(--bg);
  border: 1px solid var(--accent);
  border-radius: 5px;
  color: var(--text);
  font-size: 0.875rem;
  font-weight: 600;
  padding: 0.15rem 0.4rem;
  width: 160px;
  font-family: inherit;
}
.rename-input:focus { outline: none; }
.overlay-msg {
  color: var(--muted);
  font-size: 0.8125rem;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 640px) {
  .devices-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .header { padding: 0.75rem 1rem; }
  .main { padding: 1rem; }
}
