:root {
  color-scheme: dark;
  --bg: #050203;
  --panel: #0d0608;
  --panel-soft: #140709;
  --field: #0a0607;
  --field-hover: #16080b;
  --ink: #f8fafc;
  --muted: #94a3b8;
  --line: #281216;
  --brand: #ef4444;
  --brand-hover: #f87171;
  --brand-ink: #fff7f7;
  --accent: #dc2626;
  --warn: #fbbf24;
  --warn-soft: #2b1b08;
  --danger: #b91c1c;
  --danger-hover: #dc2626;
  --danger-soft: #2a080a;
  --shadow: 0 10px 30px -5px rgba(0, 0, 0, 0.8);
  --glow: 0 0 15px rgba(220, 38, 38, 0.22);
  --accent-gradient: linear-gradient(135deg, #ef4444, #b91c1c);
  --header-gradient: linear-gradient(90deg, rgba(7, 4, 5, 0.96), rgba(15, 5, 7, 0.96));
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden;
  color: var(--ink);
  background:
    radial-gradient(circle at top right, rgba(20, 7, 9, 0.85) 0%, rgba(5, 2, 3, 0.95) 58%, var(--bg) 100%),
    var(--bg);
  background-attachment: fixed;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: geometricPrecision;
}

body::before {
  content: "";
  position: fixed;
  inset: auto auto -58vh -30vw;
  width: 165vw;
  height: 165vw;
  border-radius: 45%;
  background: radial-gradient(ellipse at center, transparent 42%, rgba(220, 38, 38, 0.12));
  pointer-events: none;
  z-index: 0;
  animation: slow-wave 140s linear infinite;
}

#app {
  position: relative;
  z-index: 1;
}

@keyframes slow-wave {
  to {
    transform: rotate(360deg);
  }
}

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

button {
  cursor: pointer;
}

.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-panel,
.panel,
.metric,
.server,
.empty {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.login-panel {
  width: min(420px, 100%);
  padding: 28px;
  position: relative;
  overflow: hidden;
}

.login-panel::before,
.panel::before,
.metric::before,
.server::before {
  content: "";
  position: absolute;
  inset: 0 0 auto;
  height: 2px;
  background: var(--accent-gradient);
  opacity: 0.9;
}

.login-separator {
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 16px 0;
  color: var(--muted);
  font-size: 13px;
}

.login-separator::before,
.login-separator::after {
  content: "";
  height: 1px;
  flex: 1;
  background: var(--line);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 22px;
}

.brand-mark {
  width: 42px;
  height: 42px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

.brand-logo {
  display: block;
  width: 38px;
  height: 38px;
  object-fit: contain;
  filter: drop-shadow(0 0 10px rgba(220, 38, 38, 0.8));
}

.brand h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.1;
  letter-spacing: 0;
  text-shadow: 0 2px 8px rgba(220, 38, 38, 0.25);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 248px 1fr;
}

.sidebar {
  position: sticky;
  top: 0;
  height: 100vh;
  background: var(--header-gradient);
  border-right: 1px solid var(--line);
  box-shadow: 2px 0 15px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(10px);
  color: var(--ink);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  overflow: auto;
}

.sidebar .brand-mark {
  width: 42px;
  height: 42px;
}

.nav {
  display: grid;
  gap: 6px;
}

.nav button {
  border: 0;
  border-radius: 8px;
  min-height: 40px;
  padding: 10px 12px;
  text-align: left;
  color: var(--muted);
  background: transparent;
  transition: color 0.2s ease, background 0.2s ease, box-shadow 0.2s ease;
}

.nav button.active,
.nav button:hover {
  color: var(--ink);
  background: var(--panel-soft);
  box-shadow: inset 2px 0 0 var(--brand);
}

.main {
  min-width: 0;
  width: 100%;
  max-width: 1760px;
  margin: 0 auto;
  padding: 24px;
}

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

.topbar h2 {
  margin: 0;
  font-size: 24px;
  letter-spacing: 0;
}

.userbar {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 10px;
  color: var(--muted);
}

.grid {
  display: grid;
  gap: 16px;
}

.metrics {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 14px;
}

.metric {
  min-height: 112px;
  padding: 16px;
  position: relative;
  overflow: hidden;
}

.metric span {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.metric strong {
  display: block;
  margin-top: 8px;
  font-size: 26px;
  letter-spacing: 0;
}

.metric small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 12px;
}

.two-col {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  gap: 16px;
  align-items: start;
}

.split-layout {
  grid-template-columns: minmax(280px, 380px) minmax(0, 1fr);
}

.servers-layout {
  grid-template-columns: minmax(280px, 340px) minmax(0, 1fr);
}

.profile-layout {
  grid-template-columns: minmax(320px, 460px) minmax(0, 1fr);
}

.settings-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(340px, 1fr));
  gap: 16px;
  align-items: start;
}

.panel {
  padding: 16px;
  box-shadow: none;
  position: relative;
  overflow: hidden;
  min-width: 0;
}

.panel:hover,
.metric:hover,
.server:hover {
  border-color: #4a1a20;
  box-shadow: var(--glow);
}

.panel-soft {
  display: grid;
  gap: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel-soft);
}

.backup-box {
  display: grid;
  gap: 14px;
}

.app-downloads {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 14px;
}

.app-card {
  min-height: 180px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  gap: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
}

.app-card-head,
.release-summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
}

.app-card h3 {
  margin: 0;
  line-height: 1.2;
}

.app-card p {
  margin: 8px 0;
  color: var(--muted);
}

.release-summary {
  margin-top: 14px;
}

.release-summary a {
  color: var(--brand-hover);
}

.panel h3,
.server h3 {
  margin: 0 0 14px;
  font-size: 17px;
  letter-spacing: 0;
}

.form-grid {
  display: grid;
  gap: 11px;
}

label {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  padding: 8px 10px;
}

input:disabled,
select:disabled,
textarea:disabled {
  cursor: not-allowed;
  color: var(--muted);
  background: #080405;
  opacity: 0.82;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(220, 38, 38, 0.18);
  outline: none;
}

input::placeholder,
textarea::placeholder {
  color: #6d5560;
}

input[type="checkbox"] {
  width: auto;
  min-height: auto;
  margin: 0;
}

label:has(input[type="checkbox"]) {
  display: flex;
  align-items: center;
  gap: 8px;
}

textarea {
  min-height: 94px;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 13px;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

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

.panel-toolbar h3 {
  margin: 0;
}

.form-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  width: 100%;
}

.button,
button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  color: var(--ink);
  min-height: 36px;
  padding: 8px 12px;
  white-space: nowrap;
  transition: background 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease, transform 0.2s ease;
}

.button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-decoration: none;
}

button:hover,
.button:hover {
  background: var(--field-hover);
  border-color: #4a1a20;
  box-shadow: var(--glow);
}

button:active,
.button:active {
  transform: translateY(1px);
}

.primary {
  background: var(--accent-gradient);
  color: var(--brand-ink);
  border-color: var(--brand);
}

.primary:hover {
  background: var(--brand-hover);
  border-color: var(--brand-hover);
}

.danger {
  color: #fff7f6;
  background: linear-gradient(135deg, #b91c1c, #7f1d1d);
  border-color: var(--danger);
}

.danger:hover {
  background: var(--danger-hover);
  border-color: var(--danger-hover);
}

.ghost {
  background: transparent;
}

.icon-button {
  width: 34px;
  min-height: 34px;
  padding: 0;
  display: inline-grid;
  place-items: center;
}

.table-wrap {
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(34, 16, 21, 0.35);
  backdrop-filter: blur(5px);
  scrollbar-color: #4a1a20 #0a0607;
  scrollbar-width: thin;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
}

th,
td {
  padding: 11px 12px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: top;
  overflow-wrap: anywhere;
}

th {
  font-size: 12px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: rgba(7, 4, 5, 0.45);
}

tr:last-child td {
  border-bottom: 0;
}

tbody tr:hover {
  background: rgba(20, 7, 9, 0.55);
}

th.actions-cell,
td.actions-cell {
  width: 1%;
  text-align: right;
  white-space: nowrap;
  overflow-wrap: normal;
}

td.actions-cell .actions {
  justify-content: flex-end;
  flex-wrap: nowrap;
  margin-left: auto;
}

.actions-cell button {
  min-width: 70px;
}

.deployments-table {
  min-width: 680px;
  table-layout: auto;
}

.deployments-table th:nth-child(1),
.deployments-table td:nth-child(1) {
  width: 120px;
}

.deployments-table th:nth-child(2),
.deployments-table td:nth-child(2) {
  width: 70px;
}

.deployments-table .actions-cell {
  width: 560px;
  min-width: 450px;
}

.users-table {
  min-width: 720px;
  table-layout: auto;
}

.users-table th:nth-child(1),
.users-table td:nth-child(1) {
  width: 24%;
}

.users-table th:nth-child(2),
.users-table td:nth-child(2) {
  width: 30%;
}

.users-table th:nth-child(3),
.users-table td:nth-child(3),
.users-table th:nth-child(4),
.users-table td:nth-child(4) {
  width: 110px;
}

.users-table .actions-cell {
  width: 170px;
  min-width: 150px;
}

.row-actions {
  justify-content: flex-end;
  gap: 6px;
}

.row-actions button {
  min-width: 68px;
  padding-inline: 10px;
}

.deployments-table .row-actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(86px, 1fr));
  min-width: 0;
  width: 100%;
}

.deployments-table .row-actions button {
  min-width: 86px;
  width: 100%;
  padding-inline: 9px;
}

.connections-table {
  min-width: 780px;
  table-layout: auto;
}

.connections-table th:nth-child(1),
.connections-table td:nth-child(1) {
  width: 25%;
}

.connections-table th:nth-child(2),
.connections-table td:nth-child(2) {
  width: 17%;
}

.connections-table th:nth-child(3),
.connections-table td:nth-child(3),
.connections-table th:nth-child(4),
.connections-table td:nth-child(4) {
  width: 130px;
}

.connections-table .actions-cell {
  width: 300px;
  min-width: 236px;
}

.connections-table .actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(62px, 1fr));
  gap: 6px;
  width: 100%;
}

.connections-table button {
  min-width: 0;
  width: 100%;
}

.users-table .actions {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(68px, 1fr));
  gap: 6px;
  width: 100%;
}

.users-table button {
  min-width: 0;
  width: 100%;
}

.users-table .actions:has(> button:only-child) {
  display: flex;
  justify-content: flex-end;
}

.users-table .actions:has(> button:only-child) button {
  width: auto;
  min-width: 88px;
}

.badge {
  display: inline-flex;
  align-items: center;
  min-height: 24px;
  padding: 2px 8px;
  border-radius: 999px;
  background: var(--panel-soft);
  color: var(--brand);
  font-size: 12px;
  font-weight: 700;
  border: 1px solid rgba(220, 38, 38, 0.24);
}

.badge.warn {
  color: var(--warn);
  background: var(--warn-soft);
}

.badge.danger {
  color: #fff7f6;
  background: var(--danger);
}

.server-list {
  display: grid;
  gap: 14px;
}

.server {
  padding: 16px;
  box-shadow: none;
  position: relative;
  overflow: hidden;
}

.server-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 12px;
}

.server-head > .actions {
  justify-content: flex-end;
}

.deployment-form {
  grid-template-columns: minmax(170px, 1fr) minmax(130px, 170px);
  margin-top: 14px;
  padding-top: 14px;
  border-top: 1px solid var(--line);
}

.deployment-form label:nth-child(3),
.deployment-form button {
  grid-column: 1 / -1;
}

.deployment-form button {
  justify-self: start;
}

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

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

pre {
  white-space: pre-wrap;
  word-break: break-word;
  background: #050203;
  color: #fee2e2;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  overflow: auto;
}

.config-modal {
  display: grid;
  gap: 14px;
}

.qr-panel {
  display: grid;
  place-items: center;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #ffffff;
}

.qr-panel img {
  display: block;
  width: min(280px, 100%);
  height: auto;
  image-rendering: pixelated;
}

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

.summary-grid div {
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
}

.summary-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
}

.summary-grid strong {
  display: block;
  margin-top: 4px;
  word-break: break-word;
}

.traffic-panel {
  display: grid;
  gap: 14px;
  padding: 18px;
}

.chart-head {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.chart-head > * {
  min-width: 0;
}

.chart-head h3 {
  font-size: 18px;
  margin-bottom: 4px;
}

.chart-stats {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
  color: var(--muted);
  font-size: 13px;
}

.chart-stats span {
  min-height: 26px;
  display: inline-flex;
  align-items: center;
  padding: 3px 8px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--field);
  white-space: nowrap;
}

.traffic-chart-shell {
  position: relative;
  width: 100%;
  height: clamp(190px, 16vw, 240px);
  min-height: 190px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background:
    linear-gradient(180deg, rgba(239, 68, 68, 0.035), transparent 46%),
    #0a0607;
  overflow: hidden;
  isolation: isolate;
}

.traffic-chart-plot {
  position: absolute;
  inset: 18px 18px 34px 52px;
}

.traffic-chart {
  width: 100%;
  height: 100%;
  display: block;
}

.chart-grid line {
  stroke: #2a1518;
  stroke-width: 1;
}

.chart-area {
  fill: rgba(220, 38, 38, 0.16);
}

.chart-line {
  fill: none;
  stroke: var(--brand);
  stroke-width: 2.5;
  vector-effect: non-scaling-stroke;
}

.chart-dot {
  position: absolute;
  width: 9px;
  height: 9px;
  border: 2px solid #0a0607;
  border-radius: 50%;
  background: var(--warn);
  box-shadow: 0 0 0 1px rgba(251, 191, 36, 0.85);
  transform: translate(-50%, -50%);
}

.chart-y-label,
.chart-x-label {
  position: absolute;
  color: var(--muted);
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  line-height: 1;
  pointer-events: none;
  text-shadow: 0 1px 2px #0a0607;
}

.chart-y-label {
  top: 16px;
  left: 52px;
}

.chart-x-label {
  bottom: 12px;
}

.chart-x-label.start {
  left: 52px;
}

.chart-x-label.end {
  right: 18px;
}

.chart-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px 16px;
  color: var(--muted);
  font-size: 13px;
}

.chart-legend span {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.legend-dot {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--brand);
}

.legend-dot.out {
  background: var(--warn);
}

.chart-empty {
  min-height: 120px;
  display: grid;
  place-items: center;
  color: var(--muted);
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.operation-steps {
  display: grid;
  gap: 8px;
  margin: 0 0 14px;
  padding-left: 22px;
}

details {
  margin-top: 12px;
}

summary {
  cursor: pointer;
  color: var(--muted);
}

.empty {
  padding: 22px;
  color: var(--muted);
  box-shadow: none;
}

.notice {
  min-height: 38px;
  display: none;
  align-items: center;
  padding: 9px 12px;
  border-radius: 8px;
  background: var(--warn-soft);
  color: #ffd889;
  border: 1px solid #7c4a12;
}

.notice.show {
  display: flex;
}

dialog {
  width: min(760px, calc(100vw - 28px));
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 18px;
  box-shadow: var(--shadow);
}

dialog::backdrop {
  background: rgba(0, 0, 0, 0.62);
}

.close {
  position: absolute;
  top: 12px;
  right: 12px;
  color: transparent;
}

.close::before {
  content: "x";
  color: var(--ink);
  font-weight: 700;
  line-height: 1;
}

@media (max-width: 1440px) {
  .split-layout,
  .servers-layout,
  .profile-layout {
    grid-template-columns: 1fr;
  }

  .split-layout > .panel:first-child,
  .profile-layout > .panel:first-child {
    width: 100%;
    max-width: 560px;
  }
}

@media (max-width: 1100px) {
  .settings-grid {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    height: auto;
    z-index: 2;
    padding: 12px;
    overflow: hidden;
  }

  .nav {
    grid-template-columns: repeat(5, minmax(0, 1fr));
  }

  .nav button {
    text-align: center;
    padding: 9px 6px;
  }

  .metrics,
  .two-col,
  .app-downloads,
  .settings-grid,
  .deployment-form {
    grid-template-columns: 1fr;
  }

  .server-head,
  .panel-toolbar {
    align-items: flex-start;
    flex-direction: column;
  }

  .server-head > .actions,
  .row-actions {
    justify-content: flex-start;
  }
}

@media (max-width: 560px) {
  .main {
    padding: 14px;
  }

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

  .userbar {
    justify-content: flex-start;
  }

  .chart-head {
    flex-direction: column;
  }

  .chart-stats {
    justify-content: flex-start;
  }

  .traffic-chart-shell {
    height: 180px;
    min-height: 180px;
  }

  .traffic-chart-plot {
    inset: 16px 12px 34px 42px;
  }

  .chart-y-label,
  .chart-x-label.start {
    left: 42px;
  }

  .chart-x-label.end {
    right: 12px;
  }

  .connections-table {
    min-width: 820px;
  }

  .nav {
    max-width: 100%;
    overflow-x: auto;
    display: flex;
    scrollbar-width: none;
  }

  .nav::-webkit-scrollbar {
    display: none;
  }

  .nav button {
    flex: 0 0 auto;
  }
}
