/*
 * Labby App Stylesheet
 * -----------------------------------------------------------------------------
 * Contributor map:
 *  1. Base variables and shared components define the visual language.
 *  2. Desktop layout rules come first and must remain compatible with wide screens.
 *  3. Mobile behavior lives under @media (max-width: 1100px).
 *  4. Dialogs, sheets and rack-specific rules are grouped by feature.
 *
 * Style guide:
 *  - Reuse CSS variables instead of hard-coded theme colors.
 *  - Keep tap targets at least 44px on mobile.
 *  - Add new mobile-only fixes inside the mobile media block whenever possible.
 */

@import url('https://fonts.googleapis.com/css2?family=Space+Mono:wght@400;700&family=Inter:wght@400;600;700&display=swap');

:root {
  color-scheme: light;
  --bg: #ece9df;
  --bg-bottom: #d6ccc2;
  --wave: #ece9df;
  --phone: #f5f1e7;
  --panel: #ffffff;
  --text: #202126;
  --muted: #575a64;
  --line: #2e2f36;
  --yellow: #f4d371;
  --mint: #b8efca;
  --blue: #b8d9ff;
  --danger: #d84b4b;
  --type-hardware: #b8d9ff;
  --type-vm: #d6f0ff;
  --type-lxc: #d0f7ef;
  --type-app: #fce7d9;
  --type-network: #b8efca;
  --shadow: 0 14px 28px rgba(22, 25, 36, 0.14);
  --scroll-track: #f5ebe0;
  --scroll-thumb: #d6ccc2;
  --scroll-thumb-hover: #c6ac8f;
  --app-pad: clamp(10px, 1.1vw, 20px);
  --space-1: 0.3rem;
  --space-2: 0.5rem;
  --space-3: 0.75rem;
  --space-4: 1rem;
}

:root[data-theme='dark'] {
  color-scheme: dark;
  --bg: #1e1828;
  --bg-bottom: #15101e;
  --wave: #1e1828;
  --phone: #231d30;
  --panel: #2e2640;
  --text: #ede6f5;
  --muted: #9e8fb5;
  --line: #5c4d7a;
  --yellow: #e8b4d8;
  --mint: #352d48;
  --blue: #38304c;
  --danger: #e8909c;
  --type-hardware: #352c4a;
  --type-vm: #2c2844;
  --type-lxc: #2f6d72;
  --type-app: #5a4b7d;
  --type-network: #356f71;
  --shadow: 0 16px 34px rgba(10, 6, 18, 0.65);
  --scroll-track: #1c1626;
  --scroll-thumb: #5c4d7a;
  --scroll-thumb-hover: #7d6aa0;
}

:root[data-theme='ocean'] {
  color-scheme: light;
  --bg: #e3eef4;
  --bg-bottom: #c4dae6;
  --wave: #e3eef4;
  --phone: #eef6fa;
  --panel: #ffffff;
  --text: #15303d;
  --muted: #4c6675;
  --line: #1d4456;
  --yellow: #ffd36b;
  --mint: #b4ecd9;
  --blue: #bfe2f5;
  --danger: #e0574f;
  --type-hardware: #bfe2f5;
  --type-vm: #d2eefb;
  --type-lxc: #c9f0ea;
  --type-app: #ffe2cf;
  --type-network: #b4ecd9;
  --shadow: 0 14px 28px rgba(15, 50, 70, 0.18);
  --scroll-track: #d8e9f0;
  --scroll-thumb: #aacbdc;
  --scroll-thumb-hover: #87b3c9;
}

:root[data-theme='forest'] {
  color-scheme: light;
  --bg: #e8efe2;
  --bg-bottom: #cad9bf;
  --wave: #e8efe2;
  --phone: #f2f7ec;
  --panel: #ffffff;
  --text: #1f331f;
  --muted: #4f6149;
  --line: #2d4429;
  --yellow: #f2cf65;
  --mint: #c2eabf;
  --blue: #cfe6d4;
  --danger: #d8553f;
  --type-hardware: #cfe6d4;
  --type-vm: #dcefdc;
  --type-lxc: #c9eedd;
  --type-app: #f6e3c6;
  --type-network: #c2eabf;
  --shadow: 0 14px 28px rgba(30, 50, 25, 0.16);
  --scroll-track: #dde8d4;
  --scroll-thumb: #b6c9a8;
  --scroll-thumb-hover: #95ad84;
}

:root[data-theme='rose'] {
  color-scheme: light;
  --bg: #f4e7eb;
  --bg-bottom: #e3c6d0;
  --wave: #f4e7eb;
  --phone: #fbf0f3;
  --panel: #ffffff;
  --text: #3a2230;
  --muted: #6e5360;
  --line: #4a2535;
  --yellow: #f6cf7d;
  --mint: #d8ecd0;
  --blue: #d6e2f4;
  --danger: #d84b6b;
  --type-hardware: #f2cdd9;
  --type-vm: #e6d6f0;
  --type-lxc: #d6ece4;
  --type-app: #fbe0cf;
  --type-network: #d8ecd0;
  --shadow: 0 14px 28px rgba(60, 30, 45, 0.16);
  --scroll-track: #efdde3;
  --scroll-thumb: #d6b3c0;
  --scroll-thumb-hover: #c2909f;
}

:root[data-theme='solar'] {
  color-scheme: light;
  --bg: #f3e9d3;
  --bg-bottom: #e2cda2;
  --wave: #f3e9d3;
  --phone: #fbf3e1;
  --panel: #fffdf7;
  --text: #34291a;
  --muted: #6b5a3e;
  --line: #4a3a20;
  --yellow: #f3c441;
  --mint: #d8e8b0;
  --blue: #ffe0b0;
  --danger: #d8603f;
  --type-hardware: #ffe2b3;
  --type-vm: #ffedc4;
  --type-lxc: #e6edc0;
  --type-app: #ffd8b0;
  --type-network: #d8e8b0;
  --shadow: 0 14px 28px rgba(70, 50, 15, 0.18);
  --scroll-track: #ecdcbb;
  --scroll-thumb: #d4bc8a;
  --scroll-thumb-hover: #bd9f64;
}

:root[data-theme='midnight'] {
  color-scheme: dark;
  --bg: #0f1b2d;
  --bg-bottom: #08121f;
  --wave: #0f1b2d;
  --phone: #14253c;
  --panel: #1c3350;
  --text: #dce8f5;
  --muted: #8ba2bd;
  --line: #34557d;
  --yellow: #6cb6e8;
  --mint: #1d4a55;
  --blue: #1a3450;
  --danger: #e88a92;
  --type-hardware: #1f3a5c;
  --type-vm: #1c3450;
  --type-lxc: #1d4a55;
  --type-app: #2e3a66;
  --type-network: #1d5258;
  --shadow: 0 16px 34px rgba(2, 8, 18, 0.7);
  --scroll-track: #0d1828;
  --scroll-thumb: #34557d;
  --scroll-thumb-hover: #4a73a0;
}

:root[data-theme='carbon'] {
  color-scheme: dark;
  --bg: #16181b;
  --bg-bottom: #0e0f11;
  --wave: #16181b;
  --phone: #1e2125;
  --panel: #282c31;
  --text: #e6e8ea;
  --muted: #9aa1a9;
  --line: #444b54;
  --yellow: #e0c060;
  --mint: #2a3a32;
  --blue: #263340;
  --danger: #e08484;
  --type-hardware: #283540;
  --type-vm: #2c333d;
  --type-lxc: #2a3a36;
  --type-app: #3a3346;
  --type-network: #2a3a32;
  --shadow: 0 16px 34px rgba(0, 0, 0, 0.6);
  --scroll-track: #131518;
  --scroll-thumb: #444b54;
  --scroll-thumb-hover: #5e6670;
}

:root[data-theme='nord'] {
  color-scheme: dark;
  --bg: #2e3440;
  --bg-bottom: #232831;
  --wave: #2e3440;
  --phone: #3b4252;
  --panel: #434c5e;
  --text: #eceff4;
  --muted: #aeb8cc;
  --line: #5a6478;
  --yellow: #ebcb8b;
  --mint: #3b4a44;
  --blue: #3a4a5e;
  --danger: #bf616a;
  --type-hardware: #3e4a5e;
  --type-vm: #3a4456;
  --type-lxc: #3a4d4a;
  --type-app: #45405a;
  --type-network: #3b4a44;
  --shadow: 0 16px 34px rgba(10, 12, 18, 0.6);
  --scroll-track: #2a303b;
  --scroll-thumb: #5a6478;
  --scroll-thumb-hover: #76819a;
}

:root[data-theme='grape'] {
  color-scheme: dark;
  --bg: #020804;
  --bg-bottom: #000000;
  --wave: #031407;
  --phone: #050b07;
  --panel: #07120a;
  --text: #d9ffe2;
  --muted: #7cff9c;
  --line: #00ff66;
  --yellow: #39ff14;
  --mint: #063b18;
  --blue: #07351a;
  --danger: #ff3b5f;
  --type-hardware: #0b2f16;
  --type-vm: #092713;
  --type-lxc: #063b22;
  --type-app: #102414;
  --type-network: #0f4d24;
  --shadow: 0 18px 38px rgba(0, 255, 102, 0.18);
  --scroll-track: #020804;
  --scroll-thumb: #00b84a;
  --scroll-thumb-hover: #39ff14;
}

:root[data-theme='custom'] {
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }

body {
  margin: 0;
  font-family: Inter, system-ui, sans-serif;
  background: var(--bg-bottom);
  color: var(--text);
  height: 100vh;
  overflow: hidden;
  position: relative;
  isolation: isolate;
}

body::before {
  content: '';
  position: fixed;
  inset: 0;
  background: var(--bg);
  --split: 20%;
  --cut: calc(100% - var(--split));
  --amp: 2.2%;
  clip-path: polygon(
    0% 0%,
    100% 0%,
    100% calc(var(--cut) + var(--amp) * 0.35),
    92% calc(var(--cut) + var(--amp) * 0.12),
    84% calc(var(--cut) + var(--amp) * -0.05),
    76% calc(var(--cut) + var(--amp) * -0.18),
    68% calc(var(--cut) + var(--amp) * -0.26),
    60% calc(var(--cut) + var(--amp) * -0.28),
    52% calc(var(--cut) + var(--amp) * -0.22),
    44% calc(var(--cut) + var(--amp) * -0.10),
    36% calc(var(--cut) + var(--amp) * 0.05),
    28% calc(var(--cut) + var(--amp) * 0.18),
    20% calc(var(--cut) + var(--amp) * 0.27),
    12% calc(var(--cut) + var(--amp) * 0.24),
    6%  calc(var(--cut) + var(--amp) * 0.12),
    0%  calc(var(--cut) + var(--amp) * -0.05)
  );
  z-index: -1;
  pointer-events: none;
}

button, input, select, textarea { touch-action: manipulation; }

.topbar { width: min(80vw, 1920px); margin: 0 auto; padding: clamp(8px, 0.9vw, 14px) var(--app-pad); display: flex; justify-content: space-between; align-items: flex-start; gap: 0.6rem; }
.brand-wrap { display: flex; gap: 0.75rem; align-items: flex-start; }
.logo { width: clamp(34px, 2.1vw, 44px); height: clamp(34px, 2.1vw, 44px); display: block; object-fit: contain; border: 0; border-radius: 0; background: transparent; box-shadow: none; }
.topbar-actions { display: flex; gap: 0.5rem; }

/* Logo: the SVG is drawn directly without a decorative frame. */
.logo,
.brand-wrap .logo {
  border: 0 !important;
  background: transparent !important;
  box-shadow: none !important;
  border-radius: 0 !important;
  padding: 0 !important;
}

.brand { margin: 0; font: 700 clamp(0.76rem, 0.7vw, 0.95rem)/1 'Space Mono', monospace; }
h1 { margin: 0.18rem 0 0.1rem; font-family: 'Space Mono', monospace; font-size: clamp(1.15rem, 1.4vw, 1.7rem); }
.subtitle { font-size: clamp(0.76rem, 0.78vw, 0.95rem); }
.subtitle { margin: 0; color: var(--muted); }

.phone-grid {
  width: min(80vw, 1920px);
  margin: 0 auto;
  padding: 0 var(--app-pad) max(62px, env(safe-area-inset-bottom));
  height: calc(100vh - clamp(78px, 9.3vh, 114px));
  display: grid;
  grid-template-columns: minmax(320px, 0.95fr) minmax(520px, 2fr);
  gap: clamp(10px, 1vw, 16px);
  align-items: stretch;
  overflow: hidden;
}

.phone { background: color-mix(in srgb, var(--phone) 92%, white); border: 3px solid var(--line); border-radius: 24px; padding: 0.78rem; box-shadow: var(--shadow); min-height: 0; overflow: hidden; display: flex; flex-direction: column; transition: transform 180ms ease, box-shadow 180ms ease; }
.panel-center { grid-column: 2; }

h2, h3, legend { font-family: 'Space Mono', monospace; margin: 0 0 var(--space-2); }
.stack { display: grid; gap: var(--space-3); }
.share-row { display: grid; grid-template-columns: 1fr 1fr auto; gap: 0.4rem; align-items: end; }
.share-row input,
.share-row select,
.share-row .icon-btn { min-height: 42px; }
label { font-size: 0.82rem; color: var(--muted); display: grid; gap: var(--space-1); }

#resource-form { overflow: auto; min-height: 0; padding-right: var(--space-1); display: grid; gap: var(--space-2); align-content: start; }

input, select, textarea {
  border: 3px solid var(--line);
  background: var(--panel);
  color: var(--text);
  border-radius: 12px;
  padding: 0.44rem 0.58rem;
  font: 600 0.83rem/1.24 'Space Mono', monospace;
  width: 100%;
  transition: border-color 140ms ease, box-shadow 140ms ease, transform 140ms ease;
}
textarea { resize: vertical; min-height: 74px; }
::placeholder { color: #5e6270; opacity: 1; }
:root[data-dark] ::placeholder { color: #7a6a95; }

select option { color: #111; background: #fff; }
:root[data-dark] select option { color: #ede6f5; background: #2e2640; }
select[multiple] { min-height: 90px; }

.mini-title { margin: 0 0 var(--space-1); font: 700 0.82rem/1.2 "Space Mono", monospace; color: var(--muted); }
.color-picker { display: grid; grid-template-columns: repeat(6, 1.55rem); justify-content: center; gap: var(--space-2); }
.color-dot {
  width: 20px;
  height: 20px;
  border-radius: 999px;
  border: 2px solid var(--line);
  cursor: pointer;
}
.color-dot.active { outline: 2px solid var(--text); outline-offset: 1px; }

.network-fields { border: 2px solid var(--line); border-radius: 12px; padding: var(--space-2); margin: 0; display: grid; gap: var(--space-2); }
.nested-fields { margin-top: 0.2rem; }
.share-row.raid-row { grid-template-columns: 1fr 0.9fr 1fr auto; }

.button { border: 2px solid var(--line); border-radius: 14px; min-height: 36px; padding: 0.42rem 0.75rem; font: 700 0.8rem/1.2 'Space Mono', monospace; cursor: pointer; background: var(--yellow); color: #222; transition: transform 120ms ease, box-shadow 120ms ease, filter 120ms ease; }
.button.secondary { background: var(--panel); color: var(--text); border-color: var(--line); }
.button.danger { background: transparent; color: var(--danger); border-color: var(--danger); }
.actions { display: flex; gap: var(--space-2); margin-top: var(--space-1); }
.hidden { display: none !important; }

input:focus-visible,
select:focus-visible,
textarea:focus-visible,
.button:focus-visible,
.icon-btn:focus-visible,
.tree-toggle:focus-visible,
.ip-toggle:focus-visible,
.rack-toggle:focus-visible,
.color-dot:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--line) 68%, white);
  outline-offset: 2px;
}

.button,
.icon-btn,
.card,
.column,
.tree-chip,
.tree-dialog { transition: transform 120ms ease, box-shadow 140ms ease, opacity 140ms ease, filter 120ms ease; }

.button:hover { transform: translateY(-1px); box-shadow: 0 4px 12px rgba(0,0,0,0.12); }
.icon-btn:hover { transform: translateY(-1px); }

.button:active,
.icon-btn:active,
.tree-toggle:active { transform: translateY(1px) scale(0.99); box-shadow: none; }

input:hover,
select:hover,
textarea:hover { border-color: color-mix(in srgb, var(--line) 85%, white); }

input:focus,
select:focus,
textarea:focus { box-shadow: 0 0 0 3px color-mix(in srgb, var(--mint) 58%, transparent); }

.panel-head { display: flex; justify-content: space-between; align-items: center; gap: var(--space-2); margin-bottom: var(--space-2); }
.filters { margin: 0 0 var(--space-2); display: grid; grid-template-columns: 1fr 140px; gap: var(--space-2); }
.stats { border: 2px solid var(--line); background: var(--mint); border-radius: 12px; padding: 0.4rem 0.58rem; font: 700 0.76rem/1.24 'Space Mono', monospace; margin-bottom: var(--space-2); }
.boards { display: grid; gap: 0.5rem; flex: 1; min-height: 0; overflow: auto; padding-right: 0.18rem; }
.column { border: 2px solid var(--line); border-radius: 12px; padding: var(--space-2); background: var(--panel); }

.card { border: 2px solid var(--line); border-radius: 10px; padding: 0.42rem; background: var(--panel); margin-bottom: 0.32rem; }
.card[data-type='hardware'] { background: var(--type-hardware); }
.card[data-type='vm'] { background: var(--type-vm); }
.card[data-type='lxc'] { background: var(--type-lxc); }
.card[data-type='app'] { background: var(--type-app); }
.card[data-type='network'] { background: var(--type-network); }

.card-head { display: flex; justify-content: space-between; gap: var(--space-2); margin-bottom: var(--space-1); }
.title-wrap { display: flex; align-items: center; gap: 0.4rem; }
.type-badge { display: inline-block; width: 12px; height: 12px; border: 2px solid var(--line); }
.type-badge.hardware { border-radius: 999px; }
.type-badge.vm, .type-badge.lxc, .type-badge.app { border-radius: 999px; }
.type-badge.network { transform: rotate(45deg); }

.card-controls { display: flex; gap: 0.25rem; }
.icon-btn { border: 2px solid var(--line); border-radius: 14px; min-height: 36px; background: var(--panel); color: var(--text); font: 700 0.75rem/1 'Space Mono', monospace; padding: 0.25rem 0.55rem; cursor: pointer; transition: transform 120ms ease, box-shadow 120ms ease; }
.icon-btn.delete-btn { color: var(--danger); border-color: var(--danger); background: transparent; }
.icon-btn.delete-btn:hover { background: color-mix(in srgb, var(--danger) 12%, var(--panel)); }

.card-title { margin: 0; font-size: 0.82rem; color: #1f2330; }
.card-desc, .card-links, .card-ip, .card-app, .card-specs, .card-network, .card-hosting, .card-notes {
  margin: 0.12rem 0;
  font: 600 0.69rem/1.22 'Space Mono', monospace;
  color: #2d2f36;
}
:root[data-dark] .card-desc,
:root[data-dark] .card-links,
:root[data-dark] .card-ip,
:root[data-dark] .card-app,
:root[data-dark] .card-specs,
:root[data-dark] .card-network,
:root[data-dark] .card-hosting,
:root[data-dark] .card-notes { color: #cfc0e8; }

.note { border: 3px solid var(--line); border-radius: 12px; padding: var(--space-3); background: var(--blue); font: 700 0.85rem/1.35 'Space Mono', monospace; }
.file-label { position: relative; overflow: hidden; display: inline-flex; justify-content: center; }
.file-label input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }

.legend { margin-top: var(--space-3); border: 3px solid var(--line); border-radius: 14px; padding: var(--space-2); background: var(--panel); font: 700 0.85rem/1.4 'Space Mono', monospace; }
.legend p { margin: var(--space-1) 0; display: flex; align-items: center; gap: var(--space-2); }
.dot { width: 12px; height: 12px; border-radius: 999px; display: inline-block; border: 2px solid var(--line); }
.dot.hardware { background: var(--type-hardware); border-radius: 999px; }
.dot.vm { background: var(--type-vm); }
.dot.lxc { background: var(--type-lxc); }
.dot.app { background: var(--type-app); }
.dot.network { background: var(--type-network); }

.bottom-actions {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  display: flex;
  flex-direction: row;
  gap: 10px;
  align-items: center;
}

.tree-toggle {
  border: 3px solid var(--line);
  border-radius: 14px;
  padding: 0.5rem 0.7rem;
  background: var(--yellow);
  font: 700 0.8rem/1.2 'Space Mono', monospace;
  cursor: pointer;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.2);
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}

.tree-dialog {
  width: min(1280px, calc(100vw - 96px));
  height: min(760px, calc(100dvh - 96px));
  max-width: calc(100vw - 96px);
  max-height: calc(100dvh - 96px);
  box-sizing: border-box;
  border: 3px solid var(--line);
  border-radius: 16px;
  background: var(--phone);
  color: var(--text);
  padding: 0.9rem;
  animation: pop-in 180ms ease;
  margin: auto;
  overflow: hidden;
}

/* Keep native <dialog> close behavior intact.
   Do not set display:flex on the closed dialog, otherwise close() only
   removes the open attribute while CSS keeps the popup visible/clickable. */
.tree-dialog[open] {
  display: flex;
  flex-direction: column;
}
.tree-dialog .legend { margin-bottom: 0; }
.tree-dialog::backdrop { background: rgba(0, 0, 0, 0.45); }
.tree-head {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: var(--space-2);
  margin-bottom: var(--space-2);
}
.tree-head h3 { margin: 0; }
.tree-dialog .tree-head,
.tree-dialog .ip-search-bar {
  flex: 0 0 auto;
}
.tree-head-actions { display: inline-flex; align-items: center; gap: var(--space-2); justify-self: end; }
.view-switch { display: inline-flex; border: 2px solid var(--line); border-radius: 10px; padding: 2px; background: var(--panel); gap: 2px; }
.view-switch .icon-btn { min-height: 30px; padding: 0.2rem 0.55rem; }
.view-switch .icon-btn.active { background: var(--yellow); color: #111; }
.tree-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  font: 600 0.85rem/1.4 'Space Mono', monospace;
  padding-right: var(--space-1);
}
.tree-content.graph-mode {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding-right: 0;
  overflow: hidden;
  max-height: none;
}
.tree-shell {
  border: 3px solid var(--line);
  border-radius: 14px;
  padding: 0.75rem;
  background: var(--panel);
  display: grid;
  gap: 0.8rem;
  min-height: 0;
}
.tree-content.graph-mode .tree-shell {
  flex: 1 1 auto;
  height: 100%;
  min-height: 0;
  overflow: hidden;
}
.tree-section h4 { margin: 0 0 0.55rem; font-size: 1rem; }
.tree-body { display: grid; gap: 0.45rem; }
.tree-lane { border-left: 2px dashed var(--line); padding-left: 0.8rem; display: grid; gap: 0.25rem; }
.tree-lane.nested { margin-top: 0.15rem; }
.tree-children { display: grid; gap: 0.35rem; margin-left: 0.65rem; }
.tree-chip { display: inline-flex; width: fit-content; align-items: center; border: 2px solid var(--line); border-radius: 999px; padding: 0.15rem 0.55rem; font: 700 0.8rem/1.2 'Space Mono', monospace; background: var(--panel); color: #1f2330; }
.tree-meta { color: var(--muted); margin: 0; display: flex; flex-wrap: wrap; gap: 0.3rem; align-items: center; }
.tree-link { color: var(--text); text-decoration: underline; text-underline-offset: 2px; word-break: break-all; }
.tree-link:hover { opacity: 0.8; }
.tree-dot { color: var(--muted); }
.tree-empty { color: var(--muted); margin: 0.1rem 0; font-style: italic; }
.tree-subgroup { border: 2px solid var(--line); border-radius: 10px; padding: 0.45rem; display: grid; gap: 0.35rem; }
.tree-subtitle { margin: 0; font-size: 0.78rem; color: var(--muted); }

.tree-collapsible > summary { list-style: none; }
.tree-collapsible > summary::-webkit-details-marker { display: none; }
.tree-summary {
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.45rem;
  padding: 0.2rem 0.25rem;
  border-radius: 8px;
}
.tree-group-head {
  cursor: default;
  font-weight: 700;
}
.tree-summary::before {
  content: '▸';
  color: var(--muted);
  font-size: 0.84rem;
  flex-shrink: 0;
  width: 0.6rem;
  text-align: center;
  line-height: 1;
  align-self: center;
}
.tree-group-head::before { content: ''; width: 0; }
.tree-collapsible[open] > .tree-summary::before { content: '▾'; }
.tree-summary-host,
.tree-summary-guest {
  justify-content: flex-start;
  flex-wrap: wrap;
  gap: 0.45rem;
}
.tree-summary .tree-meta { margin: 0; }
.tree-count {
  margin-left: auto;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.05rem 0.4rem;
  font-size: 0.68rem;
  color: var(--muted);
}
.tree-host,
.tree-guest { margin-left: 0.35rem; }
.tree-layer-host,
.tree-layer-guest {
  margin-left: 1rem;
  border-left: 2px dashed var(--line);
  padding-left: 0.75rem;
}
.tree-lane.nested { margin-left: 0; }
:root[data-dark] .tree-shell { background: var(--panel); }
:root[data-dark] .tree-link { color: #c4a8e0; }

.graph-wrap { position: relative; display: grid; overflow: hidden; justify-content: center; align-items: start; align-content: start; width: 100%; height: 100%; overscroll-behavior: contain; touch-action: none; }
.tree-content.graph-mode .graph-wrap {
  min-height: 0;
  height: 100%;
}
.graph-canvas {
  position: relative;
  width: var(--graph-width, 880px);
  height: var(--graph-height, 520px);
  min-width: var(--graph-width, 880px);
  min-height: var(--graph-height, 520px);
  border: 0;
  border-radius: 10px;
  box-sizing: border-box;
  background: transparent;
  overflow: visible;
  transform-origin: top left;
  will-change: transform;
}

.graph-links { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.graph-node {
  position: absolute;
  transform: translate(-50%, -50%);
  width: 46px;
  height: 46px;
  border-radius: 999px;
  border: 3px solid var(--line);
  display: grid;
  place-items: center;
  font-size: 1.25rem;
  background: var(--panel);
  cursor: pointer;
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}
.graph-tooltip {
  position: absolute;
  z-index: 7;
  pointer-events: none;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--phone);
  padding: 0.22rem 0.5rem;
  font: 700 0.74rem/1.2 'Space Mono', monospace;
  box-shadow: var(--shadow);
  white-space: nowrap;
  max-width: min(260px, 70vw);
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

.toast {
  position: fixed;
  top: 14px;
  left: 50%;
  transform: translate(-50%, -20px);
  opacity: 0;
  pointer-events: none;
  z-index: 40;
  max-width: min(90vw, 520px);
  border: 3px solid var(--line);
  border-radius: 12px;
  padding: 0.55rem 0.8rem;
  background: var(--panel);
  font: 700 0.82rem/1.3 'Space Mono', monospace;
  box-shadow: var(--shadow);
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
  transition: transform 170ms ease, opacity 170ms ease;
}

@keyframes pop-in {
  from { opacity: 0; transform: scale(0.97) translateY(4px); }
  to { opacity: 1; transform: scale(1) translateY(0); }
}

* {
  scrollbar-width: thin;
  scrollbar-color: var(--scroll-thumb) var(--scroll-track);
}

#resource-form::-webkit-scrollbar,
.boards::-webkit-scrollbar,
.tree-content::-webkit-scrollbar,
.tree-dialog::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}

#resource-form::-webkit-scrollbar-track,
.boards::-webkit-scrollbar-track,
.tree-content::-webkit-scrollbar-track,
.tree-dialog::-webkit-scrollbar-track {
  background: var(--scroll-track);
  border-radius: 999px;
}

#resource-form::-webkit-scrollbar-thumb,
.boards::-webkit-scrollbar-thumb,
.tree-content::-webkit-scrollbar-thumb,
.tree-dialog::-webkit-scrollbar-thumb {
  background: var(--scroll-thumb);
  border-radius: 999px;
  border: 2px solid var(--scroll-track);
}

#resource-form::-webkit-scrollbar-thumb:hover,
.boards::-webkit-scrollbar-thumb:hover,
.tree-content::-webkit-scrollbar-thumb:hover,
.tree-dialog::-webkit-scrollbar-thumb:hover {
  background: var(--scroll-thumb-hover);
}

.github {
  position: fixed;
  left: 18px;
  bottom: 18px;
  z-index: 20;

  display: inline-flex;
  align-items: center;
  gap: 0.5rem;

  padding: 0.5rem 0.7rem;
  border: 3px solid var(--line);
  border-radius: 14px;

  background: color-mix(in srgb, var(--phone) 92%, white);
  color: var(--text);
  text-decoration: none;

  font: 700 0.8rem/1.2 'Space Mono', monospace;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.2);

  transition: transform 140ms ease, box-shadow 180ms ease, opacity 160ms ease;
}

.github svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

.github:hover { transform: translateY(-1px); }
.github:active { transform: translateY(1px) scale(0.99); }

.github:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--line) 68%, white);
  outline-offset: 2px;
}

.website-link {
  left: 132px;
}

.website-link svg {
  width: 18px;
  height: 18px;
  fill: currentColor;
}

@media (max-width: 1100px) {
  body { height: auto; min-height: 100vh; overflow: auto; }
  .topbar,
  .phone-grid { width: 100%; }
  .topbar { align-items: stretch; gap: 0.8rem; }
  .topbar-actions { flex-wrap: wrap; justify-content: flex-end; }
  .phone-grid { grid-template-columns: 1fr; height: auto; overflow: visible; }
  .panel-center { grid-column: auto; }
  .phone { min-height: auto; }
  #resource-form,
  .boards { min-height: auto; max-height: none; }
  .bottom-actions { bottom: max(12px, env(safe-area-inset-bottom)); right: max(12px, env(safe-area-inset-right)); }
}

@media (min-width: 2000px) {
  .topbar {
    width: min(80vw, 2200px);
    padding-inline: clamp(22px, 2vw, 48px);
  }
  .phone-grid {
    width: min(80vw, 2200px);
    padding-inline: clamp(22px, 2vw, 48px);
    grid-template-columns: minmax(400px, 0.95fr) minmax(900px, 2.3fr);
    gap: clamp(14px, 1.2vw, 24px);
  }
  .phone { border-radius: 28px; }
}

@media (max-width: 820px) {
  .topbar { padding: 0.85rem 0.8rem; flex-direction: column; }
  .brand-wrap { align-items: center; }
  .topbar-actions { width: 100%; justify-content: flex-start; }
  .topbar-actions .button { flex: 1; }
  h1 { font-size: 1.35rem; }
  .phone-grid { padding: 0.4rem 0.55rem 8rem; gap: 0.8rem; }
  .phone { border-width: 3px; border-radius: 24px; padding: 0.8rem; }
  .filters { grid-template-columns: 1fr; }
  .panel-head { flex-wrap: wrap; }
  .actions { flex-direction: column; }
  .actions .button { width: 100%; }
  .share-row { grid-template-columns: 1fr; }
  select[multiple] { min-height: 110px; }
  .tree-dialog {
    width: calc(100vw - 12px);
    height: calc(100dvh - 12px);
    max-width: calc(100vw - 12px);
    max-height: calc(100dvh - 12px);
    margin: 6px;
    border-radius: 14px;
    padding: 0.65rem;
  }
  .tree-content { flex: 1 1 auto; min-height: 0; max-height: none; font-size: 0.8rem; }
  .tree-head { position: sticky; top: 0; background: var(--phone); padding-bottom: 0.4rem; z-index: 2; }
  .tree-head { grid-template-columns: 1fr; }
  .tree-head-actions { width: 100%; justify-content: space-between; justify-self: stretch; flex-wrap: wrap; }
  .tree-head-actions > .icon-btn { order: -1; }
  .view-switch { margin-left: auto; }
  .view-switch .icon-btn { min-height: 34px; }
  .graph-wrap { grid-template-columns: 1fr; overflow: auto; }
  .graph-info-panel { width: 100%; min-height: 0; max-height: none; height: auto; }
  .graph-node { width: 40px; height: 40px; font-size: 1.05rem; }
  .toast { width: calc(100vw - 20px); }
  .bottom-actions { left: 10px; right: 10px; bottom: max(12px, env(safe-area-inset-bottom)); flex-direction: column-reverse; gap: 8px; }
  .tree-toggle, .ip-toggle { width: 100%; text-align: center; box-sizing: border-box; }
  #config-toggle { display: none; }
}

@media (max-width: 480px) {
  input, select, textarea { font-size: 16px; }

  .card-head { flex-wrap: wrap; }
  .card-controls { width: 100%; }
  .card-controls .icon-btn { flex: 1; }
  .github { display: none; }
  #config-toggle { display: none; }
}

:root[data-dark] .column { background: var(--panel); }
:root[data-dark] .stats { background: #352d48; color: #d4c0f0; }
:root[data-dark] .tree-dialog { box-shadow: 0 10px 32px rgba(0, 0, 0, 0.45); }
:root[data-dark] .tree-shell { background: var(--panel); }

:root[data-dark] .card-title { color: #f2f5ff; }

:root[data-dark] .tree-chip { color: #ecf1ff; background: #2a3756; }
:root[data-dark] .tree-meta,
:root[data-dark] .tree-empty,
:root[data-dark] .tree-subtitle { color: #bdc7ea; }
:root[data-dark] .tree-link { color: #a9d2ff; }

/* ── IP View styles ── */
.ip-toggle {
  border: 3px solid var(--line);
  border-radius: 14px;
  padding: 0.5rem 0.7rem;
  background: var(--mint);
  font: 700 0.8rem/1.2 'Space Mono', monospace;
  cursor: pointer;
  box-shadow: 0 10px 18px rgba(0,0,0,0.2);
  transition: transform 120ms ease, filter 120ms ease, box-shadow 120ms ease;
}
.ip-toggle:hover { filter: brightness(0.93); }
.ip-toggle:active { transform: translateY(1px) scale(0.99); }

.ip-search-bar { margin-bottom: var(--space-2); }
.ip-search-bar input {
  width: 100%;
  box-sizing: border-box;
  padding: 0.5rem 0.7rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--bg);
  color: var(--text);
  font: 0.85rem/1.4 'Space Mono', monospace;
}
.ip-search-bar input:focus { outline: none; border-color: var(--accent); }
.ip-subnet-block { margin-bottom: var(--space-3); }
.ip-subnet-head { display: flex; align-items: center; gap: var(--space-2); margin-bottom: var(--space-1); }
.ip-subnet-label { font: 700 0.8rem/1.2 'Space Mono', monospace; background: var(--yellow); border: 2px solid var(--line); border-radius: 8px; padding: 0.2rem 0.5rem; }
.ip-subnet-name { font: 0.78rem/1.2 'Space Mono', monospace; color: var(--text-2); }
.ip-row { display: flex; align-items: center; gap: var(--space-2); padding: 0.3rem 0.5rem; border: 2px solid var(--line); border-radius: 8px; background: var(--panel); margin-bottom: 0.25rem; }
.ip-row-addr { font: 700 0.78rem/1.2 'Space Mono', monospace; min-width: 140px; }
.ip-row-name { font-size: 0.82rem; }
.ip-row-type { font-size: 0.72rem; color: var(--text-2); margin-left: auto; }
.ip-highlight { background: var(--yellow); border-radius: 3px; padding: 0 2px; }
.ip-empty { font-size: 0.82rem; color: var(--text-2); padding: 0.3rem 0.5rem; }

/* ── Bottom action buttons (desktop) ── */
.bottom-actions {
  position: fixed;
  right: 18px;
  bottom: 18px;
  z-index: 20;
  display: flex;
  flex-direction: row;
  gap: 10px;
}

/* ── Bottom nav (mobile/tablet only) ── */
.bottom-nav { display: none; }
.form-close-mobile { display: none; }

/* ── Mobile view panels ── */
.mobile-view {
  display: none;
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  z-index: 50;
  background: var(--phone);
  flex-direction: column;
  overflow: hidden;
}
.mobile-view.active { display: flex; }

.mobile-view-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1rem 1rem 0.6rem;
  border-bottom: 2px solid var(--line);
  flex-shrink: 0;
  background: var(--phone);
}
.mobile-view-head h2 { margin: 0; font-size: 1rem; }
.mobile-view-body {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
}
.mobile-view-footer {
  padding: 0.7rem 1rem;
  padding-bottom: max(0.7rem, env(safe-area-inset-bottom));
  border-top: 2px solid var(--line);
  background: var(--phone);
  flex-shrink: 0;
}
.mobile-view-footer .button { width: 100%; }

@media (max-width: 1100px) {
  .bottom-actions { display: none; }

  .bottom-nav {
    display: flex;
    position: fixed;
    bottom: 0; left: 0; right: 0;
    z-index: 30;
    background: var(--panel);
    border-top: 3px solid var(--line);
    padding: 0.4rem 0 max(0.5rem, env(safe-area-inset-bottom));
    justify-content: space-around;
    box-shadow: 0 -4px 18px rgba(0,0,0,0.12);
  }
  .bottom-nav-item {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 0.2rem;
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.3rem 0.2rem;
    border-radius: 10px;
    color: var(--text);
    margin: 0 4px;
  }
  .bottom-nav-item.active { background: var(--yellow); }
  .bottom-nav-icon { font-size: 1.3rem; line-height: 1; }
  .bottom-nav-label { font: 700 0.62rem/1 'Space Mono', monospace; }

  .phone-grid {
    grid-template-columns: 1fr !important;
    padding-bottom: calc(72px + max(0.5rem, env(safe-area-inset-bottom)));
  }
  .panel-left { display: none !important; }

  .github { display: none; }
}

.dialog-footer {
  flex: 0 0 auto;
  margin-top: var(--space-2);
  padding-top: var(--space-2);
  border-top: 2px solid var(--line);
  display: block;
  background: var(--phone);
}
.dialog-footer .button {
  display: block;
  width: 100%;
  box-sizing: border-box;
  text-align: center;
}

.card-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  margin: 0.25rem 0;
}
.card-action-copy {
  font: 600 0.7rem/1.2 'Space Mono', monospace;
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 0.2rem 0.45rem;
  cursor: pointer;
  color: var(--text);
  max-width: 200px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  transition: background 0.15s;
}
.card-action-copy:hover { background: var(--mint); }
.card-action-copy.copied { background: #b6f0c8; border-color: #4caf50; }
.card-action-link {
  font: 600 0.7rem/1.2 'Space Mono', monospace;
  background: var(--yellow);
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 0.2rem 0.45rem;
  cursor: pointer;
  color: var(--text);
  text-decoration: none;
  transition: background 0.15s;
}
.card-action-link:hover { filter: brightness(0.92); }

.card-status {
  display: inline-block;
  font: 700 0.7rem/1.2 'Space Mono', monospace;
  padding: 0.15rem 0.45rem;
  border-radius: 6px;
  margin-bottom: 0.2rem;
  border: 2px solid transparent;
}
.card-status:empty { display: none; }
.status-online  { background: #d4f5d4; border-color: #4caf50; color: #1a5c1a; }
.status-offline { background: #fdd; border-color: #e53935; color: #5c1a1a; }
.status-maintenance { background: #fff8d4; border-color: #f9a825; color: #5c4200; }

.card-live-status {
  margin: 0.4rem 0;
  padding: 0.5rem 0.6rem;
  background: var(--blue);
  border: 2px solid var(--line);
  border-radius: 8px;
  font: 700 0.75rem/1.3 'Space Mono', monospace;
  color: var(--text);
  display: flex;
  flex-wrap: wrap;
  gap: 0.5rem;
  align-items: center;
}
.card-live-status:empty { display: none; }

.status-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.45rem;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 6px;
  white-space: nowrap;
  font-size: 0.7rem;
  line-height: 1.2;
}

.status-badge strong { font-weight: 800; }

.card-offline { opacity: 0.65; }
.card-maintenance { border-style: dashed !important; }

:root[data-dark] .status-online  { background: #203028; color: #a8ddb8; border-color: #7abd90; }
:root[data-dark] .status-offline { background: #2e2030; color: #e8a0b0; border-color: #c47888; }
:root[data-dark] .status-maintenance { background: #2e2838; color: #e8d0a0; border-color: #c8a870; }
:root[data-dark] .bottom-nav-item.active { background: #3d3452; outline: 2px solid #c4a8e0; }

@keyframes btn-bounce {
  0%   { transform: scale(1); }
  30%  { transform: scale(0.88); }
  60%  { transform: scale(1.12); }
  80%  { transform: scale(0.96); }
  100% { transform: scale(1); }
}

@keyframes btn-glow {
  0%   { box-shadow: 0 0 0 0 rgba(255, 220, 80, 0.7); }
  60%  { box-shadow: 0 0 0 8px rgba(255, 220, 80, 0); }
  100% { box-shadow: 0 0 0 0 rgba(255, 220, 80, 0); }
}

@keyframes nav-pop {
  0%   { transform: scale(1) translateY(0); }
  35%  { transform: scale(0.85) translateY(3px); }
  65%  { transform: scale(1.18) translateY(-4px); }
  85%  { transform: scale(0.96) translateY(1px); }
  100% { transform: scale(1) translateY(0); }
}

@keyframes delete-shake {
  0%   { transform: rotate(0deg); }
  20%  { transform: rotate(-8deg); }
  40%  { transform: rotate(8deg); }
  60%  { transform: rotate(-5deg); }
  80%  { transform: rotate(5deg); }
  100% { transform: rotate(0deg); }
}

.button:hover {
  transform: translateY(-2px) scale(1.02);
  box-shadow: 0 6px 16px rgba(0,0,0,0.13);
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.button:active {
  animation: btn-bounce 0.35s ease forwards;
}

.button.primary:active,
.button[type="submit"]:active {
  animation: btn-bounce 0.35s ease forwards, btn-glow 0.5s ease forwards;
}

.button.danger:hover { background: color-mix(in srgb, var(--danger) 12%, var(--panel)); animation: delete-shake 0.4s ease; }

.icon-btn:hover {
  transform: scale(1.08);
  transition: transform 0.15s ease;
}

.icon-btn:active {
  animation: btn-bounce 0.3s ease forwards;
}

.bottom-nav-item:active {
  animation: nav-pop 0.4s ease forwards;
}

.tree-toggle:hover,
.ip-toggle:hover {
  transform: translateY(-3px) scale(1.04) !important;
  box-shadow: 0 8px 20px rgba(0,0,0,0.18) !important;
  transition: transform 0.15s ease, box-shadow 0.15s ease !important;
  filter: none !important;
}

.tree-toggle:active,
.ip-toggle:active {
  animation: btn-bounce 0.35s ease forwards;
}

.card-action-copy:hover {
  transform: scale(1.05);
  transition: transform 0.12s ease;
}
.card-action-copy:active {
  animation: btn-bounce 0.25s ease forwards;
}

.card-action-link:hover {
  transform: scale(1.05) translateY(-1px);
  transition: transform 0.12s ease;
}
.card-action-link:active {
  animation: btn-bounce 0.25s ease forwards;
}

.welcome-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(0,0,0,0.55);
  align-items: center;
  justify-content: center;
  padding: 1rem;
}
.welcome-overlay.active { display: flex; }

.welcome-card {
  background: var(--phone);
  border: 3px solid var(--line);
  border-radius: 24px;
  padding: 2rem 1.8rem 1.5rem;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 20px 60px rgba(0,0,0,0.35);
  text-align: center;
  animation: pop-in 200ms ease;
}

.tutorial-icon { font-size: 3rem; line-height: 1; margin-bottom: 0.8rem; }
.tutorial-title { font: 700 1.1rem/1.3 'Space Mono', monospace; margin: 0 0 0.8rem; }
.tutorial-text { font-size: 0.88rem; line-height: 1.6; color: var(--text); margin: 0 0 1.2rem; }

.tutorial-dots {
  display: flex;
  justify-content: center;
  gap: 0.4rem;
  margin-bottom: 0.5rem;
}
.tutorial-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--line);
  cursor: pointer;
  transition: background 0.15s, transform 0.15s;
}
.tutorial-dot.active { background: var(--yellow); transform: scale(1.3); }

.tutorial-progress {
  font: 0.7rem/1 'Space Mono', monospace;
  color: var(--muted);
  margin-bottom: 1rem;
}

.tutorial-actions {
  display: flex;
  gap: 0.6rem;
  justify-content: center;
  margin-bottom: 0.8rem;
}
.tutorial-actions .button { min-width: 120px; }

.tutorial-skip {
  background: none;
  border: none;
  color: var(--muted);
  font: 0.72rem/1 'Space Mono', monospace;
  cursor: pointer;
  text-decoration: underline;
  padding: 0.3rem;
}
.tutorial-skip:hover { color: var(--text); }

/* ================================================================
   RACK FEATURE STYLES
   ================================================================ */

/* ── Rack toggle button ─────────────────────────────────────── */
.rack-toggle {
  border: 3px solid var(--line);
  border-radius: 14px;
  padding: 0.5rem 0.7rem;
  background: var(--blue);
  font: 700 0.8rem/1.2 'Space Mono', monospace;
  cursor: pointer;
  box-shadow: 0 10px 18px rgba(0, 0, 0, 0.2);
  transition: transform 120ms ease, filter 120ms ease;
}
.rack-toggle:hover { transform: translateY(-1px); filter: brightness(0.95); }
.rack-toggle:active { transform: translateY(1px) scale(0.99); }

/* ── Full-viewport overlay base ─────────────────────────────── */
.rack-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;  /* above topbar (auto), bottom-actions (20), github (20) */
  background: var(--bg-bottom);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
/* Wave layer — mirrors body::before so the split background appears */
.rack-overlay::before {
  content: '';
  position: absolute;
  inset: 0;
  background: var(--bg);
  --split: 20%;
  --cut: calc(100% - var(--split));
  --amp: 2.2%;
  clip-path: polygon(
    0% 0%,
    100% 0%,
    100% calc(var(--cut) + var(--amp) * 0.35),
    92% calc(var(--cut) + var(--amp) * 0.12),
    84% calc(var(--cut) + var(--amp) * -0.05),
    76% calc(var(--cut) + var(--amp) * -0.18),
    68% calc(var(--cut) + var(--amp) * -0.26),
    60% calc(var(--cut) + var(--amp) * -0.28),
    52% calc(var(--cut) + var(--amp) * -0.22),
    44% calc(var(--cut) + var(--amp) * -0.10),
    36% calc(var(--cut) + var(--amp) * 0.05),
    28% calc(var(--cut) + var(--amp) * 0.18),
    20% calc(var(--cut) + var(--amp) * 0.27),
    12% calc(var(--cut) + var(--amp) * 0.24),
    6%  calc(var(--cut) + var(--amp) * 0.12),
    0%  calc(var(--cut) + var(--amp) * -0.05)
  );
  z-index: 0;
  pointer-events: none;
}
/* All direct children sit above the wave pseudo-element */
.rack-overlay > * { position: relative; z-index: 1; }
.rack-overlay.hidden { display: none; }

/* ── Overlay header ──────────────────────────────────────────── */
.rack-overlay-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0.65rem 1.1rem;
  border-bottom: 3px solid var(--line);
  background: var(--phone);
  flex-shrink: 0;
  min-height: 52px;
}
.rack-overlay-title {
  margin: 0;
  font: 700 1rem/1.2 'Space Mono', monospace;
  color: var(--text);
}
.rack-overlay-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  flex-wrap: wrap;
}

/* ── Overview body ───────────────────────────────────────────── */
.rack-overview-body {
  flex: 1;
  overflow-y: auto;
  padding: clamp(1rem, 1.4vw, 1.6rem) clamp(0.8rem, 1.2vw, 1.4rem);
  display: flex;
  flex-direction: column;
  gap: 0;
}
/* Inner wrapper — same max-width as dashboard */
.rack-overview-inner {
  width: min(80vw, 1920px);
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  flex: 1;
}
/* Floating top bar — title + action buttons, no background */
.rack-ov-topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.75rem;
  padding: 0 0 0.8rem 0;
  flex-shrink: 0;
}
.rack-ov-title {
  margin: 0;
  font: 700 1.15rem/1.2 'Space Mono', monospace;
  color: var(--text);
}
.rack-ov-actions {
  display: flex;
  gap: 0.5rem;
  align-items: center;
}
/* Coloured action buttons matching the dashboard's feel */
.rack-ov-btn-loc  { background: var(--mint); }
.rack-ov-btn-rack { background: var(--yellow); }
.rack-ov-btn-close { background: var(--panel); color: var(--text); }

/* Rounded panel — mirrors dashboard .phone style */
.rack-ov-panel {
  background: color-mix(in srgb, var(--phone) 92%, white);
  border: 3px solid var(--line);
  border-radius: 24px;
  padding: 1rem 1.2rem;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  /* Matches .phone panel style exactly */
}

/* ── Empty state ─────────────────────────────────────────────── */
.rack-empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 0.75rem;
  text-align: center;
  padding: 3rem 1rem;
}
.rack-empty-state h3 {
  font: 700 1.4rem/1.2 'Space Mono', monospace;
  margin: 0;
}
.rack-empty-state p { color: var(--muted); margin: 0; font-size: 0.9rem; }

/* ── Location selector bar ───────────────────────────────────── */
.rack-location-bar {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid color-mix(in srgb, var(--line) 30%, transparent);
}
.rack-location-bar label {
  font: 700 0.75rem/1.2 'Space Mono', monospace;
  color: var(--muted);
}
.rack-location-bar select {
  flex: 1;
  min-width: 120px;
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 0.32rem 0.55rem;
  background: var(--panel);
  color: var(--text);
  font: 700 0.8rem/1.2 'Space Mono', monospace;
  cursor: pointer;
  transition: border-color 120ms ease;
}

/* ── Rack cards grid ─────────────────────────────────────────── */
.rack-cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 0.9rem;
}
.rack-card {
  background: color-mix(in srgb, var(--phone) 92%, white);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 0.9rem 1rem;
  cursor: pointer;
  transition: box-shadow 120ms ease, transform 120ms ease;
  box-shadow: var(--shadow);
}
.rack-card:hover {
  box-shadow: 0 16px 32px rgba(0,0,0,0.16);
  transform: translateY(-2px);
}
.rack-card-icon { font-size: 1.5rem; margin-bottom: 0.35rem; }
.rack-card-name {
  font: 700 0.88rem/1.2 'Space Mono', monospace;
  margin: 0 0 0.2rem;
  word-break: break-word;
}
.rack-card-meta { font-size: 0.72rem; color: var(--muted); margin: 0; }

/* ── Form sub-page ───────────────────────────────────────────── */
.rack-form-page-body {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  justify-content: center;
}
.rack-form-inner {
  width: 100%;
  max-width: 460px;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}
.rack-form-inner label {
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
  font: 700 0.75rem/1.2 'Space Mono', monospace;
  color: var(--muted);
}
.rack-form-inner input,
.rack-form-inner select,
.rack-form-inner textarea {
  border: 2px solid var(--line);
  border-radius: 12px;
  padding: 0.42rem 0.65rem;
  background: var(--panel);
  color: var(--text);
  font: 0.84rem/1.4 Inter, system-ui, sans-serif;
  transition: border-color 120ms ease, box-shadow 120ms ease;
}
.rack-form-inner input:focus,
.rack-form-inner select:focus,
.rack-form-inner textarea:focus {
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--mint) 58%, transparent);
  outline: none;
}
.rack-form-inner textarea { resize: vertical; min-height: 68px; }
.rack-form-actions { display: flex; gap: 0.5rem; margin-top: 0.4rem; }

/* ── Editor layout ───────────────────────────────────────────── */
.rack-editor-body {
  flex: 1;
  display: flex;
  overflow: hidden;
}
.rack-editor-title-wrap {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex: 1;
  min-width: 0;
}
.rack-editor-name {
  font: 700 1rem/1.2 'Space Mono', monospace;
  border-bottom: 2px dashed var(--line);
  padding: 0.1rem 0.3rem;
  outline: none;
  min-width: 60px;
  max-width: 240px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rack-editor-name:focus { border-bottom-color: var(--yellow); }
.rack-location-badge {
  font: 0.7rem/1.2 'Space Mono', monospace;
  color: var(--muted);
  white-space: nowrap;
  background: color-mix(in srgb, var(--blue) 30%, var(--panel));
  border: 1.5px solid var(--line);
  border-radius: 6px;
  padding: 2px 6px;
}

/* ── Component palette ───────────────────────────────────────── */
.rack-palette {
  /* Fluid: 14% of viewport, min 180px, max 260px */
  width: clamp(180px, 14vw, 260px);
  flex-shrink: 0;
  border-right: 3px solid var(--line);
  background: var(--phone);
  display: flex;
  flex-direction: column;
  overflow: hidden;
}
.rack-palette-title {
  font: 700 0.74rem/1.2 'Space Mono', monospace;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin: 0;
  padding: 0.65rem 0.8rem 0.45rem;
  border-bottom: 2px solid var(--line);
  flex-shrink: 0;
}
.rack-palette-items {
  flex: 1;
  overflow-y: auto;
  padding: 0.45rem 0.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.28rem;
}
.rack-palette-item {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 0.32rem 0.55rem;
  background: var(--panel);
  font: 600 0.74rem/1.2 'Space Mono', monospace;
  cursor: grab;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
}
.rack-palette-item:hover {
  background: color-mix(in srgb, var(--yellow) 30%, var(--panel));
}
.rack-palette-item:active { cursor: grabbing; opacity: 0.7; }
.rack-palette-drag { color: var(--muted); flex-shrink: 0; font-size: 0.9rem; }
.rack-palette-label { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.rack-palette-hu {
  font-size: 0.62rem;
  color: var(--muted);
  flex-shrink: 0;
  background: color-mix(in srgb, var(--line) 14%, transparent);
  border-radius: 4px;
  padding: 1px 4px;
  font-weight: 700;
}

/* ── Rack views wrapper ──────────────────────────────────────── */
.rack-views-wrap {
  flex: 1;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: clamp(1rem, 2vw, 2.5rem);
  overflow: auto;
  padding: clamp(0.8rem, 1.2vw, 1.4rem) clamp(0.8rem, 1.4vw, 1.6rem);
}
.rack-view-col {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1 1 0;
  min-width: 240px;
  max-width: 680px;
}
.rack-view-title {
  font: 700 0.75rem/1.2 'Space Mono', monospace;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin: 0;
  text-align: center;
  flex-shrink: 0;
}

/* ── Rack frame ──────────────────────────────────────────────── */
.rack-frame {
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  overflow: hidden;
}

/* ── Rack slots ──────────────────────────────────────────────── */
/* 1U base height — CSS custom property so JS can read/set it */
:root { --rack-u-height: clamp(28px, 1.8vh, 42px); }

.rack-slot {
  border-bottom: 1px solid color-mix(in srgb, var(--line) 40%, transparent);
  /* FIXED height — every 1U row is identical regardless of content */
  height: var(--rack-u-height);
  min-height: var(--rack-u-height);
  max-height: var(--rack-u-height);
  box-sizing: border-box;
  display: grid;
  grid-template-columns: 26px 1fr 24px;
  align-items: center;
  gap: 0;
  padding: 0;
  position: relative;
  transition: background 0.08s;
  overflow: visible;
}
.rack-slot:last-child { border-bottom: none; }

.rack-slot-num {
  font: 400 clamp(0.55rem, 0.72vw, 0.65rem)/1 'Space Mono', monospace;
  color: var(--muted);
  text-align: right;
  padding-right: 5px;
  flex-shrink: 0;
  grid-column: 1;
  align-self: center;
}

/* Content cell — clips overflow so it never pushes row height */
.rack-slot-content {
  grid-column: 2;
  display: flex;
  flex-direction: column;
  justify-content: center;
  padding: 2px 4px;
  min-width: 0;
  overflow: hidden;
  height: 100%;
}

.rack-slot-label {
  font: 600 clamp(0.68rem, 0.9vw, 0.82rem)/1.1 'Space Mono', monospace;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

.rack-slot-device {
  font: 400 clamp(0.58rem, 0.72vw, 0.68rem)/1.1 'Space Mono', monospace;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex-shrink: 0;
}

/* Remove button – sits in its own grid column */
.rack-slot-remove {
  grid-column: 3;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  background: none;
  border: none;
  border-left: 1px solid color-mix(in srgb, var(--line) 30%, transparent);
  color: var(--danger);
  font-size: 0.7rem;
  cursor: pointer;
  padding: 0;
  opacity: 0;
  transition: opacity 0.1s, background 0.1s;
  width: 22px;
}
.rack-slot:hover .rack-slot-remove { opacity: 0.55; }
.rack-slot-remove:hover { opacity: 1 !important; background: color-mix(in srgb, var(--danger) 12%, transparent); }

/* ── Category colour tokens (light mode) ───────────────────── */
:root {
  --cat-compute:  #c8dff8;   /* soft blue       */
  --cat-network:  #b8f0d0;   /* soft green      */
  --cat-power:    #fde5a8;   /* soft amber      */
  --cat-mgmt:     #e5d0f8;   /* soft violet     */
  --cat-filler:   #e0ddd8;   /* neutral grey    */
  --cat-compute-border: #7ab4e8;
  --cat-network-border: #5ecc8e;
  --cat-power-border:   #f0b840;
  --cat-mgmt-border:    #b48ee0;
  --cat-filler-border:  #aaa89e;
}
:root[data-dark] {
  --cat-compute:  #1e3a5c;
  --cat-network:  #1a4030;
  --cat-power:    #4a3408;
  --cat-mgmt:     #2e1e50;
  --cat-filler:   #2a2638;
  --cat-compute-border: #3a6ea8;
  --cat-network-border: #2e8a58;
  --cat-power-border:   #c08020;
  --cat-mgmt-border:    #7040c0;
  --cat-filler-border:  #504860;
}

/* ── Slot state colours ─────────────────────────────────────── */
.rack-slot.empty { background: var(--panel); cursor: default; }
.rack-slot.empty:hover { background: color-mix(in srgb, var(--blue) 12%, var(--panel)); cursor: crosshair; }
.rack-slot.empty .rack-slot-label {
  color: var(--muted);
  font-size: 0.62rem;
  font-weight: 400;
}

/* Category-coloured occupied slots */
.rack-slot.occupied { cursor: pointer; }

.rack-slot.occupied.cat-compute  { background: var(--cat-compute); border-left: 3px solid var(--cat-compute-border); }
.rack-slot.occupied.cat-network  { background: var(--cat-network); border-left: 3px solid var(--cat-network-border); }
.rack-slot.occupied.cat-power    { background: var(--cat-power);   border-left: 3px solid var(--cat-power-border); }
.rack-slot.occupied.cat-mgmt     { background: var(--cat-mgmt);    border-left: 3px solid var(--cat-mgmt-border); }
.rack-slot.occupied.cat-filler   { background: var(--cat-filler);  border-left: 3px solid var(--cat-filler-border); cursor: default; }

.rack-slot.occupied.cat-compute:hover  { filter: brightness(0.94); }
.rack-slot.occupied.cat-network:hover  { filter: brightness(0.94); }
.rack-slot.occupied.cat-power:hover    { filter: brightness(0.94); }
.rack-slot.occupied.cat-mgmt:hover     { filter: brightness(0.94); }
.rack-slot.occupied.cat-filler:hover   { filter: none; }

/* U-count badge on occupied slots — always visible */
.rack-slot.occupied .rack-slot-num {
  font-weight: 700;
  color: var(--text);
  opacity: 0.55;
}

.rack-slot.drag-over   { background: color-mix(in srgb, var(--mint) 50%, var(--panel)) !important; filter: none !important; }
.rack-slot.drag-invalid { background: color-mix(in srgb, var(--danger) 22%, var(--panel)) !important; filter: none !important; }

/* Palette items coloured by category */
.rack-palette-item.cat-compute { border-color: var(--cat-compute-border); }
.rack-palette-item.cat-network { border-color: var(--cat-network-border); }
.rack-palette-item.cat-power   { border-color: var(--cat-power-border); }
.rack-palette-item.cat-mgmt    { border-color: var(--cat-mgmt-border); }
.rack-palette-item.cat-filler  { border-color: var(--cat-filler-border); color: var(--muted); }

.rack-palette-item.cat-compute:hover { background: var(--cat-compute); }
.rack-palette-item.cat-network:hover { background: var(--cat-network); }
.rack-palette-item.cat-power:hover   { background: var(--cat-power); }
.rack-palette-item.cat-mgmt:hover    { background: var(--cat-mgmt); }
.rack-palette-item.cat-filler:hover  { background: var(--cat-filler); }

/* Palette section headers */
.rack-palette-section {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font: 700 0.62rem/1.2 'Space Mono', monospace;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  padding: 0.45rem 0.3rem 0.1rem;
  margin-top: 0.2rem;
}
.rack-palette-section:first-child { margin-top: 0; padding-top: 0.2rem; }

/* Multi-device tags inside a slot */
/* Multi-device lines — same plain style as single device */
.rack-multi-lines {
  display: flex;
  flex-direction: column;
  gap: 0;
  overflow: hidden;
  flex-shrink: 1;
  min-height: 0;
}
/* Small numbered prefix "1." "2." etc */
.rack-slot-device-idx {
  font-weight: 700;
  color: color-mix(in srgb, var(--muted) 80%, var(--text));
  margin-right: 2px;
}

/* ── Link panel (fixed overlay on body) ──────────────────────── */
.rack-link-panel {
  /* position / left / width / top set inline by JS */
  background: var(--phone);
  border: 3px solid var(--line);
  border-top: none;
  border-radius: 0 0 12px 12px;
  padding: 0.65rem 0.85rem 0.75rem;
  font: 600 0.72rem/1.3 'Space Mono', monospace;
  box-shadow: 0 16px 40px rgba(0,0,0,0.28);
  box-sizing: border-box;
  max-height: 60vh;
  overflow-y: auto;
}

.rack-link-multi-wrap {
  display: flex;
  flex-direction: column;
  gap: 0.32rem;
}
.rack-link-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
.rack-link-row-label {
  font: 700 0.68rem/1.2 'Space Mono', monospace;
  color: var(--muted);
  white-space: nowrap;
  min-width: 54px;
  flex-shrink: 0;
}
.rack-link-row select {
  flex: 1;
  min-width: 0;
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 0.26rem 0.42rem;
  background: var(--panel);
  color: var(--text);
  font: 0.72rem/1.3 'Space Mono', monospace;
}
.rack-link-actions {
  display: flex;
  gap: 0.4rem;
  margin-top: 0.5rem;
  padding-top: 0.45rem;
  border-top: 1px solid color-mix(in srgb, var(--line) 40%, transparent);
}
.rack-link-panel .button {
  font-size: 0.7rem;
  padding: 0.22rem 0.55rem;
}

/* Dark theme tweaks for rack toggle */
@media (prefers-color-scheme: dark) {
  .rack-toggle { background: var(--blue); }
}

/* Mobile: hide rack toggle */
@media (max-width: 1100px) {
  .rack-toggle { display: none; }
}

.rack-editor-right-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* ── Right-click context menu ────────────────────────────────── */
.rack-ctx-menu {
  position: fixed;
  z-index: 300;
  background: var(--phone);
  border: 2px solid var(--line);
  border-radius: 16px;
  padding: 0.3rem 0;
  min-width: 160px;
  box-shadow: 0 14px 32px rgba(0,0,0,0.26);
  font: 600 0.78rem/1.3 'Space Mono', monospace;
}
.rack-ctx-item {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.42rem 0.85rem;
  cursor: pointer;
  color: var(--text);
  white-space: nowrap;
  transition: background 0.08s;
}
.rack-ctx-item:hover { background: color-mix(in srgb, var(--yellow) 25%, var(--panel)); }
.rack-ctx-item.danger { color: var(--danger); }
.rack-ctx-item.danger:hover { background: color-mix(in srgb, var(--danger) 14%, var(--panel)); }
.rack-ctx-sep {
  height: 1px;
  background: color-mix(in srgb, var(--line) 35%, transparent);
  margin: 0.25rem 0;
}

/* ── Rack form dialog (popup, not full page) ─────────────────── */
.rack-form-dialog {
  width: min(500px, 92vw);
  max-height: 92vh;
  overflow-y: auto;
  z-index: 200;
  padding: 0.9rem;   /* matches .tree-dialog / config */
  border-radius: 16px;
}
.rack-form-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);  /* matches .tree-dialog::backdrop */
}
.rack-form-dialog-title {
  font: 700 1rem/1.2 'Space Mono', monospace;
  margin: 0 0 0.6rem 0;  /* tight, like config heading */
  color: var(--text);
}
.rack-form-dialog-body {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0;
}
.rack-form-btns {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
  margin-top: 0.55rem;
}
.rack-form-btn-primary,
.rack-form-btn-close {
  width: 100%;
  justify-content: center;
  text-align: center;
}
.rack-form-btn-danger {
  width: 100%;
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
  margin-top: 0.45rem;
  margin-bottom: 0;
  text-align: center;
}
.rack-form-btn-danger:hover {
  background: color-mix(in srgb, var(--danger) 12%, var(--panel));
  animation: delete-shake 0.4s ease;
}
.rack-form-dialog .rack-form-inner {
  gap: 0.45rem;  /* same density as config fields */
}

.config-btn-row { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }
.config-btn-row .button { width: 100%; }

.theme-tabs {
  display: flex;
  gap: 0.4rem;
  border-bottom: 2px solid var(--line);
  margin-bottom: 0.8rem;
}
.theme-picker-dialog { overflow-y: auto; }
.theme-tab {
  border: none;
  background: none;
  color: var(--muted);
  font: 700 0.85rem/1 'Space Mono', monospace;
  padding: 0.5rem 0.4rem;
  cursor: pointer;
  border-bottom: 3px solid transparent;
  margin-bottom: -2px;
}
.theme-tab.active { color: var(--text); border-bottom-color: var(--yellow); }
.theme-section-title {
  font: 700 0.85rem/1.2 'Space Mono', monospace;
  color: var(--muted);
  margin: 0.8rem 0 0.4rem;
}
.theme-empty-note { font: 600 0.78rem/1.3 'Space Mono', monospace; color: var(--muted); margin: 0.2rem 0; }

.theme-picker-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.85rem;
  margin-top: 0.5rem;
}
.theme-swatch {
  position: relative;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.65rem;
  min-height: 92px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
  font: inherit;
  transition: transform 120ms ease, box-shadow 120ms ease;
}
.theme-swatch:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
.theme-swatch.active { outline: 3px solid var(--yellow); outline-offset: 1px; }
.theme-swatch-preview {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 58px;
  border: 2px solid var(--line);
  border-radius: 8px;
}
.theme-swatch-preview .tsc {
  width: 28px;
  height: 28px;
  border-radius: 999px;
  border: 2px solid var(--line);
  margin-left: -8px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.25);
}
.theme-swatch-preview .tsc:first-child { margin-left: 0; }
.theme-swatch-name {
  font: 700 0.78rem/1 'Space Mono', monospace;
  text-align: center;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.theme-swatch-del {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 20px;
  height: 20px;
  border-radius: 999px;
  background: var(--danger);
  color: #fff;
  border: 2px solid var(--panel);
  font: 700 0.7rem/1 'Space Mono', monospace;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 2;
}
.theme-swatch-del:hover { filter: brightness(1.1); }

.theme-builder-body { display: flex; flex-direction: column; gap: 0.8rem; margin-top: 0.2rem; }
.tb-base-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  font: 700 0.8rem 'Space Mono', monospace;
  color: var(--text);
}
.tb-base-row select, .tb-base-row input[type='text'] { width: auto; min-width: 150px; }
.tb-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 0.5rem;
}
.tb-color-row {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font: 700 0.72rem/1.2 'Space Mono', monospace;
  color: var(--muted);
}
.tb-color-row input[type='color'] {
  width: 40px;
  height: 30px;
  flex-shrink: 0;
  border: 2px solid var(--line);
  border-radius: 6px;
  padding: 0;
  background: none;
  cursor: pointer;
}
.tb-actions { display: flex; justify-content: flex-end; }
.tb-actions .button { min-width: 140px; }


.theme-edit-btn{
  margin-top:4px;
  width:100%;
  border:1px solid var(--line);
  background:var(--panel-alt);
  border-radius:6px;
  font:700 .7rem 'Space Mono', monospace;
}

@media (max-width:1100px){
  .mobile-fullscreen-dialog{
    inset:0;
    width:100vw !important;
    max-width:none !important;
    height:100dvh;
    max-height:none !important;
    border-radius:0;
    margin:0;
    padding:1rem;
  }
  .mobile-fullscreen-dialog::backdrop{
    background:rgba(0,0,0,.45);
  }
}


/* Keep exactly five large theme cards per row on desktop. */
.theme-picker-dialog #theme-tab-themes {
  padding-right: 0.2rem;
}

@media (max-width: 900px) {
  .theme-picker-grid,
  #config-dialog .legend {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .theme-picker-grid,
  #config-dialog .legend {
    grid-template-columns: 1fr;
  }
}


/* Custom theme editor: fill the dialog with a balanced card layout. */
.theme-custom-wrap {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 260px;
  grid-template-rows: auto 1fr;
  gap: 1rem;
  align-items: stretch;
  min-height: 0;
  height: 100%;
}

.theme-custom-wrap .theme-name-field {
  grid-column: 2;
  grid-row: 1;
  align-self: start;
}

.theme-custom-wrap .theme-color-grid {
  grid-column: 1;
  grid-row: 1 / span 2;
}

.theme-custom-wrap .theme-actions {
  grid-column: 2;
  grid-row: 2;
  align-self: start;
  display: grid;
  gap: 0.8rem;
  padding: 1rem;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: var(--card);
}

.theme-custom-wrap .theme-actions::before {
  content: "Preview";
  font-weight: 900;
  letter-spacing: 0.03em;
}

.theme-custom-wrap .theme-actions::after {
  content: "";
  display: block;
  height: 120px;
  border: 2px solid var(--line);
  border-radius: 12px;
  background:
    linear-gradient(135deg, var(--accent) 0 28%, transparent 28%),
    linear-gradient(180deg, var(--panel) 0 52%, var(--info) 52% 100%);
  box-shadow: inset 0 0 0 8px var(--bg);
}

.theme-color-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 0.85rem;
  align-content: start;
}

.theme-color-field {
  display: grid;
  grid-template-columns: 62px minmax(0, 1fr);
  align-items: center;
  gap: 0.65rem;
  min-height: 72px;
  padding: 0.65rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

.theme-color-field input[type="color"] {
  width: 62px;
  height: 48px;
  padding: 3px;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  cursor: pointer;
}

.theme-color-field span,
.theme-color-field label,
.theme-color-field .theme-color-label {
  line-height: 1.2;
}

.theme-custom-wrap .theme-name-field input,
.theme-custom-wrap .theme-actions .primary-btn {
  width: 100%;
}

@media (min-width: 1200px) {
  .theme-color-grid {
    grid-template-columns: repeat(5, minmax(160px, 1fr));
  }
}

@media (max-width: 980px) {
  .theme-custom-wrap {
    grid-template-columns: 1fr;
    grid-template-rows: auto auto auto;
  }

  .theme-custom-wrap .theme-name-field,
  .theme-custom-wrap .theme-color-grid,
  .theme-custom-wrap .theme-actions {
    grid-column: 1;
    grid-row: auto;
  }

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

@media (max-width: 560px) {
  .theme-color-grid {
    grid-template-columns: 1fr;
  }
}


/* Config dialog: fill empty space with inline tutorial content. */
#config-dialog .note,
#config-dialog .stack {
  flex: 0 0 auto;
}

#config-dialog .stack {
  gap: 0.7rem;
}

#config-dialog .config-content {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  gap: 0.85rem;
  margin-top: 0.85rem;
}

#config-dialog .legend {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-content: start;
  gap: 0.65rem;
  margin: 0;
}

#config-dialog .legend p {
  min-height: 52px;
  margin: 0;
  padding: 0.55rem 0.65rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--card);
}

.config-tutorial {
  min-height: 0;
  border: 3px solid var(--line);
  border-radius: 14px;
  background: var(--panel);
  padding: 0.85rem;
  overflow: auto;
}

.config-tutorial h4 {
  margin: 0 0 0.75rem;
  font: 900 1rem/1.2 'Space Mono', monospace;
  color: var(--text);
}

.config-tutorial-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.75rem;
}

.config-tutorial article {
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding: 0.8rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}

.config-tutorial strong {
  font: 900 0.82rem/1.25 'Space Mono', monospace;
  color: var(--text);
}

.config-tutorial span {
  font: 700 0.74rem/1.45 'Space Mono', monospace;
  color: var(--muted);
}

/* Theme dialog: keep the active tab scrollable and the Close button pinned to the bottom. */
.theme-picker-dialog[open] {
  overflow: hidden;
}

.theme-picker-dialog .theme-tab-panel {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 0.2rem;
}

.theme-picker-dialog .dialog-footer {
  margin-top: auto;
}

.theme-picker-dialog #theme-tab-themes {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 0.2rem;
}

/* Keep exactly five large theme cards per row on desktop. */
.theme-picker-grid {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

@media (max-width: 1100px) {
  .config-tutorial-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 900px) {
  .theme-picker-grid,
  #config-dialog .legend {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 520px) {
  .theme-picker-grid,
  #config-dialog .legend,
  .config-tutorial-grid {
    grid-template-columns: 1fr;
  }
}


/* Graph View: show names permanently below bubbles and fit the initial view cleanly. */
.graph-node {
  z-index: 3;
}

.graph-node-label {
  position: absolute;
  transform: translate(-50%, 30px);
  z-index: 2;
  max-width: 150px;
  color: var(--text);
  font: 800 0.72rem/1.15 'Space Mono', monospace;
  text-align: center;
  white-space: normal;
  overflow-wrap: anywhere;
  pointer-events: none;
  text-shadow:
    0 1px 0 var(--panel),
    1px 0 0 var(--panel),
    -1px 0 0 var(--panel),
    0 -1px 0 var(--panel);
}

.graph-node:hover,
.graph-node:focus-visible {
  filter: brightness(0.97);
  transform: translate(-50%, -50%) scale(1.06);
}

.graph-tooltip {
  background: var(--yellow);
  color: #222;
  border-color: var(--line);
}


/* Graph View: center around the dense component group and keep labels readable. */
.graph-node-label {
  max-width: 160px;
  line-height: 1.15;
}


/* Mobile click safety: hidden views/overlays must not block buttons. */
.mobile-view:not(.active),
.rack-overview.hidden,
.rack-editor.hidden,
#welcome-overlay:not(.active) {
  pointer-events: none !important;
}

.mobile-view.active {
  pointer-events: auto;
}

.bottom-nav,
.bottom-actions {
  pointer-events: auto;
  z-index: 120;
}

.bottom-nav button,
.bottom-actions button,
.mobile-view button,
.mobile-view a,
.mobile-view input,
.mobile-view select,
.mobile-view textarea {
  pointer-events: auto;
  position: relative;
  z-index: 2;
}

dialog:not([open]) {
  pointer-events: none !important;
}

dialog[open] {
  pointer-events: auto;
}

/* Graph View: labels are visual only and the initial view centers on the dense node cluster. */
.graph-node-label {
  pointer-events: none !important;
}


/* Import Config button: keep the native file input fully hidden.
   This prevents the browser's "no file selected" text from leaking into the button
   and keeps the label looking/clicking like a normal Labby button. */
.file-label {
  position: relative;
  overflow: hidden;
  display: flex !important;
  align-items: center;
  justify-content: center;
  width: 100%;
  min-height: 36px;
  white-space: nowrap;
  text-align: center;
  line-height: 1.2;
}

.file-label input[type="file"] {
  position: absolute !important;
  inset: auto !important;
  width: 1px !important;
  height: 1px !important;
  opacity: 0 !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  pointer-events: none !important;
}

.file-label:focus-within {
  outline: 3px solid color-mix(in srgb, var(--line) 68%, white);
  outline-offset: 2px;
}

/* ================================================================
   Mobile UX overhaul
   ================================================================ */
.mobile-progress {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 500;
  height: 3px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 180ms ease;
}
.mobile-progress span {
  display: block;
  width: 38%;
  height: 100%;
  background: var(--accent);
  transform: translateX(-110%);
}
.mobile-progress.active { opacity: 1; }
.mobile-progress.active span { animation: labby-progress 900ms ease-in-out infinite; }
@keyframes labby-progress { 0% { transform: translateX(-110%); } 55% { transform: translateX(120%); } 100% { transform: translateX(280%); } }

.mobile-sheet { display: none; }
.rack-mobile-toolbar { display: none; }
.sheet-handle {
  width: 54px;
  min-height: 22px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  margin: 0 auto 0.45rem;
  display: block;
  position: relative;
}
.sheet-handle::before {
  content: '';
  position: absolute;
  left: 8px; right: 8px; top: 9px;
  height: 5px;
  border-radius: 999px;
  background: color-mix(in srgb, var(--line) 60%, transparent);
}

.rack-selected-component-pill { display: none; }
.rack-palette-backdrop { display: none; }
.rack-mobile-palette-fab { display: none; }

@media (max-width: 1100px) {
  html { scroll-behavior: smooth; }
  body {
    min-height: 100dvh;
    padding-bottom: calc(76px + env(safe-area-inset-bottom));
    overscroll-behavior: contain;
  }
  input, select, textarea, button { font-size: 16px; }
  button, .button, .icon-btn, .bottom-nav-item, .card-action-copy, .card-action-link, .rack-slot, .rack-palette-item {
    min-width: 44px;
    min-height: 44px;
  }
  button, .button, .card, .rack-card, .rack-slot, .more-item { transition-duration: 260ms; }
  button:active, .button:active, .card:active, .rack-card:active, .rack-slot:active, .more-item:active { transform: scale(0.98); }
  .topbar { display: none !important; }
  .panel-center { border-radius: 0; border-inline: 0; min-height: calc(100dvh - 76px - env(safe-area-inset-bottom)); }
  .phone-grid { padding-inline: 0; padding-bottom: calc(84px + env(safe-area-inset-bottom)); }
  .filters { position: sticky; top: 0; z-index: 4; background: var(--phone); padding: 0.35rem 0; }
  .boards {
    display: flex;
    gap: 0.85rem;
    overflow-x: auto;
    overflow-y: visible;
    scroll-snap-type: x proximity;
    overscroll-behavior: contain;
    padding-bottom: 0.75rem;
  }
  .column {
    flex: 0 0 min(86vw, 390px);
    max-height: none;
    overflow-y: visible;
    scroll-snap-align: start;
  }
  .column h3 { position: sticky; top: 58px; z-index: 2; background: inherit; padding-block: 0.4rem; }
  .card { position: relative; overflow: hidden; touch-action: pan-y; }
  .card .card-desc,
  .card .card-live-status,
  .card .card-notes,
  .card .card-ip,
  .card .card-app,
  .card .card-actions,
  .card .card-specs,
  .card .card-network,
  .card .card-hosting,
  .card .card-links { display: none; }
  .card.mobile-expanded .card-desc,
  .card.mobile-expanded .card-live-status,
  .card.mobile-expanded .card-notes,
  .card.mobile-expanded .card-ip,
  .card.mobile-expanded .card-app,
  .card.mobile-expanded .card-actions,
  .card.mobile-expanded .card-specs,
  .card.mobile-expanded .card-network,
  .card.mobile-expanded .card-hosting,
  .card.mobile-expanded .card-links { display: revert; }
  .card::before,
  .card::after {
    position: absolute;
    top: 0; bottom: 0;
    width: 82px;
    display: grid;
    place-items: center;
    font: 800 0.72rem/1 'Space Mono', monospace;
    color: var(--text);
    opacity: 0;
    transition: opacity 220ms ease;
    pointer-events: none;
  }
  .card::before { content: 'Edit'; left: 0; background: color-mix(in srgb, var(--mint) 72%, transparent); }
  .card::after { content: 'Delete'; right: 0; background: color-mix(in srgb, var(--danger) 22%, transparent); color: var(--danger); }
  .card.swipe-edit::before, .card.swipe-delete::after { opacity: 1; }
  .card-controls { display: none; }

  .mobile-view { z-index: 80; padding-top: env(safe-area-inset-top); }
  .mobile-view-body, .tree-content, .rack-overview-body, .rack-editor-body, .rack-frame, .rack-palette-items { overscroll-behavior: contain; }
  .mobile-view-head, .mobile-view-footer { padding-inline: max(1rem, env(safe-area-inset-left)); }
  #resource-form { gap: 0.85rem; }
  #resource-form label, #resource-form fieldset { border-radius: 18px; }
  #resource-form input, #resource-form select, #resource-form textarea { min-height: 44px; font-size: 16px; }
  #resource-form .network-fields {
    padding: 0.75rem;
    background: color-mix(in srgb, var(--panel) 70%, transparent);
  }
  #resource-form .mobile-collapsed > :not(legend):not(.mobile-section-toggle) { display: none !important; }
  .mobile-section-toggle {
    width: 100%;
    margin: 0.35rem 0 0;
    background: var(--panel);
  }

  .bottom-nav {
    z-index: 160;
    padding: 0.45rem max(0.35rem, env(safe-area-inset-left)) max(0.5rem, env(safe-area-inset-bottom)) max(0.35rem, env(safe-area-inset-right));
    gap: 0.15rem;
  }
  .bottom-nav-item { border-radius: 16px; padding: 0.36rem 0.1rem; }
  .bottom-nav-label { font-size: 0.64rem; }
  .mobile-sheet {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 180;
    pointer-events: none;
    visibility: hidden;
  }
  .mobile-sheet.open { pointer-events: auto; visibility: visible; }
  .mobile-sheet-backdrop {
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.18);
    opacity: 0;
    transition: opacity 260ms ease;
  }
  .mobile-sheet.open .mobile-sheet-backdrop { opacity: 1; }
  .mobile-sheet-panel {
    position: absolute;
    left: max(8px, env(safe-area-inset-left));
    right: max(8px, env(safe-area-inset-right));
    bottom: max(8px, env(safe-area-inset-bottom));
    max-height: 85dvh;
    overflow: auto;
    border: 3px solid var(--line);
    border-radius: 26px;
    background: var(--phone);
    box-shadow: 0 24px 60px rgba(0,0,0,0.26);
    padding: 0.55rem 0.75rem 0.85rem;
    transform: translateY(calc(100% + 24px));
    transition: transform 280ms ease;
  }
  .mobile-sheet.open .mobile-sheet-panel { transform: translateY(0); }
  .more-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0.55rem; }
  .more-item {
    border: 2px solid var(--line);
    border-radius: 18px;
    background: var(--panel);
    color: var(--text);
    display: grid;
    place-items: center;
    gap: 0.25rem;
    padding: 0.8rem 0.4rem;
  }
  .more-item span { font-size: 1.35rem; }
  .more-item strong { font: 800 0.72rem/1 'Space Mono', monospace; }

  .tree-dialog,
  .rack-form-dialog {
    width: auto;
    height: auto;
    max-width: none;
    max-height: 85dvh;
    margin: 0 max(8px, env(safe-area-inset-right)) max(8px, env(safe-area-inset-bottom)) max(8px, env(safe-area-inset-left));
    border-radius: 26px 26px 22px 22px;
    padding: 0.8rem;
    transform: translateY(0);
  }
  dialog.tree-dialog::backdrop,
  dialog.rack-form-dialog::backdrop { background: rgba(0,0,0,0.22); }
  .tree-dialog[open], .rack-form-dialog[open] { animation: sheet-in 260ms ease; }
  @keyframes sheet-in { from { transform: translateY(24px); opacity: 0.75; } to { transform: translateY(0); opacity: 1; } }

  .graph-wrap {
    min-height: 66dvh;
    overflow: hidden !important;
    touch-action: none;
    background: color-mix(in srgb, var(--panel) 88%, transparent);
  }
  .graph-wrap.node-selected::after {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0,0,0,0.08);
    pointer-events: none;
    z-index: 1;
  }
  .graph-canvas { z-index: 2; }
  .graph-node { width: 54px !important; height: 54px !important; font-size: 1.35rem !important; }
  .graph-node-label { transform: translate(-50%, 38px); max-width: 132px; }
  .graph-info-panel {
    position: absolute;
    left: 10px;
    right: 10px;
    bottom: 10px;
    z-index: 4;
    width: auto !important;
    max-height: 36dvh;
    overflow: auto;
    border-radius: 22px;
    transform: translateY(calc(100% + 18px));
    transition: transform 280ms ease;
    box-shadow: 0 18px 40px rgba(0,0,0,0.2);
  }
  .graph-wrap.node-selected .graph-info-panel { transform: translateY(0); }

  .rack-toggle { display: none !important; }
  .rack-overlay {
    z-index: 90;
    background: var(--phone);
    padding: env(safe-area-inset-top) env(safe-area-inset-right) calc(78px + env(safe-area-inset-bottom)) env(safe-area-inset-left);
  }
  .rack-overlay::before { display: none; }
  .rack-overview-inner { width: 100%; }
  .rack-ov-topbar { padding: 0.75rem 0.75rem 0.35rem; align-items: flex-start; }
  .rack-ov-title { font-size: 1rem; }
  .rack-ov-actions { gap: 0.35rem; flex-wrap: wrap; justify-content: flex-end; }
  .rack-ov-actions .button { padding-inline: 0.6rem; }
  .rack-ov-btn-close { display: none; }
  .rack-ov-panel { border-width: 0; box-shadow: none; padding: 0.75rem; background: transparent; }
  .rack-location-bar { display: grid; grid-template-columns: 1fr auto; }
  .rack-location-bar label { grid-column: 1 / -1; }
  .rack-cards-grid { grid-template-columns: 1fr; }
  .rack-card { min-height: 76px; display: grid; grid-template-columns: auto 1fr; column-gap: 0.75rem; align-items: center; }
  .rack-card-icon { grid-row: span 2; }
  .rack-overlay-head { padding: 0.65rem 0.8rem; min-height: 58px; }
  .rack-editor-right-actions .button { padding-inline: 0.55rem; }
  .rack-editor-body { display: block; overflow: hidden; padding: 0; }
  .rack-mobile-toolbar {
    display: flex;
    align-items: center;
    justify-content: flex-start;
    gap: 0.6rem;
    padding: 0.55rem 0.75rem;
    border-bottom: 2px solid var(--line);
    background: var(--phone);
  }
  #rack-mobile-palette-toggle { display: none; }
  .rack-side-tabs { display: flex; gap: 0.35rem; }
  .rack-side-tabs .active { background: var(--yellow); }
  .rack-selected-component-pill {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.6rem;
    margin: 0.55rem 0.75rem 0;
    padding: 0.55rem 0.75rem;
    border: 2px solid var(--line);
    border-radius: 16px;
    background: color-mix(in srgb, var(--yellow) 24%, var(--panel));
  }
  .rack-selected-component-pill.hidden { display: none; }
  .rack-selected-component-text {
    min-width: 0;
    flex: 1;
    font-size: 0.9rem;
    line-height: 1.35;
  }
  .rack-selected-component-clear {
    flex-shrink: 0;
    min-width: 44px;
    min-height: 44px;
  }
  .rack-palette-backdrop {
    display: block;
    position: fixed;
    inset: 0;
    z-index: 219;
    background: rgba(0, 0, 0, 0.24);
    opacity: 0;
    visibility: hidden;
    pointer-events: none;
    transition: opacity 260ms ease, visibility 260ms ease;
  }
  .rack-palette-backdrop.open {
    opacity: 1;
    visibility: visible;
    pointer-events: auto;
  }
  .rack-palette {
    position: fixed;
    left: 50%;
    right: auto;
    top: 50%;
    bottom: auto;
    width: min(420px, calc(100vw - 24px));
    z-index: 220;
    max-height: min(74dvh, 640px);
    overflow: auto;
    border: 3px solid var(--line);
    border-radius: 26px;
    background: var(--phone);
    box-shadow: 0 24px 60px rgba(0,0,0,0.28);
    padding: 0.55rem 0.8rem 0.9rem;
    transform: translate(-50%, calc(100% + 40px));
    opacity: 0;
    pointer-events: none;
    transition: transform 280ms ease, opacity 220ms ease;
  }
  .rack-palette.open {
    transform: translate(-50%, -50%);
    opacity: 1;
    pointer-events: auto;
  }
  .rack-palette-title { margin-top: 0.2rem; }
  .rack-palette-items { max-height: none; display: grid; gap: 0.5rem; }
  .rack-palette-item.selected { outline: 3px solid var(--accent); background: var(--yellow); }
  .rack-mobile-palette-fab {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: fixed;
    right: calc(max(10px, env(safe-area-inset-right)) + 4px);
    top: 50%;
    z-index: 218;
    width: 58px;
    height: 58px;
    border: 3px solid var(--line);
    border-radius: 999px;
    background: var(--yellow);
    color: var(--text);
    box-shadow: 0 14px 30px rgba(0, 0, 0, 0.18);
    transform: translateY(-50%);
    font-size: 1.45rem;
    line-height: 1;
  }
  .rack-views-wrap { display: block; overflow-y: auto; max-height: calc(100dvh - 178px); padding: 0.75rem; }
  .rack-view-col { display: none; }
  .rack-view-col.mobile-active { display: block; }
  .rack-view-title { position: sticky; top: 0; z-index: 2; background: var(--phone); padding: 0.35rem 0; }
  .rack-frame { max-width: min(100%, 520px); margin-inline: auto; }
  .rack-slot { min-height: 44px !important; }
  .rack-slot.occupied { min-height: 48px !important; }
  .rack-slot-remove { min-width: 44px; min-height: 44px; }
  .rack-link-panel {
    left: max(8px, env(safe-area-inset-left)) !important;
    right: max(8px, env(safe-area-inset-right)) !important;
    width: auto !important;
    top: auto !important;
    bottom: max(8px, env(safe-area-inset-bottom)) !important;
    max-height: 70dvh;
    overflow: auto;
    border-radius: 24px;
    z-index: 230 !important;
  }
}

/* ================================================================
   Mobile fixes v3: rack controls, full theme view, graph readability,
   and no horizontal start-page scrolling.
   ================================================================ */
@media (max-width: 1100px) {
  html,
  body {
    width: 100%;
    max-width: 100%;
    overflow-x: hidden !important;
  }

  .app,
  .panel-center,
  .phone-grid,
  .boards,
  .column,
  .mobile-view,
  .mobile-view-body {
    max-width: 100vw;
    overflow-x: hidden !important;
  }

  .boards {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 1rem;
    overflow-x: hidden !important;
    overflow-y: visible !important;
    scroll-snap-type: none !important;
    padding: 0 0 1rem;
  }

  .column {
    width: 100% !important;
    max-width: 100% !important;
    min-width: 0 !important;
    flex: none !important;
    overflow: visible !important;
  }

  .column h3 {
    position: static !important;
    transform: none !important;
    line-height: 1.1;
    word-break: break-word;
  }

  .card,
  .card * {
    max-width: 100%;
  }

  .card-title,
  .card-desc,
  .card-meta,
  .card span,
  .card p {
    overflow-wrap: anywhere;
    word-break: break-word;
  }

  /* Theme behaves like the other mobile tabs: full screen, no sheet handle/topbar. */
  dialog.theme-picker-dialog[open] {
    position: fixed !important;
    inset: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    width: 100vw !important;
    height: 100dvh !important;
    max-width: none !important;
    max-height: none !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    padding: env(safe-area-inset-top) 0 calc(76px + env(safe-area-inset-bottom)) 0 !important;
    overflow: hidden !important;
    background: var(--phone) !important;
  }

  dialog.theme-picker-dialog::backdrop {
    background: transparent !important;
  }

  .theme-picker-dialog > .sheet-handle {
    display: none !important;
  }

  .theme-picker-dialog .tree-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-shrink: 0;
    margin: 0;
    padding: 1rem max(1rem, env(safe-area-inset-right)) 0.6rem max(1rem, env(safe-area-inset-left));
    border-bottom: 2px solid var(--line);
    background: var(--phone);
  }

  .theme-picker-dialog .tree-head h3 {
    margin: 0;
    font-size: 1rem;
  }

  .theme-picker-dialog .theme-tabs {
    flex-shrink: 0;
    margin: 0;
    padding: 0.85rem max(1rem, env(safe-area-inset-right)) 0 max(1rem, env(safe-area-inset-left));
    border-bottom: 2px solid var(--line);
    background: var(--phone);
  }

  .theme-picker-dialog .theme-tab-panel {
    flex: 1 1 auto;
    min-height: 0;
    overflow-y: auto;
    padding: 1rem max(1rem, env(safe-area-inset-right)) 1rem max(1rem, env(safe-area-inset-left));
  }

  .theme-picker-dialog #theme-tab-themes {
    padding-right: max(1rem, env(safe-area-inset-right));
  }

  .theme-picker-dialog .theme-picker-grid {
    grid-template-columns: 1fr !important;
    gap: 0.75rem;
  }

  .theme-picker-dialog .theme-swatch {
    min-height: 92px;
    border-radius: 18px;
    padding: 0.75rem;
  }

  .theme-picker-dialog .theme-swatch-preview {
    height: 56px;
    border-radius: 12px;
  }

  .theme-picker-dialog .dialog-footer {
    flex-shrink: 0;
    margin: 0;
    padding: 0.7rem max(1rem, env(safe-area-inset-right)) max(0.7rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    border-top: 2px solid var(--line);
    background: var(--phone);
  }

  .theme-picker-dialog .dialog-footer .button {
    width: 100%;
  }

  /* Rack editor: add the missing top border and keep remove buttons reachable. */
  .rack-overlay {
    border-top: 3px solid var(--line);
  }

  .rack-overlay-head {
    border-top: 0;
    border-bottom: 3px solid var(--line);
  }

  .rack-frame {
    width: 100% !important;
    max-width: 100% !important;
    overflow: hidden;
    border-top: 3px solid var(--line);
  }

  .rack-slot {
    grid-template-columns: 2.4rem minmax(0, 1fr) 3.1rem !important;
    column-gap: 0.35rem;
    padding-right: 0.25rem !important;
    overflow: hidden;
  }

  .rack-slot-content {
    min-width: 0;
    overflow: hidden;
  }

  .rack-slot-label,
  .rack-slot-device,
  .rack-multi-lines {
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  .rack-slot-remove {
    position: static !important;
    justify-self: end;
    align-self: center;
    width: 44px !important;
    height: 44px !important;
    min-width: 44px !important;
    border-radius: 14px;
    z-index: 3;
  }

  /* Component assignment as a calm bottom sheet. */
  .rack-link-panel {
    left: max(10px, env(safe-area-inset-left)) !important;
    right: max(10px, env(safe-area-inset-right)) !important;
    bottom: max(12px, env(safe-area-inset-bottom)) !important;
    top: auto !important;
    width: auto !important;
    max-height: 72dvh !important;
    overflow: auto !important;
    border: 3px solid var(--line);
    border-radius: 26px;
    background: var(--phone);
    box-shadow: 0 24px 60px rgba(0,0,0,0.26);
    padding: 1rem;
  }

  .rack-link-row {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.35rem;
    align-items: stretch;
    margin-bottom: 0.75rem;
  }

  .rack-link-row-label {
    font-size: 0.74rem;
    opacity: 0.75;
  }

  .rack-link-row select,
  .rack-link-panel select {
    width: 100% !important;
    min-height: 48px;
  }

  .rack-link-actions {
    display: grid !important;
    grid-template-columns: 1fr 1fr;
    gap: 0.6rem;
    border-top: 1px solid color-mix(in srgb, var(--line) 42%, transparent);
    padding-top: 0.8rem;
    margin-top: 0.2rem;
  }

  /* Graph readability: keep nodes tappable and text visible after initial fit. */
  .mobile-view #mobile-tree-content,
  #mobile-tree-content .tree-shell {
    min-height: calc(100dvh - 190px);
  }

  #mobile-tree-content .graph-wrap {
    width: 100%;
    min-height: calc(100dvh - 210px) !important;
    border: 3px solid var(--line);
    border-radius: 22px;
  }

  #mobile-tree-content .graph-canvas {
    transform-origin: 0 0;
    will-change: transform;
  }

  #mobile-tree-content .graph-node {
    width: 62px !important;
    height: 62px !important;
    font-size: 1.45rem !important;
  }

  #mobile-tree-content .graph-node-label {
    transform: translate(-50%, 44px) !important;
    max-width: 150px;
    font-size: 0.8rem;
    line-height: 1.15;
  }
}
@media (max-width: 1100px) {
  .rack-slot-remove { opacity: 1 !important; }
  .rack-editor.hidden .rack-mobile-palette-fab { display: none !important; }
  .rack-editor.hidden .rack-palette-backdrop { display: none !important; }
}

/* Mobile v5: theme page consistency and no mobile app topbar. */
@media (max-width: 1100px) {
  .topbar { display: none !important; }
  dialog.theme-picker-dialog[open] { animation: none !important; }
  dialog.theme-picker-dialog[open] .sheet-handle { display: none !important; }
  dialog.theme-picker-dialog[open] .theme-picker-grid { grid-template-columns: 1fr !important; }
}


/* v6: Config no longer embeds the tutorial on desktop. */
#config-dialog .config-tutorial { display: none !important; }
#config-dialog .config-content {
  grid-template-rows: auto !important;
  flex: 0 0 auto;
}
@media (min-width: 1101px) {
  #config-dialog .stack {
    grid-template-columns: 1fr;
  }
  #theme-btn,
  #show-tutorial-btn {
    width: 100%;
  }
}

/* v6: Graph readability — use a real panning canvas instead of squeezing nodes together. */
.graph-wrap {
  justify-content: start !important;
  align-items: start !important;
  align-content: start !important;
}
.graph-canvas {
  flex: 0 0 auto;
}
.graph-node-label {
  background: color-mix(in srgb, var(--panel) 76%, transparent);
  border-radius: 6px;
  padding: 0.08rem 0.2rem;
  max-width: 180px;
}
@media (max-width: 1100px) {
  #mobile-tree-content .graph-wrap,
  .tree-content.graph-mode .graph-wrap {
    overflow: hidden !important;
    touch-action: none;
  }
  #mobile-tree-content .graph-node-label,
  .tree-content.graph-mode .graph-node-label {
    max-width: 176px !important;
    font-size: 0.74rem !important;
    line-height: 1.12 !important;
    transform: translate(-50%, 46px) !important;
  }
}


/* ================================================================
   v7: compact Rack/Location forms on desktop and centered mobile.
   ================================================================ */
.rack-form-dialog {
  width: min(560px, calc(100vw - 48px)) !important;
  height: auto !important;
  min-height: 0 !important;
  max-height: min(86vh, 720px) !important;
  padding: 1rem 1.1rem 1.1rem !important;
  overflow: auto !important;
}

.rack-form-dialog .sheet-handle {
  margin-bottom: 0.5rem;
}

.rack-form-dialog-body {
  display: block !important;
  width: 100%;
  max-height: none !important;
  overflow: visible !important;
}

.rack-form-dialog .rack-form-inner {
  width: 100%;
  max-width: none;
  gap: 0.55rem;
}

.rack-form-dialog textarea {
  min-height: 82px;
  max-height: 150px;
}

.rack-form-dialog .rack-form-btns {
  margin-top: 0.75rem;
}

@media (max-width: 1100px) {
  .rack-form-dialog {
    position: fixed !important;
    inset: 50% auto auto 50% !important;
    transform: translate(-50%, -50%) !important;
    width: min(92vw, 560px) !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: min(78dvh, 680px) !important;
    margin: 0 !important;
    border-radius: 26px !important;
    padding: 0.9rem 1rem 1rem !important;
  }

  .rack-form-dialog[open] {
    animation: rack-form-pop-in 220ms ease !important;
  }

  @keyframes rack-form-pop-in {
    from { transform: translate(-50%, -47%) scale(0.985); opacity: 0.72; }
    to { transform: translate(-50%, -50%) scale(1); opacity: 1; }
  }

  dialog.rack-form-dialog::backdrop {
    background: rgba(0, 0, 0, 0.32) !important;
  }

  .rack-form-dialog-title {
    margin-top: 0.1rem !important;
    margin-bottom: 0.65rem !important;
  }

  .rack-form-dialog .rack-form-inner {
    max-width: none !important;
    gap: 0.55rem !important;
  }

  .rack-form-dialog .rack-form-btns {
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0.55rem !important;
    margin-top: 0.75rem !important;
  }

  .rack-form-dialog input,
  .rack-form-dialog select,
  .rack-form-dialog textarea {
    min-height: 46px;
    font-size: 16px !important;
  }

  .rack-form-dialog textarea {
    min-height: 86px !important;
    max-height: 28dvh !important;
  }
}

@media (max-width: 520px) {
  .rack-form-dialog .rack-form-btns {
    grid-template-columns: 1fr !important;
  }
}


/* ================================================================
   Mobile tab alignment v8: use one header/body pattern everywhere.
   ================================================================ */
@media (max-width: 1100px) {
  .panel-center {
    border-top: 0 !important;
    border-left: 0 !important;
    border-right: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    padding: 0 !important;
    background: var(--phone) !important;
  }

  .panel-center > .panel-head,
  .mobile-view-head,
  .rack-ov-topbar,
  .rack-overlay-head {
    min-height: 74px;
    box-sizing: border-box;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 0.75rem;
    padding: calc(1rem + env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0.8rem max(1rem, env(safe-area-inset-left)) !important;
    border-top: 0 !important;
    border-bottom: 3px solid var(--line) !important;
    background: var(--phone) !important;
    flex-shrink: 0;
  }

  .panel-center > .panel-head h2,
  .mobile-view-head h2,
  .rack-ov-title,
  .rack-editor-name {
    margin: 0 !important;
    font-size: 1rem !important;
    line-height: 1.2 !important;
  }

  .panel-center > .filters,
  .panel-center > .stats,
  .panel-center > .boards {
    margin-left: max(1rem, env(safe-area-inset-left));
    margin-right: max(1rem, env(safe-area-inset-right));
  }

  .panel-center > .filters {
    position: static !important;
    top: auto !important;
    padding-top: 1rem !important;
    border-top: 0 !important;
  }

  .mobile-view {
    background: var(--phone) !important;
    padding-top: 0 !important;
  }

  .mobile-view-body {
    padding: 1rem max(1rem, env(safe-area-inset-right)) calc(88px + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)) !important;
  }

  .mobile-view-footer {
    display: none !important;
  }

  #mobile-theme .theme-tabs {
    margin: 0 0 1rem !important;
    padding: 0 !important;
    border-bottom: 3px solid var(--line) !important;
  }

  #mobile-theme .theme-tab-panel {
    padding: 0 !important;
    overflow: visible !important;
  }

  #mobile-theme .theme-picker-grid {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }

  #mobile-theme .theme-swatch {
    min-height: 92px;
    border-radius: 18px;
    padding: 0.75rem;
  }

  #mobile-theme .theme-swatch-preview {
    height: 56px;
    border-radius: 12px;
  }

  #mobile-theme .dialog-footer,
  #mobile-theme .tree-head,
  #mobile-theme > .sheet-handle,
  #mobile-theme .sheet-handle {
    display: none !important;
  }

  .rack-overlay {
    padding: 0 0 calc(78px + env(safe-area-inset-bottom)) 0 !important;
    border-top: 0 !important;
    background: var(--phone) !important;
  }

  .rack-overview-body,
  .rack-overview-inner {
    width: 100% !important;
    max-width: 100% !important;
  }

  .rack-overview-body {
    padding: 0 !important;
    overflow-y: auto !important;
  }

  .rack-ov-topbar {
    margin: 0 !important;
  }

  .rack-ov-actions {
    flex-wrap: nowrap !important;
    gap: 0.5rem !important;
  }

  .rack-ov-actions .button {
    min-height: 44px;
    padding-inline: 0.8rem !important;
  }

  .rack-ov-panel {
    padding: 1rem max(1rem, env(safe-area-inset-right)) calc(88px + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)) !important;
    margin: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: var(--phone) !important;
    box-shadow: none !important;
  }

  .rack-overlay-head {
    min-height: 74px !important;
  }

  .rack-editor-title-wrap {
    min-width: 0;
  }

  .rack-editor-right-actions .button {
    min-height: 44px;
  }
}


/* ================================================================
   v9: restore mobile Theme view and standardize all mobile topbars.
   ================================================================ */
@media (max-width: 1100px) {
  :root { --mobile-tab-head-h: calc(76px + env(safe-area-inset-top)); }

  .panel-center > .panel-head,
  .mobile-view-head,
  .rack-ov-topbar,
  .rack-overlay-head {
    height: var(--mobile-tab-head-h) !important;
    min-height: var(--mobile-tab-head-h) !important;
    max-height: var(--mobile-tab-head-h) !important;
    box-sizing: border-box !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 0.75rem !important;
    padding: env(safe-area-inset-top) max(1rem, env(safe-area-inset-right)) 0 max(1rem, env(safe-area-inset-left)) !important;
    border-top: 0 !important;
    border-bottom: 3px solid var(--line) !important;
    background: var(--phone) !important;
    flex: 0 0 var(--mobile-tab-head-h) !important;
  }

  .panel-center > .panel-head h2,
  .mobile-view-head h2,
  .rack-ov-title,
  .rack-editor-name {
    margin: 0 !important;
    font-size: 1rem !important;
    line-height: 1.2 !important;
  }

  .rack-ov-topbar .rack-ov-actions,
  .rack-overlay-head .rack-editor-right-actions {
    align-items: center !important;
  }

  #mobile-theme.active {
    display: flex !important;
    z-index: 80 !important;
    pointer-events: auto !important;
  }

  #mobile-theme-body {
    display: block !important;
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch;
    padding: 1rem max(1rem, env(safe-area-inset-right)) calc(88px + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)) !important;
  }

  #mobile-theme-body .tree-head,
  #mobile-theme-body .dialog-footer,
  #mobile-theme-body > .sheet-handle,
  #mobile-theme-body .sheet-handle {
    display: none !important;
  }

  #mobile-theme-body .theme-tabs {
    margin: 0 0 1rem !important;
    padding: 0 !important;
    border-bottom: 3px solid var(--line) !important;
    background: var(--phone) !important;
  }

  #mobile-theme-body .theme-tab-panel {
    padding: 0 !important;
    overflow: visible !important;
  }

  #mobile-theme-body .theme-picker-grid {
    grid-template-columns: 1fr !important;
    gap: 0.75rem !important;
  }

  #mobile-theme-body .theme-swatch {
    min-height: 92px !important;
    border-radius: 18px !important;
    padding: 0.75rem !important;
  }

  #mobile-theme-body .theme-swatch-preview {
    height: 56px !important;
    border-radius: 12px !important;
  }
}


/* v10: align desktop Config footer with Themes and use consistent Themes title spacing. */
#config-dialog[open] {
  overflow: hidden;
}
#config-dialog .dialog-footer {
  margin-top: auto !important;
  flex: 0 0 auto;
}
#config-dialog .config-content {
  margin-bottom: 0.85rem;
}

@media (max-width: 1100px) {
  #mobile-theme .mobile-view-head h2,
  #mobile-theme-body .tree-head h3 {
    text-transform: none;
  }
}

/* ================================================================
   v11: compact desktop rack dialogs and rack workspace.
   ================================================================ */
@media (min-width: 1101px) {
  /* Rack/Location forms are true content-sized dialogs, not Tree-sized panels. */
  dialog.rack-form-dialog,
  dialog.rack-form-dialog[open] {
    display: block !important;
    position: fixed !important;
    inset: 50% auto auto 50% !important;
    transform: translate(-50%, -50%) !important;
    width: min(540px, calc(100vw - 96px)) !important;
    height: fit-content !important;
    min-height: 0 !important;
    max-height: calc(100dvh - 96px) !important;
    max-width: calc(100vw - 96px) !important;
    margin: 0 !important;
    overflow: auto !important;
    padding: 1rem 1.15rem 1.1rem !important;
    border-radius: 18px !important;
  }

  dialog.rack-form-dialog .sheet-handle {
    margin: 0 auto 0.85rem !important;
  }

  dialog.rack-form-dialog .rack-form-dialog-title {
    margin: 0 0 0.75rem !important;
  }

  dialog.rack-form-dialog .rack-form-dialog-body,
  dialog.rack-form-dialog .rack-form-inner {
    display: block !important;
    width: 100% !important;
    max-width: none !important;
    max-height: none !important;
    overflow: visible !important;
  }

  dialog.rack-form-dialog .rack-form-inner label {
    margin-bottom: 0.55rem !important;
  }

  dialog.rack-form-dialog .rack-form-inner textarea {
    min-height: 84px !important;
    max-height: 140px !important;
  }

  dialog.rack-form-dialog .rack-form-btns {
    margin-top: 0.8rem !important;
  }

  /* Desktop Rack View becomes a compact workspace instead of a full empty page. */
  #rack-overview.rack-overlay,
  #rack-editor.rack-overlay {
    inset: 50% auto auto 50% !important;
    transform: translate(-50%, -50%) !important;
    width: min(1500px, calc(100vw - 96px)) !important;
    height: auto !important;
    min-height: 0 !important;
    max-height: calc(100dvh - 84px) !important;
    border: 3px solid var(--line) !important;
    border-radius: 22px !important;
    background: var(--phone) !important;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.28) !important;
    overflow: hidden !important;
  }

  #rack-overview.rack-overlay::before,
  #rack-editor.rack-overlay::before {
    display: none !important;
  }

  #rack-overview .rack-overview-body {
    flex: 0 1 auto !important;
    max-height: calc(100dvh - 84px) !important;
    overflow: auto !important;
    padding: 1rem 1.15rem 1.15rem !important;
  }

  #rack-overview .rack-overview-inner {
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    flex: 0 0 auto !important;
    gap: 0.8rem !important;
  }

  #rack-overview .rack-ov-topbar {
    padding: 0 0 0.75rem !important;
    border-bottom: 2px solid var(--line) !important;
  }

  #rack-overview .rack-ov-panel {
    box-shadow: none !important;
    border-width: 2px !important;
    border-radius: 18px !important;
    padding: 0.9rem !important;
    gap: 0.8rem !important;
    min-height: 0 !important;
  }

  #rack-overview .rack-cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)) !important;
    gap: 0.7rem !important;
  }

  #rack-overview .rack-card {
    padding: 0.75rem 0.8rem !important;
    border-radius: 14px !important;
    box-shadow: none !important;
  }

  #rack-overview .rack-card-icon {
    margin-bottom: 0.25rem !important;
  }

  /* Editor: palette + racks are one compact workbench with less empty space. */
  #rack-editor.rack-overlay {
    width: min(1680px, calc(100vw - 64px)) !important;
  }

  #rack-editor .rack-overlay-head {
    min-height: 48px !important;
    padding: 0.55rem 0.9rem !important;
    border-bottom-width: 2px !important;
  }

  #rack-editor .rack-editor-body {
    flex: 0 1 auto !important;
    min-height: 0 !important;
    max-height: calc(100dvh - 136px) !important;
    overflow: hidden !important;
  }

  #rack-editor .rack-palette {
    width: clamp(170px, 11vw, 220px) !important;
    border-right-width: 2px !important;
  }

  #rack-editor .rack-palette-title {
    padding: 0.55rem 0.65rem 0.4rem !important;
    border-bottom-width: 2px !important;
  }

  #rack-editor .rack-palette-items {
    padding: 0.4rem !important;
    gap: 0.22rem !important;
  }

  #rack-editor .rack-palette-item {
    padding: 0.28rem 0.42rem !important;
    font-size: 0.7rem !important;
  }

  #rack-editor .rack-views-wrap {
    justify-content: stretch !important;
    align-items: flex-start !important;
    gap: 1rem !important;
    padding: 0.75rem 0.9rem 0.95rem !important;
    overflow: auto !important;
  }

  #rack-editor .rack-view-col {
    flex: 1 1 0 !important;
    min-width: 360px !important;
    max-width: none !important;
  }

  #rack-editor .rack-view-title {
    margin-bottom: 0.15rem !important;
  }

  #rack-editor .rack-frame {
    border-width: 2px !important;
    border-radius: 12px !important;
  }
}

/* ================================================================
   v12: remove stray desktop rack dialog, make rack desktop native,
   and improve mobile custom theme editing.
   ================================================================ */

/* Safety: closed dialogs must never render as empty boxes. */
dialog.rack-form-dialog:not([open]) {
  display: none !important;
}

@media (min-width: 1101px) {
  /* Only content-size the rack/location form when it is actually open. */
  dialog.rack-form-dialog[open] {
    display: block !important;
    position: fixed !important;
    inset: 50% auto auto 50% !important;
    transform: translate(-50%, -50%) !important;
    width: min(540px, calc(100vw - 96px)) !important;
    height: fit-content !important;
    min-height: 0 !important;
    max-height: calc(100dvh - 96px) !important;
    max-width: calc(100vw - 96px) !important;
    margin: 0 !important;
    overflow: auto !important;
    padding: 1rem 1.15rem 1.1rem !important;
    border-radius: 18px !important;
  }

  /* Sheet handles belong to mobile sheets, not desktop dialogs. */
  dialog.rack-form-dialog .sheet-handle,
  #rack-palette > .sheet-handle {
    display: none !important;
  }

  /* Desktop Rack View / Editor are now native workspaces, not modal windows. */
  #rack-overview.rack-overlay,
  #rack-editor.rack-overlay {
    position: fixed !important;
    inset: 44px 0 0 0 !important;
    transform: none !important;
    width: auto !important;
    height: auto !important;
    max-height: none !important;
    min-height: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: var(--bg) !important;
    overflow: hidden !important;
  }

  #rack-overview.rack-overlay::before,
  #rack-editor.rack-overlay::before {
    display: none !important;
  }

  #rack-overview .rack-overview-body {
    height: 100% !important;
    max-height: none !important;
    overflow: auto !important;
    padding: clamp(1rem, 1.4vw, 1.6rem) clamp(1.2rem, 4vw, 4.5rem) !important;
  }

  #rack-overview .rack-overview-inner {
    width: min(1480px, 100%) !important;
    max-width: none !important;
    margin: 0 auto !important;
    flex: 0 0 auto !important;
    gap: 1rem !important;
  }

  #rack-overview .rack-ov-topbar {
    padding: 0 0 0.9rem !important;
    border-bottom: 0 !important;
  }

  #rack-overview .rack-ov-panel {
    border: 3px solid var(--line) !important;
    border-radius: 18px !important;
    box-shadow: var(--shadow) !important;
    padding: 1rem !important;
    background: color-mix(in srgb, var(--phone) 96%, white) !important;
  }

  #rack-overview .rack-cards-grid {
    grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)) !important;
    gap: 0.8rem !important;
  }

  #rack-editor .rack-overlay-head {
    flex: 0 0 50px !important;
    min-height: 50px !important;
    padding: 0.55rem clamp(1rem, 2vw, 2rem) !important;
    border-bottom: 3px solid var(--line) !important;
    background: var(--phone) !important;
  }

  #rack-editor .rack-editor-body {
    height: calc(100dvh - 94px) !important;
    max-height: none !important;
    min-height: 0 !important;
    overflow: hidden !important;
    background: var(--bg) !important;
  }

  #rack-editor .rack-palette {
    width: clamp(190px, 12vw, 250px) !important;
    border-right: 3px solid var(--line) !important;
    background: var(--phone) !important;
  }

  #rack-editor .rack-views-wrap {
    flex: 1 1 auto !important;
    height: 100% !important;
    padding: clamp(0.9rem, 1.4vw, 1.5rem) clamp(1rem, 2.4vw, 2.5rem) !important;
    justify-content: center !important;
    align-items: flex-start !important;
    gap: clamp(1.2rem, 2.2vw, 2.4rem) !important;
    overflow: auto !important;
  }

  #rack-editor .rack-view-col {
    flex: 1 1 0 !important;
    min-width: min(520px, 42vw) !important;
    max-width: 820px !important;
  }

  #rack-editor .rack-frame {
    border: 3px solid var(--line) !important;
    border-radius: 14px !important;
    background: var(--panel) !important;
  }
}

@media (max-width: 1100px) {
  /* Mobile customizer: use the full screen calmly and avoid desktop sidebars. */
  #mobile-theme-body .theme-custom-wrap {
    display: flex !important;
    flex-direction: column !important;
    gap: 1rem !important;
    height: auto !important;
    min-height: 0 !important;
  }

  #mobile-theme-body .theme-custom-wrap .theme-name-field {
    order: 0 !important;
    width: 100% !important;
  }

  #mobile-theme-body .theme-custom-wrap .theme-name-field input {
    width: 100% !important;
    min-height: 52px !important;
    font-size: 16px !important;
    border-radius: 16px !important;
    padding: 0.65rem 0.8rem !important;
  }

  #mobile-theme-body .theme-color-grid {
    order: 1 !important;
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.7rem !important;
    width: 100% !important;
  }

  #mobile-theme-body .theme-color-field {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.45rem !important;
    min-height: 106px !important;
    padding: 0.65rem !important;
    border-radius: 18px !important;
    background: var(--panel) !important;
  }

  #mobile-theme-body .theme-color-field input[type="color"] {
    width: 100% !important;
    height: 48px !important;
    border-radius: 12px !important;
  }

  #mobile-theme-body .theme-color-field span,
  #mobile-theme-body .theme-color-field label,
  #mobile-theme-body .theme-color-field .theme-color-label {
    font-size: 0.78rem !important;
    line-height: 1.15 !important;
    color: var(--muted) !important;
  }

  #mobile-theme-body .theme-custom-wrap .theme-actions {
    order: 2 !important;
    position: sticky !important;
    bottom: calc(80px + env(safe-area-inset-bottom)) !important;
    display: block !important;
    padding: 0.65rem !important;
    border: 3px solid var(--line) !important;
    border-radius: 20px !important;
    background: color-mix(in srgb, var(--phone) 94%, white) !important;
    box-shadow: 0 14px 35px rgba(0,0,0,0.18) !important;
  }

  #mobile-theme-body .theme-custom-wrap .theme-actions::before,
  #mobile-theme-body .theme-custom-wrap .theme-actions::after {
    display: none !important;
  }

  #mobile-theme-body .theme-custom-wrap .theme-actions .button,
  #mobile-theme-body .theme-custom-wrap .theme-actions .primary-btn {
    width: 100% !important;
    min-height: 52px !important;
    border-radius: 18px !important;
    font-size: 0.95rem !important;
  }
}

@media (max-width: 520px) {
  #mobile-theme-body .theme-color-grid {
    grid-template-columns: 1fr !important;
  }
}

/* ================================================================
   v13: real mobile theme customizer and simplified desktop rack workspace.
   ================================================================ */
@media (max-width: 1100px) {
  /* The Customize tab is rendered with tb-* classes, so optimize those directly. */
  #mobile-theme-body #theme-tab-customize {
    padding: 0 !important;
  }

  #mobile-theme-body #theme-customize-body.theme-builder-body {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.9rem !important;
    width: 100% !important;
    max-width: none !important;
    margin: 0 !important;
    padding: 0 0 calc(120px + env(safe-area-inset-bottom)) !important;
  }

  #mobile-theme-body .tb-base-row {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.45rem !important;
    padding: 0.8rem !important;
    border: 3px solid var(--line) !important;
    border-radius: 20px !important;
    background: var(--panel) !important;
    color: var(--muted) !important;
  }

  #mobile-theme-body .tb-base-row input[type='text'] {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 54px !important;
    padding: 0.65rem 0.8rem !important;
    border: 3px solid var(--line) !important;
    border-radius: 16px !important;
    background: var(--phone) !important;
    color: var(--text) !important;
    font-size: 16px !important;
  }

  #mobile-theme-body .tb-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.75rem !important;
    width: 100% !important;
  }

  #mobile-theme-body .tb-color-row {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.5rem !important;
    min-height: 112px !important;
    padding: 0.7rem !important;
    border: 3px solid var(--line) !important;
    border-radius: 20px !important;
    background: var(--panel) !important;
    align-items: stretch !important;
  }

  #mobile-theme-body .tb-color-row input[type='color'] {
    order: 1 !important;
    width: 100% !important;
    height: 54px !important;
    border: 3px solid var(--line) !important;
    border-radius: 14px !important;
    background: var(--phone) !important;
  }

  #mobile-theme-body .tb-color-row span {
    order: 2 !important;
    min-height: 2.2em !important;
    color: var(--muted) !important;
    font-size: 0.78rem !important;
    line-height: 1.2 !important;
    display: flex !important;
    align-items: center !important;
  }

  #mobile-theme-body .tb-actions {
    position: sticky !important;
    bottom: calc(76px + env(safe-area-inset-bottom)) !important;
    display: block !important;
    margin-top: 0.25rem !important;
    padding: 0.55rem !important;
    border: 3px solid var(--line) !important;
    border-radius: 22px !important;
    background: color-mix(in srgb, var(--phone) 96%, white) !important;
    box-shadow: 0 18px 42px rgba(0,0,0,0.18) !important;
    z-index: 5 !important;
  }

  #mobile-theme-body .tb-actions .button,
  #mobile-theme-body .tb-actions #tb-save {
    width: 100% !important;
    min-height: 56px !important;
    border-radius: 18px !important;
    background: var(--yellow) !important;
    font-size: 0.95rem !important;
  }
}

@media (max-width: 520px) {
  #mobile-theme-body .tb-grid {
    grid-template-columns: 1fr !important;
  }
}

@media (min-width: 1101px) {
  /* Rack is a native full-screen workspace on desktop: no app header overlap, no card-in-card shell. */
  #rack-overview.rack-overlay,
  #rack-editor.rack-overlay {
    position: fixed !important;
    inset: 0 !important;
    z-index: 180 !important;
    width: auto !important;
    height: auto !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: var(--bg) !important;
    overflow: hidden !important;
  }

  #rack-overview.rack-overlay::before,
  #rack-editor.rack-overlay::before {
    display: none !important;
  }

  #rack-overview .rack-overview-body {
    height: 100dvh !important;
    max-height: none !important;
    overflow: auto !important;
    padding: clamp(1rem, 2vw, 2rem) clamp(1.4rem, 4vw, 5rem) !important;
    background: var(--bg) !important;
  }

  #rack-overview .rack-overview-inner {
    width: min(1500px, 100%) !important;
    margin: 0 auto !important;
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 1rem !important;
    flex: none !important;
  }

  #rack-overview .rack-ov-topbar {
    position: sticky !important;
    top: 0 !important;
    z-index: 4 !important;
    padding: 0.35rem 0 0.9rem !important;
    background: var(--bg) !important;
    border-bottom: 3px solid var(--line) !important;
  }

  #rack-overview .rack-ov-title {
    font-size: 1.05rem !important;
  }

  #rack-overview .rack-ov-actions .button {
    min-height: 38px !important;
    padding: 0.38rem 0.7rem !important;
  }

  #rack-overview .rack-ov-panel {
    display: grid !important;
    grid-template-columns: 280px minmax(0, 1fr) !important;
    gap: 1rem !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    box-shadow: none !important;
    background: transparent !important;
  }

  #rack-overview .rack-location-bar {
    align-content: start !important;
    align-self: start !important;
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.5rem !important;
    padding: 0.9rem !important;
    border: 3px solid var(--line) !important;
    border-radius: 18px !important;
    background: var(--phone) !important;
    box-shadow: var(--shadow) !important;
  }

  #rack-overview .rack-location-bar select,
  #rack-overview .rack-location-bar .button {
    width: 100% !important;
    min-height: 40px !important;
  }

  #rack-overview .rack-cards-grid {
    display: grid !important;
    grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)) !important;
    align-content: start !important;
    gap: 0.9rem !important;
  }

  #rack-overview .rack-card {
    min-height: 120px !important;
    padding: 1rem !important;
    border: 3px solid var(--line) !important;
    border-radius: 18px !important;
    background: var(--phone) !important;
  }

  #rack-overview .rack-empty-state {
    grid-column: 1 / -1 !important;
    min-height: 320px !important;
    border: 3px dashed var(--line) !important;
    border-radius: 22px !important;
    background: color-mix(in srgb, var(--panel) 70%, transparent) !important;
  }

  #rack-editor .rack-overlay-head {
    flex: 0 0 58px !important;
    min-height: 58px !important;
    padding: 0.55rem clamp(1rem, 2vw, 2rem) !important;
    border-bottom: 3px solid var(--line) !important;
    background: var(--phone) !important;
  }

  #rack-editor .rack-editor-body {
    height: calc(100dvh - 58px) !important;
    min-height: 0 !important;
    display: grid !important;
    grid-template-columns: clamp(210px, 14vw, 300px) minmax(0, 1fr) !important;
    overflow: hidden !important;
    background: var(--bg) !important;
  }

  #rack-editor .rack-palette {
    width: auto !important;
    height: 100% !important;
    border-right: 3px solid var(--line) !important;
    background: var(--phone) !important;
  }

  #rack-editor .rack-views-wrap {
    height: 100% !important;
    display: grid !important;
    grid-template-columns: repeat(2, minmax(360px, 1fr)) !important;
    gap: clamp(1rem, 2vw, 2rem) !important;
    align-content: start !important;
    justify-content: stretch !important;
    padding: clamp(1rem, 2vw, 2.2rem) !important;
    overflow: auto !important;
  }

  #rack-editor .rack-view-col {
    min-width: 0 !important;
    max-width: none !important;
    width: 100% !important;
    flex: none !important;
  }

  #rack-editor .rack-frame {
    width: 100% !important;
    border: 3px solid var(--line) !important;
    border-radius: 18px !important;
    background: var(--panel) !important;
    box-shadow: var(--shadow) !important;
  }
}

/* ================================================================
   v14: mobile Themes uses two-column selection/customize grid.
   Name + Save stay full width for faster one-handed editing.
   ================================================================ */
@media (max-width: 1100px) {
  #mobile-theme-body {
    padding-inline: clamp(1rem, 4vw, 1.4rem) !important;
  }

  /* Default theme selection: two calm columns instead of a long single list. */
  #mobile-theme-body .theme-picker-grid,
  #mobile-theme-body #theme-tab-themes .theme-picker-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.75rem !important;
    width: 100% !important;
  }

  #mobile-theme-body .theme-swatch {
    min-width: 0 !important;
    padding: 0.65rem !important;
    border-radius: 18px !important;
  }

  #mobile-theme-body .theme-swatch-preview {
    height: 54px !important;
    min-height: 54px !important;
    border-radius: 14px !important;
  }

  #mobile-theme-body .theme-swatch-name {
    font-size: 0.78rem !important;
    line-height: 1.2 !important;
  }

  /* Customize: name input is the full-width first row. */
  #mobile-theme-body #theme-customize-body.theme-builder-body {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.85rem !important;
    width: 100% !important;
    padding-bottom: calc(112px + env(safe-area-inset-bottom)) !important;
  }

  #mobile-theme-body .tb-base-row {
    grid-column: 1 / -1 !important;
    width: 100% !important;
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.5rem !important;
    padding: 0.75rem !important;
  }

  #mobile-theme-body .tb-base-row input[type='text'],
  #mobile-theme-body #tb-name {
    width: 100% !important;
    max-width: none !important;
    min-height: 54px !important;
    font-size: 16px !important;
  }

  /* Color controls stay two-column even on narrow phones. */
  #mobile-theme-body .tb-grid,
  #mobile-theme-body .theme-color-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.65rem !important;
    width: 100% !important;
  }

  #mobile-theme-body .tb-color-row,
  #mobile-theme-body .theme-color-field {
    min-width: 0 !important;
    min-height: 96px !important;
    padding: 0.6rem !important;
    border-radius: 18px !important;
  }

  #mobile-theme-body .tb-color-row input[type='color'],
  #mobile-theme-body .theme-color-field input[type='color'] {
    width: 100% !important;
    height: 48px !important;
    min-height: 48px !important;
  }

  #mobile-theme-body .tb-color-row span,
  #mobile-theme-body .theme-color-field span,
  #mobile-theme-body .theme-color-label {
    font-size: 0.72rem !important;
    line-height: 1.15 !important;
    min-height: 2em !important;
  }

  /* Save stays a full-width sticky action. */
  #mobile-theme-body .tb-actions,
  #mobile-theme-body .theme-custom-wrap .theme-actions {
    grid-column: 1 / -1 !important;
    width: 100% !important;
    position: sticky !important;
    bottom: calc(76px + env(safe-area-inset-bottom)) !important;
    margin-top: 0.1rem !important;
    padding: 0.55rem !important;
    border-radius: 20px !important;
    z-index: 10 !important;
  }

  #mobile-theme-body .tb-actions #tb-save,
  #mobile-theme-body .tb-actions .button,
  #mobile-theme-body .theme-custom-wrap .theme-actions .button,
  #mobile-theme-body .theme-custom-wrap .theme-actions .primary-btn {
    width: 100% !important;
    max-width: none !important;
    min-height: 56px !important;
  }
}

@media (max-width: 520px) {
  #mobile-theme-body .theme-picker-grid,
  #mobile-theme-body #theme-tab-themes .theme-picker-grid,
  #mobile-theme-body .tb-grid,
  #mobile-theme-body .theme-color-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 360px) {
  #mobile-theme-body .theme-picker-grid,
  #mobile-theme-body #theme-tab-themes .theme-picker-grid,
  #mobile-theme-body .tb-grid,
  #mobile-theme-body .theme-color-grid {
    gap: 0.45rem !important;
  }

  #mobile-theme-body .tb-color-row,
  #mobile-theme-body .theme-color-field,
  #mobile-theme-body .theme-swatch {
    padding: 0.45rem !important;
  }
}

/* ================================================================
   v15: mobile theme save button is a normal final action.
   ================================================================ */
@media (max-width: 1100px) {
  #mobile-theme-body #theme-customize-body.theme-builder-body {
    padding-bottom: calc(1.5rem + env(safe-area-inset-bottom)) !important;
  }

  #mobile-theme-body .tb-actions,
  #mobile-theme-body .theme-custom-wrap .theme-actions {
    position: static !important;
    bottom: auto !important;
    z-index: auto !important;
    box-shadow: none !important;
    margin: 0.4rem 0 calc(1rem + env(safe-area-inset-bottom)) !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
  }

  #mobile-theme-body .tb-actions #tb-save,
  #mobile-theme-body .tb-actions .button,
  #mobile-theme-body .theme-custom-wrap .theme-actions .button,
  #mobile-theme-body .theme-custom-wrap .theme-actions .primary-btn {
    width: 100% !important;
    max-width: none !important;
    min-height: 58px !important;
    border-radius: 20px !important;
  }
}

/* ================================================================
   v16: use desktop Themes Customize space more deliberately.
   ================================================================ */
@media (min-width: 1101px) {
  .theme-picker-dialog #theme-tab-customize {
    min-height: 0;
  }

  .theme-picker-dialog #theme-customize-body.theme-builder-body {
    min-height: clamp(520px, 62vh, 760px);
    height: 100%;
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr) auto;
    gap: 1.15rem;
    margin-top: 0;
  }

  .theme-picker-dialog #theme-customize-body .tb-base-row {
    display: grid;
    grid-template-columns: minmax(120px, 220px) minmax(320px, 1fr);
    align-items: center;
    gap: 1rem;
    width: 100%;
    padding: 0.9rem 1rem;
    border: 2px solid var(--line);
    border-radius: 18px;
    background: color-mix(in srgb, var(--panel) 82%, var(--bg));
  }

  .theme-picker-dialog #theme-customize-body .tb-base-row input[type='text'],
  .theme-picker-dialog #theme-customize-body #tb-name {
    width: 100%;
    min-width: 0;
    min-height: 54px;
    font-size: 0.95rem;
  }

  .theme-picker-dialog #theme-customize-body .tb-grid {
    display: grid;
    grid-template-columns: repeat(5, minmax(150px, 1fr));
    grid-auto-rows: minmax(112px, 1fr);
    gap: 1rem;
    width: 100%;
    min-height: 0;
    align-content: stretch;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row {
    display: grid;
    grid-template-rows: minmax(68px, 1fr) auto;
    align-items: stretch;
    gap: 0.75rem;
    min-height: 118px;
    padding: 0.85rem;
    border: 2px solid var(--line);
    border-radius: 18px;
    background: var(--card);
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row input[type='color'] {
    width: 100%;
    height: 100%;
    min-height: 66px;
    padding: 4px;
    border: 2px solid var(--line);
    border-radius: 12px;
    background: var(--panel);
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row span {
    min-height: 2.2em;
    color: var(--muted);
    font-size: 0.78rem;
    line-height: 1.18;
  }

  .theme-picker-dialog #theme-customize-body .tb-actions {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding-top: 0.25rem;
  }

  .theme-picker-dialog #theme-customize-body .tb-actions #tb-save,
  .theme-picker-dialog #theme-customize-body .tb-actions .button {
    min-width: min(340px, 30vw);
    min-height: 52px;
    border-radius: 16px;
  }
}

@media (min-width: 1500px) {
  .theme-picker-dialog #theme-customize-body .tb-grid {
    grid-template-columns: repeat(7, minmax(140px, 1fr));
  }
}

/* ================================================================
   v17: compact mobile headers and restore mobile scrolling.
   ================================================================ */
@media (max-width: 1100px) {
  :root { --mobile-tab-head-h: calc(58px + env(safe-area-inset-top)); }

  /* Avoid the old split/wave background peeking through above mobile headers. */
  body::before { display: none !important; }
  body,
  .app,
  .phone-grid,
  .panel-center,
  .mobile-view,
  .rack-overlay {
    background: var(--phone) !important;
  }

  /* Mobile views already include safe-area inside the header; no extra strip above it. */
  .mobile-view {
    padding-top: 0 !important;
    height: 100dvh !important;
    min-height: 100dvh !important;
    overflow: hidden !important;
  }

  .panel-center > .panel-head,
  .mobile-view-head,
  .rack-ov-topbar,
  .rack-overlay-head {
    height: var(--mobile-tab-head-h) !important;
    min-height: var(--mobile-tab-head-h) !important;
    max-height: var(--mobile-tab-head-h) !important;
    padding: env(safe-area-inset-top) max(0.75rem, env(safe-area-inset-right)) 0 max(0.75rem, env(safe-area-inset-left)) !important;
    border-bottom-width: 2px !important;
  }

  .panel-center > .panel-head h2,
  .mobile-view-head h2,
  .rack-ov-title,
  .rack-editor-name {
    font-size: 0.95rem !important;
    line-height: 1.1 !important;
  }

  .mobile-view-head .view-switch,
  .rack-ov-actions,
  .rack-editor-right-actions {
    min-height: 0 !important;
    gap: 0.35rem !important;
  }

  .mobile-view-head .icon-btn,
  .rack-ov-actions .button,
  .rack-editor-right-actions .button {
    min-height: 40px !important;
    padding-block: 0.35rem !important;
    padding-inline: 0.55rem !important;
  }

  /* Topology is the main mobile tab, not a dialog: let the whole page scroll. */
  .phone-grid {
    height: 100dvh !important;
    min-height: 100dvh !important;
    overflow: hidden !important;
    padding-top: 0 !important;
    padding-bottom: calc(72px + env(safe-area-inset-bottom)) !important;
  }

  .panel-center {
    height: calc(100dvh - 72px - env(safe-area-inset-bottom)) !important;
    min-height: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior: contain !important;
  }

  .panel-center > .filters,
  .panel-center > .stats,
  .panel-center > .boards {
    flex: 0 0 auto !important;
  }

  .panel-center > .boards {
    overflow: visible !important;
    padding-bottom: 1.25rem !important;
  }

  /* Relationship Tree / Graph content must scroll inside its view. */
  #mobile-tree-content {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom)) !important;
  }

  #mobile-tree-content .tree-shell,
  #mobile-tree-content .graph-wrap {
    min-height: calc(100dvh - var(--mobile-tab-head-h) - 84px - env(safe-area-inset-bottom)) !important;
  }

  /* Rack editor: scroll the editor body and keep the selected side usable on touch. */
  #rack-editor.rack-overlay {
    height: 100dvh !important;
    min-height: 100dvh !important;
    padding: 0 0 calc(72px + env(safe-area-inset-bottom)) 0 !important;
    overflow: hidden !important;
  }

  #rack-editor .rack-editor-body {
    height: auto !important;
    min-height: 0 !important;
    flex: 1 1 auto !important;
    display: block !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior: contain !important;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom)) !important;
  }

  #rack-editor .rack-views-wrap {
    max-height: none !important;
    height: auto !important;
    overflow: visible !important;
    padding-bottom: 2rem !important;
  }

  #rack-editor .rack-frame {
    max-width: min(100%, 560px) !important;
  }
}


/* ================================================================
   v18: clean mobile bottom edge, colorful nav icons, rack scroll on slots.
   ================================================================ */
@media (max-width: 1100px) {
  /* Only one divider above the mobile nav. */
  .bottom-nav {
    border-top: 2px solid var(--line) !important;
    box-shadow: 0 -8px 20px rgba(0,0,0,0.08) !important;
  }

  .panel-center,
  .panel-center.phone,
  .mobile-view,
  .mobile-view-body,
  .phone-grid,
  .boards {
    border-bottom: 0 !important;
  }

  .panel-center::after,
  .phone-grid::after,
  .mobile-view::after {
    display: none !important;
    content: none !important;
  }

  .panel-center > .boards {
    margin-bottom: 0 !important;
    border-bottom: 0 !important;
    padding-bottom: calc(1rem + env(safe-area-inset-bottom)) !important;
  }

  /* Bring back the more colorful mobile nav feel. */
  .bottom-nav-icon {
    font-family: "Apple Color Emoji", "Segoe UI Emoji", "Noto Color Emoji", sans-serif !important;
    font-size: 1.48rem !important;
    line-height: 1 !important;
    filter: none !important;
  }

  .bottom-nav-item {
    color: var(--text) !important;
  }

  .bottom-nav-item.active .bottom-nav-icon {
    transform: translateY(-1px) scale(1.04);
  }

  /* Vertical swipes on the rack itself should scroll the editor. */
  #rack-editor .rack-editor-body,
  #rack-editor .rack-views-wrap,
  #rack-editor .rack-view-col,
  #rack-editor .rack-frame,
  #rack-editor .rack-slot,
  #rack-editor .rack-slot-content,
  #rack-editor .rack-slot-label,
  #rack-editor .rack-slot-device {
    touch-action: pan-y !important;
  }

  #rack-editor .rack-slot,
  #rack-editor .rack-slot * {
    -webkit-user-drag: none !important;
  }

  #rack-editor .rack-slot-remove {
    touch-action: manipulation !important;
  }
}

/* v19: reliable mobile graph links and edit sheet interaction */
.graph-links {
  left: 0;
  top: 0;
  overflow: visible;
  z-index: 0;
}
.graph-link {
  vector-effect: non-scaling-stroke;
}
.graph-node,
.graph-node-label {
  z-index: 2;
}
.graph-info-panel {
  pointer-events: auto;
}
.graph-info-edit {
  width: 100%;
  margin-top: 0.45rem;
}
@media (max-width: 1100px) {
  #mobile-tree-content .graph-wrap {
    min-height: calc(100dvh - var(--mobile-tab-head-h) - 92px - env(safe-area-inset-bottom)) !important;
  }
  #mobile-tree-content .graph-canvas {
    overflow: visible !important;
  }
  #mobile-tree-content .graph-links {
    display: block !important;
    opacity: 1 !important;
  }
  #mobile-tree-content .graph-link {
    stroke-width: 3px;
    stroke-opacity: 0.92;
  }
}


/* ================================================================
   v21: remove mobile Graph view, restore More ellipsis, robust rack scrolling.
   ================================================================ */
@media (max-width: 1100px) {
  #mobile-tree .view-switch { display: inline-flex !important; }
  #mobile-tree-mode-graph { display: none !important; }

  #nav-more .bottom-nav-icon {
    font-family: inherit !important;
    font-size: 1.85rem !important;
    letter-spacing: 0.08em;
    line-height: 0.8 !important;
  }

  #rack-editor .rack-editor-body {
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    touch-action: pan-y !important;
  }

  #rack-editor .rack-views-wrap,
  #rack-editor .rack-view-col,
  #rack-editor .rack-frame,
  #rack-editor .rack-slot,
  #rack-editor .rack-slot-content,
  #rack-editor .rack-slot-label,
  #rack-editor .rack-slot-device {
    touch-action: none !important;
  }

  #rack-editor .rack-slot-remove,
  #rack-editor button,
  #rack-editor select,
  #rack-editor input,
  #rack-editor textarea {
    touch-action: manipulation !important;
  }
}

/* ================================================================
   v22: make desktop Theme Customize save action full width.
   ================================================================ */
@media (min-width: 1101px) {
  .theme-picker-dialog #theme-customize-body .tb-actions {
    display: block;
    width: 100%;
    padding: 0.35rem 0 0;
  }

  .theme-picker-dialog #theme-customize-body .tb-actions #tb-save,
  .theme-picker-dialog #theme-customize-body .tb-actions .button {
    width: 100%;
    min-width: 0;
    min-height: 54px;
    border-radius: 16px;
  }
}

/* ================================================================
   v25: desktop Theme save spacing and mobile Tree bottom clearance.
   ================================================================ */
@media (min-width: 1101px) {
  .theme-picker-dialog #theme-customize-body .tb-actions {
    padding: 0.65rem 0 1.1rem !important;
    margin-bottom: 0.75rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-actions #tb-save,
  .theme-picker-dialog #theme-customize-body .tb-actions .button {
    min-height: 58px !important;
  }
}

@media (max-width: 1100px) {
  #mobile-tree-content {
    padding-bottom: calc(112px + env(safe-area-inset-bottom)) !important;
    scroll-padding-bottom: calc(112px + env(safe-area-inset-bottom)) !important;
  }

  #mobile-tree-content .tree-shell,
  #mobile-tree-content .tree-groups,
  #mobile-tree-content .tree-category:last-child,
  #mobile-tree-content .tree-card:last-child {
    margin-bottom: calc(1.5rem + env(safe-area-inset-bottom)) !important;
  }

  #mobile-tree {
    padding-bottom: calc(72px + env(safe-area-inset-bottom)) !important;
  }
}

/* ================================================================
   v27: actually match desktop Theme save height and trim mobile Tree clearance.
   ================================================================ */
@media (min-width: 1101px) {
  .theme-picker-dialog #theme-customize-body .tb-actions {
    display: block !important;
    width: 100% !important;
    padding: 0.55rem 0 0.65rem !important;
    margin: 0 !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-actions #tb-save,
  .theme-picker-dialog #theme-customize-body .tb-actions .button {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 0 !important;
    height: 44px !important;
    padding-block: 0 !important;
    border-radius: 12px !important;
    line-height: 1 !important;
  }
}

@media (max-width: 1100px) {
  #mobile-tree-content {
    padding-bottom: calc(76px + env(safe-area-inset-bottom)) !important;
    scroll-padding-bottom: calc(76px + env(safe-area-inset-bottom)) !important;
  }

  #mobile-tree-content .tree-shell,
  #mobile-tree-content .tree-groups,
  #mobile-tree-content .tree-category:last-child,
  #mobile-tree-content .tree-card:last-child {
    margin-bottom: calc(0.45rem + env(safe-area-inset-bottom)) !important;
  }

  #mobile-tree {
    padding-bottom: calc(64px + env(safe-area-inset-bottom)) !important;
  }
}


/* v28 main: clean Topology card placeholders and action buttons. */
.card-live-status.hidden,
.card-actions.hidden,
.card-live-status:empty,
.card-actions:empty,
.card-desc:empty,
.card-notes:empty,
.card-ip:empty,
.card-app:empty,
.card-specs:empty,
.card-network:empty,
.card-hosting:empty,
.card-links:empty {
  display: none !important;
  margin: 0 !important;
  padding: 0 !important;
  border: 0 !important;
}

.card-actions:not(.hidden) {
  align-items: center;
}

.card-action-copy,
.card-action-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 0;
  min-height: 34px;
  height: auto;
  max-width: min(100%, 260px);
  padding: 0.42rem 0.68rem;
  border-radius: 10px;
  box-sizing: border-box;
  line-height: 1.15;
}

.card-action-copy {
  background: var(--panel);
}

.card-action-link {
  background: var(--yellow);
}

@media (max-width: 1100px) {
  .card.mobile-expanded .card-actions.hidden,
  .card.mobile-expanded .card-live-status.hidden,
  .card.mobile-expanded .card-live-status:empty,
  .card.mobile-expanded .card-actions:empty {
    display: none !important;
  }

  .card.mobile-expanded .card-actions:not(.hidden) {
    display: flex !important;
    gap: 0.5rem;
    margin: 0.45rem 0;
  }

  .card-action-copy,
  .card-action-link {
    min-height: 44px !important;
    padding: 0.55rem 0.75rem !important;
    border-width: 2px !important;
    border-radius: 12px !important;
    font-size: 0.86rem !important;
    white-space: nowrap;
  }
}


/* ── Agent API Access ───────────────────────────────────────────────────── */
.agent-api-panel {
  margin-top: 1rem;
  padding: 0.85rem;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--panel) 92%, var(--bg));
}
.agent-api-panel h3,
.agent-api-panel h4 { margin: 0 0 0.45rem; }
.agent-key-form { display: grid; gap: 0.65rem; margin-top: 0.75rem; }
.agent-key-form label { display: grid; gap: 0.35rem; font-weight: 700; }
.agent-scope-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(145px, 1fr));
  gap: 0.45rem;
}
.agent-scope-option {
  min-height: 44px;
  display: flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.45rem 0.55rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
  font: 700 0.72rem/1.2 'Space Mono', monospace;
}
.agent-scope-option input { width: 18px; height: 18px; }
.agent-token-box {
  margin-top: 0.75rem;
  padding: 0.75rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--info);
  overflow-wrap: anywhere;
  font: 700 0.76rem/1.45 'Space Mono', monospace;
}
.agent-token-copy-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto auto;
  gap: 0.5rem;
  align-items: center;
  margin-top: 0.55rem;
}
.agent-token-copy-row input {
  min-width: 0;
  font: 700 0.72rem/1.2 'Space Mono', monospace;
}
.agent-key-form select {
  min-height: 44px;
  width: 100%;
}
.agent-key-list { display: grid; gap: 0.5rem; margin-top: 0.75rem; }
.agent-key-card {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.65rem;
  align-items: center;
  padding: 0.65rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--card);
}
.agent-key-card strong { display:block; overflow-wrap:anywhere; }
.agent-key-meta { color: var(--muted); font-size: 0.72rem; line-height: 1.35; }
.agent-key-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; justify-content: flex-end; }
.agent-key-actions .button { min-height: 38px; padding: 0.35rem 0.55rem; }
@media (max-width: 1100px) {
  .agent-api-panel { padding: 0.75rem; }
  .agent-scope-grid { grid-template-columns: 1fr 1fr; }
  .agent-key-card { grid-template-columns: 1fr; }
  .agent-key-actions { justify-content: stretch; }
  .agent-key-actions .button { flex: 1; min-height: 44px; }
}
@media (max-width: 520px) {
  .agent-scope-grid { grid-template-columns: 1fr; }
  .agent-token-copy-row { grid-template-columns: 1fr; }
}


/* v30/v38: Agent API Access uses its own dialog so Config stays compact. */
.agent-api-dialog {
  width: min(1280px, calc(100vw - 96px));
  height: min(760px, calc(100dvh - 96px));
  max-width: calc(100vw - 96px);
  max-height: calc(100dvh - 96px);
}
.agent-api-dialog .agent-dialog-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding-right: 0.15rem;
  overscroll-behavior: contain;
}
.agent-api-dialog .agent-api-panel {
  margin-top: 0;
}
#agent-api-btn {
  margin-top: 0;
}
@media (min-width: 1101px) {
  .agent-api-dialog .tree-head {
    margin-bottom: 0.8rem;
  }
  .agent-api-dialog .agent-dialog-body {
    padding-right: 0.2rem;
  }
}

@media (max-width: 1100px) {
  .agent-api-dialog {
    height: 100dvh !important;
  }
  .agent-api-dialog .agent-dialog-body {
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }
}

/* v36: desktop Config menu matches the grouped two-column action layout. */
@media (min-width: 1101px) {
  #config-dialog.tree-dialog[open] {
    width: min(1280px, calc(100vw - 96px)) !important;
    height: min(760px, calc(100dvh - 96px)) !important;
    max-width: calc(100vw - 96px) !important;
    max-height: calc(100dvh - 96px) !important;
    padding: 1.65rem 1.9rem !important;
  }

  #config-dialog .tree-head {
    margin-bottom: 1.15rem !important;
  }

  #config-dialog .config-menu-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1.05rem;
    flex: 0 0 auto;
    width: 100%;
  }

  #config-dialog .config-intro,
  #config-dialog .config-section-title,
  #config-dialog .config-menu-grid > .button,
  #config-dialog .config-menu-row > .button,
  #config-dialog .config-menu-row > .file-label {
    min-height: 52px;
    border-radius: 14px;
  }

  #config-dialog .config-intro {
    display: flex;
    align-items: center;
    margin: 0 !important;
    padding: 0 1.1rem !important;
  }

  #config-dialog .config-menu-row {
    display: grid;
    gap: 1.35rem;
    width: 100%;
  }

  #config-dialog .config-menu-row-two {
    grid-template-columns: 1fr 1fr;
  }

  #config-dialog .config-section-title {
    display: flex;
    align-items: center;
    padding: 0 1.1rem;
    margin-top: 1.2rem;
    border: 3px solid var(--line);
    background: var(--blue);
    font-weight: 800;
  }

  #config-dialog .config-wide-action {
    width: 100%;
  }

  #config-dialog .config-menu-grid .button,
  #config-dialog .config-menu-grid .file-label {
    width: 100%;
    justify-content: center;
  }

  #config-dialog .stack,
  #config-dialog .config-content,
  #config-dialog .legend {
    display: none !important;
  }

  #config-dialog .dialog-footer {
    border-top: 2px solid var(--border);
    padding-top: 0.9rem;
    margin-top: auto !important;
  }

  #config-dialog .dialog-footer .button {
    min-height: 52px;
    width: 100%;
  }
}


/* v38/v46: keep desktop Config compact and consistent with Themes/API Keys. */
@media (min-width: 1101px) {
  #config-dialog.tree-dialog[open] {
    width: min(1180px, calc(100vw - 128px)) !important;
    height: min(680px, calc(100dvh - 128px)) !important;
    max-width: calc(100vw - 128px) !important;
    max-height: calc(100dvh - 128px) !important;
    padding: 1rem 1.15rem !important;
  }

  #config-dialog .tree-head {
    margin-bottom: 0.9rem !important;
  }

  #config-dialog .config-menu-grid {
    gap: 0.75rem !important;
  }

  #config-dialog .config-menu-row {
    gap: 0.9rem !important;
  }

  #config-dialog .config-intro,
  #config-dialog .config-section-title {
    min-height: 42px !important;
    border-radius: 12px !important;
    padding: 0 0.85rem !important;
  }

  #config-dialog .config-menu-grid > .button,
  #config-dialog .config-menu-row > .button,
  #config-dialog .config-menu-row > .file-label,
  #config-dialog .dialog-footer .button {
    min-height: 36px !important;
    height: auto !important;
    border-radius: 12px !important;
    padding: 0.42rem 0.75rem !important;
  }

  #config-dialog .config-section-title {
    margin-top: 0.7rem !important;
    border: 2px solid var(--line) !important;
    background: var(--blue) !important;
  }

  #config-dialog .dialog-footer {
    padding-top: 0.7rem !important;
  }
}


/* Mobile Config uses the same calm grouped layout as the desktop Config dialog. */
@media (max-width: 1100px) {
  #mobile-config .mobile-view-body {
    padding: 1.1rem 1rem calc(6.5rem + env(safe-area-inset-bottom));
  }

  #mobile-config .config-menu-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.95rem;
    width: 100%;
  }

  #mobile-config .config-intro,
  #mobile-config .config-section-title {
    display: flex;
    align-items: center;
    min-height: 56px;
    margin: 0;
    padding: 0.85rem 1rem;
    border: 3px solid var(--line);
    border-radius: 16px;
    background: var(--blue);
  }

  #mobile-config .config-section-title {
    margin-top: 0.9rem;
    font-weight: 800;
  }

  #mobile-config .config-menu-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.85rem;
    width: 100%;
  }

  #mobile-config .config-menu-row-two {
    grid-template-columns: 1fr;
  }

  #mobile-config .button,
  #mobile-config .file-label {
    width: 100%;
    min-height: 56px;
    justify-content: center;
    border-radius: 16px;
  }
}

@media (min-width: 720px) and (max-width: 1100px) {
  #mobile-config .config-menu-row-two {
    grid-template-columns: 1fr 1fr;
  }
}

/* In the mobile API Keys page the header belongs to the mobile shell only. */
@media (max-width: 1100px) {
  #mobile-agent-api .tree-head,
  #mobile-agent-api .dialog-footer {
    display: none !important;
  }

  #mobile-agent-api .agent-api-panel {
    padding: 0;
    border: 0;
  }
}



/* v45: mobile Agent API should not sit on an extra panel background.
   Desktop customize tab gets a balanced grouped layout. */
@media (max-width: 1100px) {
  #mobile-agent-api .agent-api-panel {
    margin-top: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
  }
}

.theme-picker-dialog #theme-customize-body.theme-builder-body {
  display: block;
  min-height: 0;
  height: auto;
}

.theme-picker-dialog #theme-customize-body .tb-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 1rem;
  min-height: 0;
}

.theme-picker-dialog #theme-customize-body .tb-name-row {
  display: grid;
  grid-template-columns: 120px minmax(280px, 520px);
  align-items: center;
  gap: 0.8rem;
  margin: 0;
  padding: 0;
  background: transparent;
  border: 0;
}

.theme-picker-dialog #theme-customize-body .tb-name-row > span {
  font: 700 0.88rem/1.2 'Space Mono', monospace;
  color: var(--text);
}

.theme-picker-dialog #theme-customize-body .tb-name-row input[type='text'],
.theme-picker-dialog #theme-customize-body #tb-name {
  width: 100%;
  min-width: 0;
  min-height: 42px;
  height: 42px;
  padding: 0.55rem 0.8rem;
  border-radius: 12px;
  font: 700 0.86rem/1.2 'Space Mono', monospace;
}

.theme-picker-dialog #theme-customize-body .tb-section-grid {
  display: grid;
  grid-template-columns: minmax(0, 2.1fr) minmax(280px, 1fr);
  gap: 1rem;
  align-items: start;
}

.theme-picker-dialog #theme-customize-body .tb-section {
  display: flex;
  flex-direction: column;
  gap: 0.9rem;
  padding: 1rem;
  border: 2px solid var(--line);
  border-radius: 16px;
  background: var(--panel);
}

.theme-picker-dialog #theme-customize-body .tb-section-title {
  padding-bottom: 0.65rem;
  border-bottom: 2px solid color-mix(in srgb, var(--line) 18%, transparent);
  font: 900 1rem/1.2 'Space Mono', monospace;
  color: var(--text);
}

.theme-picker-dialog #theme-customize-body .tb-section-core .tb-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
}

.theme-picker-dialog #theme-customize-body .tb-section-types .tb-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.75rem;
}

.theme-picker-dialog #theme-customize-body .tb-color-row {
  display: grid;
  grid-template-columns: 56px minmax(0, 1fr);
  align-items: center;
  gap: 0.75rem;
  min-height: 64px;
  margin: 0;
  padding: 0.7rem 0.8rem;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--card) 92%, var(--panel));
  font: 700 0.82rem/1.25 'Space Mono', monospace;
  color: var(--muted);
}

.theme-picker-dialog #theme-customize-body .tb-color-row input[type='color'] {
  width: 56px;
  height: 42px;
  padding: 3px;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--panel);
  cursor: pointer;
}

.theme-picker-dialog #theme-customize-body .tb-color-row span {
  min-width: 0;
  line-height: 1.25;
}

.theme-picker-dialog #theme-customize-body .tb-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 0.1rem;
  padding: 0;
}

.theme-picker-dialog #theme-customize-body .tb-actions #tb-save,
.theme-picker-dialog #theme-customize-body .tb-actions .button {
  width: auto;
  min-width: 200px;
  min-height: 42px;
  height: 42px;
  padding: 0.55rem 1rem;
  border-radius: 12px;
  font-size: 0.86rem;
}

@media (max-width: 1400px) {
  .theme-picker-dialog #theme-customize-body .tb-section-grid {
    grid-template-columns: minmax(0, 1.7fr) minmax(260px, 1fr);
  }
}

@media (max-width: 1100px) {
  .theme-picker-dialog #theme-customize-body .tb-name-row {
    grid-template-columns: 1fr;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-grid {
    grid-template-columns: 1fr;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-core .tb-grid,
  .theme-picker-dialog #theme-customize-body .tb-section-types .tb-grid {
    grid-template-columns: 1fr;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row {
    min-height: 72px;
    grid-template-columns: 60px minmax(0, 1fr);
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row input[type='color'] {
    width: 60px;
    height: 46px;
  }

  .theme-picker-dialog #theme-customize-body .tb-actions .button,
  .theme-picker-dialog #theme-customize-body .tb-actions #tb-save {
    width: 100%;
    min-width: 0;
    min-height: 52px;
    height: auto;
  }
}


/* v46: desktop theme customizer matches the compact demo layout.
   Desktop uses grouped sections with simple color rows; mobile keeps large tap targets. */
@media (min-width: 1101px) {
  .theme-picker-dialog #theme-customize-body.theme-builder-body {
    padding-top: 0 !important;
    overflow-y: auto !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-layout {
    gap: 1.05rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-name-row {
    grid-template-columns: 112px minmax(320px, 520px) !important;
    align-items: center !important;
    gap: 0.85rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-name-row input[type='text'],
  .theme-picker-dialog #theme-customize-body #tb-name {
    height: 38px !important;
    min-height: 38px !important;
    padding: 0.45rem 0.75rem !important;
    border-radius: 10px !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-grid {
    display: grid !important;
    grid-template-columns: minmax(660px, 2.35fr) minmax(330px, 1fr) !important;
    gap: 1rem !important;
    align-items: start !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section {
    gap: 0.8rem !important;
    padding: 1rem 1.05rem !important;
    border: 2px solid var(--line) !important;
    border-radius: 16px !important;
    background: color-mix(in srgb, var(--panel) 82%, var(--phone)) !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-title {
    padding-bottom: 0.65rem !important;
    margin-bottom: 0.15rem !important;
    border-bottom: 2px solid color-mix(in srgb, var(--line) 16%, transparent) !important;
    font-size: 0.98rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-core .tb-grid {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(128px, 1fr)) !important;
    gap: 0.78rem 1rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-types .tb-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(120px, 1fr)) !important;
    gap: 0.78rem 1rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row {
    display: grid !important;
    grid-template-columns: 46px minmax(0, 1fr) !important;
    align-items: center !important;
    gap: 0.58rem !important;
    min-height: 42px !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    font-size: 0.78rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row input[type='color'] {
    width: 46px !important;
    height: 32px !important;
    min-width: 46px !important;
    min-height: 32px !important;
    padding: 3px !important;
    border: 2px solid var(--line) !important;
    border-radius: 8px !important;
    background: var(--panel) !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row span {
    font-size: 0.76rem !important;
    line-height: 1.15 !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-actions {
    display: flex !important;
    justify-content: flex-end !important;
    margin-top: 0.35rem !important;
    padding: 0 !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-actions #tb-save,
  .theme-picker-dialog #theme-customize-body .tb-actions .button {
    width: auto !important;
    min-width: 220px !important;
    height: 40px !important;
    min-height: 40px !important;
    padding: 0.5rem 1.1rem !important;
    border-radius: 12px !important;
    font-size: 0.84rem !important;
  }
}

@media (min-width: 1101px) and (max-width: 1450px) {
  .theme-picker-dialog #theme-customize-body .tb-section-grid {
    grid-template-columns: minmax(560px, 1.9fr) minmax(300px, 1fr) !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-core .tb-grid {
    grid-template-columns: repeat(3, minmax(130px, 1fr)) !important;
  }
}


/* v47: force desktop Theme Customize to use the compact grouped demo layout.
   This sits last on purpose so the live/main build matches the demo build exactly. */
@media (min-width: 1101px) {
  .theme-picker-dialog #theme-customize-body.theme-builder-body {
    display: block !important;
    min-height: 0 !important;
    height: auto !important;
    overflow-y: auto !important;
    padding-top: 0 !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-layout {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 1rem !important;
    min-height: 0 !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-name-row,
  .theme-picker-dialog #theme-customize-body .tb-base-row.tb-name-row {
    display: grid !important;
    grid-template-columns: 120px minmax(280px, 520px) !important;
    align-items: center !important;
    gap: 0.8rem !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-name-row > span,
  .theme-picker-dialog #theme-customize-body .tb-base-row.tb-name-row > span {
    font: 700 0.88rem/1.2 'Space Mono', monospace !important;
    color: var(--text) !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-name-row input[type='text'],
  .theme-picker-dialog #theme-customize-body #tb-name {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 42px !important;
    height: 42px !important;
    padding: 0.55rem 0.8rem !important;
    border-radius: 12px !important;
    font: 700 0.86rem/1.2 'Space Mono', monospace !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-grid {
    display: grid !important;
    grid-template-columns: minmax(0, 2.1fr) minmax(280px, 1fr) !important;
    gap: 1rem !important;
    align-items: start !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.9rem !important;
    padding: 1rem !important;
    border: 2px solid var(--line) !important;
    border-radius: 16px !important;
    background: var(--panel) !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-title {
    padding-bottom: 0.65rem !important;
    border-bottom: 2px solid color-mix(in srgb, var(--line) 18%, transparent) !important;
    font: 900 1rem/1.2 'Space Mono', monospace !important;
    color: var(--text) !important;
    margin-bottom: 0 !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-core .tb-grid {
    display: grid !important;
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
    gap: 0.75rem 1rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-types .tb-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.75rem 1rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row {
    display: grid !important;
    grid-template-columns: 46px minmax(0, 1fr) !important;
    align-items: center !important;
    gap: 0.58rem !important;
    min-height: 42px !important;
    height: auto !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    font: 700 0.78rem/1.15 'Space Mono', monospace !important;
    color: var(--muted) !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row input[type='color'] {
    width: 46px !important;
    height: 32px !important;
    min-width: 46px !important;
    min-height: 32px !important;
    padding: 3px !important;
    border: 2px solid var(--line) !important;
    border-radius: 8px !important;
    background: var(--panel) !important;
    cursor: pointer !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row span {
    min-width: 0 !important;
    font-size: 0.76rem !important;
    line-height: 1.15 !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-actions {
    display: flex !important;
    justify-content: flex-end !important;
    margin-top: 0.35rem !important;
    padding: 0 !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-actions #tb-save,
  .theme-picker-dialog #theme-customize-body .tb-actions .button {
    width: auto !important;
    min-width: 220px !important;
    max-width: none !important;
    min-height: 40px !important;
    height: 40px !important;
    padding: 0.5rem 1.1rem !important;
    border-radius: 12px !important;
    font-size: 0.84rem !important;
  }
}

@media (min-width: 1101px) and (max-width: 1450px) {
  .theme-picker-dialog #theme-customize-body .tb-section-grid {
    grid-template-columns: minmax(0, 1.9fr) minmax(300px, 1fr) !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-core .tb-grid {
    grid-template-columns: repeat(3, minmax(130px, 1fr)) !important;
  }
}

/* v48: redesign Theme Customize color picker layout with filled circles and helpful descriptions. */
.theme-picker-dialog #theme-customize-body .tb-section-intro,
#mobile-theme-body #theme-customize-body .tb-section-intro {
  margin: -0.2rem 0 0.15rem !important;
  color: var(--muted) !important;
  font: 600 0.74rem/1.45 'Inter', system-ui, sans-serif !important;
}

.theme-picker-dialog #theme-customize-body .tb-color-copy,
#mobile-theme-body #theme-customize-body .tb-color-copy {
  min-width: 0 !important;
  display: flex !important;
  flex-direction: column !important;
  gap: 0.14rem !important;
}

.theme-picker-dialog #theme-customize-body .tb-color-label,
#mobile-theme-body #theme-customize-body .tb-color-label {
  display: block !important;
  color: var(--text) !important;
  font: 700 0.8rem/1.15 'Space Mono', monospace !important;
}

.theme-picker-dialog #theme-customize-body .tb-color-desc,
#mobile-theme-body #theme-customize-body .tb-color-desc {
  display: block !important;
  color: var(--muted) !important;
  font: 500 0.72rem/1.35 'Inter', system-ui, sans-serif !important;
}

.theme-picker-dialog #theme-customize-body .tb-color-row input[type='color'],
#mobile-theme-body #theme-customize-body .tb-color-row input[type='color'] {
  appearance: none !important;
  -webkit-appearance: none !important;
  border-radius: 999px !important;
  overflow: hidden !important;
  cursor: pointer !important;
}

.theme-picker-dialog #theme-customize-body .tb-color-row input[type='color']::-webkit-color-swatch-wrapper,
#mobile-theme-body #theme-customize-body .tb-color-row input[type='color']::-webkit-color-swatch-wrapper {
  padding: 0 !important;
}

.theme-picker-dialog #theme-customize-body .tb-color-row input[type='color']::-webkit-color-swatch,
#mobile-theme-body #theme-customize-body .tb-color-row input[type='color']::-webkit-color-swatch {
  border: 0 !important;
  border-radius: 999px !important;
}

.theme-picker-dialog #theme-customize-body .tb-color-row input[type='color']::-moz-color-swatch,
#mobile-theme-body #theme-customize-body .tb-color-row input[type='color']::-moz-color-swatch {
  border: 0 !important;
  border-radius: 999px !important;
}

@media (min-width: 1101px) {
  .theme-picker-dialog #theme-customize-body.theme-builder-body {
    display: block !important;
    min-height: 0 !important;
    height: auto !important;
    overflow-y: auto !important;
    padding-top: 0 !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-layout {
    display: grid !important;
    grid-template-columns: minmax(0, 1fr) !important;
    gap: 1rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-name-row,
  .theme-picker-dialog #theme-customize-body .tb-base-row.tb-name-row {
    display: grid !important;
    grid-template-columns: 120px minmax(340px, 640px) !important;
    align-items: center !important;
    gap: 1rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-name-row input[type='text'],
  .theme-picker-dialog #theme-customize-body #tb-name {
    min-height: 46px !important;
    height: 46px !important;
    border-radius: 14px !important;
    padding: 0.65rem 0.9rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-grid {
    display: grid !important;
    grid-template-columns: minmax(0, 2.15fr) minmax(320px, 0.95fr) !important;
    gap: 1rem !important;
    align-items: start !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section {
    gap: 0.95rem !important;
    padding: 1.15rem !important;
    border-radius: 18px !important;
    background: color-mix(in srgb, var(--panel) 92%, white) !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-title {
    padding-bottom: 0.75rem !important;
    margin-bottom: 0 !important;
    font: 900 0.98rem/1.2 'Space Mono', monospace !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-core .tb-grid {
    display: grid !important;
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.85rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-types .tb-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.85rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row {
    display: grid !important;
    grid-template-columns: 56px minmax(0, 1fr) !important;
    align-items: center !important;
    gap: 0.8rem !important;
    min-height: 78px !important;
    padding: 0.9rem 0.95rem !important;
    border: 2px solid color-mix(in srgb, var(--line) 80%, transparent) !important;
    border-radius: 16px !important;
    background: color-mix(in srgb, var(--phone) 86%, white) !important;
    box-shadow: none !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row input[type='color'] {
    width: 56px !important;
    height: 56px !important;
    min-width: 56px !important;
    min-height: 56px !important;
    padding: 0 !important;
    border: 3px solid var(--line) !important;
    background: transparent !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-actions {
    display: flex !important;
    justify-content: flex-end !important;
    padding-top: 0.15rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-actions #tb-save,
  .theme-picker-dialog #theme-customize-body .tb-actions .button {
    min-width: 260px !important;
    height: 44px !important;
    min-height: 44px !important;
    border-radius: 14px !important;
  }
}

@media (min-width: 1101px) and (max-width: 1450px) {
  .theme-picker-dialog #theme-customize-body .tb-section-grid {
    grid-template-columns: minmax(0, 1.8fr) minmax(300px, 1fr) !important;
  }
}

@media (max-width: 1100px) {
  #mobile-theme-body #theme-customize-body.theme-builder-body {
    display: block !important;
    padding-top: 0 !important;
  }

  #mobile-theme-body #theme-customize-body .tb-layout {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.9rem !important;
  }

  #mobile-theme-body #theme-customize-body .tb-name-row,
  #mobile-theme-body #theme-customize-body .tb-base-row.tb-name-row {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.45rem !important;
    padding: 0 !important;
    border: 0 !important;
    background: transparent !important;
  }

  #mobile-theme-body #theme-customize-body .tb-name-row > span,
  #mobile-theme-body #theme-customize-body .tb-base-row.tb-name-row > span {
    color: var(--text) !important;
    font: 700 0.84rem/1.2 'Space Mono', monospace !important;
  }

  #mobile-theme-body #theme-customize-body #tb-name {
    width: 100% !important;
    min-height: 44px !important;
    height: 44px !important;
    padding: 0.55rem 0.8rem !important;
    border-radius: 14px !important;
  }

  #mobile-theme-body #theme-customize-body .tb-section-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.9rem !important;
  }

  #mobile-theme-body #theme-customize-body .tb-section {
    padding: 0.95rem !important;
    border: 2px solid var(--line) !important;
    border-radius: 18px !important;
    background: color-mix(in srgb, var(--panel) 92%, white) !important;
  }

  #mobile-theme-body #theme-customize-body .tb-section-title {
    margin-bottom: 0.35rem !important;
    padding-bottom: 0.6rem !important;
    border-bottom: 2px solid color-mix(in srgb, var(--line) 18%, transparent) !important;
  }

  #mobile-theme-body #theme-customize-body .tb-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.7rem !important;
  }

  #mobile-theme-body #theme-customize-body .tb-color-row {
    display: grid !important;
    grid-template-columns: 52px minmax(0, 1fr) !important;
    align-items: center !important;
    gap: 0.75rem !important;
    min-height: 70px !important;
    padding: 0.75rem 0.8rem !important;
    border: 2px solid color-mix(in srgb, var(--line) 80%, transparent) !important;
    border-radius: 16px !important;
    background: color-mix(in srgb, var(--phone) 90%, white) !important;
  }

  #mobile-theme-body #theme-customize-body .tb-color-row input[type='color'] {
    width: 52px !important;
    height: 52px !important;
    min-width: 52px !important;
    min-height: 52px !important;
    padding: 0 !important;
    border: 3px solid var(--line) !important;
    background: transparent !important;
  }

  #mobile-theme-body #theme-customize-body .tb-color-label {
    font-size: 0.82rem !important;
  }

  #mobile-theme-body #theme-customize-body .tb-color-desc,
  #mobile-theme-body #theme-customize-body .tb-section-intro {
    display: none !important;
  }

  #mobile-theme-body #theme-customize-body .tb-actions {
    display: flex !important;
    justify-content: stretch !important;
    padding-top: 0.2rem !important;
  }

  #mobile-theme-body #theme-customize-body .tb-actions #tb-save,
  #mobile-theme-body #theme-customize-body .tb-actions .button {
    width: 100% !important;
    min-width: 0 !important;
    min-height: 46px !important;
    height: 46px !important;
    border-radius: 14px !important;
  }
}

/* v49: progressive Add/Edit form with an Advanced Settings dialog. */
.advanced-resource-dialog {
  width: min(1280px, calc(100vw - 96px));
  height: min(760px, calc(100dvh - 96px));
  max-width: calc(100vw - 96px);
  max-height: calc(100dvh - 96px);
  border: 3px solid var(--line);
  border-radius: 18px;
  background: var(--phone);
  color: var(--text);
  padding: 0.95rem;
  margin: auto;
  overflow: hidden;
}

.advanced-resource-dialog[open] {
  display: flex;
  flex-direction: column;
}

.advanced-resource-dialog::backdrop {
  background: rgba(0, 0, 0, 0.45);
}

.advanced-resource-head {
  border-bottom: 2px solid var(--line);
  padding-bottom: 0.75rem;
  margin-bottom: 0.85rem;
}

.advanced-resource-subtitle {
  margin: 0.3rem 0 0;
  color: var(--muted);
  font: 600 0.78rem/1.4 'Inter', system-ui, sans-serif;
}

.advanced-resource-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 0.15rem 0.2rem 0.8rem 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.9rem;
  align-content: start;
}

.advanced-resource-body > label,
.advanced-resource-body > fieldset {
  margin: 0;
  min-width: 0;
}

.advanced-resource-body > fieldset {
  grid-column: 1 / -1;
}

.advanced-resource-body .nested-fields {
  grid-column: auto;
}

.advanced-resource-body select[multiple] {
  min-height: 132px;
}

.advanced-resource-footer {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
  padding-top: 0.85rem;
  border-top: 2px solid var(--line);
  margin-top: 0.7rem;
}

.advanced-resource-footer .button {
  width: 100%;
}

#advanced-settings-btn {
  background: var(--mint);
}

@media (max-width: 1100px) {
  .advanced-resource-dialog,
  dialog.advanced-resource-dialog[open] {
    width: 100vw;
    max-width: 100vw;
    height: 100dvh;
    max-height: 100dvh;
    margin: 0;
    border-radius: 0;
    border-left: 0;
    border-right: 0;
    padding: calc(env(safe-area-inset-top, 0px) + 0.8rem) 1rem calc(env(safe-area-inset-bottom, 0px) + 1rem);
  }

  .advanced-resource-dialog .sheet-handle {
    display: block;
  }

  .advanced-resource-head {
    grid-template-columns: 1fr;
    gap: 0.65rem;
  }

  .advanced-resource-head .button {
    display: none;
  }

  .advanced-resource-body {
    grid-template-columns: 1fr;
    gap: 0.85rem;
    padding-right: 0.15rem;
  }

  .advanced-resource-footer {
    grid-template-columns: 1fr;
    gap: 0.7rem;
  }
}

/* v50: Advanced Resource Settings polish and credentials UI. */
#advanced-resource-close-top {
  display: none !important;
}

#advanced-settings-btn {
  background: var(--mint) !important;
}

.mobile-section-toggle {
  display: none !important;
}

#resource-form .mobile-collapsed > :not(legend):not(.mobile-section-toggle) {
  display: revert !important;
}

@media (min-width: 1101px) {
  .advanced-resource-dialog,
  dialog.advanced-resource-dialog[open] {
    width: min(1180px, calc(100vw - 128px)) !important;
    height: min(680px, calc(100dvh - 128px)) !important;
    max-width: calc(100vw - 128px) !important;
    max-height: calc(100dvh - 128px) !important;
    padding: 1rem 1.15rem !important;
    border-radius: 18px !important;
  }

  .advanced-resource-head {
    display: block !important;
    margin-bottom: 0.9rem !important;
    padding-bottom: 0.7rem !important;
  }

  .advanced-resource-body {
    grid-template-columns: repeat(2, minmax(0, 1fr)) !important;
    gap: 0.75rem !important;
    padding-right: 0.35rem !important;
  }

  .advanced-resource-body > fieldset {
    padding: 0.8rem !important;
    border-radius: 14px !important;
  }

  .advanced-resource-footer {
    padding-top: 0.7rem !important;
    margin-top: 0.65rem !important;
  }

  .advanced-resource-footer .button {
    min-height: 36px !important;
    height: auto !important;
    border-radius: 12px !important;
    padding: 0.42rem 0.75rem !important;
  }
}

.credentials-fieldset {
  grid-column: 1 / -1 !important;
}

.advanced-section-note {
  margin: 0 0 0.7rem;
  color: var(--muted);
  font: 600 0.78rem/1.45 'Inter', system-ui, sans-serif;
}

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

.credential-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.45rem;
  align-items: center;
}

.credential-input-row:has(.credential-eye) {
  grid-template-columns: minmax(0, 1fr) auto auto;
}

.credential-input-row .button {
  min-height: 40px;
  white-space: nowrap;
}

.credential-eye {
  min-width: 48px;
  padding-inline: 0.55rem !important;
}

@media (max-width: 1100px) {
  .advanced-resource-dialog,
  dialog.advanced-resource-dialog[open] {
    width: 100vw !important;
    max-width: 100vw !important;
    height: 100dvh !important;
    max-height: 100dvh !important;
  }

  .advanced-resource-head .button {
    display: none !important;
  }

  .advanced-resource-body {
    grid-template-columns: 1fr !important;
  }

  .credential-grid {
    grid-template-columns: 1fr;
  }

  .credential-input-row,
  .credential-input-row:has(.credential-eye) {
    grid-template-columns: minmax(0, 1fr) auto !important;
  }

  .credential-input-row:has(.credential-eye) .credential-eye {
    grid-column: 2;
    grid-row: 1;
  }

  .credential-input-row:has(.credential-eye) [data-credential-copy] {
    grid-column: 1 / -1;
  }
}

/* v51: credentials polish, secret export modal and SVG eye icon. */
.credential-eye-svg {
  width: 20px;
  height: 20px;
  display: block;
  margin: 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.credential-eye {
  display: inline-grid !important;
  place-items: center !important;
}

.secret-key-modal {
  position: fixed;
  inset: 0;
  z-index: 99999;
  display: grid;
  place-items: center;
  padding: 1rem;
  background: rgba(20, 22, 24, 0.55);
  backdrop-filter: blur(2px);
}

.secret-key-card {
  width: min(640px, calc(100vw - 2rem));
  max-height: min(90dvh, 720px);
  overflow: auto;
  padding: 1.25rem;
  border: 3px solid var(--line);
  border-radius: 18px;
  background: var(--panel);
  color: var(--text);
  box-shadow: 0 20px 50px rgba(0,0,0,.22);
}

.secret-key-head h3 {
  margin: 0 0 0.45rem;
  font: 900 1.15rem/1.2 'Space Mono', monospace;
}

.secret-key-head p {
  margin: 0 0 1rem;
  color: var(--muted);
  font: 600 0.86rem/1.5 'Inter', system-ui, sans-serif;
}

.secret-key-row input {
  width: 100%;
  min-height: 48px;
  padding: 0.7rem 0.85rem;
  border: 3px solid var(--line);
  border-radius: 14px;
  background: var(--card);
  color: var(--text);
  font: 700 0.86rem/1.35 'Space Mono', monospace;
  overflow-wrap: anywhere;
}

.secret-key-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
  margin-top: 1rem;
}

@media (max-width: 640px) {
  .secret-key-card {
    padding: 1rem;
    border-radius: 16px;
  }

  .secret-key-actions {
    grid-template-columns: 1fr;
  }
}

/* v52: Credentials access flags and SSH/CLI window. */
.credential-access-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.75rem;
  margin: 0.75rem 0;
}

.credential-access-option {
  display: grid !important;
  grid-template-columns: auto minmax(0, 1fr);
  align-items: center;
  gap: 0.65rem;
  min-height: 58px;
  margin: 0 !important;
  padding: 0.65rem 0.75rem !important;
  border: 2px solid var(--line);
  border-radius: 14px;
  background: color-mix(in srgb, var(--panel) 92%, white);
}

.credential-access-option input[type='checkbox'] {
  width: 22px;
  height: 22px;
}

.credential-access-option strong,
.credential-access-option small {
  display: block;
}

.credential-access-option small {
  margin-top: 0.18rem;
  color: var(--muted);
  font: 600 0.72rem/1.25 'Inter', system-ui, sans-serif;
}

.card-action-cli {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  min-height: 34px;
  max-width: min(100%, 260px);
  padding: 0.42rem 0.68rem;
  border: 2px solid var(--line);
  border-radius: 10px;
  background: var(--mint);
  color: var(--text);
  cursor: pointer;
  font: 700 0.7rem/1.15 'Space Mono', monospace;
}

.cli-action-svg {
  width: 18px;
  height: 18px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2.2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.cli-dialog {
  width: min(1180px, calc(100vw - 128px));
  height: min(760px, calc(100dvh - 96px));
  max-width: calc(100vw - 96px);
  max-height: calc(100dvh - 96px);
  margin: auto;
  padding: 0;
  border: 3px solid var(--line);
  border-radius: 20px;
  background: var(--phone);
  color: var(--text);
  overflow: hidden;
}

.cli-dialog[open] {
  display: block;
}

.cli-dialog::backdrop {
  background: rgba(0, 0, 0, 0.55);
}

.cli-shell {
  height: 100%;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto auto;
  gap: 0.8rem;
  padding: 1rem;
}

.cli-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding-bottom: 0.75rem;
  border-bottom: 2px solid var(--line);
}

.cli-head h3 {
  margin: 0;
  font: 900 1.05rem/1.2 'Space Mono', monospace;
}

.cli-subtitle {
  margin: 0.25rem 0 0;
  color: var(--muted);
  font: 700 0.75rem/1.25 'Space Mono', monospace;
}

.cli-terminal {
  min-height: 0;
  overflow: auto;
  white-space: pre-wrap;
  word-break: break-word;
  user-select: text;
  -webkit-user-select: text;
  background: #05070a;
  color: #d4f7d4;
  border: 3px solid var(--line);
  border-radius: 16px;
  padding: 1rem;
  font: 700 0.82rem/1.5 'Space Mono', ui-monospace, monospace;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.04);
}

.cli-terminal::selection,
.cli-terminal *::selection {
  background: #f4d371;
  color: #05070a;
}

.cli-system-link {
  display: inline-block;
  margin-top: 0.7rem;
  color: #9eff9e;
  text-decoration: underline;
}

.cli-input-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.7rem;
}

.cli-input-row textarea {
  background: #05070a !important;
  color: #d4f7d4 !important;
  border-color: var(--line) !important;
  font-family: 'Space Mono', ui-monospace, monospace !important;
  min-height: 44px !important;
  max-height: 120px;
  resize: vertical;
  line-height: 1.35;
  overflow-y: auto;
}

.cli-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.7rem;
  padding-top: 0.75rem;
  border-top: 2px solid var(--line);
}

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

  .card-action-cli {
    min-height: 46px !important;
    height: 46px !important;
    border-radius: 14px !important;
    font-size: 0.86rem !important;
  }

  #mobile-cli {
    padding-top: 0 !important;
  }

  #mobile-cli.active {
    display: flex !important;
  }

  #mobile-cli .mobile-view-body,
  .mobile-cli-body {
    padding: 0 0 calc(76px + env(safe-area-inset-bottom)) 0 !important;
    height: 100dvh !important;
    overflow: hidden !important;
  }

  .mobile-cli-shell {
    height: calc(100dvh - 76px - env(safe-area-inset-bottom));
    padding: max(0.75rem, env(safe-area-inset-top)) 0.75rem 0.75rem;
    border-radius: 0;
  }

  .mobile-cli-head {
    padding-bottom: 0.55rem;
  }

  .cli-terminal {
    border-radius: 14px;
    padding: 0.85rem;
    font-size: 0.78rem;
  }

  .cli-input-row {
    grid-template-columns: 1fr;
    gap: 0.55rem;
  }

  .cli-footer {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
  }

  .mobile-cli-shell .cli-input-row textarea {
    max-height: 150px;
    resize: none;
  }

  .cli-footer #mobile-cli-close {
    grid-column: 1 / -1;
  }
}


/* v54: Secret export/import key popup must use the browser dialog top layer,
   otherwise it can appear behind Config/Themes dialogs. */
.secret-key-modal {
  width: 100vw !important;
  height: 100dvh !important;
  max-width: none !important;
  max-height: none !important;
  margin: 0 !important;
  border: 0 !important;
  padding: 1rem !important;
  background: rgba(20, 22, 24, 0.55) !important;
  color: var(--text) !important;
}

.secret-key-modal::backdrop {
  background: rgba(20, 22, 24, 0.55);
  backdrop-filter: blur(2px);
}

.secret-key-modal[open] {
  display: grid !important;
  place-items: center !important;
}

/* v55: Mobile Advanced Settings is a full mobile page, not a modal popup. */
@media (max-width: 1100px) {
  .advanced-resource-dialog.mobile-page-open,
  dialog.advanced-resource-dialog.mobile-page-open[open] {
    display: flex !important;
    position: fixed !important;
    inset: 0 0 calc(74px + max(0.5rem, env(safe-area-inset-bottom))) 0 !important;
    width: 100vw !important;
    max-width: 100vw !important;
    height: auto !important;
    max-height: none !important;
    margin: 0 !important;
    padding: 0 !important;
    border: 0 !important;
    border-radius: 0 !important;
    background: var(--phone) !important;
    color: var(--text) !important;
    flex-direction: column !important;
    overflow: hidden !important;
    z-index: 110 !important;
    box-shadow: none !important;
    transform: none !important;
  }

  .advanced-resource-dialog.mobile-page-open::backdrop {
    display: none !important;
    background: transparent !important;
  }

  .advanced-resource-dialog.mobile-page-open .sheet-handle {
    display: none !important;
  }

  .advanced-resource-dialog.mobile-page-open .advanced-resource-head {
    flex: 0 0 auto !important;
    display: flex !important;
    align-items: center !important;
    justify-content: space-between !important;
    gap: 0.75rem !important;
    min-height: 92px !important;
    padding: calc(env(safe-area-inset-top, 0px) + 1rem) max(1rem, env(safe-area-inset-right)) 0.85rem max(1rem, env(safe-area-inset-left)) !important;
    margin: 0 !important;
    border-bottom: 3px solid var(--line) !important;
    background: var(--phone) !important;
  }

  .advanced-resource-dialog.mobile-page-open .advanced-resource-head h3 {
    margin: 0 !important;
    font: 900 1.15rem/1.2 'Space Mono', monospace !important;
    color: var(--text) !important;
  }

  .advanced-resource-dialog.mobile-page-open .advanced-resource-subtitle {
    margin: 0.35rem 0 0 !important;
    color: var(--muted) !important;
    font-size: 0.78rem !important;
    line-height: 1.35 !important;
  }

  .advanced-resource-dialog.mobile-page-open .advanced-resource-body {
    flex: 1 1 auto !important;
    min-height: 0 !important;
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 0.85rem !important;
    padding: 1rem max(1rem, env(safe-area-inset-right)) 1rem max(1rem, env(safe-area-inset-left)) !important;
    overflow-y: auto !important;
    -webkit-overflow-scrolling: touch !important;
    overscroll-behavior: contain !important;
    background: var(--phone) !important;
  }

  .advanced-resource-dialog.mobile-page-open .advanced-resource-footer {
    flex: 0 0 auto !important;
    display: grid !important;
    grid-template-columns: 1fr 1fr !important;
    gap: 0.7rem !important;
    margin: 0 !important;
    padding: 0.75rem max(1rem, env(safe-area-inset-right)) 0.85rem max(1rem, env(safe-area-inset-left)) !important;
    border-top: 3px solid var(--line) !important;
    background: var(--phone) !important;
  }

  .advanced-resource-dialog.mobile-page-open .advanced-resource-footer .button {
    width: 100% !important;
    min-height: 48px !important;
    height: auto !important;
    border-radius: 14px !important;
    padding: 0.6rem 0.75rem !important;
  }

  .advanced-resource-dialog.mobile-page-open .advanced-resource-body > label,
  .advanced-resource-dialog.mobile-page-open .advanced-resource-body > fieldset {
    width: 100% !important;
  }

  body:has(.advanced-resource-dialog.mobile-page-open) .bottom-nav {
    z-index: 120 !important;
  }
}


/* v57: CLI text selection copies automatically; Ctrl+C action button was removed. */
.cli-terminal {
  cursor: text;
}

.cli-footer {
  gap: 0.75rem;
}

/* v58: keep toast notifications above every overlay and tighten mobile advanced footer spacing. */
.toast {
  z-index: 2147483647 !important;
  top: max(14px, calc(env(safe-area-inset-top, 0px) + 10px)) !important;
}

.toast.show {
  pointer-events: none !important;
}

@media (max-width: 1100px) {
  .advanced-resource-dialog.mobile-page-open,
  dialog.advanced-resource-dialog.mobile-page-open[open] {
    inset: 0 0 calc(62px + env(safe-area-inset-bottom, 0px)) 0 !important;
  }

  .advanced-resource-dialog.mobile-page-open .advanced-resource-footer {
    padding: 0.55rem max(1rem, env(safe-area-inset-right)) 0.45rem max(1rem, env(safe-area-inset-left)) !important;
    gap: 0.55rem !important;
  }

  .advanced-resource-dialog.mobile-page-open .advanced-resource-footer .button {
    min-height: 46px !important;
    padding: 0.5rem 0.7rem !important;
  }
}


/* v59: keep CLI output readable and align mobile rack side heights by rack units. */
.cli-terminal,
.cli-terminal *,
.mobile-cli-shell .cli-terminal,
.mobile-cli-shell .cli-terminal * {
  color: #ffffff !important;
}

.cli-input-row input,
.mobile-cli-shell .cli-input-row textarea {
  color: #ffffff !important;
  caret-color: #ffffff !important;
}

@media (max-width: 1100px) {
  .rack-slot.occupied {
    min-height: calc(44px * var(--rack-slot-u, 1)) !important;
  }
}

/* v60: restore mobile advanced footer spacing to match the Edit Resource action area. */
@media (max-width: 1100px) {
  .advanced-resource-dialog.mobile-page-open,
  dialog.advanced-resource-dialog.mobile-page-open[open] {
    inset: 0 0 calc(74px + max(0.5rem, env(safe-area-inset-bottom, 0px))) 0 !important;
  }

  .advanced-resource-dialog.mobile-page-open .advanced-resource-footer {
    padding: 0.7rem max(1rem, env(safe-area-inset-right)) 0.75rem max(1rem, env(safe-area-inset-left)) !important;
    gap: 0.65rem !important;
  }

  .advanced-resource-dialog.mobile-page-open .advanced-resource-footer .button {
    min-height: 48px !important;
    padding: 0.6rem 0.75rem !important;
  }
}

/* v61: place toast messages in the browser top layer, above active dialogs. */
.toast[popover] {
  position: fixed !important;
  inset: unset !important;
  top: max(14px, calc(env(safe-area-inset-top, 0px) + 10px)) !important;
  left: 50% !important;
  right: auto !important;
  bottom: auto !important;
  width: max-content !important;
  max-width: min(90vw, 520px) !important;
  margin: 0 !important;
  transform: translate(-50%, -20px) !important;
  opacity: 0 !important;
  pointer-events: none !important;
  z-index: 2147483647 !important;
}

.toast[popover]::backdrop {
  display: none !important;
  background: transparent !important;
}

.toast[popover].show {
  opacity: 1 !important;
  transform: translate(-50%, 0) !important;
  transition: transform 170ms ease, opacity 170ms ease !important;
}
  }

  #mobile-tree {
    padding-bottom: calc(64px + env(safe-area-inset-bottom)) !important;
  }
}


/* Demo site banner and browser-only demo shell */
.demo-banner {
  width: 100%;
  padding: 0.55rem 1rem;
  border-bottom: 3px solid var(--line);
  background: var(--yellow) !important;
  color: #222 !important;
  text-align: center;
  font: 800 0.82rem/1.35 'Space Mono', monospace;
  position: relative;
  z-index: 1000;
}
.demo-banner a {
  color: #222 !important;
  text-decoration: underline;
  text-underline-offset: 3px;
}

.demo-banner-track {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2.75rem;
  max-width: 100%;
  min-width: 0;
  white-space: nowrap;
  will-change: transform;
}
.demo-banner-message {
  display: inline-flex;
  align-items: center;
  gap: 0.25rem;
  flex: 0 0 auto;
  white-space: nowrap;
}
.demo-banner-message-clone {
  display: none;
}
.demo-banner.is-scrolling {
  justify-content: flex-start !important;
}
.demo-banner.is-scrolling .demo-banner-track {
  max-width: none;
  animation: demo-banner-marquee var(--demo-marquee-duration, 14s) linear infinite;
}
.demo-banner.is-scrolling .demo-banner-message-clone {
  display: inline-flex;
}
.demo-banner.is-scrolling:hover .demo-banner-track,
.demo-banner.is-scrolling:focus-within .demo-banner-track {
  animation-play-state: paused;
}
@keyframes demo-banner-marquee {
  from { transform: translateX(0); }
  to { transform: translateX(calc(-50% - 1.375rem)); }
}
@media (prefers-reduced-motion: reduce) {
  .demo-banner.is-scrolling .demo-banner-track {
    animation: none;
    transform: none;
  }
}

/* Demo keeps the normal split background; only the banner is accented. */
.topbar,
header.topbar {
  background: transparent !important;
}

/* Demo click safety: hidden layers must never block mobile nav or dialogs. */
.mobile-view:not(.active),
.rack-overview.hidden,
.rack-editor.hidden,
#welcome-overlay:not(.active),
dialog:not([open]) {
  pointer-events: none !important;
}
.mobile-view.active,
#welcome-overlay.active,
dialog[open] {
  pointer-events: auto !important;
}
.bottom-nav,
.bottom-actions,
.demo-banner {
  pointer-events: auto;
}

@media (max-width: 1100px) {
  .demo-banner {
    padding-top: max(0.45rem, env(safe-area-inset-top));
    font-size: 0.72rem;
  }
}

/* ================================================================
   v30 demo: reserve space for demo banner above fixed app views.
   The demo banner is part of the demo shell, so every fixed mobile
   page and rack workspace must start below it instead of rendering
   underneath it.
   ================================================================ */
:root {
  --demo-banner-h: 38px;
}

.demo-banner {
  box-sizing: border-box !important;
  min-height: var(--demo-banner-h) !important;
  height: var(--demo-banner-h) !important;
  display: flex !important;
  align-items: center !important;
  justify-content: center !important;
  padding: 0 1rem !important;
  overflow: hidden !important;
  white-space: nowrap !important;
  text-overflow: clip !important;
}

@media (min-width: 1101px) {
  #rack-overview.rack-overlay,
  #rack-editor.rack-overlay {
    top: var(--demo-banner-h) !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: calc(100dvh - var(--demo-banner-h)) !important;
    min-height: 0 !important;
  }

  #rack-overview .rack-overview-body {
    height: calc(100dvh - var(--demo-banner-h)) !important;
  }

  #rack-editor .rack-editor-body {
    max-height: calc(100dvh - var(--demo-banner-h) - 56px) !important;
  }
}

@media (max-width: 1100px) {
  :root {
    --demo-banner-h: calc(36px + env(safe-area-inset-top));
  }

  .demo-banner {
    font-size: 0.68rem !important;
    padding: env(safe-area-inset-top) 0.75rem 0 !important;
    line-height: 1.1 !important;
  }

  .mobile-view,
  .rack-overlay {
    top: var(--demo-banner-h) !important;
    bottom: 0 !important;
    left: 0 !important;
    right: 0 !important;
    height: calc(100dvh - var(--demo-banner-h)) !important;
    min-height: calc(100dvh - var(--demo-banner-h)) !important;
    max-height: calc(100dvh - var(--demo-banner-h)) !important;
  }

  .mobile-view-head,
  .rack-ov-topbar,
  .rack-overlay-head,
  .panel-center > .panel-head {
    padding-top: 0 !important;
  }

  .mobile-sheet {
    top: var(--demo-banner-h) !important;
    height: calc(100dvh - var(--demo-banner-h)) !important;
  }

  dialog.theme-picker-dialog[open] {
    top: var(--demo-banner-h) !important;
    height: calc(100dvh - var(--demo-banner-h)) !important;
    max-height: calc(100dvh - var(--demo-banner-h)) !important;
    padding-top: 0 !important;
  }
}

/* v31 demo: clean Topology card placeholders and action buttons. */
.card-live-status.hidden,
.card-actions.hidden,
.card-live-status:empty,
.card-actions:empty,
.card-desc:empty,
.card-notes:empty,
.card-ip:empty,


/* v64 demo: keep the demo notice on the active theme accent color. */
.demo-banner {
  background: var(--yellow) !important;
  color: #202126 !important;
  border-bottom-color: var(--line) !important;
}
.demo-banner a {
  color: #202126 !important;
}

/* v66 demo: force the browser-only banner back to the fixed accent strip. */
html body .demo-banner,
html body .demo-banner.is-scrolling {
  background: #f4d371 !important;
  background-color: #f4d371 !important;
  background-image: none !important;
  color: #202126 !important;
  border-bottom: 3px solid #2e2f36 !important;
  opacity: 1 !important;
  filter: none !important;
  mix-blend-mode: normal !important;
  position: relative !important;
  z-index: 2147483000 !important;
}

html body .demo-banner a,
html body .demo-banner span {
  color: #202126 !important;
}


/* v67: SSH private-key credential support. */
.credential-auth-panel {
  margin: 0 0 0.8rem;
}

.credential-auth-panel.hidden {
  display: none !important;
}

.credential-key-row {
  align-items: stretch !important;
}

.credential-key-row textarea {
  width: 100%;
  min-height: 130px;
  resize: vertical;
  font: 700 0.78rem/1.35 'Space Mono', monospace;
  white-space: pre;
  overflow: auto;
}

@media (max-width: 1100px) {
  .credential-key-row,
  .credential-key-row.credential-input-row {
    grid-template-columns: 1fr !important;
  }

  .credential-key-row textarea {
    min-height: 160px;
  }
}


/* v64/v69: normalize credential auth select height and spacing. */
#credentials-wrap #credential-auth-method {
  min-height: 42px !important;
  height: 42px !important;
  max-height: 42px !important;
  padding: 0.42rem 0.72rem !important;
  align-self: end !important;
}

#credentials-wrap .credential-grid > label:has(#credential-auth-method) {
  align-content: end !important;
}

#credentials-wrap .credential-grid > label:has(#credential-auth-method) select {
  margin-top: 0.35rem !important;
}

@media (max-width: 1100px) {
  #credentials-wrap #credential-auth-method {
    min-height: 44px !important;
    height: 44px !important;
    max-height: 44px !important;
  }
}

/* v67: Keep Advanced Switch Settings visually balanced on desktop.
   Small fields no longer share a stretched row with multi-select lists;
   switch connection lists sit next to each other with equal height. */
@media (min-width: 1101px) {
  .advanced-resource-body > label {
    align-self: start;
  }

  .advanced-resource-body #switch-ports-wrap {
    grid-column: 1 / -1;
  }

  .advanced-resource-body #switch-ports-wrap input {
    min-height: 44px !important;
  }

  .advanced-resource-body #switch-links-wrap,
  .advanced-resource-body #switch-device-links-wrap {
    align-self: stretch;
    display: flex;
    flex-direction: column;
  }

  .advanced-resource-body #switch-links-wrap select[multiple],
  .advanced-resource-body #switch-device-links-wrap select[multiple] {
    flex: 1 1 auto;
    min-height: 142px;
  }
}


/* v68/v73: compact credential auth select and remove credential helper copy. */
#credentials-wrap .credential-grid {
  align-items: end !important;
}

#credentials-wrap #credential-auth-method,
#credentials-wrap .credential-grid > label:has(#credential-auth-method) select {
  box-sizing: border-box !important;
  min-height: 40px !important;
  height: 40px !important;
  max-height: 40px !important;
  padding-block: 0 !important;
  padding-inline: 0.58rem !important;
  line-height: 1.15 !important;
  align-self: end !important;
}

#credentials-wrap .credential-input-row input,
#credentials-wrap .credential-input-row .button {
  box-sizing: border-box !important;
  min-height: 40px !important;
  height: 40px !important;
}

#credentials-wrap .credential-grid > label:has(#credential-auth-method) select {
  margin-top: 0 !important;
}

@media (max-width: 1100px) {
  #credentials-wrap #credential-auth-method,
  #credentials-wrap .credential-grid > label:has(#credential-auth-method) select,
  #credentials-wrap .credential-input-row input,
  #credentials-wrap .credential-input-row .button {
    min-height: 44px !important;
    height: 44px !important;
    max-height: 44px !important;
  }
}

/* v74: compact desktop Theme Customize color cards.
   Keep mobile touch targets large; desktop cards should feel like the API-key scope tiles. */
@media (min-width: 1101px) {
  .theme-picker-dialog #theme-customize-body .tb-section {
    gap: 0.65rem !important;
    padding: 0.85rem !important;
    border-radius: 14px !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-title {
    padding-bottom: 0.5rem !important;
    font-size: 0.9rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-intro {
    margin: -0.15rem 0 0 !important;
    font-size: 0.68rem !important;
    line-height: 1.3 !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-core .tb-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 0.55rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-types .tb-grid {
    gap: 0.55rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row {
    grid-template-columns: 38px minmax(0, 1fr) !important;
    gap: 0.58rem !important;
    min-height: 54px !important;
    padding: 0.52rem 0.62rem !important;
    border-radius: 12px !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row input[type='color'] {
    width: 38px !important;
    height: 38px !important;
    min-width: 38px !important;
    min-height: 38px !important;
    border-width: 2px !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-label {
    font-size: 0.74rem !important;
    line-height: 1.1 !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-desc {
    font-size: 0.66rem !important;
    line-height: 1.22 !important;
  }
}


/* v70: rack workspace polish and consistent mobile rack unit height */
@media (min-width: 1101px) {
  #rack-editor .rack-editor-body {
    display: grid !important;
    grid-template-columns: minmax(220px, 280px) minmax(0, 1fr) minmax(170px, 220px) !important;
    overflow: hidden !important;
  }

  #rack-editor .rack-editor-sidebar {
    display: flex !important;
    flex-direction: column;
    min-width: 0;
    border-right: 2px solid var(--line);
    background: var(--phone);
    overflow: hidden;
  }

  #rack-editor .rack-editor-sidebar-head {
    padding: 0.6rem 0.65rem;
    border-bottom: 2px solid var(--line);
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
  }

  #rack-editor .rack-editor-sidebar-title {
    font: 700 0.72rem/1.2 'Space Mono', monospace;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
  }

  #rack-editor .rack-editor-sidebar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.35rem;
  }

  #rack-editor .rack-editor-sidebar-actions .button {
    padding: 0.35rem 0.45rem;
    min-height: 32px;
    font-size: 0.66rem;
    border-width: 2px;
  }

  #rack-editor .rack-editor-sidebar-content {
    flex: 1;
    overflow: auto;
    padding: 0.45rem;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
  }

  #rack-editor .rack-editor-location-group {
    border: 2px solid color-mix(in srgb, var(--line) 45%, transparent);
    border-radius: 12px;
    padding: 0.4rem;
    background: color-mix(in srgb, var(--panel) 72%, transparent);
  }

  #rack-editor .rack-editor-location-group.active {
    border-color: var(--line);
    background: color-mix(in srgb, var(--mint) 18%, var(--panel));
  }

  #rack-editor .rack-editor-location-name {
    font: 700 0.72rem/1.2 'Space Mono', monospace;
    margin-bottom: 0.35rem;
    color: var(--text);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #rack-editor .rack-editor-rack-list {
    display: flex;
    flex-direction: column;
    gap: 0.28rem;
  }

  #rack-editor .rack-editor-rack-row {
    border: 2px solid var(--line);
    border-radius: 9px;
    background: var(--panel);
    color: var(--text);
    text-align: left;
    padding: 0.34rem 0.42rem;
    font: 700 0.68rem/1.15 'Space Mono', monospace;
    cursor: pointer;
  }

  #rack-editor .rack-editor-rack-row.active,
  #rack-editor .rack-editor-rack-row:hover {
    background: var(--yellow);
  }

  #rack-editor .rack-editor-rack-name,
  #rack-editor .rack-editor-rack-meta {
    display: block;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
  }

  #rack-editor .rack-editor-rack-meta {
    margin-top: 0.1rem;
    font-size: 0.58rem;
    color: var(--muted);
    font-weight: 600;
  }

  #rack-editor .rack-editor-empty-list {
    margin: 0;
    color: var(--muted);
    font: 0.68rem/1.35 'Space Mono', monospace;
  }

  #rack-editor .rack-views-wrap {
    order: 2;
    min-width: 0;
  }

  #rack-editor .rack-palette {
    order: 3;
    width: auto !important;
    border-right: 0 !important;
    border-left: 2px solid var(--line) !important;
  }
}

@media (max-width: 1100px) {
  :root { --rack-u-height: 44px; }
  #rack-editor .rack-editor-sidebar { display: none !important; }
  #rack-editor .rack-slot,
  #rack-editor .rack-slot.empty,
  #rack-editor .rack-slot.occupied {
    height: var(--rack-u-height) !important;
    min-height: var(--rack-u-height) !important;
    max-height: var(--rack-u-height) !important;
  }
}


/* v76 rack assignment modal */
@media (min-width: 1101px) {
  .rack-link-panel.rack-link-modal {
    position: fixed !important;
    left: 50% !important;
    top: 50% !important;
    width: min(720px, calc(100vw - 56px)) !important;
    max-height: min(78vh, 760px);
    transform: translate(-50%, -50%);
    border: 3px solid var(--line);
    border-radius: 18px;
    padding: 1rem;
    z-index: 1200;
    box-shadow: 0 24px 80px rgba(0,0,0,0.34);
  }
  .rack-link-modal::before {
    content: '';
    position: fixed;
    inset: -100vmax;
    background: rgba(15, 25, 18, 0.35);
    z-index: -1;
  }
  .rack-link-modal-head {
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: baseline;
    padding-bottom: 0.65rem;
    margin-bottom: 0.45rem;
    border-bottom: 2px solid color-mix(in srgb, var(--line) 40%, transparent);
  }
  .rack-link-modal-head strong {
    font: 800 0.88rem/1.2 'Space Mono', monospace;
  }
  .rack-link-modal-head span {
    color: var(--muted);
    font: 700 0.7rem/1.2 'Space Mono', monospace;
  }
  .rack-link-picker-row {
    align-items: stretch;
  }
  .rack-link-picker-button {
    flex: 1;
    min-height: 38px;
    border: 2px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
    color: var(--text);
    font: 700 0.74rem/1.25 'Space Mono', monospace;
    text-align: left;
    padding: 0.45rem 0.65rem;
    cursor: pointer;
  }
  .rack-link-picker-button:hover,
  .rack-link-picker-button:focus-visible {
    background: color-mix(in srgb, var(--yellow) 34%, var(--panel));
    outline: none;
  }
  .rack-port-count-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    margin-bottom: 0.25rem;
  }
  .rack-port-count-options {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
  }
  .rack-port-count-button {
    border: 2px solid var(--line);
    border-radius: 9px;
    background: var(--panel);
    color: var(--text);
    font: 700 0.68rem/1.1 'Space Mono', monospace;
    padding: 0.35rem 0.55rem;
    cursor: pointer;
  }
  .rack-port-count-button.selected {
    background: var(--yellow);
  }
  .rack-device-picker {
    position: fixed;
    inset: 0;
    z-index: 1300;
    background: rgba(15, 25, 18, 0.28);
    display: grid;
    place-items: center;
    padding: 1rem;
  }
  .rack-device-picker-card {
    width: min(560px, calc(100vw - 48px));
    max-height: min(72vh, 640px);
    overflow: auto;
    border: 3px solid var(--line);
    border-radius: 18px;
    background: var(--phone);
    box-shadow: 0 22px 70px rgba(0,0,0,0.34);
    padding: 0.9rem;
  }
  .rack-device-picker-head {
    display: flex;
    justify-content: space-between;
    gap: 0.75rem;
    align-items: center;
    margin-bottom: 0.65rem;
    padding-bottom: 0.55rem;
    border-bottom: 2px solid color-mix(in srgb, var(--line) 40%, transparent);
  }
  .rack-device-choice-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    gap: 0.4rem;
  }
  .rack-device-choice {
    border: 2px solid var(--line);
    border-radius: 10px;
    background: var(--panel);
    color: var(--text);
    text-align: left;
    min-height: 38px;
    padding: 0.45rem 0.6rem;
    font: 700 0.7rem/1.2 'Space Mono', monospace;
    cursor: pointer;
  }
  .rack-device-choice:hover,
  .rack-device-choice.selected {
    background: var(--yellow);
  }
}


/* v72/v77: make desktop Theme Customize cards uniform and keep mobile rack units true-to-U. */
@media (min-width: 1101px) {
  .theme-picker-dialog #theme-customize-body .tb-section-grid {
    grid-template-columns: 1fr !important;
    gap: 0.85rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-core .tb-grid,
  .theme-picker-dialog #theme-customize-body .tb-section-types .tb-grid {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 0.62rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section {
    gap: 0.7rem !important;
    padding: 0.9rem !important;
    border-radius: 15px !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-title {
    padding-bottom: 0.5rem !important;
    font-size: 0.9rem !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-section-intro {
    margin: -0.1rem 0 0 !important;
    font-size: 0.68rem !important;
    line-height: 1.3 !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row {
    grid-template-columns: 40px minmax(0, 1fr) !important;
    gap: 0.62rem !important;
    min-height: 58px !important;
    height: 58px !important;
    padding: 0.54rem 0.66rem !important;
    border: 2px solid color-mix(in srgb, var(--line) 80%, transparent) !important;
    border-radius: 13px !important;
    background: color-mix(in srgb, var(--phone) 86%, white) !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-row input[type='color'] {
    width: 40px !important;
    height: 40px !important;
    min-width: 40px !important;
    min-height: 40px !important;
    padding: 0 !important;
    border: 2px solid var(--line) !important;
    border-radius: 999px !important;
    background: transparent !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-label {
    font-size: 0.72rem !important;
    line-height: 1.12 !important;
  }

  .theme-picker-dialog #theme-customize-body .tb-color-desc {
    font-size: 0.64rem !important;
    line-height: 1.2 !important;
  }
}

@media (min-width: 1500px) {
  .theme-picker-dialog #theme-customize-body .tb-section-core .tb-grid,
  .theme-picker-dialog #theme-customize-body .tb-section-types .tb-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }
}

@media (max-width: 1100px) {
  #rack-editor .rack-slot.empty {
    height: var(--rack-u-height) !important;
    min-height: var(--rack-u-height) !important;
    max-height: var(--rack-u-height) !important;
  }
}


/* v73/v78: repair desktop rack assignment modal and theme customizer layout. */
@media (min-width: 1101px) {
  .rack-link-panel.rack-link-modal {
    background: var(--phone) !important;
    color: var(--text) !important;
    border: 3px solid var(--line) !important;
    border-radius: 18px !important;
    box-shadow: 0 24px 80px rgba(0, 0, 0, 0.28) !important;
    padding: 1rem !important;
    max-height: min(72vh, 620px) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    overscroll-behavior: contain !important;
  }
  .rack-link-modal::before {
    display: none !important;
    content: none !important;
  }
  .rack-link-panel.rack-link-modal .rack-link-multi-wrap {
    max-height: none !important;
    overflow: visible !important;
  }
  .rack-device-picker {
    overflow: hidden !important;
  }
  .rack-device-picker-card {
    background: var(--phone) !important;
    color: var(--text) !important;
    max-height: min(70vh, 600px) !important;
    overflow-y: auto !important;
    overflow-x: hidden !important;
    overscroll-behavior: contain !important;
  }

  .theme-picker-dialog #theme-customize-body.theme-builder-body {
    overflow-y: auto !important;
    overflow-x: hidden !important;
    padding-bottom: 5rem !important;
  }
  .theme-picker-dialog #theme-customize-body .tb-section-grid {
    display: grid !important;
    grid-template-columns: 1fr !important;
    gap: 1rem !important;
  }
  .theme-picker-dialog #theme-customize-body .tb-section {
    display: flex !important;
    flex-direction: column !important;
    gap: 0.85rem !important;
    padding: 1rem !important;
    overflow: visible !important;
  }
  .theme-picker-dialog #theme-customize-body .tb-section-core .tb-grid,
  .theme-picker-dialog #theme-customize-body .tb-section-types .tb-grid {
    display: grid !important;
    grid-template-columns: repeat(3, minmax(0, 1fr)) !important;
    gap: 0.75rem !important;
    align-items: stretch !important;
  }
  .theme-picker-dialog #theme-customize-body .tb-color-row {
    display: grid !important;
    grid-template-columns: 48px minmax(0, 1fr) !important;
    align-items: center !important;
    gap: 0.8rem !important;
    min-height: 86px !important;
    height: auto !important;
    padding: 0.72rem 0.82rem !important;
    border: 2px solid var(--line) !important;
    border-radius: 14px !important;
    background: var(--panel) !important;
    overflow: hidden !important;
  }
  .theme-picker-dialog #theme-customize-body .tb-color-row input[type='color'] {
    width: 46px !important;
    height: 46px !important;
    min-width: 46px !important;
    min-height: 46px !important;
    align-self: center !important;
    justify-self: center !important;
    margin: 0 !important;
    transform: none !important;
    position: relative !important;
    z-index: 1 !important;
  }
  .theme-picker-dialog #theme-customize-body .tb-color-copy {
    min-width: 0 !important;
    display: flex !important;
    flex-direction: column !important;
    gap: 0.32rem !important;
    justify-content: center !important;
    overflow: hidden !important;
  }
  .theme-picker-dialog #theme-customize-body .tb-color-label {
    font-size: 0.74rem !important;
    line-height: 1.15 !important;
    white-space: normal !important;
    overflow-wrap: anywhere !important;
  }
  .theme-picker-dialog #theme-customize-body .tb-color-desc {
    font-size: 0.66rem !important;
    line-height: 1.28 !important;
    white-space: normal !important;
    color: var(--muted) !important;
  }
}

@media (min-width: 1500px) {
  .theme-picker-dialog #theme-customize-body .tb-section-core .tb-grid,
  .theme-picker-dialog #theme-customize-body .tb-section-types .tb-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr)) !important;
  }
}

/* v74/v79: normalize Config section headings and rack switch assignment notes. */
#config-dialog .config-section-title,
#mobile-config .config-section-title {
  font: 700 0.8rem/1.2 'Space Mono', monospace !important;
  letter-spacing: 0 !important;
  color: var(--text) !important;
}
@media (min-width: 1101px) {
  #config-dialog .config-section-title {
    min-height: 36px !important;
    padding: 0.42rem 0.75rem !important;
  }
}
.rack-link-note {
  margin: 0.2rem 0 0.7rem !important;
  color: var(--muted) !important;
  font: 700 0.72rem/1.35 'Inter', system-ui, sans-serif !important;
}
.rack-link-modal .rack-link-note {
  grid-column: 1 / -1;
}

.connection-summary {
  display: none;
}


@media (min-width: 1101px) {
  .cli-dialog {
    width: min(1500px, calc(100vw - 96px));
  }

  .cli-shell-desktop {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(280px, 340px);
    grid-template-rows: minmax(0, 1fr);
    gap: 1rem;
    padding: 1rem;
  }

  .cli-main {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: auto minmax(0, 1fr) auto auto;
    gap: 0.8rem;
  }

  .cli-command-panel {
    min-width: 0;
    min-height: 0;
    display: grid;
    grid-template-rows: auto auto minmax(0, 1fr) auto;
    gap: 0.75rem;
    border: 3px solid var(--line);
    border-radius: 18px;
    background: var(--panel);
    padding: 0.85rem;
    box-shadow: var(--shadow);
  }

  .cli-command-head h3 {
    margin: 0;
    font: 900 0.98rem/1.2 'Space Mono', monospace;
  }

  .cli-command-head p {
    margin: 0.35rem 0 0;
    color: var(--muted);
    font: 700 0.7rem/1.35 'Space Mono', monospace;
  }

  .cli-command-search {
    width: 100%;
    min-height: 42px;
  }

  .cli-command-list {
    min-height: 0;
    overflow: auto;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    padding-right: 0.2rem;
  }

  .cli-command-item {
    text-align: left;
    border: 2px solid var(--line);
    border-radius: 14px;
    background: var(--phone);
    color: var(--text);
    padding: 0.65rem;
    cursor: pointer;
    display: grid;
    gap: 0.3rem;
  }

  .cli-command-item:hover,
  .cli-command-item.active {
    background: var(--highlight);
  }

  .cli-command-item-name {
    font: 900 0.78rem/1.2 'Space Mono', monospace;
  }

  .cli-command-item-command {
    font: 700 0.66rem/1.35 'Space Mono', monospace;
    color: var(--muted);
    white-space: pre-wrap;
    overflow-wrap: anywhere;
    max-height: 4.1rem;
    overflow: hidden;
  }

  .cli-command-item-description {
    font: 700 0.66rem/1.35 'Inter', sans-serif;
    color: var(--muted);
  }

  .cli-command-empty {
    border: 2px dashed color-mix(in srgb, var(--line) 50%, transparent);
    border-radius: 14px;
    padding: 1rem;
    color: var(--muted);
    font: 700 0.75rem/1.35 'Space Mono', monospace;
  }

  .cli-command-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.55rem;
    padding-top: 0.65rem;
    border-top: 2px solid var(--line);
  }

  .cli-command-dialog {
    width: min(620px, calc(100vw - 48px));
    border: 3px solid var(--line);
    border-radius: 18px;
    background: var(--phone);
    color: var(--text);
    padding: 0;
    box-shadow: var(--shadow);
  }

  .cli-command-dialog::backdrop {
    background: rgba(0, 0, 0, 0.48);
  }

  .cli-command-card {
    padding: 1rem;
    display: grid;
    gap: 0.85rem;
  }

  .cli-command-card h3 {
    margin: 0;
    font: 900 1rem/1.2 'Space Mono', monospace;
  }

  .cli-command-card label {
    display: grid;
    gap: 0.35rem;
    font: 700 0.78rem/1.2 'Space Mono', monospace;
  }

  .cli-command-card textarea {
    resize: vertical;
    min-height: 90px;
  }

  .cli-command-dialog-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.6rem;
    flex-wrap: wrap;
    padding-top: 0.5rem;
    border-top: 2px solid var(--line);
  }
}

@media (max-width: 1100px) {
  .cli-command-panel,
  .cli-command-dialog {
    display: none !important;
  }
}


/* v92: Backup Config dialog and mobile page */
.backup-config-dialog {
  width: min(1180px, calc(100vw - 128px));
  height: min(680px, calc(100dvh - 128px));
  max-width: calc(100vw - 128px);
  max-height: calc(100dvh - 128px);
}
.backup-config-dialog .backup-dialog-body,
#mobile-backup-config .mobile-view-body {
  overflow: auto;
  min-height: 0;
}
.backup-config-panel {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0.85rem;
}
.backup-form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.8rem 1rem;
}
.backup-form-grid label,
.backup-toggle-row {
  display: grid;
  gap: 0.35rem;
  font-weight: 800;
}
.backup-toggle-row {
  grid-column: 1 / -1;
  grid-template-columns: auto 1fr;
  align-items: center;
  min-height: 42px;
  padding: 0.65rem 0.75rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--blue);
}
.backup-status-card,
.backup-section-title {
  display: grid;
  gap: 0.25rem;
  border: 2px solid var(--line);
  border-radius: 12px;
  background: var(--blue);
  padding: 0.75rem 0.85rem;
}
.backup-section-title {
  display: flex;
  align-items: center;
  min-height: 38px;
  font-weight: 900;
}
.backup-actions-row {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.75rem;
}
.backup-list,
.backup-log-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: grid;
  gap: 0.55rem;
}
.backup-list li,
.backup-log-list li {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
  padding: 0.65rem 0.75rem;
  border: 2px solid var(--border);
  border-radius: 12px;
  background: var(--panel);
}
.backup-list li div,
.backup-log-list li {
  min-width: 0;
}
.backup-list-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.5rem;
  flex-wrap: wrap;
  min-width: max-content;
}
.backup-list li span,
.backup-log-list li span,
.backup-status-card span {
  display: block;
  color: var(--muted);
  font-size: 0.88rem;
  word-break: break-word;
}
.backup-log-error { border-color: var(--danger, #d95a4e) !important; }
#backup-config-btn,
#backup-config-btn-mobile { margin-top: 0; }
@media (max-width: 1100px) {
  #mobile-backup-config .mobile-view-body {
    padding: 1.1rem 1rem calc(6.5rem + env(safe-area-inset-bottom));
  }
  .backup-config-dialog { width: 100vw; height: 100dvh; max-width: 100vw; max-height: 100dvh; }
  .backup-form-grid,
  .backup-actions-row { grid-template-columns: 1fr; }
  .backup-list li,
  .backup-log-list li { align-items: stretch; flex-direction: column; }
  .backup-list-actions { width: 100%; display: grid; grid-template-columns: 1fr; }
  .backup-list li .button { width: 100%; }
}

/* v108: keep Backup Config typography consistent with the Labby mono UI */
.backup-config-dialog,
.backup-config-dialog *,
#mobile-backup-config,
#mobile-backup-config * {
  font-family: 'Space Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.backup-config-panel,
.backup-config-panel p,
.backup-config-panel label,
.backup-status-card,
.backup-section-title,
.backup-list,
.backup-log-list,
.backup-list li,
.backup-log-list li,
.backup-list li span,
.backup-log-list li span,
.backup-status-card span {
  font-family: 'Space Mono', ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.backup-config-panel .config-intro,
.backup-status-card span,
.backup-list li span,
.backup-log-list li span {
  font-weight: 700;
  line-height: 1.35;
}


/* v95: normalize Backup Config desktop typography and control sizing. */
@media (min-width: 1101px) {
  .backup-config-dialog[open] {
    font-size: 14px;
  }

  .backup-config-dialog .tree-head h3 {
    font-size: 1rem;
    line-height: 1.25;
    letter-spacing: 0;
  }

  .backup-config-dialog .backup-dialog-body {
    font-size: 0.86rem;
  }

  .backup-config-dialog .backup-config-panel {
    gap: 0.72rem;
  }

  .backup-config-dialog .config-intro,
  .backup-config-dialog .backup-status-card,
  .backup-config-dialog .backup-section-title,
  .backup-config-dialog .backup-form-grid label,
  .backup-config-dialog .backup-toggle-row,
  .backup-config-dialog .backup-list li,
  .backup-config-dialog .backup-log-list li {
    font-size: 0.84rem;
    line-height: 1.35;
  }

  .backup-config-dialog .backup-section-title,
  .backup-config-dialog .backup-status-card {
    padding: 0.62rem 0.75rem;
    border-radius: 12px;
  }

  .backup-config-dialog .backup-toggle-row {
    min-height: 40px;
    padding: 0.55rem 0.7rem;
  }

  .backup-config-dialog .backup-form-grid {
    gap: 0.7rem 0.85rem;
  }

  .backup-config-dialog .backup-form-grid input,
  .backup-config-dialog .backup-form-grid select {
    min-height: 38px;
    font-size: 0.84rem;
    line-height: 1.25;
    padding: 0.45rem 0.65rem;
  }

  .backup-config-dialog .backup-list li,
  .backup-config-dialog .backup-log-list li {
    padding: 0.55rem 0.68rem;
  }

  .backup-config-dialog .backup-list li strong,
  .backup-config-dialog .backup-log-list li strong,
  .backup-config-dialog .backup-status-card strong {
    font-size: 0.88rem;
    line-height: 1.28;
  }

  .backup-config-dialog .backup-list li span,
  .backup-config-dialog .backup-log-list li span,
  .backup-config-dialog .backup-status-card span {
    font-size: 0.78rem;
    line-height: 1.3;
  }

  .backup-config-dialog .button,
  .backup-config-dialog .dialog-footer .button {
    min-height: 36px;
    font-size: 0.8rem;
    line-height: 1.2;
    padding: 0.42rem 0.75rem;
  }
}


/* v111: public demo shows Backup Config as a read-only preview. */
.backup-demo-notice {
  border-style: dashed;
  background: color-mix(in srgb, var(--accent) 18%, var(--panel));
}
.backup-config-panel button:disabled,
.backup-config-panel input:disabled,
.backup-config-panel select:disabled {
  cursor: not-allowed;
  opacity: 0.68;
}

.cli-terminal:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--mint) 58%, transparent);
  outline-offset: 3px;
}


/* v104: sudo password button fits into the existing CLI footer. */
#cli-sudo-password,
#mobile-cli-sudo-password {
  white-space: nowrap;
}

@media (max-width: 1100px) {
  .cli-footer #mobile-cli-close {
    grid-column: 1 / -1;
  }
}
