:root {
  --bg: #f3f5f9;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --line: #e2e8f0;
  --field: #f8fafc;
  --accent: #2563eb;
  --accent-text: #ffffff;
  --danger: #dc2626;
  --green-bg: #dcfce7; --green-text: #14532d; --green-line: #86efac;
  --yellow-bg: #fef9c3; --yellow-text: #713f12; --yellow-line: #fde047;
  --red-bg: #fee2e2; --red-text: #7f1d1d; --red-line: #fca5a5;
  --blue-bg: #dbeafe; --blue-text: #1e3a8a;
  --shadow: 0 1px 2px rgba(15, 23, 42, .06), 0 6px 20px -10px rgba(15, 23, 42, .18);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220; --card: #131c2e; --text: #e8eef8; --muted: #8fa0b8; --line: #26334a; --field: #0f1729;
    --accent: #60a5fa; --accent-text: #0b1220; --danger: #f87171;
    --green-bg: #12432a; --green-text: #c9f7d9; --green-line: #1f7a44;
    --yellow-bg: #4a3f0b; --yellow-text: #fdf3c4; --yellow-line: #8a7512;
    --red-bg: #4c1616; --red-text: #ffd6d6; --red-line: #a32d2d;
    --blue-bg: #1e2f55; --blue-text: #dbe7ff;
    --shadow: 0 1px 2px rgba(0, 0, 0, .4), 0 6px 20px -10px rgba(0, 0, 0, .6);
  }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}
a { color: var(--accent); }
h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 18px; margin: 0 0 10px; }
h3 { font-size: 15px; margin: 14px 0 8px; }
.wrap { max-width: 1500px; margin: 0 auto; padding: 16px; }
.topbar { background: var(--card); border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 10; }
.topbar .wrap { display: flex; align-items: center; gap: 18px; padding-top: 10px; padding-bottom: 10px; flex-wrap: wrap; }
.brand { font-weight: 700; }
.nav { display: flex; gap: 4px; flex-wrap: wrap; flex: 1; }
.nav a { text-decoration: none; color: var(--muted); padding: 6px 10px; border-radius: 8px; font-weight: 600; }
.nav a.active, .nav a:hover { color: var(--text); background: var(--field); }
.today-cost { color: var(--muted); font-size: 13px; }
.card { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); padding: 16px; margin-bottom: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: flex-end; }
.row > * { min-width: 0; }
.grow { flex: 1; }
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 10px; }
label > input, label > textarea, label > select { margin-top: 5px; }
input, textarea, select {
  width: 100%; font: inherit; color: var(--text); background: var(--field);
  border: 1px solid var(--line); border-radius: 10px; padding: 9px 11px; outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { min-height: 170px; resize: vertical; }
.btn {
  appearance: none; border: 1px solid var(--line); background: var(--card); color: var(--text);
  font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 10px; cursor: pointer; white-space: nowrap;
}
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 4px 9px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: default; }
.banner { padding: 10px 14px; border-radius: 10px; margin-bottom: 12px; background: var(--yellow-bg); color: var(--yellow-text); }
.banner.error { background: var(--red-bg); color: var(--red-text); }
.banner.ok { background: var(--green-bg); color: var(--green-text); }
.paste-zone {
  border: 2px dashed var(--line); border-radius: 12px; padding: 14px; text-align: center; color: var(--muted);
  margin-bottom: 12px; cursor: pointer;
}
.paste-zone.drag { border-color: var(--accent); color: var(--accent); }
.thumbs { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; justify-content: center; }
.thumb { position: relative; }
.thumb img { height: 90px; border-radius: 8px; border: 1px solid var(--line); display: block; }
.thumb button { position: absolute; top: -8px; right: -8px; border-radius: 50%; width: 24px; height: 24px; padding: 0; line-height: 1; }
details summary { cursor: pointer; font-weight: 600; color: var(--muted); margin: 6px 0; }
pre.text { white-space: pre-wrap; background: var(--field); padding: 10px; border-radius: 10px; max-height: 360px; overflow: auto; font-size: 13px; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
th, td { border-bottom: 1px solid var(--line); padding: 7px 8px; text-align: left; vertical-align: top; }
th { color: var(--muted); font-size: 12px; font-weight: 700; white-space: nowrap; background: var(--field); position: sticky; top: 0; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
.table-scroll { overflow-x: auto; }
tr.status-green td.status { background: var(--green-bg); color: var(--green-text); }
tr.status-yellow td.status { background: var(--yellow-bg); color: var(--yellow-text); }
tr.status-red td.status { background: var(--red-bg); color: var(--red-text); }
tr.best td { background: color-mix(in srgb, var(--green-bg) 45%, transparent); }
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; background: var(--field); color: var(--muted); white-space: nowrap; }
.badge.queued { background: var(--field); color: var(--muted); }
.badge.parsing, .badge.searching { background: var(--blue-bg); color: var(--blue-text); }
.badge.done { background: var(--green-bg); color: var(--green-text); }
.badge.error { background: var(--red-bg); color: var(--red-text); }
.badge.cancelled { background: var(--yellow-bg); color: var(--yellow-text); }
.badge.favorite { background: var(--green-bg); color: var(--green-text); }
.badge.blocked { background: var(--red-bg); color: var(--red-text); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; }
.chip { background: var(--field); border: 1px solid var(--line); border-radius: 8px; padding: 2px 8px; font-size: 12.5px; }
.item-head { display: flex; gap: 10px; align-items: baseline; justify-content: space-between; flex-wrap: wrap; }
.summary { background: var(--field); border-left: 4px solid var(--accent); padding: 8px 12px; border-radius: 8px; margin: 10px 0; }
.verified { color: var(--green-text); font-weight: 700; }
.section-title { margin: 16px 0 6px; font-weight: 700; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 12px; }
.stat { background: var(--field); border-radius: 12px; padding: 12px; }
.stat .v { font-size: 22px; font-weight: 700; font-variant-numeric: tabular-nums; }
.stat .l { color: var(--muted); font-size: 12.5px; }
.progress { height: 6px; background: var(--field); border-radius: 99px; overflow: hidden; min-width: 80px; }
.progress > div { height: 100%; background: var(--accent); }
.login-body { display: grid; place-items: center; min-height: 100vh; padding: 16px; }
.login-card { background: var(--card); padding: 24px; border-radius: 16px; box-shadow: var(--shadow); width: 100%; max-width: 360px; }
.login-card h1 { margin-bottom: 16px; }
.login-card .btn { width: 100%; margin-top: 6px; }
.login-error { color: var(--danger); font-weight: 600; }
.kp textarea { min-height: 220px; }
.hint { font-size: 12.5px; color: var(--muted); margin-top: -4px; margin-bottom: 10px; }
@media (max-width: 700px) {
  .wrap { padding: 10px; }
  .card { padding: 12px; }
}
