/* cardcenter.app - centering tool (workspace, markers, loupe, controls).
   Loaded after styles.css on pages/tool.html only. Holo look via tokens.css. */

[hidden] { display: none !important; }

/* ----- Upload extras ----- */
.privacy-line { display: flex; align-items: center; justify-content: center; gap: 8px; color: var(--cc-muted); font-size: 0.8125rem; margin-top: 14px; }
.privacy-line svg { flex-shrink: 0; color: var(--cc-lime); }
.tip-line { color: var(--cc-muted); font-size: 0.8125rem; margin-top: 8px; }
.upload-zone .privacy-line { margin-bottom: 0; }

/* ----- Status toast (errors, info) ----- */
.tool-status {
    position: fixed; z-index: 1100; left: var(--pad-l); right: var(--pad-r);
    top: calc(var(--nav-h) + var(--safe-t) + 8px); max-width: 640px; margin-inline: auto;
    display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
    background: var(--cc-surface); border: 1px solid var(--cc-cyan); border-radius: var(--cc-radius-md);
    padding: 10px 8px 10px 14px; box-shadow: var(--cc-shadow-md);
    font-size: 0.875rem; color: var(--cc-text);
}
.tool-status.is-error { border-color: var(--cc-fail); }
.tool-status > span { flex: 1 1 200px; min-width: 0; }
.tool-status-btn { min-height: 44px; padding: 8px 16px; font-size: 0.875rem; }
.tool-status-close { width: 44px; height: 44px; background: none; border: 0; color: var(--cc-muted); font-size: 1.6rem; line-height: 1; cursor: pointer; border-radius: 50%; }

/* ----- Workspace shell ----- */
.workspace { display: none; max-width: 980px; margin: 0 auto; }
.workspace.active { display: block; padding-bottom: 40px; }
.workspace-layout { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
.canvas-column { min-width: 0; display: flex; flex-direction: column; }

.instructions-banner {
    background: rgba(34, 211, 238, 0.08); border: 1px solid rgba(34, 211, 238, 0.28);
    border-radius: var(--cc-radius-md); padding: 8px 12px; margin-bottom: 8px;
    font-size: 0.8125rem; color: var(--cc-muted); line-height: 1.45;
}
.hl-outer { color: var(--cc-cyan); font-weight: 700; }
.hl-inner { color: var(--cc-pink); font-weight: 700; }

.photo-warnings { border: 1px solid rgba(255, 200, 87, 0.5); background: rgba(255, 200, 87, 0.08); border-radius: var(--cc-radius-md); padding: 0 12px; margin-bottom: 8px; font-size: 0.8125rem; color: var(--cc-muted); }
.photo-warnings summary { min-height: 44px; display: flex; align-items: center; color: var(--cc-warn); font-weight: 600; cursor: pointer; }
.photo-warnings ul { padding: 0 0 10px 18px; max-height: 28dvh; overflow-y: auto; }
.photo-warnings li + li { margin-top: 6px; }

/* ----- Canvas ----- */
.canvas-container {
    position: relative; overflow: hidden; background: var(--cc-surface);
    border: 1px solid var(--cc-line); border-radius: var(--cc-radius-md);
    height: max(460px, calc(100dvh - 400px)); max-height: 900px;
    touch-action: none; /* the tool handles one-finger pan and two-finger pinch itself */
    user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
    overscroll-behavior: contain;
}
.canvas-container.drag-over { border-color: var(--cc-cyan); }
.canvas-container.panning { cursor: grabbing; }
.zoom-wrapper { position: absolute; left: 0; top: 0; transform-origin: 0 0; --ruler-scale: 1; -webkit-touch-callout: none; }
.zoom-wrapper canvas { display: block; width: 100%; height: 100%; -webkit-user-drag: none; }
.straighten-grid { position: absolute; inset: 0; pointer-events: none; display: none;
    background-image: linear-gradient(to right, rgba(255,255,255,0.35) 1px, transparent 1px), linear-gradient(to bottom, rgba(255,255,255,0.35) 1px, transparent 1px);
    background-size: 10% 10%; }
.straighten-grid.on { display: block; }

.side-empty { position: absolute; inset: 0; z-index: 5; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; padding: 20px; text-align: center; color: var(--cc-muted); }
.side-empty .upload-buttons { width: 100%; max-width: 320px; }

/* Draggable lines. Hit testing is done in JS (52px band, nearest line wins). */
.marker-line { position: absolute; z-index: 10; pointer-events: none; outline: none; }
.marker-outer { color: var(--cc-cyan); }
.marker-inner { color: var(--cc-pink); }
.marker-line.horizontal { left: 0; right: 0; height: calc(2px * var(--ruler-scale)); margin-top: calc(-1px * var(--ruler-scale)); }
.marker-line.vertical { top: 0; bottom: 0; width: calc(2px * var(--ruler-scale)); margin-left: calc(-1px * var(--ruler-scale)); }
.marker-line .line-visual { position: absolute; inset: 0; background: currentColor; }
/* inner lines are dashed so the two kinds differ by more than colour */
.marker-inner.horizontal .line-visual { background: repeating-linear-gradient(90deg, currentColor 0 calc(9px * var(--ruler-scale)), transparent calc(9px * var(--ruler-scale)) calc(14px * var(--ruler-scale))); }
.marker-inner.vertical .line-visual { background: repeating-linear-gradient(180deg, currentColor 0 calc(9px * var(--ruler-scale)), transparent calc(9px * var(--ruler-scale)) calc(14px * var(--ruler-scale))); }
.marker-line .label { display: none; position: absolute; white-space: nowrap; border-radius: calc(4px * var(--ruler-scale)); padding: calc(2px * var(--ruler-scale)) calc(6px * var(--ruler-scale)); font-family: var(--cc-font-mono); font-weight: 600; font-size: calc(12px * var(--ruler-scale)); line-height: 1.3; }
.marker-line .label { color: var(--cc-ink); }
.marker-outer .label { background: var(--cc-cyan); }
.marker-inner .label { background: var(--cc-pink); }
.marker-line.selected .label, .marker-line.dragging .label { display: block; }
.marker-line.horizontal .label { right: calc(8px * var(--ruler-scale)); bottom: calc(6px * var(--ruler-scale)); }
.marker-line.vertical .label { top: calc(8px * var(--ruler-scale)); left: calc(8px * var(--ruler-scale)); }
.marker-line.selected { z-index: 15; }
.marker-line.selected .line-visual { filter: brightness(1.2); box-shadow: 0 0 calc(6px * var(--ruler-scale)) currentColor; }
.marker-line.dragging { z-index: 20; }
.marker-line:focus-visible .line-visual { box-shadow: 0 0 0 calc(2px * var(--ruler-scale)) #fff, 0 0 calc(10px * var(--ruler-scale)) currentColor; }

/* Magnifier loupe (above the finger) */
.loupe { position: absolute; left: 0; top: 0; width: 120px; height: 120px; z-index: 30; pointer-events: none; border-radius: 50%; overflow: hidden; border: 3px solid #fff; background: var(--cc-bg); box-shadow: 0 6px 24px rgba(0, 0, 10, 0.7); }
.loupe canvas { width: 100%; height: 100%; display: block; }

.zoom-controls { position: absolute; z-index: 25; right: 8px; bottom: 8px; display: flex; flex-direction: column; gap: 6px; }
.zoom-controls button { width: 44px; height: 44px; border-radius: 50%; border: 1px solid var(--cc-line-2); background: rgba(20, 20, 58, 0.92); color: var(--cc-text); font-family: var(--cc-font-mono); font-size: 1.25rem; font-weight: 600; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.zoom-controls button:hover { border-color: var(--cc-cyan); }
#zoom-fit-btn { font-size: 0.8125rem; }

/* ----- Controls under the canvas ----- */
.tool-controls { display: grid; gap: 6px; padding-top: 8px; }
.ctrl-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--cc-line-2); border-radius: var(--cc-radius-pill); overflow: hidden; }
.seg button { min-height: 44px; min-width: 76px; padding: 0 16px; border: 0; background: transparent; color: var(--cc-text); font-family: var(--cc-font-display); font-weight: 700; font-size: 0.9rem; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.seg button[aria-pressed="true"] { background: var(--cc-lime); color: var(--cc-ink); }
.ctrl-btn { min-height: 44px; padding: 0 16px; border-radius: var(--cc-radius-pill); border: 1px solid var(--cc-line-2); background: transparent; color: var(--cc-text); font-family: var(--cc-font-display); font-weight: 600; font-size: 0.875rem; cursor: pointer; -webkit-tap-highlight-color: transparent; }
.ctrl-btn:hover { border-color: var(--cc-cyan); }
.ctrl-btn[aria-expanded="true"] { border-color: var(--cc-cyan); color: var(--cc-cyan); }
.ctrl-btn.sq { width: 44px; padding: 0; font-size: 1.2rem; }
.nudge-row { flex-wrap: wrap; justify-content: space-between; }
.line-select { flex: 1 1 110px; min-width: 0; min-height: 44px; display: inline-flex; align-items: center; gap: 8px; padding: 0 12px; border-radius: var(--cc-radius-md); border: 1px solid var(--cc-line-2); background: var(--cc-surface); color: var(--cc-text); font-size: 0.8125rem; font-weight: 600; text-align: left; cursor: pointer; }
.line-swatch { width: 18px; height: 4px; border-radius: 2px; flex-shrink: 0; background: var(--cc-cyan); }
.line-swatch.inner { background: repeating-linear-gradient(90deg, var(--cc-pink) 0 5px, transparent 5px 8px); }
.nudge-btns { display: flex; gap: 4px; }
.nudge { min-width: 46px; min-height: 44px; padding: 0 6px; border-radius: var(--cc-radius-sm); border: 1px solid var(--cc-line-2); background: var(--cc-surface); color: var(--cc-text); font-family: var(--cc-font-mono); font-size: 0.8125rem; font-weight: 600; cursor: pointer; white-space: nowrap; -webkit-tap-highlight-color: transparent; }
.nudge:active { background: var(--cc-line-2); }
.straighten-row input[type="range"] { flex: 1 1 auto; min-width: 60px; height: 44px; accent-color: var(--cc-cyan); }
.straighten-row { flex-wrap: nowrap; }
.angle-btn { min-width: 68px; padding: 0 8px; font-family: var(--cc-font-mono); font-size: 0.8125rem; }
.seg button:focus-visible, .ctrl-btn:focus-visible, .nudge:focus-visible, .line-select:focus-visible, .zoom-controls button:focus-visible, .tool-status-close:focus-visible { outline: 2px solid var(--cc-cyan); outline-offset: 2px; }

/* ----- Results ----- */
.results-panel { display: none; background: var(--cc-surface); border: 1px solid var(--cc-line); border-radius: var(--cc-radius-lg); padding: 24px; }
.results-panel h2 { font-size: 1.05rem; margin-bottom: 18px; display: flex; align-items: center; gap: 10px; }
.results-panel h3 { font-size: 0.9rem; margin-bottom: 12px; }
.side-badge { display: inline-block; font-family: var(--cc-font-mono); font-size: 0.75rem; font-weight: 600; text-transform: uppercase; letter-spacing: 0.06em; color: var(--cc-ink); background: var(--cc-cyan); border-radius: var(--cc-radius-pill); padding: 2px 10px; }
.ratio-display { text-align: center; margin-bottom: 14px; padding: 18px; background: var(--cc-bg); border: 1px solid var(--cc-line); border-radius: var(--cc-radius-md); }
.ratio-row { margin-bottom: 12px; }
.ratio-label { font-family: var(--cc-font-mono); font-size: 0.75rem; color: var(--cc-muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 4px; }
.ratio-value { font-family: var(--cc-font-mono); font-size: 1.75rem; font-weight: 600; letter-spacing: -0.02em; }
.ratio-dir { font-size: 0.75rem; color: var(--cc-muted); min-height: 1.2em; }
.ratio-note { font-size: 0.75rem; color: var(--cc-muted); }
.ratio-value.excellent, .mobile-ratio-value.excellent { color: var(--cc-lime); }
.ratio-value.good, .mobile-ratio-value.good { color: var(--cc-cyan); }
.ratio-value.fair, .mobile-ratio-value.fair { color: var(--cc-warn); }
.ratio-value.poor, .mobile-ratio-value.poor { color: var(--cc-fail); }
.borderline-chip { color: var(--cc-warn); font-size: 0.8125rem; font-weight: 600; margin: 0 0 12px; }

.grade-table { width: 100%; font-size: 0.875rem; }
.grade-table th { text-align: left; padding: 8px 6px; color: var(--cc-muted); font-family: var(--cc-font-mono); font-weight: 500; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em; border-bottom: 1px solid var(--cc-line); }
.grade-table td, .grade-table tbody th { padding: 10px 6px; border-bottom: 1px solid var(--cc-line); vertical-align: top; text-transform: none; letter-spacing: 0; font-family: inherit; }
.grade-table tr:last-child td, .grade-table tr:last-child th { border-bottom: none; }
.grade-table tbody th { color: var(--cc-text); font-size: 0.875rem; font-weight: 600; }
.grade-table .active-col { background: rgba(123, 92, 255, 0.14); }
.grade-table .company-name { font-weight: 600; display: flex; align-items: center; gap: 8px; }
.grade-logo { display: inline-block; height: 18px; width: auto; max-width: 52px; object-fit: contain; flex-shrink: 0; filter: brightness(0) invert(1); }
.grade-value { display: block; font-family: var(--cc-font-mono); font-weight: 700; font-size: 1rem; }
.grade-value.high, .mobile-grade-value.high { color: var(--cc-lime); }
.grade-value.mid, .mobile-grade-value.mid { color: var(--cc-warn); }
.grade-value.low, .mobile-grade-value.low { color: var(--cc-fail); }
.grade-desc { display: block; color: var(--cc-muted); font-size: 0.75rem; }
.grade-flag { display: block; color: var(--cc-warn); font-size: 0.75rem; font-weight: 600; }
.grade-none { color: var(--cc-muted); }

.marker-legend { margin-top: 20px; padding-top: 16px; border-top: 1px solid var(--cc-line); }
.marker-legend h3 { font-size: 0.85rem; color: var(--cc-muted); margin-bottom: 10px; }
.legend-item { display: flex; align-items: center; gap: 8px; margin-bottom: 6px; font-size: 0.875rem; color: var(--cc-muted); }
.legend-line { width: 24px; height: 3px; border-radius: 2px; flex-shrink: 0; }
.legend-line.outer { background: var(--cc-cyan); }
.legend-line.inner { background: repeating-linear-gradient(90deg, var(--cc-pink) 0 6px, transparent 6px 9px); }
.reset-btn { margin-top: 12px; width: 100%; }

/* ----- Mobile ratio bar + bottom sheet ----- */
.mobile-ratio-bar { background: rgba(20, 20, 58, 0.95); border: 1px solid var(--cc-line-2); border-radius: var(--cc-radius-md); padding: 6px 10px; margin-bottom: 8px; }
.mobile-ratio-row { display: flex; align-items: center; justify-content: center; }
.mobile-ratio-item { display: flex; align-items: center; justify-content: center; gap: 6px; flex: 1; min-width: 0; }
.mobile-ratio-label { font-family: var(--cc-font-mono); font-size: 0.75rem; font-weight: 600; color: var(--cc-muted); text-transform: uppercase; }
.mobile-ratio-value { font-family: var(--cc-font-mono); font-size: clamp(0.95rem, 4.6vw, 1.4rem); font-weight: 600; letter-spacing: -0.02em; white-space: nowrap; }
.mobile-ratio-divider { width: 1px; height: 26px; background: var(--cc-line-2); margin: 0 6px; flex-shrink: 0; }
.mobile-ratio-meta { display: flex; align-items: center; justify-content: center; gap: 8px; flex-wrap: wrap; margin-top: 2px; }
.mobile-ratio-meta .borderline-chip { margin: 0; font-size: 0.75rem; }
.side-badge { font-size: 0.6875rem; padding: 1px 8px; }

.mobile-drawer { background: var(--cc-surface); border-top: 1px solid var(--cc-line-2); border-radius: var(--cc-radius-lg) var(--cc-radius-lg) 0 0; box-shadow: 0 -8px 32px rgba(0, 0, 10, 0.55); padding-bottom: var(--safe-b); }
.mobile-drawer-toggle { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; width: 100%; min-height: 48px; padding: 6px 16px; background: none; border: 0; cursor: pointer; color: var(--cc-text); font-family: var(--cc-font-display); -webkit-tap-highlight-color: transparent; }
.drawer-handle { width: 40px; height: 4px; background: var(--cc-line-2); border-radius: 2px; }
.drawer-toggle-text { font-size: 0.95rem; font-weight: 700; color: var(--cc-cyan); }
.mobile-drawer.expanded .drawer-toggle-text { color: var(--cc-muted); }
.mobile-drawer-content { display: none; padding: 0 var(--pad-r) 12px var(--pad-l); max-height: min(40vh, 320px); max-height: min(40dvh, 320px); overflow-y: auto; }
.mobile-drawer-content.open { display: block; }
.mobile-grade-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-bottom: 10px; }
.mobile-grade-card { background: var(--cc-bg); border: 1px solid var(--cc-line); border-radius: var(--cc-radius-md); padding: 8px 10px; display: flex; align-items: center; gap: 8px; min-width: 0; }
.mobile-grade-logo { display: inline-block; height: 18px; width: auto; max-width: 40px; object-fit: contain; flex-shrink: 0; filter: brightness(0) invert(1); }
.mobile-grade-info { display: flex; flex-direction: column; min-width: 0; }
.mobile-grade-company { font-size: 0.75rem; color: var(--cc-muted); font-weight: 500; }
.mobile-sides { display: flex; gap: 8px; flex-wrap: wrap; }
.mobile-side { font-size: 0.6875rem; color: var(--cc-muted); white-space: nowrap; }
.mobile-side.on .mobile-side-n { color: var(--cc-text); font-weight: 700; }
.mobile-grade-value { font-family: var(--cc-font-mono); font-size: 1rem; font-weight: 700; }
.mobile-grade-label { font-size: 0.6875rem; color: var(--cc-muted); }
.mobile-drawer-actions { display: flex; gap: 8px; }
.mobile-drawer-actions .btn { flex: 1; min-height: 48px; font-size: 0.8125rem; padding: 8px 6px; }
.mobile-drawer .privacy-line { margin: 0 0 10px; font-size: 0.75rem; }

/* ----- Phones/tablets: app-style layout so nothing ever hides a line ----- */
@media (max-width: 899.98px) {
    .page-main.tool-page .page-header { padding: 14px 0 10px; }
    .page-main.tool-page .page-header p { font-size: 0.9rem; }
    body.tool-active { overflow: hidden; }
    .workspace.active {
        position: fixed; z-index: 50; left: 0; right: 0; bottom: 0;
        top: calc(var(--nav-h) + var(--safe-t));
        display: flex; flex-direction: column; padding: 8px var(--pad-r) 0 var(--pad-l);
        background: var(--cc-bg); max-width: none;
    }
    .workspace-layout { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; }
    .canvas-column { flex: 1 1 auto; min-height: 0; }
    .canvas-container { flex: 1 1 auto; min-height: 120px; height: auto; max-height: none; }
    .tool-controls { flex: none; }
    .mobile-ratio-bar, .instructions-banner, .photo-warnings { flex: none; }
    .mobile-drawer { flex: none; margin: 4px calc(var(--pad-r) * -1) 0 calc(var(--pad-l) * -1); }
    .photo-warnings ul { max-height: 22dvh; }
}
@media (max-width: 899.98px) and (max-height: 720px) {
    .instructions-banner { display: none; }
}
@media (max-width: 899.98px) {
    .workspace.has-moved .instructions-banner { display: none; }
}
/* Short landscape phones: canvas on the left, readings and grades on the right */
@media (max-width: 899.98px) and (orientation: landscape) and (max-height: 520px) {
    .workspace.active { display: grid; grid-template-columns: minmax(0, 1fr) 300px; grid-template-rows: auto auto minmax(0, 1fr); column-gap: 10px; }
    .workspace-layout { grid-column: 1; grid-row: 1 / span 3; }
    .mobile-ratio-bar { grid-column: 2; grid-row: 1; }
    .photo-warnings { grid-column: 2; grid-row: 2; }
    .mobile-drawer { grid-column: 2; grid-row: 3; overflow-y: auto; margin: 0; border-radius: var(--cc-radius-md); }
    .mobile-drawer-toggle { display: none; }
    .mobile-drawer-content { display: block; max-height: none; padding: 10px; }
    .mobile-grade-grid { grid-template-columns: 1fr; }
}

@media (min-width: 900px) {
    .workspace-layout { grid-template-columns: 1fr 340px; gap: 24px; }
    .results-panel { display: block; position: sticky; top: calc(var(--nav-h) + 16px); }
    .mobile-ratio-bar, .mobile-drawer { display: none; }
}

/* ----- Camera extras ----- */
.camera-note { position: absolute; z-index: 60; left: 12px; right: 12px; bottom: 12px; background: rgba(0, 0, 0, 0.75); color: #fff; padding: 8px 12px; border-radius: 10px; font-size: 0.8125rem; text-align: center; }

@media (prefers-reduced-motion: reduce) {
    .canvas-container, .marker-line, .loupe { transition: none !important; }
}
