:root {
  --bg: #f5f3ef;
  --surface: #ffffff;
  --border: #e5e0d8;
  --text: #1a1a1a;
  --text-muted: #6b6560;
  --accent: #2d5a3d;
  --accent-light: #e8f0eb;
  --danger: #c0392b;
  --danger-light: #fdecea;
  --warning: #d4a017;
  --radius: 10px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 4px 12px rgba(0,0,0,.04);
  --font: 'Pretendard', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
}

/* Header */
.app-header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 1rem 2rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
  box-shadow: var(--shadow);
}

.app-header h1 {
  font-size: 1.25rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.02em;
}

.header-actions {
  display: flex;
  gap: .5rem;
  align-items: center;
}

.stats-badge {
  font-size: .8rem;
  color: var(--text-muted);
  background: var(--bg);
  padding: .3rem .75rem;
  border-radius: 20px;
  border: 1px solid var(--border);
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 0 2rem;
  overflow-x: auto;
}

.tab-btn {
  padding: .85rem 1.25rem;
  border: none;
  background: none;
  cursor: pointer;
  font-size: .9rem;
  font-weight: 500;
  color: var(--text-muted);
  border-bottom: 2px solid transparent;
  white-space: nowrap;
  transition: color .15s, border-color .15s;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

/* Main */
.main-content {
  max-width: 1280px;
  margin: 0 auto;
  padding: 1.5rem 2rem 3rem;
}

.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
}

.card-header h2 {
  font-size: 1rem;
  font-weight: 600;
}

.card-body { padding: 1.25rem; }

/* Search bar */
.search-bar {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg);
}

.search-fields {
  display: flex;
  align-items: flex-end;
  gap: .75rem;
  flex-wrap: wrap;
}

.search-field[hidden] {
  display: none;
}

.search-field {
  display: flex;
  flex-direction: column;
  gap: .3rem;
}

.search-field label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.search-field select,
.search-field input[type="date"] {
  min-width: 160px;
  padding: .5rem .65rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .875rem;
  background: var(--surface);
}

.search-actions {
  display: flex;
  align-items: center;
  gap: .75rem;
  flex-wrap: wrap;
}

.search-result-count {
  font-size: .85rem;
  color: var(--text-muted);
  white-space: nowrap;
}

.pagination-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  padding: .85rem 1.25rem;
  border-top: 1px solid var(--border);
  background: var(--surface);
}

.pagination-info {
  font-size: .85rem;
  color: var(--text-muted);
}

.pagination-controls {
  display: flex;
  align-items: center;
  gap: .5rem;
}

.pagination-controls .btn[disabled] {
  opacity: .5;
  cursor: not-allowed;
}

.product-ids-text {
  font-size: .82rem;
  line-height: 1.5;
  word-break: break-all;
}

.table-loading td {
  text-align: center;
  padding: 2rem;
  color: var(--text-muted);
}

.col-select {
  width: 64px;
  text-align: center;
  white-space: nowrap;
}

.select-all-label {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  cursor: pointer;
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.row-select {
  text-align: center;
}

.row-select input[type="checkbox"] {
  width: 16px;
  height: 16px;
  cursor: pointer;
}

tr.is-selected {
  background: var(--accent-light);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .4rem;
  padding: .5rem 1rem;
  border-radius: 6px;
  border: 1px solid transparent;
  font-size: .875rem;
  font-weight: 500;
  cursor: pointer;
  transition: background .15s, border-color .15s;
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}
.btn-primary:hover { background: #234a32; }

.btn-secondary {
  background: var(--surface);
  color: var(--text);
  border-color: var(--border);
}
.btn-secondary:hover { background: var(--bg); }

.btn-danger {
  background: var(--danger-light);
  color: var(--danger);
  border-color: #f5c6c2;
}
.btn-danger:hover { background: #f9d5d2; }

.btn-sm { padding: .3rem .65rem; font-size: .8rem; }

/* Table */
.table-wrap { overflow-x: auto; }

table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
}

thead th {
  background: var(--bg);
  padding: .65rem 1rem;
  text-align: left;
  font-weight: 600;
  color: var(--text-muted);
  font-size: .8rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: .75rem 1rem;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tbody tr:last-child td { border-bottom: none; }
tbody tr:hover td { background: #faf9f7; }

.tag {
  display: inline-block;
  padding: .15rem .5rem;
  border-radius: 4px;
  font-size: .75rem;
  font-weight: 500;
  background: var(--accent-light);
  color: var(--accent);
}

.tag-gray {
  background: #f0eeeb;
  color: var(--text-muted);
}

.score {
  display: inline-flex;
  align-items: center;
  gap: 2px;
}

.score-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--border);
}
.score-dot.filled { background: var(--warning); }

/* Guide */
.guide-section { margin-bottom: 2rem; }
.guide-section h3 {
  font-size: .95rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: .75rem;
  padding-bottom: .4rem;
  border-bottom: 2px solid var(--accent-light);
}

.guide-table {
  width: 100%;
  border-collapse: collapse;
  font-size: .875rem;
  margin-bottom: 1rem;
}

.guide-table th {
  background: var(--bg);
  padding: .5rem .75rem;
  text-align: left;
  font-weight: 600;
  width: 160px;
  border: 1px solid var(--border);
}

.guide-table td {
  padding: .5rem .75rem;
  border: 1px solid var(--border);
}

.ref-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 1rem;
}

.ref-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .75rem 1rem;
}

.ref-card h4 {
  font-size: .8rem;
  font-weight: 700;
  color: var(--accent);
  margin-bottom: .5rem;
  text-transform: uppercase;
  letter-spacing: .05em;
}

.ref-card ul { list-style: none; }
.ref-card li {
  font-size: .8rem;
  padding: .2rem 0;
  color: var(--text-muted);
  display: flex;
  justify-content: space-between;
  gap: .5rem;
}

.ref-card li span { color: var(--text); font-weight: 500; }

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.4);
  z-index: 200;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: 0 20px 60px rgba(0,0,0,.2);
  width: 100%;
  max-width: 560px;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-header h3 { font-size: 1rem; font-weight: 600; }

.modal-close {
  background: none;
  border: none;
  font-size: 1.25rem;
  cursor: pointer;
  color: var(--text-muted);
  line-height: 1;
}

.modal-body { padding: 1.5rem; }

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border);
  display: flex;
  justify-content: flex-end;
  gap: .5rem;
}

/* Form */
.form-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}

.form-group { display: flex; flex-direction: column; gap: .35rem; }
.form-group.full { grid-column: 1 / -1; }

.form-group label {
  font-size: .8rem;
  font-weight: 600;
  color: var(--text-muted);
}

.form-group input,
.form-group select,
.form-group textarea {
  padding: .55rem .75rem;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: .875rem;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
  transition: border-color .15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}

.form-group textarea { resize: vertical; min-height: 70px; }

.form-hint {
  font-size: .75rem;
  color: var(--text-muted);
}

/* Product picker */
.product-picker {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
  margin-top: .5rem;
}

.product-chip {
  display: inline-flex;
  align-items: center;
  gap: .3rem;
  padding: .25rem .6rem;
  background: var(--accent-light);
  color: var(--accent);
  border-radius: 20px;
  font-size: .78rem;
  cursor: pointer;
  border: 1px solid transparent;
  transition: border-color .15s;
}

.product-chip.selected {
  background: var(--accent);
  color: #fff;
}

.product-chip:hover { border-color: var(--accent); }

/* Toast */
.toast-container {
  position: fixed;
  bottom: 1.5rem;
  right: 1.5rem;
  z-index: 300;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.toast {
  padding: .75rem 1.25rem;
  border-radius: 8px;
  font-size: .875rem;
  font-weight: 500;
  box-shadow: var(--shadow);
  animation: slideIn .2s ease;
}

.toast-success { background: var(--accent); color: #fff; }
.toast-error { background: var(--danger); color: #fff; }

@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

.empty-state {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text-muted);
}

.empty-state p { margin-top: .5rem; font-size: .875rem; }

/* Import */
.import-area {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 2rem;
  text-align: center;
  cursor: pointer;
  transition: border-color .15s, background .15s;
}

.import-area:hover, .import-area.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.import-area p { color: var(--text-muted); font-size: .875rem; margin-top: .5rem; }

/* Dropzone */
.dropzone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 1.25rem;
  cursor: pointer;
  transition: border-color .15s, background .15s;
  position: relative;
  min-height: 120px;
}

.dropzone:hover, .dropzone.dragover {
  border-color: var(--accent);
  background: var(--accent-light);
}

.dropzone-content {
  text-align: center;
  color: var(--text-muted);
  font-size: .875rem;
}

.dropzone-preview {
  display: flex;
  justify-content: center;
}

.image-grid {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
  margin-top: .5rem;
}

.image-card {
  position: relative;
  width: 100px;
  text-align: center;
}

.image-card img {
  width: 100px;
  height: 100px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
}

.image-card-label {
  display: block;
  font-size: .72rem;
  color: var(--text-muted);
  margin-top: .3rem;
  word-break: break-all;
}

.image-card-remove {
  position: absolute;
  top: -6px;
  right: -6px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: none;
  background: var(--danger);
  color: #fff;
  cursor: pointer;
  font-size: .9rem;
  line-height: 1;
}

.thumb {
  width: 48px;
  height: 48px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.product-ids-cell {
  display: flex;
  flex-wrap: wrap;
  gap: .4rem;
}

.mini-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
}

.mini-card img {
  width: 40px;
  height: 40px;
  object-fit: cover;
  border-radius: 4px;
  border: 1px solid var(--border);
}

.mini-card span {
  font-size: .65rem;
  color: var(--text-muted);
}

input[readonly] {
  background: var(--bg);
  color: var(--text-muted);
  cursor: default;
}

@media (max-width: 640px) {
  .app-header, .tabs, .main-content { padding-left: 1rem; padding-right: 1rem; }
  .form-grid { grid-template-columns: 1fr; }
  .header-actions { flex-wrap: wrap; }
}

.view-toggle {
  display: flex;
  gap: .35rem;
}

.view-toggle .btn.is-active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.login-overlay {
  position: fixed;
  inset: 0;
  z-index: 400;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: var(--bg);
}

.login-overlay.hidden { display: none; }

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: .5rem;
}

.login-card h2 { font-size: 1.25rem; }
.login-hint, .login-error { font-size: .85rem; color: var(--text-muted); }
.login-error { color: var(--danger); }
.login-card input {
  width: 100%;
  padding: .55rem .7rem;
  border: 1px solid var(--border);
  border-radius: 8px;
  font: inherit;
}

.stats-section-title {
  margin: 1.35rem 0 .75rem;
  font-size: .95rem;
  font-weight: 600;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: .75rem;
  margin-bottom: 1.25rem;
}

.stat-card {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: .85rem 1rem;
  background: var(--bg);
}

.stat-label {
  font-size: .75rem;
  font-weight: 600;
  color: var(--text-muted);
}

.stat-value {
  font-size: 1.45rem;
  font-weight: 700;
  color: var(--accent);
  letter-spacing: -0.03em;
  line-height: 1.3;
}

.stat-sub {
  font-size: .75rem;
  color: var(--text-muted);
}

.stats-table .num,
.stats-table th.num {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.stats-table tr.is-zero td {
  color: var(--text-muted);
}

.share-cell {
  min-width: 140px;
}

.share-bar {
  height: 8px;
  background: #efece7;
  border-radius: 99px;
  overflow: hidden;
}

.share-bar > span {
  display: block;
  height: 100%;
  background: var(--accent);
  border-radius: 99px;
}

.share-label {
  display: block;
  margin-top: .2rem;
  font-size: .75rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
}

@media (max-width: 800px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

.dup-note { margin-bottom: 1rem; }

.dup-group {
  margin-top: 1.25rem;
  padding-top: 1rem;
  border-top: 1px solid var(--border);
}

.dup-group h3 {
  font-size: .9rem;
  font-weight: 600;
  margin-bottom: .75rem;
}

.dup-items {
  display: flex;
  flex-wrap: wrap;
  gap: .75rem;
}

.dup-item {
  width: 160px;
  display: flex;
  flex-direction: column;
  gap: .15rem;
  color: inherit;
  text-decoration: none;
}

.dup-item.is-mine img {
  border: 2px solid var(--accent);
}

.dup-item img,
.dup-missing {
  width: 160px;
  height: 160px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg);
}

.dup-missing {
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: .8rem;
}

.dup-item strong {
  font-size: .85rem;
  margin-top: .25rem;
}

.dup-item span {
  font-size: .75rem;
  color: var(--text-muted);
  line-height: 1.35;
}
.login-card .btn { margin-top: .5rem; }
