:root {
  color-scheme: dark;
  --bg: #0f1216;
  --card: #171b21;
  --text: #e6edf3;
  --muted: #8b949e;
  --border: #2d333b;
  --accent: #2f81f7;
  --accent-text: #ffffff;
  --ok: #1a7f37;
  --wait: #9a6700;
  --bad: #cf222e;
  --match-bg: #12301d;
  --chip-on: #1c3456;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
h1 { font-size: 20px; margin: 0; }
h2 { font-size: 15px; margin: 0 0 12px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.empty { margin: 8px 0 0; }

input[type=text], input[type=password], input[type=number], select {
  width: 100%;
  padding: 7px 9px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

button {
  font: inherit;
  padding: 6px 12px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: var(--accent-text);
  cursor: pointer;
  white-space: nowrap;
}
button.ghost { background: transparent; color: var(--text); border-color: var(--border); }
button.danger { color: var(--bad); }
button.link { background: none; border: none; color: var(--accent); padding: 0 4px; font-size: 12px; }

.row-between { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.inline { display: flex; gap: 8px; }
.switch-row { display: flex; align-items: center; gap: 8px; cursor: pointer; }
.switch-row input { width: 16px; height: 16px; margin: 0; }

.field { display: block; margin-top: 12px; }
.field > span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.field.short { max-width: 220px; }

.status-line { display: flex; align-items: center; gap: 8px; margin-top: 12px; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--bad); flex: none; }
.dot.ok { background: var(--ok); }
.dot.wait { background: var(--wait); }
.status-line button { margin-left: auto; }

/* options page */
body.options { padding: 24px 16px 48px; }
body.options > * { max-width: 760px; margin-left: auto; margin-right: auto; }
.top { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 16px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 16px; margin-bottom: 16px; }

.rule { border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin-top: 12px; }
.rule.off { opacity: 0.55; }
.rule-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.rule-title { font-weight: 600; word-break: break-word; }
.rule-fields { display: grid; grid-template-columns: 1fr 140px 220px; gap: 12px; }
.rule-fields .field.short { max-width: none; }
.stores-head { display: flex; align-items: center; gap: 4px; margin-top: 12px; font-size: 12px; color: var(--muted); }
.stores { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.chip { display: inline-flex; align-items: center; gap: 5px; padding: 4px 8px; border: 1px solid var(--border); border-radius: 999px; font-size: 12px; cursor: pointer; user-select: none; }
.chip:has(input:checked) { background: var(--chip-on); border-color: var(--accent); }
.chip input { margin: 0; }

@media (max-width: 520px) {
  .rule-fields { grid-template-columns: 1fr; }
}

/* popup */
body.popup { width: 620px; padding: 14px; }
.switch-row.compact { font-size: 13px; }
.buttons { margin-top: 10px; }
.recent-head { margin-top: 14px; padding-bottom: 4px; border-bottom: 1px solid var(--border); }
.recent { list-style: none; margin: 0; padding: 0; max-height: 470px; overflow-y: auto; }
.recent li { padding: 10px 8px; border-bottom: 1px solid var(--border); }
.recent li.matched { background: var(--match-bg); }
.recent-top { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; font-size: 12px; }
.store { font-weight: 600; color: var(--muted); }
.price { font-weight: 700; font-size: 14px; }
.recent .title { display: block; color: var(--text); text-decoration: none; margin: 2px 0; }
.recent .title:hover { color: var(--accent); }

button:disabled { opacity: 0.4; cursor: default; }

.states-box { margin-top: 10px; }
.states-box > summary { cursor: pointer; list-style: revert; }
.states-box[open] > summary { margin-bottom: 4px; }

.recent li.has-image { display: flex; gap: 10px; align-items: flex-start; }
.recent .thumb { width: 72px; height: 72px; object-fit: contain; flex: none; border-radius: 6px; background: #fff; border: 1px solid var(--border); }
.recent-text { min-width: 0; flex: 1; }

.backup-buttons { margin-top: 12px; }

.store { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.price-box { display: inline-flex; align-items: baseline; gap: 6px; flex: none; }
.regular { color: var(--muted); text-decoration: line-through; }
.discount { background: var(--ok); color: #fff; font-weight: 700; font-size: 11px; padding: 1px 6px; border-radius: 999px; }

.deal-actions { display: flex; gap: 6px; margin-top: 6px; }
.small-btn { padding: 3px 10px; font-size: 12px; }

/* condition badges */
.meta { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.cond { font-weight: 700; font-size: 11px; padding: 1px 8px; border-radius: 999px; letter-spacing: 0.02em; }
.cond-new { background: #1a7f37; color: #fff; }
.cond-excellent { background: #0891b2; color: #fff; }
.cond-good { background: #ea580c; color: #fff; }
.cond-fair { background: #facc15; color: #1f2328; }
.cond-other { background: var(--border); color: var(--text); }

/* popup header row */
.recent-head.row-between { display: flex; }

/* feed window */
body.feed { padding: 20px 16px 40px; }
body.feed > * { max-width: 960px; margin-left: auto; margin-right: auto; }
body.feed .top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; }
body.feed .top .status-line { margin-top: 0; }
.recent.feed-list { max-height: none; overflow: visible; }

/* logo */
.brand { display: inline-flex; align-items: center; gap: 8px; }
.logo { width: 24px; height: 24px; border-radius: 6px; flex: none; }
body.feed .logo, body.options .logo { width: 36px; height: 36px; border-radius: 8px; }

/* new since last open */
.recent li.unseen { box-shadow: inset 3px 0 0 #e5383b; }
.new-count { background: #e5383b; color: #fff; font-weight: 700; font-size: 11px; padding: 1px 7px; border-radius: 999px; }

/* feed window: search + sort */
.feed-tools { display: flex; gap: 8px; margin: 12px 0 4px; flex-wrap: wrap; }
.feed-tools input[type=search] { flex: 1 1 280px; min-width: 0; }
.feed-tools select { flex: 0 0 auto; width: auto; }

/* terms page + popup banner */
.terms-text { white-space: pre-wrap; font-size: 13px; line-height: 1.5; max-height: 55vh; overflow-y: auto; padding: 14px 16px; border: 1px solid var(--border); border-radius: 8px; background: var(--bg); }
.terms-check { margin-top: 16px; align-items: flex-start; }
.terms-check input { margin-top: 3px; }
.terms-buttons { margin-top: 12px; }
.status-ok { color: var(--ok); font-weight: 600; }
.status-bad { color: var(--bad); font-weight: 600; }
.terms-banner { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-top: 10px; padding: 10px 12px; border-radius: 8px; background: #3a2a0a; border: 1px solid var(--wait); font-size: 13px; }
.terms-banner[hidden] { display: none; }

/* rules explainer + guide links */
.rules-explainer { background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; font-size: 13px; }
.rules-explainer p { margin: 0 0 6px; }
.rules-explainer ul { margin: 0 0 8px; padding-left: 18px; }
.rules-explainer li { margin: 2px 0; }
.guide-link { color: var(--accent); text-decoration: none; font-family: inherit; }
.guide-link:hover { text-decoration: underline; }
.brand .guide-link.small { font-size: 12px; margin-left: 6px; }
.header-right { display: inline-flex; gap: 14px; align-items: baseline; }

/* user guide */
body.guide { line-height: 1.55; }
body.guide .card h2 { font-size: 18px; margin-bottom: 10px; }
body.guide .card h3 { font-size: 14px; margin: 14px 0 6px; }
body.guide p, body.guide li { font-size: 14px; }
.guide-toc { display: flex; flex-wrap: wrap; gap: 6px 16px; font-size: 13px; }
.guide-toc a { color: var(--accent); text-decoration: none; }
.guide-toc a:hover { text-decoration: underline; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; margin: 10px 0; }
.explain-box { border: 1px solid var(--border); border-radius: 8px; padding: 12px 14px; background: var(--bg); }
.explain-box h3 { margin: 0 0 6px !important; }
.explain-box p { margin: 0; }
.explain-box.highlight { border-color: var(--ok); background: var(--match-bg); }
.note { border-left: 3px solid var(--accent); padding: 6px 12px; background: var(--bg); border-radius: 0 6px 6px 0; }
.table-wrap { overflow-x: auto; }
.guide-table { width: 100%; border-collapse: collapse; font-size: 13px; }
.guide-table th, .guide-table td { text-align: left; vertical-align: top; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.guide-table th { color: var(--muted); font-size: 12px; font-weight: 600; }
.guide-table td:first-child { white-space: nowrap; font-weight: 600; }
.example { display: grid; grid-template-columns: minmax(200px, 1fr) 2fr; gap: 12px; border: 1px solid var(--border); border-radius: 8px; padding: 12px; margin: 10px 0; }
@media (max-width: 640px) { .example { grid-template-columns: 1fr; } }
.example-rule { font-family: ui-monospace, Consolas, monospace; font-size: 13px; line-height: 2; }
.example-result p { margin: 2px 0; font-size: 13px; }
.chip-k { display: inline-block; font-family: system-ui, sans-serif; font-size: 11px; color: var(--muted); border: 1px solid var(--border); border-radius: 999px; padding: 0 7px; margin-right: 2px; line-height: 1.6; }
.rule-label { font-family: system-ui, sans-serif; font-size: 11px; font-weight: 700; color: var(--accent); margin-right: 4px; }
.yes, .no { display: inline-block; font-size: 11px; font-weight: 700; padding: 0 7px; border-radius: 999px; margin-right: 6px; }
.yes { background: var(--ok); color: #fff; }
.no { background: var(--border); color: var(--text); }
.mistakes li, .checklist li { margin: 6px 0; }
code { background: var(--bg); border: 1px solid var(--border); border-radius: 4px; padding: 0 5px; font-size: 12px; }
.badge-demo { display: inline-block; min-width: 34px; text-align: center; font-size: 11px; font-weight: 700; color: #fff; border-radius: 4px; padding: 1px 6px; }
.badge-demo.red { background: #e5383b; }
.badge-demo.amber { background: #9a6700; }
.badge-demo.grey { background: #6e7781; }

/* ---------- website ---------- */
body.web .header-right { align-items: center; }
.control-card { padding-top: 4px; }
.control-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.control-row .status-line { margin-top: 12px; min-width: 0; }
.control-buttons { align-items: center; flex-wrap: wrap; margin-top: 12px; }
.key-box { margin-top: 4px; }
.key-box[hidden] { display: none; }
.key-box .field > span { color: var(--text); font-size: 13px; }
.alert-setup { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--border); }
.alert-buttons { display: inline-flex; gap: 8px; margin-left: auto; flex-wrap: wrap; }
.alert-buttons button[hidden] { display: none; }
.alert-note { margin: 8px 0 0; }
.pill { font-size: 12px; font-weight: 600; padding: 2px 10px; border-radius: 999px; border: 1px solid var(--border); }
.pill-ok { border-color: var(--ok); color: #3fb950; }
.pill-bad { border-color: var(--bad); color: #ff7b72; }
.pill-wait { border-color: var(--wait); color: #d29922; }

.overlay { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(5, 7, 10, 0.82); }
.overlay[hidden] { display: none; }
body.feed .overlay > .overlay-card { max-width: 440px; width: 100%; margin: 0; text-align: center; }
.overlay-card .logo { width: 56px; height: 56px; border-radius: 12px; }
.overlay-card h2 { margin-top: 10px; }

.toasts { position: fixed; right: 16px; bottom: 16px; z-index: 40; display: flex; flex-direction: column; gap: 8px; width: min(360px, calc(100vw - 32px)); }
body.feed > .toasts { margin: 0; max-width: none; }
.toast { background: var(--card); border: 1px solid var(--ok); border-left: 4px solid var(--ok); border-radius: 8px; padding: 10px 12px; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.45); }
.toast-head { font-size: 12px; font-weight: 700; color: #3fb950; }
.toast-title { margin: 2px 0; word-break: break-word; }

input[type=search] { padding: 7px 9px; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; }

@media (max-width: 640px) {
  .alert-buttons { margin-left: 0; }
  .recent li.has-image { gap: 8px; }
  .recent .thumb { width: 56px; height: 56px; }
}
body.feed > .overlay { max-width: none; margin: 0; }
@media (max-width: 640px) { body.web .stores-head .muted { display: none; } }
