:root {
  --bg: #f6f6f4;
  --surface: #ffffff;
  --border: #e0dedb;
  --text: #22201e;
  --muted: #6e6a66;
  --accent: #1f6f5c;
  --accent-soft: #e6f1ee;
  --deal: #1f6f5c;
  --good: #9a6a1f;
  --check: #4a5a78;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #171a19;
    --surface: #1f2422;
    --border: #313835;
    --text: #ecebe8;
    --muted: #9a9994;
    --accent: #4bbfa0;
    --accent-soft: #22322d;
    --deal: #4bbfa0;
    --good: #d6a44c;
    --check: #8fa3c4;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font: 15px/1.5 system-ui, -apple-system, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 14px 22px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 10;
  flex-wrap: wrap;
}

h1 { font-size: 17px; margin: 0; letter-spacing: -0.01em; }
h2 { font-size: 15px; margin: 0 0 12px; }

nav { display: flex; gap: 4px; }

.tab {
  border: 0;
  background: none;
  color: var(--muted);
  padding: 7px 13px;
  border-radius: var(--radius);
  cursor: pointer;
  font-size: 14px;
}
.tab.active { background: var(--accent-soft); color: var(--accent); font-weight: 600; }

.status { margin-left: auto; color: var(--muted); font-size: 13px; }

main { padding: 22px; max-width: 1180px; margin: 0 auto; }
.view.hidden { display: none; }

.toolbar {
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
  margin-bottom: 18px;
}

button, select, input, textarea {
  font: inherit;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 7px 11px;
}
button { cursor: pointer; }
button:hover { border-color: var(--accent); }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
button.link { border: 0; background: none; color: var(--muted); padding: 4px 6px; }

.chips { display: flex; gap: 5px; }
.chip {
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: var(--surface);
  font-size: 13px;
  cursor: pointer;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: #fff; }

.cards { display: flex; flex-direction: column; gap: 10px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 16px;
  display: flex;
  gap: 14px;
  align-items: flex-start;
}
.card.deal { border-left-color: var(--deal); }
.card.good { border-left-color: var(--good); }
.card.check { border-left-color: var(--check); }
.card.dim { opacity: 0.5; }

.thumb {
  width: 104px;
  height: 104px;
  object-fit: cover;
  border-radius: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  flex: none;
}
.thumb.placeholder {
  background:
    linear-gradient(135deg, transparent 46%, var(--border) 46%, var(--border) 54%, transparent 54%),
    var(--bg);
}

.card-body { flex: 1; min-width: 0; }
.card-title { font-weight: 600; }
.card-title a { color: inherit; text-decoration: none; }
.card-title a:hover { text-decoration: underline; }

.meta { color: var(--muted); font-size: 13px; margin-top: 3px; }
.meta span + span::before { content: " · "; }

.price { font-weight: 600; white-space: nowrap; }
.badge {
  display: inline-block;
  padding: 1px 7px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--accent-soft);
  color: var(--accent);
  margin-left: 6px;
}
.badge.warn { background: transparent; color: var(--good); border: 1px solid var(--good); }
.badge.queued { background: transparent; color: var(--check); border: 1px solid var(--check); }
.badge.muted { background: transparent; color: var(--muted); border: 1px solid var(--border); }

.card-side { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }

.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px;
  margin-bottom: 16px;
  max-width: 520px;
}
.panel label { display: block; margin-bottom: 12px; color: var(--muted); font-size: 13px; }
.panel input[type="text"] { width: 100%; margin-top: 4px; color: var(--text); }

.row { display: flex; gap: 8px; }
.row.end { justify-content: flex-end; margin-top: 16px; }
.check { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 13px; }
.switch { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; }

.steps { margin: 0 0 14px; padding-left: 18px; color: var(--muted); font-size: 13px; }
.qr { width: 190px; }
.qr svg { width: 100%; height: auto; background: #fff; border-radius: 8px; padding: 6px; }
code { font-size: 12px; color: var(--muted); word-break: break-all; }

dialog {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  color: var(--text);
  padding: 22px;
  width: min(760px, 94vw);
}
dialog::backdrop { background: rgba(0, 0, 0, 0.45); }

.grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.grid label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.grid label.span2 { grid-column: span 2; }
.grid label.check { flex-direction: row; align-items: center; }
.grid input, .grid textarea { width: 100%; }

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

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--accent);
  color: #fff;
  padding: 10px 18px;
  border-radius: var(--radius);
  font-size: 14px;
  z-index: 50;
  max-width: 90vw;
}
.toast.error { background: #b4432f; }
.toast.hidden { display: none; }

.progress {
  background: var(--surface);
  border: 1px solid var(--border);
  border-left: 3px solid var(--border);
  border-radius: var(--radius);
  padding: 13px 16px;
  margin-bottom: 16px;
}
.progress.running { border-left-color: var(--accent); }
.progress.hidden { display: none; }
.progress-head { font-size: 14px; color: var(--muted); }
.progress-head strong { color: var(--text); }
.progress-head button { margin-left: 10px; color: var(--accent); }

.bar {
  height: 5px;
  background: var(--bg);
  border-radius: 999px;
  overflow: hidden;
  margin: 10px 0 0;
}
.bar span {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 0.4s ease;
}

.current {
  margin: 10px 0 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  max-height: 130px;
  overflow-y: auto;
}

.history-item {
  border-top: 1px solid var(--border);
  padding: 14px 0;
}
.history-item:first-child { border-top: 0; }
.history-item pre {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 12px;
  overflow-x: auto;
  white-space: pre-wrap;
  word-break: break-word;
  margin: 8px 0 0;
}
.history-item .summary { margin: 8px 0 0; font-size: 14px; }
.history-item .summary strong { color: var(--accent); }
.history-item details { margin-top: 8px; }
.history-item summary { cursor: pointer; color: var(--muted); font-size: 13px; }
#history-body { max-height: 62vh; overflow-y: auto; }

body.centered {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
}
.login { width: min(340px, 92vw); margin: 0; }
.login h1 { font-size: 17px; margin: 0 0 18px; }
.login input { width: 100%; margin-top: 4px; }
.login button { width: 100%; margin-top: 6px; }
.error { color: #b4432f; font-size: 13px; margin: 12px 0 0; }
.error.hidden { display: none; }

@media (max-width: 640px) {
  .grid { grid-template-columns: 1fr; }
  .grid label.span2 { grid-column: span 1; }
  main { padding: 14px; }
  .thumb { display: none; }
}
