/* App Hub. Mobile-first: one column on the phone, two from 900 px. No inline styles (strict CSP). */

:root {
  --bg: #0f1720;
  --panel: #17212c;
  --panel-2: #1e2a37;
  --line: #2a3846;
  --text: #e6edf3;
  --muted: #93a1b0;
  --accent: #4fb3a9;
  --accent-ink: #062320;
  --green: #3fb950;
  --amber: #d9a33b;
  --red: #f0605a;
  --grey: #6b7785;
  --code: #c9d6e2;
  --radius: 12px;
  --tap: 44px;
  --top-h: 54px;
  --gutter: 12px;
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f8;
    --panel: #ffffff;
    --panel-2: #eef2f5;
    --line: #d5dde4;
    --text: #17212b;
    --muted: #5b6875;
    --accent: #1f7f76;
    --accent-ink: #ffffff;
    --green: #1f8f3a;
    --amber: #b07a12;
    --red: #c9342e;
    --grey: #8a96a3;
    --code: #24323f;
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  padding-bottom: env(safe-area-inset-bottom);
}

a { color: var(--accent); }
code {
  font: 13px/1.4 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: var(--code);
  overflow-wrap: anywhere;
  word-break: break-word;
}
h1, h2, h3, h4 { margin: 0; line-height: 1.25; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin-bottom: 8px; }

.muted { color: var(--muted); }
.small { font-size: 13px; }
.visually-hidden {
  position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap;
}
.offscreen { position: fixed; left: -9999px; top: 0; opacity: 0; }

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

.top {
  position: sticky; top: 0; z-index: 5;
  display: flex; align-items: center; gap: 10px;
  height: calc(var(--top-h) + env(safe-area-inset-top));
  padding: env(safe-area-inset-top) max(var(--gutter), calc((100% - 1240px) / 2 + var(--gutter))) 0;
  background: color-mix(in srgb, var(--bg) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 8px; color: var(--text); text-decoration: none; font-weight: 650; font-size: 17px; }
.brand img { border-radius: 7px; display: block; }
.scan { color: var(--muted); font-size: 12px; flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who { color: var(--muted); font-size: 12px; display: none; }

main { max-width: 1240px; margin: 0 auto; padding: 0 var(--gutter) 40px; }

.notice { padding: 12px; color: var(--muted); }
.notice.error, .form-error, .warn-line { color: var(--red); }
.notice.error { background: var(--panel); border: 1px solid var(--red); border-radius: var(--radius); }

/* ------------------------------------------------------------ buttons */

.btn {
  display: inline-flex; align-items: center; justify-content: center;
  min-height: 36px; padding: 6px 12px;
  border-radius: 9px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text);
  font: inherit; font-size: 14px; font-weight: 550; text-decoration: none;
  cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn:focus-visible, .chip:focus-visible, .pin:focus-visible, input:focus-visible, summary:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent); outline-offset: 2px;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn[disabled], .btn.primary[disabled] { opacity: .38; cursor: default; background: var(--panel-2); border-color: var(--line); color: var(--muted); }
.btn.ghost { background: transparent; }
.btn.small { min-height: 30px; padding: 3px 10px; font-size: 13px; }
.btn.wide { width: 100%; min-height: var(--tap); margin-top: 6px; }

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

.login {
  max-width: 380px; margin: 8vh auto 0; padding: 22px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px;
}
.login h1 { font-size: 22px; margin-bottom: 4px; }
.login form { display: grid; gap: 6px; margin-top: 14px; }
.login label { font-size: 13px; color: var(--muted); margin-top: 6px; }
input[type="text"], input[type="password"], input[type="search"] {
  width: 100%; min-height: var(--tap); padding: 10px 12px;
  border-radius: 10px; border: 1px solid var(--line);
  background: var(--panel-2); color: var(--text); font: inherit; font-size: 16px;
}
.form-error { margin: 6px 0 0; font-size: 14px; }

/* ------------------------------------------------------------ view toggle (Products | Everything) */

.views {
  display: flex; gap: 4px; margin: 12px 0 0; padding: 4px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  max-width: 420px;
}
.view-tab {
  flex: 1; display: flex; align-items: center; justify-content: center;
  min-height: 40px; border-radius: 9px; text-decoration: none;
  color: var(--muted); font-weight: 600; font-size: 15px;
}
.view-tab:hover { color: var(--text); }
.view-tab.on { background: var(--accent); color: var(--accent-ink); }

/* ------------------------------------------------------------ Products view */

.products-count { margin: 2px 2px 6px; }
.pgroup { margin: 8px 0 18px; }
.pgrid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 10px; align-items: start; }
.pcard {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px; scroll-margin-top: calc(var(--top-h) + 72px + env(safe-area-inset-top));
}
.pcard h3 { font-size: 17px; }
.pcard .summary { margin: 2px 0 10px; }
.plinks { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.plink {
  display: flex; align-items: center; gap: 10px;
  min-height: 52px; padding: 8px 12px;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); text-decoration: none;
}
.plink:hover { border-color: var(--accent); }
.plink:active { background: color-mix(in srgb, var(--accent) 18%, var(--panel-2)); }
.plink-text { flex: 1; min-width: 0; display: grid; }
.plink-label { font-weight: 600; font-size: 15px; }
.plink-url { font-size: 12px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.plink-go { color: var(--accent); font-size: 18px; flex: none; }

/* ------------------------------------------------------------ search and chips */

/* Sticks right under the header (same height variable, so no gap shows content through). */
.searchbar { position: sticky; top: calc(var(--top-h) + env(safe-area-inset-top)); z-index: 4; padding: 10px 0 8px; background: var(--bg); }
.searchbar input { font-size: 17px; }

.filters { display: grid; gap: 6px; margin-bottom: 10px; }
.chip-row { display: flex; flex-wrap: wrap; gap: 6px; }
.chip {
  min-height: 32px; padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  font: inherit; font-size: 13px; cursor: pointer;
}
.chip.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); font-weight: 600; }
.chip.toggle { border-style: dashed; color: var(--muted); }

.project-bar { display: flex; align-items: center; gap: 10px; margin: 4px 0 12px; color: var(--muted); }

.result-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 30px; margin: 4px 2px 8px; }
.result-head p { margin: 0; font-size: 13px; }

/* ------------------------------------------------------------ pins and recents */

.strip { margin: 6px 0 16px; }
.recent-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 2px; }
.recent-list li {
  display: flex; align-items: center; gap: 8px; min-height: 36px; padding: 4px 10px;
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
}
.recent-list a, .recent-list span:not(.dot):not(.muted) { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.strip .items { display: grid; gap: 8px; }
.strip .item { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); }

/* ------------------------------------------------------------ cards */

.grid { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; align-items: start; }
.grid.single { max-width: 820px; }

.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 12px 12px 4px;
}
.card.status-retired, .card.status-parked { opacity: .8; }
.card-head { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.card-head h3 { font-size: 17px; margin-right: auto; }
.card-head h3 a { color: var(--text); text-decoration: none; }
.card-head h3 a:hover { text-decoration: underline; }
.summary { margin: 4px 0 6px; color: var(--muted); font-size: 14px; }
.card h4 { font-size: 13px; color: var(--muted); margin: 10px 0 4px; }

.items { list-style: none; margin: 0; padding: 0; }
.item { padding: 10px 0; border-top: 1px solid var(--line); }
.strip .item { padding: 10px 12px; }
.item.status-retired .item-label, .item.status-parked .item-label { color: var(--muted); }
.item-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.item-label { font-weight: 600; margin-right: auto; min-width: 0; }
.item-project { color: var(--muted); font-weight: 500; }

.tag {
  font-size: 11px; line-height: 1; padding: 4px 6px; border-radius: 6px;
  background: var(--panel-2); color: var(--muted); border: 1px solid var(--line); white-space: nowrap;
}
.tag.cat { color: var(--accent); }
.tag.st-retired, .tag.st-parked, .tag.st-planned { border-style: dashed; }
.tag.sev-high { color: var(--red); border-color: var(--red); }
.tag.sev-warn { color: var(--amber); border-color: var(--amber); }

.pin {
  width: 34px; height: 34px; border-radius: 8px; border: 1px solid transparent;
  background: transparent; color: var(--muted); font-size: 19px; line-height: 1; cursor: pointer;
}
.pin.on { color: var(--amber); }
.pin:hover { border-color: var(--line); }

.dot { width: 10px; height: 10px; border-radius: 50%; flex: none; display: inline-block; }
.dot-green { background: var(--green); box-shadow: 0 0 0 3px color-mix(in srgb, var(--green) 22%, transparent); }
.dot-amber { background: var(--amber); box-shadow: 0 0 0 3px color-mix(in srgb, var(--amber) 22%, transparent); }
.dot-red { background: var(--red); box-shadow: 0 0 0 3px color-mix(in srgb, var(--red) 22%, transparent); }
.dot-grey { background: transparent; border: 2px solid var(--grey); }

.lines { display: grid; gap: 3px; margin: 6px 0 2px; }
.line {
  display: flex; gap: 8px; align-items: baseline;
  padding: 5px 8px; background: var(--panel-2); border-radius: 8px;
}
.line-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; flex: none; }
.apk { font-size: 13px; margin-top: 4px; }
.meta { font-size: 12px; color: var(--muted); margin-top: 4px; overflow-wrap: anywhere; }
.note { font-size: 13px; color: var(--muted); margin-top: 4px; font-style: italic; }
.warn-line { font-size: 13px; margin-top: 2px; }

.actions { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }

.empty { text-align: center; padding: 24px 8px; color: var(--muted); }

/* ------------------------------------------------------------ drift */

/* Scrolling to these leaves room for the sticky header and search box. */
.card, .drift { scroll-margin-top: calc(var(--top-h) + 72px + env(safe-area-inset-top)); }

.drift {
  margin-top: 24px; background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
}
.drift summary {
  cursor: pointer; padding: 12px 14px; font-weight: 650; list-style-position: inside; min-height: var(--tap);
}
.drift[open] summary { border-bottom: 1px solid var(--line); }
#drift-body { padding: 4px 14px 12px; }
.badge {
  display: inline-block; min-width: 22px; padding: 2px 7px; margin-left: 6px; border-radius: 999px;
  font-size: 12px; text-align: center; background: var(--panel-2); color: var(--muted); border: 1px solid var(--line);
}
.badge.urgent { background: var(--amber); border-color: var(--amber); color: #1d1300; }
.drift-group { margin-top: 12px; }
.drift-group h3 { font-size: 14px; margin-bottom: 6px; }
.drift-list { list-style: none; margin: 0; padding: 0; display: grid; gap: 6px; }
.drift-item { padding: 8px 10px; background: var(--panel-2); border-radius: 8px; border-left: 3px solid var(--grey); }
.drift-item.sev-high { border-left-color: var(--red); }
.drift-item.sev-warn { border-left-color: var(--amber); }
.drift-item > div:first-child { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }

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

.toast {
  position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  max-width: min(92vw, 520px); padding: 10px 14px; border-radius: 10px;
  background: var(--text); color: var(--bg); font-size: 14px; z-index: 20;
  box-shadow: 0 6px 24px rgba(0, 0, 0, .35);
}
.toast.error { background: var(--red); color: #fff; }

/* ------------------------------------------------------------ laptop */

/* Phone: each chip group is one row that scrolls sideways, so the results start high up. */
@media (max-width: 599px) {
  .chip-row {
    flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none;
    margin: 0 calc(-1 * var(--gutter)); padding: 0 var(--gutter);
    scroll-padding-inline: var(--gutter);
  }
  .chip-row::-webkit-scrollbar { display: none; }
  .chip { flex: none; }
}

@media (min-width: 600px) {
  :root { --gutter: 20px; }
  .who { display: inline; }
}

@media (min-width: 900px) {
  .grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
  .grid.single { grid-template-columns: minmax(0, 1fr); }
  .strip .items { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .recent-list { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 6px; }
}

@media (min-width: 700px) {
  .pgrid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
}

@media (min-width: 1100px) {
  .pgrid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
