/* Focus and responsive fixes leave the approved desktop layout intact. */
html body :focus-visible { outline: 2px solid #87187a !important; outline-offset: 3px; }
[hidden] { display: none !important; }
button:disabled { cursor: not-allowed; }
.drag-over { background: #f5edf6 !important; outline: 2px dashed #87187a; outline-offset: -4px; }
.pdf-card { width: 155px; flex-shrink: 0; cursor: grab; }
.pdf-card-inner { aspect-ratio: 4/5; }
.pdf-card img { transition: transform .15s ease; }
.card-meta { color: #6b7280; font-size: 11px; }
.card-controls { display: flex; gap: 6px; }
.card-controls button { width: 32px; height: 28px; border-radius: 8px; background: #f1eef4; color: #66365c; }
.card-controls button:disabled { opacity: .35; }
.page-select { position: absolute; top: 10px; right: 10px; width: 20px; height: 20px; border-radius: 5px; color: #87187a; cursor: pointer; }
.file-row { display: flex; gap: 12px; align-items: center; padding: 12px; background: #f3f5fa; border-radius: 12px; font-size: 12px; }
.file-row span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file-row button { width: 28px; height: 28px; font-size: 20px; }
.workspace-output { margin-top: auto; display: grid; gap: 8px; flex-shrink: 0; }
.field-label { display: block; font-size: 12px; font-weight: 600; color: #52424d; margin-bottom: 4px; }
.optional { font-weight: 400; color: #6b7280; }
.workspace-output input, #aside-tools-container input:not([type=checkbox]), #aside-tools-container select { width: 100%; min-width: 0; border: 1px solid #e2d8df; border-radius: 10px; padding: 10px 12px; font-size: 13px; background: white; }
.tool-heading { font-size: 18px; font-weight: 700; color: #382d34; }
.tool-hint { color: #6b6370; font-size: 12px; line-height: 1.6; margin-top: 4px; }
.option-label { display: flex; align-items: center; gap: 10px; font-size: 13px; line-height: 1.5; }
.option-label input { color: #87187a; border-radius: 4px; flex-shrink: 0; }
.option-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.option-actions button { padding: 8px 12px; border-radius: 10px; background: #f5f1f6; color: #66365c; font-size: 12px; font-weight: 600; min-height: 36px; }
.option-actions button:disabled { opacity: .4; }
.related-tools { display: flex; flex-wrap: wrap; gap: 10px; font-size: 12px; color: #87187a; }
.related-tools a { text-decoration: underline; text-underline-offset: 3px; }
.field-error { color: #991b1b; }
#status-area { flex-shrink: 0; max-height: 150px; overflow: auto; white-space: pre-line; overflow-wrap: anywhere; }
#status-area:empty { display: none; }
#status-area .status-msg { margin-top: 0; padding: 10px; font-size: 12px; }
body[data-tool] #aside-tools-container { flex-shrink: 0; overflow: visible; gap: 16px; }
body[data-tool] #view-mode-toggle-container { gap: 10px; flex-wrap: wrap; }
.is-busy .pdf-card { pointer-events: none; }
.notice-dialog { padding: 28px; border-radius: 24px; border: 1px solid #e2d8df; max-width: min(460px, 90vw); color: #382d34; box-shadow: 0 20px 80px #22191f33; }
.notice-dialog::backdrop { background: #22191f55; }
.notice-dialog h2 { font-size: 22px; font-weight: 700; margin-bottom: 12px; }
.notice-dialog p { font-size: 14px; line-height: 1.7; }
.notice-dialog button { margin-top: 20px; padding: 10px 20px; background: #87187a; color: white; border-radius: 12px; }
/* Keep both panes usable as the window narrows. The preview column may shrink
   below the intrinsic width of a canvas, filename, or toolbar. */
body[data-tool] main > div {
  width: 90%;
  grid-template-columns: minmax(0, 1fr) clamp(260px, 30vw, 340px);
  gap: clamp(16px, 2.5vw, 32px);
}
body[data-tool] #main-workspace-drop,
body[data-tool] #drop-zone {
  min-width: 0;
}
body[data-tool] #drop-zone {
  width: 100%;
  overflow-y: auto;
  overflow-wrap: anywhere;
}
body[data-tool] #view-mode-toggle-container > div:first-child {
  flex-wrap: wrap;
  row-gap: 6px;
}
body[data-tool] #upload-btn-secondary { margin-right: 0 !important; }

@media (min-width: 768px) and (min-height: 621px) {
  body[data-tool] {
    height: 100dvh;
    min-height: 0 !important;
  }
  body[data-tool] main > div { grid-template-rows: minmax(0, 1fr); }
}

@media (max-width: 1099px) {
  body[data-tool] main > div { width: calc(100% - 2 * clamp(12px, 3vw, 32px)); }
  body[data-tool] #drop-zone {
    transform: none !important;
    padding: clamp(14px, 2.1vw, 22px);
    border-radius: 24px;
  }
  body[data-tool] #main-workspace-drop { padding-right: 0; }
}

@media (max-width: 767px), (max-height: 620px) {
  /* A short viewport needs normal page scrolling so controls and the footer
     can be reached even when they are taller than the window. */
  body[data-tool] {
    height: auto;
    min-height: 100dvh !important;
    overflow: visible;
  }
  body[data-tool] main { flex: 1 0 auto; overflow: visible; }
  body[data-tool] main > div { align-items: start; }
  body[data-tool] #main-workspace-drop {
    height: auto;
    overflow: visible !important;
  }
  body[data-tool] #drop-zone {
    height: auto !important;
    max-height: none;
    min-height: 200px;
    overflow: visible;
    transform: none !important;
  }
}

@media (max-width: 767px) {
  body[data-tool] main { padding-block: 16px; }
  body[data-tool] main > div { grid-template-columns: minmax(0, 1fr); }
  body[data-tool] #main-workspace-drop { padding-bottom: 0; }
  body[data-tool] #pdf-thumbnails-container { gap: 16px !important; }
  body[data-tool] .pdf-card {
    width: calc((100% - 32px) / 3);
    max-width: 155px;
  }
  body[data-tool] #view-mode-toggle-container { margin-bottom: 14px; }
  body[data-tool] #reset-btn { margin-left: 4px; }
  .option-label { align-items: flex-start; }
}

@media (max-width: 540px) {
  body[data-tool] .pdf-card {
    width: calc((100% - 16px) / 2);
    max-width: 155px;
  }
  body[data-tool] #view-mode-toggle-container button { padding-inline: 10px; }
  body[data-tool] #drop-zone > div:first-child button { padding-inline: 12px; }
  body[data-tool] #adv-preview { padding-inline: 16px; }
  body[data-tool] :is(.adv-file-actions, .image-card-controls) button { min-width: 0; }
}

@media (max-width: 360px) {
  body[data-tool] :is(.adv-file-actions, .image-card-controls) {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
  body[data-tool] :is(.adv-file-actions, .image-card-controls) button {
    min-height: 44px;
    margin: 0;
  }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition: none !important; scroll-behavior: auto !important; }
  .tool-card:hover { transform: none; }
}
body[data-tool]:not([data-tool=merge]):not([data-tool=rotate]) #reset-btn { margin-left: 0; }

.field-pair { display:grid; grid-template-columns:repeat(2,minmax(0,1fr)); gap:12px; }
.tool-note { padding:12px; border-radius:12px; background:#f7f2f7; color:#67566b; font-size:12px; line-height:1.6; }
.compression-results { font-size:12px; color:#166534; overflow-wrap:anywhere; display:grid; gap:10px; }
.finish-preview { width:100%; min-width:0; }
.preview-toolbar { display:flex; align-items:center; flex-wrap:wrap; gap:12px; margin-bottom:20px; font-size:13px; }
.preview-toolbar select { border:1px solid #e2d8df; border-radius:10px; font-size:13px; }
.preview-stage { position:relative; width:100%; max-width:720px; margin:auto; background:white; box-shadow:0 2px 18px #22191f15; overflow:hidden; }
.preview-stage canvas { display:block; width:100%; height:100%; }
.preview-overlay { position:absolute; inset:0; pointer-events:none; overflow:hidden; }
.watermark-overlay { position:absolute; max-width:none; object-fit:fill; pointer-events:none; }
.crop-overlay { pointer-events:auto; touch-action:none; cursor:crosshair; user-select:none; }
.crop-selection { position:absolute; box-sizing:border-box; border:2px solid #87187a; box-shadow:0 0 0 1600px #22191f66; cursor:move; }
.crop-handle { position:absolute; width:16px; height:16px; border:2px solid white; background:#87187a; border-radius:50%; }
.crop-handle.nw { left:-8px;top:-8px;cursor:nwse-resize; } .crop-handle.ne { right:-8px;top:-8px;cursor:nesw-resize; }
.crop-handle.sw { left:-8px;bottom:-8px;cursor:nesw-resize; } .crop-handle.se { right:-8px;bottom:-8px;cursor:nwse-resize; }
.is-busy .preview-overlay { pointer-events:none; }
body[data-tool=watermark] #aside-tools-container, body[data-tool=crop] #aside-tools-container { gap:12px; }
#watermark-text-fields { display:grid;gap:10px; }
#watermark-color { height:42px; padding:4px !important; }
body[data-tool=crop] #undo-btn,body[data-tool=watermark] #undo-btn { display:none; }
@media (min-width:768px) and (min-height:621px) {
  .preview-stage { max-width:min(720px,calc((100dvh - 330px) * var(--page-ratio, 0.7))); }
}
