/* Shared primitives. Feature-specific document geometry lives in styles.css. */
* { box-sizing: border-box; margin: 0; padding: 0; }
html { scroll-padding-top: 80px; }
body {
    margin: 0; min-height: 100dvh; max-width: none; overflow-x: visible;
    background: var(--background); color: var(--text-primary);
    font-family: var(--font-main); font-size: var(--text-body); line-height: 1.6;
    display: flex; flex-direction: column;
}
button, input, select, textarea { font: inherit; }
button, a, input, select, textarea { -webkit-tap-highlight-color: transparent; }
button, a { touch-action: manipulation; }
button { cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: .45; }
svg { flex-shrink: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent-bright); outline-offset: 3px; }
:where(input, textarea, select):focus-visible { outline-offset: 1px; }
a { color: var(--accent); }
h1, h2, h3 { line-height: 1.3; color: var(--text-primary); }
h1, #ws-tool-title { font-size: var(--text-title); font-weight: 700; letter-spacing: -.04em; }
h2 { font-size: var(--text-section); letter-spacing: -.02em; }
h3 { font-size: 1rem; font-weight: 600; }
.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;
}
.skip-link { position: fixed; top: 8px; left: 16px; transform: translateY(-160%); z-index: 200; background: var(--surface); padding: 12px 16px; border-radius: var(--radius-control); }
.skip-link:focus { transform: none; }
haz-upload, haz-feedback { display: contents; }
haz-footer { margin-top: auto; }
/* Button: primary, secondary, quiet, danger. Existing names are adapters. */
.btn, .btn-primary, .btn-secondary, .btn-action, .btn-success, .btn-cancel, .btn-submit,
.stitch-btn-primary, .stitch-btn-secondary, .btn-exit-studio, .pdfed-btn-exit,
.wm-studio-btn-primary, .wm-studio-btn-secondary, .compress-preview-btn,
.compress-download-btn, .compress-again-btn, .chatdoc-browse-btn, .chatdoc-changefile-btn,
.btn-add-more, .btn-clear-all, .btn-img-action, .btn-sm, .btn-icon {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: var(--control-height); max-width: 100%; padding: 8px 16px;
    border: 1px solid var(--border); border-radius: var(--radius-control);
    background: var(--surface); color: var(--text-primary);
    font-size: var(--text-body); font-weight: 600; line-height: 1.4;
    text-decoration: none; white-space: normal; box-shadow: none;
    transition: background-color var(--motion-fast), border-color var(--motion-fast), color var(--motion-fast);
}
:is(.btn-primary, .btn-action, .btn-success, .btn-submit, .stitch-btn-primary, .wm-studio-btn-primary, .compress-preview-btn, .compress-download-btn, .chatdoc-browse-btn) {
    background: var(--accent); color: var(--surface); border-color: var(--accent); box-shadow: none;
}
:is(.btn-primary, .btn-action, .btn-success, .btn-submit, .stitch-btn-primary, .wm-studio-btn-primary, .compress-preview-btn, .compress-download-btn, .chatdoc-browse-btn):hover:not(:disabled) {
    background: var(--accent-hover); border-color: var(--accent-hover); box-shadow: none; transform: none; filter: none;
}
:is(.btn, .btn-secondary, .btn-cancel, .stitch-btn-secondary, .wm-studio-btn-secondary, .btn-exit-studio, .pdfed-btn-exit, .btn-icon, .btn-img-action, .compress-again-btn):hover:not(:disabled) {
    background: var(--surface-secondary); color: var(--text-primary); border-color: var(--border-strong); transform: none; box-shadow: none;
}
:is(.btn, .btn-primary, .btn-secondary, .btn-action, .stitch-btn-primary, .stitch-btn-secondary):active:not(:disabled) { transform: translateY(1px); }
.btn-quiet, .btn-back, .btn-clear-all { background: transparent; border: 0; color: var(--text-secondary); padding: 8px; box-shadow: none; }
.btn-back { display: inline-flex; align-items: center; min-height: 40px; margin: 0 0 16px -8px; font-size: var(--text-small); text-decoration: none; }
.btn-back:hover { color: var(--accent); background: transparent; transform: none; }
.btn-danger, .btn-clear-all, .btn-icon-delete:hover { color: var(--danger); }
.btn-icon { width: var(--control-height); padding: 8px; flex-shrink: 0; }
.btn-large { padding: 12px 20px; font-size: var(--text-body); }
/* Input, Select, Checkbox, Radio and Toggle retain native keyboard behavior. */
:is(input[type=text], input[type=password], input[type=number], input[type=email], input[type=search], select, textarea, .form-control, .wm-text-field, .img-option-select, .md-option-select) {
    min-width: 0; max-width: 100%; min-height: var(--control-height);
    padding: 8px 12px; border: 1px solid var(--border-strong); border-radius: var(--radius-control);
    background: var(--surface); color: var(--text-primary); font-size: var(--text-body); line-height: 1.5; box-shadow: none;
}
textarea { resize: vertical; }
input::placeholder, textarea::placeholder { color: var(--text-muted); opacity: 1; }
input[type=checkbox], input[type=radio], input[type=range] { accent-color: var(--accent); }
input[type=checkbox], input[type=radio] { width: 18px; height: 18px; flex-shrink: 0; }
input[aria-invalid=true] { border-color: var(--danger); }
.form-group { margin-bottom: 20px; }
.form-group label, .img-option-group label, .md-option-label { font-size: var(--text-small); color: var(--text-secondary); font-weight: 600; }
.field-error { display: block; color: var(--danger); font-size: var(--text-small); margin-top: 8px; }
:is(.stitch-segmented, .wm-studio-segmented, .wm-pill-group, .compress-mode-toggle) {
    display: inline-flex; align-items: center; gap: 4px; padding: 4px; max-width: 100%;
    background: var(--surface-secondary); border: 1px solid var(--border); border-radius: var(--radius-control); box-shadow: none;
}
:is(.stitch-segmented-item, .wm-studio-seg-item, .wm-pill-item, .compress-mode-btn) {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 32px;
    padding: 6px 12px; border: 0; border-radius: var(--radius-sm); background: transparent;
    color: var(--text-secondary); font-size: var(--text-small); font-weight: 600; white-space: normal;
}
:is(.stitch-segmented-item, .wm-studio-seg-item, .compress-mode-btn).active, .wm-pill-input:checked + .wm-pill-item {
    background: var(--surface); color: var(--accent); box-shadow: none;
}
.stitch-segmented label { display: flex; position: relative; }
.stitch-segmented label:focus-within { outline: 2px solid var(--accent-bright); outline-offset: 2px; }
.stitch-segmented input[type=radio] { position: absolute; width: 1px; height: 1px; opacity: 0; }
.badge, .stitch-pill-badge, .wm-studio-pill-badge, .badge-pro, .badge-pro-card, .badge-new {
    display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px;
    border: 0; border-radius: var(--radius-sm); background: var(--surface-secondary); color: var(--text-secondary);
    font: 500 var(--text-caption)/1.5 var(--font-main); box-shadow: none; white-space: nowrap;
}
.stitch-pill-badge.success { color: var(--success); background: var(--success-surface); }
.stitch-pill-badge.amber { color: var(--warning); background: var(--warning-surface); }
/* Card and feedback surfaces. Paper previews are the only elevated cards. */
.card, .control-box, .file-preview-card { padding: 24px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: none; min-width: 0; }
.alert-info, .alert-success, .alert-warning, .alert-error, .info-box {
    padding: 12px 16px; border: 1px solid var(--border); border-radius: var(--radius-control); font-size: var(--text-body); line-height: 1.6; box-shadow: none;
}
.alert-info, .info-box { color: var(--text-secondary); background: var(--background); }
.alert-success { color: var(--success); background: var(--success-surface); }
.alert-warning { color: var(--warning); background: var(--warning-surface); }
.alert-error { color: var(--danger); background: var(--danger-surface); }
.process-loading { padding: 32px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: none; }
.progress-bar-fill, .compress-loading-fill { background: var(--accent-bright); }
.download-box { display: flex; flex-direction: column; align-items: center; gap: 16px; }
.download-box .alert-success { background: none; border: 0; color: var(--text-primary); font-weight: 600; padding: 0 0 16px; }
.download-box #btn-download { width: 100%; }
.download-box .result-actions { display: flex; justify-content: center; gap: 8px; margin-top: 16px; flex-wrap: wrap; }
/* Dialog and Sheet: shared focus management is in ui.js. */
.modal-overlay, .pdfed-sign-modal, .donate-overlay, #action-section.active-overlay {
    position: fixed; inset: 0; z-index: var(--z-modal); background: var(--overlay);
    padding: 24px; align-items: center; justify-content: center; backdrop-filter: none;
}
.modal-content, .pdfed-sign-panel, .donate-modal {
    width: 100%; max-width: 480px; max-height: calc(100dvh - 48px); overflow-y: auto;
    margin: auto; padding: 0; border: 1px solid var(--border); border-radius: var(--radius-modal);
    background: var(--surface); color: var(--text-primary); box-shadow: var(--shadow-popover);
}
.modal-header, .modal-body, .modal-footer { padding: 20px 24px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border-subtle); background: var(--surface); }
.modal-header h2 { font-size: var(--text-section); }
.modal-footer { display: flex; justify-content: flex-end; gap: 12px; border-top: 1px solid var(--border-subtle); background: var(--surface); }
.btn-close-modal, .toast-close, .donate-close { display: inline-flex; align-items: center; justify-content: center; width: 40px; min-height: 40px; border: 0; border-radius: var(--radius-control); background: transparent; color: var(--text-secondary); font-size: 1.25rem; }
.rating-stars { display: flex; justify-content: center; gap: 8px; padding: 20px 0; }
.star-btn { display: grid; place-items: center; width: 44px; height: 44px; padding: 0; border: 0; background: none; color: var(--border-strong); font-size: 2rem; }
.star-btn.active, .star-btn.hover { color: var(--accent); transform: none; }
.comment-label { display: block; margin-bottom: 8px; font-size: var(--text-small); }
.comment-textarea { width: 100%; min-height: 100px; }
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: var(--z-toast); display: flex; flex-direction: column; gap: 8px; max-width: min(400px, calc(100vw - 32px)); pointer-events: none; }
.toast { pointer-events: auto; display: flex; align-items: center; gap: 12px; padding: 12px 16px; width: 100%; background: var(--surface); color: var(--text-primary); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow-popover); font-size: var(--text-body); animation: ui-enter 140ms ease-out; }
.toast-message { min-width: 0; overflow-wrap: anywhere; flex: 1; }
.toast.error { border-left: 3px solid var(--danger); }
.toast.warning { border-left: 3px solid var(--warning); }
.toast.success { border-left: 3px solid var(--success); }
@keyframes ui-enter { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }
@media (max-width: 768px) {
    :root { --control-height: 44px; --text-title: 1.5rem; }
    :is(input[type=text], input[type=password], input[type=number], input[type=email], input[type=search], select, textarea, .form-control) { font-size: 1rem; }
    :is(.stitch-segmented-item, .wm-studio-seg-item, .compress-mode-btn) { min-height: 40px; }
    .modal-overlay, .pdfed-sign-modal, .donate-overlay, #action-section.active-overlay { padding: 16px; }
    .modal-content, .pdfed-sign-panel, .donate-modal { max-height: calc(100dvh - 32px); }
    .modal-header, .modal-body, .modal-footer { padding: 16px; }
    .modal-footer { flex-wrap: wrap; }
    .toast-container { left: 16px; right: 16px; bottom: calc(88px + env(safe-area-inset-bottom)); max-width: none; }
}
@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}
