:root {
  /* Brand */
  --cream: #f3f1ef;
  --wine: #4d0013;
  --white: #ffffff;
  --black: #000000;

  --ink: var(--black);
  --muted: #5f5955;
  --line: #e2ddd8;
  --line-strong: #c9c2bc;
  --paper: var(--white);
  --desk: var(--cream);
  --chip: #e9e5e1;
  --dot: #d8d2cc;
  --pin: var(--wine);
  --pin-dark: #330009;
  --pin-wash: #f8eff1;
  --done: #7a736e;
  --danger: #c4281c;
  --font: "Instrument Sans", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --heading: "Roboto Mono", ui-monospace, "SF Mono", Menlo, monospace;
  --focus: 0 0 0 3px rgba(77, 0, 19, 0.3);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font: 15px/1.5 var(--font); color: var(--ink); background: var(--desk); -webkit-font-smoothing: antialiased; }
h1, h2, h3 { margin: 0; line-height: 1.25; font-family: var(--heading); font-weight: 600; letter-spacing: -0.02em; }
.brand, .row-title, .group-name { font-family: var(--heading); letter-spacing: -0.02em; }
p { margin: 0; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: none; box-shadow: var(--focus); }
[hidden] { display: none !important; }

/* ---------- Controls ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  border: 1px solid var(--line); background: var(--paper); border-radius: 8px;
  padding: 8px 14px; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; color: var(--ink);
}
.btn:hover { border-color: var(--line-strong); }
.btn.primary { background: var(--pin); border-color: var(--pin); color: #fff; }
.btn.primary:hover { background: var(--pin-dark); border-color: var(--pin-dark); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13.5px; }
.btn:disabled { opacity: 0.55; cursor: default; }

.link-btn { background: none; border: 0; padding: 2px 0; font-size: 13.5px; font-weight: 600; color: var(--pin); cursor: pointer; }
.link-btn.danger { color: var(--danger); }

.seg { display: inline-flex; gap: 2px; padding: 3px; background: var(--chip); border-radius: 9px; }
.seg button { border: 0; background: transparent; border-radius: 6px; padding: 5px 10px; font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer; }
.seg button[aria-pressed="true"] { background: var(--paper); color: var(--ink); box-shadow: 0 1px 2px rgba(0, 0, 0, 0.14); }

input[type=text], input[type=url], input[type=password], input[type=search], input[type=number], select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; background: var(--paper);
}
input[type=file] { font-size: 14px; }
textarea { resize: vertical; min-height: 64px; line-height: 1.45; }

.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 14px; padding: 10px 18px;
  background: var(--paper); border-bottom: 1px solid var(--line);
}
.brand { margin-right: auto; font-size: 16px; font-weight: 600; }

.empty { padding: 40px 12px; color: var(--muted); text-align: center; }
.form-error { color: var(--danger); font-size: 14px; }
.form-error:empty { display: none; }

.toast {
  position: fixed; left: 50%; bottom: 24px; z-index: 60;
  padding: 10px 16px; border-radius: 10px; background: var(--ink); color: #fff; font-size: 14px;
  opacity: 0; transform: translate(-50%, 16px); pointer-events: none; transition: opacity 0.2s, transform 0.2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Dashboard ---------- */
.dash main { max-width: 1180px; margin: 0 auto; padding: 28px 18px 64px; }
.dash-grid { display: grid; grid-template-columns: 340px minmax(0, 1fr); gap: 28px; align-items: start; }
.panel { background: var(--paper); border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
.new-canvas { position: sticky; top: 76px; display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.new-canvas > *, .field > *, .kind-fields > * { min-width: 0; }
.new-canvas .seg { justify-self: start; max-width: 100%; }
.new-canvas .btn.primary { justify-content: center; }
input[type=file] { max-width: 100%; }
.new-canvas h2, .library-head h2 { font-size: 17px; }
.brand, .new-canvas h2, .library-head h2 { text-transform: uppercase; letter-spacing: 0.06em; }
.field { display: grid; grid-template-columns: minmax(0, 1fr); gap: 5px; }
.field label { font-size: 14px; font-weight: 600; }
.hint { font-size: 13px; color: var(--muted); }
.kind-fields { display: grid; grid-template-columns: minmax(0, 1fr); gap: 14px; }
.progress { display: grid; gap: 6px; }
.progress .track { height: 8px; border-radius: 99px; background: var(--chip); overflow: hidden; }
.progress .bar { width: 0; height: 100%; background: var(--pin); transition: width 0.2s; }
.progress-label { font-size: 13px; color: var(--muted); }

.library-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; margin-bottom: 12px; }
.library input[type=search] { margin-bottom: 20px; }
.group { margin-bottom: 24px; }
.group-name { margin-bottom: 8px; font-size: 13px; font-weight: 500; color: var(--muted); }
.row {
  display: grid; grid-template-columns: minmax(0, 1fr) auto auto; gap: 16px; align-items: center;
  margin-bottom: 8px; padding: 12px 14px; background: var(--paper); border: 1px solid var(--line); border-radius: 10px;
}
.row-main { display: grid; min-width: 0; color: inherit; text-decoration: none; }
.row-title { font-weight: 500; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row-main:hover .row-title { color: var(--pin); }
.row-meta { font-size: 13px; color: var(--muted); }
.status { font-size: 13px; color: var(--muted); white-space: nowrap; }
.status.open { color: var(--pin); font-weight: 600; }
.row-actions { display: flex; gap: 6px; }
.login { max-width: 360px; margin: 12vh auto 0; display: grid; gap: 10px; }
.login h1 { font-size: 22px; margin-bottom: 4px; }

/* ---------- Review page ---------- */
.review { display: flex; flex-direction: column; overflow: hidden; }
.review .topbar { flex-wrap: wrap; }
.doc-title { margin-right: auto; min-width: 0; }
.doc-title h1 { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-title p { font-size: 13px; color: var(--muted); }
.doc-title p:empty { display: none; }
.tools { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
/* Zoom menus: sized and styled like the small buttons beside them */
.select { position: relative; display: inline-flex; }
.select select {
  width: auto; height: 32px; padding: 0 32px 0 12px;
  font-size: 13.5px; font-weight: 600; line-height: 1;
  border: 1px solid var(--line); border-radius: 8px; background: var(--paper);
  -webkit-appearance: none; appearance: none; cursor: pointer;
}
.select select:hover { border-color: var(--line-strong); }
.select::after {
  content: ""; position: absolute; right: 12px; top: 50%; width: 7px; height: 7px; margin-top: -5px;
  border-right: 1.5px solid currentColor; border-bottom: 1.5px solid currentColor;
  transform: rotate(45deg); pointer-events: none;
}
.tools .btn.small { height: 32px; }
.inline-field { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.num { width: 92px !important; padding: 5px 8px !important; }
.panel-toggle { display: none; }
.count-pill { padding: 0 7px; border-radius: 99px; background: var(--pin); color: #fff; font-size: 12px; }
.count-pill:empty { display: none; }

.workspace { flex: 1; display: flex; min-height: 0; }

/* Files strip: every file on the canvas, stacked down the left */
.strip { width: 176px; flex: none; display: flex; flex-direction: column; min-height: 0; background: var(--paper); border-right: 1px solid var(--line); }
.strip-list { flex: 1; overflow: auto; display: grid; align-content: start; gap: 6px; padding: 12px; }
.strip-item { position: relative; border-radius: 10px; }
.strip-item.dragging { opacity: 0.4; }
.strip-item.drop-before { box-shadow: 0 -3px 0 var(--pin); }
.strip-item.drop-after { box-shadow: 0 3px 0 var(--pin); }
.strip-tile {
  display: grid; gap: 6px; width: 100%; padding: 6px; text-align: left;
  border: 2px solid transparent; border-radius: 10px; background: none; cursor: pointer;
}
.strip-tile:hover { background: var(--desk); }
.strip-tile[aria-current="true"] { border-color: var(--pin); background: var(--pin-wash); }
.strip-pic { position: relative; display: grid; place-items: center; aspect-ratio: 4 / 3; border-radius: 6px; overflow: hidden; background: var(--chip); border: 1px solid var(--line); }
.strip-pic img { width: 100%; height: 100%; object-fit: cover; object-position: top; display: block; }
.strip-pdf { font-family: var(--heading); font-size: 13px; font-weight: 600; color: var(--muted); }
.strip-count {
  position: absolute; top: 5px; right: 5px; min-width: 20px; height: 20px; padding: 0 6px;
  display: grid; place-items: center; border-radius: 10px 10px 10px 3px;
  background: var(--pin); color: #fff; font-size: 11.5px; font-weight: 700;
}
.strip-name { font-size: 12.5px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.strip-remove {
  position: absolute; top: 10px; left: 10px; width: 22px; height: 22px; padding: 0;
  display: grid; place-items: center; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, 0.72); color: #fff; font-size: 15px; line-height: 1; cursor: pointer;
  opacity: 0; transition: opacity 0.12s;
}
.strip-item:hover .strip-remove, .strip-remove:focus-visible { opacity: 1; }
.strip-add { display: grid; gap: 6px; padding: 12px; border-top: 1px solid var(--line); }
.strip-add .btn { justify-content: center; }
.strip-status { font-size: 12px; color: var(--muted); }
.strip-status:empty { display: none; }
.stage {
  flex: 1; min-width: 0; min-height: 0; position: relative; overflow: auto; padding: 24px;
  background-color: var(--desk);
  background-image: radial-gradient(var(--dot) 1px, transparent 1.3px);
  background-size: 18px 18px;
}
.stage-status, .stage-message { max-width: 420px; margin: 0 auto 16px; text-align: center; color: var(--muted); }
.stage-message { margin-top: 15vh; }

.sheet-wrap { position: relative; margin: 0 auto; }
.sheet { position: relative; transform-origin: 0 0; background: var(--paper); box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 14px 34px -14px rgba(0, 0, 0, 0.28); }
.sheet.is-pdf { background: transparent; box-shadow: none; }
.content img { display: block; width: 100%; height: auto; user-select: none; -webkit-user-drag: none; }
/* Percentage margins scale with width, so pins stay put at every zoom level. */
.content .pdf-page { margin-bottom: 2%; background: #fff; box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1), 0 14px 34px -14px rgba(0, 0, 0, 0.28); }
.content .pdf-page:last-child { margin-bottom: 0; }
.sheet.is-link .content { position: absolute; inset: 0; }
.sheet.is-link iframe { display: block; width: 100%; height: 100%; border: 0; background: #fff; }

.overlay { position: absolute; inset: 0; z-index: 2; cursor: crosshair; }
.sheet.browsing .overlay { pointer-events: none; }
.pins { position: absolute; inset: 0; z-index: 3; pointer-events: none; }
.sheet-wrap > .composer { z-index: 5; }

/* Pins: a speech bubble whose pointed corner sits exactly on the spot clicked. */
.pin {
  position: absolute; pointer-events: auto; cursor: pointer;
  display: grid; place-items: center; min-width: 30px; height: 30px; padding: 0 8px;
  border: 2px solid #fff; border-radius: 15px 15px 15px 3px;
  background: var(--pin); color: #fff; font-size: 13px; font-weight: 700;
  box-shadow: 0 2px 7px rgba(0, 0, 0, 0.38);
  transform: translateY(-100%); transform-origin: bottom left; transition: transform 0.12s;
}
.pin:hover, .pin.active { transform: translateY(-100%) scale(1.15); z-index: 2; }
.pin.active { box-shadow: 0 0 0 4px rgba(77, 0, 19, 0.28), 0 2px 7px rgba(0, 0, 0, 0.38); }
.pin.resolved { background: var(--done); }
.pin.pending { background: var(--ink); pointer-events: none; }
.sheet.browsing ~ .pins .pin { opacity: 0.7; }

.composer {
  position: absolute; z-index: 4; width: 340px; max-width: calc(100vw - 32px); margin: 8px 0 0 8px;
  display: grid; grid-template-columns: minmax(0, 1fr); gap: 8px; padding: 12px;
  background: var(--paper); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: 0 18px 40px -12px rgba(0, 0, 0, 0.4);
}
.composer.flip-x { transform: translateX(calc(-100% - 16px)); }
.composer-who { font-size: 12.5px; color: var(--muted); }
.composer-actions { display: flex; justify-content: flex-end; align-items: center; gap: 8px; }
.composer-actions { flex-wrap: wrap; }
.composer-actions .spacer { flex: 1; }
.composer.dropping, .reply-form.dropping { outline: 2px dashed var(--pin); outline-offset: 2px; }

/* Images being added to a comment */
.att-tray { display: flex; flex-wrap: wrap; gap: 6px; }
.att-tile { position: relative; width: 64px; height: 64px; border-radius: 8px; overflow: hidden; background: var(--chip); border: 1px solid var(--line); }
.att-tile img { width: 100%; height: 100%; object-fit: cover; display: block; }
.att-name { display: block; padding: 4px; font-size: 10px; line-height: 1.2; overflow-wrap: anywhere; }
.att-progress { position: absolute; left: 4px; right: 4px; bottom: 4px; height: 4px; border-radius: 4px; background: rgba(255, 255, 255, 0.8); display: none; }
.att-tile.uploading .att-progress { display: block; }
.att-tile.uploading img { opacity: 0.55; }
.att-bar { display: block; width: 0; height: 100%; border-radius: 4px; background: var(--pin); }
.att-remove {
  position: absolute; top: 3px; right: 3px; width: 20px; height: 20px; padding: 0;
  display: grid; place-items: center; border: 0; border-radius: 50%;
  background: rgba(0, 0, 0, 0.7); color: #fff; font-size: 14px; line-height: 1; cursor: pointer;
}

/* Images on posted comments */
.gallery { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 6px; margin-top: 8px; }
.gallery-item { aspect-ratio: 1; padding: 0; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; background: var(--chip); cursor: zoom-in; }
.gallery-item img { width: 100%; height: 100%; object-fit: cover; display: block; }
.gallery-item:hover { border-color: var(--pin); }

.lightbox { position: fixed; inset: 0; z-index: 70; display: flex; flex-direction: column; background: rgba(0, 0, 0, 0.88); }
.lightbox-bar { display: flex; align-items: center; gap: 8px; padding: 10px 14px; color: #fff; font-size: 14px; }
.lightbox-bar span { margin-right: auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.lightbox img { flex: 1; min-height: 0; width: 100%; object-fit: contain; padding: 0 16px 16px; }

.sidebar { width: 360px; flex: none; display: flex; flex-direction: column; min-height: 0; background: var(--paper); border-left: 1px solid var(--line); }
.side-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; padding: 16px 16px 10px; }
.side-head h2 { font-size: 16px; }
.side-sub { margin-top: 2px; font-size: 13px; color: var(--muted); }
.check { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); white-space: nowrap; cursor: pointer; }
.side-hint { padding: 0 16px 10px; font-size: 13px; color: var(--muted); }
.side-hint:empty { display: none; }
.side-warning { margin: 0 16px 10px; padding: 8px 10px; border-radius: 8px; background: #fbf0e3; font-size: 13px; }
.threads { flex: 1; overflow: auto; padding: 6px 10px 28px; border-top: 1px solid var(--line); }

.thread { margin-bottom: 4px; padding: 10px 10px 12px; border: 1px solid transparent; border-radius: 10px; }
.thread.active { border-color: var(--pin); background: var(--pin-wash); }
.thread.resolved .body { color: var(--muted); }
.thread-head { display: flex; align-items: center; gap: 8px; width: 100%; padding: 0; background: none; border: 0; text-align: left; cursor: pointer; }
.badge { display: grid; place-items: center; min-width: 24px; height: 24px; padding: 0 6px; border-radius: 12px 12px 12px 3px; background: var(--pin); color: #fff; font-size: 12px; font-weight: 700; }
.badge.resolved { background: var(--done); }
.who { font-size: 14px; font-weight: 600; }
.thread time, .reply time { margin-left: auto; font-size: 12.5px; color: var(--muted); }
.body { margin-top: 6px; font-size: 14.5px; white-space: pre-wrap; overflow-wrap: anywhere; }
.view-note { margin-top: 6px; font-size: 12.5px; color: var(--muted); }
.reply { margin: 10px 0 0 32px; padding-left: 10px; border-left: 2px solid var(--line); }
.reply-head { display: flex; align-items: center; gap: 8px; }
.thread-actions { display: flex; gap: 16px; margin: 8px 0 0 32px; }
.reply-form { display: grid; grid-template-columns: minmax(0, 1fr); gap: 6px; margin: 8px 0 0 32px; }

.modal { position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, 0.45); }
.modal-card { width: min(380px, 100%); display: grid; gap: 10px; padding: 22px; background: var(--paper); border-radius: 14px; }
.modal-card p { color: var(--muted); }

/* ---------- Small screens ---------- */
@media (max-width: 900px) {
  .dash-grid { grid-template-columns: 1fr; }
  .new-canvas { position: static; }
  .row { grid-template-columns: 1fr; gap: 8px; }
  .row-actions { flex-wrap: wrap; }

  .review .topbar { gap: 8px; padding: 8px 12px; }
  .has-strip .workspace { flex-direction: column; }
  .strip { width: auto; flex-direction: row; border-right: 0; border-bottom: 1px solid var(--line); }
  .strip-list { display: flex; overflow-x: auto; overflow-y: hidden; padding: 8px; gap: 4px; }
  .strip-item, .strip-list > .strip-tile { flex: none; width: 96px; }
  .strip-tile { padding: 4px; gap: 4px; }
  .strip-name { font-size: 11px; }
  .strip-remove { opacity: 1; top: 7px; left: 7px; }
  .strip-item.drop-before { box-shadow: -3px 0 0 var(--pin); }
  .strip-item.drop-after { box-shadow: 3px 0 0 var(--pin); }
  .strip-add { border-top: 0; border-left: 1px solid var(--line); padding: 8px; align-content: center; }
  .strip-status { max-width: 110px; }
  .doc-title { flex: 1 1 0; }
  .tools { order: 3; width: 100%; }
  .panel-toggle { display: inline-flex; }
  .stage { padding: 12px; }
  .sidebar {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30; width: auto; height: 65vh;
    border-left: 0; border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
    box-shadow: 0 -12px 32px -12px rgba(0, 0, 0, 0.3);
    transform: translateY(100%); visibility: hidden; transition: transform 0.22s, visibility 0.22s;
  }
  .sidebar.open { transform: none; visibility: visible; }
  .sheet-wrap > .composer, .composer { position: fixed; left: 12px; right: 12px; bottom: 12px; width: auto; margin: 0; transform: none !important; z-index: 40; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; scroll-behavior: auto !important; }
}
