/* Admin tools: the grid of tool buttons, the open tool, and the shared pieces
   every tool uses. Colours come from styles.css (light and dark).

   Shared pieces for tool pages (use these, not new styles, so tools look alike):
     .tool-step          a numbered card: <section class="tool-step"><h3>1. Choose the PDF</h3>…</section>
     .drop-zone          made by AdminHub.dropZone()
     .file-list > li     a file row: .file-name, .file-meta, .file-actions (small quiet buttons)
     .fields             a wrapping row of .field labels (label text above the control)
     .field              <label class="field">Pages <input …></label>; .field.wide spans the row
     .choice-row         a row of radio/checkbox labels (.check)
     .tool-actions       the row holding the main button (button.primary), right-aligned
     .tool-status        made by AdminHub.status(); .info, .good, .bad
     .thumb-grid > .thumb   page thumbnails; .thumb.selected, .thumb.removed; .thumb-caption, .thumb-tools
     .page-stage         a page drawn large, with things placed on it (edit, sign, crop)
     .result-box         a finished result: summary text and download buttons
*/

:root {
  --g-organize: #2f7d5a;
  --g-edit: #2b62b5;
  --g-to-pdf: #c25a1c;
  --g-from-pdf: #7a4fb3;
  --g-optimize: #0f7f86;
}
@media (prefers-color-scheme: dark) {
  :root {
    --g-organize: #5cc595;
    --g-edit: #7aa7f0;
    --g-to-pdf: #f0965e;
    --g-from-pdf: #b996ec;
    --g-optimize: #4fc4cb;
  }
}

/* The PDF tools tab: one centred page width, like the Zoller HMI tab. */
.admin { overflow: auto; padding: 20px 24px 40px; }
.admin-home, .tool-view { width: 100%; max-width: calc(var(--page) - 48px); margin: 0 auto; }
.admin-home { display: flex; flex-direction: column; gap: 18px; }
.admin-intro { display: flex; align-items: flex-end; justify-content: space-between; gap: 12px 24px; flex-wrap: wrap; }
.admin-intro h2 { font-size: 22px; }
.admin-intro .hint { margin-top: 2px; }
/* The search box, with a magnifier drawn in the page's own grey. */
.search-box { position: relative; display: block; width: min(320px, 100%); }
.search-box::before {
  content: ""; position: absolute; left: 12px; top: 50%; width: 16px; height: 16px; margin-top: -8px; pointer-events: none;
  background: var(--muted);
  -webkit-mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='M15.5 15.5 21 21'/%3E%3C/svg%3E") center / contain no-repeat;
  mask: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='black' stroke-width='2.4' stroke-linecap='round'%3E%3Ccircle cx='10.5' cy='10.5' r='6.5'/%3E%3Cpath d='M15.5 15.5 21 21'/%3E%3C/svg%3E") center / contain no-repeat;
}
#toolSearch {
  width: 100%; min-height: 40px;
  font: inherit; font-size: 15px;
  padding: 6px 12px 6px 36px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
#toolSearch:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* All 21 tools on one screen: one column per group (5; 3 under 1100 px; 1 on a phone). */
.tool-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 14px; align-items: start; }
.tool-group h3 { margin: 0 0 8px 2px; font-size: 15px; font-weight: 650; }
.tool-group h3 .count { margin-left: 6px; font-size: 14px; font-weight: 400; color: var(--muted); }
.tool-cards { display: flex; flex-direction: column; gap: 2px; padding: 4px; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; }

.tool-card {
  display: flex; align-items: center; justify-content: flex-start; gap: 8px; width: 100%;
  padding: 7px 6px; text-align: left;
  border: none; border-radius: 8px;
  background: none; color: var(--text);
  transition: background-color 0.12s;
}
.tool-card:hover:not(:disabled) { background: color-mix(in srgb, var(--g, var(--accent)) 9%, transparent); }
.tool-card:focus-visible { outline: 2px solid var(--accent); outline-offset: 0; }
.tool-text { display: flex; flex-direction: column; min-width: 0; }
.tool-name { font-weight: 600; font-size: 15px; line-height: 1.3; }
/* One short line; the longer description is on the tool's page (and found by the search). */
/* It wraps when a column is narrow (windows 1,100-1,300 px wide), never cut off. */
.tool-desc { font-size: 14px; color: var(--muted); line-height: 1.35; }

.g-organize { --g: var(--g-organize); }
.g-edit { --g: var(--g-edit); }
.g-to-pdf { --g: var(--g-to-pdf); }
.g-from-pdf { --g: var(--g-from-pdf); }
.g-optimize { --g: var(--g-optimize); }
.tool-icon {
  flex: none; display: grid; place-items: center;
  width: 32px; height: 32px; border-radius: 8px;
  color: var(--g, var(--accent));
  background: color-mix(in srgb, var(--g, var(--accent)) 13%, transparent);
}
.tool-icon svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

/* ---- An open tool */
.tool-view { display: flex; flex-direction: column; gap: 16px; }
.tool-head { display: flex; flex-direction: column; align-items: flex-start; gap: 12px; }
.tool-head .back { min-height: 0; padding: 0; border: none; background: none; color: var(--accent); font-weight: 600; }
.tool-head .back:hover { text-decoration: underline; text-underline-offset: 2px; }
.tool-title { display: flex; align-items: center; gap: 14px; }
.tool-title h2 { font-size: 22px; }
.tool-title .hint { margin-top: 2px; }
.tool-title .tool-icon { width: 44px; height: 44px; border-radius: 10px; }
.tool-title .tool-icon svg { width: 24px; height: 24px; }
/* What a tool cannot do, in plain words: a neutral "Good to know" line.
   Crop PDF keeps its yellow note, because it is a privacy warning. */
.tool-limit {
  margin: 0; padding: 9px 12px; font-size: 14px; max-width: 90ch;
  border-left: 3px solid var(--muted); border-radius: 0 8px 8px 0; background: var(--stripe);
}
.tool-limit.warn { border: 1px solid var(--warn-line); border-left-width: 3px; background: var(--warn-bg); }
.tool-body { display: flex; flex-direction: column; gap: 14px; }

.tool-step {
  display: flex; flex-direction: column; gap: 12px;
  padding: 16px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface);
}
.tool-step h3 { margin: 0; font-size: 15px; font-weight: 650; }
/* A numbered step title: 18 px with the number in a circle, as on the Zoller HMI steps. */
.tool-step h3.step-title { display: flex; align-items: center; gap: 10px; font-size: 18px; }
.tool-step > .hint { margin-top: -6px; }

.drop-zone {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px;
  padding: 28px 16px; text-align: center;
  border: 2px dashed var(--line); border-radius: 10px; background: var(--bg);
}
.drop-zone .button { padding: 4px 18px; font-size: 15px; }
.drop-zone.over, body.dragging .drop-zone { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 6%, var(--bg)); }

.file-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.file-list li {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 8px 10px; border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
.file-name { font-weight: 600; overflow-wrap: anywhere; flex: 1; min-width: 160px; }
.file-meta { font-size: 14px; color: var(--muted); }
.file-actions { display: flex; gap: 6px; }
.file-actions button { min-height: 30px; padding: 2px 10px; font-size: 14px; }

.fields { display: flex; flex-wrap: wrap; gap: 12px 18px; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 14px; font-weight: 600; min-width: 140px; }
.field.wide { flex: 1 1 100%; }
.field input[type="text"], .field input[type="number"], .field input:not([type]), .field select, .field textarea, .tool-body textarea {
  font: inherit; font-size: 14px; font-weight: 400;
  min-height: 36px; padding: 4px 10px; border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); color: var(--text);
}
.field input[type="color"] { width: 48px; height: 32px; padding: 2px; border: 1px solid var(--line); border-radius: 7px; background: var(--surface); }
.field input[type="range"] { accent-color: var(--accent); }
.field input:focus-visible, .field select:focus-visible, .tool-body textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.tool-body textarea { min-height: 220px; font: 14px/1.5 var(--mono); white-space: pre; resize: vertical; }
.choice-row { display: flex; flex-wrap: wrap; gap: 8px 18px; font-size: 14px; }
.choice-row .check, .tool-body label.check { display: inline-flex; align-items: center; gap: 7px; font-weight: 400; }

.tool-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: flex-end; gap: 8px; }
.tool-actions .primary { padding: 4px 20px; font-size: 15px; }
button.busy { cursor: progress; }

/* Messages often quote a file name; a long one without spaces must wrap, not run out of the box. */
.tool-status { margin: 0; padding: 9px 12px; border-radius: 8px; font-size: 14px; border: 1px solid var(--line); background: var(--bg); overflow-wrap: anywhere; }
.tool-status.info { border-color: var(--line); }
.tool-status.good { border-color: var(--good); background: var(--good-bg); color: var(--good); }
.tool-status.bad { border-color: var(--bad); background: var(--bad-bg); color: var(--bad); }

.thumb-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.thumb {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 6px;
  margin: 0; padding: 8px; border: 2px solid var(--line); border-radius: 9px; background: var(--bg);
}
.thumb canvas, .thumb img { max-width: 100%; height: auto; box-shadow: 0 1px 4px rgb(0 0 0 / 0.18); background: #fff; }
.thumb.selected { border-color: var(--accent); background: color-mix(in srgb, var(--accent) 8%, var(--bg)); }
.thumb.removed > :not(.thumb-tools) { opacity: 0.35; }
.thumb.dragging { opacity: 0.5; }
.thumb.drop-before { box-shadow: -4px 0 0 var(--accent); }
.thumb-caption { font-size: 12px; color: var(--muted); }
.thumb-tools { display: flex; gap: 4px; }
.thumb-tools button { min-height: 30px; padding: 1px 8px; font-size: 12px; }

.page-stage { position: relative; align-self: center; max-width: 100%; overflow: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--stripe); padding: 12px; }
.page-stage .page-wrap { position: relative; margin: 0 auto; width: max-content; box-shadow: 0 2px 10px rgb(0 0 0 / 0.2); }
.page-stage canvas { display: block; }

.result-box { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; padding: 12px 14px; border: 1px solid var(--good); border-radius: 10px; background: var(--good-bg); color: var(--good); overflow-wrap: anywhere; }
.result-box .actions button { color: var(--text); }

@media (max-width: 1100px) {
  .tool-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 760px) {
  .admin { padding: 16px 16px 28px; }
  .admin-intro { flex-direction: column; align-items: stretch; }
  .admin-intro h2, .tool-title h2 { font-size: 22px; }
  .search-box { width: 100%; }
  .tool-grid { grid-template-columns: minmax(0, 1fr); gap: 18px; }
  .tool-card { min-height: 52px; padding: 9px 8px; }
  .thumb-tools button, .file-actions button { min-height: 36px; }
}
@media (prefers-reduced-motion: reduce) {
  .tool-card { transition: none; }
}
