:root {
  color-scheme: light;
  --bg: #f5f6f3;
  --surface: #ffffff;
  --surface-subtle: #eef1ec;
  --text: #20231f;
  --muted: #666d63;
  --line: #d7ddd4;
  --green: #1f7456;
  --green-dark: #155840;
  --blue: #27658a;
  --danger: #b3261e;
  --shadow: 0 10px 24px rgba(28, 38, 31, 0.08);
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  min-width: 320px;
  font-family: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  color: var(--text);
  background: var(--bg);
}

button,
input {
  font: inherit;
}

button,
.download-link {
  min-height: 40px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: var(--surface);
}

button {
  padding: 0 16px;
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.primary-button,
.download-link {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  border-color: var(--green);
  color: #fff;
  background: var(--green);
  font-weight: 700;
}

.primary-button:not(:disabled):hover,
.download-link:hover {
  background: var(--green-dark);
}

.app-shell {
  display: flex;
  min-height: 100vh;
  flex-direction: column;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(260px, 360px) minmax(360px, 1fr);
  gap: 24px;
  padding: 28px 32px 20px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.title-block h1 {
  margin: 0;
  font-size: 22px;
  line-height: 1.2;
  letter-spacing: 0;
}

.product-heading {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}

.product-heading span {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.title-block p {
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.url-form {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 96px;
  gap: 10px;
  align-items: center;
}

#urlInput {
  width: 100%;
  height: 44px;
  min-width: 0;
  padding: 0 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--text);
  background: #fbfcfa;
}

#urlInput:focus {
  outline: 2px solid rgba(31, 116, 86, 0.22);
  border-color: var(--green);
}

.summary-row {
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 14px 32px;
  border-bottom: 1px solid var(--line);
  background: var(--surface-subtle);
}

.metric-group {
  display: flex;
  align-items: baseline;
  gap: 5px;
}

.metric {
  font-size: 22px;
}

.metric-label {
  color: var(--muted);
  font-size: 13px;
}

#selectAllButton {
  margin-left: auto;
}

#downloadButton {
  min-width: 128px;
}

.content-grid {
  display: grid;
  flex: 1;
  grid-template-columns: minmax(0, 1fr) 320px;
  min-height: 0;
}

.media-panel {
  position: relative;
  padding: 24px 28px 40px;
}

.empty-state {
  display: grid;
  min-height: 420px;
  place-items: center;
  align-content: center;
  gap: 12px;
  color: var(--muted);
}

.empty-state p {
  margin: 0;
}

.empty-icon {
  display: grid;
  width: 64px;
  height: 64px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  color: var(--blue);
  background: var(--surface);
  font-size: 34px;
}

.media-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 16px;
}

.media-card {
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.thumb-wrap {
  position: relative;
  aspect-ratio: 9 / 16;
  background: #151515;
}

.thumb-wrap img,
.thumb-wrap video {
  display: block;
  width: 100%;
  height: 100%;
  object-fit: contain;
}

.type-badge {
  position: absolute;
  top: 10px;
  left: 10px;
  padding: 4px 8px;
  border-radius: 6px;
  color: #fff;
  background: rgba(0, 0, 0, 0.72);
  font-size: 12px;
  font-weight: 700;
}

.card-body {
  display: grid;
  gap: 8px;
  padding: 12px;
}

.select-row {
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 24px;
  font-weight: 700;
}

.select-row input {
  width: 18px;
  height: 18px;
  accent-color: var(--green);
}

.meta,
.current-file {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
  overflow-wrap: anywhere;
}

.progress-panel {
  padding: 22px 18px;
  border-left: 1px solid var(--line);
  background: #fbfcfa;
}

.progress-panel h2 {
  margin: 0 0 18px;
  font-size: 16px;
  letter-spacing: 0;
}

.progress-wrap {
  display: grid;
  gap: 8px;
}

.progress-label {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  color: var(--muted);
  font-size: 13px;
}

.progress-bar {
  overflow: hidden;
  height: 10px;
  border-radius: 5px;
  background: #dce2d8;
}

.progress-bar div {
  width: 0;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 160ms ease;
}

.current-file {
  min-height: 38px;
  margin: 14px 0;
}

.completion-panel {
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.completion-panel strong {
  display: block;
  margin-bottom: 12px;
  font-size: 13px;
}

.download-link {
  width: 100%;
  text-decoration: none;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

@media (max-width: 820px) {
  .toolbar {
    grid-template-columns: 1fr;
    gap: 16px;
    padding: 22px 18px 18px;
  }

  .summary-row {
    padding: 12px 18px;
  }

  .content-grid {
    grid-template-columns: 1fr;
  }

  .progress-panel {
    order: -1;
    border-left: 0;
    border-bottom: 1px solid var(--line);
  }

  .media-panel {
    padding: 18px;
  }
}

@media (max-width: 520px) {
  .product-heading {
    align-items: flex-start;
    flex-direction: column;
    gap: 2px;
  }

  .url-form {
    grid-template-columns: 1fr;
  }

  #analyzeButton {
    width: 100%;
  }

  .summary-row {
    display: grid;
    grid-template-columns: auto auto 1fr;
  }

  #selectAllButton {
    grid-column: 1 / 2;
    margin-left: 0;
  }

  #downloadButton {
    grid-column: 2 / 4;
  }

  .media-grid {
    grid-template-columns: 1fr;
  }
}
