/* PnPTools shared runtime UI — canonical copy lives in the hub's shared/
   folder and is copied into every tool by scripts/sync-shared.sh.
   Builds on the CSS variables defined by each tool's style.css. */

/* ---- Top bar ------------------------------------------------------------ */

.pnp-topbar {
    display: flex;
    align-items: center;
    gap: 16px;
    flex-wrap: wrap;
    margin: -6px 0 12px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
    font-size: 0.8rem;
}

.pnp-topbar a {
    text-decoration: none;
}

.pnp-home {
    font-weight: 700;
    color: var(--accent-hover);
    white-space: nowrap;
}

.pnp-home:hover {
    color: var(--text);
}

.pnp-tools {
    display: flex;
    gap: 4px;
    flex-wrap: wrap;
    flex: 1;
    min-width: 0;
}

.pnp-tool {
    padding: 4px 10px;
    border-radius: 999px;
    color: var(--text-dim);
    white-space: nowrap;
}

.pnp-tool:hover {
    color: var(--text);
    background: var(--surface2);
}

.pnp-tool.current {
    color: var(--text);
    background: var(--surface2);
    box-shadow: inset 0 0 0 1px var(--accent);
}

.pnp-actions {
    display: flex;
    align-items: center;
    gap: 6px;
}

.pnp-topbar .pnp-project-name {
    width: 130px;
    height: auto;
    margin: 0;
    padding: 4px 8px;
    line-height: 1.3;
    border-radius: 6px;
    font-size: 0.78rem;
    background: var(--surface2);
    color: var(--text);
    border: 1px solid var(--border);
}

.pnp-topbar .pnp-project-name:focus {
    outline: none;
    border-color: var(--accent);
}

.pnp-topbar button {
    white-space: nowrap;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--surface2);
    color: var(--text-dim);
    border: 1px solid var(--border);
}

.pnp-topbar button:hover:not(:disabled) {
    background: var(--surface2);
    color: var(--text);
    border-color: var(--accent);
    filter: none;
}

/* Also used on the hub page, outside .pnp-topbar, so it is fully styled here. */
.pnp-theme-toggle {
    padding: 4px 10px;
    border-radius: 6px;
    font: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    background: var(--surface2);
    color: var(--text-dim);
    border: 1px solid var(--border);
    cursor: pointer;
}

.pnp-theme-toggle:hover {
    color: var(--text);
    border-color: var(--accent);
}

.pnp-units {
    display: inline-flex;
    margin-right: 6px;
}

.pnp-units button {
    border-radius: 0;
}

.pnp-units button:first-child {
    border-radius: 6px 0 0 6px;
}

.pnp-units button:last-child {
    border-radius: 0 6px 6px 0;
    border-left: none;
}

.pnp-units button[aria-pressed="true"],
.pnp-units button[aria-pressed="true"]:hover:not(:disabled) {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

@media (max-width: 640px) {
    .pnp-tools {
        order: 3;
        flex-basis: 100%;
    }

    /* The actions wrap onto as many rows as they need; the project name
       takes what's left of its row. */
    .pnp-actions {
        flex-wrap: wrap;
        flex-basis: 100%;
    }

    .pnp-topbar .pnp-project-name {
        flex: 1 1 120px;
        width: auto;
        min-width: 0;
    }
}

/* ---- Unit proxy inputs --------------------------------------------------- */

.pnp-unit-real {
    display: none !important;
}

/* ---- Send to / Import ---------------------------------------------------- */

/* "Send to" label on its own line, all target buttons in one even row. */
.pnp-send {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(52px, 1fr));
    gap: 6px;
    margin-top: 10px;
}

/* Icon above the name keeps every target in one row in a narrow sidebar. */
.pnp-send .btn-small {
    flex-direction: column;
    gap: 2px;
    padding: 6px 4px;
    font-size: 0.72rem;
    min-width: 0;
}

.pnp-send-icon {
    font-size: 1rem;
    line-height: 1;
}

.pnp-send-label {
    grid-column: 1 / -1;
    font-size: 0.75rem;
    color: var(--text-dim);
}

.pnp-send .btn-small span {
    white-space: nowrap;
}

.pnp-import .btn-small {
    padding: 6px 10px;
    font-size: 0.78rem;
}

.pnp-import {
    position: relative;
    margin-top: 8px;
}

.pnp-import > .btn-small {
    width: 100%;
}

.pnp-popover {
    position: absolute;
    z-index: 50;
    top: calc(100% + 4px);
    left: 0;
    right: 0;
    max-height: 280px;
    overflow-y: auto;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 12px 30px var(--shadow);
    padding: 4px;
}

.pnp-popover[hidden] {
    display: none;
}

.pnp-popover.pnp-popover-floating {
    position: fixed;
    right: auto;
    z-index: 1000;
    text-align: left;
    cursor: default;
}

/* "Pick from Inputs & outputs" inside a drop zone. */
.dropzone .pnp-pick {
    margin-top: 8px;
}

.pnp-pick-btn {
    padding: 4px 10px;
    background: none;
    border: 1px solid var(--border);
    border-radius: 999px;
    color: var(--accent);
    font: inherit;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
}

.pnp-pick-btn:hover {
    border-color: var(--accent);
    background: var(--surface2);
}

.pnp-popover-browse {
    border-bottom: 1px solid var(--border);
    border-radius: 6px 6px 0 0;
}

.pnp-popover-row {
    display: flex;
    align-items: stretch;
}

.pnp-popover-item {
    flex: 1;
    display: block;
    text-align: left;
    padding: 8px 10px;
    background: none;
    color: var(--text);
    font-weight: 400;
    font-size: 0.8rem;
    border-radius: 6px;
}

.pnp-popover-item span {
    color: var(--text-dim);
}

.pnp-popover-item:hover {
    background: var(--surface);
}

.pnp-popover-remove {
    padding: 0 10px;
    background: none;
    color: var(--text-dim);
    font-size: 0.75rem;
}

.pnp-popover-remove:hover {
    color: var(--danger);
}

.pnp-popover-empty {
    padding: 10px;
    font-size: 0.8rem;
    color: var(--text-dim);
}

.pnp-popover-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-top: 4px;
    padding: 8px 10px 4px;
    border-top: 1px solid var(--border);
    font-size: 0.72rem;
    color: var(--text-dim);
}

.pnp-popover-footer .pnp-popover-clear {
    flex-shrink: 0;
    padding: 3px 8px;
}

.pnp-popover-heading {
    padding: 8px 10px 4px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
    color: var(--text-dim);
}

/* ---- Width ⇄ height swap ---------------------------------------------- */

.pnp-swap-row {
    align-items: flex-end;
}

/* Narrow screens stack .row fields; width ⇄ height stays on one line. */
@media (max-width: 1024px) {
    .row.pnp-swap-row {
        flex-direction: row;
    }
}

.row > .pnp-swap {
    flex: 0 0 auto;
    width: 30px;
    height: 38px;
    padding: 0;
    border-radius: 8px;
    font-size: 0.95rem;
    line-height: 1;
    background: var(--surface2);
    color: var(--text-dim);
    border: 1px solid var(--border);
    cursor: pointer;
}

.row > .pnp-swap:hover {
    color: var(--text);
    border-color: var(--accent);
    background: var(--surface2);
}

/* ---- Preview output (top bar) + viewer -------------------------------- */

.pnp-outputs {
    position: relative;
}

/* Also used on the hub page, outside .pnp-topbar, so it is fully styled here. */
.pnp-outputs-btn {
    padding: 4px 10px;
    border-radius: 6px;
    font: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    white-space: nowrap;
    background: var(--surface2);
    color: var(--text-dim);
    border: 1px solid var(--border);
    cursor: pointer;
}

.pnp-outputs-btn:hover {
    color: var(--text);
    border-color: var(--accent);
}

.pnp-outputs .pnp-popover {
    left: auto;
    right: 0;
    width: min(320px, calc(100vw - 32px));
    font-size: 0.8rem;
}

.pnp-viewer-open {
    overflow: hidden;
}

.pnp-viewer-backdrop {
    position: fixed;
    inset: 0;
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    background: rgba(0, 0, 0, 0.6);
}

.pnp-viewer {
    display: flex;
    flex-direction: column;
    width: min(1200px, 100%);
    height: min(860px, 100%);
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: 0 20px 60px var(--shadow);
    overflow: hidden;
}

.pnp-viewer-head {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 14px;
    border-bottom: 1px solid var(--border);
    font-size: 0.85rem;
}

.pnp-viewer-title {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pnp-viewer-title span,
.pnp-viewer-count {
    color: var(--text-dim);
}

.pnp-viewer-count {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.pnp-viewer-btn {
    padding: 4px 10px;
    border-radius: 6px;
    font: inherit;
    font-size: 0.78rem;
    font-weight: 600;
    background: var(--surface2);
    color: var(--text-dim);
    border: 1px solid var(--border);
    cursor: pointer;
}

.pnp-viewer-btn:hover {
    color: var(--text);
    border-color: var(--accent);
    background: var(--surface2);
}

.pnp-viewer-body {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: 220px minmax(0, 1fr);
}

/* ---- Library window --------------------------------------------------- */

.pnp-library-use:not(:disabled) {
    background: var(--accent);
    border-color: var(--accent);
    color: #fff;
}

.pnp-library-use:disabled {
    opacity: 0.5;
    cursor: default;
}

.pnp-library-body {
    flex: 1;
    min-height: 0;
    display: grid;
    grid-template-columns: minmax(0, 1fr) 260px;
}

.pnp-library-items {
    overflow-y: auto;
    padding: 12px 14px;
}

.pnp-library-batch + .pnp-library-batch {
    margin-top: 16px;
}

.pnp-library-batch-head {
    display: flex;
    align-items: baseline;
    flex-wrap: wrap;
    gap: 4px 8px;
    margin-bottom: 8px;
    font-size: 0.8rem;
}

.pnp-library-batch-head span {
    color: var(--text-dim);
}

.pnp-library-link {
    padding: 0;
    border: none;
    background: none;
    font: inherit;
    color: var(--accent-hover);
    cursor: pointer;
}

.pnp-library-link:hover {
    color: var(--text);
    background: none;
}

.pnp-library-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
    gap: 8px;
}

.pnp-library-tile {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 6px;
    border-radius: 8px;
    border: 2px solid transparent;
    background: var(--surface2);
    color: var(--text);
    font: inherit;
    font-size: 0.72rem;
    text-align: left;
    cursor: pointer;
}

.pnp-library-tile:hover {
    border-color: var(--border);
    background: var(--surface2);
}

.pnp-library-tile.selected {
    border-color: var(--accent);
}

.pnp-library-pic {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 96px;
    border-radius: 4px;
    background: repeating-conic-gradient(var(--checker, #ddd) 0% 25%, transparent 0% 50%) 50% / 12px 12px;
    overflow: hidden;
}

.pnp-library-pic img {
    max-width: 100%;
    max-height: 100%;
}

.pnp-library-name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.pnp-library-tags {
    color: var(--text-dim);
}

.pnp-library-props {
    overflow-y: auto;
    padding: 12px 14px;
    border-left: 1px solid var(--border);
    background: var(--surface2);
    font-size: 0.8rem;
}

.pnp-library-props-title {
    margin-bottom: 10px;
    font-weight: 600;
}

.pnp-library-hint {
    color: var(--text-dim);
}

.pnp-library-back {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 6px;
}

.pnp-library-back img {
    width: 40px;
    height: 40px;
    object-fit: contain;
    border-radius: 4px;
    background: var(--surface);
}

@media (max-width: 700px) {
    .pnp-library-body {
        grid-template-columns: 1fr;
        grid-template-rows: minmax(0, 1fr) auto;
    }

    .pnp-library-props {
        border-left: none;
        border-top: 1px solid var(--border);
        max-height: 45vh;
    }
}

/* ---- Image editor (crop and turn) --------------------------------------- */

.pnp-crop-backdrop {
    z-index: 910;
}

.pnp-viewer.pnp-crop {
    width: auto;
    height: auto;
    max-width: 100%;
}

.pnp-crop-stage {
    display: flex;
    justify-content: center;
    padding: 16px;
    background: var(--surface2);
}

.pnp-crop-canvas {
    max-width: 100%;
    touch-action: none;
    cursor: move;
}

.pnp-viewer-list {
    overflow-y: auto;
    padding: 8px;
    display: flex;
    flex-direction: column;
    gap: 4px;
    border-right: 1px solid var(--border);
    background: var(--surface2);
}

.pnp-viewer-thumb {
    display: grid;
    grid-template-columns: 48px minmax(0, 1fr);
    align-items: center;
    gap: 8px;
    padding: 4px;
    text-align: left;
    font: inherit;
    font-size: 0.75rem;
    font-weight: 400;
    color: var(--text-dim);
    background: none;
    border: 1px solid transparent;
    border-radius: 6px;
    cursor: pointer;
}

.pnp-viewer-thumb:hover {
    color: var(--text);
    background: var(--surface);
}

.pnp-viewer-thumb.selected {
    color: var(--text);
    background: var(--surface);
    border-color: var(--accent);
}

.pnp-viewer-thumb img {
    width: 48px;
    height: 48px;
    object-fit: contain;
}

.pnp-viewer-thumb span {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Checkerboard so transparent areas of the image are visible. */
.pnp-viewer-stage {
    position: relative;
    min-width: 0;
    min-height: 0;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 16px;
    background-color: var(--bg);
    background-image:
        linear-gradient(45deg, var(--surface2) 25%, transparent 25%, transparent 75%, var(--surface2) 75%),
        linear-gradient(45deg, var(--surface2) 25%, transparent 25%, transparent 75%, var(--surface2) 75%);
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
}

.pnp-viewer-img {
    flex: 1;
    min-height: 0;
    max-width: 100%;
    object-fit: contain;
}

.pnp-viewer-img[hidden],
.pnp-viewer-doc[hidden],
.pnp-viewer-none[hidden] {
    display: none;
}

.pnp-viewer-doc {
    flex: 1;
    width: 100%;
    min-height: 0;
    border: none;
    background: #ffffff;
}

.pnp-viewer-none {
    flex: 1;
    display: flex;
    align-items: center;
    color: var(--text-dim);
    font-size: 0.9rem;
}

.pnp-viewer-filetype {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 48px;
    height: 48px;
    flex: none;
    border: 1px solid var(--border);
    border-radius: 4px;
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-dim);
}

.pnp-viewer-caption {
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.75rem;
    color: var(--text-dim);
    background: var(--surface);
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

@media (max-width: 700px) {
    .pnp-viewer-backdrop {
        padding: 0;
    }

    .pnp-viewer {
        height: 100%;
        border-radius: 0;
    }

    .pnp-viewer-body {
        grid-template-columns: minmax(0, 1fr);
        grid-template-rows: minmax(0, 1fr) auto;
    }

    .pnp-viewer-list {
        order: 2;
        flex-direction: row;
        overflow-x: auto;
        overflow-y: hidden;
        border-right: none;
        border-top: 1px solid var(--border);
    }

    .pnp-viewer-thumb {
        grid-template-columns: 48px;
    }

    .pnp-viewer-thumb span {
        display: none;
    }
}

/* ---- Toasts ------------------------------------------------------------- */

.pnp-toasts {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    gap: 8px;
    max-width: min(420px, calc(100vw - 32px));
}

.pnp-toast {
    padding: 10px 14px;
    border-radius: 8px;
    background: var(--surface2);
    border: 1px solid var(--border);
    border-left: 4px solid var(--info);
    color: var(--text);
    font-size: 0.85rem;
    box-shadow: 0 8px 24px var(--shadow);
    transition: opacity 0.4s, transform 0.4s;
}

.pnp-toast.success { border-left-color: var(--success); }
.pnp-toast.error { border-left-color: var(--danger); }

.pnp-toast.leaving {
    opacity: 0;
    transform: translateY(8px);
}

/* ---- Keyboard focus for shared dropzones -------------------------------- */

.dropzone:focus-visible {
    outline: 2px solid var(--accent);
    outline-offset: 2px;
}

/* ---- Sub-page nav (tools with several pages) --------------------------- */

.tool-nav {
    display: flex;
    gap: 16px;
    margin-top: 6px;
}

/* ---- One-line tool heading ------------------------------------------------ */

/* Title, description and page links share one row under the top bar. The
   description is cut to fit (the full text is its tooltip, set by topBar()). */
header:has(> h1) {
    display: flex;
    flex-wrap: wrap;
    align-items: baseline;
    column-gap: 14px;
    padding-top: 14px;
    padding-bottom: 12px;
}

header:has(> h1) > .pnp-topbar {
    flex: 0 0 100%;
}

header:has(> h1) > h1 {
    flex: none;
    margin: 0;
    font-size: 1.15rem;
    white-space: nowrap;
}

header:has(> h1) > .subtitle {
    flex: 1 1 0;
    min-width: 0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

header:has(> h1) > .tool-nav {
    flex: none;
    margin: 0 0 0 auto;
}

@media (max-width: 700px) {
    header:has(> h1) > .subtitle {
        display: none;
    }
}

.nav-link {
    font-size: 13px;
    font-weight: 600;
    color: var(--accent);
    text-decoration: none;
}

.nav-link:hover {
    color: var(--accent-hover);
    text-decoration: underline;
}

.nav-link.current {
    color: var(--text-dim);
    pointer-events: none;
    text-decoration: none;
}
