/* PageForge — shared tool styles (used by all standalone tool pages) */

/* === TOKEN COMPAT === */
:root {
  --surface-warm: var(--surface-2);
  --border: var(--rule);
  --border-strong: #c8d4da;
  --text: var(--fg-1);
  --text-dim: var(--fg-2);
  --text-faint: var(--fg-3);
  --accent-soft: var(--primary-soft);
  --accent-dark: var(--primary-hover);
  --radius-sm: var(--r-sm);
  --radius-md: var(--r-md);
  --radius-lg: var(--r-lg);
  --radius-pill: 999px;
  --transition: 180ms cubic-bezier(0.4, 0, 0.2, 1);
  --status-ok:      #2E8B57; --status-ok-bg:   #e6f4ec;
  --status-warn:    #C8881A; --status-warn-bg: #fdf2de;
  --status-err:     #C9382A; --status-err-bg:  #fbe7e3;
}
[data-theme="dark"] { --border-strong: #2a4454; }

/* === LAYOUT === */
*, *::before, *::after { box-sizing: border-box; }
body {
  font-family: var(--font-body);
  background: var(--bg); color: var(--fg-1);
  font-size: 14px; line-height: 1.55;
  display: flex; flex-direction: column; min-height: 100vh;
  -webkit-font-smoothing: antialiased;
  transition: background .35s ease, color .35s ease;
}
.tool-main {
  flex: 1; padding: 40px 36px 80px;
  max-width: 1080px; width: 100%; margin: 0 auto;
  display: flex; flex-direction: column; gap: 24px;
}
.tool-header { margin-bottom: 8px; }
.tool-header h1 { font-size: clamp(22px,3vw,32px); letter-spacing:-.02em; margin-bottom: 6px; }
.tool-header p { color: var(--fg-2); font-size: 15px; }

/* === SPINNER === */
.spinner {
  display: none; width: 12px; height: 12px;
  border: 1.5px solid var(--rule); border-top-color: var(--primary);
  border-radius: 50%; animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
body.busy .spinner { display: inline-block; }
body.busy { cursor: progress; }

/* === DROPZONE: stile centralizzato in styles.css (vale per tutte le pagine
   e per l'editor, che non carica questo foglio) === */

/* === CONVERT / TOOL PANELS === */
.convert-section { display: flex; flex-direction: column; gap: 14px; }
.convert-ready {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-md); padding: 14px 18px;
}
.convert-file-info { display: flex; flex-direction: column; gap: 3px; overflow: hidden; }
.convert-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.convert-dir { font-family: var(--font-mono); font-size: 11px; color: var(--primary); }
.convert-actions { display: flex; gap: 8px; flex-shrink: 0; }

.mode-toggle { display: inline-flex; background: var(--surface-warm); border: 1px solid var(--rule); border-radius: var(--radius-pill); padding: 3px; gap: 2px; }
.mode-btn { padding: 6px 16px; font-size: 13px; border-radius: var(--radius-pill); color: var(--fg-2); border: none; background: transparent; cursor: pointer; }
.mode-btn.active { background: var(--fg-1); color: var(--surface); }
.mode-btn:hover:not(.active):not(:disabled) { color: var(--fg-1); }

/* === PASSWORD === */
.password-ready { display: flex; flex-direction: column; gap: 14px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-md); padding: 16px 18px; }
.password-top-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.password-file-info { display: flex; flex-direction: column; gap: 3px; overflow: hidden; flex: 1; min-width: 0; }
.password-name { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.password-mode-label { font-family: var(--font-mono); font-size: 11px; color: var(--fg-2); }
.permissions-panel { display: flex; flex-direction: column; gap: 10px; padding: 10px 0; border-top: 1px solid var(--rule); border-bottom: 1px solid var(--rule); }
.perm-row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.perm-label { font-size: 11px; color: var(--fg-2); min-width: 80px; font-family: var(--font-mono); }
.perm-btn { padding: 5px 12px; font-size: 12px; border-radius: var(--radius-pill); color: var(--fg-2); border: none; background: transparent; cursor: pointer; }
.perm-btn.active, .wm-logo-opt.active, .wm-opt.active { background: var(--fg-1); color: var(--surface); }
.perm-btn:hover:not(.active):not(:disabled),
.wm-logo-opt:hover:not(.active):not(:disabled),
.wm-opt:hover:not(.active):not(:disabled) { color: var(--fg-1); background: transparent; }
/* i segmentati attivi mantengono il fill al rollover (coerente su tutto il sito) */
.perm-btn.active:hover:not(:disabled),
.mode-btn.active:hover:not(:disabled),
.wm-logo-opt.active:hover:not(:disabled),
.wm-opt.active:hover:not(:disabled) { background: var(--fg-1); color: var(--surface); }
.password-input-group { display: flex; gap: 8px; align-items: center; }
input[type="password"], input[type="text"].password-field {
  font-family: var(--font-body); font-size: 13px; padding: 8px 14px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-pill);
  background: var(--surface-warm); color: var(--fg-1); outline: none; transition: var(--transition); width: 180px;
}
input[type="password"]:focus { border-color: var(--primary); }

/* === BUTTONS === */
button {
  background: transparent; color: var(--fg-1); border: 1px solid transparent;
  padding: 8px 14px; font-family: var(--font-body); font-size: 13px; font-weight: 500;
  border-radius: var(--radius-pill); cursor: pointer; transition: var(--transition);
  display: inline-flex; align-items: center; gap: 6px;
}
button:hover:not(:disabled) { background: var(--surface-warm); }
button:disabled { opacity: .35; cursor: not-allowed; }
button.primary { background: var(--primary); color: #fff; box-shadow: var(--shadow-primary); }
button.primary:hover:not(:disabled) { background: var(--primary-hover); transform: translateY(-1px); box-shadow: 0 6px 16px rgba(11,28,37,.18); }
button.ghost { border: 1px solid var(--rule); }
button.ghost:hover:not(:disabled) { transform: translateY(-1px); box-shadow: 0 5px 14px rgba(11,28,37,.10); }
button.danger:hover:not(:disabled) { background: var(--tint-red); color: var(--c-red); }

/* === COMPRESS QUALITY === */
.compress-q-btn { padding: 5px 12px; font-size: 12px; border-radius: var(--radius-pill); color: var(--fg-2); border: none; background: transparent; cursor: pointer; }
.compress-q-btn.active { background: var(--fg-1); color: var(--surface); }
.compress-q-btn:hover:not(.active) { color: var(--fg-1); }

/* === IMG GRID === */
.img-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 16px; }
.img-card {
  background: var(--surface); border: 1.5px solid var(--rule); border-radius: var(--radius-md);
  overflow: hidden; cursor: pointer; transition: var(--transition); position: relative;
}
.img-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-1px); }
.img-card.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft); }
.img-card img { width: 100%; aspect-ratio: 4/3; object-fit: contain; background: var(--surface-warm); display: block; }
.img-meta { padding: 8px 10px; border-top: 1px solid var(--rule); font-family: var(--font-mono); font-size: 10px; color: var(--fg-2); }
.img-check {
  position: absolute; top: 8px; right: 8px; width: 22px; height: 22px; border-radius: 50%;
  background: var(--surface); border: 1.5px solid var(--border-strong);
  display: flex; align-items: center; justify-content: center; font-size: 11px; font-weight: 700; color: transparent;
}
.img-card.selected .img-check { background: var(--primary); border-color: var(--primary); color: #fff; }
.img-toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 12px; padding-bottom: 4px; }
.img-toolbar-left { display: flex; align-items: baseline; gap: 14px; }
.img-toolbar-right { display: flex; gap: 8px; }
.img-toolbar-left h2 { font-family: var(--font-display); font-size: 20px; font-weight: 700; }

/* === PREFLIGHT === */
.overall-badge { display: inline-flex; align-items: center; gap: 8px; padding: 9px 18px; border-radius: var(--radius-pill); font-weight: 600; font-size: 14px; }
.overall-badge.ok      { background: var(--status-ok-bg);   color: var(--status-ok);  }
.overall-badge.warning { background: var(--status-warn-bg);  color: var(--status-warn); }
.overall-badge.error   { background: var(--status-err-bg);  color: var(--status-err); }
.preflight-report { display: flex; flex-direction: column; gap: 24px; }
.preflight-report-header { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; }
.preflight-meta { display: flex; flex-wrap: wrap; gap: 6px 28px; background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-md); padding: 16px 20px; }
.preflight-meta-item { display: flex; flex-direction: column; gap: 3px; }
.preflight-meta-item .meta-label { font-family: var(--font-mono); font-size: 10px; color: var(--fg-3); text-transform: uppercase; letter-spacing: .08em; }
.preflight-meta-item .meta-value { font-family: var(--font-mono); font-size: 13px; color: var(--fg-1); font-weight: 500; }
.preflight-checks { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-md); overflow: hidden; }
.check-item { display: grid; grid-template-columns: 12px 1fr auto; gap: 14px; align-items: start; padding: 16px 20px; border-bottom: 1px solid var(--rule); }
.check-item:last-child { border-bottom: none; }
.check-dot { width: 10px; height: 10px; border-radius: 50%; margin-top: 5px; }
.check-dot.ok { background: var(--status-ok); } .check-dot.warning { background: var(--status-warn); } .check-dot.error { background: var(--status-err); }
.check-label { font-size: 14px; font-weight: 500; color: var(--fg-1); margin-bottom: 4px; }
.check-detail { font-family: var(--font-mono); font-size: 11px; color: var(--fg-2); line-height: 1.5; }
.check-badge { font-family: var(--font-mono); font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: var(--radius-pill); white-space: nowrap; }
.check-badge.ok { background: var(--status-ok-bg); color: var(--status-ok); }
.check-badge.warning { background: var(--status-warn-bg); color: var(--status-warn); }
.check-badge.error { background: var(--status-err-bg); color: var(--status-err); }

/* === WATERMARK === */
.wm-opt { padding: 5px 12px; font-size: 12px; border-radius: var(--radius-pill); color: var(--fg-2); border: none; background: transparent; cursor: pointer; }
.wm-type-btn { padding: 6px 16px; font-size: 13px; border-radius: var(--radius-pill); color: var(--fg-2); border: none; background: transparent; cursor: pointer; }
.wm-type-btn.active { background: var(--fg-1); color: var(--surface); }

/* === EDITOR CANVAS === */
.ed-toolbar {
  display: flex; align-items: center; flex-wrap: wrap; gap: 10px;
  background: var(--surface); border: 1px solid var(--rule);
  border-radius: var(--radius-md); padding: 10px 14px;
  position: sticky; top: 64px; z-index: 10;
}
.ed-tools { display: flex; gap: 3px; flex-shrink: 0; }
.ed-tool-btn {
  width: 34px; height: 34px; border-radius: var(--r-sm);
  background: transparent; border: 1px solid transparent;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px; font-weight: 700; cursor: pointer; transition: var(--transition); padding: 0;
}
.ed-tool-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; }
.ed-tool-btn.active { background: var(--fg-1); color: var(--surface); }
.ed-tool-btn:hover:not(.active) { background: var(--surface-warm); }
.ed-divider { width: 1px; height: 24px; background: var(--rule); flex-shrink: 0; }
.ed-opts { display: flex; align-items: center; gap: 10px; flex: 1; flex-wrap: wrap; }
.ed-opt-label { font-family: var(--font-mono); font-size: 11px; color: var(--fg-2); white-space: nowrap; }
.ed-opt-hint  { font-family: var(--font-mono); font-size: 11px; color: var(--fg-3); }
.ed-num-input {
  width: 54px; font-family: var(--font-body); font-size: 12px; padding: 4px 8px;
  border: 1px solid var(--border-strong); border-radius: var(--radius-pill);
  background: var(--surface-warm); color: var(--fg-1); outline: none;
}
.ed-actions { display: flex; gap: 6px; margin-left: auto; flex-shrink: 0; }
.ed-page-nav { display: flex; align-items: center; justify-content: center; gap: 10px; }
.ed-page-info { font-family: var(--font-mono); font-size: 12px; color: var(--fg-2); min-width: 100px; text-align: center; }
.ed-canvas-area { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.ed-canvas-wrap { position: relative; display: inline-block; box-shadow: var(--shadow-lg); border-radius: 2px; background: white; cursor: crosshair; max-width: 100%; }
#edOvCanvas { position: absolute; top: 0; left: 0; }
.ed-text-input {
  position: absolute; background: rgba(255,255,255,.9); border: 1.5px dashed var(--primary);
  border-radius: 2px; padding: 2px 4px; outline: none; min-width: 80px; z-index: 10; line-height: 1.2;
}

/* === ORGANIZZA PAGE GRID === */
.summary { display: flex; justify-content: space-between; align-items: baseline; padding-bottom: 4px; }
.summary h2 { font-family: var(--font-display); font-size: 24px; font-weight: 700; letter-spacing: -.02em; }
.summary .count { font-family: var(--font-mono); font-size: 12px; color: var(--fg-2); }
.summary .sources { display: flex; gap: 6px; margin-top: 4px; flex-wrap: wrap; }
.source-chip { font-family: var(--font-mono); font-size: 10px; padding: 3px 8px; border-radius: var(--radius-pill); background: var(--surface); border: 1px solid var(--rule); color: var(--fg-2); display: inline-flex; align-items: center; gap: 5px; }
.source-chip .dot { width: 6px; height: 6px; border-radius: 50%; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 18px; }
.page-card { background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-md); overflow: hidden; cursor: grab; transition: var(--transition); position: relative; box-shadow: var(--shadow-sm); user-select: none; }
.page-card:hover { border-color: var(--border-strong); box-shadow: var(--shadow-md); transform: translateY(-2px); }
.page-card.selected { border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-soft), var(--shadow-md); }
.page-card.dragging { opacity: .35; cursor: grabbing; }
.page-card.drop-before { box-shadow: -3px 0 0 var(--primary), var(--shadow-md); }
.page-card.drop-after  { box-shadow:  3px 0 0 var(--primary), var(--shadow-md); }
.thumb { aspect-ratio: 1/1.35; background: var(--surface-warm); display: flex; align-items: center; justify-content: center; position: relative; overflow: hidden; }
.thumb canvas { max-width: 92%; max-height: 92%; box-shadow: 0 2px 8px rgba(8,47,59,.1); border-radius: 2px; }
.thumb .skeleton { width: 60%; height: 80%; background: linear-gradient(90deg, var(--surface) 0%, var(--surface-warm) 50%, var(--surface) 100%); background-size: 200% 100%; animation: shimmer 1.4s infinite; border-radius: 2px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }
.rot-badge { position: absolute; top: 8px; right: 8px; background: var(--fg-1); color: var(--surface); font-family: var(--font-mono); font-size: 10px; padding: 3px 7px; border-radius: var(--radius-pill); display: none; }
.page-card[data-rotation="90"] .rot-badge, .page-card[data-rotation="180"] .rot-badge, .page-card[data-rotation="270"] .rot-badge { display: block; }
.page-meta { padding: 10px 12px; display: flex; justify-content: space-between; align-items: center; gap: 8px; border-top: 1px solid var(--rule); }
.page-meta .num { font-family: var(--font-mono); font-size: 12px; font-weight: 500; }
.page-meta .src-tag { display: inline-flex; align-items: center; gap: 5px; font-size: 11px; color: var(--fg-2); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; flex: 1; justify-content: flex-end; }
.page-meta .src-tag .dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.empty { display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 48px 24px; text-align: center; color: var(--fg-3); font-size: 18px; }
footer.toolbar {
  position: fixed; bottom: 16px; left: 50%; transform: translateX(-50%);
  background: var(--surface); border: 1px solid var(--rule); border-radius: var(--radius-pill);
  padding: 10px 14px 10px 22px; display: flex; align-items: center; gap: 16px;
  box-shadow: var(--shadow-lg); z-index: 50; transition: var(--transition);
}
.toolbar .info { display: flex; align-items: center; gap: 10px; font-family: var(--font-mono); font-size: 12px; color: var(--fg-2); white-space: nowrap; }
.toolbar .divider { width: 1px; height: 22px; background: var(--rule); }
.toolbar .actions { display: flex; gap: 6px; }

@media (max-width: 768px) {
  .tool-main { padding: 24px 16px 80px; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 12px; }
}
