:root {
  --bg: #0b0f17;
  --bg-2: #111725;
  --card: rgba(255, 255, 255, 0.04);
  --card-hover: rgba(255, 255, 255, 0.07);
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #e8ecf4;
  --muted: #8b93a7;
  --accent: #7c5cff;
  --accent-2: #22d3ee;
  --green: #22c55e;
  --red: #ef4444;
  --amber: #f59e0b;
  --gray: #64748b;
  --radius: 16px;
  --shadow: 0 10px 30px -12px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

:root[data-theme='light'] {
  --bg: #f4f6fb;
  --bg-2: #ffffff;
  --card: rgba(255, 255, 255, 0.75);
  --card-hover: #ffffff;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.18);
  --text: #0f172a;
  --muted: #64748b;
  --shadow: 0 10px 30px -15px rgba(15, 23, 42, 0.25);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'Apple Color Emoji', 'Segoe UI Emoji', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  min-height: 100dvh;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}
a { color: inherit; }
svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex-shrink: 0; }
[hidden] { display: none !important; }
.muted { color: var(--muted); }
.grow { flex: 1; }

.bg-glow {
  position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background:
    radial-gradient(600px circle at 10% -10%, color-mix(in srgb, var(--accent) 18%, transparent), transparent 60%),
    radial-gradient(500px circle at 100% 0%, rgba(34, 211, 238, 0.12), transparent 60%);
}

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 14px max(20px, env(safe-area-inset-left));
  padding-top: max(14px, env(safe-area-inset-top));
  background: color-mix(in srgb, var(--bg) 75%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
/* The brand is the server switcher: current server's icon + name, dashboard title underneath. */
.brand {
  display: flex; align-items: center; gap: 12px; min-width: 0;
  margin: -4px -8px; padding: 4px 8px; border: 0; border-radius: 14px;
  background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer; transition: background .15s;
}
.brand:not(:disabled):hover, .brand[aria-expanded='true'] { background: var(--card-hover); }
.brand:disabled { cursor: default; }
.brand:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.brand-icon { display: flex; flex-shrink: 0; }
.brand-icon > img, .brand-icon > .ticon { width: 38px; height: 38px; border-radius: 11px; }
.brand-icon > .ticon { font-size: 22px; }
.brand-icon .ticon .letter { font-size: 17px; }
.brand-text { display: flex; flex-direction: column; min-width: 0; }
.brand-title { display: flex; align-items: center; gap: 4px; font-size: 1.1rem; font-weight: 700; letter-spacing: -0.01em; }
#title, #summary { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#summary { margin-top: 2px; font-size: 0.8rem; }
.brand-chevron { width: 16px; height: 16px; flex-shrink: 0; color: var(--muted); transition: transform .15s; }
.brand[aria-expanded='true'] .brand-chevron { transform: rotate(180deg); }
.brand:disabled .brand-chevron { display: none; }
.logo { width: 38px; height: 38px; border-radius: 11px; }

.search {
  flex: 1; max-width: 520px; margin: 0 auto;
  display: flex; align-items: center; gap: 8px;
  padding: 0 12px; height: 40px;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  color: var(--muted); transition: border-color .15s;
}
.search:focus-within { border-color: var(--accent); }
.search input { flex: 1; min-width: 0; border: 0; outline: 0; background: transparent; color: var(--text); font: inherit; font-size: 0.95rem; }
.search kbd { font: 0.75rem ui-monospace, monospace; padding: 2px 6px; border: 1px solid var(--border-strong); border-radius: 6px; }

.actions { display: flex; gap: 8px; }

/* ---------- Buttons ---------- */
.btn, .icon-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 14px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--card); color: var(--text);
  font: inherit; font-size: 0.9rem; font-weight: 600; cursor: pointer; text-decoration: none;
  transition: background .15s, border-color .15s, transform .1s;
}
.icon-btn { width: 40px; padding: 0; }
.btn:hover, .icon-btn:hover { background: var(--card-hover); border-color: var(--border-strong); }
.btn:active, .icon-btn:active { transform: scale(0.97); }
.btn.primary, .btn[aria-pressed='true'] {
  background: linear-gradient(135deg, var(--accent), color-mix(in srgb, var(--accent) 70%, #fff));
  border-color: transparent; color: #fff;
}
.btn.ghost { background: transparent; }
.btn.danger { color: var(--red); }
.btn.primary.danger-fill { background: var(--red); }
.btn.sm { height: 32px; padding: 0 10px; font-size: 0.8rem; border-radius: 10px; }
.icon-btn.sm { width: 30px; height: 30px; border-radius: 9px; }
.icon-btn.sm svg { width: 15px; height: 15px; }
.btn:disabled { opacity: 0.45; pointer-events: none; }
.spin svg { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Server menu ---------- */
.ticon { width: 28px; height: 28px; flex-shrink: 0; font-size: 18px; display: grid; place-items: center; border-radius: 8px; overflow: hidden; }
.ticon img { width: 100%; height: 100%; object-fit: contain; }
.ticon .letter { font-size: 13px; font-weight: 700; color: #fff; }

.menu.server-menu { width: min(320px, calc(100vw - 16px)); }
.server-list { display: flex; flex-direction: column; gap: 2px; }
.server-item {
  display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border-radius: 11px;
  border: 1px solid transparent; background: none; color: var(--text); font: inherit; text-align: left; cursor: pointer;
}
.server-item:hover { background: var(--card-hover); }
.server-item[aria-current='true'] { background: color-mix(in srgb, var(--accent) 16%, transparent); border-color: color-mix(in srgb, var(--accent) 45%, transparent); }
.server-item:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.server-item .ticon { width: 36px; height: 36px; border-radius: 10px; font-size: 20px; }
.server-item .ticon .letter { font-size: 15px; }
.server-item-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.server-item-name, .server-item-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.server-item-name { font-size: 0.92rem; font-weight: 650; }
.server-item-sub { font-size: 0.76rem; color: var(--muted); }
.server-item-sub svg { width: 12px; height: 12px; vertical-align: -2px; margin-right: 4px; }

/* ---------- Favourites ---------- */
.favs {
  display: flex; flex-wrap: wrap; gap: 8px;
  padding: 16px 20px 0; max-width: 1400px; margin: 0 auto;
}
.fav {
  display: inline-flex; align-items: center; gap: 9px; flex-shrink: 0;
  height: 46px; padding: 0 14px 0 7px; border-radius: 14px;
  background: var(--card); border: 1px solid var(--border); box-shadow: var(--shadow);
  color: var(--text); text-decoration: none; font-size: 0.88rem; font-weight: 600;
  transition: transform .15s, border-color .15s, background .15s;
}
a.fav:hover { transform: translateY(-1px); border-color: var(--border-strong); background: var(--card-hover); }
a.fav:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.fav .icon { width: 32px; height: 32px; border-radius: 9px; font-size: 18px; }
.fav .icon .letter { font-size: 14px; }
.fav-name { max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fav .drag-handle { width: 16px; height: 30px; margin: 0 -4px 0 0; align-self: center; }
.fav .icon-btn.sm { width: 26px; height: 26px; margin-right: -8px; }
.dot.up { background: var(--green); }
.dot.down { background: var(--red); }
.dot.warn { background: var(--amber); }
.icon-btn.on { color: var(--amber); }
.icon-btn.on svg { fill: currentColor; }

main { max-width: 1400px; margin: 0 auto; padding: 12px 20px 48px; }

/* ---------- Server header ---------- */
/* Header on the left, host stats on the right; they stack when there isn't room. */
.server-top { display: flex; flex-wrap: wrap; align-items: center; gap: 14px 24px; padding: 16px 0 18px; }
.server-head { flex: 1 1 320px; display: flex; align-items: center; gap: 12px 20px; min-width: 0; }
.server-head .server-icon { width: 54px; height: 54px; border-radius: 15px; font-size: 30px; align-self: flex-start; }
.server-head .info { flex: 1; min-width: 220px; }
.server-head h2 { margin: 0; font-size: 1.5rem; letter-spacing: -0.02em; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.server-head .desc { margin: 4px 0 0; color: var(--muted); }
.meta { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 10px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  font-size: 0.78rem; padding: 4px 10px; border-radius: 999px;
  background: var(--card); border: 1px solid var(--border); color: var(--muted);
  text-decoration: none; white-space: nowrap;
}
a.chip:hover { color: var(--text); border-color: var(--border-strong); }
.chip svg { width: 13px; height: 13px; }
.chip .dot { background: currentColor; }
.chip.green { color: var(--green); border-color: color-mix(in srgb, var(--green) 35%, transparent); }
.chip.red { color: var(--red); border-color: color-mix(in srgb, var(--red) 35%, transparent); }
.chip.amber { color: var(--amber); border-color: color-mix(in srgb, var(--amber) 35%, transparent); }
.chip button { all: unset; cursor: pointer; display: inline-flex; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.toolbar { display: flex; flex-wrap: wrap; gap: 8px; }

/* ---------- Groups ---------- */
.services { display: flex; flex-direction: column; gap: 22px; }
.group-head {
  display: flex; align-items: center; gap: 8px; width: 100%; margin: 0 0 10px; padding: 4px 2px;
  background: none; border: 0; border-radius: 8px; color: var(--muted); text-align: left;
  font: inherit; font-size: 0.8rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
}
button.group-head { cursor: pointer; }
button.group-head:hover { color: var(--text); }
button.group-head:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.group-head svg { width: 16px; height: 16px; transition: transform .2s; }
.group.collapsed .group-head svg { transform: rotate(-90deg); }
.group.collapsed .group-head { margin-bottom: 0; }
.group-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.group-head .count { font-size: 0.72rem; padding: 1px 7px; border-radius: 999px; background: var(--border); letter-spacing: 0; }
.group-head .drag-handle { width: 22px; height: 28px; margin-left: -4px; align-self: center; }
.group-usage {
  display: inline-flex; align-items: baseline; gap: 5px; margin-left: auto; flex-shrink: 0;
  font-size: 0.75rem; text-transform: none; letter-spacing: 0; color: var(--text);
}
.group-usage .usage-label:not(:first-child) { margin-left: 6px; }
body.editing .group.named { padding: 10px 12px 12px; border: 1px dashed var(--border-strong); border-radius: 20px; }

/* ---------- Service cards ---------- */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(270px, 1fr)); gap: 14px; }
.card {
  position: relative; display: flex; flex-direction: column; gap: 12px;
  padding: 16px; border-radius: var(--radius);
  background: var(--card); border: 1px solid var(--border);
  box-shadow: var(--shadow);
  transition: transform .15s, border-color .15s, background .15s;
}
.card:hover { transform: translateY(-2px); border-color: var(--border-strong); background: var(--card-hover); }
.card .main-link { position: absolute; inset: 0; border-radius: inherit; z-index: 1; }
.card button.main-link { all: unset; position: absolute; inset: 0; border-radius: inherit; z-index: 1; cursor: pointer; }
.card .main-link:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.card .top { display: flex; gap: 12px; align-items: flex-start; }
.card .name { margin: 0; font-size: 1rem; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.card .description { margin: 3px 0 0; font-size: 0.85rem; color: var(--muted); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; white-space: pre-line; }
.card .text { flex: 1; min-width: 0; }
.card .links { display: flex; flex-wrap: wrap; gap: 6px; position: relative; z-index: 2; margin-top: auto; }
.card .server-tag { font-size: 0.72rem; color: var(--accent-2); font-weight: 600; text-transform: uppercase; letter-spacing: .04em; }
.card .edit-tools { position: relative; z-index: 2; display: flex; gap: 4px; }
.card.add-card {
  align-items: center; justify-content: center; min-height: 120px; cursor: pointer;
  border: 1.5px dashed var(--border-strong); background: transparent; box-shadow: none; color: var(--muted);
  font: inherit; font-weight: 600;
}
.card.add-card:hover { color: var(--text); border-color: var(--accent); }

.icon {
  width: 46px; height: 46px; flex-shrink: 0; border-radius: 12px;
  display: grid; place-items: center; overflow: hidden;
  background: color-mix(in srgb, var(--text) 6%, transparent);
  font-size: 24px; line-height: 1;
}
.icon img { width: 70%; height: 70%; object-fit: contain; }
.icon .letter { font-weight: 700; font-size: 20px; color: #fff; width: 100%; height: 100%; display: grid; place-items: center; }

.status { display: inline-flex; align-items: center; gap: 6px; font-size: 0.75rem; font-weight: 600; color: var(--muted); white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; background: var(--gray); flex-shrink: 0; }
.status.up { color: var(--green); }
.status.up .dot { background: var(--green); box-shadow: 0 0 0 0 color-mix(in srgb, var(--green) 60%, transparent); animation: pulse 2s infinite; }
.status.down { color: var(--red); }
.status.down .dot { background: var(--red); }
.status.warn { color: var(--amber); }
.status.warn .dot { background: var(--amber); }
@keyframes pulse { 70% { box-shadow: 0 0 0 7px transparent; } 100% { box-shadow: 0 0 0 0 transparent; } }

.empty { text-align: center; color: var(--muted); padding: 48px 0; }

/* ---------- Layouts (View menu) ---------- */
/* Compact: icon + name tiles; description shows on hover (title). */
body[data-layout='compact'] #services .grid { grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 10px; }
body.editing[data-layout='compact'] #services .grid { grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); }
body[data-layout='compact'] #services .card { padding: 10px 12px; gap: 0; }
body[data-layout='compact'] #services .card .top { align-items: center; gap: 10px; }
body[data-layout='compact'] #services .card .icon { width: 34px; height: 34px; border-radius: 10px; font-size: 18px; }
body[data-layout='compact'] #services .card .icon .letter { font-size: 15px; }
body[data-layout='compact'] #services .card .name { font-size: 0.92rem; }
body[data-layout='compact'] #services .card :is(.description, .links, .status-label, .usage) { display: none; }
body[data-layout='compact'] #services .add-card { min-height: 56px; flex-direction: row; gap: 8px; }

/* List: one row per service with links on the right. */
body[data-layout='list'] #services .grid { grid-template-columns: repeat(auto-fill, minmax(min(520px, 100%), 1fr)); gap: 8px; }
body[data-layout='list'] #services .card { flex-direction: row; align-items: center; gap: 14px; padding: 10px 14px; }
body[data-layout='list'] #services .card:hover { transform: none; }
body[data-layout='list'] #services .card .top { flex: 1; min-width: 0; align-items: center; }
body[data-layout='list'] #services .card .icon { width: 38px; height: 38px; border-radius: 11px; font-size: 20px; }
body[data-layout='list'] #services .card .description { -webkit-line-clamp: 1; margin-top: 1px; }
body[data-layout='list'] #services .card .links { margin-top: 0; flex-wrap: nowrap; flex-shrink: 0; max-width: 45%; overflow: hidden; }
body[data-layout='list'] #services .card .usage { display: none; }
body[data-layout='list'] #services .add-card { min-height: 56px; flex-direction: row; gap: 8px; }

/* ---------- Unlisted containers ---------- */
.unlisted { margin-top: 36px; }
.unlisted summary {
  cursor: pointer; list-style: none; display: flex; align-items: center; gap: 10px;
  font-weight: 650; padding: 8px 0; color: var(--muted);
}
.unlisted summary::-webkit-details-marker { display: none; }
.unlisted summary svg { transition: transform .2s; }
.unlisted details[open] summary svg { transform: rotate(90deg); }
.unlisted .grid { margin-top: 10px; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); }
.unlisted .card { padding: 12px 14px; gap: 8px; box-shadow: none; }
.unlisted .card .name { font-size: 0.92rem; }
.unlisted .card .image { font: 0.75rem ui-monospace, monospace; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- Dialogs ---------- */
dialog {
  width: min(520px, calc(100vw - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: 1px solid var(--border-strong); border-radius: 20px;
  background: var(--bg-2); color: var(--text); box-shadow: 0 30px 80px -20px rgba(0, 0, 0, 0.6);
}
dialog[open] { animation: pop .18s ease; }
@keyframes pop { from { opacity: 0; transform: translateY(10px) scale(.98); } }
dialog::backdrop { background: rgba(5, 8, 15, 0.55); backdrop-filter: blur(4px); }
dialog form { display: flex; flex-direction: column; max-height: inherit; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 18px 20px 6px; }
.dialog-head h2 { margin: 0; font-size: 1.15rem; }
.dialog-body { padding: 10px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.dialog-foot { display: flex; gap: 8px; padding: 14px 20px 18px; border-top: 1px solid var(--border); }
.app-version { align-self: center; font-size: 12px; color: var(--muted); font-variant-numeric: tabular-nums; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; font-weight: 600; }
.field small { font-weight: 400; color: var(--muted); }
.field code { font-size: 0.8rem; }
.field-row { display: flex; gap: 12px; align-items: flex-end; flex-wrap: wrap; }
.field-row .field { min-width: 140px; }
.field-row.cache-row { align-items: center; }
.remote-list { display: flex; flex-direction: column; gap: 6px; }
.remote-row { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border: 1px solid var(--border); border-radius: 10px; font-weight: 400; }
.remote-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.remote-text small { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#remoteName, #remoteToken { width: 140px; }
#remoteUrl { min-width: 180px; }
.field input, .field select, .field textarea {
  height: 42px; padding: 0 12px; border-radius: 10px;
  border: 1px solid var(--border-strong); background: var(--bg); color: var(--text);
  font: inherit; font-weight: 400; font-size: 16px; /* 16px prevents iOS zoom */
}
.field textarea { height: auto; min-height: 96px; padding: 10px 12px; line-height: 1.45; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.field input:invalid:not(:placeholder-shown) { border-color: var(--red); }
.icon-preview { width: 42px; height: 42px; }
.icon-preview .icon { width: 42px; height: 42px; }
.icon-suggest { display: flex; flex-wrap: wrap; gap: 6px; }
.icon-option {
  display: grid; place-items: center; width: 44px; height: 44px; padding: 7px;
  border-radius: 11px; border: 1px solid var(--border); background: var(--card); cursor: pointer;
  transition: border-color .15s, background .15s;
}
.icon-option:hover { border-color: var(--border-strong); background: var(--card-hover); }
.icon-option:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.icon-option[aria-pressed='true'] { border-color: var(--accent); box-shadow: 0 0 0 2px color-mix(in srgb, var(--accent) 35%, transparent); }
.icon-option img { width: 100%; height: 100%; object-fit: contain; }

.swatches { display: flex; flex-wrap: wrap; gap: 10px; padding: 2px; }
.swatch {
  position: relative; width: 32px; height: 32px; padding: 0; border: 0; border-radius: 50%; cursor: pointer;
  background: var(--swatch); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.15);
}
.swatch:focus-visible { outline: 2px solid var(--text); outline-offset: 3px; }
.swatch[aria-pressed='true'], .swatch.custom.on { outline: 2px solid var(--accent); outline-offset: 3px; }
.swatch.custom { overflow: hidden; background: conic-gradient(#f43f5e, #f59e0b, #22c55e, #06b6d4, #3b82f6, #a855f7, #f43f5e); }
.swatch.custom:focus-within { outline: 2px solid var(--text); outline-offset: 3px; }
.swatch.custom input { position: absolute; inset: 0; width: 100%; height: 100%; padding: 0; border: 0; opacity: 0; cursor: pointer; }
.check { display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1px solid var(--border); border-radius: 12px; cursor: pointer; font-size: 0.9rem; }
.check input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--accent); }
.file-btn { cursor: pointer; }
.form-error { margin: 0; color: var(--red); font-size: 0.85rem; font-weight: 600; }
.icon-btn.danger { color: var(--red); }

/* ---------- QR code ---------- */
.qr-dialog { width: min(380px, calc(100vw - 24px)); }
.qr-body { align-items: center; padding-bottom: 24px; }
.qr-box { width: min(280px, 100%); aspect-ratio: 1; border-radius: 16px; overflow: hidden; background: #fff; }
.qr-box .qr { display: block; width: 100%; height: 100%; stroke: none; }
.qr-url { font-size: 0.85rem; color: var(--muted); text-align: center; word-break: break-all; }
.seg { display: inline-flex; gap: 3px; padding: 3px; border-radius: 12px; background: var(--card); border: 1px solid var(--border); }
.seg button {
  all: unset; display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px; border-radius: 9px;
  font-size: 0.85rem; font-weight: 600; color: var(--muted); cursor: pointer;
}
.seg button[aria-pressed='true'] { background: var(--accent); color: #fff; }
.seg button:focus-visible { outline: 2px solid var(--accent); }
.seg svg { width: 14px; height: 14px; }

/* ---------- Ask dialog ---------- */
.ask-dialog { width: min(420px, calc(100vw - 24px)); }
.ask-message { margin: 0; line-height: 1.45; white-space: pre-line; }

/* ---------- View menu (popover) ---------- */
.menu {
  position: fixed; inset: auto; margin: 0; width: min(280px, calc(100vw - 16px)); padding: 12px;
  border: 1px solid var(--border-strong); border-radius: 16px;
  background: var(--bg-2); color: var(--text); box-shadow: 0 20px 50px -15px rgba(0, 0, 0, 0.6);
}
.menu:popover-open { display: flex; flex-direction: column; gap: 8px; animation: pop .15s ease; }
.menu-label { font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.menu .seg { display: flex; }
.menu .seg button { flex: 1; justify-content: center; padding: 7px 6px; font-size: 0.8rem; }
.menu .btn { margin-top: 6px; }
.menu-hint { margin: 6px 0 0; font-size: 0.78rem; line-height: 1.4; color: var(--muted); }

/* ---------- Shared clipboard (popover) ---------- */
#clipBtn { position: relative; }
.badge-dot { position: absolute; top: 7px; right: 7px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent-2); box-shadow: 0 0 0 2px var(--bg); }
.menu.clip-menu { width: min(360px, calc(100vw - 16px)); }
.clip-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.clip-age { font-size: 0.75rem; color: var(--muted); }
.clip-menu textarea {
  width: 100%; min-height: 110px; max-height: 50vh; padding: 10px 12px; border-radius: 10px; resize: vertical;
  border: 1px solid var(--border-strong); background: var(--bg); color: var(--text);
  font: inherit; font-size: 16px; line-height: 1.45; /* 16px prevents iOS zoom */
}
.clip-menu textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 25%, transparent); }
.clip-actions { display: flex; align-items: center; gap: 6px; }
.menu .clip-actions .btn { margin-top: 0; }

/* ---------- Service notes (popover) ---------- */
.menu.note-pop { width: min(340px, calc(100vw - 16px)); max-height: min(60vh, 420px); overflow-y: auto; }
.note-text { font-size: 0.9rem; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; }
.note-text a { color: var(--accent-2); }

/* ---------- Plain links (under the services) ---------- */
.links-section { margin-bottom: 22px; }
.link-list { display: flex; flex-wrap: wrap; gap: 8px; }
.link-pill {
  display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 12px 0 6px; border-radius: 12px;
  background: var(--card); border: 1px solid var(--border); color: var(--text); text-decoration: none;
  font: inherit; font-size: 0.85rem; font-weight: 600; cursor: pointer; transition: border-color .15s, background .15s;
}
.link-pill:hover { border-color: var(--border-strong); background: var(--card-hover); }
.link-pill:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.link-pill .ticon { width: 26px; height: 26px; border-radius: 7px; font-size: 16px; }
.link-pill .ticon .letter { font-size: 12px; }
.link-name { max-width: 180px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.link-pill .drag-handle { width: 16px; height: 26px; margin: 0 -4px 0 0; align-self: center; }
.link-pill.add { padding: 0 12px; border-style: dashed; border-color: var(--border-strong); background: transparent; color: var(--muted); }
.link-pill.add:hover { color: var(--text); border-color: var(--accent); }
.link-pill.add svg { width: 15px; height: 15px; }

/* ---------- Host stats (beside the server header) ---------- */
.stats { display: flex; flex-wrap: wrap; gap: 10px; }
.stat-card { padding: 12px 16px; border-radius: 16px; background: var(--card); border: 1px solid var(--border); min-width: 0; }

.stat-card.system { display: flex; gap: 4px; }
.metric { display: flex; flex-direction: column; align-items: center; gap: 1px; min-width: 84px; padding: 0 4px; text-align: center; }
.metric .gauge { margin-bottom: 5px; }
.metric-label { font-size: 0.68rem; font-weight: 700; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.metric-sub { font-size: 0.78rem; font-weight: 600; font-variant-numeric: tabular-nums; white-space: nowrap; }

.stat-card.sensors { display: flex; flex-direction: column; gap: 5px; width: 250px; }
.stat-card.sensors .metric-label { margin-bottom: 2px; }
.sensor { display: flex; align-items: center; gap: 8px; font-size: 0.8rem; }
.sensor svg { width: 14px; height: 14px; color: var(--muted); }
.sensor-name { flex: 1; min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sensor b { font-variant-numeric: tabular-nums; }
.sensor b.warn { color: var(--amber); }
.sensor b.crit { color: var(--red); }

.stat-card.network { display: flex; flex-direction: column; gap: 6px; width: 270px; }
.net-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.net-note { min-width: 0; font-size: 0.72rem; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: pre; }
.net-speeds { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.net-speed { display: flex; flex-direction: column; min-width: 0; }
.net-label { font-size: 0.72rem; font-weight: 650; }
.net-speed.rx .net-label { color: var(--accent-2); }
.net-speed.tx .net-label { color: var(--accent); }
.net-speed b { font-size: 1.05rem; font-variant-numeric: tabular-nums; white-space: nowrap; }
.net-graph svg { display: block; width: 100%; height: 30px; overflow: visible; }
.net-graph .area { fill: color-mix(in srgb, var(--accent-2) 18%, transparent); stroke: none; }
.net-graph polyline { vector-effect: non-scaling-stroke; stroke-width: 1.5; }
.net-graph .rx { stroke: var(--accent-2); }
.net-graph .tx { stroke: var(--accent); }

/* Ring gauge (percent in the middle) or an icon badge, same size. */
.gauge { --c: var(--accent-2); position: relative; width: 46px; height: 46px; flex-shrink: 0; display: grid; place-items: center; }
.gauge.warn { --c: var(--amber); }
.gauge.crit { --c: var(--red); }
.gauge svg { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); stroke-width: 3.5; }
.gauge .track { stroke: color-mix(in srgb, var(--text) 10%, transparent); }
.gauge .value { stroke: var(--c); transition: stroke-dasharray .6s ease; }
.gauge span { font-size: 0.8rem; font-weight: 750; font-variant-numeric: tabular-nums; }
.gauge:is(.warn, .crit) span { color: var(--c); }
.gauge.badge { border-radius: 50%; color: var(--c); background: color-mix(in srgb, var(--c) 14%, transparent); }
.gauge.badge svg { position: static; width: 20px; height: 20px; transform: none; stroke-width: 2; }

/* Container CPU / memory / network on Docker cards */
.card .usage { display: flex; flex-wrap: wrap; gap: 6px; }
.usage-item {
  display: inline-flex; align-items: baseline; gap: 6px; padding: 4px 9px; border-radius: 8px;
  background: color-mix(in srgb, var(--text) 5%, transparent); font-size: 0.75rem; white-space: pre;
}
.usage-label { font-size: 0.65rem; font-weight: 700; letter-spacing: .05em; color: var(--muted); }
.usage-value { font-weight: 600; font-variant-numeric: tabular-nums; }

/* ---------- Edit mode ---------- */
.drag-handle {
  position: relative; z-index: 2; display: inline-grid; place-items: center;
  width: 22px; align-self: stretch; margin-left: -6px; border-radius: 8px;
  color: var(--muted); cursor: grab; touch-action: none; user-select: none;
}
.drag-handle:hover { color: var(--text); background: var(--card-hover); }
.drag-handle svg { stroke-width: 3.2; }
.drag-placeholder { opacity: 0.35; border-style: dashed !important; }
.drag-ghost {
  position: fixed !important; z-index: 300; margin: 0; pointer-events: none;
  animation: none !important; transform: rotate(1.5deg) scale(1.03) !important;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.55) !important; opacity: 0.96;
  border-color: var(--accent) !important; background: var(--bg-2) !important;
}
body.editing .card[data-id] { border-color: color-mix(in srgb, var(--accent) 30%, var(--border)); }
body.editing main { padding-bottom: 110px; }

.edit-dock {
  position: fixed; left: 50%; bottom: max(16px, env(safe-area-inset-bottom)); z-index: 30;
  transform: translateX(-50%);
  display: flex; align-items: center; gap: 8px; padding: 8px;
  background: color-mix(in srgb, var(--bg-2) 85%, transparent);
  backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border: 1px solid var(--border-strong); border-radius: 18px;
  box-shadow: 0 20px 50px -15px rgba(0, 0, 0, 0.6);
  animation: sheet .25s ease;
  max-width: calc(100vw - 20px);
}
.dock-hint { font-size: 0.8rem; color: var(--muted); padding: 0 8px; white-space: nowrap; }

/* ---------- Unlisted / hidden containers ---------- */
.show-hidden { margin-top: 14px; }
.card.is-hidden { opacity: 0.6; }
.card.is-hidden:hover { opacity: 1; }

/* ---------- Lock screen ---------- */
.lock-screen {
  position: fixed; inset: 0; z-index: 500; display: grid; place-items: center; padding: 20px;
  background: var(--bg);
}
.lock-screen::before {
  content: ''; position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(500px circle at 50% 30%, color-mix(in srgb, var(--accent) 22%, transparent), transparent 60%);
}
.lock-card {
  position: relative; width: min(360px, 100%); display: flex; flex-direction: column; align-items: center; gap: 12px;
  padding: 28px 24px; border-radius: 22px; background: var(--card); border: 1px solid var(--border-strong);
  box-shadow: var(--shadow); text-align: center;
}
.lock-card .logo { width: 56px; height: 56px; border-radius: 16px; }
.lock-card h2 { margin: 4px 0 0; }
.lock-card p { margin: 0; }
.lock-card input {
  width: 100%; height: 46px; padding: 0 14px; border-radius: 12px; text-align: center;
  border: 1px solid var(--border-strong); background: var(--bg); color: var(--text); font: inherit; font-size: 16px;
}
.lock-card input:focus { outline: none; border-color: var(--accent); }
.lock-card .btn { width: 100%; height: 46px; }

/* ---------- Toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: max(20px, env(safe-area-inset-bottom)); z-index: 100;
  transform: translate(-50%, 30px); opacity: 0; pointer-events: none;
  padding: 10px 16px; border-radius: 12px; font-size: 0.9rem; font-weight: 600;
  background: var(--text); color: var(--bg); box-shadow: var(--shadow);
  transition: all .25s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.error { background: var(--red); color: #fff; }
/* Sit above the edit toolbar instead of covering it. */
body.editing .toast { bottom: calc(max(16px, env(safe-area-inset-bottom)) + 66px); }

/* ---------- Mobile ---------- */
@media (max-width: 720px) {
  .topbar { flex-wrap: wrap; gap: 10px; padding: 10px 14px; padding-top: max(10px, env(safe-area-inset-top)); }
  .brand { flex: 0 1 auto; margin-right: auto; }
  .search { order: 3; flex-basis: 100%; max-width: none; }
  .search kbd { display: none; }
  #editBtn span { display: none; }
  #editBtn { width: 40px; padding: 0; }
  .favs { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; padding: 12px 14px 4px; }
  .favs::-webkit-scrollbar { display: none; }
  .fav { box-shadow: none; }
  main { padding: 8px 14px 40px; }
  .server-top { padding: 10px 0 14px; }
  .server-head h2 { font-size: 1.25rem; }
  .server-head .server-icon { width: 44px; height: 44px; border-radius: 12px; font-size: 24px; }
  .grid { grid-template-columns: 1fr; gap: 10px; }
  body[data-layout='compact'] #services .grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  body.editing[data-layout='compact'] #services .grid { grid-template-columns: 1fr; }
  body[data-layout='list'] #services .card .links { display: none; }
  .services { gap: 18px; }
  .card { padding: 12px 14px; gap: 10px; }
  .card:hover { transform: none; }
  .icon { width: 42px; height: 42px; }
  .stats { width: 100%; gap: 8px; }
  .stat-card { flex: 1 1 100%; padding: 12px; }
  .stat-card.system { flex-wrap: wrap; justify-content: space-around; row-gap: 12px; }
  .stat-card.sensors, .stat-card.network { width: auto; }
  .metric { min-width: 76px; }
  .gauge { width: 42px; height: 42px; }
  .gauge span { font-size: 0.72rem; }
  .gauge.badge svg { width: 18px; height: 18px; }
  .dock-hint { display: none; }
  .edit-dock { gap: 6px; padding: 6px; }
  .edit-dock .btn { padding: 0 9px; }

  dialog { width: 100vw; max-width: 100vw; margin: auto 0 0; border-radius: 20px 20px 0 0; border-bottom: 0; max-height: 92dvh; }
  .qr-dialog { width: 100vw; }
  dialog[open] { animation: sheet .22s ease; }
  .dialog-foot { padding-bottom: max(18px, env(safe-area-inset-bottom)); }
}
@keyframes sheet { from { transform: translateY(40px); opacity: 0; } }

@media (max-width: 480px) {
  .dock-label { display: none; }
}

@media (min-width: 540px) and (max-width: 720px) {
  .grid { grid-template-columns: 1fr 1fr; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
