/* Studio: "Achromatic ledger" app screen on the brand. Chrome in ink, the one data hue on the main data element,
   lime only as a small marker. 1px borders and row rules are allowed on app screens. */
.studio { --line: #e3e3dd; --line-2: #d3d3cb; --card: #ffffff; background: var(--paper); font-size: 15px; }
.studio .btn { min-height: 40px; font-size: 15px; padding: 0 16px; }

/* ---------- Top bar ---------- */
.tb {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 14px;
  height: 60px; padding: 0 16px; background: var(--paper); border-bottom: 1px solid var(--line);
}
.tb-back { width: 40px; height: 40px; display: grid; place-items: center; border-radius: var(--r); text-decoration: none; font-size: 20px; color: var(--ink); transition: background-color var(--t-hover); }
.tb-back:hover { background: var(--paper-2); }
.tb-name { display: flex; align-items: center; gap: 10px; min-width: 0; }
.tb-name h1 { font-size: 17px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill { font-size: 13px; padding: 2px 9px; border-radius: 999px; background: #e3eef2; color: #164f63; white-space: nowrap; }
.pill.is-yours { background: #edf7d2; color: #3b4f0e; }
.tb-right { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.quota { display: flex; align-items: center; gap: 10px; font-size: 14px; color: var(--soft); white-space: nowrap; }
.q-dots { display: flex; gap: 3px; }
.q-dots i { width: 8px; height: 14px; border-radius: 2px; background: var(--paper-3); transition: background-color 300ms; }
.q-dots i.used { background: var(--ink); }
.q-dots i.mail { box-shadow: inset 0 -3px 0 var(--lime); }

/* ---------- Layout ---------- */
.work-area { display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 12px; padding: 12px; align-items: start; }
.side { display: grid; gap: 12px; position: sticky; top: 72px; max-height: calc(100svh - 84px); overflow-y: auto; }
.blk { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; }
.blk-h { font-size: 15px; font-weight: 500; margin-bottom: 12px; }
.blk-p { font-size: 14px; color: var(--soft); margin: 10px 0; }
.blk-p a { color: var(--ink); }
.blk-other { padding: 12px 16px; }
.blk-other .blk-p { margin: 0; }
.warn-real { font-size: 13px; color: var(--soft); margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }

.seg { display: grid; grid-auto-flow: column; grid-auto-columns: 1fr; background: var(--paper-2); border-radius: 8px; padding: 3px; gap: 3px; }
.seg label { position: relative; }
.seg input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.seg span { display: block; text-align: center; padding: 8px 6px; border-radius: 6px; font-size: 14px; transition: background-color var(--t-hover), color var(--t-hover); }
.seg input:checked + span { background: var(--card); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06); }
.seg input:focus-visible + span { outline: 2px solid var(--ink); outline-offset: 1px; }
.seg-sm span { padding: 6px; font-size: 13px; }

.drop { display: grid; gap: 4px; padding: 20px 16px; margin-top: 12px; border: 1px dashed var(--line-2); border-radius: 8px; text-align: center; cursor: pointer; transition: background-color var(--t-hover), border-color var(--t-hover); }
.drop:hover, .drop.over { background: #f3f8ea; border-color: #9fbf44; }
.drop b { font-weight: 500; }
.drop span { font-size: 13px; color: var(--soft); }
.notices { display: grid; gap: 6px; margin-top: 10px; }
.notices li { font-size: 13px; padding: 8px 10px; border-radius: 6px; background: #e3eef2; color: #164f63; }
.notices li.bad { background: var(--bad-tint); color: var(--bad); }

.meta { display: grid; gap: 10px; }
.meta label { display: grid; gap: 4px; font-size: 13px; color: var(--soft); }
.meta input, .meta select { height: 36px; padding: 0 10px; border: 1px solid var(--line-2); border-radius: 6px; background: var(--card); font-size: 15px; color: var(--ink); }
.meta input:focus, .meta select:focus { outline: 2px solid var(--ink); outline-offset: -1px; border-color: transparent; }

.designs { display: grid; gap: 8px; }
.dcard { position: relative; display: grid; grid-template-columns: 64px 1fr; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 8px; cursor: pointer; transition: border-color var(--t-hover), background-color var(--t-hover); }
.dcard:hover { background: #fafaf7; }
.dcard input { position: absolute; opacity: 0; }
.dcard:has(input:checked) { border-color: var(--ink); box-shadow: inset 3px 0 0 var(--lime); }
.dcard:has(input:focus-visible) { outline: 2px solid var(--ink); outline-offset: 1px; }
.dthumb { width: 64px; height: 80px; border-radius: 4px; overflow: hidden; background: var(--paper-2); position: relative; }
.dthumb iframe { position: absolute; left: 0; top: 0; width: 794px; height: 993px; border: 0; transform: scale(0.0806); transform-origin: 0 0; pointer-events: none; }
.dname { font-weight: 500; font-size: 15px; }
.dline { font-size: 13px; color: var(--soft); line-height: 1.35; }
.both { display: flex; align-items: center; gap: 8px; margin-top: 10px; font-size: 14px; }
.both input { width: 18px; height: 18px; accent-color: var(--ink); }

/* ---------- Canvas ---------- */
.canvas { min-width: 0; }
.view { animation: viewIn 180ms var(--ease-out); }
@keyframes viewIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.v-edit { display: grid; grid-template-columns: minmax(0, 1fr) minmax(360px, 0.72fr); gap: 12px; align-items: start; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 16px; min-width: 0; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.card-h { font-size: 18px; font-weight: 500; }
.card-meta { font-size: 13px; color: var(--soft); }
.card-meta b { color: var(--ink); font-weight: 500; }
.card-meta .e { color: var(--bad); }

/* the rows grid */
.grid-scroll { overflow: auto; max-height: calc(100svh - 230px); border: 1px solid var(--line); border-radius: 8px; overscroll-behavior: contain; }
.grid { border-collapse: separate; border-spacing: 0; font-size: 14px; min-width: 100%; }
.grid th, .grid td { border-bottom: 1px solid #efefe9; border-right: 1px solid #f3f3ee; padding: 0; background: var(--card); }
.grid thead th { position: sticky; top: 0; z-index: 2; background: #fafaf7; font-weight: 400; color: var(--soft); font-size: 12px; text-align: left; padding: 8px 8px; white-space: nowrap; }
.grid thead th.grp { top: 0; }
.grid .rn { position: sticky; left: 0; z-index: 1; width: 40px; min-width: 40px; text-align: center; color: var(--soft); font-size: 12px; background: #fafaf7; }
.grid thead .rn { z-index: 3; }
.grid tr.on td, .grid tr.on .rn { background: #f1f7fa; }
.grid tr.on .rn { box-shadow: inset 3px 0 0 var(--data); color: var(--data); font-weight: 500; }
.grid td input, .grid td select {
  width: 100%; min-width: var(--w, 150px); height: 36px; border: 0; padding: 0 8px; background: transparent; font-size: 14px; color: var(--ink); font-feature-settings: "tnum" 1;
}
.grid td.num input { text-align: right; }
.grid td input:focus, .grid td select:focus { outline: 2px solid var(--data); outline-offset: -2px; background: var(--card); }
.grid td.err input { background: var(--bad-tint); color: var(--bad); }
.grid td.wrn input { background: var(--warn-tint); }
.grid td.err.shake input { animation: shake 240ms 1; }
@keyframes shake { 25% { transform: translateX(-3px); } 75% { transform: translateX(3px); } }
.grid .act { width: 40px; text-align: center; }
.grid .del, .grid .sub { width: 32px; height: 32px; border: 0; border-radius: 6px; background: transparent; color: var(--soft); font-size: 16px; }
.grid .del:hover, .grid .sub:hover { background: var(--paper-2); color: var(--ink); }
.grid .sub { width: auto; padding: 0 8px; font-size: 13px; white-space: nowrap; }
.grid tr.subrow > td { padding: 10px 10px 12px 48px; background: #fbfbf8; }
.subgrid { border-collapse: collapse; font-size: 13px; }
.subgrid th { font-weight: 400; color: var(--soft); text-align: left; padding: 4px 6px; font-size: 12px; }
.subgrid td { border: 1px solid #ecece6; padding: 0; background: var(--card); }
.subgrid td input, .subgrid td select { height: 32px; font-size: 13px; }
.grid-foot { display: flex; align-items: flex-start; gap: 12px; margin-top: 12px; flex-wrap: wrap; }
.issues { flex: 1; display: grid; gap: 4px; font-size: 13px; max-height: 120px; overflow-y: auto; }
.issues li { display: flex; gap: 8px; }
.issues li button { border: 0; background: none; padding: 0; text-align: left; color: inherit; text-decoration: underline; text-underline-offset: 2px; }
.issues .e { color: var(--bad); } .issues .w { color: var(--warn); }

/* preview */
.prev-card { position: sticky; top: 72px; }
.prev-ctl { display: flex; align-items: center; gap: 6px; }
.ic { width: 34px; height: 34px; border: 0; border-radius: 6px; background: var(--paper-2); font-size: 18px; line-height: 1; transition: background-color var(--t-hover); }
.ic:hover { background: var(--paper-3); }
.ic:active { transform: scale(0.95); }
.prev-who { font-size: 14px; min-width: 9ch; text-align: center; max-width: 22ch; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.a4 { position: relative; margin-top: 10px; height: calc(100svh - 240px); min-height: 460px; background: var(--paper-2); border-radius: 8px; overflow: hidden; perspective: 1400px; }
.a4 iframe { position: absolute; left: 0; top: 0; border: 0; background: var(--card); transform-origin: 0 0; transition: opacity 200ms var(--ease-out), rotate 400ms var(--ease-out); }
.a4 iframe.fading { opacity: 0.25; }
.a4-msg { position: absolute; inset: 0; display: grid; place-items: center; padding: 24px; text-align: center; color: var(--soft); background: var(--paper-2); }

/* run */
.run-card { max-width: 720px; margin: 8vh auto 0; padding: 28px; }
.run-sub { color: var(--soft); margin: 6px 0 18px; }
.bar { height: 4px; border-radius: 2px; background: var(--paper-2); overflow: hidden; }
.bar i { display: block; height: 100%; width: 100%; background: var(--data); transform-origin: left; transform: scaleX(0); transition: transform 400ms var(--ease-out); }
.stages { margin-top: 18px; display: grid; gap: 2px; }
.stages li { display: grid; grid-template-columns: 24px 1fr auto; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid #efefe9; color: var(--soft); }
.stages li.now { color: var(--ink); }
.stages li.done { color: var(--ink); }
.stages svg { width: 18px; height: 18px; }
.stages .tick { stroke: var(--data); stroke-width: 2.4; fill: none; stroke-dasharray: 20; stroke-dashoffset: 20; transition: stroke-dashoffset 220ms var(--ease-out); }
.stages li.done .tick { stroke-dashoffset: 0; }
.stages .spin { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--paper-3); border-top-color: var(--data); animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.stages time { font-size: 13px; color: var(--soft); font-feature-settings: "tnum" 1; }

/* results */
.res-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.res-notes { display: grid; gap: 6px; margin-bottom: 12px; }
.res-notes li { font-size: 14px; padding: 8px 12px; border-radius: 6px; background: #e3eef2; color: #164f63; }
.res-notes li.bad { background: var(--warn-tint); color: var(--warn); }
.tiles { display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 10px; }
.tile-doc { border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--card); transition: border-color var(--t-hover), transform var(--t-press) var(--ease-out); }
.tile-doc:hover { border-color: var(--line-2); }
.tile-doc button { display: block; width: 100%; border: 0; padding: 0; background: none; text-align: left; }
.tile-doc button:active { transform: scale(0.98); }
.td-pic { position: relative; height: 200px; overflow: hidden; background: var(--paper-2); }
.td-pic iframe { position: absolute; left: 0; top: 0; width: 794px; height: 1123px; border: 0; transform-origin: 0 0; pointer-events: none; }
.td-txt { padding: 10px 12px 12px; }
.td-name { font-weight: 500; font-size: 14px; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.td-meta { font-size: 12px; color: var(--soft); }
.td-meta .ok { color: var(--data); }
.td-meta .no { color: var(--warn); }
.viewer { margin-top: 12px; }
.panes { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pane { min-width: 0; }
.pane-h { font-size: 13px; font-weight: 400; color: var(--soft); margin-bottom: 6px; }
.pane-body { height: calc(100svh - 200px); min-height: 520px; border: 1px solid var(--line); border-radius: 8px; overflow: auto; background: var(--paper-2); }
.pane-body iframe { width: 100%; height: 100%; border: 0; background: var(--card); }
.pdf-body { padding: 12px; display: grid; gap: 12px; align-content: start; }
.pdf-body canvas { width: 100%; height: auto; background: #fff; border-radius: 2px; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08); }
.pdf-body .pdf-msg { color: var(--soft); font-size: 14px; padding: 8px; }
.pdf-body .pdf-frame { position: relative; width: 100%; aspect-ratio: 210 / 297; background: #fff; overflow: hidden; }
.pdf-body .pdf-frame iframe { position: absolute; left: 0; top: 0; width: 794px; height: 1123px; transform-origin: 0 0; border: 0; }
.ic-close { font-size: 20px; }

/* locked */
.lock-card { max-width: 640px; margin: 8vh auto 0; padding: 28px; }
.lock-p { color: var(--soft); margin: 8px 0 18px; }

/* e-mail gate */
.gate { border: 0; border-radius: 12px; padding: 0; width: min(440px, calc(100vw - 32px)); box-shadow: 0 24px 80px rgba(0, 0, 0, 0.3); color: var(--ink); }
.gate::backdrop { background: rgba(6, 8, 11, 0.45); }
.gate form { padding: 24px; display: grid; gap: 12px; }
.gate h2 { font-size: 20px; font-weight: 500; }
.gate p { color: var(--soft); font-size: 15px; }
.g-field { display: grid; gap: 4px; font-size: 13px; color: var(--soft); }
.g-field input { height: 44px; padding: 0 12px; border: 1px solid var(--line-2); border-radius: 6px; font-size: 16px; color: var(--ink); }
.g-field input:focus { outline: 2px solid var(--ink); outline-offset: -1px; }
.g-err { color: var(--bad) !important; font-size: 14px; min-height: 1.2em; }
.g-actions { display: flex; justify-content: flex-end; gap: 8px; }

.mbar { display: none; }

/* ---------- Narrower desktops ---------- */
@media (max-width: 1360px) {
  .v-edit { grid-template-columns: 1fr; }
  .prev-card { position: static; }
  .a4 { height: 70svh; }
}
@media (max-width: 1100px) {
  .tb-fmt { display: none; }
  .panes { grid-template-columns: 1fr; }
}

/* ---------- Phone ---------- */
@media (max-width: 760px) {
  .tb { height: 52px; padding: 0 8px; gap: 8px; }
  .tb-name h1 { font-size: 15px; }
  .quota .q-text, .tb-make { display: none; }
  .pill { display: none; }
  .work-area { grid-template-columns: 1fr; padding: 8px 8px 96px; gap: 8px; }
  .side { position: static; max-height: none; overflow: visible; }
  .grid-scroll { max-height: 60svh; }
  .a4 { height: 76svh; min-height: 0; }
  .card { padding: 12px; }
  .mbar {
    display: flex; align-items: center; gap: 10px; position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    padding: 10px 16px calc(10px + env(safe-area-inset-bottom, 0px)); background: var(--paper); border-top: 1px solid var(--line);
  }
  .mbar-q { flex: 1; font-size: 13px; color: var(--soft); }
  .mbar .btn { min-height: 44px; }
  .studio .chat-launch { bottom: calc(74px + env(safe-area-inset-bottom, 0px)); right: 10px; }
  .studio .chat-panel { bottom: calc(132px + env(safe-area-inset-bottom, 0px)); height: calc(100svh - 150px); }
  .pane-body { height: 72svh; min-height: 0; }
  .tiles { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .td-pic { height: 170px; }
}

/* run summary under the grid: the product's own numbers fill the card */
.run-sum { margin-top: 14px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); border: 1px solid var(--line); border-radius: 8px; }
.run-sum > div { padding: 10px 12px; border-bottom: 1px solid #efefe9; }
.run-sum > div:nth-child(odd) { border-right: 1px solid #efefe9; }
.run-sum > div:nth-last-child(-n+2) { border-bottom: 0; }
.run-sum dt { font-size: 12px; color: var(--soft); }
.run-sum dd { margin: 2px 0 0; font-size: 15px; font-weight: 500; }
#rs-docs { color: var(--data); }
@media (min-width: 1361px) {
  .v-edit { align-items: stretch; }
  .grid-card, .prev-card { height: calc(100svh - 84px); display: flex; flex-direction: column; }
  .grid-scroll { flex: 0 1 auto; max-height: none; min-height: 200px; }
  .run-sum { margin-top: auto; }
  .grid-foot { margin-bottom: 14px; }
  .grid td input, .grid td select { height: 44px; }
  .grid .rn { font-size: 13px; }
  .a4 { flex: 1 1 auto; height: auto; min-height: 0; }
  .side { height: calc(100svh - 84px); }
}
@media (max-width: 760px) { .run-sum { grid-template-columns: 1fr; } .run-sum > div:nth-child(odd) { border-right: 0; } .run-sum > div:nth-last-child(2) { border-bottom: 1px solid #efefe9; } }

/* phone: rows and preview come before the long details form */
@media (max-width: 760px) {
  .side { display: contents; }
  .side > .blk:nth-child(1) { order: 1; }
  .canvas { order: 2; }
  .side > .blk:nth-child(3) { order: 3; }
  .side > .blk:nth-child(2) { order: 4; }
  .side > .blk-other { order: 5; }
}
@media (min-width: 1361px) { .grid td input, .grid td select { height: 40px; } }
