/* Price Finder — single hand-written stylesheet (offline, no CDN). Spec §10. */

:root {
  --navy: #17233d;
  --navy-2: #223257;
  --accent: #2f6fed;
  --ink: #1d2433;
  --muted: #6b7280;
  --line: #e2e6ee;
  --bg: #f4f6fb;
  --row: #fafbfe;
  --ok: #1a7f45;
  --ok-bg: #e6f4ec;
  --warn: #9a6400;
  --warn-bg: #fbf0d6;
  --gray-bg: #eceef2;
  --danger: #c0392b;
  --danger-bg: #fbe9e7;
  --coupon: #6d3bd1;
  --coupon-bg: #efe8fb;
}

* { box-sizing: border-box; }
html, body { overflow-x: hidden; }
body {
  margin: 0;
  font-family: "Malgun Gothic", "Apple SD Gothic Neo", "Noto Sans KR", system-ui, sans-serif;
  color: var(--ink);
  background: var(--bg);
  font-size: 14px;
  line-height: 1.5;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
code { background: #eef1f6; padding: 1px 5px; border-radius: 4px; font-size: 12px; }

/* Top bar (navy header) */
.topbar {
  display: flex; align-items: center; gap: 24px;
  background: var(--navy); color: #fff;
  padding: 0 24px; height: 56px;
}
.brand { font-weight: 700; font-size: 17px; letter-spacing: .3px; }
.mainnav { display: flex; gap: 6px; flex: 1; }
.mainnav a { color: #c7d0e4; padding: 8px 14px; border-radius: 7px; font-weight: 500; }
.mainnav a:hover { background: var(--navy-2); text-decoration: none; color: #fff; }
.mainnav a.active { background: var(--accent); color: #fff; }
.userbox { display: flex; align-items: center; gap: 14px; }
.uname { color: #dfe5f2; font-size: 13px; }
.logout { color: #c7d0e4; font-size: 13px; }

.content { max-width: 1180px; margin: 0 auto; padding: 26px 24px 60px; }
.page-title { font-size: 22px; margin: 4px 0 20px; }
.page-title .count, .count { font-size: 14px; color: var(--muted); font-weight: 500; }
.crumbs { color: var(--muted); font-size: 13px; margin-bottom: 6px; }
.hint { color: var(--muted); margin-top: 16px; }
.detail-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; }

/* Cards */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(190px, 100%), 1fr)); gap: 16px; }
.card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 18px; }
.card.danger { border-color: #f2c9c3; }
.card-label { color: var(--muted); font-size: 13px; }
.card-value { font-size: 30px; font-weight: 700; margin-top: 6px; }
.card-value.small { font-size: 16px; font-weight: 600; }
.card.danger .card-value { color: var(--danger); }

.bar { background: #e9edf5; border-radius: 6px; height: 8px; margin-top: 10px; overflow: hidden; }
.bar > span { display: block; height: 100%; background: var(--accent); }

/* Panels */
.panel { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-top: 20px; }
.panel-title { font-size: 15px; margin: 0 0 14px; }
.grid2 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; align-items: start; }
.side .panel:first-child { margin-top: 0; }

/* Search / forms */
.searchbar { display: flex; gap: 10px; align-items: center; margin: 8px 0 18px; flex-wrap: wrap; }
.searchbar input[type=text] { min-width: 220px; }
.chk { display: inline-flex; align-items: center; gap: 6px; color: var(--ink); }
input, select { padding: 8px 10px; border: 1px solid #cdd3df; border-radius: 8px; font-size: 14px; background: #fff; }
input:focus, select:focus { outline: 2px solid #bcd0fb; border-color: var(--accent); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.stack input, .stack select { color: var(--ink); }
.form-msg { font-size: 13px; color: var(--danger); min-height: 16px; }

/* Buttons */
.btn { display: inline-block; padding: 8px 14px; border: 1px solid #cdd3df; background: #fff; color: var(--ink);
  border-radius: 8px; cursor: pointer; font-size: 13px; font-weight: 500; }
.btn:hover { background: #f1f4fa; text-decoration: none; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: #2559c9; }
.btn.small { padding: 5px 10px; font-size: 12px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .6; cursor: default; }

/* Tables (striped rows, shaded header) */
.table-wrap { overflow-x: auto; }
table.grid { width: 100%; border-collapse: collapse; font-size: 13px; }
table.grid th, table.grid td { padding: 9px 12px; text-align: left; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.grid thead th { background: #eef1f7; color: #33405c; font-weight: 600; border-bottom: 2px solid #dbe1ec; }
table.grid tbody tr:nth-child(even) { background: var(--row); }
table.grid tbody tr:hover { background: #eef3fe; }
table.grid td.num, table.grid th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.num.neg { color: var(--danger); font-weight: 600; }
td.num.pos { color: var(--ok); font-weight: 600; }
td.channels { white-space: normal; }
.empty { text-align: center; color: var(--muted); padding: 22px 0; }

/* Key-value */
dl.kv { display: grid; grid-template-columns: 140px 1fr; gap: 8px 16px; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

/* Badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 999px; font-size: 11.5px; font-weight: 600; margin: 1px 2px; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.gray { background: var(--gray-bg); color: var(--muted); }
.badge.coupon { background: var(--coupon-bg); color: var(--coupon); }
a.badge { text-decoration: none; cursor: pointer; }
a.badge.ok:hover { filter: brightness(0.95); }

/* dashboard product list + external seller links */
.section-title { font-size: 15px; font-weight: 700; color: var(--ink, #22303f); margin: 24px 0 10px; }
.muted { color: var(--muted, #6b7784); font-size: 0.9em; }
.btn-sm { display: inline-block; padding: 3px 10px; border-radius: 6px; background: var(--panel, #eef2f7); color: var(--ink, #22303f); text-decoration: none; font-size: 12.5px; white-space: nowrap; }
.btn-sm:hover { background: var(--line, #d6dee7); }
.link-ext { font-size: 12px; color: var(--accent, #2e6fb0); text-decoration: none; margin-left: 4px; white-space: nowrap; }
.link-ext:hover { text-decoration: underline; }

.alert { padding: 10px 12px; border-radius: 8px; font-size: 13px; margin-bottom: 12px; }
.alert.error { background: var(--danger-bg); color: var(--danger); }

/* CSS bar chart (search log) */
.chart { display: flex; align-items: flex-end; gap: 8px; height: 180px; padding-top: 8px; }
.chart-col { display: flex; flex-direction: column; align-items: center; justify-content: flex-end; flex: 1; min-width: 22px; height: 100%; }
.chart-bar { width: 70%; background: linear-gradient(180deg, #4d84f0, #2f6fed); border-radius: 4px 4px 0 0; min-height: 2px; }
.chart-x { font-size: 10px; color: var(--muted); margin-top: 5px; }

/* Login */
.login-body { display: flex; align-items: center; justify-content: center; min-height: 100vh; background: var(--navy); }
.login-card { background: #fff; border-radius: 14px; padding: 34px 30px; width: 340px; display: flex; flex-direction: column; gap: 12px; box-shadow: 0 12px 40px rgba(0,0,0,.3); }
.login-title { margin: 0; text-align: center; color: var(--navy); }
.login-sub { margin: 0 0 8px; text-align: center; color: var(--muted); font-size: 13px; }
.login-card label { display: flex; flex-direction: column; gap: 5px; font-size: 13px; color: var(--muted); }

@media (max-width: 820px) {
  .grid2 { grid-template-columns: 1fr; }

  /* The nav used to be display:none here, which left a phone with no way to leave
     the page it landed on. It wraps onto its own row instead: the header grows
     rather than the navigation disappearing. */
  .topbar {
    height: auto; flex-wrap: wrap; gap: 8px 16px;
    padding: 10px 16px; align-items: center;
  }
  .brand { flex: 1 1 auto; font-size: 16px; }
  .userbox { flex: 0 0 auto; }
  .mainnav {
    order: 3; flex: 1 0 100%; gap: 4px;
    overflow-x: auto; -webkit-overflow-scrolling: touch;
    padding-bottom: 2px; scrollbar-width: none;
  }
  .mainnav::-webkit-scrollbar { display: none; }
  .mainnav a { padding: 7px 12px; font-size: 13px; white-space: nowrap; }
  .content { padding: 18px 14px 48px; }
}

/* --- product edit form + pager (added with the in-place edit UI) --- */
.editform .grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 10px 16px; margin-bottom: 12px; }
.editform label { display: flex; flex-direction: column; font-size: 12px; color: #6B7784; gap: 4px; }
.editform label.chk { flex-direction: row; align-items: center; gap: 6px; }
.editform input[type=text], .editform input[type=number] {
  padding: 6px 8px; border: 1px solid #D6DEE7; border-radius: 4px; font-size: 13px; }
/* A rejected save has to read as a stop, not as the usual grey status line — the
   operator's edits are still on screen and only a reload will reconcile them. */
#edit-msg.conflict { color: var(--danger); font-weight: 600; }
.pager { display: flex; align-items: center; gap: 12px; margin: 14px 0 4px; }
.pager .btn.disabled { opacity: .4; pointer-events: none; }
/* An unmatched run: absence of data, not a zero price. */
.chart-bar.none { height: 100%; background: repeating-linear-gradient(45deg,
  #EEF2F7, #EEF2F7 3px, transparent 3px, transparent 6px); border: 1px dashed #D6DEE7; }

/* --- sortable column header + inline percentage --- */
th.sortable a { color: inherit; text-decoration: none; white-space: nowrap; }
th.sortable a:hover { text-decoration: underline; }
.sortdir { font-size: 11px; font-weight: 400; color: #2E6FB0; }
.sortdir.muted { color: #B4BDC6; }
/* Lighter than the amount: the won figure is the number being compared. */
.pct { font-size: 11px; opacity: .75; }

/* --- Dashboard status panels ------------------------------------------------
   Light theme kept; what changed is that the page reports health instead of
   dumping the catalogue. Everything here is additive — no existing rule altered. */
.cards { grid-template-columns: repeat(auto-fit, minmax(min(210px, 100%), 1fr)); }
.card-foot { font-size: 12px; margin-top: 8px; }
.card-value .unit { font-size: 17px; font-weight: 600; margin-left: 2px; color: var(--muted); }

.dashgrid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(min(310px, 100%), 1fr));
  gap: 16px; margin-top: 20px; align-items: start;
}
.dashgrid .panel { margin-top: 0; }
/* The trend chart earns a double column when there is room for one. */
.dashgrid .panel.wide { grid-column: span 2; }
.dashgrid .panel-title .muted { font-weight: 400; }

/* Freshness: one bar, three states, so "how old is this" is a glance not a query. */
.stackbar { display: flex; height: 10px; border-radius: 6px; overflow: hidden;
  background: var(--gray-bg); margin: 6px 0 12px; }
.stackbar .seg { display: block; height: 100%; }
.stackbar .seg.ok { background: #2f9e5f; }
.stackbar .seg.warn { background: #e0a32e; }
.stackbar .seg.danger { background: #d4553f; }
.legend { list-style: none; display: flex; flex-wrap: wrap; gap: 6px 18px;
  margin: 0; padding: 0; font-size: 12.5px; color: var(--muted); }
.legend b { color: var(--ink); margin-left: 3px; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; margin-right: 6px; }
.dot.ok { background: #2f9e5f; } .dot.warn { background: #e0a32e; } .dot.danger { background: #d4553f; }

/* Horizontal bars: label, proportion, value — readable without a chart library. */
.hbars { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 10px; }
.hbars li { display: grid; grid-template-columns: 92px 1fr auto; align-items: center; gap: 10px; }
.hbar-label { font-size: 12.5px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; }
.hbar-track { background: var(--gray-bg); border-radius: 6px; height: 8px; overflow: hidden; }
.hbar-fill { display: block; height: 100%; background: var(--accent); border-radius: 6px; }
.hbar-fill.ok { background: #2f9e5f; }
.hbar-val { font-size: 12.5px; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Daily collection volume. A gap in the bars is a gap in updating. */
.minichart { display: flex; align-items: flex-end; gap: 6px; height: 140px; padding-top: 6px; }
.minicol { flex: 1; min-width: 16px; height: 100%; display: flex;
  flex-direction: column; align-items: center; justify-content: flex-end; }
.minibar { width: 66%; min-height: 2px; border-radius: 4px 4px 0 0;
  background: linear-gradient(180deg, #6f9ef5, var(--accent)); }
.minix { font-size: 10px; color: var(--muted); margin-top: 5px; white-space: nowrap; }

/* Recent activity feed. */
.feed { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; }
.feed li { display: flex; align-items: baseline; justify-content: space-between; gap: 4px 12px;
  padding: 8px 0; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.feed li:last-child { border-bottom: 0; }
.feed-name { font-size: 13px; flex: 1 1 60%; min-width: 0; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.feed-meta { display: flex; align-items: baseline; gap: 8px; font-size: 12px;
  white-space: nowrap; font-variant-numeric: tabular-nums; }
.feed-meta .neg { color: var(--danger); font-weight: 600; }
.feed-meta .pos { color: var(--ok); font-weight: 600; }

/* A stale-data banner has to read as a warning, not as chrome. */
.alert.warnbar { background: var(--warn-bg); color: var(--warn); border: 1px solid #eed9a8; }

@media (max-width: 720px) {
  .dashgrid .panel.wide { grid-column: span 1; }
}
