/* web/css/preview.css
 *
 * The browser preview pane.
 *
 * Linked from web/index.html in the order the sections had in the old
 * web/styles.css, and concatenated in that order they reproduce it exactly, so
 * the cascade is unchanged. A rule that moves between these files moves in the
 * cascade too: check what it now comes before and after.
 */

/* ── browser preview ─────────────────────────────────────────────────────
   web/preview.js. DevBrowser's toolbar, in this app's surfaces rather than its
   own: one row, controls left, address in the middle taking the slack, the
   viewport presets right. Everything below the bar is the canvas the device
   frame sits in. */

.preview {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
    min-width: 0;
    /* The bar's width is the pane's, not the window's: a Live board docked
       beside it takes a share the viewport never hears about. */
    container-type: inline-size;
}
.preview[hidden] { display: none; }

.pv-bar {
    flex: none;
    display: flex;
    align-items: center;
    gap: var(--sp-6);
    height: 52px;
    padding: 0 var(--sp-6);
    background: var(--s2);
    border-bottom: 1px solid var(--outline-soft);
}
/* Only the address bar gives: the button groups keep their size, or a narrow
   window squeezes them under it. */
.pv-nav { flex: none; display: flex; align-items: center; gap: var(--sp-1); }
.pv-divider { flex: none; width: 1px; height: 22px; background: var(--outline-soft); }

.pv-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: 0;
    border-radius: var(--r-xs);
    background: none;
    color: var(--text-2);
    cursor: pointer;
}
.pv-btn[hidden] { display: none; }
.pv-btn:hover:not(:disabled) { background: var(--s4); color: var(--text); }
.pv-btn:disabled { color: var(--text-4); opacity: 0.5; cursor: default; }
.pv-btn.on { background: var(--blue-cont); color: var(--blue); }

.pv-address {
    flex: 1;
    min-width: 120px;
    display: flex;
    align-items: center;
    height: 34px;
    padding: 0 var(--sp-6);
    border: 1px solid var(--outline-soft);
    border-radius: var(--r-sm);
    background: var(--s1);
    font: 400 var(--fs-md)/var(--lh-none) var(--mono);
    color: var(--text-3);
    cursor: text;
}
.pv-address:focus-within { border-color: var(--blue); }
.pv-title {
    flex: none;
    max-width: 200px;
    margin-right: var(--sp-5);
    padding: var(--sp-1) var(--sp-4);
    border-radius: var(--r-xs);
    background: var(--blue-tint);
    color: var(--blue);
    font: 500 var(--fs-xs)/var(--lh-snug) var(--sans);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}
.pv-title[hidden] { display: none; }
/* The Pages button carries a count once there is more than one page, and a dot
   while an agent is on one of them. */
.pv-pages { position: relative; flex: none; }
.pv-page-count {
    position: absolute;
    top: 1px;
    right: 0;
    min-width: 14px;
    height: 14px;
    padding: 0 3px;
    border-radius: var(--pill);
    background: var(--s5);
    color: var(--text);
    font: 600 var(--fs-2xs)/14px var(--sans);
    text-align: center;
}
.pv-page-count[hidden] { display: none; }
.pv-pages.agent::after {
    content: '';
    position: absolute;
    bottom: 4px;
    right: 4px;
    width: 7px;
    height: 7px;
    border-radius: 50%;
    background: var(--blue);
}
.pv-path {
    flex: 1;
    min-width: 40px;
    border: 0;
    outline: 0;
    padding: 0;
    background: none;
    color: var(--text);
    font: inherit;
}

.pv-sizes { flex: none; display: flex; align-items: center; gap: var(--sp-4); }
.pv-label { font: 500 var(--fs-xs)/var(--lh-none) var(--sans); color: var(--text-4); white-space: nowrap; }
.pv-group {
    display: flex;
    padding: var(--sp-1);
    border-radius: var(--r-sm);
    background: var(--s1);
}
.pv-size {
    border: 0;
    border-radius: var(--r-xs);
    padding: var(--sp-2) var(--sp-5);
    background: none;
    color: var(--text-3);
    font: 500 var(--fs-sm)/var(--lh-none) var(--sans);
    cursor: pointer;
}
.pv-size:hover { color: var(--text); }
.pv-size.on { background: var(--s4); color: var(--text); }

/* The presets' label is the first thing a narrow window can do without — the
   buttons say Phone, Tablet and Desktop on their own. */
@media (max-width: 1480px) { .pv-label { display: none; } }

/* Past that, the presets go, and then Screenshot and Pick. The right-hand group
   ends in Close, and `.main` clips what overflows — so anything that does not
   fit takes the way out of the preview with it. Close is the one control this
   bar may never lose. */
@container (max-width: 900px) {
    .pv-sizes, .pv-sizes + .pv-divider { display: none; }
}
@container (max-width: 600px) {
    .pv-nav:first-child .pv-divider,
    .pv-btn:is([data-pv="shot"], [data-pv="pick"]) { display: none; }
}

.pv-canvas {
    position: relative;
    flex: 1;
    min-height: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: var(--bg);
    transition: padding var(--dur-base) var(--ease-standard);
}
.pv-canvas.device-mode { padding: var(--sp-10); }

.pv-device {
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    height: 100%;
    background: #fff;
    /* 0.35s, longer than --dur-slow on purpose: a phone frame growing into a
       desktop one travels hundreds of pixels, and at 240ms that read as a jump. */
    transition: width 0.35s var(--ease-standard), height 0.35s var(--ease-standard),
        border-radius 0.35s, border-width 0.35s;
}
/* The bezels are drawn outside the size preview.js sets, so the page inside
   lays out at exactly the preset's pixels. DevBrowser's frames, recoloured. */
.pv-device:not(.fit) {
    box-sizing: content-box;
    border: 0 solid var(--s4);
    box-shadow: var(--shadow-dialog);
}
.pv-device.phone { border-radius: 36px; border-width: 14px 12px; }
.pv-device.tablet { border-radius: 20px; border-width: 16px; }
.pv-device.desktop { border-radius: 8px; border-width: 8px 8px 24px; }

.pv-notch, .pv-homebar { display: none; }
.pv-device.phone .pv-notch, .pv-device.phone .pv-homebar {
    display: block;
    position: absolute;
    z-index: 2;
    pointer-events: none;
}
.pv-device.phone .pv-notch {
    top: -12px; left: 50%; transform: translateX(-50%);
    width: 110px; height: 18px;
    background: var(--s4);
    border-radius: 0 0 12px 12px;
}
.pv-device.phone.landscape .pv-notch {
    top: 50%; left: -12px; transform: translateY(-50%);
    width: 18px; height: 110px;
    border-radius: 0 12px 12px 0;
}
.pv-device.phone .pv-homebar {
    bottom: 6px; left: 50%; transform: translateX(-50%);
    width: 100px; height: 4px;
    border-radius: 2px;
    background: #0004;
}
.pv-device.phone.landscape .pv-homebar {
    bottom: 50%; left: auto; right: 6px; transform: translateY(50%);
    width: 4px; height: 100px;
}

.pv-frames {
    position: relative;
    flex: 1;
    overflow: hidden;
    border-radius: inherit;
}
.pv-device.phone .pv-frames { border-radius: 24px; }
.pv-device.tablet .pv-frames { border-radius: 6px; }
.pv-device.desktop .pv-frames { border-radius: 0; }
.pv-frame {
    position: absolute;
    inset: 0;
    width: 100%;
    height: 100%;
    border: 0;
    background: #fff;
    /* Off-screen rather than display:none — see web/preview.js. */
    transform: translateY(-99999px);
    opacity: 0;
    pointer-events: none;
}
.pv-frame.active { transform: none; opacity: 1; pointer-events: auto; }
.pv-frames.picking { cursor: crosshair; }

.pv-badge {
    position: absolute;
    bottom: -30px;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    font: 400 var(--fs-xs)/var(--lh-none) var(--mono);
    color: var(--text-4);
}
.pv-badge[hidden] { display: none; }

.pv-empty {
    position: absolute;
    inset: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0;
    color: var(--text-3);
    font: 400 var(--fs-base)/var(--lh-snug) var(--sans);
    background: var(--bg);
}
.pv-empty[hidden] { display: none; }

/* Maximize: everything but the top bar and the preview's own toolbar. The rail
   column collapses to nothing and a docked Live board goes, so the page has the
   whole of the window below the bar. */
.app[data-preview-max="1"] {
    /* minmax, not 1fr: a bare 1fr is at least the top bar's content width, and
       with the rail gone that pushed the page off the right of the window. */
    grid-template-columns: minmax(0, 1fr);
    grid-template-areas: "bar" "main";
}
.app[data-preview-max="1"] .rail,
.app[data-preview-max="1"] #live { display: none; }
.app[data-preview-max="1"] .main { border-radius: 0; }

/* ── an agent driving the preview ─────────────────────────────────────────
   web/preview-agent.js. Under the toolbar and above the page, so whatever the
   agent does to the page cannot cover it: one bar per site an agent is asking
   to open, then the banner that says one is connected, with Stop. */

.pv-agent {
    flex: none;
    display: flex;
    flex-direction: column;
    border-bottom: 1px solid var(--outline-soft);
}
.pv-agent[hidden] { display: none; }

.pv-ask,
.pv-driving {
    display: flex;
    align-items: center;
    gap: var(--sp-4);
    min-height: 40px;
    padding: var(--sp-2) var(--sp-6);
    font: 400 var(--fs-md)/var(--lh-snug) var(--sans);
    color: var(--text);
}
.pv-ask { background: var(--yellow-cont); }
.pv-ask + .pv-ask { border-top: 1px solid var(--outline-soft); }
.pv-driving { background: var(--blue-cont); }
.pv-ask-text,
.pv-driving-text { flex: none; }
/* The full URL gives where the host alone would not; it is the part that gives. */
.pv-ask-url {
    flex: 1;
    min-width: 0;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    font: 400 var(--fs-sm)/var(--lh-none) var(--mono);
    color: var(--text-3);
}
.pv-driving-text { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.pv-ask-btn {
    flex: none;
    height: 28px;
    padding: 0 var(--sp-5);
    border: 1px solid var(--outline);
    border-radius: var(--r-xs);
    background: var(--s1);
    color: var(--text);
    font: 500 var(--fs-sm)/var(--lh-none) var(--sans);
    cursor: pointer;
}
.pv-ask-btn:hover { background: var(--s4); }
.pv-ask-btn.deny { color: var(--red); }

.pv-driving-dot {
    flex: none;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--blue);
}
/* Lit while commands are arriving, so "connected" and "doing something now"
   read differently. */
.pv-driving.active .pv-driving-dot { --pulse-dim: 0.25; animation: pulse var(--dur-loop) var(--ease-standard) infinite; }
@media (prefers-reduced-motion: reduce) {
    .pv-driving.active .pv-driving-dot { animation: none; }
}

/* ── the list of pages ───────────────────────────────────────────────────
   web/preview-menu.js, in the right-click menu's element. One row a page: a
   mark (a port's number, a site's first letter — no favicons, see the module),
   its title over its address and the session that opened it, and a flag for
   an agent on it or a site waiting on you. */
.ctx-menu[data-kind="pages"] { min-width: 300px; max-width: min(460px, calc(100vw - 16px)); }
.pvp-row { display: flex; align-items: center; gap: var(--sp-5); min-width: 0; width: 100%; text-align: left; }
.pvp-mark {
    flex: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 26px;
    height: 26px;
    padding: 0 var(--sp-2);
    border-radius: var(--r-xs);
    background: var(--s5);
    color: var(--text-2);
    font: 600 var(--fs-sm)/1 var(--sans);
}
.pvp-mark.port { font: 500 var(--fs-xs)/1 var(--mono); }
.pvp-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.pvp-label, .pvp-sub { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pvp-label { color: var(--text); font: 500 var(--fs-md)/var(--lh-snug) var(--sans); }
.pvp-sub { color: var(--text-3); font: 400 var(--fs-xs)/var(--lh-snug) var(--mono); }
.pvp-flag {
    flex: none;
    padding: var(--sp-1) var(--sp-3);
    border-radius: var(--pill);
    font: 500 var(--fs-xs)/var(--lh-none) var(--sans);
    color: var(--text-3);
    background: var(--s4);
}
.pvp-flag.agent { color: var(--blue); background: var(--blue-cont); }
.pvp-flag.ask { color: var(--text); background: var(--yellow-cont); }

/* The conversation's chips for the preview: the agent's page when it is off
   screen, and the list. In the port strip, so they borrow .channel's shape. */
.channel.pv-pages-chip { padding-right: var(--sp-3); }
.channel.pv-agent-chip { background: var(--blue-cont); padding-right: var(--sp-3); }
.channel.pv-agent-chip .led { background: var(--blue); --pulse-dim: 0.25; animation: pulse var(--dur-loop) var(--ease-standard) infinite; }
.channel.pv-agent-chip .name { max-width: 320px; color: var(--text-2); }
.channel.pv-agent-chip .name strong { color: var(--text); font-weight: 500; }
@media (prefers-reduced-motion: reduce) {
    .channel.pv-agent-chip .led { animation: none; }
}
