/* ==========================================================================
   M3U Panel: a control-room look. Status lamps are the signature element.
   ========================================================================== */
:root {
  --bg: #0f1420;
  --rail: #121a2a;
  --panel: #1a2336;
  --panel-2: #222d45;
  --line: #2d3a57;
  --ink: #eaf0fa;
  --muted: #9aa8c2;
  --faint: #6c7b98;
  --accent: #8b9bff;
  --accent-ink: #0b1020;
  --ok: #3fdcab;
  --warn: #ffbe3d;
  --bad: #ff6f7d;
  --tabbar-h: 62px;
  color-scheme: dark;
}

*, *::before, *::after { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--ink);
  font: 16px/1.5 ui-rounded, "SF Pro Rounded", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  min-height: 100dvh;
}
body.noscroll { overflow: hidden; }
button, input, select, textarea { font: inherit; color: inherit; touch-action: manipulation; }
h1, h2, p { margin: 0; }
h1 { font-size: 1.9rem; font-weight: 700; letter-spacing: -0.02em; line-height: 1.15; }
h2 { font-size: 1.15rem; font-weight: 650; }
code { background: var(--panel-2); border-radius: 6px; padding: .05rem .4rem; font-size: .88em; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
svg { stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---------- Status lamp ---------- */
.lamp { width: 10px; height: 10px; border-radius: 50%; background: var(--faint); flex: none; display: inline-block; }
.lamp.ok   { background: var(--ok);   box-shadow: 0 0 0 3px rgba(63,220,171,.15), 0 0 12px rgba(63,220,171,.65); }
.lamp.warn { background: var(--warn); box-shadow: 0 0 0 3px rgba(255,190,61,.15), 0 0 12px rgba(255,190,61,.6); }
.lamp.bad  { background: var(--bad);  box-shadow: 0 0 0 3px rgba(255,111,125,.15), 0 0 12px rgba(255,111,125,.6); }
.lamp.busy { background: var(--warn); animation: breathe 1.1s ease-in-out infinite; }
@keyframes breathe { 50% { opacity: .3; } }

/* ---------- Loading ---------- */
.spinner { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; flex: none; display: inline-block; }
.spinner.sm { width: 16px; height: 16px; }
.spinner.lg { width: 36px; height: 36px; border-width: 3px; }
@keyframes spin { to { transform: rotate(360deg); } }

.topbar { position: fixed; top: env(safe-area-inset-top, 0px); left: 0; right: 0; height: 3px; z-index: 80; overflow: hidden; opacity: 0; transition: opacity .2s; pointer-events: none; }
.topbar.on { opacity: 1; }
.topbar::before { content: ""; position: absolute; top: 0; bottom: 0; width: 40%; background: var(--accent); border-radius: 3px; animation: slide 1.1s ease-in-out infinite; }
@keyframes slide { 0% { left: -40%; } 100% { left: 100%; } }

.boot { position: fixed; left: 0; top: 0; right: 0; bottom: 0; z-index: 70; background: var(--bg); display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; color: var(--muted); }

.skeleton { background: linear-gradient(90deg, var(--panel) 0%, var(--panel-2) 50%, var(--panel) 100%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite; border-radius: 10px; }
.skeleton.row { height: 66px; border-radius: 0; }
.skeleton.block { height: 44px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.progress { margin: 0 0 14px; }
.progress-track { height: 8px; background: var(--panel-2); border-radius: 99px; overflow: hidden; margin-bottom: 6px; }
.progress-track span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 99px; transition: width .25s ease; }

/* ---------- Controls ---------- */
.field { display: grid; gap: 6px; font-weight: 600; font-size: .92rem; }
.field.wide, .form-grid .wide { grid-column: 1 / -1; }
input, select, textarea {
  width: 100%; min-height: 46px; padding: .6rem .8rem;
  background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  font-size: 16px; /* 16px stops iPhone Safari from zooming into the field */
  -webkit-appearance: none; appearance: none; font-weight: 400;
}
textarea { resize: vertical; min-height: 130px; line-height: 1.45; }
select {
  padding-right: 2.2rem;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8' fill='none' stroke='%239aa8c2' stroke-width='1.8' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpath d='M1 1.5l5 5 5-5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right .85rem center;
}
input[type="search"]::-webkit-search-cancel-button { -webkit-appearance: none; }
input:focus-visible, select:focus-visible, textarea:focus-visible,
.btn:focus-visible, .icon-btn:focus-visible, .device:focus-visible, button:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: .55rem 1.1rem; cursor: pointer;
  font-weight: 650; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px;
  -webkit-appearance: none; appearance: none; position: relative;
}
.btn svg { width: 18px; height: 18px; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.danger  { background: rgba(255,111,125,.12); border-color: rgba(255,111,125,.55); color: var(--bad); }
.btn.ghost   { background: transparent; }
.btn.block   { width: 100%; }
.btn:active  { transform: scale(.98); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.loading { color: transparent !important; pointer-events: none; }
.btn.loading::after { content: ""; position: absolute; left: 50%; top: 50%; width: 18px; height: 18px; margin: -9px 0 0 -9px; border-radius: 50%; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; animation: spin .8s linear infinite; }
.btn.primary.loading::after { border-color: rgba(11,16,32,.25); border-top-color: var(--accent-ink); }

.icon-btn { width: 44px; height: 44px; display: inline-grid; place-items: center; background: transparent; border: 0; border-radius: 12px; cursor: pointer; color: var(--muted); }
.icon-btn:active { background: var(--panel-2); }

.seg { display: inline-grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 4px; gap: 4px; }
.seg button { min-height: 40px; padding: 0 .9rem; border: 0; border-radius: 10px; background: transparent; color: var(--muted); font-weight: 650; cursor: pointer; }
.seg button.active { background: var(--panel-2); color: var(--ink); box-shadow: inset 0 0 0 1px var(--line); }

.form-error { color: var(--bad); min-height: 1.4em; font-size: .92rem; }

/* ---------- Signed-in account ---------- */
.who { color: var(--muted); font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin: 0; }
.who b { color: var(--ink); font-weight: 650; }
.mobilebar .who { margin-left: auto; margin-right: 4px; max-width: 42%; }

/* ---------- Brand, login ---------- */
.brand { display: inline-flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; letter-spacing: -0.01em; }
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: calc(20px + env(safe-area-inset-top, 0px)) 16px calc(20px + env(safe-area-inset-bottom, 0px)); }
.login-card { width: min(400px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 24px; padding: 28px 24px; display: grid; gap: 16px; }

/* ---------- Layout ---------- */
.shell { display: grid; grid-template-columns: 250px minmax(0, 1fr); min-height: 100vh; min-height: 100dvh; }
.rail { position: sticky; top: 0; height: 100vh; background: var(--rail); border-right: 1px solid var(--line); padding: 26px 16px 20px; display: flex; flex-direction: column; gap: 28px; }
.rail-nav { display: grid; gap: 4px; align-content: start; flex: 1; }
.rail-nav button { display: flex; align-items: center; gap: 12px; min-height: 46px; padding: 0 14px; border: 0; border-radius: 12px; background: transparent; color: var(--muted); font-weight: 600; cursor: pointer; text-align: left; }
.rail-nav button svg { width: 20px; height: 20px; }
.rail-nav button:hover { background: var(--panel); color: var(--ink); }
.rail-nav button.active { background: var(--panel-2); color: var(--ink); }
.main { min-width: 0; }
.content { max-width: 940px; padding: 36px 40px 64px; }
.mobilebar, .tabbar { display: none; }

.view > * + *, [data-pane] > * + *, .view-stack > * + * { margin-top: 16px; }
#bulk-form > * + * { margin-top: 14px; }
.view-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 20px; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-actions { grid-column: 1 / -1; }
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.search { position: relative; flex: 1 1 220px; display: block; }
.search svg { position: absolute; left: 14px; top: 50%; width: 18px; height: 18px; margin-top: -9px; color: var(--faint); pointer-events: none; }
.search input { padding-left: 42px; }
.toolbar select { width: auto; min-width: 150px; }

/* ---------- Filter chips ---------- */
.chips { display: flex; gap: 8px; overflow-x: auto; -webkit-overflow-scrolling: touch; padding-bottom: 2px; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line); background: var(--panel); color: var(--muted); font-weight: 650; cursor: pointer; }
.chip b { font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.chip[aria-pressed="true"] { background: var(--ink); color: var(--bg); border-color: var(--ink); }
.chip[aria-pressed="true"] b { color: var(--bg); }

/* ---------- Grouped list (users, packages) ---------- */
.device-list { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; overflow: hidden; }
.device { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 14px; width: 100%; min-height: 66px; padding: 12px 18px; border: 0; background: transparent; text-align: left; cursor: pointer; }
.device + .device, .device + .list-row, .list-row + .list-row, .skeleton.row + .skeleton.row { border-top: 1px solid var(--line); }
.device:hover { background: rgba(255,255,255,.03); }
.device:active { background: var(--panel-2); }
.device-main, .device-side { display: grid; min-width: 0; }
.device-name { font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.device-note { color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-height: 1.3em; }
.device-side { text-align: right; justify-items: end; }
.device-date { color: var(--faint); font-size: .85rem; font-variant-numeric: tabular-nums; }
.state { font-weight: 650; font-size: .92rem; }
.state.active { color: var(--ok); } .state.expiring { color: var(--warn); }
.state.expired, .state.disabled { color: var(--bad); } .state.unknown { color: var(--muted); }
.list-row { display: flex; gap: 16px; align-items: baseline; padding: 14px 18px; }
.list-row .id { color: var(--faint); font-variant-numeric: tabular-nums; min-width: 4.5ch; }
.empty { padding: 36px 20px; text-align: center; display: grid; gap: 12px; justify-items: center; }
.empty p { max-width: 36ch; color: var(--muted); }
.empty .row-actions { display: flex; gap: 10px; flex-wrap: wrap; justify-content: center; }

/* ---------- Result panels ---------- */
.facts { display: grid; grid-template-columns: max-content minmax(0, 1fr); gap: 10px 20px; margin: 0; }
.facts dt { color: var(--muted); }
.facts dd { margin: 0; text-align: right; overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.url-box { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .82rem; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 12px; overflow-wrap: anywhere; line-height: 1.45; }
.notice { border-radius: 12px; padding: 10px 14px; font-size: .92rem; background: rgba(255,190,61,.12); border: 1px solid rgba(255,190,61,.45); color: var(--warn); }
.success-line { display: flex; align-items: center; gap: 10px; font-weight: 650; }
.fail-list { margin: 10px 0 0; padding-left: 1.1rem; color: var(--muted); font-size: .9rem; }

/* ---------- Server status ---------- */
.server-list { display: grid; gap: 14px; }
.server { background: var(--panel); border: 1px solid var(--line); border-radius: 20px; padding: 18px 20px; display: grid; gap: 14px; }
.server-head { display: flex; align-items: center; gap: 14px; }
.server-head .grow { flex: 1; min-width: 0; }
.server-name { font-weight: 700; }
.server-host { color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.steps { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.step { display: grid; grid-template-columns: 26px minmax(0, 1fr) auto auto; gap: 10px; align-items: start; padding: 8px 0; border-top: 1px solid var(--line); }
.step:first-child { border-top: 0; }
.mark { width: 22px; height: 22px; display: inline-grid; place-items: center; border-radius: 50%; }
.mark svg { width: 15px; height: 15px; stroke-width: 2.6; }
.mark.ok { background: rgba(63,220,171,.16); color: var(--ok); }
.mark.bad { background: rgba(255,111,125,.16); color: var(--bad); }
.mark.pending { border: 2px solid var(--line); }
.mark.dim { color: var(--faint); }
.step-main { display: grid; min-width: 0; }
.step-err { color: var(--bad); font-size: .88rem; }
.step-meta { color: var(--muted); font-size: .88rem; font-variant-numeric: tabular-nums; text-align: right; }
.server-foot { color: var(--muted); font-size: .9rem; }

/* ---------- Sheet (device details) ---------- */
.sheet-backdrop { position: fixed; left: 0; top: 0; right: 0; bottom: 0; z-index: 60; background: rgba(5,8,15,.66); -webkit-backdrop-filter: blur(4px); backdrop-filter: blur(4px); display: flex; align-items: flex-end; justify-content: center; }
.sheet { width: 100%; max-width: 560px; max-height: 90vh; max-height: 90dvh; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; background: var(--panel); border: 1px solid var(--line); border-bottom: 0; border-radius: 26px 26px 0 0; padding: 8px 20px calc(24px + env(safe-area-inset-bottom, 0px)); animation: rise .22s ease-out; }
@keyframes rise { from { transform: translateY(24px); opacity: .4; } to { transform: none; opacity: 1; } }
.sheet-head { position: sticky; top: 0; z-index: 1; background: var(--panel); display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 10px 0 8px; }
.sheet-head h2 { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sheet-body { display: grid; gap: 22px; padding-top: 6px; }
.sheet-status { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 1.05rem; }
.group { display: grid; gap: 12px; }
.group-title { font-weight: 650; color: var(--muted); font-size: .9rem; }
.inline { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 10px; }
.pw-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.pw-row .v { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; overflow-wrap: anywhere; }

/* ---------- Toast ---------- */
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translate(-50%, 12px); width: max-content; max-width: min(440px, calc(100vw - 32px)); padding: 12px 16px; border-radius: 14px; background: var(--panel-2); border: 1px solid var(--line); box-shadow: 0 10px 30px rgba(0,0,0,.45); opacity: 0; pointer-events: none; transition: opacity .18s, transform .18s; z-index: 90; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast.success { border-color: rgba(63,220,171,.6); }
.toast.error { border-color: rgba(255,111,125,.7); color: #ffd3d8; }

/* ==========================================================================
   Phones and tablets
   ========================================================================== */
@media (max-width: 899px) {
  .shell { display: block; }
  .rail { display: none; }
  .mobilebar {
    display: flex; align-items: center; justify-content: space-between;
    position: sticky; top: 0; z-index: 20;
    padding: calc(8px + env(safe-area-inset-top, 0px)) calc(12px + env(safe-area-inset-right, 0px)) 8px calc(16px + env(safe-area-inset-left, 0px));
    background: rgba(15,20,32,.82); -webkit-backdrop-filter: saturate(1.4) blur(18px); backdrop-filter: saturate(1.4) blur(18px);
    border-bottom: 1px solid var(--line);
  }
  .content { padding: 18px calc(16px + env(safe-area-inset-right, 0px)) calc(var(--tabbar-h) + 32px + env(safe-area-inset-bottom, 0px)) calc(16px + env(safe-area-inset-left, 0px)); }
  h1 { font-size: 1.65rem; }

  .tabbar {
    display: grid; grid-template-columns: repeat(4, 1fr);
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding: 6px calc(8px + env(safe-area-inset-right, 0px)) calc(6px + env(safe-area-inset-bottom, 0px)) calc(8px + env(safe-area-inset-left, 0px));
    background: rgba(18,26,42,.88); -webkit-backdrop-filter: saturate(1.4) blur(18px); backdrop-filter: saturate(1.4) blur(18px);
    border-top: 1px solid var(--line);
  }
  .tabbar button { display: grid; justify-items: center; gap: 2px; padding: 6px 0 4px; min-height: 50px; border: 0; background: transparent; color: var(--faint); font-size: .72rem; font-weight: 650; cursor: pointer; }
  .tabbar button svg { width: 24px; height: 24px; }
  .tabbar button.active { color: var(--accent); }

  .toast { bottom: calc(var(--tabbar-h) + 16px + env(safe-area-inset-bottom, 0px)); }
}

@media (max-width: 640px) {
  .form-grid { grid-template-columns: 1fr; }
  .toolbar select { flex: 1 1 140px; }
  .toolbar .btn { flex: 1 1 auto; }
  .panel { padding: 16px; }
  .device { padding: 12px 14px; gap: 12px; }
  .step { grid-template-columns: 26px minmax(0, 1fr) auto; }
  .step-meta.ms { display: none; }
  .sheet { border-radius: 24px 24px 0 0; }
}

@media (min-width: 720px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border: 1px solid var(--line); border-radius: 24px; max-height: 86vh; }
}

@media (prefers-reduced-motion: reduce) {
  .skeleton, .lamp.busy, .topbar::before, .sheet { animation: none; }
  .progress-track span, .toast { transition: none; }
}

/* ==========================================================================
   Account chip, credits, servers, credentials
   ========================================================================== */

/* ---------- Account chip (initial in a colour taken from the name) ---------- */
.account { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar { width: 34px; height: 34px; border-radius: 50%; display: grid; place-items: center; flex: none; color: #0b1020; font-weight: 750; font-size: 1rem; box-shadow: inset 0 0 0 2px rgba(255,255,255,.28); }
.account-name { font-weight: 650; letter-spacing: -0.01em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.rail .account { padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 16px; }

/* ---------- Credits ---------- */
.rail-foot { display: grid; gap: 10px; }
.credits {
  display: flex; flex-direction: column; align-items: flex-start; gap: 2px; width: 100%;
  padding: 12px 16px; text-align: left; cursor: pointer;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
}
.credits-label { color: var(--muted); font-size: .82rem; font-weight: 600; }
.credits-value { font-size: 1.7rem; font-weight: 750; letter-spacing: -0.02em; line-height: 1.1; font-variant-numeric: tabular-nums; }
.credits.warn .credits-value { color: var(--warn); }
.credits.bad  .credits-value { color: var(--bad); }
.credits.busy .credits-value { animation: breathe 1s ease-in-out infinite; }
/* Phone pill: centred in the bar, same height as the account pill next to it. */
.credits.compact { flex-direction: row-reverse; align-items: center; justify-content: center; gap: 5px; width: auto; height: 36px; min-height: 0; padding: 0 12px; border-radius: 99px; line-height: 1; }
.credits.compact .credits-value { font-size: 1.02rem; line-height: 1; }
.credits.compact .credits-label { font-size: .78rem; line-height: 1; transform: translateY(1px); }
.cost { color: var(--muted); font-size: .9rem; margin: 0; }
.cost.bad { color: var(--bad); }

/* ---------- Phone top bar ---------- */
.mobile-right { display: flex; align-items: center; gap: 8px; min-width: 0; }
.mobilebar .account { gap: 8px; height: 36px; padding: 0 12px 0 3px; background: var(--panel); border: 1px solid var(--line); border-radius: 99px; }
.mobilebar .avatar { width: 28px; height: 28px; font-size: .85rem; }
.mobilebar .account-name { max-width: 76px; font-size: .92rem; line-height: 1; }
@media (max-width: 440px) {
  .brand-text { display: none; }
}

/* ---------- Server column in the users list (wide screens only) ---------- */
.device-server { display: none; min-width: 0; }
.server-tag { display: inline-block; max-width: 100%; padding: 3px 10px; border-radius: 99px; background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); font-size: .82rem; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (min-width: 900px) {
  .device { grid-template-columns: auto minmax(0, 1fr) minmax(0, 170px) auto; }
  .device-server { display: block; }
}

/* ---------- Credentials in the user sheet ---------- */
.cred { display: grid; gap: 10px; }
.cred-row { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 6px; background: var(--bg); border: 1px solid var(--line); border-radius: 14px; padding: 6px 6px 6px 14px; }
.cred-text { display: grid; min-width: 0; padding: 4px 0; }
.cred-label { color: var(--muted); font-size: .8rem; }
.cred-value { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 1.02rem; letter-spacing: .02em; overflow-wrap: anywhere; }
.cred-actions { display: flex; }
.cred-actions .icon-btn { color: var(--ink); }
.sheet-title-sub { color: var(--muted); font-size: .88rem; }
.sheet-head h2 { font-size: 1.3rem; font-weight: 700; letter-spacing: -0.01em; }

/* ---------- Server cards and stats ---------- */
.server-open { display: flex; align-items: center; gap: 10px; flex: 1; min-width: 0; padding: 0; border: 0; background: transparent; text-align: left; cursor: pointer; color: inherit; }
.server-open .txt { display: grid; min-width: 0; flex: 1; }
.server-open svg { width: 18px; height: 18px; color: var(--faint); flex: none; }
.server-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.stats { display: flex; flex-wrap: wrap; gap: 6px 0; }
.stat { display: grid; padding: 0 20px 0 0; margin-right: 20px; border-right: 1px solid var(--line); }
.stat:last-child { border-right: 0; margin-right: 0; padding-right: 0; }
.stat b { font-size: 1.35rem; font-weight: 700; font-variant-numeric: tabular-nums; line-height: 1.2; }
.stat span { color: var(--muted); font-size: .85rem; }
.mini-list { background: var(--bg); border: 1px solid var(--line); border-radius: 14px; overflow: hidden; }
.mini-row { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: center; gap: 12px; width: 100%; min-height: 52px; padding: 8px 14px; border: 0; background: transparent; text-align: left; cursor: pointer; }
.mini-row + .mini-row { border-top: 1px solid var(--line); }
.mini-row:active { background: var(--panel-2); }
.mini-id { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.mini-name { flex: none; max-width: 62%; font-weight: 650; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-note { min-width: 0; color: var(--muted); font-size: .88rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mini-row.dim { opacity: .55; }
.mini-state { color: var(--muted); font-size: .88rem; text-align: right; }
.mini-state.ok { color: var(--ok); }
.mini-state.bad { color: var(--bad); }
.mini-empty { padding: 16px; color: var(--muted); text-align: center; }

@media (max-width: 640px) {
  .server-actions .btn { flex: 1 1 auto; }
  .stat { padding-right: 14px; margin-right: 14px; }
}
@media (prefers-reduced-motion: reduce) { .credits.busy .credits-value { animation: none; } }

/* ---------- Server user rows on a phone: state goes under the name ---------- */
@media (max-width: 640px) {
  .mini-row { grid-template-columns: auto minmax(0, 1fr); row-gap: 2px; }
  .mini-state { grid-column: 2; text-align: left; }
}

/* ---------- Five tabs on a phone ---------- */
@media (max-width: 899px) {
  .tabbar { grid-template-columns: repeat(5, 1fr); }
  .tabbar button { font-size: .68rem; }
}

/* ---------- History ---------- */
.day-head { padding: 9px 18px; background: var(--panel-2); color: var(--muted); font-size: .82rem; font-weight: 650; }
.tx { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 14px; align-items: start; padding: 13px 18px; }
.tx + .tx, .day-head + .tx, .tx + .day-head { border-top: 1px solid var(--line); }
.tx .lamp { margin-top: 7px; }
.tx-main { display: grid; min-width: 0; gap: 2px; }
.tx-line { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 10px; min-width: 0; }
.tx-title { font-weight: 650; }
.tx-user { font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: .9rem; color: var(--muted); overflow-wrap: anywhere; }
.tx-detail { color: var(--muted); font-size: .88rem; overflow-wrap: anywhere; }
.tx-side { display: grid; justify-items: end; gap: 2px; text-align: right; }
.tx-credits { font-weight: 700; font-variant-numeric: tabular-nums; }
.tx-credits.neg { color: var(--warn); }
.tx-credits.pos { color: var(--ok); }
.tx-time { color: var(--faint); font-size: .82rem; font-variant-numeric: tabular-nums; }
#history-more { margin-top: 14px; }

/* ---------- Performance and small additions ---------- */
.device { content-visibility: auto; contain-intrinsic-size: auto 66px; }
.skeleton.card { height: 130px; border-radius: 20px; }
.url-box.spaced { margin: 14px 0; }
.more-row { width: 100%; padding: 15px; border: 0; border-top: 1px solid var(--line); background: transparent; color: var(--accent); font-weight: 650; cursor: pointer; }
.more-row:active { background: var(--panel-2); }

.address { margin: -12px 0 0; overflow-wrap: anywhere; font-size: .92rem; }
