:root {
  --bg: #f4f5f7;
  --card: #ffffff;
  --border: #e7e8ec;
  --text: #222;
  --muted: #9a9ea6;
  --sub: #6b7079;
  --accent: #f6c744;      /* 코에르/셀하 느낌의 옐로우 */
  --accent-deep: #e9b100;
  --up: #e5484d;          /* 순위 상승(빨강, 한국식) */
  --down: #2f6fed;        /* 순위 하락(파랑) */
  --chip: #f3f4f6;
}
* { box-sizing: border-box; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: "Pretendard", -apple-system, "Malgun Gothic", sans-serif;
  font-size: 14px;
}
.wrap { max-width: 1120px; margin: 0 auto; padding: 18px 20px 60px; }

/* ── 탭 ── */
.tabs-row { display: flex; justify-content: space-between; align-items: flex-end; border-bottom: 1px solid var(--border); }
.tabs { display: flex; gap: 4px; }
.tab {
  background: #eceef1; border: 1px solid var(--border); border-bottom: none;
  padding: 9px 22px; font-size: 15px; font-weight: 700; color: var(--muted);
  border-radius: 8px 8px 0 0; cursor: pointer;
}
.tab.active { background: #fff; color: #111; }
.btn-ghost {
  background: #fff; border: 1px solid var(--border); border-radius: 6px;
  padding: 7px 13px; color: var(--sub); cursor: pointer; margin-bottom: 8px; font-size: 13px;
}

/* ── 통계 줄 ── */
.stat-row { display: flex; justify-content: space-between; align-items: center; margin: 16px 2px; }
.stats { display: flex; gap: 26px; font-size: 14px; }
.stat b { color: #f08c00; font-weight: 800; }
.stat .muted { color: var(--muted); }
.diamond { display: inline-block; width: 8px; height: 8px; background: #f0a020; transform: rotate(45deg); margin-right: 6px; }
.right-controls { display: flex; gap: 8px; align-items: center; }
.login-badge { font-size: 12px; font-weight: 700; padding: 6px 10px; border-radius: 6px; }
.login-badge.on { color: #1a7f37; background: #e6f4ea; }
.login-badge.warn { color: #b54708; background: #fef0e6; }
.login-badge.off { color: #b42318; background: #fee4e2; }
.btn-measure {
  background: #fff; border: 1px solid var(--accent-deep); color: #b57e00;
  border-radius: 8px; padding: 9px 16px; font-weight: 700; cursor: pointer;
}
.btn-measure:hover { background: #fffdf3; }
.btn-big {
  background: var(--accent); border: none; border-radius: 8px;
  padding: 9px 18px; font-weight: 800; cursor: pointer; color: #4a3b00;
}
.btn-big .ico { font-weight: 900; margin-right: 4px; }

/* ── 그리드 ── */
.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }
.grid.big { grid-template-columns: repeat(2, 1fr); }

/* ── 추가 카드 ── */
.card.add {
  border: 2px dashed var(--accent-deep); background: #fffdf4;
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  text-align: center; color: var(--sub); cursor: pointer; min-height: 210px; gap: 14px;
}
.card.add .plus {
  width: 54px; height: 54px; border-radius: 50%; background: #fbe7bf;
  color: #d79a00; font-size: 30px; display: grid; place-items: center;
}
.card.add .cat-btn {
  background: #fff; border: 1px solid var(--border); border-radius: 20px;
  padding: 7px 16px; color: var(--sub); font-size: 12px;
}

/* ── 상품 카드 ── */
.card {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 16px; position: relative;
}
.card-head { display: flex; gap: 12px; }
.thumb {
  width: 66px; height: 66px; border-radius: 8px; background: #eef0f3 center/cover;
  flex: 0 0 66px; overflow: hidden;
}
.title {
  font-size: 13px; line-height: 1.45; font-weight: 600; color: #2a2a2a;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}

.metrics { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 14px 0 12px; text-align: left; }
.metric .label { color: var(--muted); font-size: 11px; }
.metric .val { font-weight: 700; font-size: 13px; margin-top: 2px; }
.metric .val .up { color: var(--up); font-size: 11px; }

.kw-list { display: grid; grid-template-columns: 1fr 1fr; gap: 7px 10px; border-top: 1px solid #f0f1f3; padding-top: 12px; }
.kw {
  display: flex; align-items: center; justify-content: space-between; gap: 5px;
  background: var(--chip); border-radius: 6px; padding: 6px 9px; font-size: 12px;
}
.kw .name { color: #333; font-weight: 600; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.kw .rank { flex: 0 0 auto; white-space: nowrap; font-weight: 700; color: #222; }
.kw .rank.na { color: var(--muted); font-weight: 600; }
.kw .delta { font-size: 11px; margin-left: 2px; }
.kw .delta.up { color: #22a06b; }    /* 순위 상승 = 초록 ▲ */
.kw .delta.down { color: #e5484d; }   /* 순위 하락 = 빨강 ▼ */
.kw .delta.same { color: var(--muted); }
.kw-more { display: flex; align-items: center; padding-left: 4px; color: var(--muted); font-size: 12px; cursor: pointer; }
.kw-more:hover { color: var(--sub); }

/* ── 모달 ── */
.modal-back { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: grid; place-items: center; z-index: 50; }
.modal-back[hidden] { display: none; }  /* hidden 속성이 display:grid 를 확실히 이기도록 */
.modal { background: #fff; border-radius: 14px; padding: 24px; width: 380px; }
.modal h3 { margin: 0 0 14px; }
.modal-sub { color: var(--sub); margin: -6px 0 12px; font-size: 13px; }
.modal label { display: block; font-size: 12px; color: var(--sub); margin: 12px 0 5px; }
.modal input, .modal textarea {
  width: 100%; border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px; font-size: 13px; font-family: inherit;
}
.modal-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 18px; }
.btn-primary { background: var(--accent); border: none; border-radius: 8px; padding: 9px 20px; font-weight: 700; cursor: pointer; color: #4a3b00; }

/* ── 상품 순서 설정 모달 ── */
.order-modal { width: 640px; max-width: 92vw; position: relative; padding: 26px 28px; }
.modal-x { position: absolute; top: 18px; right: 20px; background: none; border: none; font-size: 22px; line-height: 1; color: var(--muted); cursor: pointer; }
.modal-x:hover { color: #111; }
.order-tab { display: inline-block; margin: 14px 0 4px; padding: 6px 2px; font-weight: 700; color: #b57e00; border-bottom: 2px solid var(--accent-deep); }
.order-hint { color: var(--muted); font-size: 12px; margin: 4px 0 12px; border-top: 1px solid #f0f1f3; padding-top: 12px; }
.order-list { max-height: 56vh; overflow-y: auto; }
.order-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 6px;
  border-bottom: 1px solid #f0f1f3; background: #fff;
}
.order-item .oi-thumb { width: 34px; height: 34px; border-radius: 6px; background: #eef0f3 center/cover; flex: 0 0 34px; }
.order-item .oi-title {
  flex: 1; min-width: 0; font-size: 13px; font-weight: 600; color: #2a2a2a;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.order-item .oi-handle { flex: 0 0 auto; color: #c2c6cd; font-size: 18px; cursor: grab; padding: 0 6px; }
.order-item.dragging { opacity: .5; background: #fffdf3; }

/* ── 상세 뷰 ── */
#detail { padding-top: 4px; }
.back { background: none; border: none; color: var(--sub); font-size: 14px; cursor: pointer; padding: 6px 0; margin-bottom: 10px; }
.back:hover { color: #111; }

.dcard { background: #fff; border: 1px solid var(--border); border-radius: 12px; padding: 18px; display: flex; gap: 16px; }
.thumb-lg { width: 92px; height: 92px; border-radius: 8px; background: #eef0f3 center/cover; flex: 0 0 92px; }
.dinfo { min-width: 0; }
.dtitle { font-size: 15px; font-weight: 700; color: #222; margin-bottom: 8px; }
.dmetrics { color: var(--sub); font-size: 13px; }
.dmetrics b { color: #222; }
.dmetrics i { display: inline-block; width: 1px; height: 11px; background: var(--border); margin: 0 10px; vertical-align: middle; }
.dcat { color: var(--muted); font-size: 12px; margin-top: 8px; }
.dlink { display: inline-block; margin-top: 8px; font-size: 12px; color: #2f6fed; text-decoration: none; }
.dlink:hover { text-decoration: underline; }

.dtabs { display: flex; gap: 4px; margin: 18px 0 0; border-bottom: 1px solid var(--border); }
.dtab { background: none; border: none; border-bottom: 2px solid transparent; padding: 10px 14px; font-size: 14px; font-weight: 700; color: var(--muted); cursor: pointer; }
.dtab.active { color: #111; border-bottom-color: var(--accent-deep); }
.dtab.off { color: #cfd2d8; cursor: default; }

.panel { background: #fff; border: 1px solid var(--border); border-radius: 12px; margin-top: 16px; overflow: hidden; }
.panel-head { padding: 14px 18px; font-weight: 700; border-bottom: 1px solid #f0f1f3; }
.panel-head small { color: var(--muted); font-weight: 500; font-size: 12px; margin-left: 6px; }
.panel-body { padding: 18px; }

.kw-input-row { display: flex; gap: 8px; }
.kw-input-row input { flex: 1; border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; font-size: 13px; }
.btn-amber { background: var(--accent); border: none; border-radius: 8px; padding: 0 20px; font-weight: 700; color: #4a3b00; cursor: pointer; }
.staged-head { display: flex; justify-content: space-between; align-items: center; margin: 16px 0 8px; font-size: 13px; color: var(--sub); }
.staged-head b { color: #f08c00; }
.link { color: var(--muted); cursor: pointer; text-decoration: underline; font-size: 12px; }
.staged-chips { display: flex; flex-wrap: wrap; gap: 7px; min-height: 30px; }
.staged-chips .empty { color: var(--muted); font-size: 13px; }
.chip { display: inline-flex; align-items: center; gap: 6px; background: #f3f4f6; border: 1px solid var(--border); border-radius: 16px; padding: 5px 11px; font-size: 12px; font-weight: 600; color: #333; }
.chip.rep { background: #fff7e0; border-color: var(--accent); }
.chip.rep b { color: #b57e00; }
.chip .x { color: #bfc3c9; cursor: pointer; font-weight: 700; }
.chip .x:hover { color: var(--up); }
.save { display: block; width: 100%; padding: 12px; margin-top: 16px; }

.rank-controls { margin-bottom: 12px; }
.rank-controls select { border: 1px solid var(--border); border-radius: 8px; padding: 8px 12px; font-size: 13px; background: #fff; }
.rank-table-wrap { overflow-x: auto; }
.rank-table { border-collapse: collapse; width: auto; font-size: 13px; }
.rank-table th, .rank-table td { padding: 14px 8px; text-align: left; border-bottom: 1px solid #eef0f2; white-space: nowrap; vertical-align: middle; }
.rank-table thead th { color: #97a0ad; font-weight: 600; font-size: 13px; background: #fff; position: sticky; top: 0; }
.rank-table th.kwname { min-width: 108px; }
.rank-table td.kwname { min-width: 108px; font-weight: 700; color: #222; }
.rank-table th.vol, .rank-table td.vol { padding-left: 2px; padding-right: 18px; }
.rank-table td.vol { color: #6aa84f; font-weight: 700; }
.rank-table td.rk { min-width: 132px; }
.rank-table td.rk b { font-weight: 700; color: #222; }
.rank-table td.rk .pg { color: #9aa0a8; font-size: 12px; margin-left: 3px; }
.rank-table td.rk .delta { margin-left: 8px; font-weight: 700; font-size: 12px; }
.rank-table td.rk .delta.up { color: #22a06b; }    /* 순위 상승 = 초록 ▲ */
.rank-table td.rk .delta.down { color: #e5484d; }   /* 순위 하락 = 빨강 ▼ */
.rank-table td.rk.out { color: #b6bbc2; }
.rank-table tr.dim td.kwname,
.rank-table tr.dim td.vol { color: #b6bbc2; font-weight: 600; }
.rank-table tbody tr:hover { background: #fafbfc; }

/* ── 단일/원부 배지 ── */
.ptype {
  display: inline-block; vertical-align: 1px; margin-right: 4px;
  font-size: 11px; font-weight: 800; padding: 2px 7px; border-radius: 10px;
  cursor: pointer; user-select: none;
}
.ptype.single { color: #1a7f37; background: #e6f4ea; border: 1px solid #bfe3cb; }
.ptype.wonbu  { color: #6941c6; background: #f0ebfb; border: 1px solid #d9cdf3; }
.ptype.none   { color: #9a9ea6; background: #f3f4f6; border: 1px dashed #d5d8dd; }

/* ── 상세: 운영 정보 입력 ── */
.op-row { display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap; }
.op-row label { display: flex; flex-direction: column; gap: 5px; font-size: 12px; color: var(--sub); }
.op-row input, .op-row select {
  border: 1px solid var(--border); border-radius: 8px; padding: 9px 11px;
  font-size: 13px; font-family: inherit; width: 140px; background: #fff;
}
.op-row .btn-amber { padding: 10px 22px; }

/* 측정 중 배너 */
.toast {
  position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%);
  background: #222; color: #fff; padding: 12px 22px; border-radius: 24px; font-size: 13px; z-index: 60;
  box-shadow: 0 6px 20px rgba(0,0,0,.25);
}
