/* ==========================================================================
   二手監察 WebApp — Design tokens
   概念：一個持續掃描市場嘅「雷達」。靛藍 + 冷灰白為底，琥珀橙標記「新搵到」，
   青綠色標記「即時狀態」。Space Grotesk 做標題，IBM Plex Sans 做內文，
   IBM Plex Mono 做價錢/時間呢啲「數據感」內容。
   ========================================================================== */

:root {
  --ink: #161829;
  --ink-soft: #4b4d6b;
  --paper: #f1f2f8;
  --card: #ffffff;
  --border: #e1e3ee;
  --signal: #f5a623;
  --signal-ink: #7a4a05;
  --signal-bg: #fef3de;
  --live: #12b3a8;
  --live-bg: #e2f7f5;
  --danger: #e0435f;
  --danger-bg: #fdeaee;
  --ok: #1f9d66;
  --muted: #70728f;
  --radius: 12px;
  --radius-sm: 8px;
  --font-display: 'Space Grotesk', 'Segoe UI', sans-serif;
  --font-body: 'IBM Plex Sans', 'PingFang HK', 'Microsoft JhengHei', sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, monospace;
}

* { box-sizing: border-box; }

body {
  font-family: var(--font-body);
  background: var(--paper);
  color: var(--ink);
  margin: 0;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { font-family: var(--font-display); letter-spacing: -0.01em; }

a { color: var(--ink); }

:focus-visible {
  outline: 2px solid var(--live);
  outline-offset: 2px;
}

/* ---------- Header ---------- */
.topbar {
  background: var(--ink);
  color: #fff;
  padding: 0 24px;
  border-bottom: 1px solid rgba(255,255,255,0.09);
  box-shadow: 0 8px 24px rgba(20,20,40,0.12);
  position: relative;
  z-index: 50;
}
.topbar-inner {
  width: 100%; max-width: 1180px; min-height: 72px; margin: 0 auto;
  display: grid; grid-template-columns: minmax(220px, auto) minmax(0, 1fr) auto;
  align-items: center; gap: 24px;
}
.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-display);
  color: #fff; text-decoration: none;
  white-space: nowrap;
}
.brand:hover { color: #fff; }
.brand-mark { flex-shrink: 0; color: var(--signal); width: 24px; height: 24px; }
.brand-copy { display: flex; align-items: center; gap: 9px; min-width: 0; }
.brand-title { font-size: 16px; line-height: 1.15; font-weight: 600; letter-spacing: -0.01em; }
.brand-role {
  font-family: var(--font-mono);
  font-size: 9px; font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  background: rgba(245, 166, 35, 0.18);
  color: var(--signal);
  border: 1px solid rgba(245, 166, 35, 0.28);
  padding: 3px 7px;
  border-radius: 20px;
}

.primary-nav {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
}
.nav-link {
  position: relative;
  color: rgba(255,255,255,0.68); font-size: 13px; font-weight: 500;
  text-decoration: none; padding: 10px 11px; border-radius: 8px;
  white-space: nowrap; transition: color .15s, background .15s;
}
.nav-link:hover { background: rgba(255,255,255,0.07); color: #fff; }
.nav-link.active { background: rgba(255,255,255,0.09); color: #fff; }
.nav-link.active::after {
  content: ''; position: absolute; left: 11px; right: 11px; bottom: 4px;
  height: 2px; border-radius: 2px; background: var(--signal);
}

.topbar-actions {
  display: flex; align-items: center; justify-content: flex-end; gap: 8px;
}

/* nav dropdown, done natively with <details>/<summary>, no JS needed */
.nav-menu { position: relative; }
.nav-menu summary {
  list-style: none; cursor: pointer; user-select: none;
  color: rgba(255,255,255,0.88); padding: 6px 9px 6px 6px;
  border: 1px solid rgba(255,255,255,0.13); border-radius: 10px;
  display: flex; align-items: center; gap: 8px;
  transition: background .15s, border-color .15s;
}
.nav-menu summary::-webkit-details-marker { display: none; }
.nav-menu summary:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.25); color: #fff; }
.nav-menu[open] summary, .account-menu.active summary { background: rgba(255,255,255,0.11); border-color: rgba(245,166,35,0.38); color: #fff; }
.nav-menu summary::after { content: '▾'; font-size: 10px; opacity: 0.55; margin-left: 2px; }
.account-avatar {
  width: 30px; height: 30px; border-radius: 8px; display: grid; place-items: center;
  background: var(--signal); color: var(--signal-ink);
  font-family: var(--font-display); font-size: 13px; font-weight: 700;
}
.account-summary { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.account-label { font-size: 12px; font-weight: 600; }
.account-email {
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  color: rgba(255,255,255,0.48); font-family: var(--font-mono); font-size: 9.5px;
}
.nav-dropdown {
  position: absolute; right: 0; top: calc(100% + 9px);
  background: var(--card); color: var(--ink);
  border: 1px solid var(--border); border-radius: 11px;
  box-shadow: 0 16px 40px rgba(20,20,40,0.22);
  min-width: 245px; padding: 7px; z-index: 60;
}
.nav-dropdown a {
  display: block; padding: 9px 10px; border-radius: 7px;
  font-size: 13px; font-weight: 500; text-decoration: none; color: var(--ink-soft);
}
.nav-dropdown a:hover { background: var(--paper); }
.nav-dropdown a.active { background: var(--signal-bg); color: var(--signal-ink); }
.nav-dropdown a.dropdown-danger { color: var(--danger); }
.account-card {
  position: relative; padding: 9px 10px 12px; margin-bottom: 5px;
  border-bottom: 1px solid var(--border);
}
.account-card-label {
  display: block; margin-bottom: 3px; color: var(--muted);
  font-family: var(--font-mono); font-size: 9px; text-transform: uppercase; letter-spacing: .08em;
}
.account-card strong {
  display: block; max-width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  font-family: var(--font-mono); font-size: 11px; color: var(--ink);
}
.account-admin-badge {
  position: absolute; right: 9px; top: 9px; padding: 2px 6px; border-radius: 10px;
  background: var(--signal-bg); color: var(--signal-ink);
  font-family: var(--font-mono); font-size: 8px; font-weight: 600; text-transform: uppercase;
}

/* ---------- Language switcher ---------- */
.lang-switcher {
  background: rgba(255,255,255,0.07); color: rgba(255,255,255,0.88);
  border: 1px solid rgba(255,255,255,0.14); border-radius: 9px;
  padding: 8px 9px; font-size: 11px; font-family: var(--font-body);
  cursor: pointer; margin: 0;
}
.lang-switcher option { color: #111; }
.login-page .lang-switcher {
  position: fixed; top: 18px; right: 18px; background: var(--card); color: var(--ink-soft);
  border: 1px solid var(--border); z-index: 10;
}

@media (max-width: 920px) {
  .topbar { padding: 0 16px; }
  .topbar-inner {
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 10px 14px; padding: 10px 0 9px;
  }
  .primary-nav {
    grid-column: 1 / -1; grid-row: 2; justify-content: flex-start;
    overflow-x: auto; padding-top: 8px; border-top: 1px solid rgba(255,255,255,0.08);
    scrollbar-width: none;
  }
  .primary-nav::-webkit-scrollbar { display: none; }
  .nav-link { flex: 0 0 auto; }
  .account-email { display: none; }
}

@media (max-width: 540px) {
  .topbar { padding: 0 12px; }
  .brand-copy { gap: 6px; }
  .brand-title { font-size: 14px; }
  .brand-role { font-size: 8px; padding: 2px 5px; }
  .topbar-actions { gap: 5px; }
  .account-summary { display: none; }
  .account-menu summary { padding: 4px 6px 4px 4px; gap: 4px; }
  .account-avatar { width: 28px; height: 28px; }
  .nav-dropdown { position: fixed; right: 12px; top: 63px; min-width: min(245px, calc(100vw - 24px)); }
}

/* ---------- Layout ---------- */
main { max-width: 720px; margin: 28px auto; padding: 0 16px 40px; }
.card {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 20px;
  box-shadow: 0 1px 2px rgba(20,20,40,0.04);
}
.card h2 {
  margin: 0 0 4px; font-size: 16px; font-weight: 600;
}
.card-eyebrow {
  font-family: var(--font-mono); font-size: 11px; letter-spacing: 0.08em;
  text-transform: uppercase; color: var(--muted); margin: 0 0 6px;
}

/* ---------- Forms ---------- */
.add-form label { display: block; margin-bottom: 14px; font-size: 13.5px; font-weight: 500; color: var(--ink-soft); }
.add-form input[type=text],
.add-form input[type=email],
.add-form input[type=number] {
  width: 100%; padding: 10px 12px; margin-top: 6px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px;
  font-family: var(--font-body); background: var(--paper);
  transition: border-color .15s, background .15s;
}
.add-form input[type=text]:focus,
.add-form input[type=email]:focus,
.add-form input[type=number]:focus {
  border-color: var(--live); background: var(--card); outline: none;
}
fieldset { border: none; padding: 0; margin: 4px 0 16px; }
legend { font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); padding: 0 0 8px; }

/* checkbox 變做 chip 樣式 */
.checkbox {
  display: inline-flex; align-items: center; gap: 6px;
  margin: 0 8px 8px 0; padding: 7px 12px 7px 10px;
  border: 1px solid var(--border); border-radius: 20px;
  font-size: 12.5px; cursor: pointer; user-select: none;
  background: var(--card); color: var(--ink-soft);
  transition: all .12s;
}
.checkbox:hover { border-color: var(--ink-soft); }
.checkbox input { accent-color: var(--ink); margin: 0; }
.checkbox:has(input:checked) {
  background: var(--ink); color: #fff; border-color: var(--ink);
}
.checkbox:has(input:checked) input { accent-color: #fff; }

button, .btn {
  background: var(--ink); color: #fff; border: none; padding: 11px 20px;
  border-radius: var(--radius-sm); cursor: pointer; font-size: 14px; font-weight: 500;
  font-family: var(--font-body);
}
button:hover { background: #2a2c48; }
.btn-secondary {
  display: inline-block; margin-left: 8px; padding: 10px 16px;
  background: var(--paper); color: var(--ink-soft); border: 1px solid var(--border);
  text-decoration: none; vertical-align: middle;
}
.btn-secondary:hover { background: var(--border); color: var(--ink); }

/* ---------- Password field w/ show-hide eye ---------- */
.password-wrapper {
  position: relative; display: flex; align-items: stretch; overflow: hidden;
  min-height: 48px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  background: #f2f6ff; transition: border-color .15s, background .15s, box-shadow .15s;
}
.password-wrapper:focus-within {
  border-color: var(--live); background: var(--card);
  box-shadow: 0 0 0 3px rgba(18, 179, 168, 0.12);
}
.password-wrapper input[type=password], .password-wrapper input[type=text] {
  flex: 1 1 auto; min-width: 0; width: 100%; border: none; background: transparent;
  padding: 11px 14px; margin: 0; font-size: 14px; font-family: var(--font-body);
  border-radius: 0;
}
.password-wrapper input:focus { outline: none; }
.password-wrapper > .toggle-password {
  position: static !important; flex: 0 0 48px !important;
  width: 48px !important; min-width: 48px !important; max-width: 48px !important;
  height: auto !important; min-height: 0 !important; margin: 0 !important; padding: 0 !important;
  background: #eaf1fc; border: none; border-left: 1px solid #d9e2f0;
  cursor: pointer; line-height: 0; color: #748095; border-radius: 0;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, color .15s;
}
.toggle-password:hover { background: #dfe9f8; color: var(--ink-soft); }
.toggle-password:focus-visible { outline-offset: -3px; }
.password-wrapper > .toggle-password > svg {
  display: block !important; flex: none !important;
  width: 20px !important; height: 20px !important;
  min-width: 20px !important; min-height: 20px !important;
  max-width: 20px !important; max-height: 20px !important;
}
.add-form label .password-wrapper { margin-top: 6px; margin-bottom: 0; }

/* ---------- Product / listing cards ---------- */
.product { border-top: 1px solid var(--border); padding: 16px 0; }
.product:first-of-type { border-top: none; }
.product.inactive { opacity: .5; }
.product-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.product-header strong { font-family: var(--font-display); font-size: 15.5px; font-weight: 600; }
.tags { margin-top: 6px; display: flex; flex-wrap: wrap; gap: 5px; }
.tag {
  display: inline-block; background: var(--paper); color: var(--ink-soft);
  font-family: var(--font-mono); font-size: 10.5px; padding: 3px 9px;
  border-radius: 20px; border: 1px solid var(--border);
}

/* "live" 脈動點：代表最近檢查過 */
.live-dot {
  display: inline-block; width: 7px; height: 7px; border-radius: 50%;
  background: var(--live); margin-right: 6px; position: relative; top: -1px;
  animation: pulse 2s ease-in-out infinite;
}
.live-dot.stale { background: var(--muted); animation: none; }
@keyframes pulse {
  0%, 100% { box-shadow: 0 0 0 0 rgba(18,179,168,0.35); }
  50% { box-shadow: 0 0 0 4px rgba(18,179,168,0); }
}
@media (prefers-reduced-motion: reduce) {
  .live-dot { animation: none; }
}

.actions form { display: inline; }
.cashback-actions {
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
  flex: 0 0 auto;
}
.cashback-actions form { display: block; }
.cashback-actions a, .cashback-actions .link-btn { margin-left: 0; }
.actions a, .link-btn {
  font-size: 12.5px; margin-left: 12px; text-decoration: none; color: var(--muted);
  font-family: var(--font-mono); text-transform: uppercase; letter-spacing: 0.03em;
}
.actions a:hover, .link-btn:hover { color: var(--ink); text-decoration: underline; }
.actions a.danger, .link-btn.danger-btn { color: var(--danger); }
.link-btn {
  background: none; border: none; cursor: pointer; padding: 0;
}
.link-btn:hover { background: none; }

.muted { color: var(--muted); }
.small { font-size: 12px; }

.listing-list { list-style: none; padding: 0; margin: 12px 0 0; }
.listing-list li {
  padding: 9px 0; border-top: 1px dashed var(--border); font-size: 13px;
  display: flex; align-items: baseline; flex-wrap: wrap; gap: 6px;
}
.listing-list a { color: var(--ink); text-decoration: none; font-weight: 500; }
.listing-list a:hover { text-decoration: underline; }
.price {
  font-family: var(--font-mono); font-weight: 600; font-size: 12px;
  background: var(--signal-bg); color: var(--signal-ink); padding: 2px 8px; border-radius: 5px;
}

/* ---------- Login-style pages ---------- */
.login-page {
  display: flex; align-items: center; justify-content: center; min-height: 100vh;
  background: radial-gradient(circle at 20% 15%, #1d2040 0%, var(--paper) 45%);
}
.login-box {
  background: var(--card); padding: 36px 32px; border-radius: var(--radius); width: 320px;
  box-shadow: 0 12px 40px rgba(20,20,45,0.14); text-align: center;
  border: 1px solid var(--border);
}
.login-box h1 {
  font-size: 19px; margin: 0 0 22px; display: flex; align-items: center; justify-content: center; gap: 8px;
}
.login-box > input[type=email], .login-box > input[type=text] {
  width: 100%; padding: 11px 12px; margin-bottom: 12px;
  border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 14px;
  font-family: var(--font-body); background: var(--paper);
}
.login-box input:focus { outline: none; border-color: var(--live); background: var(--card); }
.login-box > button { width: 100%; padding: 12px; }
.error { color: var(--danger); font-size: 13px; background: var(--danger-bg); padding: 8px 10px; border-radius: 8px; margin-bottom: 12px; }
