/* Printshop workspace. Root rules are scoped to .uwapp-root.uwapp-printshop (the body carries .uwapp-printshop too).
   Own light/dark tokens (html[data-theme] / prefers-color-scheme); the preview "desk" stays neutral grey in both
   themes so white paper reads as paper. Transitions only under prefers-reduced-motion: no-preference. */
.uwapp-root.uwapp-printshop {
  --ps-bg: #f3f5f7; --ps-surface: #ffffff; --ps-surface-2: #e9eef2; --ps-ink: #17232c; --ps-muted: #4a5a66;
  --ps-line: #d2dbe2; --ps-control: #687b88; --ps-accent: #0b6e8a; --ps-accent-ink: #085a71; --ps-on-accent: #ffffff;
  --ps-magenta: #ad1457; --ps-warn: #9a3412; --ps-warn-bg: #fff4e5; --ps-focus: #b45309; --ps-desk: #c9d1d8; --ps-desk-2: #bcc5cd;
  background: var(--ps-bg); color: var(--ps-ink); color-scheme: light;
}
:root[data-theme="dark"] .uwapp-root.uwapp-printshop {
  --ps-bg: #0f1519; --ps-surface: #172128; --ps-surface-2: #213039; --ps-ink: #e7eef2; --ps-muted: #a9bac5;
  --ps-line: #2f414c; --ps-control: #7f95a3; --ps-accent: #5cc6e3; --ps-accent-ink: #8ad8ee; --ps-on-accent: #06222b;
  --ps-magenta: #f48fb1; --ps-warn: #fdba74; --ps-warn-bg: #2b1f12; --ps-focus: #fbbf24; --ps-desk: #26323a; --ps-desk-2: #1f2a31;
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .uwapp-root.uwapp-printshop {
    --ps-bg: #0f1519; --ps-surface: #172128; --ps-surface-2: #213039; --ps-ink: #e7eef2; --ps-muted: #a9bac5;
    --ps-line: #2f414c; --ps-control: #7f95a3; --ps-accent: #5cc6e3; --ps-accent-ink: #8ad8ee; --ps-on-accent: #06222b;
    --ps-magenta: #f48fb1; --ps-warn: #fdba74; --ps-warn-bg: #2b1f12; --ps-focus: #fbbf24; --ps-desk: #26323a; --ps-desk-2: #1f2a31;
    color-scheme: dark;
  }
}

/* Platform element defaults leak into app workspaces: reset them at zero specificity. */
:where(.ps-app) button { font: inherit; font-size: .9rem; font-weight: 600; padding: 0; border: 0; border-radius: 8px; background: none; color: inherit; cursor: pointer; width: auto; min-height: 0; }
:where(.ps-app) button:hover { background: none; }
:where(.ps-app) :is(input, select, textarea) { font: inherit; font-size: .92rem; color: var(--ps-ink); background: var(--ps-surface); border: 1px solid var(--ps-control); border-radius: 8px; padding: .4rem .55rem; width: 100%; box-sizing: border-box; min-height: 36px; margin: 0; }
:where(.ps-app) input[type="checkbox"] { width: 20px; height: 20px; min-height: 0; padding: 0; accent-color: var(--ps-accent); flex: none; }
:where(.ps-app) input[type="color"] { padding: 2px; height: 36px; cursor: pointer; }
:where(.ps-app) input[type="range"] { padding: 0; border: 0; background: none; accent-color: var(--ps-accent); }
:where(.ps-app) table { border-collapse: collapse; width: 100%; margin: 0; font-size: .9rem; }
:where(.ps-app) :is(th, td) { text-align: start; padding: 6px 8px; border-bottom: 1px solid var(--ps-line); }
:where(.ps-app) thead th { background: var(--ps-surface-2); color: var(--ps-ink); }
:where(.ps-app) kbd { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85em; padding: 1px 6px; border: 1px solid var(--ps-control); border-bottom-width: 2px; border-radius: 5px; background: var(--ps-surface-2); color: var(--ps-ink); white-space: nowrap; }
:where(.ps-app) :is(h2, h3) { color: var(--ps-ink); }
:where(.ps-app) a { color: var(--ps-accent-ink); }

.ps-app { display: flex; flex-direction: column; flex: 1; min-height: 0; background: var(--ps-bg); color: var(--ps-ink); }
.ps-app :focus-visible { outline: 3px solid var(--ps-focus); outline-offset: 2px; }
.ps-sr { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; border: 0; }
.ps-hint { color: var(--ps-muted); font-size: .84rem; margin: .25rem 0 .4rem; }
.ps-warn { color: var(--ps-warn); font-weight: 600; font-size: .9rem; }
.ps-note { font-size: .88rem; color: var(--ps-ink); background: var(--ps-surface-2); border-radius: 8px; padding: .55rem .75rem; }
.ps-mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: .85rem; }
.ps-wide { width: 100%; box-sizing: border-box; }
.ps-row { display: flex; flex-wrap: wrap; gap: .5rem; align-items: center; margin: .3rem 0; }

/* ---------- buttons */
.ps-btn { display: inline-flex; align-items: center; gap: .4rem; min-height: 36px; padding: .35rem .8rem; border: 1px solid var(--ps-control); border-radius: 8px; background: var(--ps-surface); color: var(--ps-ink); font-size: .88rem; white-space: nowrap; }
.ps-btn:hover:not([disabled]) { background: var(--ps-surface-2); }
.ps-btn[disabled], .ps-icon-btn[disabled] { opacity: .5; cursor: not-allowed; }
.ps-btn-primary, .ps-app button[type=submit].ps-btn-primary { background: var(--ps-accent); border-color: var(--ps-accent); color: var(--ps-on-accent); }
.ps-btn-primary:hover:not([disabled]) { background: var(--ps-accent-ink); border-color: var(--ps-accent-ink); color: var(--ps-on-accent); }
.ps-btn-small { min-height: 30px; padding: .2rem .6rem; font-size: .82rem; }
.ps-icon-btn { display: inline-grid; place-items: center; width: 36px; height: 36px; border: 1px solid transparent; border-radius: 8px; color: var(--ps-ink); flex: none; }
.ps-icon-btn:hover:not([disabled]) { background: var(--ps-surface-2); border-color: var(--ps-line); }

/* ---------- toolbar */
.ps-toolbar { flex: none; display: flex; flex-wrap: wrap; align-items: center; gap: .5rem 1rem; padding: .45rem .9rem; background: var(--ps-surface); border-bottom: 1px solid var(--ps-line); }
.ps-tb-group { display: flex; flex-wrap: wrap; align-items: center; gap: .3rem; min-width: 0; }
.ps-grow { flex: 1 1 12rem; }
.ps-name { max-width: 26rem; font-weight: 600; }
.ps-savestate { color: var(--ps-muted); font-size: .82rem; }
.ps-menu-wrap { position: relative; }
.ps-menu-btn { display: inline-flex; align-items: center; gap: .2rem; min-height: 36px; padding: .3rem .65rem; border-radius: 8px; color: var(--ps-ink); }
.ps-menu-btn:hover, .ps-menu-btn[aria-expanded="true"] { background: var(--ps-surface-2); }
.ps-menu { position: absolute; inset-inline-start: 0; top: calc(100% + 4px); z-index: 30; min-width: 16rem; max-width: min(24rem, 92vw); padding: .3rem; background: var(--ps-surface); border: 1px solid var(--ps-line); border-radius: 10px; box-shadow: 0 10px 30px rgb(0 0 0 / .18); }
.ps-menu[hidden] { display: none; }
.ps-menu-item { display: flex; justify-content: space-between; gap: 1rem; width: 100%; text-align: start; padding: .45rem .65rem; border-radius: 6px; font-weight: 500; }
.ps-menu-item:is(:hover, :focus) { background: var(--ps-surface-2); }
.ps-menu-item[aria-disabled="true"] { opacity: .5; cursor: not-allowed; }
.ps-menu-key { color: var(--ps-muted); font-size: .8rem; }
.ps-menu-sep { height: 1px; margin: .3rem .2rem; background: var(--ps-line); }

/* ---------- main layout */
.ps-main { flex: 1; min-height: 0; display: grid; grid-template-columns: 6.2rem minmax(17rem, 23rem) 1fr; }
.ps-nav { border-inline-end: 1px solid var(--ps-line); background: var(--ps-surface); overflow-y: auto; }
.ps-kinds { display: flex; flex-direction: column; gap: .25rem; padding: .5rem .35rem; }
.ps-kind { display: flex; flex-direction: column; align-items: center; gap: .2rem; padding: .5rem .2rem; border-radius: 10px; color: var(--ps-muted); font-size: .76rem; font-weight: 600; text-align: center; line-height: 1.15; border: 1px solid transparent; }
.ps-kind:hover { background: var(--ps-surface-2); color: var(--ps-ink); }
.ps-kind[aria-pressed="true"] { background: var(--ps-accent); color: var(--ps-on-accent); }
.ps-side { min-height: 0; overflow-y: auto; background: var(--ps-surface); border-inline-end: 1px solid var(--ps-line); }
.ps-settings { padding: .6rem .9rem 2rem; }
.ps-panel-title { font-size: 1.15rem; margin: .2rem 0 .1rem; }
.ps-section { border-top: 1px solid var(--ps-line); padding: .55rem 0 .35rem; margin-top: .5rem; }
.ps-section h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ps-muted); margin: 0 0 .35rem; }
.ps-field { display: flex; flex-direction: column; gap: .2rem; margin: .4rem 0; min-width: 0; }
.ps-field > label { font-size: .86rem; font-weight: 600; }
.ps-secret { display: grid; grid-template-columns: 1fr auto; gap: .2rem .4rem; align-items: center; }
.ps-secret > label, .ps-secret > .ps-hint { grid-column: 1 / -1; }
.ps-check { display: grid; grid-template-columns: auto 1fr; gap: .1rem .5rem; align-items: center; margin: .45rem 0; }
.ps-check > label { font-size: .88rem; }
.ps-check > .ps-hint { grid-column: 2; margin: 0; }
.ps-two { display: grid; grid-template-columns: 1fr 1fr; gap: 0 .6rem; align-items: end; }
.ps-imglist { margin: .4rem 0; padding-inline-start: 1.4rem; }
.ps-imglist li { display: flex; align-items: center; gap: .2rem; }
.ps-imglist li > span { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* ---------- preview */
.ps-preview { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.ps-previewbar { flex: none; display: flex; justify-content: space-between; flex-wrap: wrap; gap: .3rem; padding: .35rem .7rem; background: var(--ps-surface); border-bottom: 1px solid var(--ps-line); }
.ps-pageno { min-width: 7rem; text-align: center; font-size: .86rem; font-variant-numeric: tabular-nums; }
.ps-stage { flex: 1 1 0; min-height: 16rem; overflow: auto; display: grid; place-items: center; contain: size; padding: 16px; background: repeating-linear-gradient(45deg, var(--ps-desk) 0 12px, var(--ps-desk-2) 12px 24px); }
.ps-page { display: block; background: #ffffff; box-shadow: 0 2px 4px rgb(0 0 0 / .15), 0 12px 32px rgb(0 0 0 / .18); max-width: none; }
.ps-error { max-width: 30rem; padding: 1rem 1.2rem; border-radius: 10px; background: var(--ps-surface); color: var(--ps-ink); border: 2px solid var(--ps-warn); }
.ps-error p { margin: .4rem 0 0; }
.ps-below { flex: none; max-height: 40%; overflow-y: auto; padding: .4rem .9rem .6rem; background: var(--ps-surface); border-top: 1px solid var(--ps-line); font-size: .86rem; }
.ps-info p { margin: .15rem 0; color: var(--ps-muted); }
.ps-warnings { margin: .2rem 0 .4rem; padding: .45rem .7rem .45rem 1.6rem; background: var(--ps-warn-bg); color: var(--ps-warn); border-radius: 8px; font-weight: 600; }
.ps-warnings[hidden] { display: none; }
.ps-status { flex: none; min-height: 1.6rem; padding: .2rem .9rem; font-size: .84rem; color: var(--ps-muted); background: var(--ps-surface); border-top: 1px solid var(--ps-line); }

/* ---------- dialogs */
.ps-dialog { width: min(34rem, 94vw); max-height: 88vh; padding: 0; border: 1px solid var(--ps-line); border-radius: 14px; background: var(--ps-surface); color: var(--ps-ink); box-shadow: 0 24px 60px rgb(0 0 0 / .3); }
.ps-dialog-wide { width: min(50rem, 94vw); }
.ps-dialog::backdrop { background: rgb(10 20 28 / .5); }
.ps-dialog-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; padding: .75rem 1rem .4rem; }
.ps-dialog-head h2 { font-size: 1.15rem; margin: 0; }
.ps-dialog-lede { margin: 0 1rem .4rem; color: var(--ps-muted); font-size: .9rem; }
.ps-dialog-body { padding: .3rem 1rem 1rem; overflow-y: auto; }
.ps-dialog-actions { display: flex; flex-wrap: wrap; gap: .5rem; margin-top: .8rem; }
.ps-cards { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(14rem, 1fr)); gap: .7rem; }
.ps-card { display: flex; flex-direction: column; gap: .3rem; padding: .7rem .8rem; border: 1px solid var(--ps-line); border-radius: 10px; background: var(--ps-bg); }
.ps-card h3 { margin: 0; font-size: 1rem; }
.ps-card p { margin: 0 0 .3rem; flex: 1; font-size: .88rem; color: var(--ps-muted); }
.ps-card .ps-btn { align-self: flex-start; }
.ps-recent { list-style: none; margin: 0; padding: 0; }
.ps-recent li { display: flex; flex-wrap: wrap; align-items: center; gap: .5rem; padding: .5rem 0; border-bottom: 1px solid var(--ps-line); }
.ps-recent-text { flex: 1 1 14rem; display: flex; flex-direction: column; min-width: 0; }
.ps-badge { align-self: flex-start; font-size: .75rem; padding: 0 .4rem; border-radius: 999px; background: var(--ps-surface-2); }
.ps-tablewrap { overflow: auto; max-height: 50vh; border: 1px solid var(--ps-line); border-radius: 8px; }
.ps-tablewrap td { white-space: nowrap; }

/* ---------- narrow screens: kinds on top, preview, then settings */
@media (max-width: 900px) {
  .ps-main { display: flex; flex-direction: column; overflow-y: auto; }
  .ps-main > * { flex: none; }
  .ps-nav { border-inline-end: 0; border-bottom: 1px solid var(--ps-line); overflow-x: auto; overflow-y: hidden; }
  .ps-kinds { flex-direction: row; padding: .35rem; }
  .ps-kind { flex: none; min-width: 4.6rem; }
  .ps-preview { order: 1; }
  .ps-side { order: 2; overflow: visible; border-inline-end: 0; }
  .ps-stage { flex: none; height: min(70vh, 34rem); min-height: 0; }
  .ps-below { max-height: none; }
  .ps-name { max-width: none; }
}
@media (max-width: 420px) {
  .ps-two { grid-template-columns: 1fr; }
  .ps-toolbar { padding: .4rem .5rem; gap: .35rem .5rem; }
}
@media (prefers-reduced-motion: no-preference) {
  .ps-kind, .ps-btn, .ps-menu-item { transition: background-color .12s ease, color .12s ease; }
}
