:root {
  --bg: #0a111d;
  --bg-soft: #111f34;
  --panel: rgba(20, 34, 56, 0.78);
  --panel-border: rgba(136, 183, 255, 0.18);
  --text: #ecf3ff;
  --muted: #a9bad3;
  --accent: #59d9b7;
  --accent-2: #ffb370;
  --danger: #f06f7d;
  --shadow: 0 20px 50px rgba(1, 8, 20, 0.55);
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  font-family: 'Manrope', sans-serif;
  color: var(--text);
  background: radial-gradient(1400px 700px at 10% -15%, #1f3764 0%, transparent 65%),
    radial-gradient(1200px 700px at 95% -20%, #523623 0%, transparent 65%),
    linear-gradient(150deg, #070d16 0%, #0e1827 55%, #0b1320 100%);
  overflow-x: hidden;
}

body {
  position: relative;
}

.noise {
  position: fixed;
  inset: 0;
  pointer-events: none;
  opacity: 0.06;
  background-image: radial-gradient(circle at 25% 20%, #fff 1px, transparent 1px);
  background-size: 4px 4px;
}

.shell {
  width: min(1300px, 100% - 2rem);
  margin: 1.25rem auto 2rem;
}

#loadingCard,
#loginCard,
#dashboard {
  display: none;
}

body[data-view='loading'] #loadingCard {
  display: block;
}

body[data-view='login'] #loginCard {
  display: block;
}

body[data-view='dashboard'] #dashboard {
  display: grid;
}

.card {
  border: 1px solid var(--panel-border);
  background: var(--panel);
  backdrop-filter: blur(12px);
  border-radius: 18px;
  box-shadow: var(--shadow);
}

.auth-card {
  width: min(420px, 100%);
  margin: 5rem auto;
  padding: 1.5rem;
}

.auth-card h1 {
  margin: 0;
  font-size: 2rem;
  letter-spacing: 0.02em;
}

.auth-card p {
  margin: 0.6rem 0 1.2rem;
  color: var(--muted);
}

form {
  display: grid;
  gap: 0.9rem;
}

label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.9rem;
  color: var(--muted);
}

input,
select,
button {
  font: inherit;
}

input,
select {
  width: 100%;
  background: rgba(8, 16, 30, 0.72);
  color: var(--text);
  border: 1px solid rgba(154, 180, 230, 0.28);
  border-radius: 12px;
  padding: 0.65rem 0.8rem;
}

input:focus,
select:focus {
  outline: 2px solid rgba(89, 217, 183, 0.36);
  border-color: var(--accent);
}

button {
  cursor: pointer;
  border: 1px solid transparent;
  border-radius: 12px;
  padding: 0.62rem 0.95rem;
  color: #05211e;
  background: linear-gradient(135deg, var(--accent), #7ef6d6);
  font-weight: 700;
}

button.secondary {
  background: rgba(95, 130, 198, 0.2);
  border-color: rgba(163, 189, 240, 0.35);
  color: var(--text);
}

button.danger {
  background: rgba(240, 111, 125, 0.2);
  border-color: rgba(243, 144, 157, 0.4);
  color: #ffd7dd;
}

button:hover {
  transform: translateY(-1px);
}

.error {
  margin-top: 0.9rem;
  color: #ffc6ce;
}

.dashboard {
  display: grid;
  gap: 1rem;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-end;
  gap: 1rem;
}

.topbar h2 {
  margin: 0;
  font-size: 1.7rem;
}

.topbar p {
  margin: 0.25rem 0 0;
  color: var(--muted);
}

.topbar-actions {
  display: flex;
  gap: 0.65rem;
  align-items: flex-end;
  flex-wrap: wrap;
}

.topbar-actions label {
  min-width: 200px;
}

.stats-grid {
  display: grid;
  gap: 0.9rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.stat {
  border: 1px solid rgba(147, 178, 235, 0.2);
  background: linear-gradient(135deg, rgba(16, 31, 53, 0.9), rgba(15, 36, 54, 0.9));
  border-radius: 16px;
  padding: 1rem;
}

.stat-label {
  margin: 0;
  font-size: 0.82rem;
  text-transform: uppercase;
  color: var(--muted);
}

.stat-value {
  margin: 0.35rem 0 0;
  font-size: 1.55rem;
  font-weight: 800;
}

.filters {
  padding: 1rem;
}

.filter-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.filter-actions {
  margin-top: 0.85rem;
  display: flex;
  gap: 0.6rem;
}

.remote-panel {
  padding: 1rem;
}

.remote-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.remote-head h3 {
  margin: 0;
}

.remote-actions-inline {
  display: flex;
  gap: 0.6rem;
}

.remote-grid {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 220px 1fr 170px;
  align-items: end;
}

.remote-grid .remote-text {
  min-width: 0;
}

.remote-grid button {
  height: 42px;
}

.charts-grid {
  display: grid;
  gap: 0.95rem;
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.chart-card {
  padding: 0.9rem;
  min-height: 300px;
  height: 320px;
  display: flex;
  flex-direction: column;
}

.chart-card h3 {
  margin: 0 0 0.55rem;
}

.chart-card canvas {
  width: 100% !important;
  flex: 1;
  min-height: 220px;
  max-height: 250px;
}

.logs-card {
  padding: 1rem;
}

.cards-2col {
  display: grid;
  gap: 0.95rem;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.alerts-card,
.command-history-card {
  padding: 1rem;
}

.section-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
  gap: 0.75rem;
}

.section-head h3 {
  margin: 0;
}

.pill {
  border: 1px solid rgba(163, 189, 240, 0.35);
  border-radius: 999px;
  padding: 0.22rem 0.7rem;
  font-size: 0.82rem;
  color: var(--muted);
  background: rgba(95, 130, 198, 0.18);
}

.alerts-list {
  display: grid;
  gap: 0.55rem;
  max-height: 360px;
  overflow: auto;
}

.alert-item {
  border: 1px solid rgba(146, 179, 238, 0.2);
  border-radius: 12px;
  padding: 0.65rem 0.75rem;
  background: rgba(14, 28, 46, 0.7);
}

.alert-item.high {
  border-color: rgba(243, 144, 157, 0.5);
}

.alert-title {
  margin: 0 0 0.2rem;
  font-weight: 700;
}

.alert-meta {
  margin: 0;
  font-size: 0.82rem;
  color: var(--muted);
}

.logs-header {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  align-items: center;
  margin-bottom: 0.8rem;
}

.logs-header h3 {
  margin: 0;
}

.pager {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-family: 'JetBrains Mono', monospace;
  color: var(--muted);
}

.table-wrap {
  overflow: auto;
  border-radius: 12px;
  border: 1px solid rgba(146, 179, 238, 0.2);
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 980px;
  table-layout: fixed;
}

thead {
  background: rgba(104, 151, 234, 0.15);
}

th,
td {
  text-align: left;
  padding: 0.68rem 0.75rem;
  border-bottom: 1px solid rgba(131, 170, 235, 0.16);
  vertical-align: top;
  overflow-wrap: anywhere;
  word-break: break-word;
}

td {
  color: #d9e8ff;
  font-size: 0.92rem;
}

.item-icon-cell {
  width: 64px;
  min-width: 64px;
  text-align: center;
}

.item-icon {
  width: 24px;
  height: 24px;
  object-fit: contain;
  display: inline-block;
  vertical-align: middle;
}

.item-icon-char {
  display: inline-block;
  font-size: 1.05rem;
  line-height: 1;
}

.icon-fallback {
  color: #7c90ac;
}

td.small {
  font-size: 0.82rem;
  color: var(--muted);
  white-space: normal;
}

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

.mono {
  font-family: 'JetBrains Mono', monospace;
  font-size: 0.82rem;
}

@media (max-width: 1100px) {
  .charts-grid,
  .filter-grid,
  .stats-grid,
  .cards-2col {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .remote-grid {
    grid-template-columns: 1fr 1fr;
  }

  .remote-grid button {
    grid-column: 1 / -1;
  }
}

@media (max-width: 760px) {
  .shell {
    width: min(1300px, 100% - 1rem);
  }

  .topbar {
    flex-direction: column;
    align-items: flex-start;
  }

  .charts-grid,
  .filter-grid,
  .stats-grid,
  .cards-2col,
  .remote-grid {
    grid-template-columns: 1fr;
  }

  .topbar-actions label {
    min-width: 150px;
  }
}
