:root {
  --bg: #14161a; --bg2: #1c1f26; --card: #21252d; --border: #2e333d;
  --text: #e6e8eb; --muted: #9aa3b0; --accent: #4f8cff;
  --ok: #3ecf8e; --warn: #f5a524; --danger: #f0475d;
}
* { box-sizing: border-box; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  position: relative; min-height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}
.hidden { display: none !important; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; }
.login-box {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 32px; width: 320px; display: flex; flex-direction: column; gap: 12px;
}
.login-box h1 { margin: 0 0 8px; font-size: 20px; text-align: center; }
.login-box input {
  padding: 10px 12px; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg2); color: var(--text); font-size: 14px;
}
.login-box button { margin-top: 4px; }
.error { color: var(--danger); font-size: 13px; margin: 0; }

header {
  display: flex; justify-content: space-between; align-items: center;
  padding: 16px 24px; border-bottom: 1px solid var(--border);
}
header h1 { font-size: 18px; margin: 0; }
.header-right { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 13px; }

nav#tabs { display: flex; gap: 4px; padding: 0 24px; border-bottom: 1px solid var(--border); }
nav#tabs button {
  background: none; border: none; color: var(--muted); padding: 12px 16px;
  cursor: pointer; font-size: 14px; border-bottom: 2px solid transparent;
}
nav#tabs button.active { color: var(--text); border-bottom-color: var(--accent); }

main { padding: 24px; max-width: 1100px; margin: 0 auto; }
.tab { display: none; }
.tab.active { display: block; }

.card-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 20px; }
.card h2 { margin: 0 0 12px; font-size: 15px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: 0.04em; }

button {
  background: var(--accent); color: white; border: none; border-radius: 8px;
  padding: 9px 14px; font-size: 13px; cursor: pointer; font-weight: 500;
}
button:hover { filter: brightness(1.1); }
button.small { padding: 6px 10px; font-size: 12px; background: var(--bg2); border: 1px solid var(--border); }
button.warn { background: var(--danger); }
button:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }

.status-line { font-size: 14px; padding: 8px 0; }
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pill.ok { background: rgba(62,207,142,0.15); color: var(--ok); }
.pill.warn { background: rgba(245,165,36,0.15); color: var(--warn); }
.pill.danger { background: rgba(240,71,93,0.15); color: var(--danger); }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; font-size: 12px; text-transform: uppercase; }

.slider-row { display: flex; align-items: center; gap: 8px; }
.slider-row input[type=range] { width: 100px; }
.slider-val { width: 20px; text-align: center; font-variant-numeric: tabular-nums; }

.group-block { background: var(--bg2); border: 1px solid var(--border); border-radius: 10px; padding: 14px; margin-bottom: 12px; }
.group-block h3 { margin: 0 0 8px; font-size: 14px; }
.group-block .needs-review { color: var(--warn); font-size: 12px; }
.candidate-row { font-size: 12px; padding: 4px 0; color: var(--muted); font-family: ui-monospace, monospace; }
.candidate-row.keep { color: var(--ok); }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.6); display: flex; align-items: center; justify-content: center; }
.modal-box { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 24px; max-width: 400px; }

.progress-bar { height: 8px; border-radius: 4px; background: var(--bg2); overflow: hidden; margin-top: 6px; }
.progress-bar-fill { height: 100%; background: var(--accent); }

.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: 100%; right: 0; margin-top: 6px; min-width: 160px;
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px; z-index: 10; box-shadow: 0 8px 24px rgba(0,0,0,0.4);
}
.dropdown-menu a {
  display: block; padding: 8px 10px; border-radius: 6px; color: var(--text);
  text-decoration: none; font-size: 13px;
}
.dropdown-menu a:hover { background: var(--bg2); }

.mini-bar-row { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 13px; }
.mini-bar-row .label { width: 110px; flex-shrink: 0; color: var(--muted); }
.mini-bar-row .progress-bar { flex: 1; }
.mini-bar-row .val { width: 40px; text-align: right; font-variant-numeric: tabular-nums; }

/* background jobs tab + start/finish notice */
#job-toast { position: fixed; right: 16px; bottom: 16px; z-index: 20; display: flex; gap: 12px; align-items: center;
  max-width: calc(100vw - 32px); padding: 10px 12px 10px 16px; font-size: 13px; background: var(--card);
  border: 1px solid var(--border); border-left: 3px solid var(--accent); border-radius: 10px; box-shadow: 0 8px 28px rgba(0,0,0,0.5); }
#job-toast.failed { border-left-color: var(--danger); }
#job-toast.hidden { display: none; }
.tab-badge { display: inline-block; min-width: 18px; padding: 1px 6px; margin-left: 4px; border-radius: 999px;
  background: var(--accent); color: white; font-size: 11px; line-height: 16px; text-align: center; }
.tab-badge.hidden { display: none; }
.jobs-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
#jobs-list { background: var(--card); border: 1px solid var(--border); border-radius: 12px; padding: 4px 16px; }
#jobs-list > p { margin: 12px 0; }
.job-row .job-meta { color: var(--muted); font-size: 12px; white-space: nowrap; }
.job-more { font-size: 12px; margin: 8px 0 0; }
p.muted { color: var(--muted); }
@media (max-width: 700px) { .job-row .job-meta { display: none; } }
.job-row { padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13px; }
.job-row:last-child { border-bottom: none; }
.job-row summary { cursor: pointer; display: flex; gap: 8px; align-items: center; list-style: none; }
.job-row summary::-webkit-details-marker { display: none; }
.job-row .job-label { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.job-row .job-time { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12px; }
.job-out { white-space: pre-wrap; font-size: 12px; max-height: 60vh; overflow: auto; background: var(--bg2); padding: 8px; border-radius: 8px; margin: 8px 0 0; }
.pill.run { background: rgba(79,140,255,0.18); color: var(--accent); }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* streaming top 10 */
.stream-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.stream-meta { display: flex; align-items: center; gap: 10px; color: var(--muted); font-size: 12px; }
.chip-row { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--bg2); border: 1px solid var(--border); color: var(--muted); border-radius: 999px; padding: 6px 14px; }
.chip.active { background: var(--accent); border-color: var(--accent); color: white; }
.stream-note { color: var(--muted); font-size: 12px; margin: 12px 0 16px; }
.stream-row { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); }
.stream-row:last-child { border-bottom: none; }
.stream-rank { width: 20px; text-align: right; color: var(--muted); font-variant-numeric: tabular-nums; font-size: 13px; }
.stream-row img, .stream-row .noposter { width: 40px; height: 60px; border-radius: 4px; background: var(--bg2); object-fit: cover; flex-shrink: 0; }
.stream-title { flex: 1; min-width: 0; font-size: 14px; }
.stream-title small { display: block; color: var(--muted); font-size: 12px; margin-top: 2px; }
.chip-groups { display: flex; flex-direction: column; gap: 10px; flex: 1; min-width: 0; }
.chip-group { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.chip-group-label { width: 130px; flex-shrink: 0; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em; }
.chip-region { font-size: 10px; opacity: 0.75; border: 1px solid currentColor; border-radius: 4px; padding: 0 4px; margin-left: 4px; }
@media (max-width: 700px) { .chip-group-label { width: 100%; } }

a.linkbtn { display: inline-block; margin-left: 8px; padding: 2px 8px; font: 500 11px -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg2); border: 1px solid var(--border); border-radius: 6px; color: var(--text); text-decoration: none; }
a.linkbtn:hover { border-color: var(--accent); }
.candidate-row button.linkbtn-del { margin-left: 6px; padding: 2px 8px; font-size: 11px; border-radius: 6px; }

/* background picture (kept behind everything, dimmed so text stays readable) */
body::before {
  content: ""; position: fixed; inset: 0; z-index: -1; pointer-events: none;
  background: linear-gradient(rgba(20,22,26,.80), rgba(20,22,26,.90)), url(/static/bg.jpg) center / cover no-repeat;
}
header { background: rgba(20,22,26,.55); backdrop-filter: blur(6px); }
.card, .login-box { background: rgba(33,37,45,.88); backdrop-filter: blur(4px); }

/* accounts + view-only mode */
.field { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; }
.field label, label.check { font-size: 13px; color: var(--muted); }
label.check { display: block; margin: 8px 0; color: var(--text); }
.field input, .field select, #um-perms select { padding: 8px 10px; border-radius: 8px; border: 1px solid var(--border); background: var(--bg2); color: var(--text); font-size: 14px; }
#um-perms select { padding: 5px 8px; font-size: 13px; }
.field small { color: var(--muted); font-size: 11px; }
.access-pills { display: flex; gap: 4px; flex-wrap: wrap; }
.pill.muted { background: var(--bg2); color: var(--muted); }
/* a tab the account can only look at: hide every control that would change something */
.tab.readonly button:not(.chip):not(.layout-btn):not(.card-handle):not(.card-resize):not(.cctv-hd) { display: none !important; }
.tab.readonly form { display: none; }
.tab.readonly input[type=range] { pointer-events: none; opacity: .6; }

.stream-search { display: flex; gap: 8px; margin-bottom: 14px; }
.stream-search input { flex: 1; padding: 11px 14px; border-radius: 10px; border: 1px solid var(--border); background: rgba(28,31,38,.9); color: var(--text); font-size: 15px; }
.stream-search input:focus { outline: none; border-color: var(--accent); }
.stream-kind { display: inline-block; font-size: 10px; text-transform: uppercase; letter-spacing: .04em; padding: 1px 6px; border-radius: 4px; background: var(--bg2); border: 1px solid var(--border); color: var(--muted); margin-right: 6px; }

/* phone / installed-app polish: keep clear of the notch and home bar */
header { padding-top: calc(16px + env(safe-area-inset-top)); }
main { padding-bottom: calc(24px + env(safe-area-inset-bottom)); }
@media (max-width: 700px) {
  header { padding-left: 14px; padding-right: 14px; flex-wrap: wrap; gap: 8px; }
  nav#tabs { overflow-x: auto; padding: 0 8px; -webkit-overflow-scrolling: touch; }
  nav#tabs button { white-space: nowrap; padding: 12px 12px; }
  main { padding: 14px; }
}

/* overview: full-width card; Tdarr jobs */
.span-all { grid-column: 1 / -1; }
.td-job { padding: 8px 0; border-bottom: 1px solid var(--border); }
.td-job:last-child { border-bottom: 0; }
.td-job .td-file { font: 12px ui-monospace, monospace; word-break: break-all; }
.td-job .td-meta { color: var(--muted); font-size: 11px; margin-top: 4px; display: flex; flex-wrap: wrap; gap: 4px 12px; }

/* docker ports */
.port-chip { display: inline-block; margin: 1px 4px 1px 0; padding: 1px 6px; border-radius: 6px; font: 11px ui-monospace, monospace;
  background: var(--bg2); border: 1px solid var(--border); white-space: nowrap; }
.port-chip.internal { color: var(--muted); border-style: dashed; }

/* claude code tab */
.claude-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.claude-head a.linkbtn { margin-left: 0; }
#browser-frame { width: 100%; height: calc(100vh - 230px); min-height: 360px; border: 1px solid var(--border); border-radius: 8px; background: #000; }
#claude-frame { width: 100%; height: calc(100vh - 230px); min-height: 360px; border: 1px solid var(--border); border-radius: 8px; background: #000; }

/* 2FA QR */
.qr-box { background: #fff; display: inline-block; padding: 6px; border-radius: 8px; line-height: 0; }

.net-legend { float: right; font-weight: normal; text-transform: none; color: var(--muted); font-size: 11px; }
.net-legend i { display: inline-block; width: 10px; height: 3px; border-radius: 2px; margin: 0 4px 2px 10px; vertical-align: middle; }
.net-rx { background: var(--accent); }
.net-tx { background: var(--ok); }
.net-port { display: grid; grid-template-columns: minmax(180px, 1.2fr) minmax(150px, 1fr) 2fr; gap: 6px 16px; align-items: center; padding: 10px 0; border-bottom: 1px solid var(--border); }
.net-port:last-child { border-bottom: 0; }
.net-port.member { padding-left: 18px; }
.net-name { font: 600 14px ui-monospace, monospace; }
.net-meta { color: var(--muted); font-size: 11px; margin-top: 3px; display: flex; flex-wrap: wrap; gap: 2px 10px; }
.net-rates { font-size: 13px; line-height: 1.6; font-variant-numeric: tabular-nums; }
.net-rates .dn { color: var(--accent); }
.net-rates .up { color: var(--ok); }
.net-rates small { color: var(--muted); font-size: 11px; }
.net-spark { width: 100%; height: 44px; display: block; background: var(--bg2); border-radius: 6px; }
.net-spark polyline { fill: none; stroke-width: 1.5; vector-effect: non-scaling-stroke; }
@media (max-width: 700px) { .net-port { grid-template-columns: 1fr 1fr; } .net-spark-wrap { grid-column: 1 / -1; } }

.layout-bar { display: flex; justify-content: flex-end; align-items: center; gap: 10px; margin: -4px 0 12px; }
.layout-bar span { color: var(--muted); font-size: 12px; margin-right: auto; }
.card-grid > .card { position: relative; }
.card-handle { position: absolute; top: 10px; right: 10px; z-index: 2; width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid var(--border); background: var(--bg2); color: var(--text); font-size: 18px; line-height: 1;
  cursor: grab; touch-action: none; padding: 0; }
.card-handle:focus-visible { outline: 2px solid var(--accent); }
.arranging > .card { outline: 1px dashed var(--accent); outline-offset: -1px; }
.arranging > .card > :not(.card-handle):not(.card-resize) { pointer-events: none; user-select: none; opacity: 0.55; }
.arranging > .card.dragging { opacity: 0.85; outline: 2px solid var(--accent); box-shadow: 0 8px 24px rgba(0,0,0,0.45); }
.arranging > .card.dragging .card-handle { cursor: grabbing; }
.pu-stream { margin-top: 6px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 8px; font-size: 13px; }
.pu-stream small { color: var(--muted); }
.pu-stream button { margin-top: 4px; }

/* resizable boxes (arrange mode): width snaps to grid columns, height is free; a sized box scrolls inside */
.card-grid > .card.sized-h { overflow: auto; }
.card-resize { position: absolute; z-index: 2; width: 30px; height: 30px; padding: 0;
  border-radius: 8px; background: var(--bg2); border: 1px solid var(--accent); color: var(--accent);
  touch-action: none; font-size: 16px; line-height: 1; }
.card-resize.grip-wh { right: 4px; bottom: 4px; cursor: nwse-resize; }
.card-resize.grip-w { right: 4px; top: calc(50% - 15px); cursor: ew-resize; }
.card-resize.grip-h { left: calc(50% - 15px); bottom: 4px; cursor: ns-resize; }
.card-resize:focus-visible { outline: 2px solid var(--accent); }
.arranging > .card.resizing { outline: 2px solid var(--accent); }
.size-tag { position: absolute; left: 8px; bottom: 8px; z-index: 2; font-size: 11px; color: var(--accent);
  background: var(--bg2); border-radius: 6px; padding: 2px 6px; pointer-events: none; }
.host-note { font-size: 11px; margin: -2px 0 6px; }

/* read me tab */
.readme { line-height: 1.5; font-size: 14px; }
.readme > p { margin: 0 0 12px; }
.readme details { border-top: 1px solid var(--border); padding: 10px 0; }
.readme summary { cursor: pointer; font-weight: 600; font-size: 15px; }
.readme dl { display: grid; grid-template-columns: minmax(140px, 260px) 1fr; gap: 6px 16px; margin: 10px 0 0; }
.readme dt { font-weight: 600; }
.readme dd { margin: 0; color: var(--muted); }
.readme details > p { color: var(--muted); margin: 8px 0 0; }
@media (max-width: 700px) { .readme dl { grid-template-columns: 1fr; } .readme dd { margin-bottom: 6px; } }

/* disk space bars */
.mini-fill { display: inline-block; width: 70px; height: 6px; border-radius: 3px; background: var(--bg2); vertical-align: middle; overflow: hidden; }
.mini-fill i { display: block; height: 100%; }
.disk-used { font-size: 12px; margin-top: 4px; }
.disk-used small, .disk-space small { color: var(--muted); }
.disk-space { display: flex; flex-wrap: wrap; gap: 6px 18px; font-size: 12px; padding-bottom: 8px; border-bottom: 1px solid var(--border); }

/* CCTV */
.cctv-card h2 { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.cctv-view { background: #000; border-radius: 8px; overflow: hidden; aspect-ratio: 4 / 3; display: flex; align-items: center; justify-content: center; color: var(--muted); font-size: 13px; }
.cctv-view video-stream, .cctv-view video { width: 100%; height: 100%; display: block; object-fit: contain; }
.cctv-card.sized-h .cctv-view { aspect-ratio: auto; height: calc(100% - 40px); }
.cctv-modal-box { width: min(1400px, 96vw); max-width: none; padding: 12px; }
.cctv-modal-head { display: flex; gap: 12px; align-items: center; margin-bottom: 8px; }
.cctv-modal-head .muted { font-size: 12px; flex: 1; }
#cctv-modal-view { aspect-ratio: 16 / 9; }
