:root {
  --navy: #16213e;
  --navy2: #1f3a5f;
  --gold: #f0a500;
  --gold-soft: #fdf3dd;
  --red: #e0483a;
  --red-soft: #fdeeea;
  --ink: #24292f;
  --muted: #7a8494;
  --line: #e6e8ec;
  --bg: #f4f5f7;
  --card: #ffffff;
  --sidebar: #fafbfc;
  --shadow: 0 1px 3px rgba(20, 30, 60, .06);
}

[data-theme="dark"] {
  --ink: #e7ebf0;
  --muted: #98a2b3;
  --line: #303743;
  --bg: #161a21;
  --card: #1e242e;
  --sidebar: #1a1f28;
  --gold-soft: #3a3018;
  --red-soft: #3a221f;
  --shadow: none;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", "Microsoft YaHei", "PingFang SC", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.6;
}
a { color: var(--navy2); text-decoration: none; }
button, input, select, textarea { font-family: inherit; font-size: inherit; }
button { cursor: pointer; }

/* ---------- top bar ---------- */
.topbar {
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy2) 100%);
  color: #fff;
  display: flex; align-items: center; gap: 14px;
  padding: 10px 20px; flex-wrap: wrap;
  position: sticky; top: 0; z-index: 30;
  box-shadow: 0 2px 8px rgba(0,0,0,.18);
}
.brand { font-size: 19px; font-weight: 700; white-space: nowrap; }
.brand .mark { color: var(--gold); margin-right: 6px; }
.channels { display: flex; gap: 4px; flex-wrap: wrap; }
.channels button {
  background: transparent; border: 0; color: rgba(255,255,255,.78);
  padding: 6px 12px; border-radius: 6px; font-size: 13px;
}
.channels button:hover { background: rgba(255,255,255,.12); color: #fff; }
.channels button.active { background: var(--gold); color: #1a1a1a; font-weight: 600; }
.search { display: flex; background: #fff; border-radius: 6px; overflow: hidden; height: 34px; }
.search input { border: 0; outline: 0; padding: 0 12px; width: 220px; color: var(--ink); }
.search button { border: 0; background: var(--gold); color: #1a1a1a; font-weight: 600; padding: 0 14px; }
.topbar .spacer { flex: 1; }
.navlink {
  background: transparent; border: 1px solid rgba(255,255,255,.35); color: #fff;
  padding: 6px 12px; border-radius: 6px; font-size: 13px; white-space: nowrap;
}
.navlink:hover { background: rgba(255,255,255,.14); }
.navlink.primary { background: var(--red); border-color: var(--red); }
.userbox { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.userbox .role { color: var(--gold); }
.welcome-bar {
  background: var(--gold-soft); color: #8a5a00; text-align: center;
  padding: 7px 16px; font-size: 13px; border-bottom: 1px solid #f0e2c0;
}
[data-theme="dark"] .welcome-bar { color: #f0c060; }

/* ---------- layout ---------- */
.layout { display: flex; align-items: flex-start; gap: 16px; max-width: 1500px; margin: 16px auto; padding: 0 16px; }
.sidebar {
  width: 230px; flex: 0 0 230px; background: var(--sidebar);
  border: 1px solid var(--line); border-radius: 10px;
  position: sticky; top: 70px; max-height: calc(100vh - 90px); overflow-y: auto;
}
.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1; background: transparent; border: 0; padding: 10px 0;
  color: var(--muted); font-weight: 600; border-bottom: 2px solid transparent;
}
.tabs button.active { color: var(--red); border-bottom-color: var(--red); }
.filter-group { border-bottom: 1px solid var(--line); padding: 10px 12px; }
.filter-group h4 { font-size: 12px; color: var(--muted); font-weight: 600; margin-bottom: 8px; letter-spacing: .5px; }
.filter-group .vals { display: flex; flex-direction: column; gap: 5px; max-height: 190px; overflow-y: auto; }
.fv { display: flex; align-items: center; gap: 6px; font-size: 12.5px; cursor: pointer; }
.fv input { accent-color: var(--red); }
.fv .cnt { margin-left: auto; color: var(--muted); font-size: 11px; }
.fv.excluded { color: var(--red); text-decoration: line-through; }
.filter-group .empty { color: var(--muted); font-size: 12px; }
.content { flex: 1; min-width: 0; }
.crumb { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 14px 18px; box-shadow: var(--shadow); }
.crumb h1 { font-size: 20px; }
.crumb p { color: var(--muted); font-size: 13px; margin-top: 4px; }

/* ---------- quick bar ---------- */
.quickbar {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 12px; margin-top: 12px; display: flex; gap: 8px; flex-wrap: wrap;
  box-shadow: var(--shadow);
}
.chip {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); border-radius: 20px; padding: 4px 10px;
  background: var(--card); font-size: 12.5px; color: var(--ink);
}
.chip:hover { border-color: var(--red); }
.chip.active { background: var(--red-soft); border-color: var(--red); color: var(--red); }
.chip .logo { width: 16px; height: 16px; border-radius: 4px; background: var(--navy2); color: #fff;
  display: inline-flex; align-items: center; justify-content: center; font-size: 10px; }
.chip .n { color: var(--muted); font-size: 11px; }

/* ---------- result bar ---------- */
.resultbar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  margin: 14px 2px 8px; font-size: 13px; color: var(--muted);
}
.resultbar b { color: var(--red); font-size: 16px; }
.resultbar .spacer { flex: 1; }
.resultbar select, .mini {
  border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 6px; padding: 5px 10px; font-size: 12.5px;
}
.mini:hover { border-color: var(--red); }
.active-filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.af { background: var(--gold-soft); color: #8a5a00; border-radius: 14px; padding: 2px 10px; font-size: 12px; }
.af.ex { background: var(--red-soft); color: var(--red); }
.af button { border: 0; background: transparent; color: inherit; margin-left: 4px; font-weight: 700; }

/* ---------- deal cards ---------- */
.deal-list { display: flex; flex-direction: column; gap: 12px; }
.deal {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  box-shadow: var(--shadow); display: flex; gap: 14px; padding: 16px;
}
.deal .logo {
  width: 44px; height: 44px; flex: 0 0 44px; border-radius: 10px;
  background: linear-gradient(135deg, var(--navy2), #3a6ea5); color: #fff;
  display: flex; align-items: center; justify-content: center; font-size: 15px; font-weight: 700;
}
.deal .body { flex: 1; min-width: 0; }
.deal .head { display: flex; align-items: flex-start; gap: 8px; flex-wrap: wrap; }
.deal .cat { font-size: 11px; color: var(--muted); background: var(--bg); border-radius: 4px; padding: 1px 6px; }
.deal h3 { font-size: 15.5px; font-weight: 650; }
.badge { font-size: 11px; border-radius: 4px; padding: 1px 6px; white-space: nowrap; }
.badge.new { background: #e8f5e9; color: #2e7d32; }
.badge.soon { background: var(--gold-soft); color: #b26a00; }
.badge.dup { background: #eef0f5; color: #5c6a7e; }
.badge.expired { background: #eee; color: #888; }
[data-theme="dark"] .badge.new { background: #1d3a20; color: #8fd394; }
.benefits { margin: 8px 0; padding-left: 16px; }
.benefits li { font-size: 13.5px; margin: 2px 0; }
.benefits li::marker { color: var(--red); }
.meta-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 4px 16px; margin: 8px 0; }
.meta-grid div { font-size: 12.5px; color: var(--muted); }
.meta-grid b { color: var(--ink); font-weight: 500; }
.tags { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.tag { font-size: 11px; color: var(--navy2); background: var(--bg); border-radius: 4px; padding: 1px 7px; }
[data-theme="dark"] .tag { color: #9fc0f0; }
.raw { display: none; margin-top: 10px; padding: 10px; background: var(--bg); border-radius: 6px;
  font-size: 12.5px; white-space: pre-wrap; max-height: 260px; overflow-y: auto; }
.raw.show { display: block; }
.deal .side {
  width: 130px; flex: 0 0 130px; display: flex; flex-direction: column;
  align-items: flex-end; gap: 8px; border-left: 1px solid var(--line); padding-left: 12px;
}
.deal .endlabel { font-size: 11px; color: var(--muted); text-align: right; }
.deal .enddate { font-size: 14px; font-weight: 700; color: var(--ink); }
.deal .enddate.danger { color: var(--red); }
.btn {
  border: 0; border-radius: 6px; padding: 7px 12px; font-size: 12.5px; font-weight: 600;
  background: var(--red); color: #fff; width: 100%;
}
.btn:hover { filter: brightness(1.08); }
.btn.ghost { background: transparent; color: var(--navy2); border: 1px solid var(--line); }
[data-theme="dark"] .btn.ghost { color: #9fc0f0; }
.btn.small { width: auto; padding: 4px 9px; }
.btn.gray { background: var(--bg); color: var(--muted); }
.deal .actions { display: flex; gap: 10px; margin-top: 8px; font-size: 12px; color: var(--muted); }
.deal .actions span { cursor: pointer; }
.deal .actions span:hover { color: var(--red); }
.deal .foot { display: flex; justify-content: space-between; align-items: center; margin-top: 10px;
  font-size: 11.5px; color: var(--muted); border-top: 1px dashed var(--line); padding-top: 8px; }
.empty-state { background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 40px; text-align: center; color: var(--muted); }
.pager { display: flex; gap: 8px; justify-content: center; align-items: center; margin: 18px 0 30px; }

/* ---------- modals ---------- */
.overlay { position: fixed; inset: 0; background: rgba(10, 16, 30, .55); z-index: 100;
  display: flex; align-items: flex-start; justify-content: center; padding: 40px 16px; overflow-y: auto; }
.modal { background: var(--card); border-radius: 12px; width: min(760px, 100%); padding: 20px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.modal.wide { width: min(980px, 100%); }
.modal h2 { font-size: 18px; margin-bottom: 4px; }
.modal .sub { color: var(--muted); font-size: 12.5px; margin-bottom: 14px; }
.modal .close { float: right; border: 0; background: transparent; font-size: 20px; color: var(--muted); }
.field { margin-bottom: 10px; }
.field label { display: block; font-size: 12.5px; color: var(--muted); margin-bottom: 4px; }
.field input, .field textarea, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px;
  background: var(--card); color: var(--ink); outline: 0;
}
.field input:focus, .field textarea:focus { border-color: var(--gold); }
.field textarea { min-height: 110px; resize: vertical; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.modal-actions { display: flex; gap: 8px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.notice { background: var(--gold-soft); color: #8a5a00; padding: 8px 12px; border-radius: 6px; font-size: 12.5px; margin: 10px 0; }
[data-theme="dark"] .notice { color: #f0c060; }
.err { color: var(--red); font-size: 12.5px; margin-top: 6px; }
.json-preview { background: var(--bg); border-radius: 6px; padding: 10px; font-size: 12px;
  white-space: pre-wrap; max-height: 240px; overflow-y: auto; }
.list-row { display: flex; gap: 10px; align-items: center; border-bottom: 1px solid var(--line); padding: 9px 0; }
.list-row .grow { flex: 1; }

/* ---------- auth / admin pages ---------- */
.auth-wrap { max-width: 420px; margin: 60px auto; padding: 24px; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; box-shadow: var(--shadow); }
.auth-wrap h1 { font-size: 20px; margin-bottom: 4px; }
.auth-wrap p { color: var(--muted); font-size: 13px; margin-bottom: 18px; }
.admin-wrap { max-width: 1180px; margin: 20px auto; padding: 0 16px; }
.admin-head { display: flex; align-items: center; gap: 12px; margin-bottom: 16px; }
.admin-head h1 { font-size: 20px; }
.admin-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.admin-tabs button { border: 1px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: 6px; padding: 6px 12px; font-size: 13px; }
.admin-tabs button.active { background: var(--navy2); color: #fff; border-color: var(--navy2); }
.panel { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 10px; margin-bottom: 16px; }
.stat { background: var(--bg); border-radius: 8px; padding: 12px; }
.stat b { display: block; font-size: 22px; color: var(--navy2); }
.stat span { font-size: 12px; color: var(--muted); }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 12px; }
.review { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.review .col { background: var(--bg); border-radius: 8px; padding: 12px; }
.review pre { white-space: pre-wrap; font-size: 12.5px; max-height: 320px; overflow-y: auto; }
.review .col .field { margin-bottom: 8px; }

@media (max-width: 860px) {
  .layout { flex-direction: column; }
  .sidebar { width: 100%; flex: none; position: static; max-height: 240px; }
  .deal { flex-direction: column; }
  .deal .side { width: 100%; flex: none; border-left: 0; border-top: 1px solid var(--line);
    padding: 10px 0 0; flex-direction: row; align-items: center; justify-content: space-between; flex-wrap: wrap; }
  .deal .side .btn { width: auto; }
  .search input { width: 140px; }
  .review { grid-template-columns: 1fr; }
  .grid2 { grid-template-columns: 1fr; }
}
