﻿
:root {
  --border: #e5e7eb;
  --muted: #6b7280;
  --bg: #f5f7fa;
  --fg: #0f1724;
  --accent: #111111; /* matte black */
}
html, body {
  background: var(--bg);
  color: var(--fg);
  margin: 0;
  font-family: 'Poppins', system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, sans-serif;
  /* Avoid any sideways scrollbars on narrow mobile viewports */
  overflow-x: hidden;
  /* Prevent iOS Safari from auto-zooming text */
  -webkit-text-size-adjust: 100%;
}
.wrapper {
  /* Centered card with gutters; clamp avoids edge-to-edge on phones */
  width: clamp(280px, calc(100% - 48px), 520px);
  max-width: 520px;
  margin: 60px auto;
  background: #fff;
  border: 1px solid var(--border);
  padding: 40px 32px;
  border-radius: 8px;
  box-sizing: border-box;
  /* Slightly stronger layered shadow + outer ring */
  box-shadow:
    0 2px 4px rgba(0,0,0,0.10),
    0 12px 30px rgba(0,0,0,0.12),
    0 0 0 2px rgba(0,0,0,0.12);
}
.logo-wrap { display: flex; justify-content: center; margin-bottom: 16px; }
.logo-img { max-width: 180px; height: auto; opacity: 0.95; }
.tabs { display: flex; justify-content: space-around; margin-bottom: 28px; border-bottom: 1px solid #d1d5db; }
.tabs button { flex: 1; padding: 12px; font-size: 15px; font-weight: 600; background: none; border: none; cursor: pointer; border-bottom: 3px solid transparent; color: #6b7280; transition: all 0.2s ease; }
.tabs button:hover { color: var(--accent); }
.tabs button.active { color: var(--accent); border-bottom-color: var(--accent); }

.tab-pane { display: none; }
.tab-pane.active { display: block; }

.search-box { margin-top: 20px; }
.search-box .search-input-wrap { position: relative; }
.search-box input { width: 100%; max-width: 100%; display: block; box-sizing: border-box; padding: 16px 40px 16px 18px; font-size: 17px; border: 1px solid #d1d5db; border-radius: 6px; outline: none; transition: border-color 0.2s ease; }
.search-box input:focus { border-color: var(--accent); }

.clear-btn { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); border: none; background: #fee2e2; width: 26px; height: 26px; border-radius: 999px; cursor: pointer; line-height: 24px; text-align: center; font-size: 16px; color: #b91c1c; display: none; }
.clear-btn:hover { background: #fecaca; }
.clear-btn:focus-visible { outline: none; box-shadow: 0 0 0 2px #fecaca; }

.btn { margin-top: 12px; width: 100%; padding: 10px; font-size: 14px; font-weight: 600; border: none; border-radius: 4px; cursor: pointer; background: var(--accent); color: #fff; letter-spacing: 0.3px; transition: all 0.2s ease; }
.btn:hover { background: #000; transform: translateY(-1px); box-shadow: 0 2px 8px rgba(0,0,0,0.15); }
.btn:active { transform: translateY(0); }

/* Form styling improvements */
#tab-upload label { font-weight: 500; font-size: 13px; color: #374151; margin-bottom: 2px; display: block; }
#tab-upload form { display: flex; flex-direction: column; gap: 0; }

/* Character counter */
.char-counter { float: right; font-size: 11px; font-weight: 400; color: var(--muted); }
.char-counter.valid { color: #059669; }
.char-counter.invalid { color: #dc2626; }

.note { margin-top: 28px; padding: 16px; font-size: 15px; line-height: 1.6; color: #374151; background: #f9fafb; border: 1px solid var(--border); border-radius: 6px; font-style: italic; }
footer { text-align: center; margin-top: 36px; font-size: 13px; color: var(--muted); font-weight: 500; }

.results { margin-top: 18px; }
.results.grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  align-items: stretch;
}
.result {
  border: 1px solid #e5e7eb;
  padding: 12px;
  border-radius: 8px;
  background: #fff;
  display: flex;
  flex-direction: column;
  box-sizing: border-box;
  min-width: 0; /* prevent grid overflow in narrow columns */
}
.results:not(.grid) .result + .result { margin-top: 12px; }
.result .thumb-wrap {
  margin-top: 6px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #fafafa;
  border: 1px solid var(--border);
  border-radius: 6px;
  width: 100%;
  overflow: hidden;
  min-height: 140px;
}
.result .thumb { width: 100%; height: auto; border-radius: 6px; display: block; object-fit: contain; }
.result .score { color: var(--muted); font-size: 12px; }
.result .meta { color: var(--muted); font-size: 12px; margin-top: 6px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.meta-left { display: flex; align-items: center; gap: 8px; min-width: 0; }
.meta-right { margin-left: auto; white-space: nowrap; }
.meta-right { overflow: hidden; text-overflow: ellipsis; }
.badge { font-size: 11px; background: #111; color: #fff; padding: 2px 6px; border-radius: 999px; text-transform: uppercase; letter-spacing: 0.5px; }
.context-block { margin-top: 6px; font-size: 11px; color: #6b7280; font-style: italic; line-height: 1.35; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; word-break: break-word; }
.actions { display: flex; gap: 8px; margin-top: auto; }
.actions .btn-sm { padding: 8px 10px; font-size: 13px; border-radius: 6px; border: 1px solid var(--border); background: #fff; cursor: pointer; }
.actions .btn-sm.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.muted { color: var(--muted); }

.filters-row { display: flex; justify-content: space-between; align-items: center; margin-top: 10px; flex-wrap: wrap; gap: 12px; }
.filters { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--border); background: #fff; color: #111; padding: 6px 10px; border-radius: 999px; cursor: pointer; font-size: 13px; }
.chip.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Date Filter Dropdown */
.date-filter-dropdown { position: relative; }
.dropdown-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  cursor: pointer;
  font-size: 12px;
  color: #374151;
  transition: all 0.2s ease;
  min-width: 120px;
  justify-content: space-between;
}
.dropdown-btn:hover { border-color: var(--accent); }
.dropdown-arrow {
  font-size: 10px;
  transition: transform 0.2s ease;
  color: #9ca3af;
}
.dropdown-btn.open .dropdown-arrow { transform: rotate(180deg); }
.dropdown-menu {
  position: absolute;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.15);
  z-index: 1000;
  display: none;
  margin-top: 2px;
}
.dropdown-menu.show { display: block; }
.dropdown-menu.floating { z-index: 9999; }
.dropdown-item {
  padding: 8px 12px;
  cursor: pointer;
  font-size: 12px;
  color: #374151;
  transition: background-color 0.2s ease;
}
.dropdown-item:hover { background: #f3f4f6; }
.dropdown-item.active {
  background: var(--accent);
  color: #fff;
}
.dropdown-item.active:hover { background: var(--accent); }

.context-box { width: 100%; box-sizing: border-box; padding: 8px 10px; border: 1px solid #d1d5db; border-radius: 4px; margin: 3px 0 8px; font-family: inherit; height: 36px; max-height: 80px; resize: vertical; transition: border-color 0.2s ease, box-shadow 0.2s ease; font-size: 14px; }
.context-box:focus { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(17, 17, 17, 0.08); outline: none; }

.dropzone { border: 2px dashed #cbd5e1; border-radius: 8px; padding: 8px; text-align: center; color: var(--muted); background: #fafafa; cursor: pointer; min-height: 45px; overflow: hidden; display: flex; flex-direction: column; gap: 0px; align-items: center; justify-content: center; transition: all 0.2s ease; margin-top: 4px; font-size: 12px; }
.dropzone:hover { border-color: #3b82f6; background: #eff6ff; }
.dropzone.drag { background: #eff6ff; border-color: #3b82f6; color: #111; }

.upload-icon { font-size: 20px; color: #cbd5e1; margin-bottom: 1px; }
.upload-text { font-size: 12px; color: #374151; margin-bottom: 0px; font-weight: 600; }
.upload-subtext { font-size: 11px; color: #64748b; }

.spinner { width: 28px; height: 28px; border: 3px solid #ddd; border-top-color: var(--accent); border-radius: 50%; animation: spin 0.8s linear infinite; margin: 12px auto; }
@keyframes spin { to { transform: rotate(360deg); } }

/* Upload previews */
.preview-grid { display: grid; grid-auto-flow: column; grid-auto-columns: 52px; gap: 6px; margin-top: 4px; width: 100%; height: 44px; overflow: hidden; padding-right: 0; justify-content: center; align-content: center; justify-items: center; align-items: center; }
.preview { position: relative; border: 1px solid var(--border); border-radius: 3px; padding: 3px; background: #fff; display: flex; flex-direction: column; align-items: center; justify-content: center; overflow: hidden; box-shadow: 0 1px 2px rgba(0,0,0,0.08); }
.preview img { width: 100%; height: 32px; object-fit: cover; border-radius: 2px; display: block; }
.dropzone .fname, .dropzone .fmeta { display: none; }
.preview .fname { font-size: 12px; color: #374151; margin-top: 6px; text-align: center; word-break: break-word; }
.preview .fmeta { font-size: 11px; color: var(--muted); }

/* Per-file upload overlay */
.preview .overlay { position: absolute; inset: 0; background: rgba(0,0,0,0.35); color: #fff; display: none; align-items: center; justify-content: center; flex-direction: column; padding: 8px; text-align: center; }
.preview.uploading .overlay { display: flex; }
.ov-pct { font-weight: 600; font-size: 12px; }
.ov-bar { width: 100%; height: 6px; background: rgba(255,255,255,0.35); border-radius: 999px; overflow: hidden; margin-top: 8px; }
.ov-fill { height: 100%; width: 0%; background: #22c55e; transition: width 0.1s linear; }
.preview.done .overlay { display: flex; background: rgba(34,197,94,0.25); }
.preview.done .ov-pct { color: #052e16; }

/* Upload progress indicator */
.upload-progress { display: flex; align-items: center; gap: 8px; margin-top: 8px; margin-bottom: 4px; }
.progress-bar { flex: 1; height: 4px; background: #e5e7eb; border-radius: 999px; overflow: hidden; }
.progress-fill { height: 100%; width: 0%; background: var(--accent); transition: width 0.2s ease; border-radius: 999px; }
.progress-text { font-size: 11px; color: var(--muted); font-weight: 500; min-width: 26px; text-align: right; }

/* Legacy progress bar (keep for compatibility) */
.progress { height: 6px; background: #e5e7eb; border-radius: 999px; overflow: hidden; margin-top: 8px; display: none; position: relative; }
.progress .bar { height: 100%; width: 0%; background: #0ea5e9; transition: width 0.1s linear; }

/* Multiple File Upload Styles */
.selected-files { margin-top: 16px; padding: 16px; border: 1px solid var(--border); border-radius: 6px; background: #f9fafb; }
.selected-files h3 { margin: 0 0 12px 0; font-size: 14px; font-weight: 600; color: var(--fg); }

.file-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.file-item { display: flex; align-items: center; gap: 12px; padding: 8px 12px; border: 1px solid #e2e8f0; border-radius: 4px; background: white; }
.file-item .file-icon { font-size: 20px; }
.file-item .file-info { flex: 1; }
.file-item .file-name { font-weight: 500; font-size: 13px; margin-bottom: 2px; }
.file-item .file-meta { font-size: 11px; color: var(--muted); }
.file-item .file-remove { background: none; border: none; color: #dc2626; cursor: pointer; font-size: 16px; padding: 4px; }
.file-item .file-remove:hover { background: #fee2e2; border-radius: 2px; }

.btn-link { background: none; border: none; color: #6366f1; cursor: pointer; font-size: 12px; text-decoration: underline; }
.btn-link:hover { color: #4f46e5; }

.context-section { margin-top: 16px; }
.context-section h4 { margin: 16px 0 8px 0; font-size: 14px; font-weight: 600; }

.individual-toggle { margin: 16px 0; }
.toggle-label { display: flex; align-items: center; gap: 8px; cursor: pointer; font-size: 14px; }
.toggle-label input[type="checkbox"] { margin: 0; }
.toggle-text { color: #374151; }

.individual-contexts { margin-top: 12px; padding: 12px; border: 1px solid #e2e8f0; border-radius: 4px; background: #f8fafc; }

.individual-context-tip { background: #eff6ff; border: 1px solid #bfdbfe; border-radius: 4px; padding: 12px; margin-bottom: 16px; font-size: 13px; color: #1e40af; }
.individual-context-tip strong { color: #1d4ed8; }

.individual-context-item { margin-bottom: 16px; padding: 12px; border: 1px solid #e5e7eb; border-radius: 4px; background: white; }
.individual-context-item:last-child { margin-bottom: 0; }

.individual-file-header { display: flex; align-items: center; gap: 12px; margin-bottom: 8px; }
.individual-thumbnail-container { flex-shrink: 0; width: 48px; height: 48px; border-radius: 4px; overflow: hidden; background: #f3f4f6; display: flex; align-items: center; justify-content: center; }
.individual-thumbnail { width: 100%; height: 100%; object-fit: cover; opacity: 0; transition: opacity 0.2s ease; }
.individual-file-icon { font-size: 24px; }
.individual-file-info { flex: 1; min-width: 0; }
.individual-file-name { font-weight: 500; font-size: 13px; color: var(--fg); margin-bottom: 2px; word-break: break-word; }
.individual-file-meta { font-size: 11px; color: var(--muted); }

.copy-context-btn { background: #f3f4f6; border: 1px solid #d1d5db; border-radius: 4px; padding: 4px 8px; font-size: 11px; color: #374151; cursor: pointer; transition: all 0.2s ease; }
.copy-context-btn:hover { background: #e5e7eb; border-color: #9ca3af; }

.context-field-container { position: relative; }
.individual-context-textarea { margin-bottom: 4px !important; }
.individual-context-counter { display: flex; justify-content: between; align-items: center; gap: 8px; margin-bottom: 8px; }
.individual-context-counter .char-count { font-size: 11px; font-weight: 500; }
.individual-context-counter .context-status { font-size: 11px; flex: 1; }

.individual-context-item .context-box { margin-bottom: 8px; }

/* Viewer modal */
.modal { position: fixed; inset: 0; background: rgba(0,0,0,0.8); display: none; align-items: center; justify-content: center; z-index: 5000; padding: 20px; box-sizing: border-box; }
.modal .panel { background: #fff; border-radius: 6px; max-width: 95vw; max-height: 95vh; box-shadow: 0 10px 30px rgba(0,0,0,0.3); display: flex; flex-direction: column; overflow: hidden; }
.modal .head { display: flex; justify-content: space-between; align-items: center; padding: 8px 12px; border-bottom: 1px solid var(--border); flex-shrink: 0; }
.modal .head .title { font-weight: 600; font-size: 14px; }
.modal .head .close { border: none; background: none; font-size: 18px; cursor: pointer; padding: 4px; }
.modal .body { padding: 0; overflow: hidden; display: flex; align-items: center; justify-content: center; flex: 1; min-height: 0; }

/* Content-specific viewer styles */
.viewer { width: 100%; height: 100%; border: none; display: block; }
.viewer-img { max-width: 100%; max-height: 100%; width: auto; height: auto; display: block; object-fit: contain; }
.viewer-aud, .viewer-vid { width: 100%; height: auto; max-height: 100%; min-height: 56px; display: block; }

/* PDF and iframe viewer */
iframe.viewer { width: 100%; height: 100%; border: none; }

/* Mobile optimizations */
@media (max-width: 900px) { .results.grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 580px) {
  .results.grid { grid-template-columns: 1fr; }
  /* Ensure side gutters on small screens and comfortable spacing */
  .wrapper { margin: 24px auto; padding: 20px 16px; width: clamp(280px, calc(100% - 48px), 520px); max-width: 520px; box-sizing: border-box; }
  /* Guard against horizontal overflow by any child */
  .tabs, .filters-row, .filters, .date-filter-dropdown, .search-box, .note { max-width: 100%; overflow-x: hidden; }
  /* Avoid iOS zoom-on-focus by keeping form controls >= 16px */
  input, textarea, select { font-size: 16px !important; }
  .context-box { height: 32px; padding: 6px 8px; font-size: 16px; }
  .upload-input { font-size: 16px; }
  /* Respect iOS safe areas while keeping visual gutters */
  @supports(padding: max(0px)) {
    .wrapper { padding-left: max(16px, env(safe-area-inset-left)); padding-right: max(16px, env(safe-area-inset-right)); }
  }
  .context-box { height: 32px; padding: 6px 8px; font-size: 13px; }
  .dropzone { min-height: 40px; padding: 6px; font-size: 11px; }
  .upload-icon { font-size: 18px; margin-bottom: 1px; }
  .upload-text { font-size: 11px; }
  .upload-subtext { font-size: 10px; }
  .btn { padding: 8px; font-size: 13px; }
  #tab-upload label { font-size: 12px; margin-bottom: 1px; }
  .preview-grid { grid-auto-columns: 48px; height: 40px; gap: 4px; }
  .preview img { height: 28px; }
  .upload-progress { margin-top: 6px; margin-bottom: 3px; gap: 6px; }
  .progress-text { font-size: 10px; min-width: 24px; }
  .char-counter { font-size: 10px; }

  /* Mobile filter adjustments */
  .filters-row { flex-direction: column; align-items: stretch; gap: 8px; }
  .filters { justify-content: center; }
  .date-filter-dropdown { align-self: stretch; }
  .dropdown-btn { width: 100%; }

  /* Mobile PDF viewer adjustments */
  .modal .panel { max-width: 98vw; max-height: 98vh; }
}

.progress.done .bar { background: #22c55e; }
.progress-label { position: absolute; right: 8px; top: -20px; font-size: 12px; color: var(--muted); }
.modal #dup-body { overflow: hidden; }
.modal #dup-cands { overflow: hidden; }
