:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --text: #1c2128;
  --muted: #6b7280;
  --line: #e2e5ea;
  --accent: #2563eb;
  --accent-ink: #ffffff;
  --danger: #dc2626;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(16, 24, 40, .08), 0 1px 2px rgba(16, 24, 40, .04);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14171c;
    --card: #1e232b;
    --text: #e7eaf0;
    --muted: #98a1ae;
    --line: #313945;
    --accent: #5b8def;
    --accent-ink: #0d1117;
    --danger: #f26d6d;
    --shadow: 0 1px 3px rgba(0, 0, 0, .4);
  }
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
}
main { max-width: 900px; margin: 0 auto; padding: 1rem 1rem 4rem; }
a { color: var(--accent); text-decoration: none; }
h1 { font-size: 1.4rem; margin: .8rem 0; }
h2 { font-size: 1.1rem; margin: 1.4rem 0 .6rem; }

/* top bar */
.topbar {
  display: flex; justify-content: space-between; align-items: center;
  padding: .6rem 1rem; background: var(--card);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 700; color: var(--text); }
.topbar nav { display: flex; gap: 1rem; align-items: center; }
.inline { display: inline; }
.linklike {
  background: none; border: none; color: var(--muted);
  cursor: pointer; font: inherit; padding: 0;
}

/* flashes */
.flashes { margin: .8rem 0; }
.flash {
  background: var(--card); border: 1px solid var(--line);
  border-left: 4px solid var(--accent);
  padding: .5rem .8rem; border-radius: 8px; margin-bottom: .4rem;
}

/* cards & forms */
.card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1rem;
}
.form label { display: block; margin: .7rem 0; font-weight: 600; font-size: .9rem; }
.form input:not([type=checkbox]):not([type=file]), .form select, .form textarea,
.searchbar input, .searchbar select {
  width: 100%; padding: .55rem .7rem; margin-top: .25rem;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); color: var(--text); font: inherit;
}
.form .row { display: flex; gap: .8rem; flex-wrap: wrap; }
.form .row label { flex: 1; min-width: 140px; }
.form .row label.narrow { flex: 0 0 90px; min-width: 90px; }
.hint { color: var(--muted); font-weight: 400; font-size: .85rem; }
.check { font-weight: 400 !important; display: flex !important; gap: .5rem; align-items: center; }
.preview { max-width: 220px; border-radius: 8px; margin-top: .5rem; }
.actions { display: flex; gap: .6rem; margin-top: 1rem; flex-wrap: wrap; }

/* buttons */
.btn {
  display: inline-block; padding: .5rem .95rem; border-radius: 8px;
  border: 1px solid var(--line); background: var(--card);
  color: var(--text); font: inherit; font-weight: 600; cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); border-color: var(--danger); background: transparent; }
.btn.wide { width: 100%; }
.dangerzone { margin-top: 2.5rem; text-align: right; }

/* login */
.login-wrap { display: flex; justify-content: center; padding-top: 8vh; }
.login-card { width: 100%; max-width: 360px; }
.login-card h1 { text-align: center; margin-bottom: 1rem; }

/* dashboard tiles */
.greeting { margin-top: 1.5rem; }
.tiles {
  display: grid; gap: 1rem;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  margin-top: 1rem;
}
.tile {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); box-shadow: var(--shadow);
  padding: 1.4rem; color: var(--text);
  transition: transform .08s ease, box-shadow .08s ease;
}
.tile:hover { transform: translateY(-2px); box-shadow: 0 4px 12px rgba(16,24,40,.12); }
.tile.disabled { opacity: .55; }
.tile-icon { font-size: 2rem; }
.tile-name { font-weight: 700; font-size: 1.1rem; margin-top: .4rem; }
.tile-sub { color: var(--muted); font-size: .9rem; }

/* search + item grid */
.pagehead { display: flex; justify-content: space-between; align-items: center; gap: .8rem; flex-wrap: wrap; }
.searchbar { display: flex; gap: .5rem; margin: .8rem 0 1.2rem; flex-wrap: wrap; }
.searchbar input[type=search] { flex: 2 1 220px; }
.searchbar select { flex: 1 1 130px; width: auto; }
.item-grid {
  display: grid; gap: .8rem;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
}
.item-card {
  background: var(--card); border: 1px solid var(--line);
  border-radius: var(--radius); overflow: hidden; color: var(--text);
  box-shadow: var(--shadow);
}
.item-card img, .item-card .noimg {
  width: 100%; height: 120px; object-fit: cover; display: block;
}
.item-card .noimg {
  display: flex; align-items: center; justify-content: center;
  font-size: 2rem; background: var(--bg); color: var(--muted);
}
.item-card-body { padding: .6rem .7rem; }
.item-name { font-weight: 600; font-size: .95rem; }
.qty { color: var(--muted); font-weight: 400; }
.item-meta { color: var(--muted); font-size: .8rem; margin-top: .15rem; }
.empty { color: var(--muted); text-align: center; padding: 2.5rem 0; }

/* tables */
.table { width: 100%; border-collapse: collapse; background: var(--card); border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow); }
.table th, .table td { text-align: left; padding: .55rem .8rem; border-bottom: 1px solid var(--line); }
.table th { font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.table tr:last-child td { border-bottom: none; }

/* QR labels */
.labels { display: flex; flex-wrap: wrap; gap: .6rem; }
.label {
  display: flex; align-items: center; gap: .6rem;
  border: 1px dashed #999; border-radius: 6px; padding: .5rem .8rem .5rem .5rem;
  background: #fff; color: #000; break-inside: avoid;
}
.label img { width: 100px; height: 100px; }
.label-code { font-weight: 800; font-size: 1.3rem; }
.label-loc { font-size: .85rem; color: #444; }

@media print {
  .topbar, .noprint, .flashes { display: none !important; }
  body { background: #fff; }
  main { max-width: none; padding: 0; }
}

/* users page */
.row-actions details { position: relative; }
.row-actions summary { list-style: none; cursor: pointer; display: inline-block; }
.popform { position: absolute; right: 0; z-index: 20; min-width: 240px; margin-top: .3rem; }

/* status page */
.status-summary { display: flex; align-items: center; gap: .8rem; font-weight: 700; }
.status-summary.all-up { color: #16a34a; }
.status-summary.some-down { color: var(--danger); }
.status-list { display: flex; flex-direction: column; gap: .6rem; margin-top: .8rem; }
.status-row { display: flex; align-items: center; gap: .9rem; padding: .8rem 1rem; }
.status-dot { width: 14px; height: 14px; border-radius: 50%; flex: 0 0 14px; }
.status-dot.ok { background: #22c55e; box-shadow: 0 0 6px rgba(34,197,94,.6); }
.status-dot.bad { background: #ef4444; box-shadow: 0 0 6px rgba(239,68,68,.6); }
.status-dot.na { background: var(--line); }
.status-main { flex: 1; min-width: 0; }
.status-name { font-weight: 600; }
.status-target { color: var(--muted); font-size: .82rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.status-info { text-align: right; }
.status-detail { font-size: .85rem; color: var(--muted); }
.dots { display: flex; gap: 3px; justify-content: flex-end; margin-top: .3rem; }
.mini { width: 7px; height: 14px; border-radius: 2px; display: inline-block; }
.mini.ok { background: #22c55e; opacity: .75; }
.mini.bad { background: #ef4444; }

/* tabs, add bars, checklists */
.tabbar { display: flex; gap: .5rem; margin: .8rem 0 1rem; }
.tab { padding: .45rem .9rem; border-radius: 999px; border: 1px solid var(--line); color: var(--text); font-weight: 600; background: var(--card); }
.tab.active { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.tab .count { background: rgba(0,0,0,.15); border-radius: 999px; padding: 0 .5rem; font-size: .8rem; }
.addbar { display: flex; gap: .5rem; margin: .8rem 0 1rem; }
.addbar input { flex: 1; padding: .55rem .7rem; border: 1px solid var(--line); border-radius: 8px; background: var(--card); color: var(--text); font: inherit; }
.checklist { display: flex; flex-direction: column; gap: .35rem; }
.checkrow { display: flex; align-items: center; gap: .7rem; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: .5rem .8rem; }
.checkrow.is-done .checktext { text-decoration: line-through; color: var(--muted); }
.checkbox { width: 26px; height: 26px; border-radius: 7px; border: 2px solid var(--accent); background: transparent; color: var(--accent); font-weight: 800; cursor: pointer; flex: 0 0 26px; }
.checkrow.is-done .checkbox { background: var(--accent); color: var(--accent-ink); }
.checktext { flex: 1; }

/* renewals */
.renewal-list { display: flex; flex-direction: column; gap: .6rem; }
.renewal-row { display: flex; align-items: center; gap: 1rem; padding: .7rem 1rem; }
.renewal-row.soon { border-left: 4px solid #f59e0b; }
.renewal-row.overdue { border-left: 4px solid var(--danger); }
.countdown { text-align: center; min-width: 64px; }
.cd-num { font-size: 1.3rem; font-weight: 800; display: block; }
.cd-label { font-size: .68rem; color: var(--muted); line-height: 1.1; display: block; }

/* trips */
.packbar { width: 90px; height: 8px; border-radius: 999px; background: var(--bg); overflow: hidden; flex: 0 0 90px; }
.packbar-fill { height: 100%; background: var(--accent); }

/* bills */
.billcard { margin: 1rem 0; }
.billchart { display: flex; align-items: flex-end; gap: 6px; height: 120px; padding-top: .5rem; }
.billbar-wrap { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: flex-end; height: 100%; max-width: 56px; }
.billbar { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 4px; }
.billbar-label { font-size: .68rem; color: var(--muted); margin-top: .25rem; }
.delta-up { color: var(--danger); }
.delta-down { color: #16a34a; }

/* HA strip on dashboard */
.ha-strip { display: flex; gap: .5rem; flex-wrap: wrap; margin-top: .8rem; }
.ha-chip { background: var(--card); border: 1px solid var(--line); border-radius: 999px; padding: .3rem .8rem; display: flex; gap: .5rem; align-items: baseline; box-shadow: var(--shadow); }
.ha-chip.bad { border-color: var(--danger); }
.ha-chip-name { font-size: .78rem; color: var(--muted); }
.ha-chip-state { font-weight: 700; font-size: .9rem; }
.tile-alert { border-color: #f59e0b; }

/* quick-add chips */
.quickadd { display: flex; flex-wrap: wrap; gap: .4rem; align-items: center; margin: 0 0 1rem; }
.quickchip-form { display: inline-flex; align-items: center; background: var(--card); border: 1px solid var(--line); border-radius: 999px; overflow: hidden; }
.quickchip { background: none; border: none; color: var(--accent); font: inherit; font-weight: 600; font-size: .85rem; padding: .3rem .3rem .3rem .7rem; cursor: pointer; }
.quickchip-x { background: none; border: none; color: var(--muted); font-size: .7rem; padding: .3rem .55rem .3rem .3rem; cursor: pointer; }
