*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --brand: #2C697A;
  --brand-light: #EBF7FA;
  --green: #10b981;
  --red: #ef4444;
  --yellow: #FAD441;
  --purple: #8b5cf6;
  --bg: #EBF7FA;
  --card: #ffffff;
  --border: #cce6ed;
  --text: #0f2d35;
  --muted: #5794A5;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

/* Header */
header {
  background: linear-gradient(135deg, #0F4250 0%, #2C697A 100%);
  color: white;
  padding: 18px 32px;
  display: flex;
  align-items: center;
  gap: 14px;
  box-shadow: 0 2px 12px rgba(0,0,0,0.2);
}
header .logo { font-size: 30px; }
header h1 { font-size: 19px; font-weight: 700; }
header p  { font-size: 12px; opacity: 0.65; margin-top: 2px; }
.header-logo { height: 44px; width: auto; display: block; }
.header-guide-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  flex-shrink: 0;
  font-size: 13px;
  font-weight: 600;
  color: rgba(255,255,255,0.75);
  text-decoration: none;
  padding: 7px 14px;
  border: 1.5px solid rgba(255,255,255,0.25);
  border-radius: 50px;
  transition: all 0.2s;
}
.header-guide-link:hover {
  color: white;
  border-color: rgba(255,255,255,0.6);
  background: rgba(255,255,255,0.1);
}

.container { max-width: 1800px; margin: 0 auto; padding: 24px 10% 60px; }

/* 横並び3カード */
.mid-row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 14px;
  margin-top: 14px;
  align-items: stretch;
}

/* 空の状態 */
.empty-state {
  background: var(--card);
  border-radius: 16px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  text-align: center;
  padding: 64px 24px;
  color: var(--muted);
}
.empty-state .es-icon  { margin-bottom: 14px; line-height: 1; }
.empty-state .es-title { font-size: 15px; font-weight: 700; color: #374151; margin-bottom: 6px; }
.empty-state .es-desc  { font-size: 13px; line-height: 1.8; }

@media (max-width: 900px) {
  .container { padding: 16px 5% 40px; }
  .mid-row { grid-template-columns: 1fr; }
}

/* Card */
.card {
  background: var(--card);
  border-radius: 16px;
  padding: 20px 22px;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
}
.card-title {
  font-size: 13px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin-bottom: 14px;
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Drop zone */
.drop-zone {
  border: 2px dashed var(--border);
  border-radius: 12px;
  padding: 36px 20px;
  text-align: center;
  cursor: pointer;
  transition: all 0.2s;
  background: #fafafa;
}
.drop-zone:hover, .drop-zone.dragover {
  border-color: var(--brand);
  background: var(--brand-light);
}
.drop-zone input { display: none; }
.drop-zone .dz-icon { margin-bottom: 10px; line-height: 1; }
.drop-zone .dz-main { font-size: 15px; font-weight: 600; color: #374151; margin-bottom: 4px; }
.drop-zone .dz-sub  { font-size: 13px; color: var(--muted); }
.dz-pick-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 10px 16px;
  border-radius: 10px;
  border: 1.5px solid var(--border);
  background: white;
  color: #374151;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
  font-family: inherit;
}
.dz-pick-btn:hover {
  border-color: var(--brand);
  color: var(--brand);
  background: var(--brand-light);
}

/* Image grid */
.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(max(120px, calc((100% - 7 * 12px) / 8)), 1fr));
  gap: 12px;
  margin-top: 16px;
  max-height: 500px;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: thin;
  scrollbar-color: #d1d5db transparent;
  padding-right: 4px;
  border-radius: 8px;
}
.image-grid::-webkit-scrollbar { width: 6px; }
.image-grid::-webkit-scrollbar-thumb { background: #d1d5db; border-radius: 99px; }
.image-grid::-webkit-scrollbar-track { background: transparent; }
.img-thumb {
  border: 2px solid var(--border);
  border-radius: 10px;
  overflow: hidden;
  position: relative;
  background: #f9fafb;
  cursor: default;
}
.img-thumb img {
  width: 100%;
  height: 110px;
  object-fit: cover;
  display: block;
}
.img-thumb .thumb-info { padding: 6px 8px; }
.img-thumb .thumb-name {
  font-size: 11px;
  font-weight: 600;
  color: #374151;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.img-thumb .thumb-status {
  font-size: 10px;
  margin-top: 3px;
  display: flex;
  align-items: center;
  gap: 4px;
}
.img-thumb .remove-thumb {
  position: absolute;
  top: 5px; right: 5px;
  background: rgba(0,0,0,0.55);
  color: white;
  border: none;
  border-radius: 50%;
  width: 22px; height: 22px;
  font-size: 12px;
  cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.img-thumb .remove-thumb:hover { background: rgba(220,38,38,0.85); }
.img-thumb .thumb-progress {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  height: 3px;
  background: #e5e7eb;
}
.img-thumb .thumb-progress-fill {
  height: 100%;
  background: var(--brand);
  transition: width 0.3s;
}
.img-thumb.done      { border-color: var(--green); }
.img-thumb.restored  { border-color: var(--purple); }
.img-thumb.error     { border-color: var(--red); }
.img-thumb.processing { border-color: var(--brand); }

/* Action bar */
.action-bar {
  display: flex;
  gap: 10px;
  margin-top: 18px;
  flex-wrap: wrap;
  justify-content: flex-end;
}
.btn {
  padding: 11px 28px;
  border-radius: 50px;
  border: none;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.2s;
  font-family: inherit;
}
.btn-primary {
  background: linear-gradient(135deg, var(--brand), #5794A5);
  color: white;
  box-shadow: 0 3px 12px rgba(44,105,122,0.3);
}
.btn-primary:hover { transform: translateY(-1px); box-shadow: 0 5px 16px rgba(44,105,122,0.4); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; box-shadow: none; }
.btn-ghost {
  background: #f3f4f6;
  color: #374151;
}
.btn-ghost:hover { background: #e5e7eb; }
.btn-ghost:disabled { opacity: 0.4; cursor: not-allowed; }

/* Small button variant */
.btn-sm {
  padding: 7px 14px;
  font-size: 12px;
  border-radius: 8px;
}

/* Language badge */
.lang-badges {
  display: flex;
  gap: 6px;
  margin-top: 14px;
  flex-wrap: wrap;
}
.lang-badge {
  padding: 5px 12px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 2px solid transparent;
  transition: all 0.15s;
  user-select: none;
}
.lang-badge.selected { border-color: var(--brand); background: var(--brand-light); color: var(--brand); }
.lang-badge:not(.selected) { background: #f3f4f6; color: var(--muted); }

/* Notice */
.notice {
  background: #f0fdf4;
  border: 1px solid #86efac;
  border-radius: 10px;
  padding: 12px 16px;
  font-size: 12px;
  color: #166534;
  margin-top: 14px;
  display: flex;
  gap: 8px;
  align-items: flex-start;
}
.notice-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--green);
  color: white;
  flex-shrink: 0;
}

/* Search bar */
.search-wrap {
  display: flex;
  gap: 10px;
  align-items: center;
}
.search-input {
  flex: 1;
  padding: 13px 18px;
  border: 2px solid var(--border);
  border-radius: 50px;
  font-size: 15px;
  outline: none;
  transition: border-color 0.2s;
  background: white;
  font-family: inherit;
}
.search-input:focus { border-color: var(--brand); }
.search-input:disabled { background: #f9fafb; color: var(--muted); }
.search-btn {
  padding: 13px 28px;
  border-radius: 50px;
  border: none;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  background: linear-gradient(135deg, var(--brand), #5794A5);
  color: white;
  transition: all 0.2s;
}
.search-btn:hover { transform: translateY(-1px); }
.search-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }
.search-stat { font-size: 13px; color: var(--muted); margin-top: 10px; }

/* Tag Filter (in search card) */
#tagFilterArea {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.tag-filter-label {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 8px;
}
.tag-filter-badges {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.tag-filter-chip {
  padding: 4px 11px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background: #f3f4f6;
  color: #374151;
  border: 2px solid transparent;
  transition: all 0.15s;
  user-select: none;
}
.tag-filter-chip:hover { background: #e5e7eb; }
.tag-filter-chip.active {
  background: #ede9fe;
  border-color: var(--purple);
  color: #5b21b6;
}

/* Results */
.result-card {
  background: var(--card);
  border-radius: 14px;
  overflow: hidden;
  box-shadow: 0 2px 8px rgba(0,0,0,0.06);
  margin-bottom: 14px;
  border: 2px solid var(--border);
  transition: border-color 0.2s;
}
.result-card.matched { border-color: var(--brand); }
.result-card.no-match { opacity: 0.5; }

.result-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 18px;
  cursor: pointer;
  user-select: none;
}
.result-header:hover { background: #f9fafb; }
.result-thumb {
  width: 52px;
  height: 40px;
  object-fit: cover;
  border-radius: 6px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}
.result-meta { flex: 1; min-width: 0; }
.result-name {
  font-size: 14px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: flex;
  align-items: center;
  gap: 6px;
}
.result-count {
  font-size: 12px;
  margin-top: 2px;
}
.result-count.found { color: var(--brand); font-weight: 700; }
.result-count.none  { color: var(--muted); }
.result-chevron { color: var(--muted); font-size: 18px; transition: transform 0.2s; flex-shrink: 0; }
.result-card.open .result-chevron { transform: rotate(90deg); }

.result-body {
  display: none;
  padding: 0 18px 16px;
  border-top: 1px solid var(--border);
}
.result-card.open .result-body { display: block; }

.result-body-inner {
  display: flex;
  gap: 14px;
  padding-top: 14px;
}
.result-body-img {
  width: 180px;
  flex-shrink: 0;
}
.result-body-img img {
  width: 100%;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.result-text-area { flex: 1; min-width: 0; }
.result-text-label {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 8px;
}
.result-text {
  font-size: 13px;
  line-height: 1.8;
  color: #374151;
  white-space: pre-wrap;
  word-break: break-all;
  background: #f9fafb;
  padding: 12px;
  border-radius: 8px;
  max-height: 200px;
  overflow-y: auto;
  border: 1px solid var(--border);
}
.result-text mark {
  background: #fde047;
  color: #111;
  border-radius: 2px;
  padding: 0 1px;
}

/* Edit section */
.edit-section {
  margin-top: 14px;
  border-top: 1px dashed var(--border);
  padding-top: 12px;
}
.edit-section-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.edit-textarea {
  width: 100%;
  min-height: 100px;
  padding: 10px 12px;
  border: 2px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  line-height: 1.7;
  color: #374151;
  background: white;
  resize: vertical;
  outline: none;
  transition: border-color 0.2s;
}
.edit-textarea:focus { border-color: var(--brand); }
.edit-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 8px;
  gap: 8px;
}
.edit-hint {
  font-size: 11px;
  color: #9ca3af;
  flex: 1;
}

/* Tag section */
.tag-section {
  margin-top: 14px;
  border-top: 1px dashed var(--border);
  padding-top: 12px;
}
.tag-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 8px;
  min-height: 24px;
}
.no-tags-msg {
  font-size: 12px;
  color: #9ca3af;
}
.tag-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border-radius: 99px;
  font-size: 12px;
  font-weight: 600;
  background: #ede9fe;
  color: #5b21b6;
  border: 1.5px solid #c4b5fd;
}
.tag-chip.small {
  padding: 2px 8px;
  font-size: 11px;
  background: #f3f0ff;
  border-color: #ddd6fe;
}
.tag-chip.editable { padding-right: 6px; }
.tag-remove {
  background: none;
  border: none;
  cursor: pointer;
  color: #7c3aed;
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  padding: 0 1px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 50%;
  width: 16px; height: 16px;
  transition: background 0.1s;
}
.tag-remove:hover { background: #c4b5fd; }
.tag-input-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.tag-input {
  flex: 1;
  padding: 7px 12px;
  border: 1.5px solid var(--border);
  border-radius: 8px;
  font-size: 13px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.2s;
}
.tag-input:focus { border-color: var(--purple); }

/* Reviewed / Unreviewed badges */
.badge-unreviewed {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  background: #fff7ed;
  color: #c2410c;
  border: 1.5px solid #fed7aa;
  white-space: nowrap;
  flex-shrink: 0;
}
.badge-reviewed {
  display: inline-flex;
  align-items: center;
  padding: 2px 8px;
  border-radius: 99px;
  font-size: 11px;
  font-weight: 700;
  background: #f0fdf4;
  color: #166534;
  border: 1.5px solid #bbf7d0;
  white-space: nowrap;
  flex-shrink: 0;
}

/* Progress global */
.global-progress {
  background: var(--card);
  border-radius: 12px;
  padding: 14px 18px;
  margin-bottom: 16px;
  display: none;
  border: 1px solid var(--brand-light);
}
.global-progress .gp-label { font-size: 13px; font-weight: 600; color: var(--brand); margin-bottom: 8px; }
.gp-bar-bg { background: #e5e7eb; border-radius: 99px; height: 6px; overflow: hidden; }
.gp-bar-fill { height: 100%; border-radius: 99px; background: linear-gradient(90deg, var(--brand), #90C2CF); transition: width 0.4s; }

/* File summary bar */
.file-summary {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-top: 14px;
  padding: 10px 14px;
  background: #f9fafb;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 13px;
  color: #374151;
  flex-wrap: wrap;
}
.file-summary .fs-item { display: flex; align-items: center; gap: 5px; }
.fs-badge {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 99px;
  letter-spacing: 0.04em;
}
.fs-badge.ok     { background: #dcfce7; color: #166534; }
.fs-badge.warn   { background: #fef9c3; color: #854d0e; }
.fs-badge.danger { background: #fee2e2; color: #991b1b; }

/* File warnings */
.file-warnings { margin-top: 10px; display: flex; flex-direction: column; gap: 6px; }
.warn-item {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  padding: 9px 13px;
  border-radius: 9px;
  font-size: 12px;
  line-height: 1.6;
}
.warn-item.info   { background: #eff6ff; border: 1px solid #bfdbfe; color: #1e40af; }
.warn-item.warn   { background: #fffbeb; border: 1px solid #fde68a; color: #92400e; }
.warn-item.danger { background: #fff1f2; border: 1px solid #fecdd3; color: #9f1239; }
.warn-item .wi-icon { font-size: 14px; flex-shrink: 0; margin-top: 1px; }

/* Size chip on thumbnails */
.size-chip {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 99px;
  margin-left: 4px;
}
.size-chip.ok     { background: #f3f4f6; color: #6b7280; }
.size-chip.warn   { background: #fef9c3; color: #854d0e; }
.size-chip.danger { background: #fee2e2; color: #991b1b; }
.img-thumb.size-warn   { border-color: #f59e0b !important; }
.img-thumb.size-danger { border-color: #ef4444 !important; }

/* Toggle switch */
.toggle-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  font-size: 13px;
  color: #374151;
  cursor: pointer;
  user-select: none;
}
.toggle-switch {
  position: relative;
  width: 40px;
  height: 22px;
  flex-shrink: 0;
}
.toggle-switch input { display: none; }
.toggle-track {
  position: absolute;
  inset: 0;
  background: #d1d5db;
  border-radius: 99px;
  transition: background 0.2s;
}
.toggle-switch input:checked + .toggle-track { background: var(--brand); }
.toggle-knob {
  position: absolute;
  top: 3px; left: 3px;
  width: 16px; height: 16px;
  background: white;
  border-radius: 50%;
  box-shadow: 0 1px 3px rgba(0,0,0,0.2);
  transition: transform 0.2s;
}
.toggle-switch input:checked ~ .toggle-knob { transform: translateX(18px); }
.toggle-desc { font-size: 11px; color: var(--muted); margin-top: 1px; }

/* Results area — full-width below layout */
#results {
  margin-top: 20px;
}

/* DB management card */
.db-status-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: #374151;
  padding: 8px 10px;
  background: #f9fafb;
  border-radius: 8px;
  border: 1px solid var(--border);
}
.db-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.db-dot.idb { background: #f59e0b; }
.db-dot.fs  { background: var(--green); }

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  right: 24px;
  padding: 10px 18px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 600;
  opacity: 0;
  transform: translateY(8px);
  transition: opacity 0.2s, transform 0.2s;
  z-index: 9999;
  box-shadow: 0 4px 16px rgba(0,0,0,0.2);
  pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.toast-success { background: #065f46; color: white; }
.toast.toast-error   { background: #991b1b; color: white; }

/* No results */
.no-results-msg {
  text-align: center;
  padding: 40px;
  color: var(--muted);
  font-size: 14px;
}

@media (max-width: 600px) {
  .result-body-inner { flex-direction: column; }
  .result-body-img { width: 100%; }
}

/* Footer */
footer {
  text-align: center;
  padding: 20px 32px;
  font-size: 12px;
  color: var(--muted);
  border-top: 1px solid var(--border);
  margin-top: 20px;
}
