:root {
  --bg: #f5f7fb;
  --card: #ffffff;
  --text: #0f172a;
  --muted: #64748b;
  --border: #e2e8f0;
  --accent: #0b5cad;
  --accent-strong: #094a8c;
  --accent-soft: #eaf2fb;
  --hero-from: #0b5cad;
  --hero-to: #0e7490;
  --ok: #1a7f37;
  --warn: #b54708;
  --shadow: 0 1px 2px rgba(15, 23, 42, .04), 0 8px 24px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: system-ui, "Segoe UI", Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
}

/* ---------- Header with moving water ---------- */

.hero {
  position: relative;
  background: linear-gradient(135deg, var(--hero-from) 0%, var(--hero-to) 100%);
  color: #fff;
  padding: 32px 32px 0;
  overflow: hidden;
}
.hero-text { max-width: 1240px; margin: 0 auto; }
.hero h1 { margin: 0; font-size: 1.8rem; }
.hero .sub { margin: 6px 0 0; color: rgba(255, 255, 255, .85); font-size: .95rem; }

/* Full-bleed: cancel the header's side padding so the water reaches both edges. */
.waves { display: block; width: calc(100% + 64px); height: 90px; margin: 16px -32px 0; }
.wave-layers > use { animation: wave-drift 25s cubic-bezier(.55, .5, .45, .5) infinite; }
.wave-layers > use:nth-child(1) { fill: rgba(255, 255, 255, .45); animation-delay: -2s; animation-duration: 7s; }
.wave-layers > use:nth-child(2) { fill: rgba(255, 255, 255, .3); animation-delay: -3s; animation-duration: 10s; }
.wave-layers > use:nth-child(3) { fill: rgba(255, 255, 255, .18); animation-delay: -4s; animation-duration: 13s; }
.wave-layers > use:nth-child(4) { fill: var(--bg); animation-delay: -5s; animation-duration: 20s; }
@keyframes wave-drift {
  0% { transform: translate3d(-90px, 0, 0); }
  100% { transform: translate3d(85px, 0, 0); }
}
@media (prefers-reduced-motion: reduce) {
  .wave-layers > use { animation: none; }
}

/* ---------- Layout: work area + settings panel ---------- */

main {
  max-width: 1240px; margin: 0 auto; padding: 8px 24px 32px;
  display: grid; gap: 20px; align-items: start;
  grid-template-columns: minmax(0, 1fr) 360px;
  grid-template-areas: "upload settings" "results settings";
}
.upload-card { grid-area: upload; }
.settings { grid-area: settings; position: sticky; top: 16px; }
#resultsCard { grid-area: results; }

@media (max-width: 900px) {
  main { grid-template-columns: minmax(0, 1fr); grid-template-areas: "upload" "settings" "results"; padding: 8px 16px 24px; }
  .settings { position: static; }
  .hero { padding: 24px 16px 0; }
  .hero h1 { font-size: 1.5rem; }
  .waves { height: 56px; width: calc(100% + 32px); margin: 12px -16px 0; }
}

.card {
  background: var(--card);
  border-radius: 16px;
  box-shadow: var(--shadow);
  padding: 20px;
}

/* ---------- Upload ---------- */

.dropzone {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding: 56px 16px;
  border: 2px dashed #bfd3ea;
  border-radius: 14px;
  background: linear-gradient(180deg, #fbfdff, #f2f7fd);
  cursor: pointer;
  text-align: center;
  color: var(--muted);
  transition: background .15s, border-color .15s;
}
.dropzone strong { color: var(--text); font-size: 1.1rem; }
.dropzone.over, .dropzone:hover { background: var(--accent-soft); border-color: var(--accent); }
.drop-icon {
  width: 56px; height: 56px; border-radius: 50%; margin-bottom: 8px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center;
  box-shadow: 0 6px 16px rgba(11, 92, 173, .3);
}

.upload-actions { display: flex; gap: 16px; align-items: center; margin-top: 12px; }

.file-list { list-style: none; padding: 0; margin: 12px 0 0; display: flex; flex-wrap: wrap; gap: 8px; }
.file-list li {
  background: var(--accent-soft); border-radius: 999px; padding: 4px 12px; font-size: .85rem;
  display: flex; align-items: center; gap: 6px;
}
.file-list button { border: 0; background: none; cursor: pointer; color: var(--muted); font-size: 1rem; padding: 0; }

/* ---------- Settings ---------- */

.settings { display: grid; grid-template-columns: 1fr; gap: 16px; }
.field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.field > label { font-weight: 600; font-size: .9rem; }
.field[hidden] { display: none; }
.row { display: flex; align-items: center; gap: 8px; }
.row input { width: 100%; }
.row select { flex: 1; }
.hint { color: var(--warn); font-size: .8rem; }
.note { color: var(--muted); font-size: .8rem; }
.check { font-weight: 400 !important; font-size: .85rem; display: flex; gap: 6px; align-items: center; }

select, input[type=number], input[type=text] {
  min-width: 0; max-width: 100%;
  font: inherit; padding: 9px 10px; border: 1px solid var(--border); border-radius: 10px; background: #fff;
  transition: border-color .15s, box-shadow .15s;
}
select:focus, input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 3px rgba(11, 92, 173, .15); }
input[type=color] { width: 60px; height: 40px; border: 1px solid var(--border); border-radius: 10px; padding: 2px; }

.add-size { background: var(--accent-soft); border-radius: 12px; padding: 12px; }

.advanced { border-top: 1px solid var(--border); padding-top: 12px; }
.advanced summary { cursor: pointer; color: var(--muted); font-size: .9rem; }
.advanced .field { margin-top: 12px; }

/* ---------- Buttons ---------- */

button.primary {
  font: inherit; font-weight: 600;
  background: var(--accent); color: #fff;
  border: 0; border-radius: 10px; padding: 12px 18px; cursor: pointer;
  box-shadow: 0 6px 16px rgba(11, 92, 173, .28);
  transition: background .15s, transform .05s;
}
button.primary:hover { background: var(--accent-strong); }
button.primary:active { transform: translateY(1px); }
button.primary:disabled { opacity: .5; cursor: not-allowed; box-shadow: none; }

button.secondary {
  font: inherit; font-weight: 600;
  background: var(--accent-soft); color: var(--accent);
  border: 1px solid var(--accent); border-radius: 10px; padding: 8px 14px; cursor: pointer;
}
button.link {
  font: inherit; font-size: .85rem; background: none; border: 0; padding: 0;
  color: var(--accent); cursor: pointer; text-decoration: underline; align-self: flex-start;
}
button[hidden] { display: none; }

/* ---------- Results ---------- */

.results-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.results-head h2 { margin: 0; font-size: 1.2rem; }
.results { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 16px; margin-top: 16px; }

.result {
  border-radius: 12px; overflow: hidden; background: var(--card);
  box-shadow: 0 1px 3px rgba(15, 23, 42, .1);
  display: flex; flex-direction: column;
}
.result .thumb {
  background: repeating-conic-gradient(#eef1f5 0% 25%, #fff 0% 50%) 50% / 16px 16px;
  display: flex; align-items: center; justify-content: center; height: 160px;
}
.result img { max-width: 100%; max-height: 160px; }
.result .meta { padding: 10px 12px 12px; font-size: .82rem; display: grid; gap: 4px; }
.result .name { font-weight: 600; word-break: break-all; direction: ltr; text-align: right; }
.result .size.ok { color: var(--ok); }
.result .size.warn { color: var(--warn); }
.result .info { color: var(--muted); }
.result .info.warn { color: var(--warn); }
.result a { color: var(--accent); font-weight: 600; text-decoration: none; }

/* ---------- Footer ---------- */

.site-footer {
  text-align: center; color: var(--muted); font-size: .82rem;
  padding: 8px 16px 28px;
}

/* ---------- Units, crop button, AI option ---------- */

.unit { color: var(--muted); font-size: .85rem; direction: ltr; }
.check.strong { font-weight: 600 !important; font-size: .95rem; }
.ai-field { background: linear-gradient(135deg, #eef6ff, #f3f0ff); border-radius: 12px; padding: 12px; }
.ai-progress { display: grid; gap: 6px; margin-top: 4px; }
.ai-progress[hidden] { display: none; }
.ai-progress-head { display: flex; justify-content: space-between; font-size: .82rem; font-weight: 600; }
.ai-progress-track { height: 10px; border-radius: 999px; background: #dfe6f3; overflow: hidden; }
.ai-progress-track > span {
  display: block; height: 100%; width: 0; border-radius: inherit;
  background: linear-gradient(90deg, var(--accent), #7c5cff);
  transition: width .2s;
}
.ai-progress.done .ai-progress-track > span { background: var(--ok); }
.file-list .crop-btn { color: var(--accent); font-size: .85rem; }
.file-list .crop-btn.cropped { font-weight: 600; }
#uploadStatus:empty { display: none; }
#uploadStatus { display: block; margin-top: 8px; }

/* ---------- Pop-up windows (PDF pages, crop) ---------- */

.modal {
  border: 0; border-radius: 16px; padding: 0;
  width: min(760px, calc(100vw - 32px)); max-height: calc(100vh - 32px);
  box-shadow: 0 20px 60px rgba(15, 23, 42, .3);
  color: var(--text);
}
.modal-wide { width: min(1000px, calc(100vw - 32px)); }
.modal::backdrop { background: rgba(15, 23, 42, .55); }
.modal-body { padding: 20px; display: grid; gap: 14px; }
.modal-body h2 { margin: 0; font-size: 1.2rem; }
.modal-tools { display: flex; gap: 16px; align-items: center; flex-wrap: wrap; }
.modal-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; }
.modal-actions .link { align-self: center; }

.pdf-pages {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px;
  max-height: 55vh; overflow: auto; padding: 4px;
}
.pdf-page {
  display: grid; gap: 6px; justify-items: center; padding: 8px; cursor: pointer;
  border: 2px solid var(--border); border-radius: 12px; font-size: .85rem;
}
.pdf-page:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.pdf-thumb { min-height: 120px; display: grid; place-items: center; }
.pdf-thumb canvas { max-width: 100%; box-shadow: 0 1px 3px rgba(15, 23, 42, .2); background: #fff; }
.pdf-mode { display: grid; gap: 6px; }

.crop-area { height: min(60vh, 560px); background: #f1f5f9; border-radius: 12px; overflow: hidden; }
.crop-area img { display: block; max-width: 100%; }

input[type=range] { accent-color: var(--accent); width: 100%; }

/* ---------- Results: summary, actions ---------- */

.results-actions { display: flex; gap: 10px; flex-wrap: wrap; }
.results-summary { margin-top: 8px; font-size: .88rem; color: var(--muted); }
.results-summary:empty { display: none; }
.results-summary .warn { color: var(--warn); font-weight: 600; }
.results-summary .ok { color: var(--ok); font-weight: 600; }
.result .thumb { border: 0; padding: 0; width: 100%; cursor: zoom-in; }
.result .quality-warning { font-weight: 600; }
.card-actions { display: flex; gap: 12px; align-items: center; flex-wrap: wrap; margin-top: 2px; }
.card-actions .link { font-size: .82rem; text-decoration: none; font-weight: 600; }

/* ---------- Large view: before / after ---------- */

.view-head { display: flex; gap: 12px; align-items: baseline; flex-wrap: wrap; }
.view-head h2 { font-size: 1.05rem; word-break: break-all; }
/* Before and after, side by side (stacked on narrow screens). */
.side-by-side { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.side-by-side figure { margin: 0; display: grid; gap: 6px; min-width: 0; }
.side-by-side figcaption { font-weight: 600; font-size: .9rem; text-align: center; }
.side-by-side .pane {
  display: grid; place-items: center; overflow: auto; max-height: 62vh; border-radius: 12px;
  background: repeating-conic-gradient(#eef1f5 0% 25%, #fff 0% 50%) 50% / 16px 16px;
}
.side-by-side img { display: block; max-width: 100%; max-height: 62vh; }
.side-by-side.actual .pane { place-items: start center; }
.side-by-side.actual img { max-width: none; max-height: none; }
@media (max-width: 700px) { .side-by-side { grid-template-columns: 1fr; } }
.spacer { flex: 1; }
.button-link { display: inline-block; text-decoration: none; }
.modal-actions .link:disabled { opacity: .4; cursor: default; }
#cropRotate[hidden] { display: none; }
#cropRotate input[type=range] { width: 180px; }
a.button-link.primary {
  background: var(--accent); color: #fff; font-weight: 600; border-radius: 10px; padding: 12px 18px;
  box-shadow: 0 6px 16px rgba(11, 92, 173, .28);
}
a.button-link.primary:hover { background: var(--accent-strong); }
