:root {
  color-scheme: light;
  --ink: #13203a;
  --muted: #6f7b8e;
  --line: #e4e7ec;
  --paper: #ffffff;
  --canvas: #f3f4f1;
  --navy: #101a2f;
  --blue: #3468ff;
  --green: #19a974;
  --red: #de5a5a;
  --amber: #e99a2d;
  --radius: 18px;
  font-family: Inter, "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--canvas); }
body { margin: 0; color: var(--ink); background: radial-gradient(circle at 80% -10%, #dce5ff 0, transparent 26rem), var(--canvas); }
button, input, select { font: inherit; }
button, a { -webkit-tap-highlight-color: transparent; }

.shell { min-height: 100vh; width: min(1500px, 100%); margin: auto; padding: 24px 32px 0; }
.button { min-height: 40px; padding: 0 16px; border: 1px solid transparent; border-radius: 11px; cursor: pointer; transition: transform .16s ease, box-shadow .16s ease, background .16s ease; }
.button:hover { transform: translateY(-1px); }
.button:disabled { opacity: .58; cursor: wait; transform: none; }
.button.primary { color: white; background: var(--navy); box-shadow: 0 8px 20px #101a2f20; }
.button.ghost { color: var(--ink); border-color: #d9dde5; background: #ffffffa8; }
.scan-actions { display: grid; gap: 5px; }
.scan-actions .button { min-height: 34px; }
.local-scan-button { font-size: 11px; }
.scan-icon { display: inline-block; margin-right: 6px; font-size: 18px; vertical-align: -1px; }
.scanning .scan-icon { animation: rotate 1s linear infinite; }
.stream-status { display: flex; align-items: center; gap: 7px; margin-right: 6px; color: var(--muted); font-size: 12px; }
.stream-status i { width: 8px; height: 8px; border-radius: 50%; background: #aab1bd; box-shadow: 0 0 0 4px #aab1bd20; }
.stream-status.online i { background: var(--green); box-shadow: 0 0 0 4px #19a97420; }
.stream-status.error i { background: var(--red); box-shadow: 0 0 0 4px #de5a5a20; }
.visually-hidden { position: absolute !important; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

.stats { display: grid; grid-template-columns: minmax(250px, 1.35fr) repeat(4, minmax(125px, 1fr)); overflow: hidden; border: 1px solid var(--line); border-radius: var(--radius); background: #ffffffdf; box-shadow: 0 14px 42px #1c29490a; backdrop-filter: blur(12px); }
.brand-summary { min-width: 0; min-height: 108px; display: flex; align-items: center; gap: 14px; padding: 20px 26px; color: inherit; border-right: 1px solid var(--line); text-decoration: none; }
.brand-summary:hover .brand-mark { transform: translateY(-1px); box-shadow: 0 10px 24px #101a2f22; }
.brand-mark { display: grid; place-items: center; width: 46px; height: 46px; flex: 0 0 46px; border-radius: 14px; color: #fff; font: 800 24px/1 Georgia, serif; background: var(--navy); box-shadow: 0 7px 20px #101a2f1c; transition: .16s ease; }
.brand-copy { min-width: 0; }
.brand-copy strong, .brand-copy small { display: block; }
.brand-copy strong { font-size: 17px; letter-spacing: .01em; }
.brand-copy small { max-width: 180px; margin-top: 5px; color: var(--muted); font-size: 11px; line-height: 1.45; }
.stats article { min-height: 108px; padding: 21px 26px; border-right: 1px solid var(--line); }
.stats article:last-child { border-right: 0; }
.stats article span, .stats article small { display: block; color: var(--muted); font-size: 11px; }
.stats article strong { display: block; margin: 7px 0 3px; font-size: 29px; line-height: 1; letter-spacing: -.04em; }

.board { margin: 18px 0 20px; padding: 24px; border: 1px solid var(--line); border-radius: 22px; background: #ffffffd9; box-shadow: 0 18px 50px #1c29490b; }
.category-bar { display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: start; gap: 20px; }
.category-wrap { overflow: visible; }
.categories { display: flex; flex-wrap: wrap; align-items: flex-start; gap: 8px; overflow: visible; padding: 2px 2px 13px; }
.category-actions { min-height: 42px; display: flex; align-items: center; justify-content: flex-end; gap: 10px; padding: 1px 0 0 8px; white-space: nowrap; }
.category { flex: 0 0 auto; display: flex; align-items: center; gap: 7px; min-height: 38px; padding: 0 13px; color: #5c6676; border: 1px solid #dfe3e9; border-radius: 999px; background: #fafaf8; cursor: pointer; }
.category:hover { border-color: #bfc7d4; }
.category.active { color: white; border-color: var(--navy); background: var(--navy); }
.category b { min-width: 20px; padding: 2px 5px; border-radius: 999px; color: #788294; background: #e9ebef; font-size: 10px; }
.category.active b { color: #dbe4f6; background: #ffffff20; }
.refresh-indicator { width: 11px; height: 11px; flex: 0 0 11px; border: 1.5px solid currentColor; border-right-color: transparent; border-radius: 50%; opacity: 0; }
.category.refreshing { border-color: #91a5d4; }
.category.refreshing .refresh-indicator { opacity: .72; animation: rotate .7s linear infinite; }
.toolbar { display: grid; grid-template-columns: minmax(220px, 1fr) auto auto auto; align-items: center; gap: 16px; padding: 12px 0 22px; }
.search { position: relative; }
.search svg { position: absolute; left: 13px; top: 50%; width: 18px; transform: translateY(-50%); fill: none; stroke: #8791a2; stroke-width: 1.8; stroke-linecap: round; }
.search input { width: 100%; height: 43px; padding: 0 15px 0 41px; color: var(--ink); border: 1px solid #dfe3e9; border-radius: 11px; outline: none; background: #fafaf9; }
.search input:focus { border-color: #95a8d8; box-shadow: 0 0 0 4px #3468ff0c; }
.stock-toggle { display: flex; align-items: center; gap: 8px; color: #5f6979; font-size: 12px; cursor: pointer; }
.stock-toggle input { position: absolute; opacity: 0; }
.stock-toggle span { width: 35px; height: 20px; padding: 2px; border-radius: 999px; background: #d8dce3; transition: .2s; }
.stock-toggle span::after { content: ""; display: block; width: 16px; height: 16px; border-radius: 50%; background: white; box-shadow: 0 1px 4px #0002; transition: .2s; }
.stock-toggle input:checked + span { background: var(--green); }
.stock-toggle input:checked + span::after { transform: translateX(15px); }
.select-label { color: var(--muted); font-size: 11px; }
.select-label select { height: 39px; margin-left: 6px; padding: 0 30px 0 10px; color: var(--ink); border: 1px solid #dfe3e9; border-radius: 10px; background: white; }
.result-count { color: var(--muted); font-size: 12px; white-space: nowrap; }

.product-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 14px; }
.product-card { position: relative; min-width: 0; display: flex; flex-direction: column; padding: 18px; color: inherit; border: 1px solid var(--line); border-radius: 16px; background: var(--paper); cursor: pointer; transition: transform .18s ease, border-color .18s ease, box-shadow .18s ease; }
.product-card:hover { transform: translateY(-2px); border-color: #c8cfdb; box-shadow: 0 16px 34px #1c294912; }
.product-card.product-refreshing { border-color: #91a5d4; }
.product-card-link { position: absolute; inset: 0; z-index: 1; border-radius: inherit; }
.product-card-link:focus-visible { outline: 3px solid #8ea5dd; outline-offset: 2px; }
.product-refresh, .product-history { position: absolute; top: 11px; z-index: 2; display: grid; place-items: center; width: 30px; height: 30px; padding: 0; color: #687386; border: 1px solid #dfe3e9; border-radius: 9px; background: #fff; box-shadow: 0 4px 12px #101a2f0d; cursor: pointer; transition: color .16s ease, border-color .16s ease, background .16s ease; }
.product-refresh { right: 11px; }
.product-history { right: 47px; }
.product-refresh:hover, .product-history:hover { color: var(--blue); border-color: #b9c7e8; background: #f7f9ff; }
.product-refresh:disabled { cursor: wait; }
.product-refresh span { display: inline-block; font-size: 17px; line-height: 1; }
.product-refreshing .product-refresh span { animation: rotate .7s linear infinite; }
.product-history svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.product-head { display: flex; align-items: flex-start; gap: 13px; padding-right: 68px; }
.product-image { width: 54px; height: 54px; flex: 0 0 54px; object-fit: cover; border-radius: 12px; background: linear-gradient(135deg, #eef1f7, #dfe5f1); }
.product-image.fallback { display: grid; place-items: center; color: #65728a; font: 800 21px/1 Georgia, serif; }
.product-title { min-width: 0; flex: 1; }
.product-title-link { display: -webkit-box; overflow: hidden; color: var(--ink); font-size: 14px; font-weight: 700; line-height: 1.5; -webkit-box-orient: vertical; -webkit-line-clamp: 2; }
.product-card:hover .product-title-link { color: var(--blue); }
.shop-line { margin-top: 6px; overflow: hidden; color: var(--muted); font-size: 11px; text-overflow: ellipsis; white-space: nowrap; }
.tags { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 15px; }
.tag { padding: 3px 7px; color: #53627a; border-radius: 6px; background: #eef1f6; font-size: 10px; font-weight: 700; }
.tag.stock { color: #087e56; background: #e5f7f0; }
.tag.out { color: #a64545; background: #fbe9e9; }
.price-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px; margin-top: auto; padding-top: 20px; }
.price { color: var(--ink); font-size: 28px; font-weight: 800; line-height: 1; letter-spacing: -.05em; }
.price::before { content: "¥"; margin-right: 2px; font-size: 14px; font-weight: 600; }
.market-price { margin-top: 5px; color: #a0a7b2; font-size: 11px; text-decoration: line-through; }
.product-meta { text-align: right; }
.stock-number { color: #4c596e; font-size: 11px; }
.updated { display: block; margin-top: 5px; color: #a0a7b2; font-size: 10px; }
.empty { padding: 80px 20px; text-align: center; color: var(--muted); }
.empty span { display: block; color: #c2c8d2; font: 42px/1 Georgia, serif; }
.empty strong { display: block; margin: 12px 0 6px; color: var(--ink); }
.empty p { margin: 0; font-size: 12px; }

footer { display: flex; justify-content: space-between; gap: 20px; padding: 18px 4px 30px; color: #828b99; font-size: 11px; }

.source-dialog { width: min(720px, calc(100% - 30px)); max-height: min(82vh, 760px); padding: 0; border: 0; border-radius: 20px; color: var(--ink); background: white; box-shadow: 0 30px 100px #07112655; }
.source-dialog::backdrop { background: #07112680; backdrop-filter: blur(5px); }
.history-dialog { width: min(840px, calc(100% - 30px)); max-height: min(88vh, 820px); padding: 0; border: 0; border-radius: 20px; color: var(--ink); background: white; box-shadow: 0 30px 100px #07112655; }
.history-dialog::backdrop { background: #07112680; backdrop-filter: blur(5px); }
.history-body { padding: 22px 26px 26px; }
.history-shop { display: flex; align-items: center; justify-content: space-between; gap: 18px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 12px; background: #fafbf9; }
.history-shop span, .history-shop strong { display: block; }
.history-shop span { color: var(--muted); font-size: 10px; }
.history-shop strong { margin-top: 3px; font-size: 13px; }
.history-shop code { max-width: 45%; overflow: hidden; padding: 5px 8px; color: #53627a; border-radius: 7px; background: #eef1f6; font-size: 10px; text-overflow: ellipsis; white-space: nowrap; }
.history-summary { display: grid; grid-template-columns: repeat(4, 1fr); margin: 14px 0; border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.history-summary article { padding: 13px 15px; border-right: 1px solid var(--line); }
.history-summary article:last-child { border-right: 0; }
.history-summary span { display: block; color: var(--muted); font-size: 10px; }
.history-summary strong { display: block; margin-top: 5px; font-size: 17px; }
.history-chart { min-height: 290px; display: grid; place-items: center; overflow: hidden; border: 1px solid var(--line); border-radius: 14px; background: linear-gradient(180deg, #fbfcff, #f8f9f7); }
.history-chart > p, .history-empty { color: var(--muted); font-size: 12px; }
.history-chart svg { display: block; width: 100%; height: auto; }
.chart-grid line { stroke: #dfe4ec; stroke-width: 1; stroke-dasharray: 4 5; }
.chart-grid text, .chart-time { fill: #8a94a4; font-size: 10px; }
.chart-area { fill: #3468ff0c; }
.chart-line { fill: none; stroke: var(--blue); stroke-width: 2.3; stroke-linecap: round; stroke-linejoin: round; }
.chart-points circle { fill: white; stroke: var(--blue); stroke-width: 1.7; }
.history-note { margin: 10px 2px 0; color: #9099a7; font-size: 10px; }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 24px 26px 18px; border-bottom: 1px solid var(--line); }
.dialog-head small { color: var(--blue); font-size: 9px; font-weight: 800; letter-spacing: .16em; }
.dialog-head h2 { margin: 4px 0 0; font-size: 22px; }
.icon-button { width: 36px; height: 36px; border: 0; border-radius: 50%; color: #687386; background: #f0f2f5; font-size: 24px; cursor: pointer; }
.dialog-body { padding: 22px 26px 28px; overflow-y: auto; }
.field { display: grid; gap: 7px; }
.field span { color: #687386; font-size: 11px; }
.field input { width: 100%; height: 42px; padding: 0 12px; border: 1px solid #dfe3e9; border-radius: 10px; outline: 0; }
.field input:focus { border-color: #8ea5dd; }
.add-source { display: flex; align-items: end; gap: 10px; margin-top: 16px; }
.add-source .grow { flex: 1; }
.source-discovery { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin: 14px 0 20px; }
.source-tip { margin: 0; color: #818b9a; font-size: 11px; line-height: 1.6; }
.source-discovery .button { flex: 0 0 auto; min-height: 34px; font-size: 11px; }
.source-list { display: grid; gap: 9px; }
.source-item { display: grid; grid-template-columns: 1fr auto auto; align-items: center; gap: 12px; padding: 13px 14px; border: 1px solid var(--line); border-radius: 12px; }
.source-name { min-width: 0; }
.source-name strong, .source-name span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.source-name strong { font-size: 13px; }
.source-name span { margin-top: 4px; color: var(--muted); font-size: 10px; }
.source-status { padding: 4px 7px; border-radius: 6px; color: #747e8e; background: #eef0f3; font-size: 9px; }
.source-status.ok { color: #087e56; background: #e5f7f0; }
.source-status.error { color: #a64545; background: #fbe9e9; }
.source-actions { display: flex; gap: 6px; }
.source-actions button { height: 30px; padding: 0 9px; border: 1px solid #e0e3e8; border-radius: 8px; color: #667183; background: white; font-size: 10px; cursor: pointer; }
.source-actions button.danger { color: #b34c4c; }
.toast { position: fixed; right: 24px; bottom: 24px; z-index: 20; max-width: min(380px, calc(100% - 48px)); padding: 12px 16px; color: white; border-radius: 10px; background: #101a2f; box-shadow: 0 15px 40px #101a2f40; font-size: 12px; opacity: 0; pointer-events: none; transform: translateY(10px); transition: .2s; }
.toast.show { opacity: 1; transform: none; }
.toast.error { background: #a94040; }

@keyframes rotate { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { box-shadow: 0 0 0 12px #55e1ad00; } }

@media (max-width: 1100px) {
  .product-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stats { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .brand-summary { grid-column: 1 / -1; min-height: 88px; border-right: 0; border-bottom: 1px solid var(--line); }
  .category-bar { grid-template-columns: 1fr; gap: 6px; }
  .category-actions { grid-row: 1; padding: 0 0 8px; }
}

@media (max-width: 760px) {
  .shell { padding: 14px 14px 0; }
  .stream-status { margin: 0; }
  .stream-status span { display: none; }
  .button { min-height: 38px; padding: 0 11px; font-size: 12px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .brand-summary { min-height: 82px; padding: 16px 18px; }
  .brand-mark { width: 42px; height: 42px; flex-basis: 42px; font-size: 22px; }
  .stats article { min-height: 90px; padding: 17px 18px; }
  .stats article:nth-of-type(2n) { border-right: 0; }
  .stats article:nth-of-type(-n+2) { border-bottom: 1px solid var(--line); }
  .stats article strong { font-size: 24px; }
  .board { margin-top: 14px; padding: 16px; border-radius: 17px; }
  .category-actions { justify-content: flex-start; gap: 7px; }
  .scan-actions { min-width: 132px; }
  .toolbar { grid-template-columns: 1fr auto; gap: 12px; }
  .search { grid-column: 1 / -1; }
  .select-label { display: none; }
  .result-count { justify-self: end; }
  .product-grid { grid-template-columns: 1fr; }
  footer { display: grid; }
  .dialog-body, .dialog-head { padding-left: 18px; padding-right: 18px; }
  .add-source { align-items: stretch; flex-direction: column; }
  .source-discovery { align-items: stretch; flex-direction: column; }
  .source-item { grid-template-columns: 1fr auto; }
  .source-status { grid-column: 1; width: max-content; }
  .source-actions { grid-column: 2; grid-row: 1 / span 2; }
  .history-body { padding: 16px; }
  .history-summary { grid-template-columns: repeat(2, 1fr); }
  .history-summary article:nth-child(2) { border-right: 0; }
  .history-summary article:nth-child(-n+2) { border-bottom: 1px solid var(--line); }
  .history-chart { min-height: 220px; }
}
