:root {
  --bg: #0f1117;
  --surface: #1a1d27;
  --surface2: #222536;
  --border: #2e3250;
  --accent: #4f8ef7;
  --accent-hover: #3a7af0;
  --danger: #e84949;
  --danger-hover: #c93a3a;
  --warn: #f59e0b;
  --success: #22c55e;
  --text: #e8eaf0;
  --text-muted: #8b8fa8;
  --radius: 12px;
  --radius-sm: 7px;
  --shadow: 0 2px 12px rgba(0,0,0,0.4);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  -webkit-tap-highlight-color: transparent;
}

/* ---- Layout ---- */
#app { display: flex; flex-direction: column; min-height: 100vh; }

header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}

header h1 { font-size: 17px; font-weight: 700; letter-spacing: 0.3px; }

.header-right { display: flex; align-items: center; gap: 12px; }

.btn-logout {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  cursor: pointer;
  font-size: 13px;
}
.btn-logout:hover { color: var(--text); border-color: var(--text-muted); }

main { flex: 1; padding: 16px; max-width: 700px; margin: 0 auto; width: 100%; }

/* ---- Page sections ---- */
.page { display: none; }
.page.active { display: block; }

/* ---- Login ---- */
#login-page {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 24px 16px;
}

.login-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  box-shadow: var(--shadow);
}

.login-card h2 { text-align: center; margin-bottom: 6px; font-size: 20px; }
.login-card .subtitle { text-align: center; color: var(--text-muted); font-size: 13px; margin-bottom: 28px; }

.form-group { margin-bottom: 16px; }
.form-group label { display: block; margin-bottom: 6px; font-size: 13px; color: var(--text-muted); }
.form-group input {
  width: 100%;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  color: var(--text);
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
}
.form-group input:focus { border-color: var(--accent); }

.error-msg { color: var(--danger); font-size: 13px; margin-top: 8px; min-height: 18px; }

/* ---- Buttons ---- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 10px 18px;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  font-size: 14px;
  font-weight: 600;
  transition: background 0.15s, opacity 0.15s;
  white-space: nowrap;
}
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: var(--danger-hover); }
.btn-warn { background: var(--warn); color: #000; }
.btn-warn:hover:not(:disabled) { background: #d97706; }
.btn-ghost { background: transparent; border: 1px solid var(--border); color: var(--text); }
.btn-ghost:hover:not(:disabled) { background: var(--surface2); }
.btn-full { width: 100%; }
.btn-sm { padding: 6px 12px; font-size: 12px; }

/* ---- Nav tabs ---- */
.tabs {
  display: flex;
  gap: 4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 4px;
  margin-bottom: 16px;
}
.tab {
  flex: 1;
  padding: 8px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  transition: all 0.15s;
}
.tab.active { background: var(--accent); color: #fff; }

/* ---- Command bar ---- */
.cmd-bar {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px;
  margin-bottom: 16px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
.cmd-bar-label { color: var(--text-muted); font-size: 12px; font-weight: 600; width: 100%; }

/* ---- Status bar ---- */
.status-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 12px;
  font-size: 13px;
  color: var(--text-muted);
}
.last-update { font-size: 12px; }

/* ---- Device cards ---- */
.device-list { display: flex; flex-direction: column; gap: 10px; }

.device-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transition: border-color 0.2s;
}
.device-card.online { border-left: 3px solid var(--success); }
.device-card.offline { border-left: 3px solid var(--text-muted); opacity: 0.75; }

.device-header { display: flex; align-items: center; justify-content: space-between; }
.device-name { font-weight: 700; font-size: 15px; }

.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.badge-online { background: rgba(34,197,94,0.18); color: var(--success); }
.badge-offline { background: rgba(139,143,168,0.15); color: var(--text-muted); }

.device-meta { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 12px; color: var(--text-muted); }
.device-meta span { display: flex; align-items: center; gap: 4px; }

.device-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---- Empty / Loading states ---- */
.state-msg {
  text-align: center;
  padding: 40px 16px;
  color: var(--text-muted);
  font-size: 14px;
}

/* ---- Logs ---- */
.log-table-wrap { overflow-x: auto; border-radius: var(--radius); border: 1px solid var(--border); }
table { width: 100%; border-collapse: collapse; font-size: 12px; }
th { background: var(--surface2); padding: 10px 12px; text-align: left; color: var(--text-muted); font-weight: 600; }
td { padding: 9px 12px; border-top: 1px solid var(--border); vertical-align: top; }
tr:hover td { background: var(--surface2); }
.log-pager { display: flex; justify-content: space-between; align-items: center; margin-top: 12px; font-size: 13px; color: var(--text-muted); }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.65);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000;
  padding: 16px;
  backdrop-filter: blur(3px);
}
.modal-overlay.hidden { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: var(--shadow);
}
.modal h3 { margin-bottom: 10px; font-size: 17px; }
.modal p { color: var(--text-muted); font-size: 14px; margin-bottom: 20px; line-height: 1.5; }
.modal .form-group { margin-bottom: 20px; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ---- Spinner ---- */
.spinner {
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Toast ---- */
#toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: var(--surface2); border: 1px solid var(--border);
  border-radius: 99px; padding: 10px 22px;
  font-size: 14px; box-shadow: var(--shadow);
  z-index: 2000; transition: opacity 0.3s;
  white-space: nowrap;
}
#toast.hidden { opacity: 0; pointer-events: none; }

/* ---- Responsive ---- */
@media (min-width: 480px) {
  .device-actions { gap: 10px; }
  .cmd-bar-label { width: auto; }
}
