:root {
  color-scheme: dark;
  --bg: #0b0f14;
  --bg-elevated: #121820;
  --panel: #171f2a;
  --panel-hover: #1c2533;
  --text: #e8edf4;
  --muted: #8b98a8;
  --accent: #4da3ff;
  --accent-dim: rgba(77, 163, 255, 0.12);
  --danger: #ff6b6b;
  --danger-dim: rgba(255, 107, 107, 0.12);
  --ok: #57d38c;
  --ok-dim: rgba(87, 211, 140, 0.12);
  --warn: #f0b429;
  --warn-dim: rgba(240, 180, 41, 0.12);
  --border: #243041;
  --sidebar-w: 240px;
  font-family: Segoe UI, system-ui, sans-serif;
}

* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); color: var(--text); min-height: 100vh; }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
  width: var(--sidebar-w);
  background: var(--bg-elevated);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 1.25rem 1rem;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand { margin-bottom: 1.5rem; display: flex; flex-direction: column; gap: 0.2rem; }
.brand strong { font-size: 1.05rem; }
.brand .muted { font-size: 0.8rem; }

.sidebar-nav { display: flex; flex-direction: column; gap: 0.35rem; flex: 1; }
.nav-item {
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  color: var(--muted);
  padding: 0.65rem 0.85rem;
  border-radius: 10px;
  cursor: pointer;
  font-size: 0.95rem;
}
.nav-item:hover { background: var(--panel); color: var(--text); }
.nav-item.active {
  background: var(--accent-dim);
  border-color: rgba(77, 163, 255, 0.35);
  color: var(--text);
}
.nav-badge {
  display: inline-block;
  min-width: 1.25rem;
  padding: 0 0.35rem;
  border-radius: 999px;
  background: var(--warn);
  color: #111;
  font-size: 0.72rem;
  font-weight: 700;
  margin-left: 0.35rem;
}
.nav-badge.hidden { display: none; }

.sidebar-footer { display: flex; flex-direction: column; gap: 0.5rem; margin-top: 1rem; }
.sidebar-footer label { font-size: 0.8rem; display: flex; flex-direction: column; gap: 0.35rem; }

.main-area { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  padding: 1.25rem 1.5rem 0.75rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
}
.topbar h1 { margin: 0; font-size: 1.45rem; font-weight: 600; }
.topbar .muted { margin: 0.25rem 0 0; font-size: 0.9rem; }

main { padding: 1.25rem 1.5rem 2rem; flex: 1; }
.view { display: none; }
.view.active:not(.hidden) { display: block; }

.server-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 1rem;
  margin-bottom: 1.25rem;
}

.server-card {
  text-align: left;
  width: 100%;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 1rem 1.1rem;
  color: inherit;
  cursor: pointer;
  transition: border-color 0.15s, transform 0.15s;
}
.server-card:hover {
  border-color: var(--accent);
  transform: translateY(-1px);
}
.server-card-head {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 0.75rem;
  margin-bottom: 0.65rem;
}
.server-card-head strong { font-size: 1.05rem; }
.server-card-meta { color: var(--muted); font-size: 0.9rem; margin-bottom: 0.75rem; }
.server-card-foot {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  flex-wrap: wrap;
  font-size: 0.82rem;
}
.card-meta-warn { color: var(--warn); }

.add-server-panel summary {
  cursor: pointer;
  font-weight: 600;
  margin-bottom: 0.75rem;
}
.add-server-panel[open] summary { margin-bottom: 1rem; }

.back-link {
  margin-bottom: 1rem;
  padding-left: 0;
}

.server-hero {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
}
.server-hero-main h2 { margin: 0 0 0.5rem; }
.hero-badges {
  display: flex;
  align-items: center;
  gap: 0.65rem;
  flex-wrap: wrap;
  margin-bottom: 0.5rem;
}
.hero-actions {
  display: flex;
  gap: 0.5rem;
  flex-wrap: wrap;
}

.control-section {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}
.section-title {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 0.75rem;
  flex-wrap: wrap;
  margin-bottom: 0.85rem;
}
.section-title h3 { margin: 0; font-size: 1rem; }
.nested-panel { margin-top: 1rem; background: var(--bg-elevated); }
.issue-list { margin: 0; padding-left: 1.2rem; }
.compact-table { min-width: 520px; }
.empty-state.compact { padding: 1rem; }

.panel { display: none; }
.panel.active { display: block; }

.cards {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 0.85rem;
  margin-bottom: 1.5rem;
}
.stat-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem;
}
.stat-card strong { font-size: 1.6rem; display: block; line-height: 1.1; }
.stat-card.clickable { cursor: pointer; transition: border-color 0.15s; }
.stat-card.clickable:hover { border-color: var(--accent); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1rem 1.1rem;
  margin-bottom: 1rem;
}
.card h2, .card h3, .card h4 { margin-top: 0; }

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 1.25rem 0 0.65rem;
}
.section-header h2 { margin: 0; font-size: 1.05rem; font-weight: 600; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.85rem;
  align-items: end;
}
.form-grid label {
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

input, select, button { font: inherit; }
input, select {
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.55rem 0.75rem;
}
button { cursor: pointer; border-radius: 8px; }

.btn {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  padding: 0.5rem 0.85rem;
}
.btn:hover { border-color: var(--accent); }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #061018; font-weight: 600; }
.btn-primary:hover { filter: brightness(1.08); }
.btn-secondary { background: var(--panel); }
.btn-danger { border-color: rgba(255, 107, 107, 0.5); color: var(--danger); }
.btn-link { background: transparent; border: none; color: var(--accent); padding: 0; }
.btn-block { width: 100%; }
.btn-sm { padding: 0.35rem 0.6rem; font-size: 0.85rem; }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.status-ok { color: var(--ok); }
.status-bad { color: var(--danger); }

.actions { display: flex; gap: 0.5rem; flex-wrap: wrap; margin-top: 0.75rem; }
.actions-inline { margin-top: 0; flex-wrap: nowrap; }

.status-badge, .job-badge {
  display: inline-block;
  padding: 0.15rem 0.55rem;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  border: 1px solid transparent;
  white-space: nowrap;
}
.status-badge.status-online, .job-badge.job-completed { color: var(--ok); border-color: rgba(87, 211, 140, 0.35); background: var(--ok-dim); }
.status-badge.status-offline, .job-badge.job-failed { color: var(--danger); border-color: rgba(255, 107, 107, 0.35); background: var(--danger-dim); }
.status-badge.status-never, .status-badge.status-disabled { color: var(--muted); border-color: rgba(154, 167, 184, 0.35); background: rgba(154, 167, 184, 0.1); }
.status-badge.status-unbound { color: var(--warn); border-color: rgba(240, 180, 41, 0.35); background: var(--warn-dim); }
.job-badge.job-pending { color: var(--warn); border-color: rgba(240, 180, 41, 0.35); background: var(--warn-dim); }
.job-badge.job-running { color: var(--accent); border-color: rgba(77, 163, 255, 0.35); background: var(--accent-dim); }

.type-badge {
  display: inline-block;
  font-size: 0.78rem;
  padding: 0.12rem 0.45rem;
  border-radius: 6px;
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
}

.data-table-wrap { overflow-x: auto; margin-bottom: 1rem; }
.data-table { width: 100%; min-width: 680px; border-collapse: collapse; }
.data-table th {
  text-align: left;
  padding: 0.55rem 0.65rem;
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.data-table td {
  padding: 0.65rem;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}
.data-table tbody tr:hover { background: var(--panel-hover); }
.data-table tbody tr.clickable { cursor: pointer; }

.panel-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.75rem;
  flex-wrap: wrap;
}

.filters { display: flex; gap: 0.85rem; flex-wrap: wrap; align-items: end; }
.filters label { display: flex; flex-direction: column; gap: 0.35rem; font-size: 0.82rem; color: var(--muted); }
.filters-card { margin-bottom: 1rem; }

.bound-servers { margin: 0; padding-left: 1rem; }
.bound-servers li { margin-bottom: 0.35rem; }

.uuid-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  margin: 0.5rem 0;
}
.uuid-row code, .mono {
  font-family: Consolas, monospace;
  font-size: 0.82rem;
  background: var(--bg);
  padding: 0.2rem 0.45rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  word-break: break-all;
}
.copy-btn { padding: 0.25rem 0.6rem; font-size: 0.82rem; }

.notice {
  border-left: 3px solid var(--accent);
  padding: 0.75rem 1rem;
  margin: 1rem 0;
  background: var(--bg);
  border-radius: 0 8px 8px 0;
}

.server-detail-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 1rem;
  flex-wrap: wrap;
  margin-bottom: 1rem;
}
.detail-tabs { display: flex; gap: 0.35rem; margin-bottom: 1rem; flex-wrap: wrap; }
.detail-tab {
  background: var(--bg);
  border: 1px solid var(--border);
  color: var(--muted);
  padding: 0.45rem 0.85rem;
  border-radius: 999px;
  font-size: 0.88rem;
}
.detail-tab.active { color: var(--text); border-color: var(--accent); background: var(--accent-dim); }
.detail-pane.hidden { display: none; }

.toast-host {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  align-items: flex-end;
  min-width: 280px;
}
.toast {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 0.75rem 1rem;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  animation: toast-in 0.2s ease;
  max-width: 360px;
}
.toast-success { border-color: rgba(87, 211, 140, 0.45); }
.toast-error { border-color: rgba(255, 107, 107, 0.45); }
@keyframes toast-in {
  from { opacity: 0; transform: translateY(-8px); }
  to { opacity: 1; transform: translateY(0); }
}

.modal {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.65);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  z-index: 1000;
}
.modal-content {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  width: min(760px, 100%);
  max-height: 85vh;
  overflow: auto;
  padding: 1rem 1.1rem;
}
.modal-content.modal-wide { width: min(920px, 100%); }
.inventory-note { margin: 0 0 1rem; font-size: 0.88rem; line-height: 1.45; }
.status-error { color: var(--danger); }
.modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 1rem;
}
.modal-header h3 { margin: 0; }
.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1rem;
}
.detail-item label { display: block; font-size: 0.78rem; color: var(--muted); margin-bottom: 0.2rem; }
.json-block {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.75rem;
  overflow: auto;
  font-family: Consolas, monospace;
  font-size: 0.78rem;
  max-height: 280px;
  white-space: pre-wrap;
  word-break: break-word;
}

.empty-state {
  text-align: center;
  padding: 2rem 1rem;
  color: var(--muted);
}

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

.login-card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  max-width: 360px;
  padding: 24px;
  width: 100%;
}

.login-card-header {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.login-subtitle {
  color: var(--muted);
  font-size: 0.9rem;
  margin: 0 0 8px;
}

.field-label {
  color: var(--muted);
  font-size: 0.82rem;
}

.text-input {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  padding: 0.55rem 0.65rem;
  width: 100%;
}

.text-input:focus {
  border-color: var(--accent);
  outline: none;
}

.login-btn {
  margin-top: 8px;
  width: 100%;
}

.login-error {
  color: var(--danger);
  font-size: 0.85rem;
  margin: 0;
}

.sidebar-user {
  font-size: 0.82rem;
  padding: 0 0.25rem 0.75rem;
  word-break: break-word;
}

@media (max-width: 860px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: static;
    border-right: none;
    border-bottom: 1px solid var(--border);
  }
  .sidebar-nav { flex-direction: row; flex-wrap: wrap; }
  .sidebar-footer { flex-direction: row; flex-wrap: wrap; align-items: end; }
  .sidebar-footer label { flex: 1; min-width: 160px; }
}
