/* ============================================================
   VLE PC — shared UI for tool pages: workspace, previews,
   controls, results. Loaded only on tool pages.
   ============================================================ */

.tool-panel {
    background: var(--bg-secondary);
    border: 1px solid var(--gray-100);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    padding: var(--space-6);
    margin-bottom: var(--space-4);
}

.tool-panel__title {
    font-size: var(--text-base);
    font-weight: 600;
    margin-bottom: var(--space-4);
}

/* Two columns on desktop, stacked on a phone. */
.tool-split {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 320px);
    gap: var(--space-4);
    align-items: start;
}

@media (max-width: 860px) {
    .tool-split { grid-template-columns: minmax(0, 1fr); }
}

/* ── File list / thumbnails ──────────────────────────────── */

.file-list {
    list-style: none;
    padding: 0;
    margin: 0;
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
}

.file-item {
    display: flex;
    align-items: center;
    gap: var(--space-3);
    padding: var(--space-2) var(--space-3);
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
}

.file-item__name {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font-weight: 500;
}

.file-item__size { color: var(--text-tertiary); font-size: var(--text-xs); flex-shrink: 0; }

.file-item__remove {
    color: var(--text-tertiary);
    line-height: 0;
    padding: var(--space-1);
    border-radius: var(--radius-sm);
    flex-shrink: 0;
}

.file-item__remove:hover { color: var(--error); background: var(--error-light); }

.thumb-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
    gap: var(--space-3);
}

.thumb {
    position: relative;
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-md);
    background: var(--gray-50);
    overflow: hidden;
    aspect-ratio: 3 / 4;
    display: grid;
    place-items: center;
    cursor: grab;
}

.thumb.dragging { opacity: .4; }
.thumb.selected { outline: 3px solid var(--primary-500); outline-offset: -3px; }
.thumb img, .thumb canvas { width: 100%; height: 100%; object-fit: contain; }

.thumb__label {
    position: absolute;
    left: var(--space-1);
    bottom: var(--space-1);
    background: rgba(15, 23, 42, .75);
    color: #fff;
    font-size: var(--text-xs);
    padding: 1px 6px;
    border-radius: var(--radius-full);
}

.thumb__action {
    position: absolute;
    top: var(--space-1);
    right: var(--space-1);
    background: rgba(15, 23, 42, .75);
    color: #fff;
    width: 22px;
    height: 22px;
    border-radius: var(--radius-full);
    display: grid;
    place-items: center;
    font-size: 13px;
    line-height: 1;
}

/* More than one action on the same thumb (e.g. card-cropper's download +
   redo): a positioned row holds them, each .thumb__action inside it sitting
   plainly rather than also trying to self-position to the same corner. */
.thumb__actions {
    position: absolute;
    top: var(--space-1);
    right: var(--space-1);
    display: flex;
    gap: 4px;
}
.thumb__actions .thumb__action {
    position: static;
    top: auto;
    right: auto;
}

/* ── Card-cropper: a captured side reads as a real, tilted card, not a
   plain thumbnail. Scoped under the .card-cropper wrapper class that only
   app/layout/card-cropper.php's markup carries — #dropzone and #sheetPanel
   are IDs several *other* tools also happen to reuse for their own upload
   zone / print-sheet panel, so scoping by ID alone would have leaked this
   styling onto their pages too. ── */

.card-cropper #capturedGrid {
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: var(--space-8);
    perspective: 900px;
    padding: var(--space-4) 0 var(--space-6);
}

/* The grid item is now this wrapper (card + a real download button below
   it), not the card itself — the card keeps its own 3D tilt regardless. */
.card-cropper #capturedGrid .captured-card {
    display: flex;
    flex-direction: column;
    gap: var(--space-4);
}

.card-cropper .captured-card__download--a {
    background: linear-gradient(135deg, #6366f1, #a855f7);
    color: #fff;
}
.card-cropper .captured-card__download--a:hover { filter: brightness(1.08); }

.card-cropper .captured-card__download--b {
    background: linear-gradient(135deg, #f97316, #ec4899);
    color: #fff;
}
.card-cropper .captured-card__download--b:hover { filter: brightness(1.08); }

.card-cropper #capturedGrid .thumb--card {
    cursor: default;
    border: none;
    padding: 5px;
    border-radius: var(--radius-xl);
    transform-style: preserve-3d;
    transform: rotateY(-22deg) rotateX(8deg) translateZ(0);
    box-shadow: 22px 26px 34px -16px rgba(30, 41, 59, .45), 4px 8px 14px rgba(30, 41, 59, .15);
    transition: transform .4s cubic-bezier(.2, .8, .2, 1), box-shadow .4s ease;
}

.card-cropper #capturedGrid .thumb--b.thumb--card { transform: rotateY(22deg) rotateX(8deg) translateZ(0); }

.card-cropper #capturedGrid .thumb--card:hover {
    transform: translateY(-8px) scale(1.05) rotateY(0deg) rotateX(0deg);
    box-shadow: 0 30px 46px -16px rgba(30, 41, 59, .4), 0 10px 20px rgba(30, 41, 59, .14);
}

.card-cropper #capturedGrid .thumb--a { background: linear-gradient(135deg, #6366f1, #a855f7); }
.card-cropper #capturedGrid .thumb--b { background: linear-gradient(135deg, #f97316, #ec4899); }

.card-cropper #capturedGrid .thumb--card img {
    border-radius: calc(var(--radius-xl) - 4px);
    background: #fff;
}

.card-cropper #capturedGrid .thumb__label { font-weight: 700; letter-spacing: .02em; padding: 3px 12px; }
.card-cropper #capturedGrid .thumb--a .thumb__label { background: #6366f1; }
.card-cropper #capturedGrid .thumb--b .thumb__label { background: #f97316; }

@media (max-width: 520px) {
    /* A 3D tilt needs room to read as depth, not just a skew — flatten it
       on a narrow phone screen where cards are already stacked close. */
    .card-cropper #capturedGrid .thumb--card,
    .card-cropper #capturedGrid .thumb--b.thumb--card { transform: none; }
    .card-cropper #capturedGrid .thumb--card:hover { transform: translateY(-2px); }
}

.card-cropper #dropzone {
    border-color: #a855f7;
    background: linear-gradient(135deg, #faf5ff, #fdf2f8);
}
.card-cropper #dropzone:hover, .card-cropper #dropzone.dragover {
    border-color: #ec4899;
    background: linear-gradient(135deg, #f3e8ff, #fce7f3);
}
.card-cropper #dropzone .dropzone__icon { color: #a855f7; }

.card-cropper #sheetPanel .preview {
    background-image: none;
    background: linear-gradient(160deg, #eef2ff, #fdf4ff);
}

/* ── Preview ─────────────────────────────────────────────── */

.preview {
    background: var(--gray-100);
    border-radius: var(--radius-md);
    padding: var(--space-4);
    display: grid;
    place-items: center;
    min-height: 200px;
    /* A checkerboard so transparent PNGs read as transparent, not white. */
    background-image:
        linear-gradient(45deg, var(--gray-200) 25%, transparent 25%),
        linear-gradient(-45deg, var(--gray-200) 25%, transparent 25%),
        linear-gradient(45deg, transparent 75%, var(--gray-200) 75%),
        linear-gradient(-45deg, transparent 75%, var(--gray-200) 75%);
    background-size: 16px 16px;
    background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.preview img, .preview canvas { max-height: 420px; box-shadow: var(--shadow-md); background: #fff; }

/* ── Controls ────────────────────────────────────────────── */

.control-row {
    display: flex;
    gap: var(--space-3);
    align-items: flex-end;
    flex-wrap: wrap;
}

.control-row > .field { flex: 1; min-width: 140px; margin-bottom: 0; }

.range {
    width: 100%;
    accent-color: var(--primary-600);
}

.chip-row { display: flex; flex-wrap: wrap; gap: var(--space-2); }

.chip {
    padding: var(--space-2) var(--space-3);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-full);
    background: var(--bg-secondary);
    font-size: var(--text-sm);
    font-weight: 500;
    color: var(--text-secondary);
    transition: all var(--transition-fast);
}

.chip:hover { border-color: var(--primary-300); color: var(--primary-700); }

.chip.active {
    background: var(--primary-600);
    border-color: var(--primary-600);
    color: #fff;
}

/* ── Result ──────────────────────────────────────────────── */

.result {
    border: 1px solid var(--success);
    background: var(--success-light);
    border-radius: var(--radius-lg);
    padding: var(--space-5);
}

.result__stats {
    display: flex;
    gap: var(--space-6);
    flex-wrap: wrap;
    margin-bottom: var(--space-4);
}

.result__stat-label { font-size: var(--text-xs); color: #065f46; opacity: .8; }
.result__stat-value { font-size: var(--text-xl); font-weight: 700; color: #065f46; }

/* ── Progress ────────────────────────────────────────────── */

.progress {
    height: 8px;
    background: var(--gray-200);
    border-radius: var(--radius-full);
    overflow: hidden;
}

.progress__bar {
    height: 100%;
    width: 0;
    background: var(--gradient-button);
    transition: width 200ms ease;
}

/* ── Toast ───────────────────────────────────────────────── */

.toast-stack {
    position: fixed;
    left: 50%;
    bottom: var(--space-6);
    transform: translateX(-50%);
    z-index: var(--z-toast);
    display: flex;
    flex-direction: column;
    gap: var(--space-2);
    width: min(420px, calc(100vw - var(--space-8)));
}

.toast {
    padding: var(--space-3) var(--space-4);
    border-radius: var(--radius-md);
    font-size: var(--text-sm);
    color: #fff;
    background: var(--gray-800);
    box-shadow: var(--shadow-lg);
    animation: toast-in 200ms ease;
}

.toast--error { background: var(--error); }
.toast--success { background: var(--success); }

@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}

/* ── Printable document output (the Marathi generators) ──── */

.doc-sheet {
    background: #fff;
    color: #000;
    font-family: var(--font-marathi);
    width: 210mm;
    min-height: 297mm;
    padding: 20mm 18mm;
    margin: 0 auto;
    box-shadow: var(--shadow-lg);
    line-height: 2;
    font-size: 12pt;
}

.doc-sheet h2 { text-align: center; font-size: 15pt; margin-bottom: 12mm; text-decoration: underline; }
.doc-sheet .doc-fill { font-weight: 600; border-bottom: 1px dotted #333; padding: 0 4px; }
/* An unfilled slot reads as a blank to write on, not as missing text. */
.doc-sheet .doc-fill--empty { font-weight: 400; color: #888; letter-spacing: 1px; }
.doc-sheet ol, .doc-sheet ul { padding-left: 8mm; }
.doc-sheet li { margin-bottom: 4mm; }
.doc-sheet .doc-head { text-align: right; margin-bottom: 8mm; }
.doc-sheet .doc-to { margin-bottom: 6mm; }
.doc-sheet table { width: 100%; border-collapse: collapse; margin: 6mm 0; }
.doc-sheet th, .doc-sheet td { border: 1px solid #333; padding: 2mm 3mm; text-align: left; font-size: 11pt; }
.doc-sheet .doc-sign { margin-top: 22mm; text-align: right; }

/* A checkbox slot in a document — ☑ / ☐, set by doc-generator.js's fill().
   No dotted underline: unlike a doc-fill text slot there is nothing here to
   write in by hand, so it should not look like a blank to fill. */
.doc-sheet .doc-check { font-size: 13pt; }

/* Multi-page sheets (doc-sheet--paged): each .doc-page is a whole, separate
   A4 sheet with its own margins, stacked with a visible break between them
   on screen and a real page break when printed — see doc-generator.js's
   captureCanvases(), which renders one image/PDF page per .doc-page instead
   of squeezing the whole stack onto a single page. */
.doc-sheet.doc-sheet--paged { padding: 0; min-height: 0; }

/* Denser than the default .doc-sheet line-height: 2 — a paged sheet already
   has two whole pages' worth of content to fit, and the wide default spacing
   (tuned for shorter single-page letters) pushed real, filled-in content
   past the page's own printed border. Scoped to --paged only; every
   single-page generator keeps its original spacing untouched. */
.doc-sheet--paged { line-height: 1.55; }
.doc-sheet--paged table { margin: 3mm 0; }
.doc-sheet--paged .doc-sign { margin-top: 10mm; }
.doc-sheet--paged p { margin: 0 0 3mm; }

.doc-sheet--paged .doc-page {
    box-sizing: border-box;
    width: 100%;
    min-height: 297mm;   /* a floor, not a ceiling — a short page's border still
                             reaches the full physical page, but real content
                             that runs long pushes the box (and its border)
                             taller instead of spilling out past a fixed edge */
    padding: 18mm;
}

/* An optional bordered frame just inside the page margin, matching a
   certificate-style printed form — wrap a page's content in this when the
   reference document it is modelled on has one. min-height, not height —
   see .doc-page above; a border on a box with a fixed height would clip or
   let content overflow past it instead of growing to actually contain it. */
.doc-sheet--paged .doc-page__inner {
    min-height: 261mm; /* 297mm minus .doc-page's own 18mm top+bottom padding */
    box-sizing: border-box;
    border: 1.25px solid #333;
    padding: 8mm;
}

.doc-sheet--paged .doc-page:not(:last-child) {
    border-bottom: 2px dashed var(--gray-200);
    page-break-after: always;
}

@media print {
    .doc-sheet--paged .doc-page:not(:last-child) { border-bottom: none; }
}

/* The photo box printed on the sheet itself — a dashed placeholder until a
   photo field's fill() swaps a real <img> in over it. */
.doc-sheet .doc-photo-slot {
    position: relative;
    width: 28mm;
    height: 34mm;
    margin: 0 auto;
    border: 1px dashed #666;
    overflow: hidden;
}
.doc-sheet .doc-photo-slot__placeholder {
    position: absolute; inset: 0;
    display: flex; align-items: center; justify-content: center;
    font-size: 9pt; color: #888; text-align: center; line-height: 1.4; padding: 2mm;
}
.doc-sheet .doc-photo-slot img { width: 100%; height: 100%; object-fit: cover; display: block; }

/* ── Photo field: upload-or-webcam picker in the form panel ──────────── */

.doc-photo-picker { display: flex; align-items: center; gap: var(--space-3); flex-wrap: wrap; }

.doc-photo-picker__preview {
    width: 72px; height: 90px; flex-shrink: 0;
    border: 1px dashed var(--gray-300); border-radius: var(--radius-md);
    background: var(--gray-50);
    display: flex; align-items: center; justify-content: center;
    overflow: hidden;
}
.doc-photo-picker__preview img { width: 100%; height: 100%; object-fit: cover; }
.doc-photo-picker__empty { font-size: 10px; color: var(--text-tertiary); text-align: center; padding: 0 4px; }

.doc-photo-picker__actions { display: flex; flex-direction: column; gap: var(--space-2); }

.doc-camera-overlay {
    position: fixed; inset: 0; z-index: var(--z-modal, 1000);
    background: rgba(0, 0, 0, .7);
    display: flex; align-items: center; justify-content: center;
    padding: var(--space-4);
}
.doc-camera-box {
    background: var(--bg-secondary); border-radius: var(--radius-lg);
    padding: var(--space-4); max-width: 380px; width: 100%;
}
.doc-camera-box video, .doc-camera-box canvas {
    width: 100%; border-radius: var(--radius-md); background: #000;
    aspect-ratio: 4 / 5; object-fit: cover; display: block;
}
.doc-camera-box__actions { display: flex; gap: var(--space-2); margin-top: var(--space-3); flex-wrap: wrap; }
.doc-camera-box__actions .btn { flex: 1 1 auto; }

/* The sheet is a fixed 210 mm so that print is exact. On screen it is scaled
   down by doc-generator.js to fit whatever width the column has — the scale
   is applied here, and undone for printing and for PDF capture. */
.doc-scroll { overflow-x: auto; padding: var(--space-4); background: var(--gray-100); border-radius: var(--radius-md); }
.doc-sheet { transform-origin: top left; }

@media print {
    body > *:not(.print-root) { display: none !important; }
    .print-root, .print-root * { visibility: visible; }
    .doc-scroll { overflow: visible; padding: 0; background: none; height: auto !important; }
    .doc-sheet {
        box-shadow: none; width: auto; min-height: 0; margin: 0; padding: 15mm;
        transform: none !important;
    }
    @page { size: A4; margin: 0; }
}
