/* Library, New label, Print & export, Settings. */

/* Library --------------------------------------------------------------------------- */
.lib-toolbar { display: flex; align-items: center; gap: 8px; height: 56px; flex: none; padding: 0 16px; background: var(--bg-panel); border-bottom: 1px solid var(--border); }
.lib-brand { display: flex; align-items: center; gap: 10px; margin-right: 8px; }
.lib-brand h1 { font-size: var(--fs-title); font-weight: 600; }
.lib-toolbar .search { flex: 1 1 160px; min-width: 120px; max-width: 260px; }
.lib-toolbar > * { flex-shrink: 0; }
.lib-toolbar > .search { flex-shrink: 1; }
@media (max-width: 1180px) { .lib-toolbar .btn-import .btn-label { display: none; } .lib-toolbar .btn-import { padding: 0 12px; } .lib-toolbar .select-wrap { width: 132px; } }
.lib-toolbar .select-wrap { width: 150px; flex: none; }
.lib-toolbar .seg { width: auto; flex: none; }
.lib-toolbar .seg-btn { flex: 0 0 auto; }
.lib-toolbar .seg:not(.seg--icons) .seg-btn { padding: 0 12px; }
.lib-toolbar .seg--icons .seg-btn { width: 36px; flex: none; }
.search { position: relative; display: block; }
.search > .icon { position: absolute; left: 10px; top: 50%; margin-top: -9px; color: var(--text-3); pointer-events: none; }
.topbar--lib { gap: 0; padding-left: 16px; }
.topbar--lib .topbar-title { margin-right: auto; }
.screen-library .topbar--lib { display: none; }
.lib-phone-search { display: none; }
[data-form="phone"] .screen-library .topbar--lib { display: flex; }
[data-form="phone"] .screen-library .lib-toolbar { display: none; }
[data-form="phone"] .lib-phone-search { display: flex; flex-direction: column; gap: 8px; padding: 8px 16px 8px; background: var(--bg-panel); border-bottom: 1px solid var(--border); }
.lib-scroll { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding: 16px; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }

.proj-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(208px, 1fr)); gap: 16px; align-content: start; }
.proj { position: relative; display: flex; flex-direction: column; background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; transition: border-color var(--t-fast) var(--ease); }
.proj:hover { border-color: var(--border-strong); }
.proj-link { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.proj-link:focus-visible { box-shadow: inset 0 0 0 2px var(--accent); }
.proj-thumb-wrap { display: flex; align-items: center; justify-content: center; height: 148px; padding: 20px; background: var(--bg-canvas); border-bottom: 1px solid var(--divider); }
.proj-thumb { width: 100%; height: 100%; object-fit: contain; opacity: 0; transition: opacity var(--t-state) var(--ease); filter: drop-shadow(0 1px 2px rgb(24 35 45 / 0.28)); }
.proj-thumb.is-loaded { opacity: 1; }
.proj-body { display: flex; flex-direction: column; gap: 2px; padding: 10px 12px 12px; min-width: 0; }
.proj-name { font-size: var(--fs-body); font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding-right: 28px; }
.proj-meta { display: flex; gap: 6px; font-size: var(--fs-help); color: var(--text-2); white-space: nowrap; overflow: hidden; }
.proj-meta time { min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.proj-body .badge { margin-top: 4px; }
.proj-more { position: absolute; right: 4px; top: calc(148px + 4px); width: 32px; height: 32px; }
.proj-trash-actions { display: flex; gap: 8px; padding: 0 12px 12px; }
.proj-trash-actions .btn { flex: 1; padding: 0 8px; }
.is-trashed .proj-thumb { opacity: 0.6; }
.proj-skel .proj-thumb-wrap { opacity: 0.6; }
.skel { display: block; height: 12px; border-radius: 4px; background: var(--bg-hover); }
.skel-a { width: 60%; height: 14px; margin: 4px 0 6px; }
.skel-b { width: 40%; }

/* List view (user choice, and always on phones) */
.screen-library[data-view="list"] .proj-list, [data-form="phone"] .proj-list { grid-template-columns: 1fr; gap: 0; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg-panel); overflow: hidden; }
.screen-library[data-view="list"] .proj, [data-form="phone"] .proj { flex-direction: row; align-items: center; border: 0; border-bottom: 1px solid var(--divider); border-radius: 0; }
.screen-library[data-view="list"] .proj:last-child, [data-form="phone"] .proj:last-child { border-bottom: 0; }
.screen-library[data-view="list"] .proj-link, [data-form="phone"] .proj-link { flex-direction: row; align-items: center; gap: 12px; padding: 8px 8px 8px 12px; }
.screen-library[data-view="list"] .proj-thumb-wrap, [data-form="phone"] .proj-thumb-wrap { flex: none; width: 88px; height: 64px; padding: 8px; border: 0; border-radius: var(--r-sm); }
.screen-library[data-view="list"] .proj-body, [data-form="phone"] .proj-body { padding: 0; flex: 1; }
.screen-library[data-view="list"] .proj-more, [data-form="phone"] .proj-more { position: static; margin-right: 4px; }
[data-form="phone"] .proj { min-height: 80px; }
[data-form="phone"] .proj-more { width: 44px; height: 44px; }
.screen-library[data-view="list"] .proj-trash-actions, [data-form="phone"] .proj-trash-actions { padding: 0 12px 0 0; flex: none; }
.screen-library[data-view="list"] .proj.is-trash, [data-form="phone"] .proj.is-trash { flex-wrap: wrap; }
[data-form="phone"] .proj.is-trash .proj-link { flex: 1 1 100%; }
[data-form="phone"] .proj.is-trash .proj-trash-actions { flex: 1 1 100%; padding: 0 12px 12px; }
.proj-skel { pointer-events: none; }
[data-form="phone"] .proj-skel .proj-thumb-wrap { margin: 8px 8px 8px 12px; }
[data-form="phone"] .proj-skel .proj-body { padding: 0 12px 0 0; }

.empty--first { padding-top: 56px; }
.tpl-quick { list-style: none; margin: 0; padding: 0; align-self: stretch; border: 1px solid var(--border); border-radius: var(--r-md); background: var(--bg-panel); overflow: hidden; text-align: left; }
.tpl-quick li + li { border-top: 1px solid var(--divider); }
.tpl-quick-btn { display: flex; align-items: center; gap: 12px; width: 100%; min-height: 48px; padding: 0 12px; border: 0; background: transparent; text-align: left; }
.tpl-quick-btn:hover { background: var(--bg-hover); }
.tpl-quick-name { font-weight: 600; color: var(--text); }
.tpl-quick-hint { flex: 1; color: var(--text-2); font-size: var(--fs-help); }

/* New label ----------------------------------------------------------------------------------- */
.nl { display: flex; flex-direction: column; min-height: 0; flex: 1; }
.nl-body { display: flex; flex-direction: column; gap: 16px; padding: 4px 16px 16px; overflow: auto; flex: 1; min-height: 0; }
.nl-actions { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 16px calc(12px + env(safe-area-inset-bottom)); border-top: 1px solid var(--divider); background: var(--bg-panel); }
[data-form="phone"] .nl-actions .btn { flex: 1; }
.nl-custom { display: grid; grid-template-columns: 1fr 1fr 96px; gap: 8px; }
.tpl-tiles { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
.tpl-tile { display: flex; flex-direction: column; gap: 6px; padding: 6px; border: 1px solid var(--border); border-radius: var(--r-sm); background: var(--bg-panel); text-align: center; }
.tpl-tile:hover { background: var(--bg-hover); }
.tpl-tile.is-on { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); background: var(--accent-soft); }
.tpl-tile-thumb { display: flex; align-items: center; justify-content: center; height: 56px; background: var(--bg-canvas); border-radius: 4px; padding: 6px; }
.tpl-tile-thumb img { max-width: 100%; max-height: 100%; width: 100%; height: 100%; object-fit: contain; filter: drop-shadow(0 1px 1px rgb(0 0 0 / 0.25)); }
.tpl-tile-name { font-size: var(--fs-label); font-weight: 500; line-height: 1.2; padding-bottom: 2px; }

/* Print & export ---------------------------------------------------------------------------------- */
.screen-print { background: var(--bg-app); }
.topbar--print { gap: 4px; }
.print-title { display: flex; flex-direction: column; min-width: 0; }
.print-title h1 { font-size: var(--fs-title); font-weight: 600; line-height: 1.2; }
.print-sub { font-size: var(--fs-help); color: var(--text-2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.print-tabs { display: none; margin: 8px 16px; flex: none; }
.print-body { flex: 1; min-height: 0; display: grid; grid-template-columns: minmax(320px, 380px) minmax(0, 1fr); }
.print-settings { min-height: 0; display: flex; flex-direction: column; background: var(--bg-panel); border-right: 1px solid var(--border); }
.ps-scroll { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; padding-bottom: calc(16px + env(safe-area-inset-bottom)); }
.ps-summary { padding: 14px 16px 4px; font-size: var(--fs-body); }
.ps-per { color: var(--text-2); }
.ps-warnings { padding: 0 16px; display: flex; flex-direction: column; gap: 6px; }
.ps-warnings:not(:empty) { padding-top: 8px; padding-bottom: 4px; }
.ps-warning { display: flex; gap: 8px; align-items: flex-start; padding: 8px 10px; border-radius: var(--r-sm); background: var(--warning-soft); color: var(--text); font-size: var(--fs-help); line-height: 1.4; }
.ps-warning .icon { color: var(--warning); margin-top: 1px; }
.ps-form .psec:first-child { border-top: 0; }
.ps-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.ps-pair .prop, .ps-custom .prop, .ps-manual .prop { grid-template-columns: minmax(0, 1fr); gap: 4px; align-items: stretch; }
.ps-custom, .ps-manual { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 12px; }
.ps-details > summary { cursor: default; font-size: var(--fs-body); padding: 4px 0; list-style: none; display: flex; align-items: center; gap: 6px; }
.ps-details > summary::before { content: ''; width: 6px; height: 6px; border-right: 1.5px solid var(--text-2); border-bottom: 1.5px solid var(--text-2); transform: rotate(-45deg); transition: transform var(--t-fast) var(--ease); }
.ps-details[open] > summary::before { transform: rotate(45deg); }
.ps-details > * + * { margin-top: 8px; }
.ps-details .btn { width: 100%; }
.ps-actions { padding: 16px; display: flex; flex-direction: column; gap: 12px; border-top: 1px solid var(--divider); }
.print-guidance { display: flex; gap: 8px; align-items: flex-start; padding: 10px; border-radius: var(--r-sm); background: var(--bg-sunken); font-size: var(--fs-help); color: var(--text-2); line-height: 1.4; }
.print-guidance strong { color: var(--text); }
.print-guidance .icon { margin-top: 1px; flex: none; }
.export-status:empty { display: none; }
.export-progress { display: flex; flex-direction: column; gap: 6px; font-size: var(--fs-help); color: var(--text-2); }
.export-done, .export-error { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; font-size: var(--fs-body); }
.export-done > .icon { color: var(--success); }
.export-done span { flex: 1 1 auto; font-weight: 500; }
.export-error { color: var(--error); align-items: flex-start; }
.print-sticky { display: none; }
.print-frame { position: fixed; width: 1px; height: 1px; right: 0; bottom: 0; border: 0; opacity: 0; pointer-events: none; }

.print-preview { min-height: 0; display: flex; flex-direction: column; background: var(--bg-canvas); }
.pv-head { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 6px 12px; background: var(--bg-panel); border-bottom: 1px solid var(--border); }
.pv-nav { display: flex; align-items: center; gap: 4px; font-size: var(--fs-label); }
.pv-pagenum { min-width: 90px; text-align: center; font-weight: 500; }
.pv-info { font-size: var(--fs-help); color: var(--text-2); }
.pv-scroll { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; container-type: size; }
.pv-pages { display: flex; flex-direction: column; align-items: center; gap: 20px; padding: 24px 16px calc(24px + env(safe-area-inset-bottom)); outline: none; }
/* Fit a whole page in view (like a PDF viewer's "fit page"), never wider than the pane. */
.pv-page { position: relative; flex: none; width: min(100%, 820px, calc((100cqh - 48px) * var(--page-w) / var(--page-h))); min-width: min(100%, 280px); background: #fff; box-shadow: var(--paper-shadow); }
.pv-label, .pv-slot, .pv-pick { position: absolute; display: block; }
.pv-label { object-fit: fill; pointer-events: none; }
.pv-slot { border: 1px dashed #B9C4CC; pointer-events: none; }
.pv-slot.is-used { background: repeating-linear-gradient(135deg, transparent 0 5px, rgb(24 35 45 / 0.07) 5px 6px); }
.pv-pick { padding: 0; border: 0; background: transparent; z-index: 2; cursor: pointer; border-radius: 2px; }
.pv-pick:hover { outline: 2px solid var(--select); outline-offset: -2px; background: var(--select-soft); }
.pv-pick.is-start { outline: 2px solid var(--select); outline-offset: -2px; }
.pv-pick:focus-visible { box-shadow: none; outline: 2px solid var(--accent); outline-offset: 1px; }

/* Print: tablet portrait / narrow stacks */
@media (max-width: 899px) { .print-body { grid-template-columns: minmax(300px, 340px) minmax(0, 1fr); } }
[data-form="phone"] .print-tabs { display: flex; }
[data-form="phone"] .print-body { display: block; position: relative; }
[data-form="phone"] .print-body > * { position: absolute; inset: 0; }
[data-form="phone"] .print-body[data-tab="settings"] .print-preview, [data-form="phone"] .print-body[data-tab="preview"] .print-settings { display: none; }
[data-form="phone"] .print-settings { border-right: 0; }
[data-form="phone"] .ps-actions .btn-row { display: none; }
[data-form="phone"] .print-sticky { display: flex; gap: 8px; flex: none; padding: 8px 16px calc(8px + env(safe-area-inset-bottom)); background: var(--bg-panel); border-top: 1px solid var(--border); }
[data-form="phone"] .print-sticky .btn { flex: 1; height: 48px; }
[data-form="phone"] .print-sticky .btn--primary { flex: 2; }
[data-form="phone"] .pv-page { width: 100%; }

/* Settings --------------------------------------------------------------------------------------------- */
.topbar--settings { gap: 4px; }
.settings-scroll { flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; }
.settings-col { max-width: 680px; margin: 0 auto; padding: 16px 16px calc(32px + env(safe-area-inset-bottom)); }
.sgroup { margin-bottom: 24px; }
.sgroup-title { font-size: var(--fs-section); font-weight: 600; color: var(--text-2); padding: 0 4px 8px; text-transform: uppercase; letter-spacing: 0.04em; }
.sgroup-body { background: var(--bg-panel); border: 1px solid var(--border); border-radius: var(--r-md); overflow: hidden; }
.srow { display: flex; align-items: center; justify-content: space-between; gap: 16px; padding: 12px 16px; border-bottom: 1px solid var(--divider); min-height: 56px; }
.sgroup-body > :last-child { border-bottom: 0; }
.srow--stack { flex-direction: column; align-items: stretch; }
.srow-text { min-width: 0; flex: 1; }
.srow-label { font-size: var(--fs-body); font-weight: 500; }
.srow-ctl { flex: none; max-width: 100%; }
.srow-ctl .seg { min-width: 240px; }
.srow-ctl .seg-btn { flex: 1 0 auto; }
.srow-value { color: var(--text-2); display: inline-flex; align-items: center; gap: 4px; }
.srow-value.ok { color: var(--success); }
.sync-status { display: flex; align-items: flex-start; gap: 12px; padding: 14px 16px; border-bottom: 1px solid var(--divider); }
.sync-status[data-status="synced"] .sync-icon, .sync-status[data-status="idle"] .sync-icon { color: var(--success); }
.sync-status[data-status="error"] .sync-icon { color: var(--error); }
.sync-status[data-status="conflict"] .sync-icon, .sync-status[data-status="waiting"] .sync-icon { color: var(--warning); }
.sync-icon { margin-top: 1px; color: var(--text-2); }
.sync-status-text { display: flex; flex-direction: column; gap: 2px; font-size: var(--fs-help); color: var(--text-2); }
.sync-status-text strong { font-size: var(--fs-body); color: var(--text); }
.sync-note { display: flex; gap: 8px; padding: 12px 16px; border-bottom: 1px solid var(--divider); }
.conflicts { padding: 14px 16px; border-bottom: 1px solid var(--divider); background: var(--warning-soft); display: flex; flex-direction: column; gap: 10px; }
.conflicts-title { display: flex; align-items: center; gap: 6px; font-size: var(--fs-body); font-weight: 600; }
.conflict { display: flex; flex-direction: column; gap: 6px; padding-top: 10px; border-top: 1px solid var(--divider); }
.conflict .btn-row { flex-wrap: wrap; }
.restore-result { display: flex; gap: 8px; align-items: flex-start; padding: 0 16px; font-size: var(--fs-help); }
.restore-result:not(:empty) { padding: 12px 16px; border-bottom: 1px solid var(--divider); }
.restore-result.is-ok { color: var(--success); }
.restore-result.is-error { color: var(--error); }
.storage-usage { padding: 14px 16px; border-bottom: 1px solid var(--divider); display: flex; flex-direction: column; gap: 8px; }
.storage-usage .progress { margin-top: 8px; }
.install-steps { display: flex; gap: 10px; padding: 14px 16px; color: var(--text-2); }
.about-text { padding: 12px 16px; border-bottom: 1px solid var(--divider); }
[data-form="phone"] .srow { flex-wrap: wrap; }
[data-form="phone"] .srow-ctl { width: 100%; }
[data-form="phone"] .srow-ctl .seg { width: 100%; }
[data-form="phone"] .srow-ctl .btn-row { width: 100%; }
[data-form="phone"] .srow-ctl .btn-row .btn { flex: 1; }
[data-form="phone"] .srow:has(.switch) { flex-wrap: nowrap; }
[data-form="phone"] .srow:has(.switch) .srow-ctl { width: auto; }
