:root {
  --bg: #f6f7f9;
  --card: #ffffff;
  --border: #e2e5ea;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #1a5fb4;
  --accent-soft: #e8f0fb;
  --danger: #b3261e;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 20px; background: var(--card); border-bottom: 1px solid var(--border);
}
.brand { font-weight: 700; font-size: 18px; color: var(--accent); text-decoration: none; }
.topbar nav { margin-left: auto; display: flex; align-items: center; gap: 16px; }
.topbar nav a { color: var(--text); text-decoration: none; }
.topbar nav a:hover { color: var(--accent); }
.account-menu { position: relative; font-size: 13px; }
.account-menu summary { cursor: pointer; color: var(--muted); }
.account-menu > div { position: absolute; right: 0; top: 26px; z-index: 20; min-width: 230px;
  padding: 10px; border: 1px solid var(--border); border-radius: 8px; background: var(--card);
  box-shadow: 0 6px 20px rgba(0,0,0,.12); }
.account-menu span, .account-menu > div a, .account-menu button { display: block; padding: 5px; }
.account-menu form { margin: 0; }
.account-menu button { width: 100%; border: 0; background: none; color: var(--text);
  text-align: left; font: inherit; cursor: pointer; }
.account-menu button:hover { color: var(--accent); }

.container { max-width: 960px; margin: 24px auto; padding: 0 16px; }

h1 { font-size: 24px; }
h2 { font-size: 20px; }

.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px; margin-bottom: 14px;
}

.btn {
  display: inline-block; padding: 8px 14px; border-radius: 8px; border: 1px solid var(--accent);
  background: var(--accent); color: #fff; text-decoration: none; cursor: pointer; font-size: 14px;
}
.btn.secondary { background: #fff; color: var(--accent); }
.btn.danger { background: #fff; color: var(--danger); border-color: var(--danger); }
.btn.small { padding: 4px 10px; font-size: 13px; }

.row { display: flex; gap: 12px; align-items: center; justify-content: space-between; }
.muted { color: var(--muted); }
.tag { display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft);
  color: var(--accent); font-size: 12px; }
.tag.off { background: #f0f0f0; color: var(--muted); }

form label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0 4px; }
form input[type=text], form input[type=number], form input[type=email], form select, form textarea {
  width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; font-size: 14px;
}
form textarea { resize: vertical; font-family: inherit; line-height: 1.4; }
.wishlist-actions { display: flex; align-items: center; gap: 12px; margin-top: 8px; flex-wrap: wrap; }
.wishlist-actions .hint { margin: 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.checks label { display: inline-flex; align-items: center; gap: 6px; margin: 6px 14px 6px 0; color: var(--text); }
.checks input { width: auto; }
.checks .check-group { display: inline-flex; flex-direction: column; align-items: flex-start;
  margin: 6px 14px 6px 0; padding: 2px 0 2px 10px; border-left: 3px solid var(--accent-soft); }
.checks .check-group label { margin: 3px 0; }
.checks .check-group .sub { margin-left: 20px; font-size: .92em; color: var(--muted); }
.checks .check-group .sub::before { content: "↳"; margin-right: 4px; color: var(--muted); }
.checks .check-group label.is-disabled { opacity: .45; cursor: default; }

/* Inline help text */
.hint { font-size: 12px; color: var(--muted); margin: 4px 0 0; line-height: 1.4; }
.implied-ppm { margin-top: 8px; padding: 10px 12px; border: 1px solid var(--accent);
  border-radius: 8px; background: var(--accent-soft); }
.implied-ppm strong, .implied-ppm span, .implied-ppm small { display: block; }
.implied-ppm span { margin-top: 3px; font-size: 17px; color: var(--text); }
.implied-ppm small { margin-top: 3px; color: var(--muted); line-height: 1.35; }
.ppm-filter-help { margin-top: 30px; }
.info-box { background: var(--accent-soft); border-color: var(--accent); }
.info-box p { margin: 0; font-size: 14px; }
.actions { margin-top: 18px; }
.login-card { max-width: 480px; margin-left: auto; margin-right: auto; }
.filter-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.filter-head h2 { margin: 0; }
.advanced-filters { margin-top: 12px; border-top: 1px solid var(--border); padding-top: 10px; }
.advanced-filters summary, .form-section > summary { cursor: pointer; font-weight: 650; color: var(--accent); }
.active-filters { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 14px; }
.form-section { border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px;
  margin: 14px 0; background: #fff; }
.form-section > summary { font-size: 18px; }
.sticky-actions { position: sticky; bottom: 8px; z-index: 15; display: flex; align-items: center;
  justify-content: space-between; gap: 12px; padding: 10px 12px; background: rgba(255,255,255,.96);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: 0 -3px 16px rgba(0,0,0,.08); }
.alert-grid { display: grid; gap: 12px; }
.alert-card-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.alert-card h2 { margin: 0; font-size: 18px; }
.alert-meta { display: flex; flex-wrap: wrap; gap: 7px 14px; margin: 10px 0; font-size: 13px; }
.alert-actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.more-actions { position: relative; }
.more-actions summary { cursor: pointer; color: var(--accent); padding: 5px 8px; }
.more-actions > div { display: flex; flex-wrap: wrap; gap: 8px; padding-top: 8px; }
.triage-help { margin-top: -4px; }
.location-picker { border: 1px solid #b9cbe3; background: #f7faff; border-radius: 10px;
  padding: 12px; margin: 10px 0; }
.location-picker-head { display: flex; align-items: center; justify-content: space-between; gap: 14px; }
.location-text-fallback { margin: 12px 0; }
.location-text-fallback > summary { cursor: pointer; color: var(--muted); font-size: 13px; }
.location-map-dialog { width: min(1120px, calc(100vw - 32px)); height: min(760px, calc(100vh - 32px));
  padding: 0; border: 0; border-radius: 12px; box-shadow: 0 18px 60px rgba(0,0,0,.3); }
.location-map-dialog::backdrop { background: rgba(18,27,39,.62); }
.map-dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 12px;
  padding: 12px 14px; border-bottom: 1px solid var(--border); }
.map-breadcrumbs { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 4px; }
.map-breadcrumbs button { border: 0; background: transparent; color: var(--accent); padding: 0;
  cursor: pointer; font-size: 12px; }
.map-layout { height: calc(100% - 65px); display: grid; grid-template-columns: minmax(0, 1fr) 290px; }
#location-map { min-width: 0; height: 100%; background: #e9eef4; }
.map-area-panel { overflow: auto; padding: 12px; border-left: 1px solid var(--border); }
.map-area-panel label { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.map-area-panel input { width: 100%; padding: 8px 10px; border: 1px solid var(--border); border-radius: 8px; }
.map-area-list { display: grid; gap: 5px; margin-top: 10px; }
.map-area-option { width: 100%; display: flex; justify-content: space-between; align-items: center;
  gap: 8px; border: 1px solid var(--border); border-radius: 7px; background: #fff;
  color: var(--text); padding: 7px 9px; text-align: left; cursor: pointer; }
.map-area-option:hover { border-color: var(--accent); background: var(--accent-soft); }
.map-area-option.is-selected { background: var(--accent-soft); border-color: var(--accent); color: var(--accent); }
.map-area-option span:last-child { color: var(--muted); font-size: 11px; white-space: nowrap; }

/* Chips multiselect */
.ms-controls { display: flex; gap: 8px; align-items: stretch; }
.ms-controls .ms-select { flex: 1; min-width: 0; }
.ms-controls .ms-add { white-space: nowrap; }
.ms-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: var(--accent-soft);
  color: var(--accent); padding: 4px 10px; border-radius: 999px; font-size: 13px; }
.chip-x { border: none; background: transparent; color: var(--accent); cursor: pointer;
  font-size: 16px; line-height: 1; padding: 0; }
.chip-x:hover { color: var(--danger); }

/* Listing cards with thumbnails */
.listing-card { display: flex; gap: 12px; align-items: stretch; text-decoration: none;
  color: inherit; padding: 10px; transition: box-shadow .15s, transform .05s; }
.listing-card:hover { box-shadow: 0 3px 14px rgba(0,0,0,.09); }
.listing-card:active { transform: translateY(1px); }
.thumb { position: relative; flex: 0 0 170px; width: 170px; height: 122px; border-radius: 8px;
  overflow: hidden; background: #eef0f3; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb-empty { display: flex; align-items: center; justify-content: center; height: 100%;
  color: var(--muted); font-size: 12px; }
.photo-count { position: absolute; bottom: 6px; right: 6px; background: rgba(0,0,0,.62);
  color: #fff; font-size: 11px; padding: 1px 7px; border-radius: 10px; }
.listing-body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 6px; }
.lc-top { display: flex; justify-content: space-between; gap: 10px; align-items: baseline; }
.lc-top .listing-title { font-size: 15px; }
.price { white-space: nowrap; font-weight: 700; }
.price .per { font-weight: 400; font-size: 12px; color: var(--muted); }
.specs { display: flex; flex-wrap: wrap; gap: 5px 10px; align-items: center; font-size: 13px; }
.small { font-size: 12px; }
.tag.energy { background: #e7f6ec; color: #1a7f37; }
.tag.pon { background: #f3eefb; color: #6f42c1; text-transform: capitalize; }

/* Alert matches: toolbar, triage cards, reason tags, price deltas */
.matches-toolbar { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center;
  justify-content: space-between; }
.matches-toolbar .mt-controls { display: flex; flex-wrap: wrap; gap: 12px; align-items: end; }
.matches-toolbar label { display: flex; flex-direction: column; gap: 3px; margin: 0;
  font-size: 12px; color: var(--muted); }
.matches-toolbar select { width: auto; padding: 6px 8px; }
.matches-toolbar .mt-check { flex-direction: row; align-items: center; gap: 6px; font-size: 13px;
  color: var(--text); align-self: center; }
.matches-toolbar .mt-check input { width: auto; }
.matches-toolbar .mt-count { font-size: 13px; }

.match-item { margin-bottom: 14px; }
.match-item .listing-card { margin-bottom: 0; border-bottom-left-radius: 0; border-bottom-right-radius: 0; }
.match-item.is-unread .listing-card { border-left: 3px solid var(--accent); }
.match-item.is-saved .listing-card { border-left: 3px solid #d4a017; }
.match-item.is-dismissed { opacity: .55; }
.match-actions { display: flex; flex-wrap: wrap; gap: 8px; padding: 8px 12px;
  background: var(--card); border: 1px solid var(--border); border-top: 0;
  border-radius: 0 0 10px 10px; }
.match-actions .btn.is-on { background: #fbf4dd; color: #8a6d0b; border-color: #e3c766; }
.unread-dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%;
  background: var(--accent); margin-right: 6px; vertical-align: middle; }
.unread-badge { background: var(--accent); color: #fff; margin-left: 6px; }

.tag.reason-new { background: var(--accent-soft); color: var(--accent); }
.tag.reason-price_drop { background: #e7f6ec; color: #1a7f37; }
.tag.reason-price_rise { background: #fdecea; color: var(--danger); }
.tag.reason-provider_changed { background: #f3eefb; color: #6f42c1; }
.price-delta { font-size: 13px; font-weight: 600; }
.price-delta.down { color: #1a7f37; }
.price-delta.up { color: var(--danger); }

/* Alert form: live match-count preview */
.preview-bar { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
.preview-bar .hint { margin: 0; }
.hint.warn { color: var(--danger); font-weight: 600; }

/* AI assessment card (listing detail) */
.analysis-card .ai-score { font-size: 26px; font-weight: 800; color: var(--accent); white-space: nowrap; }
.analysis-card .ai-score-max { font-size: 13px; font-weight: 400; color: var(--muted); }
.signals-h { margin: 4px 0 4px; font-size: 13px; }
.signals-h.pro { color: #1a7f37; }
.signals-h.anti { color: var(--danger); }
.signals { margin: 0 0 8px; padding-left: 18px; font-size: 13px; line-height: 1.5; }
.feature-table { margin-top: 4px; }
.feature-table th { width: 150px; font-weight: 600; color: var(--text); }
.feature-table td { color: var(--muted); }
.rating { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.rating-excellent { background: #e7f6ec; color: #146c2e; }
.rating-good { background: #eaf5ed; color: #1a7f37; }
.rating-fair { background: #fff6e6; color: #9a6700; }
.rating-poor { background: #fdecea; color: var(--danger); }
.rating-unknown { background: #f0f0f0; color: var(--muted); }
.hardness { border-left: 4px solid; border-radius: 6px; padding: 9px 11px; margin-top: 10px; }
.hardness-label { font-weight: 700; }
.hardness-moderate { background: #fff8dd; border-color: #d4a017; }
.hardness-elevated { background: #fff0d6; border-color: #d97706; }
.hardness-high { background: #fde8d7; border-color: #c2410c; }
.grade-max { font-weight: 400; opacity: .7; font-size: 11px; }
.feature-table td.feat-imp { width: 34px; white-space: nowrap; text-align: left; }
.imp-dot { display: inline-block; width: 6px; height: 6px; border-radius: 999px; background: var(--border); margin-right: 2px; vertical-align: middle; }
.imp-dot.on { background: var(--accent); }
.feature-table tr.feat-minor th { font-weight: 500; color: var(--muted); }
.ai-chip { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px;
  font-weight: 700; background: var(--accent); color: #fff; }
/* AI chip / score coloured by score band */
.ai-chip.ai-excellent { background: #146c2e; }
.ai-chip.ai-good { background: #1a7f37; }
.ai-chip.ai-fair { background: #9a6700; }
.ai-chip.ai-poor { background: #b3261e; }
.ai-score.ai-excellent { color: #146c2e; }
.ai-score.ai-good { color: #1a7f37; }
.ai-score.ai-fair { color: #9a6700; }
.ai-score.ai-poor { color: #b3261e; }

/* Composite deal score — headline grade chip (coloured by band) */
.deal-chip { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12px;
  font-weight: 800; color: #fff; }
.deal-chip.deal-excellent, .ai-score.deal-excellent { background: #146c2e; color: #fff; }
.deal-chip.deal-good, .ai-score.deal-good { background: #1a7f37; color: #fff; }
.deal-chip.deal-fair, .ai-score.deal-fair { background: #9a6700; color: #fff; }
.deal-chip.deal-poor, .ai-score.deal-poor { background: #b3261e; color: #fff; }
/* The detail headline reuses .ai-score sizing but gets a filled pill background */
.ai-score.deal-excellent, .ai-score.deal-good, .ai-score.deal-fair, .ai-score.deal-poor {
  padding: 2px 12px; border-radius: 999px; font-size: 20px; }
.ai-score.deal-excellent .ai-score-max, .ai-score.deal-good .ai-score-max,
.ai-score.deal-fair .ai-score-max, .ai-score.deal-poor .ai-score-max { color: rgba(255,255,255,.75); }

/* Price-position badge (value ranking) */
.pp { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12px; font-weight: 600; }
.pp-good { background: #e7f6ec; color: #146c2e; }
.pp-bad { background: #fdecea; color: var(--danger); }
.pp-mid { background: #f0f0f0; color: var(--muted); }

/* Compact AI overview on the browse list cards */
.ai-overview { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-top: 4px; }
.ai-summary { margin-top: 3px; line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2;
  -webkit-box-orient: vertical; overflow: hidden; }

/* Admin: LLM connection status light */
.status-dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%;
  vertical-align: middle; margin: 0 3px; }
.status-ok { background: #1a7f37; }
.status-warn { background: #d4a017; }
.status-error { background: var(--danger); }
.status-idle, .status-disabled { background: #b0b4bb; }

/* Detail price + features + description */
.price-big { font-size: 22px; font-weight: 700; margin: 0 0 12px; }
.price-big .per { font-size: 14px; font-weight: 400; color: var(--muted); }
.feat-tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0 14px; }
.desc { white-space: pre-line; line-height: 1.55; }

/* Image gallery */
.gallery { margin-bottom: 16px; }
.gallery-main { width: 100%; border-radius: 10px; overflow: hidden; background: #111; }
.gallery-main img { width: 100%; max-height: 460px; object-fit: contain; display: block; background: #111; }
.gallery-thumbs { display: flex; gap: 8px; overflow-x: auto; padding: 8px 0 2px; }
.gallery-thumb { width: 92px; height: 66px; object-fit: cover; border-radius: 6px; cursor: pointer;
  opacity: .6; flex: 0 0 auto; border: 2px solid transparent; }
.gallery-thumb.active, .gallery-thumb:hover { opacity: 1; border-color: var(--accent); }
.gallery-main img { cursor: zoom-in; }

/* Fullscreen lightbox */
.lightbox { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,.9);
  display: flex; align-items: center; justify-content: center; }
.lightbox[hidden] { display: none; }
.lightbox .lb-img { max-width: 92vw; max-height: 88vh; object-fit: contain; border-radius: 6px; }
.lightbox .lb-close { position: absolute; top: 16px; right: 20px; }
.lightbox .lb-nav { position: absolute; top: 50%; transform: translateY(-50%); font-size: 40px;
  line-height: 1; padding: 0 12px; }
.lightbox .lb-prev { left: 12px; }
.lightbox .lb-next { right: 12px; }
.lightbox .lb-close, .lightbox .lb-nav { background: rgba(0,0,0,.4); color: #fff;
  border: none; cursor: pointer; border-radius: 8px; }
.lightbox .lb-close { font-size: 26px; width: 40px; height: 40px; }
.lightbox .lb-nav:hover, .lightbox .lb-close:hover { background: rgba(255,255,255,.2); }

/* Mobile: collapse multi-column grids to a single column */
@media (max-width: 640px) {
  .grid2, .grid3 { grid-template-columns: 1fr; }
  .grid3 > div:empty { display: none; }
  .container { margin: 16px auto; }
  .topbar { flex-wrap: wrap; gap: 8px 12px; }
  .topbar nav { gap: 12px; }
  .account-menu > div { right: -8px; min-width: 210px; }
  .listing-card { flex-direction: column; }
  .thumb { flex-basis: auto; width: 100%; height: 200px; }
  .gallery-main img { max-height: 320px; }
  table { display: block; overflow-x: auto; white-space: nowrap; }
  .sticky-actions { bottom: 4px; flex-direction: column; align-items: stretch; }
  .sticky-actions .actions { display: flex; margin: 0; }
  .location-picker-head { align-items: stretch; flex-direction: column; }
  .location-map-dialog { width: 100vw; height: 100vh; max-width: none; max-height: none; border-radius: 0; }
  .map-layout { grid-template-columns: 1fr; grid-template-rows: 58vh minmax(0, 1fr); }
  .map-area-panel { border-left: 0; border-top: 1px solid var(--border); }
}

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 8px; border-bottom: 1px solid var(--border); }
th { color: var(--muted); font-weight: 600; }
tr.clickable { cursor: pointer; }
tr.clickable:hover { background: var(--accent-soft); }

.notice { background: var(--accent-soft); border: 1px solid var(--accent); color: var(--accent);
  padding: 12px; border-radius: 8px; }
.error { background: #fdecea; border: 1px solid var(--danger); color: var(--danger);
  padding: 12px; border-radius: 8px; }
.flash { margin: 0 0 14px; }
.price { font-weight: 700; }
a.listing-title { color: var(--accent); text-decoration: none; font-weight: 600; }
