:root {
  color-scheme: dark;
  --bg: #070b12;
  --bg-elevated: #0d1420;
  --bg-card: rgba(16, 24, 38, 0.88);
  --border: rgba(148, 163, 184, 0.12);
  --border-strong: rgba(148, 163, 184, 0.22);
  --text: #e8eef6;
  --muted: #8b9cb3;
  --faint: #5d708a;
  --accent: #22d3ee;
  --accent-2: #2dd4bf;
  --danger: #f87171;
  --danger-strong: #ef4444;
  --warn: #fbbf24;
  --ok: #34d399;
  --cpu: #38bdf8;
  --ram: #a78bfa;
  --disk: #34d399;
  --shadow: 0 20px 50px rgba(0, 0, 0, 0.45);
  --radius: 18px;
  --font: "Outfit", system-ui, -apple-system, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
}

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

html {
  margin: 0;
  min-height: 100%;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  margin: 0;
  min-height: 100%;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  font-family: var(--font);
  background:
    radial-gradient(1200px 600px at 10% -10%, rgba(34, 211, 238, 0.12), transparent 55%),
    radial-gradient(900px 500px at 90% 0%, rgba(167, 139, 250, 0.1), transparent 50%),
    radial-gradient(700px 400px at 50% 100%, rgba(45, 212, 191, 0.08), transparent 45%),
    var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  padding-left: env(safe-area-inset-left);
  padding-right: env(safe-area-inset-right);
}

/* Desktop shows full labels; mobile can switch to short */
.label-short { display: none; }
.label-full { display: inline; }

button, input { font: inherit; }
button { cursor: pointer; }

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

#app { min-height: 100vh; }

/* ─── Login ─── */

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

.login-card {
  width: min(420px, 100%);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: calc(var(--radius) + 4px);
  box-shadow: var(--shadow);
  backdrop-filter: blur(16px);
  padding: 32px 28px;
}

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

.brand-mark {
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  display: grid;
  place-items: center;
  color: #041018;
  font-weight: 700;
  font-size: 0.95rem;
  letter-spacing: -0.03em;
  box-shadow: 0 8px 24px rgba(34, 211, 238, 0.25);
  flex-shrink: 0;
}

.brand-text h1 {
  margin: 0;
  font-size: 1.25rem;
  letter-spacing: -0.02em;
}

.brand-text p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 0.88rem;
}

.login-card h2 {
  margin: 0 0 6px;
  font-size: 1.55rem;
  letter-spacing: -0.03em;
}

.login-card .subtitle {
  margin: 0 0 24px;
  color: var(--muted);
  line-height: 1.5;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  margin-bottom: 14px;
}

.field label {
  font-size: 0.86rem;
  color: var(--muted);
  font-weight: 500;
}

.field input {
  width: 100%;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: rgba(7, 11, 18, 0.65);
  color: var(--text);
  padding: 12px 14px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease;
}

.field input:focus {
  border-color: rgba(34, 211, 238, 0.55);
  box-shadow: 0 0 0 3px rgba(34, 211, 238, 0.12);
}

.password-wrap { position: relative; }
.password-wrap input { padding-right: 48px; }

.ghost-btn {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
  border: 0;
  background: transparent;
  color: var(--faint);
  padding: 6px 8px;
  border-radius: 8px;
}

.ghost-btn:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.04);
}

.error-box {
  margin: 4px 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.25);
  color: #fecaca;
  font-size: 0.9rem;
}

.ok-box {
  margin: 4px 0 14px;
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.25);
  color: #a7f3d0;
  font-size: 0.9rem;
}

.primary-btn {
  width: 100%;
  border: 0;
  border-radius: 12px;
  padding: 13px 16px;
  font-weight: 600;
  color: #041018;
  background: linear-gradient(135deg, var(--accent-2), var(--accent));
  box-shadow: 0 10px 28px rgba(34, 211, 238, 0.22);
  transition: transform 0.12s ease, filter 0.12s ease, opacity 0.12s ease;
}

.primary-btn:hover:not(:disabled) {
  filter: brightness(1.05);
  transform: translateY(-1px);
}

.primary-btn:disabled {
  opacity: 0.65;
  cursor: not-allowed;
}

.login-foot {
  margin-top: 18px;
  text-align: center;
  color: var(--faint);
  font-size: 0.82rem;
}

/* ─── Shell layout ─── */

.shell {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 20px;
  padding-top: max(12px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--border);
  background: rgba(7, 11, 18, 0.94);
  backdrop-filter: blur(14px);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
  flex: 1;
}

.topbar-titles {
  min-width: 0;
  flex: 1;
}

.topbar h1 {
  margin: 0;
  font-size: 1.1rem;
  letter-spacing: -0.02em;
}

.topbar .meta {
  color: var(--muted);
  font-size: 0.84rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-shrink: 0;
  justify-content: flex-end;
}

.user-chip {
  display: none;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: var(--muted);
  font-size: 0.86rem;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 4px rgba(52, 211, 153, 0.15);
}

.status-dot.stale {
  background: var(--warn);
  box-shadow: 0 0 0 4px rgba(251, 191, 36, 0.15);
}

.status-dot.error {
  background: var(--danger);
  box-shadow: 0 0 0 4px rgba(248, 113, 113, 0.15);
}

.secondary-btn,
.danger-btn {
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 500;
  font-size: 0.9rem;
  white-space: nowrap;
}

.secondary-btn:hover {
  background: rgba(255, 255, 255, 0.06);
}

.danger-btn {
  border-color: rgba(248, 113, 113, 0.45);
  color: #fecaca;
  background: rgba(248, 113, 113, 0.08);
}

.danger-btn:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.16);
}

.danger-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

/* ─── Sub-nav (Overview / Email / Console) ─── */

.subnav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 20px;
  border-bottom: 1px solid var(--border);
  background:
    linear-gradient(180deg, rgba(16, 24, 38, 0.98), rgba(10, 15, 24, 0.94));
  position: sticky;
  top: 0;
  z-index: 15;
}

.subnav-tabs {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  border-radius: 14px;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid rgba(148, 163, 184, 0.12);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.04);
  min-width: 0;
}

.nav-link {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-weight: 600;
  font-size: 0.9rem;
  letter-spacing: 0.01em;
  padding: 9px 18px;
  min-height: 40px;
  border-radius: 10px;
  text-decoration: none;
  cursor: pointer;
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, box-shadow 0.15s ease;
  -webkit-tap-highlight-color: transparent;
}

.nav-link:hover {
  color: var(--text);
  background: rgba(255, 255, 255, 0.05);
  text-decoration: none;
}

.nav-link.active {
  color: #041018;
  background: linear-gradient(135deg, #2dd4bf 0%, #22d3ee 100%);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.25) inset,
    0 6px 16px rgba(34, 211, 238, 0.22);
}

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

.warn-btn {
  border: 1px solid rgba(251, 191, 36, 0.4);
  background: rgba(251, 191, 36, 0.1);
  color: #fde68a;
  border-radius: 10px;
  padding: 9px 14px;
  font-weight: 600;
  font-size: 0.88rem;
  white-space: nowrap;
}

.warn-btn:hover:not(:disabled) {
  background: rgba(251, 191, 36, 0.18);
}

.warn-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-sm {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 8px;
  padding: 6px 12px;
  font-weight: 600;
  font-size: 0.8rem;
  white-space: nowrap;
  border: 1px solid var(--border-strong);
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
}

.btn-sm:hover:not(:disabled) {
  background: rgba(255, 255, 255, 0.08);
}

.btn-sm:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-sm.live-start {
  border-color: rgba(52, 211, 153, 0.4);
  background: rgba(52, 211, 153, 0.1);
  color: #6ee7b7;
}

.btn-sm.live-start:hover:not(:disabled) {
  background: rgba(52, 211, 153, 0.18);
}

.btn-sm.live-stop {
  border-color: rgba(248, 113, 113, 0.4);
  background: rgba(248, 113, 113, 0.1);
  color: #fecaca;
}

.btn-sm.live-stop:hover:not(:disabled) {
  background: rgba(248, 113, 113, 0.18);
}

.badge.live {
  color: #6ee7b7;
  background: rgba(52, 211, 153, 0.14);
  box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.25);
}

.badge.sleeping {
  color: var(--faint);
  background: rgba(255, 255, 255, 0.05);
}

.live-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--ok);
  box-shadow: 0 0 0 3px rgba(52, 211, 153, 0.2);
  animation: pulse-live 1.6s ease infinite;
}

@keyframes pulse-live {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.45; }
}

.model-name-cell {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.model-name-cell .row-live {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

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

/* legacy alias if anything still uses .nav */
.nav {
  display: none;
}

.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 120;
  max-width: min(360px, calc(100vw - 32px));
  padding: 12px 16px;
  border-radius: 12px;
  border: 1px solid var(--border-strong);
  background: rgba(15, 23, 36, 0.96);
  box-shadow: var(--shadow);
  color: var(--text);
  font-size: 0.9rem;
  animation: toast-in 0.2s ease;
}

.toast.ok {
  border-color: rgba(52, 211, 153, 0.35);
  color: #a7f3d0;
}

.toast.err {
  border-color: rgba(248, 113, 113, 0.35);
  color: #fecaca;
}

@keyframes toast-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.main {
  width: min(1180px, 100%);
  margin: 0 auto;
  padding: 24px;
}

.main.full-width {
  width: 100%;
  max-width: none;
  padding: 16px 20px 24px;
}

.grid-hero {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-bottom: 16px;
}

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

.metric-card {
  position: relative;
  overflow: hidden;
}

.metric-card::before {
  content: "";
  position: absolute;
  inset: 0 auto auto 0;
  width: 100%;
  height: 3px;
  background: var(--metric-color, var(--accent));
  opacity: 0.9;
}

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

.metric-label {
  margin: 0;
  color: var(--muted);
  font-size: 0.9rem;
  font-weight: 500;
}

.metric-value {
  margin: 4px 0 0;
  font-size: 2rem;
  font-weight: 700;
  letter-spacing: -0.04em;
  font-variant-numeric: tabular-nums;
}

.ring {
  --p: 0;
  --c: var(--metric-color, var(--accent));
  width: 68px;
  height: 68px;
  border-radius: 50%;
  background: conic-gradient(var(--c) calc(var(--p) * 1%), rgba(255, 255, 255, 0.08) 0);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}

.ring-inner {
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: #0b1220;
  display: grid;
  place-items: center;
  font-family: var(--mono);
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--text);
}

.bar {
  height: 8px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  margin-bottom: 12px;
}

.bar > span {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: inherit;
  background: linear-gradient(90deg, color-mix(in srgb, var(--metric-color) 70%, white), var(--metric-color));
  transition: width 0.45s ease;
}

.metric-foot {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  color: var(--faint);
  font-size: 0.82rem;
  font-family: var(--mono);
  flex-wrap: wrap;
}

.panel { margin-bottom: 16px; }

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

.panel-head h2 {
  margin: 0;
  font-size: 1.05rem;
  letter-spacing: -0.02em;
}

.panel-head span {
  color: var(--faint);
  font-size: 0.82rem;
  font-family: var(--mono);
}

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

.hint-text {
  margin: 0 0 14px;
  line-height: 1.45;
}

.info-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 12px;
}

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

.info-item {
  padding: 14px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--border);
}

.info-item .k {
  color: var(--faint);
  font-size: 0.78rem;
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

.info-item .v {
  font-weight: 600;
  font-size: 0.98rem;
  word-break: break-word;
}

.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.92rem;
}

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

th {
  color: var(--faint);
  font-weight: 500;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}

td { font-variant-numeric: tabular-nums; }

td.mono {
  font-family: var(--mono);
  font-size: 0.86rem;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 999px;
  font-size: 0.78rem;
  font-weight: 600;
  text-transform: capitalize;
}

.badge.online,
.badge.active {
  color: #6ee7b7;
  background: rgba(52, 211, 153, 0.12);
}

.badge.stopped,
.badge.errored,
.badge.stopping,
.badge.inactive,
.badge.failed {
  color: #fca5a5;
  background: rgba(248, 113, 113, 0.12);
}

.badge.unknown,
.badge.launching {
  color: #fde68a;
  background: rgba(251, 191, 36, 0.12);
}

.empty {
  color: var(--muted);
  padding: 8px 0;
}

.loading-page,
.error-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 24px;
  text-align: center;
}

/* ─── Email page ─── */

.link-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.link-card {
  display: block;
  padding: 16px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.03);
  color: inherit;
  transition: border-color 0.15s ease, background 0.15s ease, transform 0.12s ease;
  text-decoration: none;
}

.link-card:hover {
  border-color: rgba(34, 211, 238, 0.35);
  background: rgba(34, 211, 238, 0.06);
  transform: translateY(-1px);
  text-decoration: none;
}

.link-card strong {
  display: block;
  margin-bottom: 6px;
  color: var(--text);
}

.link-card span {
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.service-list {
  display: grid;
  gap: 10px;
}

.service-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.025);
}

.service-row .name {
  font-weight: 600;
}

.service-row .unit {
  color: var(--faint);
  font-family: var(--mono);
  font-size: 0.8rem;
  margin-top: 2px;
}

/* ─── Terminal console ─── */

.term-wrap {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 10px;
  min-height: calc(100vh - 170px);
  min-height: calc(100dvh - 170px);
}

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

.term-toolbar .hint {
  color: var(--muted);
  font-size: 0.88rem;
}

.term-frame {
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  overflow: hidden;
  background: #0a0f18;
  box-shadow: var(--shadow);
  min-height: 280px;
  height: calc(100vh - 220px);
  height: calc(100dvh - 220px);
  padding: 8px;
  max-width: 100%;
}

.term-frame .xterm {
  height: 100%;
}

.term-frame .xterm-viewport {
  overflow-y: auto !important;
}

/* ─── Modal ─── */

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(2, 6, 12, 0.72);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal {
  width: min(440px, 100%);
  background: #0f1724;
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: 18px;
  box-shadow: 0 24px 60px rgba(0, 0, 0, 0.55);
  padding: 24px;
}

.modal h3 {
  margin: 0 0 8px;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}

.modal p {
  margin: 0 0 16px;
  color: var(--muted);
  line-height: 1.5;
  font-size: 0.94rem;
}

.modal-actions {
  display: flex;
  gap: 10px;
  margin-top: 8px;
}

.modal-actions .primary-btn,
.modal-actions .secondary-btn,
.modal-actions .danger-btn {
  width: auto;
  flex: 1;
}

.modal .danger-btn.solid {
  background: linear-gradient(135deg, #f87171, #ef4444);
  border: 0;
  color: #1a0505;
  font-weight: 700;
}

@media (min-width: 900px) {
  .user-chip { display: inline-flex; }
}

/* Tablet */
@media (max-width: 960px) {
  .grid-hero { grid-template-columns: 1fr; }
  .info-grid { grid-template-columns: 1fr 1fr; }
  .link-grid { grid-template-columns: 1fr; }

  .subnav {
    flex-wrap: wrap;
  }

  .subnav-tabs {
    flex: 1 1 auto;
  }

  .subnav-actions {
    flex: 1 1 auto;
    justify-content: stretch;
  }

  .subnav-actions .warn-btn,
  .subnav-actions .danger-btn {
    flex: 1;
  }
}

/* Mobile phones */
@media (max-width: 720px) {
  .label-full { display: none; }
  .label-short { display: inline; }

  .login-page {
    padding: 16px;
    align-items: flex-start;
    padding-top: max(24px, env(safe-area-inset-top));
  }

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

  .login-card h2 {
    font-size: 1.35rem;
  }

  .topbar {
    padding: 10px 12px;
    padding-top: max(10px, env(safe-area-inset-top));
    gap: 8px;
  }

  .brand-mark {
    width: 36px;
    height: 36px;
    border-radius: 10px;
    font-size: 0.85rem;
  }

  .topbar h1 {
    font-size: 1rem;
  }

  .topbar .meta {
    font-size: 0.75rem;
  }

  .topbar-right {
    gap: 6px;
  }

  .secondary-btn,
  .danger-btn,
  .warn-btn {
    padding: 8px 10px;
    font-size: 0.82rem;
    min-height: 40px;
  }

  .subnav {
    flex-direction: column;
    align-items: stretch;
    gap: 8px;
    padding: 8px 12px 10px;
    position: sticky;
    top: 56px; /* sit under sticky topbar */
    z-index: 15;
  }

  .subnav-tabs {
    width: 100%;
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
  }

  .nav-link {
    flex: none;
    width: 100%;
    text-align: center;
    padding: 10px 6px;
    font-size: 0.82rem;
    min-height: 42px;
  }

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

  .subnav-actions .warn-btn,
  .subnav-actions .danger-btn {
    width: 100%;
    justify-content: center;
  }

  .main {
    padding: 12px;
    width: 100%;
  }

  .main.full-width {
    padding: 10px 12px 16px;
  }

  .card {
    padding: 14px;
    border-radius: 14px;
  }

  .grid-hero {
    gap: 10px;
    margin-bottom: 12px;
  }

  .metric-value {
    font-size: 1.55rem;
  }

  .ring {
    width: 56px;
    height: 56px;
  }

  .ring-inner {
    width: 42px;
    height: 42px;
    font-size: 0.7rem;
  }

  .metric-foot {
    font-size: 0.72rem;
  }

  .info-grid {
    grid-template-columns: 1fr 1fr;
    gap: 8px;
  }

  .info-item {
    padding: 10px;
    border-radius: 12px;
  }

  .info-item .v {
    font-size: 0.88rem;
  }

  .panel {
    margin-bottom: 12px;
  }

  .panel-head,
  .panel-head-stack {
    flex-direction: column;
    align-items: stretch;
    gap: 10px;
  }

  .panel-actions {
    justify-content: flex-start;
    width: 100%;
  }

  .panel-actions .warn-btn,
  .panel-actions .btn-sm {
    flex: 1 1 auto;
  }

  .hint-text {
    font-size: 0.86rem;
  }

  /* Tables → stacked cards on small screens */
  .table-wrap {
    overflow: visible;
    margin: 0 -2px;
  }

  table.mobile-cards {
    border-collapse: separate;
    border-spacing: 0;
  }

  table.mobile-cards thead {
    display: none;
  }

  table.mobile-cards tbody {
    display: grid;
    gap: 10px;
  }

  table.mobile-cards tr {
    display: grid;
    gap: 2px;
    padding: 12px;
    border: 1px solid var(--border);
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.03);
  }

  table.mobile-cards tr.is-live {
    border-color: rgba(52, 211, 153, 0.28);
    box-shadow: 0 0 0 1px rgba(52, 211, 153, 0.08);
  }

  table.mobile-cards td {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 6px 0;
    border-bottom: 1px solid rgba(148, 163, 184, 0.08);
    white-space: normal;
    text-align: right;
    min-width: 0;
  }

  table.mobile-cards td:last-child {
    border-bottom: 0;
    padding-top: 10px;
  }

  table.mobile-cards td::before {
    content: attr(data-label);
    color: var(--faint);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    text-align: left;
    flex-shrink: 0;
  }

  table.mobile-cards td.actions-cell {
    justify-content: stretch;
  }

  table.mobile-cards td.actions-cell::before {
    display: none;
  }

  table.mobile-cards td.actions-cell .btn-sm {
    width: 100%;
    min-height: 42px;
    justify-content: center;
  }

  table.mobile-cards td .empty {
    width: 100%;
    text-align: center;
  }

  .service-row {
    flex-wrap: wrap;
    gap: 8px;
  }

  .term-wrap {
    min-height: calc(100dvh - 200px);
  }

  .term-frame {
    min-height: 240px;
    height: calc(100dvh - 240px);
    border-radius: 12px;
    padding: 4px;
  }

  .term-toolbar {
    gap: 8px;
  }

  .term-toolbar .secondary-btn {
    flex: 1;
  }

  .modal-backdrop {
    padding: 12px;
    align-items: flex-end;
  }

  .modal {
    width: 100%;
    max-height: min(90dvh, 100%);
    overflow-y: auto;
    border-radius: 16px 16px 12px 12px;
    padding: 18px 16px calc(18px + env(safe-area-inset-bottom));
  }

  .modal-actions {
    flex-direction: column-reverse;
  }

  .modal-actions .secondary-btn,
  .modal-actions .danger-btn {
    width: 100%;
    min-height: 44px;
  }

  .toast {
    left: 12px;
    right: 12px;
    bottom: max(12px, env(safe-area-inset-bottom));
    max-width: none;
  }

  .field input {
    font-size: 16px; /* prevents iOS zoom on focus */
    min-height: 44px;
  }
}

/* Very small phones */
@media (max-width: 380px) {
  .info-grid {
    grid-template-columns: 1fr;
  }

  .nav-link {
    font-size: 0.78rem;
    padding: 10px 4px;
  }

  .metric-value {
    font-size: 1.35rem;
  }
}

/* Landscape phones: keep content usable */
@media (max-width: 900px) and (max-height: 480px) and (orientation: landscape) {
  .topbar {
    padding: 6px 12px;
  }

  .subnav {
    position: relative;
  }

  .term-frame {
    height: calc(100dvh - 140px);
    min-height: 180px;
  }

  .login-page {
    place-items: start center;
    padding-top: 12px;
  }
}
