:root {
  --bg: #f3f3f5;
  --panel: #ffffff;
  --tile: #ffffff;
  --raised: #f7f7f9;
  --text: #1b1c20;
  --muted: #6b6f7b;
  --line: #e1e2e7;
  --hover: #eeeef3;
  --accent: #6c5ce7;
  --accent-soft: #e9e6fd;
  --accent-text: #ffffff;
  --star: #e8a400;
  --good: #1f8a4c;
  --bad: #d03b3b;
  --warn: #c27c00;
  --shadow: 0 10px 40px rgba(20, 20, 35, .18);
  --radius: 10px;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #131417;
    --panel: #1a1b1f;
    --tile: #1f2025;
    --raised: #24252b;
    --text: #e7e7ea;
    --muted: #91939d;
    --line: #2c2d34;
    --hover: #26272e;
    --accent: #8b7cff;
    --accent-soft: #2c2850;
    --accent-text: #ffffff;
    --star: #ffc83d;
    --good: #4fce80;
    --bad: #ff6b6b;
    --warn: #f0b04a;
    --shadow: 0 10px 40px rgba(0, 0, 0, .55);
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #131417; --panel: #1a1b1f; --tile: #1f2025; --raised: #24252b; --text: #e7e7ea; --muted: #91939d;
  --line: #2c2d34; --hover: #26272e; --accent: #8b7cff; --accent-soft: #2c2850; --star: #ffc83d;
  --good: #4fce80; --bad: #ff6b6b; --warn: #f0b04a; --shadow: 0 10px 40px rgba(0, 0, 0, .55); color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
.note { color: var(--muted); }

input, select, textarea {
  background: var(--raised); border: 1px solid var(--line); border-radius: 8px; padding: 7px 10px; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
input[type=range] { padding: 0; accent-color: var(--accent); background: none; border: 0; }
input[type=checkbox] { accent-color: var(--accent); width: 16px; height: 16px; }
button {
  background: var(--raised); border: 1px solid var(--line); border-radius: 8px; padding: 7px 12px;
  cursor: pointer; white-space: nowrap; line-height: 1.2;
}
button:hover:not(:disabled) { background: var(--hover); }
button:disabled { opacity: .45; cursor: default; }
button.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); background: var(--accent); }
button.danger { color: var(--bad); }
button.ghost { background: transparent; border-color: transparent; }
button.icon { padding: 6px 9px; font-size: 16px; line-height: 1; }
.chip { border-radius: 999px; padding: 6px 12px; }
.chip[aria-pressed="true"] { background: var(--accent-soft); border-color: var(--accent); color: var(--text); }
#f-star[aria-pressed="true"] { color: var(--star); border-color: var(--star); background: transparent; }

/* Login */
.login { min-height: 100%; display: grid; place-items: center; padding: 16px; }
.login-card {
  width: min(340px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
  padding: 28px 24px; display: flex; flex-direction: column; gap: 12px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 0 0 6px; font-size: 20px; text-align: center; }
.login-card .logo-mark { width: 44px; height: 44px; margin: 0 auto; }
.logo-mark { display: inline-block; width: 22px; height: 22px; background: url(icon.svg) center / contain no-repeat; vertical-align: middle; }

/* App frame */
.app { position: fixed; inset: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: var(--panel);
  border-bottom: 1px solid var(--line); flex-wrap: wrap;
  padding-top: max(8px, env(safe-area-inset-top));
}
.brand { display: flex; align-items: center; gap: 8px; font-weight: 700; letter-spacing: .2px; margin-right: 6px; }
.search { flex: 1 1 260px; min-width: 160px; }
.search input { width: 100%; padding: 8px 12px; border-radius: 999px; }
#zoom { width: 110px; }
.body { flex: 1; min-height: 0; display: flex; }

/* Sidebar */
.side { width: 260px; flex: none; background: var(--panel); border-right: 1px solid var(--line); overflow: auto; }
.side-inner { padding: 10px; display: flex; flex-direction: column; gap: 12px; }
.views { display: flex; flex-direction: column; gap: 2px; }
.views button, .bundles button {
  text-align: left; background: transparent; border: 0; padding: 7px 10px; border-radius: 8px; color: var(--muted);
}
.views button:hover, .bundles button:hover { background: var(--hover); color: var(--text); }
.views button.on, .bundles button.on { background: var(--accent-soft); color: var(--text); font-weight: 600; }
.sect h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 4px 6px 6px; font-weight: 650; }
.sect h3 .note { text-transform: none; letter-spacing: 0; font-weight: 400; }
.sect label, .side-filters label { display: flex; flex-direction: column; gap: 4px; font-size: 12.5px; color: var(--muted); margin: 6px 4px; }
details.sect summary { cursor: pointer; font-size: 12px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); font-weight: 650; padding: 4px 6px; }
.bundles { display: flex; flex-direction: column; gap: 2px; }
.tags-sect { display: flex; flex-direction: column; gap: 6px; min-height: 0; }
.tags-sect input { width: 100%; }
.tags { display: flex; flex-direction: column; }
.tag-row {
  display: flex; justify-content: space-between; gap: 8px; padding: 4px 8px; border-radius: 6px; cursor: pointer;
  background: transparent; border: 0; text-align: left; width: 100%;
}
.tag-row:hover { background: var(--hover); }
.tag-row.on { background: var(--accent-soft); font-weight: 600; }
.tag-row .n { color: var(--muted); font-variant-numeric: tabular-nums; font-size: 12.5px; }
.tag-row .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.active-tags { display: flex; flex-wrap: wrap; gap: 4px; }
.tagchip {
  display: inline-flex; align-items: center; gap: 4px; padding: 2px 4px 2px 10px; border-radius: 999px;
  background: var(--accent-soft); border: 1px solid var(--accent); font-size: 12.5px; cursor: pointer;
}
.tagchip.plain { padding: 2px 10px; border-color: var(--line); background: var(--raised); }
.tagchip.plain:hover { border-color: var(--accent); }
.tagchip .x { border: 0; background: transparent; padding: 0 5px; font-size: 13px; color: var(--muted); }

/* Main */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; position: relative; }
.crumbs { display: flex; align-items: center; gap: 8px; padding: 8px 14px 0; flex-wrap: wrap; min-height: 34px; }
#chips { display: flex; gap: 6px; flex-wrap: wrap; }
.grid-host { flex: 1; min-height: 0; position: relative; }
.grid-canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.grid-scroll { position: absolute; inset: 0; overflow-y: auto; overflow-x: hidden; outline: none; touch-action: pan-y; overscroll-behavior: contain; }
.grid-spacer { width: 1px; }
.grid-empty { position: absolute; inset: 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
.grid-empty::before { content: "Nothing matches these filters."; }

/* Selection bar */
.selbar {
  position: absolute; left: 50%; bottom: max(14px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  display: flex; align-items: center; gap: 6px; padding: 6px 6px 6px 14px; max-width: calc(100% - 24px);
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px; box-shadow: var(--shadow); z-index: 5;
}
.sel-count { font-weight: 650; white-space: nowrap; }
.sel-actions { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: thin; }
.sel-actions button { background: transparent; border-color: transparent; }
.sel-actions button:hover { background: var(--hover); }

/* Detail panel */
.detail {
  width: 380px; flex: none; background: var(--panel); border-left: 1px solid var(--line); overflow: auto;
  display: flex; flex-direction: column;
}
.detail .hero { position: relative; background: #000; aspect-ratio: 16 / 9; flex: none; }
.detail .hero img { width: 100%; height: 100%; object-fit: contain; display: block; }
.detail .hero .logo { object-fit: none; background: var(--raised); }
.detail .hero .count {
  position: absolute; right: 8px; bottom: 8px; background: rgba(0,0,0,.6); color: #fff; border: 0;
  border-radius: 999px; padding: 3px 10px; font-size: 12.5px;
}
.detail .close { position: absolute; top: 6px; right: 6px; background: rgba(0,0,0,.5); color: #fff; border: 0; z-index: 1; }
.strip { display: flex; gap: 4px; padding: 6px; overflow-x: auto; flex: none; }
.strip img { height: 52px; border-radius: 4px; cursor: pointer; opacity: .65; border: 2px solid transparent; }
.strip img.on, .strip img:hover { opacity: 1; border-color: var(--accent); }
.detail .info { padding: 12px 14px 20px; display: flex; flex-direction: column; gap: 10px; }
.detail h2 { margin: 0; font-size: 16px; line-height: 1.35; word-break: break-word; }
.detail .url { font-size: 12.5px; word-break: break-all; }
.detail .meta { font-size: 12.5px; color: var(--muted); display: flex; flex-wrap: wrap; gap: 4px 12px; }
.detail .desc { white-space: pre-wrap; word-break: break-word; }
.detail .notes { white-space: pre-wrap; word-break: break-word; font-size: 13px; background: var(--raised); border-radius: 8px; padding: 8px 10px; max-height: 200px; overflow: auto; }
.detail .tagline { display: flex; flex-wrap: wrap; gap: 4px; }
.detail .btnrow { display: flex; flex-wrap: wrap; gap: 6px; }
.detail .health { font-size: 13px; }
.st-ok { color: var(--good); } .st-dead { color: var(--bad); } .st-warn { color: var(--warn); }
.star-on { color: var(--star); }

/* Modals */
.modal-back {
  position: fixed; inset: 0; background: rgba(0, 0, 0, .5); display: grid; place-items: center; z-index: 50; padding: 16px;
  animation: fade .12s ease-out;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow); width: min(520px, 100%);
  max-height: calc(100dvh - 32px); display: flex; flex-direction: column; padding: 14px 16px 16px;
  border: 1px solid var(--line);
}
.modal.wide { width: min(900px, 100%); }
.modal.full { width: min(1400px, 100%); height: calc(100dvh - 32px); }
.modal-head { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.modal-head h2 { margin: 0; font-size: 16px; flex: 1; word-break: break-word; }
.modal-body { overflow: auto; min-height: 0; flex: 1; }
.modal-body > p { margin: 0; white-space: pre-wrap; }
.modal-btns { display: flex; justify-content: flex-end; gap: 6px; margin-top: 14px; flex-wrap: wrap; }
.form { display: grid; grid-template-columns: max-content 1fr; gap: 8px 12px; align-items: center; }
.form .span2 { grid-column: 1 / -1; }
.form textarea { min-height: 90px; resize: vertical; width: 100%; }
.form input:not([type=checkbox]) { width: 100%; }
.form .checks { display: flex; gap: 16px; flex-wrap: wrap; }
.form label.check { display: inline-flex; align-items: center; gap: 6px; }
.warnbox { color: var(--warn); }

/* Gallery */
.gallery { display: flex; flex-direction: column; height: 100%; gap: 8px; }
.gallery .big { flex: 1; min-height: 0; display: grid; place-items: center; background: #000; border-radius: 10px; position: relative; overflow: hidden; }
.gallery .big img { max-width: 100%; max-height: 100%; object-fit: contain; }
.gallery .nav { position: absolute; top: 50%; transform: translateY(-50%); background: rgba(0,0,0,.5); color: #fff; border: 0; font-size: 22px; padding: 10px 14px; }
.gallery .prev { left: 8px; } .gallery .next { right: 8px; }

/* Tasks, toast */
.task-status { white-space: pre-wrap; margin: 6px 0; word-break: break-word; }
.bar.busy > div, .bar > div { height: 100%; background: var(--accent); }
.bar { height: 6px; border-radius: 3px; background: var(--raised); overflow: hidden; }
.bar > div { width: 0; transition: width .4s; }
.bar.busy > div { width: 30%; animation: busy 1.2s ease-in-out infinite; }
@keyframes busy { 0% { margin-left: -30%; } 100% { margin-left: 100%; } }
.log { background: var(--raised); border-radius: 8px; padding: 8px; max-height: 45vh; overflow: auto; font-size: 12.5px; white-space: pre-wrap; margin: 8px 0 0; }
.toast {
  position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); z-index: 60;
  background: var(--text); color: var(--panel); padding: 9px 16px; border-radius: 10px; box-shadow: var(--shadow);
  max-width: calc(100vw - 32px);
}
.menu { position: fixed; z-index: 40; background: var(--panel); border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 4px; min-width: 200px; }
.menu button { display: block; width: 100%; text-align: left; background: transparent; border: 0; padding: 8px 12px; border-radius: 6px; }
.menu button:hover { background: var(--hover); }
.menu hr { border: 0; border-top: 1px solid var(--line); margin: 4px 0; }

/* Folder browser, task and job lists */
.btnrow { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.folder-body { display: flex; flex-direction: column; height: 100%; gap: 8px; }
.folder-top { display: flex; gap: 8px 14px; align-items: center; flex-wrap: wrap; justify-content: space-between; }
.folder-grid { flex: 1; min-height: 280px; border-radius: 10px; background: var(--bg); }
.tasklist, .joblist { display: flex; flex-direction: column; gap: 8px; }
.task { background: var(--raised); border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 6px; }
.task-head { display: flex; justify-content: space-between; gap: 8px; }
.jobrow { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 8px; background: var(--raised); }
.jobrow input { margin-top: 3px; }
.jobmain { flex: 1; min-width: 0; }
.jobtitle { word-break: break-word; font-weight: 500; }
.jobstate { flex: none; max-width: 40%; text-align: right; font-size: 13px; }
.jobrow.run .jobstate { color: var(--accent); }
.jobrow.bad .jobstate { color: var(--bad); }
.jobrow .note { font-size: 12px; word-break: break-all; }

.only-sm, .only-xs { display: none !important; }

/* Tablets: the detail panel floats over the grid. */
@media (max-width: 1100px) {
  .detail { position: absolute; right: 0; top: 0; bottom: 0; z-index: 20; box-shadow: var(--shadow); }
  .body { position: relative; }
}
/* Phones */
@media (max-width: 760px) {
  .only-sm { display: inline-flex !important; }
  .hide-sm { display: none !important; }
  .topbar { gap: 6px; padding-left: 10px; padding-right: 10px; }
  .search { order: 10; flex-basis: 100%; }
  .brand { margin-right: auto; }
  .side {
    position: fixed; top: 0; bottom: 0; left: 0; z-index: 30; width: min(300px, 86vw);
    transform: translateX(-102%); transition: transform .18s ease-out; box-shadow: var(--shadow);
  }
  .side.open { transform: none; }
  .detail { position: fixed; inset: 0; width: auto; z-index: 25; }
  .selbar { left: 8px; right: 8px; transform: none; max-width: none; }
  .crumbs { padding: 6px 10px 0; }
}
@media (max-width: 480px) {
  .hide-xs { display: none !important; }
  .only-xs { display: flex !important; }
  .side-filters { flex-direction: column; }
  .form { grid-template-columns: 1fr; }
}

/* Search suggestions */
.suggest {
  position: absolute; left: 8px; right: 8px; top: calc(100% + 4px); z-index: 45; background: var(--panel);
  border: 1px solid var(--line); border-radius: 10px; box-shadow: var(--shadow); padding: 4px; max-height: 60vh; overflow: auto;
}
.suggest .sg { display: flex; justify-content: space-between; gap: 10px; padding: 6px 10px; border-radius: 6px; cursor: pointer; }
.suggest .sg:hover, .suggest .sg.on { background: var(--accent-soft); }

/* Host families */
.hosts-dialog { display: flex; flex-direction: column; gap: 8px; }
.hosts-dialog h3 { margin: 8px 0 0; font-size: 14px; }
.families { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.family { background: var(--raised); border-radius: 10px; padding: 10px; display: flex; flex-direction: column; gap: 6px; }
.family.new { border: 1px dashed var(--line); background: transparent; }
.family input:not([type=checkbox]) { width: 100%; }
.fam-head { display: flex; gap: 8px; align-items: baseline; }
.fam-head .ghost { margin-left: auto; padding: 2px 6px; }
.hostlist { display: flex; flex-direction: column; max-height: 40vh; overflow: auto; }
.hostrow { display: grid; grid-template-columns: 1fr auto 160px; gap: 10px; align-items: center; padding: 4px 6px; border-bottom: 1px solid var(--line); }
.hostrow .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
