:root {
  --ink: #12202a;
  --muted: #5a6b76;
  --line: #c9d4dc;
  --paper: #f3f6f8;
  --card: #ffffff;
  --teal: #0d7377;
  --teal-deep: #095456;
  --amber: #c47d14;
  --rust: #b33a2b;
  --ok: #1f7a4c;
  --shadow: 0 1px 0 rgba(18, 32, 42, 0.04);
  --elev: 0 18px 50px rgba(18, 32, 42, 0.16);
  --th-bg: #f8fafb;
  --row-hover: #f7fbfb;
  --note-bg: #e8f1f2;
  --pill-ok-bg: #e5f6ec;
  --pill-mute-bg: #eef2f5;
  --pill-amber-bg: #fff4df;
  --pill-rust-bg: #fde8e4;
  --pill-teal-bg: #e8f1f2;
  --input-bg: #ffffff;
  --mark-bg: #ffffff;
  --backdrop: rgba(18, 32, 42, 0.4);
  --header-bg: rgba(243, 246, 248, 0.9);
  --atm-1: rgba(13, 115, 119, 0.14);
  --atm-2: rgba(196, 125, 20, 0.12);
  --atm-base: linear-gradient(180deg, #e7eef2 0%, #f3f6f8 42%, #eef2f5 100%);
  --font: "Source Sans 3", system-ui, sans-serif;
  --display: "Fraunces", Georgia, serif;
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
}

html[data-theme="dark"] {
  --ink: #e7eef2;
  --muted: #8fa3b0;
  --line: #2a3b46;
  --paper: #0c1418;
  --card: #152028;
  --teal: #2bb5b8;
  --teal-deep: #7ee0e2;
  --amber: #e0a84a;
  --rust: #f07167;
  --ok: #5dcc8c;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.25);
  --elev: 0 22px 60px rgba(0, 0, 0, 0.45);
  --th-bg: #101a21;
  --row-hover: #1a2a33;
  --note-bg: #163038;
  --pill-ok-bg: #163528;
  --pill-mute-bg: #1c2a33;
  --pill-amber-bg: #3a2c14;
  --pill-rust-bg: #3a1c1a;
  --pill-teal-bg: #163038;
  --input-bg: #0f181e;
  --mark-bg: #0f181e;
  --backdrop: rgba(4, 10, 14, 0.72);
  --header-bg: rgba(12, 20, 24, 0.92);
  --atm-1: rgba(43, 181, 184, 0.16);
  --atm-2: rgba(224, 168, 74, 0.1);
  --atm-base: linear-gradient(180deg, #0a1216 0%, #0c1418 45%, #101a20 100%);
}

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

html {
  -webkit-text-size-adjust: 100%;
  overflow-x: hidden;
}

body {
  margin: 0;
  min-height: 100%;
  min-height: 100dvh;
  font-family: var(--font);
  color: var(--ink);
  background: var(--paper);
  overflow-x: hidden;
  padding-bottom: var(--safe-bottom);
}

.atmosphere {
  position: fixed;
  inset: 0;
  z-index: -1;
  pointer-events: none;
  background:
    radial-gradient(1000px 480px at 8% -8%, var(--atm-1), transparent 55%),
    radial-gradient(820px 380px at 92% 0%, var(--atm-2), transparent 50%),
    var(--atm-base);
}

html[data-theme="dark"] .atmosphere::after {
  content: "";
  position: absolute;
  inset: -20%;
  background: conic-gradient(
    from 210deg at 18% 12%,
    transparent 0deg,
    rgba(43, 181, 184, 0.07) 28deg,
    transparent 70deg
  );
  animation: radar-sweep 14s linear infinite;
  opacity: 0.85;
}

@keyframes radar-sweep {
  to {
    transform: rotate(360deg);
  }
}

/* Visibility helpers — phone-first toggle in media query */
.phone-only {
  display: none !important;
}

.desk-only {
  display: revert;
}

.top {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  align-items: flex-end;
  padding: calc(28px + var(--safe-top)) 40px 18px;
  border-bottom: 1px solid var(--line);
  background: var(--header-bg);
  backdrop-filter: blur(10px);
  position: sticky;
  top: 0;
  z-index: 5;
}

.env-banner {
  position: sticky;
  top: 0;
  z-index: 50;
  text-align: center;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.12em;
  padding: 6px 12px;
  color: #1a1208;
  background: linear-gradient(90deg, #e8a838, #f0c14a 50%, #e8a838);
  border-bottom: 1px solid rgba(0, 0, 0, 0.12);
}

.global-status {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 10px;
  position: sticky;
  top: 0;
  z-index: 45;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 600;
  color: var(--teal-deep);
  background: var(--note-bg);
  border-bottom: 1px solid var(--line);
}

.global-status.is-busy {
  display: flex;
}

.global-status.is-error {
  display: flex;
  color: var(--rust);
  background: var(--pill-rust-bg);
}

.global-status-spin {
  width: 14px;
  height: 14px;
  border: 2px solid var(--line);
  border-top-color: var(--teal);
  border-radius: 50%;
  animation: mc-spin 0.7s linear infinite;
  flex: 0 0 auto;
}

.global-status.is-error .global-status-spin {
  display: none;
}

@keyframes mc-spin {
  to {
    transform: rotate(360deg);
  }
}

body.role-member .ops-only {
  display: none !important;
}

.user-menu {
  position: relative;
}

.user-menu-btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 36px;
  padding: 4px 10px 4px 4px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: var(--card);
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: border-color 0.15s ease, background 0.15s ease;
}

.user-menu-btn:hover,
.user-menu-btn[aria-expanded="true"] {
  border-color: var(--teal);
  background: color-mix(in srgb, var(--teal) 12%, var(--card));
}

.user-avatar {
  display: inline-grid;
  place-items: center;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  background: linear-gradient(145deg, var(--teal), var(--teal-deep));
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  flex-shrink: 0;
}

.user-menu-name {
  max-width: 110px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 13px;
}

.user-caret {
  font-size: 11px;
  opacity: 0.7;
  line-height: 1;
}

.user-menu-panel {
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  z-index: 40;
  min-width: 220px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  box-shadow: var(--elev);
  display: grid;
  gap: 4px;
  isolation: isolate;
}

.user-menu-panel[hidden] {
  display: none !important;
}

.user-menu-meta {
  display: grid;
  gap: 2px;
  padding: 8px 10px 10px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 4px;
}

.user-menu-meta strong {
  font-size: 14px;
  color: var(--ink);
}

.user-menu-meta .muted {
  font-size: 12px;
  font-weight: 600;
}

.user-menu-item {
  display: block;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 10px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  padding: 10px 12px;
  cursor: pointer;
}

.user-menu-item:hover {
  background: color-mix(in srgb, var(--teal) 12%, transparent);
}

.user-menu-item.danger {
  color: #b42318;
}

.user-menu-item.danger:hover {
  background: color-mix(in srgb, #b42318 10%, transparent);
}

html[data-theme="dark"] .user-menu-panel {
  box-shadow: 0 16px 40px rgba(0, 0, 0, 0.45);
}

html[data-theme="dark"] .user-menu-item.danger {
  color: #f97066;
}

.eyebrow {
  margin: 0 0 6px;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--teal-deep);
  font-weight: 700;
}

h1 {
  margin: 0;
  font-family: var(--display);
  font-weight: 700;
  font-size: clamp(1.85rem, 5vw, 2.75rem);
  letter-spacing: -0.02em;
  line-height: 1.05;
}

.tagline {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 1.05rem;
}

.top-actions {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 12px;
  min-width: 0;
}

.action-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  align-items: center;
}

.stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.stat {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 13px;
  font-weight: 600;
  box-shadow: var(--shadow);
  white-space: nowrap;
}

.stat b {
  color: var(--teal-deep);
}

main {
  padding: 24px 40px calc(64px + var(--safe-bottom));
  display: grid;
  gap: 20px;
  width: 100%;
  max-width: 100%;
}

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

.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.chip {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 999px;
  padding: 8px 14px;
  font: inherit;
  font-weight: 600;
  font-size: 13px;
  cursor: pointer;
  min-height: 40px;
}

.chip.active {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

html[data-theme="dark"] .chip.active {
  color: #062022;
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 600;
  min-width: 0;
}

.search input {
  width: min(320px, 70vw);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  font: inherit;
  background: var(--input-bg);
  color: var(--ink);
  min-height: 42px;
}

.phone-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  width: 100%;
}

.field {
  display: grid;
  gap: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
  min-width: 0;
}

.field select {
  width: 100%;
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 10px;
  font: inherit;
  font-weight: 600;
  font-size: 14px;
  text-transform: none;
  letter-spacing: normal;
  color: var(--ink);
  background: var(--input-bg);
}

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
  animation: rise 420ms ease-out both;
  width: 100%;
  max-width: 100%;
}

.panel.secondary {
  animation-delay: 80ms;
}

.panel-head {
  padding: 18px 22px;
  border-bottom: 1px solid var(--line);
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: baseline;
}

.panel-titles h2 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.35rem;
  font-weight: 600;
}

.meta,
.muted {
  margin: 0;
  color: var(--muted);
  font-size: 13px;
}

.table-wrap {
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  max-height: min(70vh, calc(100dvh - 260px));
}

table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 14px;
}

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

th {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  background: var(--th-bg);
  position: sticky;
  top: 0;
  z-index: 3;
  box-shadow: 0 1px 0 var(--line);
}

.th-sort {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  font-weight: 700;
  letter-spacing: inherit;
  text-transform: inherit;
  cursor: pointer;
  white-space: nowrap;
}

.th-sort::after {
  content: "↕";
  font-size: 10px;
  opacity: 0.35;
}

.th-sort.is-active {
  color: var(--teal-deep);
}

.th-sort.is-active[data-dir="asc"]::after {
  content: "▲";
  opacity: 0.9;
}

.th-sort.is-active[data-dir="desc"]::after {
  content: "▼";
  opacity: 0.9;
}

tr:hover td {
  background: var(--row-hover);
}

.mono {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
}

.urls {
  display: flex;
  flex-direction: column;
  gap: 4px;
  word-break: break-word;
}

.urls a {
  color: var(--teal-deep);
  text-decoration: none;
  font-weight: 600;
}

.urls a:hover {
  text-decoration: underline;
}

.pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 4px 10px;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill.fully-wired {
  background: var(--pill-ok-bg);
  color: var(--ok);
}
.pill.unpublished {
  background: var(--pill-mute-bg);
  color: var(--muted);
}
.pill.npm-only {
  background: var(--pill-amber-bg);
  color: var(--amber);
}
.pill.dead-route,
.pill.dns-orphan {
  background: var(--pill-rust-bg);
  color: var(--rust);
}
.pill.internal,
.pill.infra,
.pill.external-target,
.pill.ops,
.pill.jenkins,
.pill.phpmyadmin {
  background: var(--pill-teal-bg);
  color: var(--teal-deep);
}

.btn {
  border: 1px solid var(--line);
  background: var(--card);
  color: var(--ink);
  border-radius: 10px;
  padding: 8px 12px;
  font: inherit;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  min-height: 40px;
}

.btn.primary {
  background: var(--teal);
  border-color: var(--teal);
  color: #fff;
}

html[data-theme="dark"] .btn.primary {
  color: #062022;
}

.btn.primary:hover {
  background: var(--teal-deep);
}

.btn.ghost:hover,
.btn:hover {
  border-color: var(--teal);
}

.btn.danger {
  color: var(--rust);
  border-color: color-mix(in srgb, var(--rust) 40%, var(--line));
}

.btn:disabled {
  opacity: 0.5;
  cursor: wait;
}

/* Never let display:flex on .btn win over the hidden attribute (Admin gear bug). */
[hidden],
.btn[hidden],
.btn.iconish[hidden] {
  display: none !important;
}

.btn.iconish {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.btn-compact {
  min-height: 34px;
  padding: 6px 10px;
  font-size: 12px;
}

.theme-label {
  font-size: 12px;
}

.yes {
  color: var(--ok);
  font-weight: 700;
}
.no {
  color: var(--muted);
}

/* —— Phone list (real mobile UI) —— */
.phone-list {
  display: grid;
  gap: 0;
}

.plist-item {
  display: grid;
  grid-template-columns: 52px minmax(0, 1fr);
  gap: 0 10px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  align-items: start;
  width: 100%;
  max-width: 100%;
  overflow: hidden;
}

.plist-item:last-child {
  border-bottom: 0;
}

.plist-item.orphan {
  grid-template-columns: 1fr;
}

.plist-port {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}

.plist-port .mono {
  font-size: 1.05rem;
  line-height: 1.1;
}

.plist-role {
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--muted);
  line-height: 1.2;
}

.plist-body {
  min-width: 0;
  overflow: hidden;
}

.plist-body.full {
  width: 100%;
}

.plist-line1 {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.plist-name {
  font-size: 13px;
  line-height: 1.25;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}

.plist-name.wrap {
  white-space: normal;
  word-break: break-word;
}

.plist-line1 .pill {
  flex-shrink: 0;
  font-size: 10px;
  padding: 2px 7px;
  max-width: 42%;
  overflow: hidden;
  text-overflow: ellipsis;
}

.plist-line2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  min-width: 0;
}

.plist-line2 a {
  flex: 1;
  min-width: 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--teal-deep);
  text-decoration: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.plist-badges {
  display: inline-flex;
  gap: 4px;
  flex-shrink: 0;
}

.badge {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.03em;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 6px;
  color: var(--muted);
  opacity: 0.55;
}

.badge.on {
  opacity: 1;
  color: var(--ok);
  border-color: color-mix(in srgb, var(--ok) 45%, var(--line));
  background: var(--pill-ok-bg);
}

.badge.warn {
  opacity: 1;
  color: var(--amber);
  border-color: color-mix(in srgb, var(--amber) 45%, var(--line));
  background: var(--pill-amber-bg);
}

.plist-actions {
  margin-top: 6px;
}

.plist-actions .btn {
  width: 100%;
}

.empty {
  margin: 0;
  padding: 20px 14px;
  color: var(--muted);
  text-align: center;
}

/* Login */
.login-body {
  min-height: 100vh;
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 28px 18px calc(28px + var(--safe-bottom));
  position: relative;
}

.login-shell {
  width: min(420px, 100%);
}

.login-toolbar {
  position: absolute;
  top: 16px;
  right: 16px;
  z-index: 2;
}

.login-form {
  margin-top: 28px;
  display: grid;
  gap: 16px;
}

.login-form label {
  display: grid;
  gap: 6px;
  font-size: 0.9rem;
  font-weight: 600;
  color: var(--muted);
}

.login-form input {
  width: 100%;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  font: inherit;
  background: var(--input-bg);
  color: var(--ink);
}

.login-form .btn {
  width: 100%;
  margin-top: 4px;
  min-height: 44px;
}

.login-form .error,
.form-error {
  margin: 0;
  color: var(--rust);
  font-size: 0.95rem;
  font-weight: 600;
}

/* Dialogs */
dialog {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  width: min(440px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  overflow: auto;
  background: var(--card);
  color: var(--ink);
  box-shadow: var(--elev);
}

dialog::backdrop {
  background: var(--backdrop);
}

dialog form,
.progress-card {
  padding: 22px;
  display: grid;
  gap: 14px;
}

dialog h3 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(1.2rem, 4vw, 1.4rem);
}

.dialog-sub {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  word-break: break-word;
}

.dialog-note {
  margin: 0;
  padding: 10px 12px;
  background: var(--note-bg);
  border-radius: 10px;
  font-size: 13px;
  color: var(--teal-deep);
  line-height: 1.4;
}

.progress-steps {
  margin: 0;
  padding: 0;
  list-style: none;
  display: grid;
  gap: 10px;
}

.progress-steps li {
  display: grid;
  grid-template-columns: 22px 1fr;
  gap: 10px;
  font-size: 14px;
  font-weight: 600;
  color: var(--muted);
}

.progress-steps li .mark {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 11px;
  background: var(--mark-bg);
}

.progress-steps li.active {
  color: var(--ink);
}
.progress-steps li.active .mark {
  border-color: var(--teal);
  color: var(--teal);
  animation: pulse 1s ease-in-out infinite;
}
.progress-steps li.done {
  color: var(--ok);
}
.progress-steps li.done .mark {
  border-color: var(--ok);
  background: var(--pill-ok-bg);
  color: var(--ok);
}
.progress-steps li.fail {
  color: var(--rust);
}
.progress-steps li.fail .mark {
  border-color: var(--rust);
  background: var(--pill-rust-bg);
  color: var(--rust);
}
.progress-steps li .detail {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
}

@keyframes pulse {
  0%,
  100% {
    transform: scale(1);
  }
  50% {
    transform: scale(1.08);
  }
}

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

dialog input:not([type="checkbox"]),
dialog select {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--input-bg);
  min-height: 44px;
  width: 100%;
}

dialog label.check {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  color: var(--ink);
}

dialog input[type="checkbox"] {
  -webkit-appearance: checkbox;
  appearance: checkbox;
  width: 1.05rem;
  height: 1.05rem;
  min-height: 0;
  min-width: 0;
  margin: 0;
  padding: 0;
  border: 1px solid var(--line);
  border-radius: 3px;
  flex: 0 0 auto;
  accent-color: var(--teal);
  background: var(--input-bg);
}

.dns-check {
  margin: -4px 0 0;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  min-height: 1.2em;
}

.dns-check.ok {
  color: var(--ok);
}

.dns-check.warn {
  color: var(--amber);
}

.dns-check.bad {
  color: var(--rust);
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  flex-wrap: wrap;
  gap: 8px;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

/* —— Smartphone layout —— */
@media (max-width: 820px) {
  .phone-only {
    display: revert !important;
  }

  .desk-only {
    display: none !important;
  }

  .phone-controls.phone-only {
    display: grid !important;
  }

  .phone-list.phone-only {
    display: grid !important;
  }

  .theme-label {
    display: none;
  }

  .top {
    flex-direction: row;
    align-items: center;
    gap: 10px;
    padding: calc(10px + var(--safe-top)) 12px 10px;
  }

  .brand-block {
    min-width: 0;
    flex: 1;
  }

  .eyebrow {
    margin: 0 0 2px;
    font-size: 10px;
  }

  h1 {
    font-size: 1.35rem;
  }

  .top-actions {
    align-items: flex-end;
    gap: 6px;
    flex-shrink: 0;
  }

  .stats {
    max-width: 100%;
    justify-content: flex-end;
    flex-wrap: nowrap;
    overflow-x: auto;
    gap: 4px;
    scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }

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

  .stat {
    padding: 3px 8px;
    font-size: 11px;
  }

  .action-row {
    gap: 4px;
    align-items: center;
  }

  .user-menu {
    order: -1;
    margin-right: auto;
  }

  .user-menu-btn {
    min-height: 34px;
    padding: 3px 8px 3px 3px;
  }

  .user-menu-panel {
    left: 0;
    right: auto;
    min-width: min(260px, calc(100vw - 24px));
  }

  .action-row .btn {
    min-height: 34px;
    padding: 5px 8px;
    font-size: 12px;
  }

  main {
    padding: 10px 10px calc(20px + var(--safe-bottom));
    gap: 10px;
  }

  .toolbar {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
  }

  .search {
    width: 100%;
  }

  .search input {
    width: 100%;
    min-height: 40px;
  }

  .panel {
    border-radius: 12px;
  }

  .panel-head {
    padding: 10px 12px;
  }

  .panel-titles h2 {
    font-size: 1.05rem;
  }

  .panel-titles .meta {
    font-size: 11px;
  }

  .dialog-actions .btn {
    flex: 1 1 auto;
    min-height: 44px;
  }
}

@media (max-width: 380px) {
  h1 {
    font-size: 1.2rem;
  }

  .plist-item {
    grid-template-columns: 44px minmax(0, 1fr);
    padding: 8px 10px;
  }

  .plist-port .mono {
    font-size: 0.95rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .panel,
  .progress-steps li.active .mark,
  html[data-theme="dark"] .atmosphere::after {
    animation: none !important;
  }
}

/* Admin panel */
.admin-dialog {
  width: min(560px, calc(100vw - 24px));
  max-height: calc(100dvh - 24px);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 0;
  background: var(--card);
  color: var(--ink);
}

.admin-dialog::backdrop {
  background: var(--backdrop);
}

.admin-card {
  padding: 20px 20px 24px;
  display: flex;
  flex-direction: column;
  gap: 22px;
  max-height: calc(100dvh - 24px);
  overflow: auto;
}

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

.admin-head h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.45rem;
}

.admin-section h4 {
  margin: 0 0 10px;
  font-size: 0.95rem;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}

.admin-form {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.admin-form label,
.scope-fieldset {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-weight: 600;
}

.scope-fieldset {
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px;
  margin: 0;
}

.scope-fieldset legend {
  padding: 0 6px;
  font-size: 0.85rem;
  color: var(--muted);
}

.admin-form input[type="email"],
.admin-form input[type="text"],
.admin-form input[type="password"],
#invite-ports,
#invite-link,
#totp-code {
  font: inherit;
  font-weight: 600;
  color: var(--ink);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--input-bg);
  min-height: 44px;
  width: 100%;
}

.invite-link-box {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  background: var(--note-bg);
}

.invite-link-row {
  display: flex;
  gap: 8px;
  margin-top: 8px;
}

.admin-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.admin-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--input-bg);
}

.admin-row strong {
  font-weight: 700;
}

.admin-row .meta-line {
  width: 100%;
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  font-weight: 600;
}

.admin-row .row-actions {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.mono.small {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 11px;
  word-break: break-all;
  color: var(--muted);
}

#totp-qr {
  display: block;
  margin: 8px 0;
  border-radius: 8px;
  background: #fff;
}

.totp-setup {
  margin-top: 8px;
  padding-top: 12px;
  border-top: 1px solid var(--line);
}

.totp-setup .dialog-actions {
  margin-top: 4px;
}

.login-form .btn.ghost {
  width: 100%;
  margin-top: 0;
}

#totp-form .btn {
  width: 100%;
}

#totp-form .btn.ghost {
  margin-top: 8px;
}

/* View-only file browser */
.files-dialog {
  width: min(960px, calc(100vw - 24px));
  max-width: 960px;
  border: 0;
  padding: 0;
  background: transparent;
}

.files-dialog::backdrop {
  background: var(--backdrop);
}

.files-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 16px;
  box-shadow: var(--elev);
  padding: 16px 18px 18px;
  display: grid;
  gap: 10px;
  max-height: min(86vh, 820px);
}

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

.files-head h3 {
  margin: 0;
  font-family: var(--display);
  font-size: 1.35rem;
}

.files-port {
  color: var(--teal-deep);
  font-weight: 700;
}

.files-crumb {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--th-bg);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
}

.files-crumb-btn {
  border: 0;
  background: transparent;
  color: var(--teal-deep);
  font: inherit;
  font-weight: 700;
  padding: 2px 4px;
  border-radius: 6px;
  cursor: pointer;
}

.files-crumb-btn:hover {
  background: color-mix(in srgb, var(--teal) 14%, transparent);
}

.files-crumb-sep {
  color: var(--muted);
}

.files-body {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) minmax(280px, 1.2fr);
  gap: 10px;
  min-height: 320px;
  max-height: min(58vh, 560px);
}

.files-list-wrap,
.files-preview-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.files-list {
  overflow: auto;
  padding: 6px;
  display: grid;
  gap: 2px;
  flex: 1;
}

.files-row {
  display: grid;
  grid-template-columns: 22px 1fr auto;
  gap: 8px;
  align-items: center;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  padding: 8px 10px;
  cursor: pointer;
}

.files-row:hover,
.files-row:focus-visible {
  background: color-mix(in srgb, var(--teal) 12%, var(--card));
  outline: none;
}

.files-row-icon {
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.02em;
  text-transform: uppercase;
  color: var(--muted);
}

.files-row-icon.kind-dir {
  color: var(--teal-deep);
}

.files-row-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-weight: 600;
  font-size: 13px;
}

.files-row-meta {
  font-size: 11px;
  font-weight: 600;
}

.files-preview-meta {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
  background: var(--th-bg);
}

.files-preview {
  margin: 0;
  padding: 12px 14px;
  overflow: auto;
  flex: 1;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.45;
  white-space: pre-wrap;
  word-break: break-word;
  color: var(--ink);
  background: var(--card);
}

@media (max-width: 720px) {
  .files-body {
    grid-template-columns: 1fr;
    max-height: none;
  }

  .files-list-wrap {
    max-height: 40vh;
  }

  .files-preview-wrap {
    min-height: 28vh;
  }
}

/* Database browser */
.db-card {
  width: min(1100px, calc(100vw - 24px));
}

.db-body {
  display: grid;
  grid-template-columns: minmax(160px, 220px) 1fr;
  gap: 10px;
  min-height: 360px;
  max-height: min(70vh, 640px);
}

.db-tables-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--paper);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.db-tables-head {
  padding: 8px 12px;
  border-bottom: 1px solid var(--line);
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  background: var(--th-bg);
}

.db-tables {
  overflow: auto;
  padding: 6px;
  display: grid;
  gap: 2px;
  flex: 1;
}

.db-table-btn {
  display: grid;
  gap: 2px;
  width: 100%;
  text-align: left;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--ink);
  font: inherit;
  padding: 8px 10px;
  cursor: pointer;
}

.db-table-btn:hover,
.db-table-btn.active {
  background: color-mix(in srgb, var(--teal) 12%, var(--card));
}

.db-table-name {
  font-weight: 700;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.db-table-meta {
  font-size: 11px;
  font-weight: 600;
}

.db-main {
  display: grid;
  grid-template-rows: auto 1fr auto;
  gap: 8px;
  min-height: 0;
  min-width: 0;
}

.db-result-meta {
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}

.db-grid-wrap {
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  overflow: auto;
  min-height: 140px;
}

.db-grid {
  width: max-content;
  min-width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.db-grid th,
.db-grid td {
  border-bottom: 1px solid var(--line);
  padding: 6px 10px;
  text-align: left;
  white-space: nowrap;
  max-width: 280px;
  overflow: hidden;
  text-overflow: ellipsis;
}

.db-grid th {
  position: sticky;
  top: 0;
  background: var(--th-bg);
  font-weight: 700;
  z-index: 1;
}

.db-grid tbody tr:hover td {
  background: var(--row-hover);
}

.db-sql-form {
  display: grid;
  gap: 6px;
}

.db-sql-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

#db-sql {
  width: 100%;
  resize: vertical;
  min-height: 88px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--input-bg);
  color: var(--ink);
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.4;
  padding: 10px 12px;
}

.db-sql-actions {
  margin: 0;
  justify-content: flex-end;
}

@media (max-width: 720px) {
  .db-body {
    grid-template-columns: 1fr;
    max-height: none;
  }

  .db-tables-wrap {
    max-height: 28vh;
  }

  .db-grid-wrap {
    max-height: 36vh;
  }
}
