/* iPad photo entry points and Sheet Photo (Beta): js/sheet-photo.js.
   Everything here is scoped to elements that module creates, so no other
   layout (desktop, Classic, phone) is affected. Controls are at least 44 px
   for fingers; fields are 16 px so iPadOS does not zoom the page on focus. */

/* The pickers behind Take Photo / Choose Image: present for iPadOS, never seen. */
.ipad-photo-input { position: fixed; left: -200vw; top: 0; width: 1px; height: 1px; opacity: 0; pointer-events: none; }

#sheet-photo-dialog { margin: auto; padding: 0; width: min(96vw, 760px); max-height: calc(100dvh - 24px); overflow: auto; -webkit-overflow-scrolling: touch;
    color: var(--text-primary); background: var(--surface); border: 1px solid var(--border-color); border-radius: 14px; }
#sheet-photo-dialog::backdrop { background: rgba(0, 0, 0, .66); }
#sheet-photo-dialog [hidden] { display: none !important; }
#sheet-photo-dialog .sp-card { padding: 18px 20px calc(18px + env(safe-area-inset-bottom, 0px)); }
#sheet-photo-dialog .sp-kicker { font-size: .7rem; letter-spacing: .1em; color: var(--text-secondary); }
#sheet-photo-dialog h2 { margin: .2em 0 .4em; font-size: 1.35rem; outline: none; }
#sheet-photo-dialog h3 { margin: 14px 0 6px; font-size: 1rem; }
#sheet-photo-dialog p, #sheet-photo-dialog li { font-size: .9rem; line-height: 1.42; }
#sheet-photo-dialog p { margin: 8px 0; }
#sheet-photo-lead { font-weight: 600; min-height: 1.4em; }
#sheet-photo-dialog .sp-hint { font-size: .82rem; color: var(--text-secondary); }
#sheet-photo-dialog .sp-error { padding: 9px 12px; border: 1px solid #f87171; border-radius: 8px; background: rgba(239, 68, 68, .14); color: #fecaca; font-weight: 600; }
#sheet-photo-dialog .sp-notice { padding: 9px 12px; border: 1px solid var(--warning, #f59e0b); border-radius: 8px; background: rgba(245, 158, 11, .1); }
#sheet-photo-dialog .sp-facts, #sheet-photo-dialog .sp-warnings { margin: 8px 0; padding-left: 20px; }
#sheet-photo-dialog .sp-warnings li { margin: 4px 0; color: #fcd34d; }

#sheet-photo-dialog button, #sheet-photo-dialog select { min-height: 44px; }
#sheet-photo-dialog button:disabled { opacity: .5; }
#sheet-photo-dialog button:focus-visible, #sheet-photo-dialog input:focus-visible, #sheet-photo-dialog select:focus-visible,
#sheet-photo-strip summary:focus-visible, #sheet-photo-strip button:focus-visible, #sheet-photo-strip input:focus-visible { outline: 2px solid #93c5fd; outline-offset: 2px; }
#sheet-photo-dialog .sp-choices { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin: 14px 0 4px; }
#sheet-photo-dialog .sp-choices button { padding: 12px 14px; font-size: 1rem; }
#sheet-photo-dialog .sp-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 0; }
#sheet-photo-dialog .sp-row button, #sheet-photo-job-size { padding: 8px 14px; }
#sheet-photo-job-size { width: 100%; text-align: left; }

#sheet-photo-dialog .sp-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 9px 12px; align-items: end; }
#sheet-photo-dialog .sp-box { grid-template-columns: repeat(4, minmax(0, 1fr)) auto; margin-top: 10px; }
#sheet-photo-dialog .sp-grid label { display: flex; flex-direction: column; gap: 4px; font-size: .84rem; min-width: 0; }
#sheet-photo-dialog .sp-grid input, #sheet-photo-dialog .sp-grid select { min-width: 0; width: 100%; min-height: 44px; padding: 6px 9px; font-size: 16px;
    color: inherit; background: var(--background); border: 1px solid var(--border-color); border-radius: 6px; }

/* The photo. touch-action: none so a finger or Pencil places and drags
   corners instead of scrolling the dialog; scroll from anywhere around it. */
#sheet-photo-dialog .sp-stage { margin: 10px 0; display: flex; justify-content: center; background: var(--background); border: 1px solid var(--border-color); border-radius: 8px; overflow: hidden; }
#sheet-photo-dialog canvas { display: block; max-width: none; touch-action: none; -webkit-user-select: none; user-select: none; -webkit-touch-callout: none; }
#sheet-photo-canvas, #sheet-photo-marks { cursor: crosshair; }

#sheet-photo-dialog .sp-corners { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 8px; }
#sheet-photo-dialog .sp-corner { padding: 6px 8px; font-size: .84rem; color: var(--text-secondary); background: var(--background); border: 1px dashed var(--border-color); border-radius: 8px; }
#sheet-photo-dialog .sp-corner.is-set { color: var(--text-primary); border-style: solid; }
#sheet-photo-dialog .sp-corner[aria-pressed="true"] { border-color: #ffd166; box-shadow: inset 0 0 0 1px #ffd166; }

#sheet-photo-dialog .sp-list { list-style: none; margin: 6px 0; padding: 0; display: grid; gap: 6px; }
#sheet-photo-dialog .sp-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 6px 10px; border: 1px solid var(--border-color); border-radius: 8px; }
#sheet-photo-dialog .sp-list li span { flex: 1 1 200px; min-width: 0; }
#sheet-photo-dialog .sp-list button { padding: 6px 14px; }

#sheet-photo-dialog .sp-actions { position: sticky; bottom: 0; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 10px; margin: 14px -20px -18px; padding: 12px 20px calc(12px + env(safe-area-inset-bottom, 0px));
    background: var(--surface); border-top: 1px solid var(--border-color); }
#sheet-photo-dialog .sp-actions button { padding: 8px 18px; }

/* Controls for the placed photo: a small disclosure on the canvas, so it
   takes one chip of room until it is opened. */
#sheet-photo-strip { position: absolute; left: 10px; bottom: 10px; z-index: 5; max-width: calc(100% - 20px); font-size: .85rem; color: var(--text-primary);
    background: var(--surface); border: 1px solid var(--border-color); border-radius: 10px; touch-action: manipulation; }
#sheet-photo-strip summary { display: flex; align-items: center; gap: 8px; min-height: 44px; padding: 0 14px; cursor: pointer; list-style: none; font-weight: 600; }
#sheet-photo-strip summary::-webkit-details-marker { display: none; }
#sheet-photo-strip .sp-beta { padding: 1px 6px; border: 1px solid var(--border-color); border-radius: 999px; font-size: .68rem; font-weight: 600; letter-spacing: .04em; color: var(--text-secondary); }
#sheet-photo-strip .sp-strip-panel { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; padding: 0 12px 12px; max-width: 420px; }
#sheet-photo-strip .sp-strip-panel p { flex: 1 1 100%; margin: 0; font-size: .78rem; color: var(--text-secondary); }
#sheet-photo-strip input[type="range"] { flex: 1 1 120px; min-width: 100px; min-height: 44px; }
#sheet-photo-strip button { min-height: 44px; padding: 6px 14px; }
/* Touch layout: undo chips are top-left, the view cluster top-right, the tool
   pill mid-left and a docked panel can cover the left of the canvas, so the
   chip goes bottom-right, under the touch chrome (z 25). The line and measure
   bars (z 28) lie over it only while those tools are in use. */
body.layout-touch #sheet-photo-strip { left: auto; right: 8px; bottom: 12px; z-index: 24; max-width: calc(100% - var(--canvas-start, 0px) - 16px); }

/* Printing (browser Print, Save as PDF). The setup dialog and the chip never
   print. js/sheet-photo.js redraws the canvas without the photo, the marks and
   an iPad tracing photo when printing starts, and takes this class off; if a
   browser prints without telling the page, the class is still on and the
   canvas is left out rather than printed with the picture. A job without a
   photo never has the class, so its printing is unchanged. */
@media print {
    #sheet-photo-dialog, #sheet-photo-dialog::backdrop, #sheet-photo-strip { display: none !important; }
    body.sheet-photo-private #preview-canvas { visibility: hidden !important; }
}

@media (max-width: 560px) {
    #sheet-photo-dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; border-radius: 0; border-left: 0; border-right: 0; }
    #sheet-photo-dialog .sp-card { padding-left: 14px; padding-right: 14px; }
    #sheet-photo-dialog .sp-actions { margin-left: -14px; margin-right: -14px; padding-left: 14px; padding-right: 14px; }
    #sheet-photo-dialog .sp-grid, #sheet-photo-dialog .sp-box, #sheet-photo-dialog .sp-corners, #sheet-photo-dialog .sp-choices { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    #sheet-photo-dialog .sp-box button { grid-column: 1 / -1; }
    #sheet-photo-dialog .sp-actions button { flex: 1 1 auto; }
}
