/* Watch editor. Colours come from Telegram's theme (light or dark) with fallbacks
   for a plain browser. Mobile first: big touch targets, one column. */
:root {
  --bg: var(--tg-theme-secondary-bg-color, #f1f1f4);
  --card: var(--tg-theme-section-bg-color, var(--tg-theme-bg-color, #ffffff));
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --accent: var(--tg-theme-button-color, #2481cc);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2481cc);
  --danger: var(--tg-theme-destructive-text-color, #e53935);
  --line: var(--tg-theme-section-separator-color, rgba(128, 128, 128, 0.25));
  --warn-bg: rgba(255, 170, 0, 0.16);
  --ok: #2e9d4a;
  --warn: #d97706;
  --over: #e53935;
  --tier-S: #e5484d;
  --tier-A: #f08c00;
  --tier-B: #2f80ed;
  --tier-C: #8e8e98;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-tg]) {
    --bg: #18181b; --card: #232327; --text: #f2f2f2; --hint: #9a9aa0; --line: rgba(255,255,255,0.12);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN",
        "Noto Sans JP", "Segoe UI", sans-serif;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(96px + env(safe-area-inset-bottom));
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
.loading, .empty { text-align: center; color: var(--hint); padding: 48px 16px; }
.view { max-width: 720px; margin: 0 auto; padding: 12px 12px 0; }

/* header */
.top { display: flex; align-items: center; gap: 8px; margin: 4px 4px 12px; }
.top h1 { font-size: 22px; margin: 0; flex: 1; }
.top .count { color: var(--hint); font-size: 15px; font-weight: normal; margin-left: 6px; }
.icon-btn {
  border: 0; background: var(--card); width: 44px; height: 44px; border-radius: 12px;
  font-size: 20px; line-height: 44px; text-align: center; padding: 0;
}
.lang-btn { width: auto; min-width: 44px; padding: 0 12px; font-size: 14px; font-weight: 600; color: var(--link); }
.link-btn { border: 0; background: none; color: var(--link); padding: 8px 0 0; font-size: 14px; }
.hidden { display: none !important; }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 13px; }

/* cards & sections */
.card { background: var(--card); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.section-title { font-size: 13px; color: var(--hint); margin: 16px 6px 6px; text-transform: none; }
.budget { font-size: 14px; }
.budget b { font-weight: 600; }
.note { font-size: 13px; color: var(--hint); margin-top: 6px; }
.warn { background: var(--warn-bg); border-radius: 10px; padding: 8px 10px; margin-top: 8px; font-size: 13px; }
.alert-paused { border-left: 4px solid var(--danger); }

/* capacity gauge */
.cap-head { display: flex; align-items: baseline; gap: 8px; margin-bottom: 8px; }
.cap-title { flex: 1; font-weight: 600; }
.cap-pct { font-size: 22px; font-weight: 700; }
.ok { color: var(--ok); }
.near { color: var(--warn); }
.over { color: var(--over); }
.gauge {
  position: relative; display: flex; height: 14px; border-radius: 999px; overflow: hidden;
  background: var(--line);
}
.gauge.small { height: 10px; margin-top: 10px; }
.gauge-seg { height: 100%; transition: width .25s ease; }
.gauge-seg + .gauge-seg { box-shadow: inset 1px 0 0 rgba(255, 255, 255, .55); }
.seg-S { background: var(--tier-S); }
.seg-A { background: var(--tier-A); }
.seg-B { background: var(--tier-B); }
.seg-C { background: var(--tier-C); }
.gauge-limit { position: absolute; top: 0; bottom: 0; width: 3px; margin-left: -1px; background: var(--text); box-shadow: 0 0 0 1.5px var(--card); }
.cap-legend { display: flex; flex-wrap: wrap; gap: 4px 14px; margin-top: 8px; font-size: 13px; }
.legend { display: inline-flex; align-items: center; gap: 5px; }
.legend.none { color: var(--hint); }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 3px; flex: none; }
.cap-details { margin-top: 10px; font-size: 13px; }
.cap-details p { margin: 0 0 8px; }
.cap-row { display: flex; align-items: center; gap: 8px; padding: 3px 0; }

/* priority tiers */
.tier {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  width: 26px; height: 26px; border-radius: 8px; font-weight: 800; font-size: 14px; color: #fff;
}
.tier-S { --tier: var(--tier-S); }
.tier-A { --tier: var(--tier-A); }
.tier-B { --tier: var(--tier-B); }
.tier-C { --tier: var(--tier-C); }
.tier { background: var(--tier); }
.chip.chip-tier { font-weight: 700; min-width: 40px; justify-content: center; }
.chip.chip-tier.on { background: var(--tier); border-color: var(--tier); color: #fff; }
.prio-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.prio {
  display: flex; flex-direction: column; align-items: center; gap: 1px; padding: 8px 2px 7px;
  border: 1.5px solid var(--line); border-radius: 12px; background: transparent; min-height: 84px;
}
.prio-letter { font-size: 20px; font-weight: 800; color: var(--tier); }
.prio-name { font-size: 12px; font-weight: 600; }
.prio-meta, .prio-cost { font-size: 11px; color: var(--hint); }
.prio.on { border-color: var(--tier); background: var(--tier); color: #fff; }
.prio.on .prio-letter, .prio.on .prio-meta, .prio.on .prio-cost { color: #fff; }
.impact { margin-top: 2px; }
.impact-text { font-size: 14px; font-weight: 600; margin-top: 6px; }

/* search and filters */
.search {
  width: 100%; border: 0; border-radius: 12px; padding: 11px 14px; background: var(--card);
  margin-bottom: 10px; outline: none;
}
.filters { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 6px; margin-bottom: 4px; align-items: center; }
.search-row { display: flex; gap: 8px; margin-bottom: 10px; }
.search-row .search { flex: 1; min-width: 0; margin-bottom: 0; }
.sort {
  flex: none; max-width: 40%; border: 0; border-radius: 12px; background: var(--card);
  padding: 0 10px; font-size: 14px;
}
.filters::-webkit-scrollbar { display: none; }

/* chips */
.chip {
  display: inline-flex; align-items: center; gap: 4px; border-radius: 999px; padding: 6px 12px;
  border: 1px solid var(--line); background: var(--card); font-size: 14px; white-space: nowrap;
}
.chip.on { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
.chip.small { padding: 2px 9px; font-size: 12px; }
.chip.tag { padding: 4px 6px 4px 11px; }
.chip.tag button { border: 0; background: none; padding: 0 4px; font-size: 16px; line-height: 1; color: inherit; opacity: 0.7; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }

/* watch list */
.watch { display: block; position: relative; }
.watch.off { opacity: 0.55; }
.watch-head { display: flex; align-items: flex-start; gap: 10px; }
.watch-head .tier { margin-top: 1px; }
.watch-title { flex: 1; min-width: 0; }
.watch-name { font-weight: 600; font-size: 16px; overflow-wrap: anywhere; }
.watch-sub { color: var(--hint); font-size: 14px; overflow-wrap: anywhere; }
.watch .chips { margin-top: 8px; }
.watch-foot { display: flex; align-items: center; gap: 8px; margin-top: 8px; font-size: 13px; color: var(--hint); }
.watch-foot .grow { flex: 1; }
.more-btn { border: 0; background: none; font-size: 22px; line-height: 1; padding: 4px 8px; color: var(--hint); }
.badge-hot { color: #ff7a00; font-size: 13px; font-weight: 600; margin-left: 4px; }

/* switch */
.switch { position: relative; width: 51px; height: 31px; flex: none; }
.switch input { opacity: 0; width: 100%; height: 100%; margin: 0; position: absolute; z-index: 1; cursor: pointer; }
.switch span {
  position: absolute; inset: 0; border-radius: 31px; background: var(--line); transition: background .15s;
}
.switch span::after {
  content: ""; position: absolute; width: 27px; height: 27px; left: 2px; top: 2px; border-radius: 50%;
  background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.3); transition: transform .15s;
}
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::after { transform: translateX(20px); }

/* form */
.field { margin-bottom: 14px; }
.field:last-child { margin-bottom: 0; }
.field > label, .label { display: block; font-size: 14px; font-weight: 600; margin-bottom: 6px; }
.hint { font-size: 12px; color: var(--hint); margin-top: 4px; }
.input, textarea.input {
  width: 100%; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: transparent;
  outline: none; min-height: 44px;
}
.input:focus { border-color: var(--accent); }
.input.error, .field.error .input { border-color: var(--danger); }
.field-error { color: var(--danger); font-size: 13px; margin-top: 4px; }
textarea.input { min-height: 80px; resize: vertical; }
.row { display: flex; gap: 10px; align-items: center; }
.row > * { flex: 1; }
.yen { position: relative; }
.yen::before { content: "¥"; position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--hint); }
.yen .input { padding-left: 26px; }
.tilde { flex: none; color: var(--hint); }
.toggle-row { display: flex; align-items: center; gap: 12px; min-height: 44px; }
.toggle-row .text { flex: 1; }
.toggle-row .text small { display: block; color: var(--hint); font-size: 12px; }
.toggle-row + .field, .field + .toggle-row { margin-top: 14px; }
.segmented { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.segmented button { flex: 1; border: 0; background: transparent; padding: 10px 4px; min-height: 42px; font-size: 14px; }
.segmented button + button { border-left: 1px solid var(--line); }
.segmented button.on { background: var(--accent); color: var(--accent-text); }
.tag-input { display: flex; gap: 6px; margin-top: 8px; }
.tag-input .input { flex: 1; }
details.card summary { font-weight: 600; cursor: pointer; list-style: none; }
details.card summary::after { content: " ▾"; color: var(--hint); }
details.card[open] summary { margin-bottom: 12px; }

/* buttons */
.btn {
  border: 0; border-radius: 12px; padding: 12px 16px; min-height: 48px; font-weight: 600;
  background: var(--accent); color: var(--accent-text);
}
.btn.secondary { background: var(--card); color: var(--link); border: 1px solid var(--line); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid var(--line); }
.btn.block { width: 100%; }
.btn.danger-fill { background: var(--danger); color: #fff; }
.btn:disabled { opacity: 0.5; }
.small-btn { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 0 14px; min-height: 44px; }
.footer {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 5;
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg); border-top: 1px solid var(--line);
}
.footer .inner { max-width: 720px; margin: 0 auto; display: flex; gap: 10px; }
.footer .btn { flex: 1; }
.fab {
  position: fixed; right: 16px; bottom: calc(18px + env(safe-area-inset-bottom)); z-index: 5;
  border: 0; border-radius: 999px; padding: 0 22px; height: 56px; font-size: 17px; font-weight: 700;
  background: var(--accent); color: var(--accent-text); box-shadow: 0 4px 14px rgba(0,0,0,.25);
}
.actions { display: flex; gap: 10px; margin: 8px 0 16px; }
.actions .btn { flex: 1; }

/* settings and backup */
.nav-card { display: block; width: 100%; text-align: left; border: 0; color: inherit; }
.nav-card b { display: block; color: var(--link); margin-bottom: 2px; }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row.left > * { flex: none; }
.tip { font-size: 13px; color: var(--hint); background: var(--bg); border-radius: 10px; padding: 10px 12px; }
.plan-title { font-weight: 700; margin-bottom: 8px; }
.plan .warn { margin: 0 0 10px; }
.plan-counts { margin-bottom: 8px; }
.chip.add { border-color: var(--ok); color: var(--ok); }
.chip.upd { border-color: var(--tier-B); color: var(--tier-B); }
.chip.del { border-color: var(--danger); color: var(--danger); }
.plan-group { font-size: 14px; margin: 8px 0; }
.plan-group.del b { color: var(--danger); }
.names { margin: 4px 0 0; padding-left: 20px; font-size: 14px; overflow-wrap: anywhere; }
.plan .btn { margin-top: 12px; }
.snapshot { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-top: 1px solid var(--line); font-size: 14px; }
.snapshot .grow { flex: 1; min-width: 0; }
.note.first { margin-top: 0; }

/* review flag */
.chip.review { background: var(--warn-bg); border-color: var(--warn); color: var(--warn); font-weight: 600; }
.chip.list { border-style: dashed; }
.chip.chip-review.on { background: var(--warn); border-color: var(--warn); color: #fff; }
.watch.to-check { box-shadow: inset 4px 0 0 var(--warn); }
.review-card { background: var(--warn-bg); display: flex; flex-direction: column; gap: 10px; font-size: 14px; }
.note.clamp, small.clamp { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }

/* exclusion lists */
.list-picker { display: flex; flex-direction: column; gap: 8px; }
.list-option { display: flex; align-items: stretch; border: 1.5px solid var(--line); border-radius: 12px; overflow: hidden; }
.list-option.on { border-color: var(--accent); }
.list-toggle {
  flex: 1; display: flex; align-items: flex-start; gap: 10px; border: 0; background: transparent;
  padding: 10px 12px; text-align: left; min-height: 48px;
}
.list-toggle .check {
  flex: none; width: 22px; height: 22px; border-radius: 6px; border: 1.5px solid var(--line);
  display: inline-flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700;
}
.list-option.on .check { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.list-toggle .grow, .list-row .grow { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.list-toggle small, .list-row small { color: var(--hint); font-size: 12px; overflow-wrap: anywhere; }
.info-btn { flex: none; width: 48px; border: 0; border-left: 1px solid var(--line); background: transparent; font-size: 20px; color: var(--link); }
.list-row {
  display: flex; align-items: center; gap: 10px; width: 100%; border: 0; border-top: 1px solid var(--line);
  background: transparent; padding: 12px 2px; text-align: left; color: inherit;
}
.list-row + .btn { margin-top: 12px; }
.chev { color: var(--hint); font-size: 22px; }
.sheet-body { padding: 0 8px 12px; max-height: 50vh; overflow-y: auto; }
.sheet-body .label { margin: 10px 0 6px; }
.pattern-info { border-top: 1px solid var(--line); padding: 8px 0; font-size: 14px; }
.pattern-info code { display: block; color: var(--hint); font-size: 12px; overflow-wrap: anywhere; margin-top: 2px; }
.pattern-row { display: flex; flex-direction: column; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--line); }
.pattern-row:first-child { padding-top: 0; }
.link-btn.danger-text { color: var(--danger); align-self: flex-start; padding-top: 0; }

/* trying words and patterns */
.test-details { margin-top: 14px; border-top: 1px solid var(--line); padding-top: 12px; }
.test-details summary { font-weight: 600; cursor: pointer; color: var(--link); }
.test-details[open] summary { margin-bottom: 10px; }
.test-panel { display: flex; flex-direction: column; gap: 10px; }
.hint.first { margin-top: 0; }
.test-results { display: flex; flex-direction: column; gap: 8px; }
.test-results:empty { display: none; }
.test-item { border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; font-size: 14px; }
.test-item.zero { opacity: 0.7; }
.test-head { display: flex; gap: 8px; align-items: baseline; }
.test-label { flex: 1; font-weight: 600; overflow-wrap: anywhere; }
.test-count { flex: none; color: var(--danger); font-size: 13px; font-weight: 600; }
.test-item.zero .test-count { color: var(--hint); }
.test-pattern { display: block; color: var(--hint); font-size: 12px; overflow-wrap: anywhere; margin-top: 2px; }
.test-examples { margin: 6px 0 0; padding-left: 18px; font-size: 13px; }
.test-examples li { margin: 2px 0; overflow-wrap: anywhere; }
.test-price { color: var(--hint); font-variant-numeric: tabular-nums; }
mark { background: rgba(229, 57, 53, 0.22); color: inherit; border-radius: 3px; padding: 0 1px; }
.test-sample-label { margin: 4px 0 -4px; }
.test-quiet { font-size: 13px; color: var(--hint); overflow-wrap: anywhere; }
.verdict { border-radius: 10px; padding: 8px 10px; font-size: 14px; display: flex; flex-direction: column; gap: 2px; overflow-wrap: anywhere; }
.verdict.excluded { background: rgba(229, 57, 53, 0.1); }
.verdict.excluded b { color: var(--danger); }
.verdict.kept { background: rgba(46, 157, 74, 0.12); }
.verdict.kept b { color: var(--ok); }

/* preview */
.result { display: flex; gap: 10px; padding: 10px 0; border-bottom: 1px solid var(--line); text-decoration: none; color: inherit; }
.result:last-child { border-bottom: 0; }
.result.excluded { opacity: 0.5; }
.result img, .result .noimg { width: 72px; height: 72px; border-radius: 10px; object-fit: cover; flex: none; background: var(--line); }
.result .body { flex: 1; min-width: 0; }
.result .price { font-weight: 700; }
.result .title { font-size: 14px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.result .meta { font-size: 12px; color: var(--hint); margin-top: 2px; }
.result .why { font-size: 12px; color: var(--danger); margin-top: 2px; }
.badge { display: inline-block; font-size: 11px; border-radius: 6px; padding: 1px 6px; margin-right: 4px; background: var(--line); }
.badge.new { background: #e53935; color: #fff; }

/* sheet + toast */
.backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 10; display: flex; align-items: flex-end; }
.sheet { background: var(--card); width: 100%; border-radius: 16px 16px 0 0; padding: 8px 12px calc(12px + env(safe-area-inset-bottom)); }
.sheet .title { color: var(--hint); font-size: 13px; text-align: center; padding: 8px; }
.sheet button { display: block; width: 100%; border: 0; background: none; padding: 15px; font-size: 17px; border-top: 1px solid var(--line); color: var(--link); }
.sheet button.danger { color: var(--danger); }
.sheet-head { padding: 10px 8px 14px; text-align: center; }
.sheet-head p { margin: 6px 0 0; font-size: 14px; color: var(--hint); }
.sheet-prio { display: flex; align-items: center; gap: 8px; padding: 6px 8px 12px; }
.sheet-prio span { flex: 1; color: var(--hint); font-size: 14px; }
.sheet .sheet-prio .tier-btn {
  display: inline-block; width: 46px; height: 40px; padding: 0; border: 1.5px solid var(--tier);
  border-radius: 10px; color: var(--tier); font-weight: 800; font-size: 16px; background: none;
}
.sheet .sheet-prio .tier-btn.on { background: var(--tier); color: #fff; }
#toast {
  position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: rgba(30,30,30,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px;
  max-width: calc(100% - 32px); z-index: 20; opacity: 0; pointer-events: none; transition: opacity .2s;
}
#toast.show { opacity: 1; }
