:root {
  --bg: #ffffff;
  --bg-subtle: #f7f8fa;
  --bg-hover: #f0f2f5;
  --text: #14171a;
  --text-muted: #5b6570;
  --border: #e6e8eb;
  --border-strong: #d4d8dd;
  --accent: #2563eb;
  --accent-soft: #eaf1fe;
  --restock-bg: #e7f6ee; --restock-fg: #0f6e56;
  --price-bg: #fdf1dd;   --price-fg: #8a5106;
  --new-bg: #e8f0fd;     --new-fg: #185fa5;
  --danger: #d64545;
  --radius: 12px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #16181c;
    --bg-subtle: #1e2126;
    --bg-hover: #23272e;
    --text: #e7e9ea;
    --text-muted: #8a939d;
    --border: #2a2e35;
    --border-strong: #3a3f47;
    --accent: #4f8cf0;
    --accent-soft: #1b2740;
    --restock-bg: #12352a; --restock-fg: #5dcaa5;
    --price-bg: #3a2c10;   --price-fg: #f0c46a;
    --new-bg: #14273f;     --new-fg: #85b7eb;
    --danger: #f0736f;
  }
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

.icon { width: 22px; height: 22px; flex-shrink: 0; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

.hidden { display: none !important; }

/* ---- App shell ---- */
.app {
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  max-width: 920px;
  margin: 0 auto;
  min-height: 100vh;
}

/* ---- Left rail (desktop) ---- */
.rail {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 18px 12px;
  border-right: 1px solid var(--border);
}

.brand { display: flex; align-items: center; gap: 10px; padding: 8px 10px 14px; }
.brand-icon { width: 26px; height: 26px; color: var(--accent); }
.brand-name { font-size: 17px; font-weight: 700; letter-spacing: -0.01em; }

.rail-nav { display: flex; flex-direction: column; gap: 2px; }

.nav-item {
  display: flex;
  align-items: center;
  gap: 13px;
  width: 100%;
  padding: 11px 12px;
  border: none;
  background: none;
  border-radius: 999px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  text-align: left;
  transition: background 0.12s;
}
.nav-item:hover { background: var(--bg-hover); }
.nav-item.is-active { font-weight: 700; }
.nav-item.is-active .icon { color: var(--accent); }

.rail-status { margin-top: auto; padding: 6px 8px; }

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 13px;
  color: var(--text-muted);
}
.status-pill .dot { width: 9px; height: 9px; border-radius: 50%; background: var(--border-strong); flex-shrink: 0; }
.status-pill.on .dot { background: #22a06b; }

.status-cta {
  display: block;
  width: 100%;
  padding: 10px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 14px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.status-cta:hover { filter: brightness(1.05); }

/* ---- Main ---- */
.main { min-width: 0; border-right: 1px solid var(--border); }
.view { min-width: 0; }

/* ---- Feed ---- */
.feed-head {
  position: sticky;
  top: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding-right: 8px;
  background: color-mix(in srgb, var(--bg) 85%, transparent);
  backdrop-filter: saturate(1.4) blur(6px);
  border-bottom: 1px solid var(--border);
}

.tabs { display: flex; flex: 1; }
.tab {
  flex: 1;
  padding: 15px 0 0;
  border: none;
  background: none;
  color: var(--text-muted);
  font-size: 15px;
  font-family: inherit;
  cursor: pointer;
  position: relative;
}
.tab span, .tab { line-height: 1.2; }
.tab .tab-label { display: inline-block; padding-bottom: 13px; border-bottom: 3px solid transparent; }
.tab.is-active { color: var(--text); font-weight: 700; }
.tab.is-active .tab-label { border-bottom-color: var(--accent); }
.tab:hover { background: var(--bg-hover); }

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 38px; height: 38px;
  border: none;
  background: none;
  border-radius: 50%;
  color: var(--text-muted);
  cursor: pointer;
}
.icon-btn:hover { background: var(--bg-hover); color: var(--text); }

.recent-list { display: flex; flex-direction: column; }

.recent-item {
  display: flex;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  text-decoration: none;
  color: var(--text);
  transition: background 0.12s;
}
.recent-item:hover { background: var(--bg-subtle); }

.recent-thumb {
  width: 52px; height: 52px;
  flex-shrink: 0;
  border-radius: 10px;
  object-fit: cover;
  background: var(--bg-subtle);
  border: 1px solid var(--border);
}
.recent-thumb-ph {
  display: flex; align-items: center; justify-content: center;
  color: var(--text-muted);
}
.recent-thumb-ph .icon { width: 24px; height: 24px; }

.recent-body { min-width: 0; flex: 1; }
.recent-line1 { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.recent-meta { font-size: 13px; color: var(--text-muted); }
.recent-title { font-size: 14px; margin-top: 3px; line-height: 1.45; word-break: break-word; }
.recent-price { color: var(--text-muted); }

.badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 9px;
  border-radius: 999px;
  white-space: nowrap;
}
.badge.cat-restock { background: var(--restock-bg); color: var(--restock-fg); }
.badge.cat-pricedown { background: var(--price-bg); color: var(--price-fg); }
.badge.cat-newitem { background: var(--new-bg); color: var(--new-fg); }
.badge.cat-other { background: var(--bg-hover); color: var(--text-muted); }

.empty { color: var(--text-muted); font-size: 14px; text-align: center; padding: 40px 16px; }

.banner {
  margin: 12px 16px;
  padding: 12px 14px;
  background: var(--accent-soft);
  border-radius: var(--radius);
  font-size: 13px;
  line-height: 1.6;
}
.banner.warn { background: var(--price-bg); color: var(--price-fg); }
.banner-cta {
  display: inline-block;
  margin-top: 8px;
  padding: 7px 14px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}

/* ---- Settings ---- */
.settings-head { padding: 18px 18px 6px; border-bottom: 1px solid var(--border); }
.settings-head h1 { font-size: 19px; margin: 0; }
.settings-head .sub { margin: 4px 0 12px; color: var(--text-muted); font-size: 13px; }

#settings-form { padding: 8px 18px 0; }
fieldset { border: none; padding: 0; margin: 0 0 20px; }
legend { padding: 0; font-size: 14px; font-weight: 700; margin-bottom: 10px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border: 1px solid var(--border-strong);
  border-radius: 999px;
  font-size: 13px;
  cursor: pointer;
  user-select: none;
  transition: background 0.12s, border-color 0.12s;
}
.chip input { position: absolute; opacity: 0; width: 0; height: 0; }
.chip:has(input:checked) {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

input[type="text"] {
  width: 100%;
  padding: 11px 13px;
  border-radius: 10px;
  border: 1px solid var(--border-strong);
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
input[type="text"]:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }

.hint { color: var(--text-muted); font-size: 12px; margin: 8px 0 0; }

.settings-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; padding: 4px 18px 0; }
.primary {
  padding: 12px 22px;
  border-radius: 999px;
  border: none;
  background: var(--accent);
  color: #fff;
  font-size: 15px;
  font-weight: 700;
  font-family: inherit;
  cursor: pointer;
}
.primary:hover { filter: brightness(1.05); }
.primary:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-danger {
  padding: 12px 18px;
  border-radius: 999px;
  border: 1px solid var(--border-strong);
  background: none;
  color: var(--danger);
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.btn-danger:hover { background: var(--bg-hover); }

.message { margin: 14px 18px 0; font-size: 13px; padding: 10px 13px; border-radius: 10px; }
.message.ok { background: var(--restock-bg); color: var(--restock-fg); }
.message.error { background: var(--price-bg); color: var(--price-fg); }

/* ---- Mobile: rail becomes bottom bar ---- */
@media (max-width: 640px) {
  .app { grid-template-columns: 1fr; }
  .main { border-right: none; padding-bottom: 68px; }

  .rail {
    position: fixed;
    top: auto;
    bottom: 0; left: 0; right: 0;
    height: auto;
    flex-direction: row;
    align-items: center;
    gap: 0;
    padding: 6px 4px calc(6px + env(safe-area-inset-bottom));
    border-right: none;
    border-top: 1px solid var(--border);
    background: var(--bg);
    z-index: 10;
  }
  .brand { display: none; }
  .rail-nav { flex: 1; flex-direction: row; }
  .nav-item {
    flex-direction: column;
    gap: 3px;
    padding: 6px 4px;
    border-radius: var(--radius);
    font-size: 11px;
    justify-content: center;
    text-align: center;
  }
  .rail-status { margin: 0; padding: 0 6px; max-width: 34%; }
  .status-pill { font-size: 11px; }
  .status-cta { padding: 8px 10px; font-size: 12px; white-space: nowrap; }
}
