/* Personal Hub — shares the Monitor design tokens, lighter layout.
   This is a navigation home, not a dashboard: minimal motion, no charts. */

:root {
  --bg: #0B0D10;
  --surface: #111419;
  --surface-2: #161A20;
  --surface-3: #1C2128;
  --border: rgba(255, 255, 255, 0.07);
  --border-strong: rgba(255, 255, 255, 0.12);
  --text: rgba(255, 255, 255, 0.92);
  --text-2: rgba(255, 255, 255, 0.56);
  --text-3: rgba(255, 255, 255, 0.36);
  --accent: #4C8DF6;
  --accent-soft: rgba(76, 141, 246, 0.14);
  --ok: #3FB950;
  --warn: #D29922;
  --err: #F85149;
  --info: #58A6FF;
  --muted: #6E7681;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --radius-card: 14px;
  --radius-ctl: 9px;
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --dur: 180ms;
  --font: ui-sans-serif, system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  color-scheme: dark;
}

:root[data-theme="light"] {
  --bg: #F5F6F8;
  --surface: #FFFFFF;
  --surface-2: #F0F2F5;
  --surface-3: #E8EBF0;
  --border: rgba(15, 23, 42, 0.08);
  --border-strong: rgba(15, 23, 42, 0.16);
  --text: rgba(15, 23, 42, 0.92);
  --text-2: rgba(15, 23, 42, 0.58);
  --text-3: rgba(15, 23, 42, 0.38);
  --accent: #2E6BE6;
  --accent-soft: rgba(46, 107, 230, 0.10);
  --ok: #1A7F37;
  --warn: #9A6700;
  --err: #CF222E;
  --info: #0969DA;
  --muted: #8C959F;
  --shadow: 0 8px 24px rgba(15, 23, 42, 0.08);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 var(--font);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
}
::selection { background: var(--accent-soft); }
a { color: inherit; text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; animation: none !important; }
}

.hidden { display: none !important; }
.mono { font-family: var(--mono); font-size: 12px; }
.muted { color: var(--text-3); }
.small { font-size: 12px; }

/* ---- header ---- */

.top {
  position: sticky;
  top: 0;
  z-index: 20;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
  padding: 10px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 15px; flex-shrink: 0; }
.brand-mark { color: var(--accent); display: inline-flex; }

.server-status {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 4px 14px;
  border: 1px solid var(--border);
  border-radius: 99px;
  background: var(--surface);
  cursor: pointer;
  transition: border-color var(--dur) ease;
  white-space: nowrap;
  min-width: 0;
  overflow: hidden;
}
.server-status:hover { border-color: var(--border-strong); }
.ss-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--muted); flex-shrink: 0; }
.ss-dot.online { background: var(--ok); }
.ss-dot.offline { background: var(--err); }
.ss-metric { display: inline-flex; gap: 6px; align-items: baseline; font-size: 12.5px; }
#ss-body { display: inline-flex; align-items: center; gap: 12px; min-width: 0; }
.ss-metric b { font-weight: 600; font-variant-numeric: tabular-nums; }
.ss-metric span { color: var(--text-3); font-size: 11px; }
.ss-sep { width: 1px; height: 14px; background: var(--border); flex-shrink: 0; }

.top .spacer { flex: 1; }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px; height: 32px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  color: var(--text-2);
  cursor: pointer;
  transition: background var(--dur) ease, color var(--dur) ease;
  flex-shrink: 0;
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn.active { background: var(--accent-soft); color: var(--accent); }

.search-pill {
  display: flex;
  align-items: center;
  gap: 8px;
  height: 32px;
  padding: 0 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-3);
  cursor: pointer;
  font-size: 13px;
  transition: border-color var(--dur) ease;
  white-space: nowrap;
}
.search-pill:hover { border-color: var(--border-strong); color: var(--text-2); }
.search-pill kbd {
  font-family: var(--mono);
  font-size: 11px;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0 4px;
  background: var(--surface-2);
}

.seg {
  display: inline-flex;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 2px;
  gap: 2px;
  flex-shrink: 0;
}
.seg button {
  border: 0;
  background: transparent;
  color: var(--text-3);
  font-size: 12px;
  font-weight: 550;
  padding: 3px 9px;
  border-radius: 6px;
  cursor: pointer;
  transition: background var(--dur) ease, color var(--dur) ease;
}
.seg button:hover { color: var(--text-2); }
.seg button.active { background: var(--surface-3); color: var(--text); }

/* ---- layout / sections ---- */

.wrap { max-width: 1180px; margin: 0 auto; padding: 24px 24px 80px; }

.hero {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
  flex-wrap: wrap;
}
.hero h1 { font-size: 22px; margin: 0; font-weight: 650; letter-spacing: -0.2px; }
.hero .sub { color: var(--text-2); font-size: 13px; margin-top: 3px; }

.section { margin-bottom: 28px; }
.section-head {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}
.section-head h2 {
  font-size: 12px;
  font-weight: 650;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  color: var(--text-3);
  margin: 0;
}
.section-head .count { color: var(--text-3); font-size: 12px; }

.grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.grid.compact { grid-template-columns: repeat(6, 1fr); }
.list { display: flex; flex-direction: column; gap: 8px; }
@media (max-width: 1100px) { .grid { grid-template-columns: repeat(3, 1fr); } .grid.compact { grid-template-columns: repeat(4, 1fr); } }
@media (max-width: 800px) { .grid { grid-template-columns: repeat(2, 1fr); } .grid.compact { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 520px) { .grid, .grid.compact { grid-template-columns: repeat(2, 1fr); } }

.grid > *, .list > * { min-width: 0; }
@media (max-width: 720px) {
  /* Container names are too wide for phone cards; status stays. */
  .svc .meta > span:not(.st) { display: none; }
  .svc { padding: 12px; }
}
@media (max-width: 560px) {
  .svc { gap: 9px; }
  .svc .ico { width: 30px; height: 30px; border-radius: 8px; }
  .svc .meta .st span { display: none; } /* latency digits: keep the dot */
}

/* ---- service card ---- */

.svc {
  display: flex;
  gap: 12px;
  align-items: center;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 14px;
  min-width: 0;
  position: relative;
  transition: border-color var(--dur) ease, transform var(--dur) ease, background var(--dur) ease;
}
.svc:hover { border-color: var(--border-strong); background: var(--surface-2); }
.svc:active { transform: scale(0.99); }
.svc .ico {
  width: 38px; height: 38px;
  border-radius: 10px;
  background: var(--surface-3);
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-2);
  flex-shrink: 0;
  font-weight: 650;
  font-size: 15px;
  overflow: hidden;
}
.svc .body { min-width: 0; flex: 1; }
.svc .nm, .svc .ds { display: block; } /* spans need block for ellipsis */
.svc .nm {
  font-weight: 600;
  font-size: 13.5px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}
.svc .ds {
  color: var(--text-2);
  font-size: 12px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.svc .meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  flex-shrink: 0;
  font-size: 11.5px;
  color: var(--text-3);
}
.svc .st { display: inline-flex; align-items: center; gap: 5px; }
.svc .st i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); display: inline-block; }
.svc .st.online i { background: var(--ok); }
.svc .st.warning i { background: var(--warn); }
.svc .st.offline i { background: var(--err); }
.svc .st.unknown i { background: var(--muted); }
.svc .st.maintenance i { background: var(--info); }
.svc .st span { font-variant-numeric: tabular-nums; }

.svc.dragging { opacity: 0.45; }
.svc.drag-over { border-color: var(--accent); }
body.editing .svc { cursor: grab; }
body.editing .svc:hover { border-color: var(--accent); }

.fav-toggle {
  position: absolute;
  top: 8px; right: 8px;
  width: 26px; height: 26px;
  border-radius: 7px;
  border: 0;
  background: transparent;
  color: var(--text-3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity var(--dur) ease, color var(--dur) ease;
}
.svc:hover .fav-toggle, .fav-toggle.on { opacity: 1; }
.fav-toggle:hover { color: var(--warn); background: var(--surface-3); }
.fav-toggle.on { color: var(--warn); }
body.editing .fav-toggle { opacity: 1; }

.edit-btns {
  position: absolute;
  top: 8px; left: 8px;
  display: none;
  gap: 4px;
  z-index: 2;
}
body.editing .edit-btns { display: flex; }
.edit-btns .icon-btn {
  width: 26px; height: 26px;
  background: var(--surface);
  border: 1px solid var(--border);
}
.edit-btns .icon-btn:hover { background: var(--surface-3); }
.edit-btns .icon-btn.remove:hover { color: var(--err); border-color: var(--err); }

.editing-hint {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  margin-bottom: 20px;
  font-size: 13px;
  display: flex;
  gap: 12px;
  align-items: center;
  flex-wrap: wrap;
}

/* list layout variant */
.list .svc { padding: 10px 14px; border-radius: 12px; }

/* compact variant */
.grid.compact .svc { padding: 10px; flex-direction: column; text-align: center; gap: 8px; }
.grid.compact .svc .ds, .grid.compact .svc .meta { display: none; }
.grid.compact .svc .nm { justify-content: center; }

/* ---- server offline / events ---- */

.monitor-down {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-2);
  font-size: 12.5px;
}

.events { display: flex; flex-direction: column; }
.event-row {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 8px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.event-row:last-child { border-bottom: 0; }
.event-ico { margin-top: 2px; flex-shrink: 0; display: inline-flex; }
.event-msg { min-width: 0; overflow-wrap: anywhere; }
.event-time { margin-left: auto; color: var(--text-3); font-size: 12px; flex-shrink: 0; padding-left: 8px; }
.tone-ok { color: var(--ok); }
.tone-warn { color: var(--warn); }
.tone-err { color: var(--err); }
.tone-info { color: var(--info); }
.tone-muted { color: var(--muted); }

.events-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-card);
  padding: 14px 16px;
}

/* ---- states ---- */

.state-block {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 8px; padding: 36px 20px; color: var(--text-2); text-align: center;
  grid-column: 1 / -1;
}
.state-block .hint { font-size: 12.5px; color: var(--text-3); }

.skeleton {
  border-radius: 12px;
  background: linear-gradient(90deg, var(--surface) 25%, var(--surface-2) 50%, var(--surface) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.4s infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }

/* ---- palette ---- */

.palette-scrim {
  position: fixed; inset: 0; background: rgba(0,0,0,0.55); z-index: 60;
  border: 0; padding: 0; cursor: default;
}
.palette {
  position: fixed;
  top: 14vh; left: 50%;
  transform: translateX(-50%);
  width: min(560px, 92vw);
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 14px;
  box-shadow: var(--shadow);
  z-index: 61;
  overflow: hidden;
  animation: pop var(--dur) ease;
}
@keyframes pop { from { transform: translateX(-50%) scale(0.98); opacity: 0; } }
.palette input {
  width: 100%;
  height: 48px;
  border: 0;
  border-bottom: 1px solid var(--border);
  background: transparent;
  padding: 0 16px;
  font-size: 15px;
  outline: none;
}
.palette .results { max-height: 46vh; overflow-y: auto; padding: 6px; }
.palette .result {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px 12px;
  border-radius: 9px;
  cursor: pointer;
}
.palette .result.sel { background: var(--accent-soft); }
.palette .result .ico {
  width: 28px; height: 28px; border-radius: 8px;
  background: var(--surface-3); color: var(--text-2);
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 650; flex-shrink: 0;
}
.palette .result .nm { font-weight: 550; font-size: 13.5px; }
.palette .result .ds { color: var(--text-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.palette .result .cat { margin-left: auto; color: var(--text-3); font-size: 11.5px; flex-shrink: 0; }
.palette .foot {
  padding: 7px 14px;
  border-top: 1px solid var(--border);
  color: var(--text-3);
  font-size: 11.5px;
  display: flex;
  gap: 14px;
}
.palette .empty { padding: 22px; text-align: center; color: var(--text-3); font-size: 13px; }

/* ---- modal / drawer ---- */

.scrim {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55);
  z-index: 40; border: 0; padding: 0; cursor: default;
}
.modal-wrap {
  position: fixed; inset: 0; z-index: 50;
  display: flex; align-items: center; justify-content: center;
  padding: 16px;
}
.modal {
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-card);
  box-shadow: var(--shadow);
  width: min(460px, 100%);
  max-height: 86vh;
  overflow-y: auto;
  padding: 24px;
  animation: modalpop var(--dur) ease;
}
@keyframes modalpop { from { transform: scale(0.97); opacity: 0; } }
.modal h3 { margin: 0 0 16px; }
.form-row { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.form-row label { font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.input {
  height: 38px;
  padding: 0 12px;
  border-radius: var(--radius-ctl);
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font-size: 13px;
  min-width: 0;
}
.input:focus { border-color: var(--accent); outline: none; box-shadow: 0 0 0 3px var(--accent-soft); }
.form-check { display: flex; gap: 8px; align-items: center; font-size: 13px; color: var(--text-2); margin-bottom: 14px; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 6px; }

.btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  height: 34px;
  padding: 0 14px;
  border-radius: var(--radius-ctl);
  border: 1px solid var(--border-strong);
  background: var(--surface-2);
  color: var(--text);
  font-weight: 550;
  font-size: 13px;
  cursor: pointer;
  transition: background var(--dur) ease;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-3); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--err); }
.btn.danger:hover { background: rgba(248, 81, 73, 0.12); border-color: var(--err); }
.btn.sm { height: 28px; padding: 0 10px; font-size: 12px; }

.drawer {
  position: fixed;
  top: 0; right: 0; bottom: 0;
  width: min(560px, 96vw);
  background: var(--surface);
  border-left: 1px solid var(--border);
  z-index: 45;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow);
  animation: slide-in var(--dur) ease;
}
@keyframes slide-in { from { transform: translateX(24px); opacity: 0; } }
.drawer-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px; border-bottom: 1px solid var(--border);
}
.drawer-head h3 { margin: 0; }
.drawer-body { padding: 16px; overflow-y: auto; flex: 1; min-height: 0; }

/* discovery rows */
.disc-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 2px;
  border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.disc-row:last-child { border-bottom: 0; }
.disc-row .main { flex: 1; min-width: 0; }
.disc-row .dom { font-weight: 550; }
.disc-row .sub { color: var(--text-3); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  font-size: 11px;
  font-weight: 600;
  padding: 1px 8px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-2);
  white-space: nowrap;
}
.badge.mapped { color: var(--ok); }
.badge.unmapped { color: var(--warn); }

.switch {
  position: relative;
  width: 36px; height: 21px;
  border-radius: 11px;
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  cursor: pointer;
  transition: background var(--dur) ease;
  flex-shrink: 0;
  padding: 0;
}
.switch::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 15px; height: 15px;
  border-radius: 50%;
  background: var(--text-2);
  transition: transform var(--dur) ease, background var(--dur) ease;
}
.switch[aria-checked="true"] { background: var(--accent); border-color: var(--accent); }
.switch[aria-checked="true"]::after { transform: translateX(15px); background: #fff; }

.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  padding: 13px 0;
  border-bottom: 1px solid var(--border);
}
.setting-row:last-child { border-bottom: 0; }
.setting-name { font-weight: 550; font-size: 13.5px; }
.setting-desc { font-size: 12px; color: var(--text-3); margin-top: 2px; }

/* ---- login view ---- */

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; }
.login-card { width: min(360px, 100%); }
.login-brand { display: flex; align-items: center; gap: 10px; font-weight: 650; font-size: 16px; justify-content: center; margin-bottom: 24px; }
.login-card .btn { width: 100%; justify-content: center; height: 40px; margin-top: 4px; }
.login-err { color: var(--err); font-size: 13px; min-height: 18px; margin: 10px 0 2px; text-align: center; }
.login-title { text-align: center; color: var(--text-2); font-size: 13.5px; margin-bottom: 18px; }

/* ---- toast ---- */

.toast-wrap {
  position: fixed;
  bottom: 20px; left: 50%;
  transform: translateX(-50%);
  z-index: 100;
  display: flex;
  flex-direction: column;
  gap: 8px;
  align-items: center;
}
.toast {
  background: var(--surface-3);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 9px 16px;
  font-size: 13px;
  box-shadow: var(--shadow);
  animation: toastpop var(--dur) ease;
  max-width: 90vw;
}
@keyframes toastpop { from { transform: translateY(8px); opacity: 0; } }
.toast.error { border-color: var(--err); color: var(--err); }

/* ---- mobile ---- */

@media (max-width: 720px) {
  .top { padding: 8px 12px; gap: 8px; flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .top::-webkit-scrollbar { display: none; }
  .brand span.txt { display: none; }
  .search-pill kbd { display: none; }
  .server-status { padding: 4px 10px; gap: 10px; }
  .ss-metric span { display: none; }
  .wrap { padding: 16px 12px 64px; }
  .hero h1 { font-size: 19px; }
  .layout-seg { display: none; }
}
