/* 云端浏览器 — shared look. Light + dark follow the device setting. */
:root {
  --bg: #f3f5f9;
  --bg-grad: radial-gradient(1200px 500px at 50% -200px, #e3ebff 0%, rgba(227,235,255,0) 70%);
  --card: #ffffff;
  --card-2: #f7f8fb;
  --text: #141824;
  --text-2: #3d4454;
  --muted: #6b7385;
  --line: #e4e7ee;
  --line-2: #d5d9e3;
  --primary: #2f66e6;
  --primary-2: #2556d8;
  --primary-soft: #e8efff;
  --primary-text: #ffffff;
  --danger: #d93a3a;
  --danger-soft: #fdecec;
  --ok: #17924a;
  --ok-soft: #e4f6ec;
  --warn: #b26b00;
  --warn-soft: #fff4e0;
  --busy: #8a5cf6;
  --busy-soft: #f1ebff;
  --shadow-sm: 0 1px 2px rgba(20,24,36,.06);
  --shadow: 0 1px 2px rgba(20,24,36,.05), 0 6px 20px rgba(20,24,36,.06);
  --shadow-lg: 0 12px 40px rgba(20,24,36,.18);
  --ring: 0 0 0 3px rgba(47,102,230,.25);
  --radius: 14px;
  --radius-sm: 10px;
  --bar: #0f1218;
  --bar-2: #1a1f29;
  --bar-line: #2a303c;
  --bar-text: #e9ecf2;
  --bar-muted: #9aa3b5;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0c0f14;
    --bg-grad: radial-gradient(1200px 500px at 50% -200px, #16213d 0%, rgba(22,33,61,0) 70%);
    --card: #151922;
    --card-2: #1b202b;
    --text: #e9ecf2;
    --text-2: #c4cad6;
    --muted: #8f98ab;
    --line: #252b37;
    --line-2: #333a48;
    --primary: #5b8cff;
    --primary-2: #4a7cf2;
    --primary-soft: #1a2747;
    --danger: #ff6b6b;
    --danger-soft: #3a1d20;
    --ok: #3ccf7a;
    --ok-soft: #14301f;
    --warn: #f0b04a;
    --warn-soft: #3a2c12;
    --busy: #a98bff;
    --busy-soft: #2a2145;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.3);
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 8px 24px rgba(0,0,0,.25);
    --shadow-lg: 0 16px 48px rgba(0,0,0,.5);
    --ring: 0 0 0 3px rgba(91,140,255,.35);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font: 15px/1.55 -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  min-height: 100vh;
  background: var(--bg-grad), var(--bg);
  background-repeat: no-repeat;
}
a { color: var(--primary); text-decoration: none; }
h1, h2, h3 { line-height: 1.25; margin: 0; letter-spacing: -.01em; }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
::selection { background: var(--primary-soft); }

/* ---------- layout ---------- */
.wrap { max-width: 1040px; margin: 0 auto; padding: 20px 20px 48px; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 12px;
  padding: 10px 20px; padding-top: max(10px, env(safe-area-inset-top));
  background: var(--card); /* older phones */
  background: color-mix(in srgb, var(--card) 82%, transparent);
  backdrop-filter: saturate(1.6) blur(14px); -webkit-backdrop-filter: saturate(1.6) blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar .inner { max-width: 1000px; margin: 0 auto; width: 100%; display: flex; align-items: center; gap: 12px; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 16px; color: var(--text); white-space: nowrap; }
.brand img { width: 30px; height: 30px; border-radius: 8px; box-shadow: var(--shadow-sm); }
.spacer { flex: 1; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.stack > * + * { margin-top: 12px; }

/* ---------- buttons ---------- */
button, .btn {
  font: inherit; font-weight: 550; font-size: 14px;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 40px; padding: 0 14px;
  border-radius: var(--radius-sm); border: 1px solid var(--line-2);
  background: var(--card); color: var(--text);
  cursor: pointer; user-select: none; -webkit-user-select: none; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s, box-shadow .15s, transform .08s, opacity .15s;
  text-decoration: none;
}
button:hover, .btn:hover { border-color: var(--muted); }
button:active, .btn:active { transform: scale(.97); }
button:focus-visible, .btn:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: none; box-shadow: var(--ring); }
button.primary, .btn.primary { background: var(--primary); border-color: var(--primary); color: var(--primary-text); box-shadow: 0 1px 2px rgba(37,86,216,.3); }
button.primary:hover, .btn.primary:hover { background: var(--primary-2); border-color: var(--primary-2); }
button.ghost, .btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
button.ghost:hover, .btn.ghost:hover { background: var(--card-2); }
button.soft, .btn.soft { background: var(--primary-soft); border-color: transparent; color: var(--primary); }
button.danger, .btn.danger { color: var(--danger); }
button.danger:hover { border-color: var(--danger); background: var(--danger-soft); }
button.danger.solid { background: var(--danger); border-color: var(--danger); color: #fff; }
button.sm, .btn.sm { min-height: 34px; padding: 0 11px; font-size: 13px; border-radius: 9px; }
button.lg, .btn.lg { min-height: 48px; padding: 0 20px; font-size: 15px; border-radius: 12px; }
button.block, .btn.block { width: 100%; }
button.icon { padding: 0; width: 40px; }
button:disabled, .btn[aria-disabled="true"] { opacity: .5; cursor: default; transform: none; pointer-events: none; }
.mini-spin { width: 15px; height: 15px; border-radius: 50%; border: 2px solid currentColor; border-right-color: transparent; animation: spin .7s linear infinite; flex: none; }
button.busy { pointer-events: none; opacity: .85; }

/* ---------- forms ---------- */
.field { display: block; margin-top: 14px; }
.field > span { display: block; font-size: 13px; font-weight: 600; color: var(--text-2); margin-bottom: 6px; }
.field > small, .hint { display: block; font-size: 12.5px; color: var(--muted); margin-top: 6px; }
input, select, textarea {
  font: inherit; font-size: 15px; width: 100%;
  padding: 10px 12px; min-height: 44px;
  border: 1px solid var(--line-2); border-radius: var(--radius-sm);
  background: var(--card); color: var(--text);
  transition: border-color .15s, box-shadow .15s;
}
input::placeholder, textarea::placeholder { color: var(--muted); opacity: .75; }
input:focus, select:focus, textarea:focus { border-color: var(--primary); outline: none; box-shadow: var(--ring); }
textarea { resize: vertical; min-height: 72px; line-height: 1.5; }
.input-wrap { position: relative; }
.input-wrap input { padding-right: 46px; }
.input-wrap .eye { position: absolute; right: 2px; top: 2px; bottom: 2px; width: 42px; min-height: 0; border: 0; background: transparent; color: var(--muted); }
.input-wrap .eye:hover { color: var(--text); }
.suffix-wrap { position: relative; }
.suffix-wrap input { padding-right: 52px; }
.suffix-wrap em { position: absolute; right: 12px; top: 50%; transform: translateY(-50%); font-style: normal; color: var(--muted); font-size: 13px; pointer-events: none; }
.err { color: var(--danger); font-size: 13.5px; min-height: 1.4em; margin: 10px 0 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
@media (max-width: 520px) { .grid2 { grid-template-columns: 1fr; } }

/* choice tiles (radio cards) */
.choices { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.choice { position: relative; display: flex; gap: 10px; align-items: flex-start; padding: 12px; border: 1.5px solid var(--line-2); border-radius: 12px; cursor: pointer; background: var(--card); transition: border-color .15s, background .15s; }
.choice input { position: absolute; opacity: 0; pointer-events: none; }
.choice b { display: block; font-size: 14px; }
.choice small { display: block; color: var(--muted); font-size: 12.5px; line-height: 1.4; margin-top: 2px; }
.choice .i { width: 22px; height: 22px; margin-top: 1px; color: var(--muted); }
.choice:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); }
.choice:has(input:checked) .i { color: var(--primary); }
.choice:has(input:focus-visible) { box-shadow: var(--ring); }

/* chips (multi select) */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 6px 12px 6px 8px; border-radius: 99px; border: 1.5px solid var(--line-2); cursor: pointer; font-size: 14px; background: var(--card); user-select: none; transition: all .15s; }
.chip input { position: absolute; opacity: 0; pointer-events: none; }
.chip .tick { width: 18px; height: 18px; border-radius: 50%; border: 1.5px solid var(--line-2); display: grid; place-items: center; transition: all .15s; }
.chip .tick svg { width: 12px; height: 12px; stroke: #fff; stroke-width: 3; opacity: 0; }
.chip:has(input:checked) { border-color: var(--primary); background: var(--primary-soft); color: var(--primary); }
.chip:has(input:checked) .tick { background: var(--primary); border-color: var(--primary); }
.chip:has(input:checked) .tick svg { opacity: 1; }
.chip:has(input:focus-visible) { box-shadow: var(--ring); }

/* ---------- cards ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow-sm); }
.muted { color: var(--muted); font-size: 13px; }
.section-head { display: flex; align-items: flex-end; gap: 12px; justify-content: space-between; margin: 8px 0 14px; flex-wrap: wrap; }
.section-head h2 { font-size: 22px; }
.section-head p { margin: 4px 0 0; color: var(--muted); font-size: 14px; }

/* status pill */
.pill { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; font-weight: 600; padding: 3px 10px 3px 8px; border-radius: 99px; background: var(--card-2); color: var(--muted); white-space: nowrap; }
.pill::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; opacity: .9; }
.pill.sleeping::before { opacity: .45; }
.pill.running, .pill.keepalive { background: var(--ok-soft); color: var(--ok); }
.pill.starting { background: var(--primary-soft); color: var(--primary); }
.pill.starting::before, .pill.keepalive::before { animation: pulse 1.2s ease-in-out infinite; }
.pill.in_use { background: var(--busy-soft); color: var(--busy); }
.pill.mine { background: var(--ok-soft); color: var(--ok); }
.badge { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; padding: 2px 8px; border-radius: 6px; background: var(--card-2); color: var(--text-2); font-weight: 550; white-space: nowrap; }
.badge.admin { background: var(--primary-soft); color: var(--primary); }

/* site avatar (letter in a coloured square) */
.site { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; color: #fff; font-weight: 700; font-size: 15px; flex: none; box-shadow: inset 0 0 0 1px rgba(255,255,255,.12); text-transform: uppercase; }
.site.sm { width: 20px; height: 20px; border-radius: 6px; font-size: 11px; }
.sites { display: flex; }
.sites .site + .site { margin-left: -8px; box-shadow: 0 0 0 2.5px var(--card); }
.avatar { width: 32px; height: 32px; border-radius: 50%; display: grid; place-items: center; font-weight: 700; font-size: 13px; color: #fff; background: linear-gradient(135deg, #6f9bff, #2f66e6); flex: none; }

/* segmented control */
.seg { display: inline-flex; padding: 3px; gap: 2px; background: var(--card-2); border: 1px solid var(--line); border-radius: 12px; }
.seg button { min-height: 34px; border: 0; background: transparent; color: var(--muted); border-radius: 9px; padding: 0 14px; font-weight: 600; }
.seg button:hover { color: var(--text); }
.seg button.on { background: var(--card); color: var(--text); box-shadow: var(--shadow-sm); }

/* skeleton */
.skel { position: relative; overflow: hidden; background: var(--card-2); border-radius: 8px; }
.skel::after { content: ""; position: absolute; inset: 0; transform: translateX(-100%); background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--card) 70%, transparent), transparent); animation: shimmer 1.3s infinite; }

/* empty state */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); }
.empty .ill { width: 64px; height: 64px; border-radius: 18px; display: grid; place-items: center; margin: 0 auto 14px; background: var(--primary-soft); color: var(--primary); }
.empty .ill svg { width: 30px; height: 30px; }
.empty h3 { color: var(--text); font-size: 17px; margin-bottom: 6px; }

/* ---------- toast ---------- */
#toasts { position: fixed; left: 50%; transform: translateX(-50%); bottom: max(20px, env(safe-area-inset-bottom)); z-index: 1000; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(92vw, 420px); }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 10px; padding: 11px 16px; border-radius: 12px; background: #1b2030; color: #fff; box-shadow: var(--shadow-lg); font-size: 14px; animation: toastIn .22s ease-out; max-width: 100%; }
.toast.out { animation: toastOut .2s ease-in forwards; }
.toast svg.i { width: 18px; height: 18px; }
.toast.ok svg.i { color: #4ade80; }
.toast.err svg.i { color: #ff8a8a; }
@media (prefers-color-scheme: dark) { .toast { background: #f2f4f8; color: #141824; } .toast.ok svg.i { color: #17924a; } .toast.err svg.i { color: #d93a3a; } }

/* ---------- dialog ---------- */
dialog.dlg { border: 0; padding: 0; background: transparent; color: var(--text); max-width: none; max-height: none; width: 100%; height: 100%; margin: 0; display: none; }
dialog.dlg[open] { display: grid; place-items: center; }
dialog.dlg::backdrop { background: rgba(10,13,20,.5); backdrop-filter: blur(2px); -webkit-backdrop-filter: blur(2px); animation: fade .2s; }
.dlg-box { width: min(440px, calc(100vw - 32px)); max-height: calc(100dvh - 48px); overflow: auto; background: var(--card); border-radius: 18px; box-shadow: var(--shadow-lg); padding: 22px; animation: pop .2s cubic-bezier(.2,.9,.3,1.2); overscroll-behavior: contain; }
.dlg-box.wide { width: min(620px, calc(100vw - 32px)); }
.dlg-box h3 { font-size: 18px; }
.dlg-box .body { color: var(--text-2); margin: 8px 0 0; white-space: pre-line; }
.dlg-box .actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 22px; }
.dlg-head { display: flex; align-items: center; gap: 10px; margin-bottom: 4px; }
.dlg-head .x { margin-left: auto; }
@media (max-width: 600px) {
  dialog.dlg[open] { place-items: end center; }
  .dlg-box { width: 100%; max-height: 92dvh; border-radius: 20px 20px 0 0; padding: 20px 18px max(18px, env(safe-area-inset-bottom)); animation: sheet .26s cubic-bezier(.2,.9,.3,1); }
  .dlg-box.wide { width: 100%; }
  .dlg-box .actions { flex-direction: column-reverse; }
  .dlg-box .actions button { width: 100%; min-height: 46px; }
}

/* ---------- animations ---------- */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: .3; } }
@keyframes shimmer { to { transform: translateX(100%); } }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: scale(.96) translateY(6px); } }
@keyframes sheet { from { transform: translateY(100%); } }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px) scale(.98); } }
@keyframes toastOut { to { opacity: 0; transform: translateY(6px); } }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }
@keyframes rise { from { opacity: 0; transform: translateY(8px); } }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid rgba(255,255,255,.18); border-top-color: #fff; animation: spin .8s linear infinite; }
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; } }

@media (max-width: 600px) {
  .wrap { padding: 16px 16px 40px; }
  .topbar { padding-left: 16px; padding-right: 16px; }
  .section-head h2 { font-size: 20px; }
}

/* keep Save/Cancel visible at the bottom of long forms */
.dlg-box form > .actions { position: sticky; bottom: -22px; margin: 18px -22px -22px; padding: 14px 22px 22px; background: var(--card); border-top: 1px solid var(--line); z-index: 2; }
@media (max-width: 600px) {
  .dlg-box form > .actions { bottom: calc(-1 * max(18px, env(safe-area-inset-bottom))); margin: 18px -18px calc(-1 * max(18px, env(safe-area-inset-bottom))); padding: 12px 18px max(18px, env(safe-area-inset-bottom)); }
}
