/* ── Variables ── */
:root {
  --bg: #ffffff;
  --bg2: #f8f9fa;
  --bg3: #f1f3f5;
  --border: #e9ecef;
  --border2: #dee2e6;
  --text: #212529;
  --text2: #495057;
  --text3: #868e96;
  --primary: #339af0;
  --primary-dark: #1c7ed6;
  --success: #51cf66;
  --danger: #ff6b6b;
  --warning: #fcc419;
  --info: #74c0fc;
  --radius: 8px;
  --radius-sm: 4px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow-md: 0 4px 16px rgba(0,0,0,.10);
  --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Noto Sans KR', sans-serif;
  --mono: 'JetBrains Mono', 'Cascadia Code', monospace;
}

/* ── Reset ── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body { font-family: var(--font); font-size: 14px; color: var(--text); background: var(--bg2); line-height: 1.5; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
button { cursor: pointer; font-family: inherit; }
input, select, textarea { font-family: inherit; }

/* ── Layout ── */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  /* activity-bar가 뜨면 JS가 --activity-bar-height를 실측해서 채운다 (기본 0) */
  padding-top: var(--activity-bar-height, 0px);
}

.nav {
  background: var(--bg);
  border-bottom: 1px solid var(--border);
  padding: 0 24px;
  display: flex;
  align-items: center;
  gap: 24px;
  height: 52px;
  position: sticky;
  top: var(--activity-bar-height, 0px);
  z-index: 100;
  box-shadow: var(--shadow);
}

/* ── 상단 고정 상태바 — 크롤링/R2업로드/등록 진행 중일 때만 표시 ── */
.activity-bar {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 200;
  background: #e8590c;
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  padding: 7px 20px;
  flex-wrap: wrap;
  align-items: center;
  gap: 4px 24px;
  box-shadow: var(--shadow-md);
}
.activity-bar.visible { display: flex; }
.activity-bar-item { white-space: nowrap; }
.nav-brand {
  font-weight: 700;
  font-size: 16px;
  color: var(--text);
  letter-spacing: -.3px;
}
.nav-brand span { color: var(--primary); }
.nav-links { display: flex; gap: 4px; }
.nav-link {
  padding: 6px 12px;
  border-radius: var(--radius-sm);
  color: var(--text2);
  font-size: 13px;
  font-weight: 500;
  transition: background .15s, color .15s;
}
.nav-link:hover, .nav-link.active { background: var(--bg3); color: var(--text); text-decoration: none; }
.nav-spacer { flex: 1; }
.nav-chrome-hint {
  font-size: 11px;
  color: var(--text3);
  background: var(--bg3);
  padding: 4px 10px;
  border-radius: 20px;
  cursor: pointer;
  border: none;
}

.chrome-status-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 4px 10px;
  border-radius: 20px;
  margin-right: 8px;
  background: var(--bg3);
  color: var(--text3);
  white-space: nowrap;
}
.chrome-status-badge.connected { background: #d3f9d8; color: #2f9e44; }
.chrome-status-badge.disconnected { background: #ffe3e3; color: #e03131; }

.main { flex: 1; padding: 24px; max-width: 1400px; margin: 0 auto; width: 100%; }

/* ── Cards ── */
.card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}
.card-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
}
.card-title { font-size: 15px; font-weight: 600; }
.card-body { padding: 20px; }

/* ── Buttons ── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font-size: 13px;
  font-weight: 500;
  transition: all .15s;
  white-space: nowrap;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--primary); color: #fff; border-color: var(--primary); }
.btn-primary:hover:not(:disabled) { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; border-color: var(--success); }
.btn-danger { background: var(--danger); color: #fff; border-color: var(--danger); }
.btn-ghost { background: transparent; color: var(--text2); border-color: var(--border2); }
.btn-ghost:hover:not(:disabled) { background: var(--bg3); color: var(--text); }
.btn-sm { padding: 4px 10px; font-size: 12px; }
.btn-xs { padding: 2px 7px; font-size: 11px; }
.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

/* ── Badges ── */
.badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 20px;
  font-size: 11px;
  font-weight: 600;
}
.badge-미수집 { background: var(--bg3); color: var(--text3); }
.badge-수집중 { background: #fff3bf; color: #e67700; }
.badge-완료  { background: #d3f9d8; color: #2f9e44; }
.badge-오류  { background: #ffe3e3; color: #e03131; }
.badge-로그인필요 { background: #ffe8cc; color: #d9480f; }
.badge-대기  { background: var(--bg3); color: var(--text3); }
.badge-검토중 { background: #e7f5ff; color: #1971c2; }
.badge-등록완료 { background: #d3f9d8; color: #2f9e44; }
.badge-부분등록 { background: #fff3bf; color: #e67700; }
.badge-안올림 { background: #fff5f5; color: #c92a2a; }

/* ── Tables ── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--border); }
th { font-size: 12px; font-weight: 600; color: var(--text3); background: var(--bg2); white-space: nowrap; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg2); }
td.num { text-align: right; font-family: var(--mono); }

/* ── Dashboard specific ── */
.date-table td { vertical-align: middle; }
.date-table .collect-btn { min-width: 80px; }
.date-table .date-col { font-family: var(--mono); font-size: 13px; }

.num-muted { color: var(--text3); }
.num-danger {
  color: #e03131;
  font-weight: 700;
  cursor: pointer;
  background: none;
  border: none;
  font-family: var(--mono);
  font-size: inherit;
  text-decoration: none;
  padding: 2px 6px;
  border-radius: 4px;
}
.num-danger:hover { background: #ffe3e3; text-decoration: underline; }

/* ── 등록실패 상세 모달 (아코디언) ── */
.regfail-site { border-bottom: 1px solid var(--border); }
.regfail-site:last-child { border-bottom: none; }
.regfail-site-toggle {
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  padding: 10px 4px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  color: var(--text);
}
.regfail-site-toggle:hover { background: var(--bg2); }
.regfail-caret { display: inline-block; width: 14px; color: var(--text3); }
.regfail-list { list-style: none; margin: 0 0 8px 22px; padding: 0; }
.regfail-list li {
  padding: 6px 8px;
  font-size: 13px;
  color: var(--text2);
  border-bottom: 1px dashed var(--border);
}
.regfail-list li:last-child { border-bottom: none; }

/* Progress log */
.progress-log {
  background: #1a1a2e;
  color: #c3e6fb;
  border-radius: var(--radius);
  padding: 16px;
  font-family: var(--mono);
  font-size: 12px;
  overflow-y: auto;
  line-height: 1.7;
}
.log-line { display: flex; gap: 8px; }
.log-idx  { color: #74c0fc; min-width: 60px; }
.log-icon { min-width: 20px; }
.log-brand { color: #ffd43b; }
.log-title { color: #e9ecef; }
.log-price { color: #69db7c; }
.log-error { color: #ff6b6b; }
.log-info  { color: #74c0fc; }

/* Progress bar */
.progress { background: var(--bg3); border-radius: 20px; height: 6px; overflow: hidden; margin: 8px 0; }
.progress-bar { height: 100%; background: var(--primary); border-radius: 20px; transition: width .3s; }

/* ── Review table ── */
.review-table { font-size: 13px; }
.review-table th { position: sticky; top: 0; z-index: 10; }
.review-table td { vertical-align: middle; max-width: 280px; }
.thumb-cell { width: 64px; }
.thumb { width: 56px; height: 56px; object-fit: cover; border-radius: var(--radius-sm); cursor: pointer; border: 2px solid transparent; transition: border-color .15s; }
.thumb:hover { border-color: var(--primary); }
.thumb-placeholder { width: 56px; height: 56px; background: var(--bg3); border-radius: var(--radius-sm); display: flex; align-items: center; justify-content: center; color: var(--text3); font-size: 20px; }

/* Inline editable cell */
.editable { cursor: pointer; border-radius: var(--radius-sm); padding: 2px 4px; min-height: 24px; }
.editable:hover { background: var(--bg3); }
.editable input, .editable select {
  border: 1px solid var(--primary);
  border-radius: var(--radius-sm);
  padding: 3px 6px;
  font-size: 13px;
  width: 100%;
  outline: none;
  background: #fff;
}

.skip-btn { color: var(--text3); border: none; background: none; font-size: 16px; padding: 4px; border-radius: 50%; width: 28px; height: 28px; display: inline-flex; align-items: center; justify-content: center; transition: background .15s, color .15s; }
.skip-btn:hover { background: #ffe3e3; color: var(--danger); }

/* Selection */
.review-table tr.selected td { background: #e7f5ff; }
.review-table tr.skipped td { opacity: .45; text-decoration: line-through; }

/* ── Modal ── */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(0,0,0,.55);
  display: flex; align-items: center; justify-content: center;
  z-index: 1000; padding: 24px;
}
.modal {
  background: var(--bg); border-radius: var(--radius);
  max-width: 800px; width: 100%; max-height: 85vh;
  display: flex; flex-direction: column;
  box-shadow: var(--shadow-md);
}
.modal-header {
  padding: 16px 20px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; justify-content: space-between;
}
.modal-title { font-size: 15px; font-weight: 600; }
.modal-close { background: none; border: none; font-size: 20px; color: var(--text3); cursor: pointer; }
.modal-body { padding: 20px; overflow-y: auto; flex: 1; }
.modal-footer { padding: 16px 20px; border-top: 1px solid var(--border); display: flex; justify-content: flex-end; gap: 8px; }

.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
.img-item { position: relative; cursor: pointer; }
.img-item img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius-sm); border: 3px solid transparent; transition: border-color .15s; }
.img-item.selected img { border-color: var(--primary); }
.img-item .img-badge {
  position: absolute; top: 4px; left: 4px;
  background: var(--primary); color: #fff;
  border-radius: var(--radius-sm); font-size: 10px; padding: 2px 6px;
}
.img-item .img-delete-btn {
  position: absolute; top: 4px; right: 4px;
  width: 22px; height: 22px; line-height: 20px; text-align: center;
  background: rgba(220,38,38,.85); color: #fff;
  border: none; border-radius: 50%; font-size: 13px; cursor: pointer;
  display: none; z-index: 2;
}
.img-item:hover .img-delete-btn { display: block; }
.img-item .img-delete-btn:disabled { opacity: .35; cursor: not-allowed; }

/* ── Register queue: force-register icon ── */
.btn-force-reg {
  margin-left: 4px; width: 18px; height: 18px; line-height: 16px;
  border: 1px solid var(--border2); border-radius: 50%; background: var(--bg);
  color: var(--text2); font-size: 11px; cursor: pointer; padding: 0;
}
.btn-force-reg:hover { background: var(--bg3); border-color: var(--primary); color: var(--primary); }

/* ── R2 File Browser ── */
.bc-link { color: var(--primary); cursor: pointer; font-size: 13px; }
.bc-link:hover { text-decoration: underline; }
.bc-current { font-weight: 600; font-size: 13px; color: var(--text); }
.bc-sep { color: var(--text3); margin: 0 4px; font-size: 13px; }
.r2-folder-link { color: var(--primary); cursor: pointer; font-size: 13px; }
.r2-folder-link:hover { text-decoration: underline; }
.r2-file-name { font-size: 13px; color: var(--text); }
.r2-table { width: 100%; border-collapse: collapse; }
.r2-table th { padding: 10px 12px; text-align: left; font-size: 12px; color: var(--text3); border-bottom: 1px solid var(--border); }
.r2-table td { padding: 8px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.r2-table tr:hover { background: var(--bg2); }
.r2-table tr.selected { background: color-mix(in srgb, var(--primary) 8%, transparent); }

/* ── Filter bar ── */
.filter-bar {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  padding: 12px 20px; border-bottom: 1px solid var(--border);
  background: var(--bg);
}
.filter-bar input, .filter-bar select {
  padding: 6px 10px; border: 1px solid var(--border2); border-radius: var(--radius-sm);
  font-size: 13px; background: var(--bg); color: var(--text); outline: none;
}
.filter-bar input:focus, .filter-bar select:focus { border-color: var(--primary); }

/* ── 사이트 컬럼 표시필터 드롭다운 (사이트 개수 늘어도 컬럼을 줄여볼 수 있게) ── */
.site-filter-dropdown { position: relative; }
.site-filter-dropdown > summary {
  list-style: none; cursor: pointer; padding: 6px 10px; border: 1px solid var(--border2);
  border-radius: var(--radius-sm); font-size: 13px; background: var(--bg); color: var(--text);
  user-select: none;
}
.site-filter-dropdown > summary::-webkit-details-marker { display: none; }
.site-filter-panel {
  position: absolute; top: calc(100% + 4px); left: 0; z-index: 50;
  background: var(--bg); border: 1px solid var(--border2); border-radius: var(--radius-sm);
  box-shadow: 0 4px 12px rgba(0,0,0,0.12); padding: 8px 12px; min-width: 160px;
  max-height: 240px; overflow-y: auto;
}
.site-filter-panel label {
  display: flex; align-items: center; gap: 6px; font-size: 13px; padding: 4px 0; white-space: nowrap;
}

/* ── Stats row ── */
.stats { display: flex; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.stat-card {
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 20px; display: flex; flex-direction: column; gap: 4px; min-width: 120px;
}
.stat-label { font-size: 11px; color: var(--text3); font-weight: 600; text-transform: uppercase; letter-spacing: .5px; }
.stat-value { font-size: 22px; font-weight: 700; color: var(--text); font-family: var(--mono); }

/* ── Bottom action bar (review) ── */
.action-bar {
  position: sticky; bottom: 0; background: var(--bg);
  border-top: 1px solid var(--border); padding: 12px 20px;
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  box-shadow: 0 -2px 8px rgba(0,0,0,.06);
}
.action-bar .selected-info { font-size: 13px; color: var(--text2); font-weight: 500; }

/* ── Result page ── */
.result-list { display: flex; flex-direction: column; gap: 16px; }
.result-item { background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px 20px; }
.result-item-header { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.result-sites { display: flex; flex-direction: column; gap: 6px; padding-left: 16px; }
.result-site-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }

/* ── Chrome hint modal ── */
.chrome-hint { background: var(--bg); border-radius: var(--radius); padding: 20px; max-width: 480px; }
.chrome-hint pre { background: #1a1a2e; color: #74c0fc; padding: 12px; border-radius: var(--radius-sm); font-size: 12px; white-space: pre-wrap; word-break: break-all; margin: 10px 0; }

/* ── 작업대상 날짜 배너 (수집검토/등록대기) — "오늘 날짜"로 오해하지 않게 크고 눈에 띄게 ── */
.date-banner {
  font-size: 22px;
  font-weight: 800;
  color: #e03131;
  margin-bottom: 16px;
  padding: 10px 4px;
}
.date-banner:empty { display: none; }

/* ── 텔레그램 알림 토글 (우하단 고정, 전 화면 공통) ── */
.telegram-toggle-btn {
  position: fixed;
  right: 18px;
  bottom: 72px; /* 토스트 알림(.toast-container, bottom:24px)과 겹치지 않도록 위쪽에 배치 */
  z-index: 9999;
  padding: 7px 12px;
  border-radius: 20px;
  border: none;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--shadow-md);
  white-space: nowrap;
  transition: background .15s, transform .1s;
}
.telegram-toggle-btn:active { transform: scale(0.97); }
.telegram-toggle-btn.on { background: #d3f9d8; color: #2f9e44; }
.telegram-toggle-btn.off { background: #e9ecef; color: #868e96; }

/* ── Utilities ── */
.flex { display: flex; }
.items-center { align-items: center; }
.gap-8 { gap: 8px; }
.gap-12 { gap: 12px; }
.text-muted { color: var(--text3); }
.text-sm { font-size: 12px; }
.font-mono { font-family: var(--mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hidden { display: none !important; }
.w-full { width: 100%; }
.mt-4 { margin-top: 4px; }
.mt-8 { margin-top: 8px; }
.mt-16 { margin-top: 16px; }
.mb-16 { margin-bottom: 16px; }

/* ── Toast ── */
.toast-container { position: fixed; bottom: 24px; right: 24px; display: flex; flex-direction: column; gap: 8px; z-index: 2000; }
.toast {
  background: var(--text); color: #fff; padding: 10px 16px; border-radius: var(--radius);
  font-size: 13px; box-shadow: var(--shadow-md); animation: slideIn .25s ease;
  max-width: 320px;
}
.toast.success { background: #2f9e44; }
.toast.error   { background: #e03131; }
.toast.warning { background: #e67700; }
@keyframes slideIn { from { transform: translateX(100%); opacity: 0; } to { transform: none; opacity: 1; } }

/* ── Responsive ── */
@media (max-width: 768px) {
  .main { padding: 12px; }
  .stats { gap: 8px; }
  .stat-card { padding: 10px 14px; min-width: 90px; }
  .stat-value { font-size: 18px; }
  .filter-bar { gap: 8px; }
  .action-bar { gap: 8px; }
  .nav { padding: 0 12px; gap: 12px; }
}

@media (max-width: 480px) {
  .nav-chrome-hint { display: none; }
}
