:root {
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --danger: #ef4444;
  --danger-dark: #b91c1c;
  --warning: #f59e0b;
  --warning-dark: #b45309;
  --success: #10b981;
  --success-dark: #047857;
  --unknown: #64748b;
  --unknown-dark: #334155;
  --bg: #f8fafc;
  --card: #ffffff;
  --text: #1e293b;
  --muted: #64748b;
  --border: #e2e8f0;
  --soft: #f1f5f9;
  --shadow: 0 20px 25px -5px rgba(0,0,0,0.1);
}

* { box-sizing: border-box; }

body {
  font-family: Inter, system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  margin: 0;
  padding: 15px;
  color: var(--text);
}

.container {
  max-width: 720px;
  margin: auto;
  background: var(--card);
  padding: 25px;
  border-radius: 32px;
  box-shadow: var(--shadow);
  position: relative;
}

.narrow { max-width: 500px; }
.wide { max-width: 980px; }

.header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
  border-bottom: 1px solid var(--border);
  padding-bottom: 15px;
  gap: 12px;
}

.header h1,
.header h3 {
  margin: 0;
  font-size: 22px;
  letter-spacing: -0.02em;
}

.nav {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-bottom: 18px;
}

.nav a {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 36px;
  padding: 8px 11px;
  border-radius: 999px;
  background: var(--soft);
  color: var(--text);
  text-decoration: none;
  font-weight: 800;
  font-size: 13px;
}

.nav a.active {
  background: #dbeafe;
  color: var(--primary-dark);
}

select, input, textarea {
  width: 100%;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  border-radius: 14px;
  padding: 12px;
  font-size: 14px;
  outline: none;
}

textarea {
  min-height: 180px;
  resize: vertical;
  line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, 'Liberation Mono', monospace;
  font-size: 12px;
}

select:focus, input:focus, textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(37,99,235,0.12);
}

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: 22px;
  padding: 18px;
  margin-top: 16px;
}

.card h2, .card h3, .card h4 {
  margin-top: 0;
}

.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}

.field { display: grid; gap: 6px; margin-bottom: 12px; }
.field label { font-weight: 800; color: #475569; font-size: 13px; }
.field small { color: var(--muted); line-height: 1.45; }

button, .button, .link-button {
  padding: 14px 16px;
  border-radius: 16px;
  border: none;
  font-weight: 800;
  cursor: pointer;
  transition: 0.2s;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  font-size: 14px;
  color: var(--text);
  min-height: 48px;
}

button:active, .button:active, .link-button:active { transform: translateY(1px) scale(0.99); }
button:disabled { opacity: 0.55; cursor: not-allowed; }

.btn-primary { background: var(--primary); color: white; }
.btn-dark { background: #1e293b; color: white; }
.btn-soft { background: var(--soft); color: var(--text); }
.btn-danger { background: #fee2e2; color: var(--danger-dark); }
.btn-warning { background: #fef3c7; color: var(--warning-dark); }
.btn-success { background: #dcfce7; color: var(--success-dark); }
.full { width: 100%; }

.preview-wrapper {
  position: relative;
  width: 100%;
  border-radius: 24px;
  overflow: hidden;
  background: #0f172a;
  aspect-ratio: 1/1;
  margin-bottom: 20px;
  display: flex;
  align-items: center;
  justify-content: center;
}

video, #file-preview { width: 100%; height: 100%; object-fit: cover; }
#file-preview { display: none; }

.preview-wrapper.has-result::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 6;
  background: rgba(255,255,255,0.58);
  backdrop-filter: blur(1.5px) saturate(0.95);
  pointer-events: none;
}

.empty-preview {
  color: #cbd5e1;
  text-align: center;
  padding: 22px;
  line-height: 1.6;
}
.empty-preview strong { color: #fff; }

.loading-overlay {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  background: rgba(255,255,255,0.9);
  display: none;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  z-index: 10;
  backdrop-filter: blur(4px);
  text-align: center;
  padding: 22px;
}

.spinner {
  width: 48px; height: 48px;
  border: 4px solid #e2e8f0;
  border-top: 4px solid var(--primary);
  border-radius: 50%;
  animation: spin 1s infinite linear;
}
@keyframes spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg); } }

.controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
.controls .main-action { grid-column: span 2; }

.scan-line {
  position: absolute;
  width: 100%; height: 2px;
  background: var(--primary);
  top: 0;
  z-index: 5;
  display: none;
  animation: scan 2s linear infinite;
  box-shadow: 0 0 15px var(--primary);
}
@keyframes scan { 0% { top: 0; } 100% { top: 100%; } }
.preview-result-overlay {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 14px;
  z-index: 8;
  display: none;
  border-radius: 22px;
  padding: 16px 16px 16px 18px;
  color: #0f172a;
  background: rgba(255,255,255,0.90);
  backdrop-filter: blur(12px);
  box-shadow: 0 16px 40px rgba(15,23,42,0.22);
  text-align: left;
  border: 1px solid rgba(255,255,255,0.74);
  border-left: 8px solid var(--unknown);
}
.preview-result-overlay.show { display: block; }
.preview-result-overlay h2 {
  margin: 0 0 8px;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: -0.02em;
}
.preview-result-overlay p {
  margin: 5px 0;
  font-size: 14px;
  line-height: 1.5;
}
.preview-result-overlay .overlay-product {
  font-weight: 900;
  font-size: 15px;
}
.preview-result-overlay .overlay-reason {
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.preview-result-overlay .overlay-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}
.preview-result-overlay .overlay-tag {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 6px 10px;
  font-size: 12px;
  font-weight: 900;
  background: #f1f5f9;
  color: #0f172a;
  border: 1px solid #e2e8f0;
}
.preview-result-overlay .overlay-progress {
  margin-top: 10px;
  color: #475569;
  font-size: 12px;
  font-weight: 800;
}
.preview-result-overlay.overlay-danger { border-left-color: var(--danger); }
.preview-result-overlay.overlay-danger h2 { color: var(--danger-dark); }
.preview-result-overlay.overlay-warning { border-left-color: var(--warning); }
.preview-result-overlay.overlay-warning h2 { color: var(--warning-dark); }
.preview-result-overlay.overlay-safe { border-left-color: var(--success); }
.preview-result-overlay.overlay-safe h2 { color: var(--success-dark); }
.preview-result-overlay.overlay-unknown { border-left-color: var(--unknown); }
.preview-result-overlay.overlay-unknown h2 { color: var(--unknown-dark); }


.alert-box {
  padding: 24px;
  border-radius: 24px;
  margin-top: 20px;
  border-top: 8px solid #ccc;
  text-align: center;
}
.alert-critical { background: #fef2f2; border-color: var(--danger); color: var(--danger-dark); }
.alert-warning { background: #fffbeb; border-color: var(--warning); color: var(--warning-dark); }
.alert-safe { background: #f0fdf4; border-color: var(--success); color: var(--success-dark); }
.alert-unknown { background: #f8fafc; border-color: var(--unknown); color: var(--unknown-dark); }

.tag {
  display: inline-block;
  padding: 5px 9px;
  border-radius: 999px;
  margin: 3px;
  background: rgba(0,0,0,0.06);
  font-size: 12px;
  font-weight: 800;
}
.tag-danger { background: #fee2e2; color: var(--danger-dark); }
.tag-warning { background: #fef3c7; color: var(--warning-dark); }
.tag-success { background: #dcfce7; color: var(--success-dark); }

.notice {
  margin-top: 14px;
  padding: 14px;
  border-radius: 18px;
  background: #eff6ff;
  border: 1px solid #bfdbfe;
  color: #1e40af;
  font-size: 13px;
  line-height: 1.55;
  text-align: left;
}
.warning-notice { background: #fffbeb; border-color: #fde68a; color: #92400e; }
.danger-notice { background: #fef2f2; border-color: #fecaca; color: #991b1b; }

.mono-box {
  white-space: pre-wrap;
  word-break: break-word;
  background: #f8fafc;
  padding: 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  color: #334155;
  font-size: 12px;
  line-height: 1.6;
  max-height: 320px;
  overflow: auto;
}

.pill-row { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.pill {
  border: 1px solid var(--border);
  background: #fff;
  border-radius: 999px;
  padding: 8px 10px;
  cursor: pointer;
  font-size: 12px;
  font-weight: 800;
  user-select: none;
}
.pill.active { background: #dbeafe; border-color: #93c5fd; color: #1d4ed8; }

.recommendations { margin-top: 16px; display: grid; gap: 12px; }
.recommendation-card { border: 1px solid var(--border); border-radius: 20px; padding: 14px; background: #fff; }
.recommendation-card h4 { margin: 0 0 10px; font-size: 15px; }
.recommendation-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-top: 10px; }
.amazon-link { background: #ffedd5; color: #9a3412; }
.rakuten-link { background: #fee2e2; color: #991b1b; }
.custom-link { background: #e0e7ff; color: #3730a3; }

.article-list { display: grid; gap: 12px; }
.article-item { border: 1px solid var(--border); border-radius: 18px; padding: 14px; background: #fff; }
.article-item h3 { margin: 0 0 8px; }
.article-item a { color: var(--primary-dark); text-decoration: none; }
.article-body { line-height: 1.85; }
.article-body h1, .article-body h2, .article-body h3 { line-height: 1.35; }

.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { border-bottom: 1px solid var(--border); padding: 10px; text-align: left; vertical-align: top; }
th { color: #475569; background: #f8fafc; }

.admin-layout { display: grid; grid-template-columns: 220px 1fr; gap: 16px; }
.admin-sidebar { position: sticky; top: 12px; align-self: start; }
.admin-main { min-width: 0; }

.footer {
  margin-top: 22px;
  padding-top: 16px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.6;
  text-align: center;
}
.footer a { color: var(--muted); }

@media (max-width: 760px) {
  body { padding: 10px; }
  .container { padding: 18px; border-radius: 26px; }
  .header { align-items: flex-start; flex-direction: column; }
  .grid-2, .grid-3, .recommendation-actions, .admin-layout { grid-template-columns: 1fr; }
  .admin-sidebar { position: static; }
}

.product-card {
  display: grid;
  grid-template-columns: 132px 1fr;
  gap: 14px;
  align-items: start;
}

.product-image-wrap {
  width: 132px;
}

.product-photo {
  width: 132px;
  height: 132px;
  border-radius: 18px;
  object-fit: contain;
  background: #f8fafc;
  border: 1px solid var(--border);
  display: block;
}

.product-photo.placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px;
  text-align: center;
  font-size: 12px;
  color: var(--muted);
}

.product-photo.placeholder a {
  color: var(--primary);
  font-weight: 800;
  text-decoration: none;
}

.product-image-wrap small {
  display: block;
  margin-top: 6px;
  color: var(--muted);
  font-size: 11px;
  text-align: center;
}

.product-detail p {
  margin: 8px 0;
  line-height: 1.55;
}

@media (max-width: 560px) {
  .product-card {
    grid-template-columns: 1fr;
  }
  .product-image-wrap,
  .product-photo {
    width: 100%;
  }
  .product-photo {
    height: 220px;
  }
}

.product-photo-link {
  display: block;
  position: relative;
  text-decoration: none;
  color: inherit;
}

.product-photo-link .photo-fallback-label {
  position: absolute;
  left: 8px;
  right: 8px;
  bottom: 8px;
  padding: 6px 8px;
  border-radius: 999px;
  background: rgba(15, 23, 42, 0.78);
  color: #fff;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
}

.product-photo-link.photo-error {
  width: 132px;
  height: 132px;
  border-radius: 18px;
  background: #f8fafc;
  border: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-photo-link.photo-error .photo-fallback-label {
  position: static;
  background: transparent;
  color: var(--primary);
}

@media (max-width: 560px) {
  .product-photo-link.photo-error {
    width: 100%;
    height: 220px;
  }
}


.admax-slot {
  margin: 24px 0;
  text-align: center;
  width: 100%;
}

.admax-slot:empty {
  display: none;
}




.footer .footer-admax {
  display: block;
  clear: both;
  margin: 16px auto 0;
  padding: 0;
  width: 100%;
  max-width: 100%;
  text-align: center;
  overflow: hidden;
  position: relative;
  z-index: 1;
}

.footer .footer-admax:empty {
  display: none;
}

.footer .footer-admax > * {
  max-width: 100% !important;
}


/* AdMax top-safe display
   AdMax may render only at the top on some mobile browsers. In that case,
   reserve a dedicated top banner area so the site title is never covered. */
.top-admax-shell {
  width: calc(100% + 30px);
  min-height: 58px;
  max-height: 112px;
  margin: -15px -15px 16px;
  padding: 4px 0;
  background: #fff;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  text-align: center;
  position: relative;
  z-index: 1;
}

.top-admax-shell:empty {
  display: none;
}

.top-admax-shell > *,
.top-admax-shell img,
.top-admax-shell object,
.top-admax-shell embed {
  max-width: 100% !important;
}

.container {
  z-index: 2;
}

.header h1,
.header h3 {
  display: block !important;
  visibility: visible !important;
  opacity: 1 !important;
  min-height: 1.2em;
}

body.admax-top-overlap-fixed .container {
  transition: margin-top 0.15s ease;
}

@media (max-width: 560px) {
  .top-admax-shell {
    min-height: 54px;
    max-height: 104px;
    margin-bottom: 14px;
  }

  .container {
    margin-top: 0;
  }
}
