:root {
  --navy: #0e2a47;
  --blue: #0b56a4;
  --bg: #f4f6f9;
  --card: #ffffff;
  --line: #e2e7ee;
  --text: #182430;
  --muted: #5b6875;
  --green: #0e6b3a;
  --red: #b3261e;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 22px;
  background: var(--navy);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; }
.brand-name { font-weight: 700; font-size: 17px; letter-spacing: .2px; }
.logo {
  background: #fff; color: var(--navy); font-weight: 800; font-size: 13px;
  border-radius: 7px; padding: 4px 8px;
}
.chip {
  font-size: 11.5px; font-weight: 600; border-radius: 20px; padding: 3px 10px;
  background: rgba(255,255,255,.14); color: #fff;
}
.chip-warn { background: #c77700; }

main { max-width: 880px; margin: 0 auto; padding: 22px 16px 60px; }

.cards { display: flex; flex-direction: column; gap: 14px; }
.card {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px 18px;
}
.card-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; }
.card-name { font-size: 16.5px; font-weight: 700; margin: 0; }
.badges { display: flex; gap: 6px; flex-wrap: wrap; }
.badge {
  font-size: 11px; font-weight: 700; border-radius: 5px; padding: 2px 7px;
  text-transform: uppercase; letter-spacing: .4px;
}
.badge-paused { background: #eef0f3; color: var(--muted); }
.badge-error { background: #fdeceb; color: var(--red); }
.badge-running { background: #e8f1fd; color: var(--blue); }

.tags { display: flex; flex-wrap: wrap; gap: 6px; margin: 10px 0 8px; }
.tag {
  font-size: 12px; color: var(--muted); background: #f1f4f8;
  border-radius: 6px; padding: 3px 9px;
}
.card-meta { font-size: 13px; color: var(--muted); margin: 4px 0 2px; }
.card-error {
  font-size: 12.5px; color: var(--red); background: #fdeceb;
  border-radius: 6px; padding: 7px 10px; margin-top: 8px;
  overflow-wrap: anywhere;
}
.card-actions { display: flex; gap: 8px; margin-top: 12px; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--line); background: #fff; color: var(--text);
  border-radius: 8px; padding: 7px 14px; font-size: 13.5px; font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: #f3f6fa; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: #094784; }
.btn.danger { color: var(--red); border-color: #f0c4c1; }
.btn.danger:hover { background: #fdeceb; }
.btn.small { padding: 5px 11px; font-size: 12.5px; }
.btn:disabled { opacity: .55; cursor: default; }

.empty { text-align: center; color: var(--muted); margin-top: 70px; }
.empty h2 { color: var(--text); }

dialog {
  border: none; border-radius: 14px; padding: 0;
  width: min(540px, calc(100vw - 32px));
  box-shadow: 0 18px 60px rgba(14, 42, 71, .25);
}
dialog::backdrop { background: rgba(14, 42, 71, .45); }

form { padding: 22px 24px; }
form h2, .runs-head h2 { margin: 0 0 14px; font-size: 18px; }
label { display: block; font-size: 13px; font-weight: 600; margin: 12px 0; color: var(--text); }
label small { font-weight: 400; color: var(--muted); }
input[type="text"], input[type="number"], input[type="email"], select {
  display: block; width: 100%; margin-top: 5px;
  border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px;
  font-size: 14px; font-family: inherit; background: #fff;
}
.check { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.check input { margin: 0; }
.row { display: flex; gap: 12px; }
.row label { flex: 1; }
hr { border: none; border-top: 1px solid var(--line); margin: 16px 0 4px; }
.actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 18px; }
.form-error { color: var(--red); font-size: 13px; }
.hint { font-size: 12px; color: var(--muted); margin: 14px 0 0; }

.runs-wrap { padding: 22px 24px; min-width: min(560px, calc(100vw - 60px)); }
.runs-head { display: flex; justify-content: space-between; align-items: center; }
.runs-list { max-height: 60vh; overflow-y: auto; }
.run {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 10px 2px; border-bottom: 1px solid var(--line); font-size: 13.5px;
}
.run-status { font-weight: 700; }
.run-status.ok { color: var(--green); }
.run-status.baseline { color: var(--blue); }
.run-status.error { color: var(--red); }
.run-status.empty { color: var(--muted); }
.run-time { color: var(--muted); font-size: 12.5px; }
a { color: var(--blue); }
.preview-list { max-height: 55vh; overflow-y: auto; }
#import-box { background: #f1f4f8; border-radius: 8px; padding: 10px 12px; margin-bottom: 4px; }
#import-box label { margin: 4px 0 8px; }

/* search view */
.criteria-panel {
  background: var(--card); border: 1px solid var(--line); border-radius: 12px;
  padding: 14px 16px; margin-bottom: 16px;
}
.row-main { display: flex; gap: 10px; }
.row-main input[type="text"] { flex: 1; margin: 0; font-size: 15px; padding: 10px 12px; }
.row-main .btn { white-space: nowrap; }
#s-filters summary {
  cursor: pointer; font-size: 13px; font-weight: 600; color: var(--muted);
  padding: 10px 0 2px; user-select: none;
}
#s-filters details.import-details { margin-top: 4px; }
#s-filters .import-details summary { padding: 2px 0; }
.row label select, .row label input { margin-top: 4px; }
.cat-cascade { display: flex; flex-direction: column; gap: 6px; }
.cat-cascade select { margin: 0; }
.results-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 10px; margin: 4px 0 12px;
}
.results-info { display: flex; align-items: center; gap: 10px; }
.results-info select { width: auto; margin: 0; }
.results-head .results-info strong { font-size: 14.5px; }
.results { display: flex; flex-direction: column; gap: 10px; }
.load-wrap { text-align: center; margin: 16px 0; }
.tabs { display: flex; align-items: center; gap: 8px; }
.tab {
  background: transparent; border: 1px solid transparent; color: #cfd9e4;
  font-size: 14.5px; font-weight: 600; padding: 7px 14px; border-radius: 8px;
  cursor: pointer;
}
.tab:hover { color: #fff; }
.tab.active { background: rgba(255,255,255,.14); color: #fff; }
.tab-badge {
  background: var(--blue); color: #fff; border-radius: 10px;
  font-size: 11.5px; padding: 1px 7px; margin-left: 2px;
}
.sort-hint { margin: -6px 2px 12px; font-size: 12.5px; color: var(--muted); }

/* dark mode */
body.dark { --bg: #0f141a; --card: #18212b; --line: #2a3542; --text: #e6ebf1; --muted: #97a4b3; }
body.dark .logo { background: #e6ebf1; }
body.dark .btn { background: #1d2733; color: #e6ebf1; border-color: #2a3542; }
body.dark .btn:hover { background: #243040; }
body.dark input, body.dark select { background: #101720; color: #e6ebf1; border-color: #2a3542; }
body.dark .tag { background: #202b37; color: #97a4b3; }
body.dark .badge-paused { background: #202b37; }
body.dark #import-box { background: #101720; }
body.dark .chip-warn { background: #9a6a00; }
.icon-btn {
  background: transparent; border: 1px solid var(--line); color: var(--text);
  border-radius: 8px; padding: 4px 9px; font-size: 14px; cursor: pointer;
}
.icon-btn:hover { background: var(--card); }
.icon-btn.active { background: var(--blue); color: #fff; border-color: var(--blue); }
header .icon-btn { background: rgba(255,255,255,.1); border-color: transparent; color: #fff; }
header .icon-btn.active { background: #fff; color: var(--navy); }

/* gallery view */
.gallery-grid { display: none; flex-wrap: wrap; gap: 12px; }
.gallery-grid.show { display: flex; }
.gallery-tile {
  width: calc(33.33% - 8px); background: var(--card); border: 1px solid var(--line);
  border-radius: 10px; overflow: hidden; text-decoration: none; color: var(--text);
}
.gallery-tile img { width: 100%; height: 150px; object-fit: cover; display: block; background: #eef1f5; }
.gallery-tile .gt-body { padding: 10px 12px; }
.gallery-tile .gt-title { font-size: 13.5px; font-weight: 600; color: var(--blue); line-height: 1.3; }
.gallery-tile .gt-price { font-size: 14px; font-weight: 700; color: var(--text); margin: 5px 0 4px; }
.gallery-tile .gt-badges { display: flex; flex-wrap: wrap; gap: 4px; }

/* category search */
#s-catSearch { margin-top: 6px; }
.cat-search-results {
  position: relative; z-index: 10; max-height: 220px; overflow-y: auto;
  background: var(--card); border: 1px solid var(--line); border-radius: 8px; margin-top: 4px;
}
.cat-search-results .cat-hit {
  padding: 7px 10px; font-size: 13px; cursor: pointer; color: var(--muted);
}
.cat-search-results .cat-hit:hover { background: #eef4fb; color: var(--text); }
.cat-search-results .cat-hit b { color: var(--text); }
.cat-search-results .cat-none { padding: 7px 10px; font-size: 13px; color: var(--muted); }

/* health strip */
.health-strip {
  background: var(--card); border: 1px solid var(--line); border-radius: 10px;
  padding: 10px 16px; font-size: 13px; color: var(--muted); margin-bottom: 14px;
}
.health-strip strong { color: var(--text); }
.health-strip .hs-error { color: var(--red); }

/* dark mode: dialogs */
body.dark dialog { background: var(--card); color: var(--text); }

/* dark mode: server-rendered result cards use inline styles — override them.
   Selectors target the exact inline declarations emitted by src/emails.js. */
body.dark #results [style*="background:#eef1f5"] { background: transparent !important; padding: 0 !important; }
body.dark #results [style*="background:#ffffff"] { background: var(--card) !important; }
body.dark #results [style*="border-bottom:1px solid #edf0f4"] { border-bottom-color: var(--line) !important; }
body.dark #results [style*="background:#f7f9fb"] { background: #101720 !important; }
body.dark #results [style*="color:#8a95a1"] { color: #6b7683 !important; }
body.dark #results [style*="color:#0b56a4"] { color: #7cb3e8 !important; }
body.dark #results [style*="color:#0e2a47"] { color: #e6ebf1 !important; }
body.dark #results [style*="color:#182430"] { color: #e6ebf1 !important; }
body.dark #results [style*="color:#5b6875"] { color: #97a4b3 !important; }
body.dark #results [style*="background:#fdf1dc"] { background: #2a2410 !important; }
body.dark #results [style*="color:#7a4d00"] { color: #e0c26a !important; }
body.dark #results img { background: #101720; }

/* gallery photo fidelity: use larger source + natural aspect crop */
.gallery-tile img { aspect-ratio: 4 / 3; height: auto; object-fit: cover; }

/* clickable category line on result cards */
#results .cat-jump:hover { color: var(--blue) !important; }

/* auth + settings */
.auth-card {
  max-width: 420px; margin: 60px auto; background: var(--card);
  border: 1px solid var(--line); border-radius: 12px; padding: 24px 26px;
}
.auth-card h2 { margin: 0 0 8px; }
.auth-card .hint { margin: 0 0 14px; }
.auth-area { display: flex; align-items: center; gap: 8px; color: #cfd9e4; font-size: 13.5px; }
.auth-area .username { color: #fff; font-weight: 600; }
.auth-area button {
  background: rgba(255,255,255,.1); border: none; color: #cfd9e4;
  padding: 6px 10px; border-radius: 8px; cursor: pointer; font-size: 13px;
}
.auth-area button:hover { color: #fff; background: rgba(255,255,255,.18); }
.settings-form { display: flex; flex-direction: column; gap: 10px; max-width: 420px; }
.settings-form input { margin: 0; }
#email-saved, #password-saved { color: var(--green); }
.admin-row {
  display: flex; justify-content: space-between; align-items: center; gap: 10px;
  padding: 8px 2px; border-bottom: 1px solid var(--line); font-size: 13.5px;
}
#search-error { color: var(--red); font-size: 13.5px; margin: 0 0 10px; }
