:root {
  color-scheme: dark;
  --bg: #0d1117;
  --bg-elevated: #111827;
  --bg-panel: rgba(23, 29, 40, 0.92);
  --bg-panel-strong: rgba(18, 23, 32, 0.98);
  --border: #283244;
  --border-soft: rgba(148, 163, 184, 0.16);
  --text: #e6edf3;
  --text-muted: #94a3b8;
  --text-dim: #7b8ba3;
  --accent: #3b82f6;
  --accent-strong: #2563eb;
  --accent-soft: rgba(59, 130, 246, 0.14);
  --success-bg: rgba(34, 197, 94, 0.14);
  --success-text: #7ee787;
  --danger-bg: rgba(248, 81, 73, 0.16);
  --danger-text: #ff938a;
  --warn-bg: rgba(234, 179, 8, 0.16);
  --warn-text: #facc15;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.36);
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  max-width: 100%;
  overflow-x: hidden;
  background-color: #0b0f15;
  -webkit-text-size-adjust: 100%;
}

body {
  margin: 0;
  position: relative;
  isolation: isolate;
  font-family: "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  background-color: #0b0f15;
  color: var(--text);
  min-height: 100vh;
}

body::before {
  content: "";
  position: fixed;
  inset: 112px 0 112px 0;
  background:
    radial-gradient(circle at 18% 140px, rgba(59, 130, 246, 0.1), transparent 24%),
    radial-gradient(circle at 88% 220px, rgba(99, 102, 241, 0.08), transparent 22%),
    linear-gradient(180deg, #0d1117 0%, #0c1119 40%, #0a0e14 100%);
  pointer-events: none;
  z-index: -1;
}

@media (min-width: 641px) {
  body::before {
    inset: 0;
    background:
      radial-gradient(circle at 18% 240px, rgba(59, 130, 246, 0.1), transparent 24%),
      radial-gradient(circle at 88% 300px, rgba(99, 102, 241, 0.08), transparent 22%),
      linear-gradient(180deg, #0b0f15 0, #0b0f15 140px, #0d1117 340px, #0a0e14 100%);
  }
}

a { color: #7cc2ff; text-decoration: none; }
code, pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; }

.topbar, .page {
  width: min(100%, 1080px);
  margin: 0 auto;
  padding: 24px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding-top: 32px;
  padding-bottom: 8px;
}

.page.narrow {
  width: min(100%, 760px);
}

.card {
  background: linear-gradient(180deg, var(--bg-panel) 0%, var(--bg-panel-strong) 100%);
  border: 1px solid var(--border-soft);
  border-radius: 18px;
  padding: 24px;
  box-shadow: var(--shadow);
  margin-bottom: 18px;
  backdrop-filter: blur(10px);
  max-width: 100%;
}

body.login-shell {
  width: 100%;
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.login-card {
  width: min(420px, calc(100vw - 48px));
  max-width: 100%;
  position: relative;
  overflow: hidden;
}

.login-card::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 4px;
  background: linear-gradient(90deg, #3b82f6, #22c55e, #8b5cf6);
}

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

label span {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  color: var(--text-muted);
}

input {
  appearance: none;
  -webkit-appearance: none;
  width: 100%;
  box-sizing: border-box;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: #0f1724;
  color: var(--text);
  transition: border-color 120ms ease, box-shadow 120ms ease, background 120ms ease;
}

input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px rgba(59, 130, 246, 0.14);
  background: #101a2a;
}

button, .button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 16px;
  min-height: 46px;
  border: none;
  border-radius: 12px;
  background: linear-gradient(180deg, var(--accent) 0%, var(--accent-strong) 100%);
  color: #fff;
  cursor: pointer;
  font-family: inherit;
  font-size: 15px;
  line-height: 1.2;
  font-weight: 600;
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.1);
  max-width: 100%;
  text-align: center;
}

button.secondary, .button.secondary {
  background: #1a2332;
  color: var(--text);
  border: 1px solid var(--border);
}

button.warning { background: linear-gradient(180deg, #a16207 0%, #854d0e 100%); color: #fff4cf; }
button.danger { background: linear-gradient(180deg, #b42318 0%, #8f1d14 100%); color: #fff2f1; }

.actions {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  align-items: center;
  max-width: 100%;
}

.topbar .actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
  align-items: stretch;
}

.topbar .actions > * {
  min-width: 0;
}

.topbar .actions form {
  display: flex;
}

.topbar .actions .button,
.topbar .actions button {
  width: 100%;
}

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

.flash {
  padding: 12px 14px;
  border-radius: 12px;
  margin-bottom: 16px;
  border: 1px solid transparent;
}

.flash-success {
  background: var(--success-bg);
  color: var(--success-text);
  border-color: rgba(34, 197, 94, 0.2);
}

.flash-error {
  background: var(--danger-bg);
  color: var(--danger-text);
  border-color: rgba(248, 81, 73, 0.22);
}

.table-wrap {
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  margin-top: 8px;
  border: 1px solid var(--border-soft);
  border-radius: 16px;
  -webkit-overflow-scrolling: touch;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 720px;
  background: rgba(15, 23, 36, 0.55);
}

th, td {
  text-align: left;
  padding: 12px 10px;
  border-bottom: 1px solid var(--border-soft);
}

th {
  font-size: 12px;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--text-dim);
  background: rgba(99, 102, 241, 0.05);
}

.pill {
  display: inline-flex;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
}

.pill-ok {
  background: var(--success-bg);
  color: var(--success-text);
}

.pill-off {
  background: var(--danger-bg);
  color: var(--danger-text);
}

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

.grid.compact {
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 12px;
}

.metric {
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border-soft);
  background: rgba(11, 18, 32, 0.72);
}

.metric-value {
  font-size: 15px;
  line-height: 1.35;
  color: var(--text);
}

.metric-value.muted {
  color: var(--text-muted);
}

.metric strong {
  display: block;
  margin-bottom: 6px;
}

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

.form-grid label {
  min-width: 0;
}

.form-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  align-items: stretch;
}

.form-actions > * {
  min-width: 0;
}

.form-actions form {
  display: flex;
}

.form-actions .button,
.form-actions button {
  width: 100%;
}

.user-action-toggle.is-warning {
  background: rgba(234, 179, 8, 0.1);
  color: #f6d776;
  border: 1px solid rgba(234, 179, 8, 0.18);
}

.user-action-toggle.is-success {
  background: rgba(34, 197, 94, 0.1);
  color: #8de8a7;
  border: 1px solid rgba(34, 197, 94, 0.18);
}

.user-action-delete {
  background: rgba(248, 81, 73, 0.1);
  color: #ffaba4;
  border: 1px solid rgba(248, 81, 73, 0.18);
}

.user-action-muted {
  background: rgba(99, 102, 241, 0.08);
  color: #d6e4ff;
  border: 1px solid rgba(148, 163, 184, 0.18);
}

.form-actions > *:last-child:nth-child(odd) {
  grid-column: 1 / -1;
}

pre {
  white-space: pre-wrap;
  word-break: break-word;
  overflow-wrap: anywhere;
  background: #0b1220;
  color: #dbe9f9;
  padding: 16px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

h1, h2 {
  margin-top: 0;
}

form {
  margin: 0;
}

strong {
  color: var(--text-muted);
  font-size: 13px;
}

@media (max-width: 820px) {
  .topbar {
    flex-direction: column;
    align-items: stretch;
  }
}

@media (max-width: 640px) {
  .topbar, .page {
    padding: 16px;
  }

  .topbar {
    gap: 12px;
    padding-bottom: 4px;
  }

  .topbar h1 {
    margin-bottom: 8px;
  }

  .topbar p {
    margin: 0;
  }

  .topbar .actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
    align-items: stretch;
  }

  .topbar .actions > * {
    width: 100%;
    min-width: 0;
  }

  .topbar .actions form,
  .topbar .actions a,
  .topbar .actions button {
    width: 100%;
  }

  body.login-shell {
    padding: 16px;
  }

  .login-card {
    width: 100%;
  }

  .card {
    padding: 18px;
    border-radius: 16px;
  }

  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .actions > * {
    width: 100%;
    min-width: 0;
  }

  .actions form,
  .actions a,
  .actions button {
    width: 100%;
  }

  .actions form button {
    width: 100%;
  }

  .table-wrap {
    overflow: visible;
    border: none;
    margin-top: 0;
  }

  table,
  thead,
  tbody,
  tr,
  th,
  td {
    display: block;
    width: 100%;
  }

  table {
    min-width: 0;
    background: transparent;
  }

  thead {
    display: none;
  }

  tbody {
    display: grid;
    gap: 10px;
  }

  tr {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 14px;
    background: linear-gradient(180deg, rgba(18, 23, 32, 0.98) 0%, rgba(15, 21, 31, 0.98) 100%);
    border: 1px solid var(--border-soft);
    border-radius: 14px;
    padding: 14px;
    box-shadow: var(--shadow);
    overflow: hidden;
  }

  td {
    border: none;
    padding: 0;
    min-width: 0;
  }

  td[data-label="Name"] {
    grid-column: 1;
    align-self: start;
  }

  td[data-label="Status"] {
    grid-column: 2;
    grid-row: 1;
    text-align: right;
    align-self: start;
  }

  td[data-label="Status"] .pill {
    margin-left: auto;
  }

  td[data-label="Address"] {
    grid-column: 1 / -1;
  }

  td[data-label="Down"] {
    grid-column: 1;
  }

  td[data-label="Up"] {
    grid-column: 2;
  }

  td[data-label="RX"] {
    grid-column: 1;
  }

  td[data-label="TX"] {
    grid-column: 2;
  }

  td[data-label="Name"] a {
    font-size: 18px;
    font-weight: 600;
    line-height: 1.25;
  }

  td::before {
    content: attr(data-label);
    display: block;
    margin-bottom: 6px;
    font-size: 11px;
    letter-spacing: 0.04em;
    text-transform: uppercase;
    color: var(--text-dim);
  }

  td[data-label="Status"]::before {
    display: none;
  }

  .grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

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

  .metric {
    padding: 12px;
  }

  .form-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
  }

  .form-grid label:first-child,
  .form-actions,
  .stack > button,
  .stack > .button,
  .stack > .muted {
    grid-column: 1 / -1;
  }

  .form-actions {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 10px;
  }

  .form-actions > * {
    min-width: 0;
  }

  .form-actions > *:last-child:nth-child(odd) {
    grid-column: 1 / -1;
  }

  code {
    white-space: normal;
    overflow-wrap: anywhere;
    word-break: break-word;
  }
}
