/* ===================================================================
   Images Extractor - panel UI (light)
   Brand: forest · lime · leaf
   =================================================================== */
:root {
  /* Brand */
  --forest: #2e5e2e;
  --lime: #70a030;
  --leaf: #9fc15b;
  --brand-gradient: linear-gradient(
    135deg,
    #2e5e2e 0%,
    #5c8c28 55%,
    #70a030 100%
  );
  --brand-solid: #2e5e2e;
  --brand-solid-hover: #214521;
  --brand-accent: #2f6a2a; /* readable green for small text accents */
  --brand-soft: rgba(112, 160, 48, 0.16);

  /* Neutrals - a grounded sage light theme */
  --bg: #e7eed9;
  --surface: #ffffff;
  --surface-2: #f2f6e8;
  --line: #d6e0c8;
  --ink: #1b271f;
  --ink-soft: #3b4a40;
  --muted: #5f6f5d;
  --faint: #647268; /* WCAG AA against both the card and toolbar backgrounds */

  /* Status */
  --danger: #b34a3e;
  --danger-soft: #f7e6e3;

  --shadow-sm:
    0 1px 2px rgba(28, 40, 30, 0.06), 0 4px 12px rgba(28, 40, 30, 0.07);
  --shadow-md: 0 14px 28px rgba(46, 94, 46, 0.16);
  --shadow-brand: 0 8px 22px rgba(46, 94, 46, 0.28);
  --radius: 14px;
  --radius-sm: 10px;
}

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

html,
body {
  background: var(--bg);
}

body {
  font-family:
    -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Oxygen, Ubuntu,
    Cantarell, sans-serif;
  /* min-width is what Chrome sizes the popup from; width:100% makes the layout
     fill the viewport if Chrome ever hands us a wider one. With a fixed width
     the surplus showed html's background as dead space down the right side. */
  min-width: 600px;
  width: 100%;
  /* Chrome caps a popup at 600px tall. Capping the document to the same height
     and making it a flex column means the document itself never scrolls, so the
     header and toolbar always stay put and only the results list scrolls. */
  max-height: 600px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  /* min-height:0 lets the app shrink inside the capped body instead of
     overflowing it; without it a flex item refuses to go below its content. */
  min-height: 0;
  background: var(--bg);
  overflow: hidden;
}

/* ===== Header ===== */
.app-header {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 16px 18px;
  background: var(--brand-gradient);
  color: #fff;
  overflow: hidden;
  /* Never let a long results list squeeze the chrome - as a flex item this
     would otherwise shrink, and the header visibly lost height as images grew. */
  flex-shrink: 0;
}

.app-header::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(
    120% 140% at 0% 0%,
    rgba(255, 255, 255, 0.18) 0%,
    transparent 45%
  );
  pointer-events: none;
}

.brand {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  min-width: 0;
}

.brand-logo {
  width: 34px;
  height: 34px;
  border-radius: 9px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.22);
  flex-shrink: 0;
}

.brand-text h1 {
  font-size: 16px;
  font-weight: 700;
  letter-spacing: -0.01em;
  line-height: 1.2;
}

.subtitle {
  font-size: 12px;
  opacity: 0.9;
  font-weight: 500;
}

.icon-btn {
  position: relative;
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border: 1px solid rgba(255, 255, 255, 0.35);
  background: rgba(255, 255, 255, 0.16);
  color: #fff;
  border-radius: 11px;
  cursor: pointer;
  display: grid;
  place-items: center;
  transition:
    background 0.18s ease,
    transform 0.18s ease;
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.28);
}

.icon-btn:active .icon-btn__glyph {
  transform: rotate(180deg);
}

.icon-btn__glyph {
  font-size: 19px;
  line-height: 1;
  transition: transform 0.4s ease;
}

.icon-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 2px;
}

/* ===== Toolbar ===== */
.toolbar {
  z-index: 5;
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 11px 18px;
  background: rgba(244, 248, 236, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
}

.count {
  font-size: 12.5px;
  font-weight: 700;
  color: var(--brand-accent);
  background: var(--brand-soft);
  border: 1px solid rgba(112, 160, 48, 0.3);
  padding: 5px 12px;
  border-radius: 999px;
}

.hint {
  font-size: 12px;
  color: var(--faint);
  font-weight: 500;
}

/* ===== Loading skeleton ===== */
.loading {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px;
}

.skeleton-grid {
  display: grid;
  /* mirror the results grid so the layout doesn't jump when cards replace it */
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  gap: 14px;
  width: 100%;
}

.skel {
  aspect-ratio: 1;
  border-radius: var(--radius);
  background: linear-gradient(100deg, #dde6cf 30%, #eef3e3 50%, #dde6cf 70%);
  background-size: 220% 100%;
  animation: shimmer 1.3s ease-in-out infinite;
}

@keyframes shimmer {
  to {
    background-position: -220% 0;
  }
}

.loading-text {
  margin-top: 16px;
  color: var(--muted);
  font-size: 13.5px;
  font-weight: 500;
}

/* ===== Status (error / empty) ===== */
.status {
  display: flex;
  flex-direction: column;
  align-items: center;
  text-align: center;
  gap: 12px;
  padding: 52px 24px;
  color: var(--muted);
  font-size: 14px;
  font-weight: 500;
}

.status__icon {
  width: 56px;
  height: 56px;
  /* popup.js reveals these panels with display:block, which drops the parent's
     flex centring - so centre the badge on its own. */
  margin: 10px auto;
  border-radius: 16px;
  display: grid;
  place-items: center;
  font-size: 24px;
  font-weight: 800;
}

/* The empty state uses an SVG; the error state is still a text glyph */
.status__icon svg {
  width: 27px;
  height: 27px;
  display: block;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.status--empty .status__icon {
  color: var(--brand-accent);
  background: var(--brand-soft);
}

.status--error {
  color: var(--danger);
}

.status--error .status__icon {
  background: var(--danger-soft);
  color: var(--danger);
}

/* ===== Results ===== */
/* The scroll container and the grid are deliberately separate elements. Making
   the grid itself the scroller gives it a definite height, and a grid with a
   definite height cannot resolve the cards' aspect-ratio into an intrinsic row
   height - it sized every row to 145px and squashed the previews. Kept apart,
   the wrapper is the only thing that scrolls and the grid stays auto-height. */
.images-scroll {
  /* grow: 0 so a short list doesn't leave dead space; shrink: 1 + min-height: 0
     so a long one shrinks to the space left by the header and toolbar and
     scrolls inside it, instead of making the document scroll. */
  flex: 0 1 auto;
  min-height: 0;
  overflow-y: auto;
  /* Reserve the scrollbar's width on BOTH edges. Without this it eats 10px from
     the right only, leaving the grid visibly off-centre and shifting it the
     moment the list starts to overflow. */
  scrollbar-gutter: stable both-edges;
}

.images-list {
  display: grid;
  /* auto-fill keeps 3 columns at the 600px default and adds a column instead of
     stretching if the popup viewport is ever wider */
  grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
  align-content: start;
  gap: 14px;
  padding: 16px 6px;
}

/* ===== Card ===== */
.image-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow-sm);
  display: flex;
  flex-direction: column;
  position: relative;
  transition:
    transform 0.25s cubic-bezier(0.4, 0, 0.2, 1),
    box-shadow 0.25s ease,
    border-color 0.25s ease;
  animation: fadeInUp 0.4s ease-out both;
}

@keyframes fadeInUp {
  from {
    opacity: 0;
    transform: translateY(10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.image-card:nth-child(1) {
  animation-delay: 0.03s;
}
.image-card:nth-child(2) {
  animation-delay: 0.06s;
}
.image-card:nth-child(3) {
  animation-delay: 0.09s;
}
.image-card:nth-child(4) {
  animation-delay: 0.12s;
}
.image-card:nth-child(5) {
  animation-delay: 0.15s;
}
.image-card:nth-child(n + 6) {
  animation-delay: 0.18s;
}

.image-card:hover {
  transform: translateY(-4px);
  box-shadow: var(--shadow-md);
  border-color: rgba(112, 160, 48, 0.5);
}

/* ===== Preview ===== */
.image-preview-container {
  position: relative;
  width: 100%;
  aspect-ratio: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: linear-gradient(135deg, #f3f7ea 0%, #e4ecd6 100%);
}

.image-preview {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  cursor: pointer;
  transition: transform 0.3s ease;
}

.image-card:hover .image-preview {
  transform: scale(1.05);
}

.image-error {
  color: var(--faint);
  font-size: 12.5px;
  font-weight: 500;
}

/* Favicon (site icon) cards */
.image-preview-container.is-favicon {
  background:
    radial-gradient(
      circle at 50% 42%,
      rgba(112, 160, 48, 0.18) 0%,
      transparent 60%
    ),
    linear-gradient(135deg, #f3f7ea 0%, #e4ecd6 100%);
}

.image-preview-container.is-favicon .image-preview {
  width: 54px;
  height: 54px;
  object-fit: contain;
  image-rendering: -webkit-optimize-contrast;
  filter: drop-shadow(0 6px 12px rgba(28, 40, 30, 0.2));
}

.fav-badge {
  position: absolute;
  top: 8px;
  left: 8px;
  z-index: 6;
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: #fff;
  background: var(--brand-gradient);
  padding: 3px 9px;
  border-radius: 999px;
  box-shadow: 0 3px 9px rgba(46, 94, 46, 0.4);
}

/* Hover action bar */
.card-actions {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 5px;
  padding: 7px;
  background: linear-gradient(
    to top,
    rgba(20, 32, 26, 0.8) 0%,
    rgba(20, 32, 26, 0) 100%
  );
  opacity: 0;
  transform: translateY(6px);
  transition:
    opacity 0.22s ease,
    transform 0.22s ease;
  pointer-events: none;
}

.image-card:hover .card-actions {
  opacity: 1;
  transform: translateY(0);
  pointer-events: auto;
}

.action-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  height: 28px;
  color: var(--brand-solid);
  background: rgba(255, 255, 255, 0.95);
  border: none;
  border-radius: 8px;
  padding: 0;
  cursor: pointer;
  text-decoration: none;
  transition:
    background 0.15s ease,
    color 0.15s ease,
    transform 0.12s ease;
}

.action-btn svg {
  width: 15px;
  height: 15px;
  display: block;
}

.action-btn:hover {
  background: #fff;
  color: var(--brand-solid-hover);
}

.action-btn:active {
  transform: scale(0.92);
}

.action-btn:focus-visible {
  outline: 2px solid #fff;
  outline-offset: 1px;
}

/* Busy while an image is being fetched, encoded, or handed to the downloader */
.action-btn.is-busy {
  cursor: progress;
}

.action-btn.is-busy svg {
  animation: btnPulse 0.9s ease-in-out infinite;
}

@keyframes btnPulse {
  50% {
    opacity: 0.35;
  }
}

/* ===== Copy feedback ===== */
.copy-feedback {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  background: rgba(46, 94, 46, 0.96);
  color: #fff;
  padding: 9px 16px;
  border-radius: var(--radius-sm);
  font-size: 12.5px;
  font-weight: 700;
  z-index: 10;
  pointer-events: none;
  max-width: calc(100% - 16px);
  text-align: center;
  text-wrap: balance;
  box-shadow: 0 8px 22px rgba(28, 40, 30, 0.3);
  backdrop-filter: blur(4px);
}

.copy-feedback.error {
  background: rgba(179, 74, 62, 0.96);
}

/* ===== Card info ===== */
.image-info {
  padding: 9px 11px 11px;
  display: flex;
  flex-direction: column;
  gap: 7px;
  min-width: 0;
}

.image-details {
  display: flex;
  align-items: center;
  gap: 8px;
}

.image-index {
  font-size: 11px;
  font-weight: 800;
  color: var(--brand-accent);
  background: var(--brand-soft);
  padding: 2px 8px;
  border-radius: 999px;
}

.image-dimensions {
  font-size: 11px;
  color: var(--faint);
  font-weight: 600;
}

.image-link {
  color: var(--muted);
  text-decoration: none;
  font-size: 11px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
  line-height: 1.4;
  font-family: "Monaco", "Menlo", "Courier New", monospace;
  transition: color 0.18s ease;
}

.image-link:hover {
  color: var(--brand-accent);
  text-decoration: underline;
}

/* ===== Scrollbar ===== */
.images-scroll::-webkit-scrollbar {
  width: 10px;
}

.images-scroll::-webkit-scrollbar-track {
  background: transparent;
}

/* A 3px inset on a 10px bar left only 4px of visible thumb, which read as
   dead space rather than a control. 2px keeps the inset look but stays legible. */
.images-scroll::-webkit-scrollbar-thumb {
  background: #b3c49a;
  border-radius: 999px;
  border: 2px solid var(--bg);
}

.images-scroll::-webkit-scrollbar-thumb:hover {
  background: #9fb283;
}
