:root {
  --bg: #080d17;
  --bg-soft: #0c1422;
  --panel: #101a2b;
  --panel-2: #142136;
  --border: #22314a;
  --border-soft: #1a263b;
  --text: #e8eef8;
  --muted: #8fa3bf;
  --accent: #38bdf8;
  --accent-strong: #0ea5e9;
  --down: #f87171;
  --warning: #fbbf24;
  --up: #34d399;
  --paused: #94a3b8;
  --unknown: #a78bfa;
  --danger: #ef4444;
  --ok: #22c55e;
  --radius: 14px;
  --shadow: 0 18px 45px rgba(0, 0, 0, 0.28);
}

* {
  box-sizing: border-box;
}

html {
  color-scheme: dark;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(56, 189, 248, 0.12), transparent 60%),
    radial-gradient(900px 500px at 100% 0%, rgba(167, 139, 250, 0.10), transparent 55%),
    var(--bg);
  color: var(--text);
  font-family: "Inter", ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  text-decoration: underline;
}

h1, h2, h3 {
  margin: 0 0 0.45rem;
  line-height: 1.2;
  letter-spacing: -0.015em;
}

h1 {
  font-size: 1.7rem;
}

h2 {
  font-size: 1.05rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: #c8d7ea;
}

p {
  margin: 0 0 0.8rem;
}

.muted {
  color: var(--muted);
}

.mono {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: 0.86em;
}

.small {
  font-size: 0.82rem;
}

.hidden,
[hidden] {
  display: none !important;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  gap: 1.25rem;
  padding: 0.8rem clamp(1rem, 3vw, 2rem);
  background: rgba(8, 13, 23, 0.86);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border-soft);
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 0.65rem;
  color: var(--text);
  font-weight: 700;
  letter-spacing: -0.01em;
  white-space: nowrap;
}

.brand:hover {
  text-decoration: none;
}

.brand-mark {
  width: 1.55rem;
  height: 1.55rem;
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, #06111f 0 28%, transparent 29%),
    conic-gradient(from 210deg, var(--accent), #6366f1, var(--up), var(--accent));
  box-shadow: 0 0 0 1px rgba(56, 189, 248, 0.35), 0 0 22px rgba(56, 189, 248, 0.35);
  flex: none;
}

.main-nav {
  display: flex;
  align-items: center;
  gap: 0.25rem;
  flex-wrap: wrap;
}

.main-nav a {
  color: var(--muted);
  padding: 0.42rem 0.7rem;
  border-radius: 9px;
  font-weight: 600;
  font-size: 0.9rem;
}

.main-nav a:hover {
  color: var(--text);
  background: var(--panel-2);
  text-decoration: none;
}

.main-nav a.active {
  color: var(--accent);
  background: rgba(56, 189, 248, 0.1);
}

.user-area {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  font-size: 0.88rem;
}

.username {
  color: #d5e1f1;
  font-weight: 600;
}

.role-badge {
  display: inline-block;
  padding: 0.18rem 0.55rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid transparent;
}

.role-admin {
  color: #fda4af;
  background: rgba(244, 63, 94, 0.12);
  border-color: rgba(244, 63, 94, 0.28);
}

.role-operator {
  color: #7dd3fc;
  background: rgba(14, 165, 233, 0.12);
  border-color: rgba(14, 165, 233, 0.3);
}

.role-viewer {
  color: #c4b5fd;
  background: rgba(139, 92, 246, 0.12);
  border-color: rgba(139, 92, 246, 0.3);
}

.inline-form {
  display: inline;
  margin: 0;
}

.link-button {
  border: 0;
  background: none;
  color: var(--muted);
  cursor: pointer;
  font: inherit;
  padding: 0;
}

.link-button:hover {
  color: var(--text);
  text-decoration: underline;
}

.container {
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 1.5rem clamp(1rem, 3vw, 2rem) 3rem;
}

.site-footer {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  width: min(1500px, 100%);
  margin: 0 auto;
  padding: 1rem clamp(1rem, 3vw, 2rem) 2rem;
  color: var(--muted);
  font-size: 0.8rem;
  border-top: 1px solid var(--border-soft);
}

.flash-stack {
  width: min(1500px, 100%);
  margin: 1rem auto 0;
  padding: 0 clamp(1rem, 3vw, 2rem);
}

.flash {
  padding: 0.8rem 1rem;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  margin-bottom: 0.75rem;
  font-size: 0.9rem;
}

.flash-error {
  border-color: rgba(248, 113, 113, 0.45);
  background: rgba(127, 29, 29, 0.28);
  color: #fecaca;
}

.flash-ok {
  border-color: rgba(52, 211, 153, 0.4);
  background: rgba(6, 78, 59, 0.3);
  color: #bbf7d0;
}

.flash-warning {
  border-color: rgba(251, 191, 36, 0.4);
  background: rgba(120, 53, 15, 0.25);
  color: #fde68a;
}

.page-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  margin: 0.4rem 0 1.25rem;
}

.page-head h1 {
  margin-bottom: 0.2rem;
}

.head-actions {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
}

.back-link {
  display: inline-block;
  margin-bottom: 0.4rem;
  font-size: 0.86rem;
  font-weight: 600;
}

.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1rem;
}

.stat {
  position: relative;
  overflow: hidden;
  padding: 0.85rem 1rem 0.95rem;
  background: linear-gradient(160deg, var(--panel-2), var(--panel));
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.stat::before {
  content: "";
  position: absolute;
  inset: 0 auto 0 0;
  width: 3px;
  background: var(--accent);
}

.stat-label {
  display: block;
  color: var(--muted);
  font-size: 0.74rem;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  margin-bottom: 0.25rem;
}

.stat strong {
  display: block;
  font-size: 1.85rem;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.stat-total::before { background: var(--accent); }
.stat-down::before { background: var(--down); }
.stat-warning::before { background: var(--warning); }
.stat-up::before { background: var(--up); }
.stat-paused::before { background: var(--paused); }
.stat-unknown::before { background: var(--unknown); }

.stat-down strong { color: var(--down); }
.stat-warning strong { color: var(--warning); }
.stat-up strong { color: var(--up); }
.stat-paused strong { color: var(--paused); }
.stat-unknown strong { color: var(--unknown); }

.server-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 0.8rem;
  margin-bottom: 1.1rem;
}

.server-card {
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.9rem 1rem;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--border-soft);
  color: var(--text);
  box-shadow: var(--shadow);
  transition: border-color 0.15s ease, transform 0.15s ease;
}

.server-card:hover {
  text-decoration: none;
  border-color: rgba(56, 189, 248, 0.55);
  transform: translateY(-1px);
}

.server-card.status-error {
  border-color: rgba(248, 113, 113, 0.4);
}

.server-card.status-disabled {
  opacity: 0.72;
}

.server-card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.7rem;
}

.server-name {
  font-weight: 700;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.server-base {
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.server-counts {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 0.35rem;
  padding-top: 0.35rem;
  border-top: 1px solid var(--border-soft);
}

.server-count {
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
  color: var(--muted);
  font-size: 0.72rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.server-count b {
  color: var(--text);
  font-size: 1rem;
  font-variant-numeric: tabular-nums;
}

.server-count.count-down b { color: var(--down); }
.server-count.count-warning b { color: var(--warning); }
.server-count.count-up b { color: var(--up); }
.server-count.count-paused b { color: var(--paused); }

.server-footer {
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
  color: var(--muted);
  font-size: 0.75rem;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1rem 1.1rem 1.1rem;
  margin-bottom: 1rem;
}

.panel > h2 {
  margin-bottom: 0.8rem;
}

.toolbar {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  margin-bottom: 0.8rem;
}

.status-filter {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
}

.chip {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 0.28rem 0.72rem;
  font: inherit;
  font-size: 0.82rem;
  font-weight: 600;
  cursor: pointer;
}

.chip:hover {
  color: var(--text);
  border-color: rgba(56, 189, 248, 0.5);
}

.chip.active {
  color: #03111d;
  background: var(--accent);
  border-color: var(--accent);
}

.filter-fields {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 0.6rem;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.22rem;
  min-width: 140px;
}

.field > span {
  color: var(--muted);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.field.grow {
  flex: 1 1 220px;
}

.field.is-hidden {
  display: none;
}

input,
select,
button {
  font: inherit;
}

input[type="text"],
input[type="password"],
input[type="search"],
select {
  width: 100%;
  padding: 0.53rem 0.65rem;
  color: var(--text);
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 9px;
  outline: none;
}

input:focus,
select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(56, 189, 248, 0.15);
}

.primary-button,
.secondary-button,
.danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  border-radius: 9px;
  padding: 0.55rem 0.95rem;
  font-weight: 700;
  font-size: 0.88rem;
  cursor: pointer;
  border: 1px solid transparent;
  white-space: nowrap;
}

.primary-button {
  color: #03111d;
  background: linear-gradient(180deg, #67d3fb, var(--accent-strong));
  border-color: rgba(56, 189, 248, 0.7);
}

.primary-button:hover {
  text-decoration: none;
  filter: brightness(1.06);
}

.secondary-button {
  color: var(--text);
  background: var(--panel-2);
  border-color: var(--border);
}

.secondary-button:hover {
  text-decoration: none;
  border-color: rgba(56, 189, 248, 0.5);
}

.danger-button {
  color: #fecaca;
  background: rgba(127, 29, 29, 0.35);
  border-color: rgba(248, 113, 113, 0.45);
}

.danger-button:hover {
  text-decoration: none;
  background: rgba(127, 29, 29, 0.55);
}

button.small,
.primary-button.small,
.secondary-button.small,
.danger-button.small {
  padding: 0.35rem 0.6rem;
  font-size: 0.78rem;
}

button:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border-soft);
  border-radius: 11px;
}

.sensor-table,
.data-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.sensor-table th,
.data-table th {
  position: sticky;
  top: 0;
  z-index: 1;
  text-align: left;
  padding: 0.6rem 0.7rem;
  background: #0d1625;
  color: var(--muted);
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.sensor-table td,
.data-table td {
  padding: 0.55rem 0.7rem;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: top;
}

.sensor-table tbody tr:hover,
.data-table tbody tr:hover {
  background: rgba(56, 189, 248, 0.045);
}

.sensor-table tbody tr:last-child td,
.data-table tbody tr:last-child td {
  border-bottom: 0;
}

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

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.78rem;
  font-weight: 700;
  white-space: nowrap;
}

.dot {
  display: inline-block;
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  flex: none;
}

.dot-down { background: var(--down); box-shadow: 0 0 8px rgba(248, 113, 113, 0.7); }
.dot-warning { background: var(--warning); box-shadow: 0 0 8px rgba(251, 191, 36, 0.55); }
.dot-up { background: var(--up); box-shadow: 0 0 8px rgba(52, 211, 153, 0.5); }
.dot-paused { background: var(--paused); }
.dot-unknown { background: var(--unknown); }
.dot-collecting { background: var(--accent); }

.status-down { color: var(--down); }
.status-warning { color: var(--warning); }
.status-up { color: var(--up); }
.status-paused { color: var(--paused); }
.status-unknown,
.status-collecting { color: var(--unknown); }

.cell-title {
  font-weight: 600;
  color: var(--text);
}

.cell-sub {
  color: var(--muted);
  font-size: 0.76rem;
}

.value-cell {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.82rem;
  white-space: nowrap;
}

.message-cell {
  max-width: 340px;
  color: var(--muted);
  font-size: 0.8rem;
}

.message-cell span {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.row-action {
  white-space: nowrap;
  text-align: right;
}

.ack-button {
  border: 1px solid rgba(56, 189, 248, 0.4);
  background: rgba(56, 189, 248, 0.08);
  color: var(--accent);
  border-radius: 7px;
  padding: 0.28rem 0.55rem;
  font-size: 0.75rem;
  font-weight: 700;
  cursor: pointer;
}

.ack-button:hover {
  background: rgba(56, 189, 248, 0.16);
}

.pager {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-top: 0.75rem;
  flex-wrap: wrap;
}

.pager-controls {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  font-size: 0.82rem;
  color: var(--muted);
}

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  color: var(--muted);
  font-size: 0.78rem;
  padding: 0.15rem 0.2rem 1rem;
}

.legend span {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}

.pill {
  display: inline-block;
  padding: 0.14rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 700;
  border: 1px solid transparent;
  white-space: nowrap;
}

.pill-ok {
  color: #bbf7d0;
  background: rgba(34, 197, 94, 0.12);
  border-color: rgba(34, 197, 94, 0.3);
}

.pill-warn {
  color: #fde68a;
  background: rgba(251, 191, 36, 0.1);
  border-color: rgba(251, 191, 36, 0.3);
}

.pill-bad {
  color: #fecaca;
  background: rgba(239, 68, 68, 0.14);
  border-color: rgba(239, 68, 68, 0.35);
}

.pill-muted {
  color: var(--muted);
  background: rgba(148, 163, 184, 0.1);
  border-color: rgba(148, 163, 184, 0.25);
}

.tag {
  display: inline-block;
  padding: 0.08rem 0.42rem;
  border-radius: 6px;
  background: var(--panel-2);
  border: 1px solid var(--border);
  color: #b8c9df;
  font-size: 0.7rem;
  font-weight: 600;
}

.tag-list {
  display: flex;
  gap: 0.25rem;
  flex-wrap: wrap;
  margin-top: 0.25rem;
}

.inline-error {
  color: #fca5a5;
  font-size: 0.76rem;
  margin-top: 0.3rem;
}

.stack-form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.stack-form label,
.grid-form label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  color: #c8d7ea;
  font-size: 0.82rem;
  font-weight: 600;
}

.stack-form.compact {
  gap: 0.5rem;
}

.stack-form.compact label {
  font-size: 0.76rem;
}

.grid-form {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  gap: 0.8rem;
  align-items: end;
}

.form-action {
  display: flex;
  align-items: end;
}

.mini-form {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  margin: 0;
}

.mini-form select {
  min-width: 100px;
  padding: 0.3rem 0.4rem;
  font-size: 0.78rem;
}

.detail-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 0.75rem 1.2rem;
  margin: 0;
}

.detail-grid dt {
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.detail-grid dd {
  margin: 0.15rem 0 0;
  overflow-wrap: anywhere;
}

.two-column {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(320px, 1fr));
  gap: 1rem;
}

.note-panel {
  background: linear-gradient(160deg, rgba(56, 189, 248, 0.06), var(--panel));
}

.error-panel {
  text-align: center;
  padding: 3rem 1rem;
}

.error-code {
  font-size: 4rem;
  font-weight: 800;
  line-height: 1;
  margin: 0 0 0.5rem;
  color: var(--accent);
}

.actions-cell {
  position: relative;
}

.action-menu {
  position: relative;
}

.action-menu > summary {
  list-style: none;
}

.action-menu > summary::-webkit-details-marker {
  display: none;
}

.action-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 0.35rem);
  z-index: 20;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 280px;
  padding: 0.75rem;
  background: #0c1524;
  border: 1px solid var(--border);
  border-radius: 10px;
  box-shadow: var(--shadow);
}

.action-panel form {
  margin: 0;
}

.user-table td {
  vertical-align: middle;
}

.auth-body {
  display: flex;
  min-height: 100vh;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background:
    radial-gradient(900px 500px at 20% 0%, rgba(56, 189, 248, 0.15), transparent 60%),
    radial-gradient(800px 500px at 100% 100%, rgba(139, 92, 246, 0.14), transparent 60%),
    var(--bg);
}

.auth-shell {
  width: min(460px, 100%);
}

.auth-brand {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.6rem;
  margin-bottom: 1rem;
  font-weight: 700;
  font-size: 1.05rem;
}

.auth-card {
  background: linear-gradient(165deg, rgba(20, 33, 54, 0.96), rgba(13, 22, 37, 0.98));
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 1.5rem;
}

.auth-card h1 {
  font-size: 1.35rem;
}

.auth-foot {
  margin-top: 1rem;
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
}

.auth-version {
  text-align: center;
  color: #5b6b83;
  font-size: 0.72rem;
  margin-top: 0.35rem;
}

.auth-link {
  text-align: center;
  margin-top: 0.9rem;
  font-size: 0.86rem;
}

.code-input {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 1.25rem;
  letter-spacing: 0.35em;
  text-align: center;
}

.qr-wrap {
  display: flex;
  justify-content: center;
  margin: 0.8rem 0;
}

.qr {
  width: 210px;
  max-width: 100%;
  padding: 12px;
  background: #fff;
  border-radius: 12px;
}

.qr svg {
  display: block;
  width: 100%;
  height: auto;
}

.secret-line {
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  overflow-wrap: anywhere;
}

.secret-line code {
  color: var(--text);
  background: var(--bg-soft);
  padding: 0.15rem 0.4rem;
  border-radius: 5px;
}

.recovery-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
  margin: 0.8rem 0;
}

.recovery-grid code {
  display: block;
  padding: 0.4rem 0.5rem;
  text-align: center;
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 7px;
  font-size: 0.9rem;
  letter-spacing: 0.05em;
}

@media (max-width: 760px) {
  .topbar {
    flex-wrap: wrap;
    gap: 0.6rem;
  }

  .user-area {
    margin-left: 0;
    width: 100%;
    justify-content: flex-end;
  }

  .page-head {
    align-items: flex-start;
  }

  .server-counts {
    grid-template-columns: repeat(2, 1fr);
  }

  .action-panel {
    right: auto;
    left: 0;
  }
}
