:root {
  --bg: #0f1115;
  --bg-card: #171a21;
  --bg-hover: #1d212b;
  --text: #e8eaed;
  --muted: #9aa2af;
  --accent: #4f7cff;
  --accent-text: #ffffff;
  --border: #2a2e38;
  --danger: #ff6b6b;
  --ok: #34c98f;
  --warn: #e0a758;
  color-scheme: dark;
}

* {
  box-sizing: border-box;
}

/* #login-view and #app-view set their own `display` below, which has
   higher specificity than the UA stylesheet's `[hidden] { display: none }`
   — without this rule, toggling the `hidden` attribute would not actually
   hide them. */
[hidden] {
  display: none !important;
}

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  line-height: 1.5;
}

a {
  color: var(--accent);
}

button, input, select {
  font: inherit;
  color: inherit;
}

/* ---------- Login view ---------- */

#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

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

.login-card h1 {
  font-size: 1.3rem;
  margin: 0 0 4px;
}

.login-card p.hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 20px;
}

/* ---------- App shell ---------- */

#app-view {
  display: flex;
  min-height: 100vh;
}

.sidebar {
  width: 220px;
  flex: none;
  background: var(--bg-card);
  border-right: 1px solid var(--border);
  padding: 16px 0;
  display: flex;
  flex-direction: column;
}

.sidebar .brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  padding: 0 16px 16px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 8px;
}

.brand-mark {
  width: 30px;
  height: 30px;
  border-radius: 8px;
  background: var(--accent);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.8rem;
  flex: none;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex: 1;
}

.sidebar nav a {
  color: var(--muted);
  text-decoration: none;
  padding: 10px 16px;
  font-size: 0.92rem;
  border-left: 3px solid transparent;
}

.sidebar nav a:hover {
  background: var(--bg-hover);
  color: var(--text);
}

.sidebar nav a.active {
  color: var(--text);
  border-left-color: var(--accent);
  background: var(--bg-hover);
}

.sidebar-footer {
  padding: 12px 16px 0;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}

.sidebar-footer .whoami {
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 8px;
  word-break: break-all;
}

main.content {
  flex: 1;
  min-width: 0;
  padding: 24px 28px 60px;
}

main.content h1 {
  margin: 0 0 4px;
  font-size: 1.4rem;
}

.page-hint {
  color: var(--muted);
  font-size: 0.85rem;
  margin: 0 0 20px;
}

/* ---------- Shared widgets ---------- */

.btn {
  background: var(--accent);
  color: var(--accent-text);
  border: none;
  border-radius: 8px;
  padding: 8px 14px;
  font-weight: 600;
  cursor: pointer;
  font-size: 0.88rem;
}

.btn:hover {
  filter: brightness(1.08);
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn.secondary {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}

.btn.danger {
  background: var(--danger);
}

.btn.small {
  padding: 4px 10px;
  font-size: 0.78rem;
  border-radius: 6px;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="number"],
input[type="datetime-local"],
textarea {
  width: 100%;
  background: #0c0e12;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  color: var(--text);
}

label {
  display: block;
  font-size: 0.82rem;
  color: var(--muted);
  margin-bottom: 4px;
  margin-top: 12px;
}

label:first-child {
  margin-top: 0;
}

.field-row {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}
.field-row > * {
  flex: 1;
  min-width: 140px;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
}

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 24px;
}

.stat-card .stat-value {
  font-size: 1.6rem;
  font-weight: 700;
}

.stat-card .stat-label {
  color: var(--muted);
  font-size: 0.8rem;
  margin-top: 2px;
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.86rem;
}

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

th {
  color: var(--muted);
  font-weight: 600;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.02em;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 20px;
}

.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.badge.ok { background: rgba(52, 201, 143, 0.15); color: var(--ok); }
.badge.danger { background: rgba(255, 107, 107, 0.15); color: var(--danger); }
.badge.muted { background: rgba(154, 162, 175, 0.15); color: var(--muted); }
.badge.not-connected { background: rgba(224, 167, 88, 0.18); color: var(--warn); }

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
}

.error-banner {
  background: rgba(255, 107, 107, 0.12);
  border: 1px solid rgba(255, 107, 107, 0.4);
  color: #ffb3b3;
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 16px;
  font-size: 0.86rem;
}

.empty-state {
  color: var(--muted);
  padding: 20px 0;
  font-size: 0.9rem;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding: 40px 16px;
  overflow-y: auto;
  z-index: 50;
}

.modal {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 22px;
  width: 100%;
  max-width: 480px;
}

.modal h2 {
  margin-top: 0;
  font-size: 1.1rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 18px;
}

/* ---------- Responsive ---------- */

@media (max-width: 720px) {
  #app-view {
    flex-direction: column;
  }
  .sidebar {
    width: 100%;
    border-right: none;
    border-bottom: 1px solid var(--border);
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    padding: 10px 12px;
  }
  .sidebar .brand {
    border-bottom: none;
    padding: 0 10px 0 0;
    margin-bottom: 0;
  }
  .sidebar nav {
    flex-direction: row;
    flex-wrap: wrap;
    flex: 1;
  }
  .sidebar nav a {
    border-left: none;
    border-bottom: 3px solid transparent;
    padding: 8px 10px;
  }
  .sidebar nav a.active {
    border-left-color: transparent;
    border-bottom-color: var(--accent);
  }
  .sidebar-footer {
    border-top: none;
    margin-top: 0;
    padding: 0;
  }
  main.content {
    padding: 18px 14px 40px;
  }
}
