:root {
  color-scheme: light;
  --bg: #f4f4f6;
  --surface: #ffffff;
  --surface-soft: #f8f8fb;
  --ink: #252733;
  --ink-soft: #777b8c;
  --line: #e6e7ed;
  --line-strong: #252733;
  --accent: #ee694f;
  --accent-soft: #fff0ec;
  --sidebar: #f6f5f9;
  --focus: #c64c37;
  --shadow: 0 18px 50px rgb(34 37 49 / 8%);
  --font: "Avenir Next", Avenir, "Segoe UI", Helvetica, Arial, sans-serif;
}

* {
  box-sizing: border-box;
}

[hidden] {
  display: none !important;
}

html {
  min-width: 760px;
  background: var(--bg);
}

body {
  min-height: 100dvh;
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  background: var(--bg);
  font-family: var(--font);
  font-size: 14px;
}

.login-shell {
  position: fixed;
  z-index: 100;
  display: grid;
  inset: 0;
  place-items: center;
  padding: 24px;
  background: rgb(244 244 246 / 96%);
}

.login-card {
  display: grid;
  width: min(390px, 100%);
  gap: 16px;
  padding: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.login-card h1,
.login-card p {
  margin: 0;
}

.login-card > p {
  color: var(--ink-soft);
}

.login-card input,
.remote-toolbar input,
.remote-toolbar select {
  width: 100%;
  min-height: 34px;
  padding: 5px 9px;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
}

.login-error {
  color: #a83727 !important;
}

button,
input,
textarea,
select {
  color: inherit;
  font: inherit;
}

button {
  cursor: pointer;
}

button:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.app-bar {
  position: relative;
  z-index: 10;
  display: grid;
  grid-template-columns: 54px minmax(260px, 1fr) auto auto;
  min-height: 58px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.brand-mark {
  display: grid;
  align-self: stretch;
  place-items: center;
  background: var(--accent);
  color: #fff;
}

.brand-mark svg {
  width: 27px;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.7;
}

.project-crumbs {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 12px;
  padding: 0 20px;
  color: var(--ink-soft);
  font-size: 13px;
}

.project-name,
.project-crumbs strong {
  color: var(--ink);
}

.project-name {
  font-size: 15px;
  font-weight: 700;
}

.crumb-separator {
  color: #c1c3cc;
}

.save-state {
  min-width: 128px;
  padding-right: 8px;
  color: var(--ink-soft);
  font-size: 12px;
  text-align: right;
}

.save-state.is-saving::before {
  display: inline-block;
  width: 6px;
  height: 6px;
  margin-right: 7px;
  border-radius: 50%;
  background: var(--accent);
  content: "";
}

.top-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 16px 0 8px;
}

.session-user {
  max-width: 150px;
  overflow: hidden;
  color: var(--ink-soft);
  font-size: 12px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.remote-toolbar {
  position: relative;
  z-index: 9;
  display: flex;
  min-height: 58px;
  align-items: end;
  gap: 8px;
  padding: 10px 16px;
  overflow-x: auto;
  border-bottom: 1px solid var(--line);
  background: var(--surface-soft);
}

.remote-toolbar label {
  display: grid;
  min-width: 170px;
  gap: 3px;
  color: var(--ink-soft);
  font-size: 9px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.access-controls {
  display: flex;
  align-items: end;
  gap: 8px;
  padding-left: 10px;
  border-left: 1px solid var(--line);
}

.access-controls label:first-child {
  min-width: 140px;
}

.access-controls label:nth-child(2) {
  min-width: 95px;
}

.legacy-import {
  flex: 0 0 auto;
}

.button,
.icon-button,
.text-button,
.comment-button,
.row-menu-button,
.delete-row-button,
.auto-duration-button,
.image-picker-button,
.remove-row-image-button,
.drag-handle {
  border: 0;
  background: transparent;
}

.button {
  min-height: 34px;
  padding: 0 14px;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 12px;
  font-weight: 700;
  transition: transform 150ms ease, background 150ms ease, border-color 150ms ease;
}

.button:active,
.icon-button:active,
.text-button:active {
  transform: scale(0.98);
}

.button-primary {
  background: var(--accent);
  color: #fff;
}

.button-primary:hover {
  background: #db5a42;
}

.button-secondary {
  border-color: var(--line);
  background: var(--surface);
}

.button-secondary:hover {
  border-color: #cbccd4;
  background: var(--surface-soft);
}

.full-width {
  width: 100%;
}

.workspace-shell {
  display: grid;
  grid-template-columns: 286px minmax(700px, 1fr) 292px;
  height: calc(100dvh - 116px);
}

body.is-readonly .script-page input,
body.is-readonly .script-page textarea,
body.is-readonly .script-page button,
body.is-readonly .inspector input,
body.is-readonly .inspector textarea,
body.is-readonly .inspector select,
body.is-readonly .inspector button {
  cursor: not-allowed;
}

body.is-readonly .script-row {
  background: #fafafa;
}

.version-sidebar,
.inspector {
  position: relative;
  z-index: 2;
  overflow: auto;
  background: var(--sidebar);
}

.version-sidebar {
  border-right: 1px solid var(--line);
}

.sidebar-heading,
.inspector-header {
  border-bottom: 1px solid var(--line);
}

.sidebar-heading {
  display: flex;
  min-height: 54px;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.icon-button {
  display: grid;
  width: 30px;
  height: 30px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface);
  color: var(--accent);
  font-size: 20px;
}

.version-list {
  padding: 16px 12px;
}

.version-item {
  display: grid;
  grid-template-columns: 32px minmax(0, 1fr) auto;
  width: 100%;
  min-height: 54px;
  align-items: center;
  gap: 9px;
  padding: 8px 10px;
  border: 1px solid transparent;
  border-radius: 4px;
  background: transparent;
  text-align: left;
}

.version-item:hover {
  background: rgb(255 255 255 / 70%);
}

.version-item.is-active {
  border-color: #f7d8ce;
  background: var(--accent-soft);
}

.version-number {
  display: grid;
  min-height: 26px;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--surface);
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 800;
}

.version-label {
  overflow: hidden;
  color: var(--ink);
  font-size: 12px;
  font-weight: 700;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.version-item.is-active .version-label {
  color: var(--accent);
}

.version-row-count {
  color: var(--ink-soft);
  font-size: 11px;
  font-weight: 700;
}

.storage-note {
  margin: auto 18px 24px;
  padding-top: 18px;
  border-top: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 11px;
  line-height: 1.55;
}

.document-stage {
  overflow: auto;
  padding: 32px clamp(28px, 5vw, 72px) 80px;
  background: #f7f7f8;
}

.script-page {
  width: min(100%, 1040px);
  min-height: calc(100dvh - 125px);
  margin: 0 auto;
  padding: 56px clamp(42px, 5vw, 74px) 48px;
  border: 1px solid #f0f0f2;
  border-radius: 3px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.script-header {
  display: flex;
  align-items: flex-start;
  gap: 16px;
  margin-bottom: 28px;
}

.version-badge {
  display: grid;
  width: 28px;
  height: 26px;
  flex: 0 0 auto;
  place-items: center;
  border: 1px solid var(--line);
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 800;
}

.script-title-block {
  min-width: 0;
}

.title-input,
.segment-title,
.audio-input,
.visual-input,
.duration-input {
  border: 0;
  background: transparent;
}

.title-input {
  width: 100%;
  padding: 0;
  color: var(--ink);
  font-size: clamp(24px, 2.3vw, 34px);
  font-weight: 760;
  letter-spacing: -0.03em;
}

.document-totals {
  margin: 9px 0 0;
  color: var(--ink-soft);
  font-size: 12px;
}

.segment + .segment {
  margin-top: 38px;
}

.segment-title-label {
  display: block;
  margin-bottom: 20px;
  text-align: center;
}

.segment-title {
  width: min(420px, 100%);
  padding: 6px 8px;
  color: var(--ink);
  font-size: 16px;
  font-weight: 750;
  text-align: center;
}

.sheet-grid {
  display: grid;
  grid-template-columns: 74px minmax(190px, 1fr) minmax(190px, 1.05fr) 124px 82px 62px;
}

.sheet-head {
  min-height: 34px;
  align-items: end;
  border-bottom: 4px solid var(--line-strong);
  color: #5f6270;
  font-size: 11px;
  font-weight: 800;
}

.sheet-head > div {
  padding: 0 10px 9px;
}

.script-row {
  position: relative;
  min-height: 112px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
  transition: background 150ms ease;
}

.script-row:hover,
.script-row.is-selected {
  background: #fbfbfd;
}

.script-row.is-selected::before {
  position: absolute;
  inset: 0 auto 0 -8px;
  width: 3px;
  background: var(--accent);
  content: "";
}

.row-meta,
.cell-label,
.image-cell,
.duration-cell,
.row-tools {
  padding: 14px 10px;
}

.row-meta {
  position: relative;
  display: flex;
  min-width: 0;
  flex-direction: column;
  gap: 3px;
}

.drag-handle {
  position: absolute;
  top: 15px;
  left: -13px;
  display: grid;
  width: 13px;
  gap: 2px;
  padding: 3px 0;
  opacity: 0;
  transition: opacity 150ms ease;
}

.script-row:hover .drag-handle,
.drag-handle:focus-visible {
  opacity: 1;
}

.drag-handle span {
  display: block;
  width: 11px;
  height: 2px;
  background: #a9acb8;
}

.row-number {
  font-size: 15px;
}

.row-word-count,
.row-reading-time {
  color: #9396a4;
  font-size: 9px;
  font-weight: 650;
}

.cell-label {
  display: block;
  min-width: 0;
}

.audio-input,
.visual-input {
  width: 100%;
  min-height: 82px;
  resize: vertical;
  overflow: hidden;
  color: #525562;
  font-size: 12px;
  line-height: 1.5;
}

.audio-input::placeholder,
.visual-input::placeholder {
  color: #9da0ac;
}

.image-cell {
  position: relative;
  display: grid;
  min-width: 0;
  place-items: center;
  margin: 8px 7px;
  padding: 0;
  overflow: hidden;
  border-radius: 4px;
  background: #f1f2f8;
}

.image-picker-button {
  display: grid;
  width: 100%;
  height: 100%;
  min-height: 94px;
  place-items: center;
  padding: 0;
  overflow: hidden;
}

.image-picker-button img {
  width: 100%;
  height: 94px;
  object-fit: cover;
}

.remove-row-image-button {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 2;
  display: grid;
  width: 26px;
  height: 26px;
  place-items: center;
  border: 1px solid rgb(255 255 255 / 52%);
  border-radius: 50%;
  background: rgb(37 39 51 / 84%);
  color: #fff;
  font-size: 18px;
  line-height: 1;
  transition: background 150ms ease, transform 150ms ease;
}

.remove-row-image-button:hover {
  background: #a83727;
}

.remove-row-image-button:active {
  transform: scale(0.94);
}

.image-placeholder {
  width: 38px;
  fill: #c1c4d2;
}

.image-placeholder rect {
  fill: #c7cad8;
}

.image-placeholder circle,
.image-placeholder path {
  fill: #aeb2c3;
}

.duration-cell {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
}

.duration-input {
  width: 58px;
  padding: 2px;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  text-align: center;
}

.auto-duration-button {
  color: var(--accent);
  font-size: 9px;
  font-weight: 800;
  opacity: 1;
  text-transform: uppercase;
  transition: opacity 150ms ease;
}

.script-row:hover .auto-duration-button,
.auto-duration-button:focus-visible {
  opacity: 1;
}

.row-tools {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 5px;
}

.comment-button {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px;
  color: #7f8290;
  font-size: 10px;
}

.comment-button svg {
  width: 15px;
  fill: currentColor;
}

.row-menu-button,
.delete-row-button {
  color: #a4a6b1;
  font-size: 9px;
  opacity: 0;
  transition: color 150ms ease, opacity 150ms ease;
}

.delete-row-button {
  font-size: 18px;
}

.script-row:hover .row-menu-button,
.script-row:hover .delete-row-button,
.row-menu-button:focus-visible,
.delete-row-button:focus-visible {
  opacity: 1;
}

.delete-row-button:hover,
.danger:hover {
  color: #a83727;
}

.segment-footer {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) minmax(400px, auto);
  align-items: end;
  gap: 24px;
  padding: 13px 10px 12px;
  border-bottom: 1px solid var(--line);
}

.segment-end-label {
  display: flex;
  min-width: 0;
  flex-direction: column;
}

.eyebrow,
.segment-totals dt {
  color: #8c8f9d;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.04em;
  text-transform: uppercase;
}

.segment-end-title {
  overflow: hidden;
  font-size: 10px;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.segment-totals {
  display: grid;
  grid-template-columns: repeat(4, minmax(72px, 1fr));
  gap: 12px;
  margin: 0;
}

.segment-totals div {
  text-align: right;
}

.segment-totals dt,
.segment-totals dd {
  margin: 0;
}

.segment-totals dd {
  margin-top: 4px;
  font-size: 11px;
  font-weight: 800;
}

.segment-actions {
  display: flex;
  justify-content: flex-end;
  gap: 14px;
  padding: 8px 2px 0;
}

.text-button {
  padding: 7px 4px;
  color: var(--ink-soft);
  font-size: 10px;
  font-weight: 800;
}

.text-button span {
  margin-right: 3px;
  color: var(--accent);
  font-size: 15px;
}

.text-button:hover {
  color: var(--ink);
}

.document-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 20px;
}

.inspector {
  border-left: 1px solid var(--line);
  background: var(--surface);
}

.inspector-header {
  min-height: 90px;
  padding: 19px 20px 14px;
}

.inspector-header h2 {
  margin: 5px 0 0;
  font-size: 16px;
  letter-spacing: -0.02em;
}

.inspector-empty {
  padding: 24px 20px;
  color: var(--ink-soft);
  font-size: 12px;
  line-height: 1.6;
}

.inspector-form {
  display: grid;
  gap: 20px;
  padding: 22px 20px;
}

.field-group {
  display: grid;
  gap: 8px;
}

.field-group > span {
  color: #676a78;
  font-size: 11px;
  font-weight: 750;
}

.field-group input,
.field-group textarea,
.field-group select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--surface-soft);
}

.field-group input,
.field-group select {
  min-height: 36px;
  padding: 0 10px;
}

.field-group textarea {
  padding: 10px;
  resize: vertical;
  line-height: 1.55;
}

.toast {
  position: fixed;
  z-index: 30;
  right: 24px;
  bottom: 24px;
  max-width: 340px;
  padding: 12px 15px;
  border: 1px solid #e8d0c9;
  border-radius: 4px;
  background: #fff9f7;
  box-shadow: 0 12px 36px rgb(37 39 51 / 16%);
  font-size: 12px;
  font-weight: 700;
}

.is-dragging {
  opacity: 0.55;
}

.drag-over {
  box-shadow: inset 0 3px 0 var(--accent);
}

@media (max-width: 1250px) {
  .workspace-shell {
    grid-template-columns: 224px minmax(700px, 1fr);
  }

  .sheet-grid {
    grid-template-columns: 74px minmax(190px, 1fr) 82px minmax(190px, 1.05fr) 124px 62px;
  }

  .sheet-grid > :nth-child(1) {
    grid-column: 1;
  }

  .sheet-grid > :nth-child(2) {
    grid-column: 2;
  }

  .sheet-grid > :nth-child(3) {
    grid-column: 4;
  }

  .sheet-grid > :nth-child(4) {
    grid-column: 5;
  }

  .sheet-grid > :nth-child(5) {
    grid-column: 3;
  }

  .sheet-grid > :nth-child(6) {
    grid-column: 6;
  }

  .sheet-grid > * {
    grid-row: 1;
  }

  .inspector {
    position: fixed;
    top: 58px;
    right: 0;
    bottom: 0;
    z-index: 15;
    width: 292px;
    box-shadow: -12px 0 40px rgb(37 39 51 / 10%);
    transform: translateX(calc(100% - 7px));
    transition: transform 220ms cubic-bezier(0.16, 1, 0.3, 1);
  }

  .inspector:focus-within,
  .inspector.is-open {
    transform: translateX(0);
  }
}

@media (max-width: 980px) {
  .app-bar {
    grid-template-columns: 54px minmax(220px, 1fr) auto;
  }

  .save-state {
    display: none;
  }

  .top-actions .button-secondary:first-of-type {
    display: none;
  }

  .workspace-shell {
    grid-template-columns: 72px minmax(680px, 1fr);
  }

  .sidebar-heading > span,
  .version-label,
  .version-row-count,
  .storage-note {
    display: none;
  }

  .sidebar-heading {
    justify-content: center;
    padding: 0;
  }

  .version-list {
    padding: 12px 8px;
  }

  .version-item {
    grid-template-columns: 1fr;
    padding: 5px;
  }
}

@media print {
  @page {
    size: A4 landscape;
    margin: 12mm;
  }

  html,
  body {
    min-width: 0;
    overflow: visible;
    background: #fff;
  }

  .app-bar,
  .remote-toolbar,
  .version-sidebar,
  .inspector,
  .segment-actions,
  .document-actions,
  .row-menu-button,
  .delete-row-button,
  .remove-row-image-button,
  .auto-duration-button,
  .drag-handle,
  .toast {
    display: none !important;
  }

  .workspace-shell,
  .document-stage {
    display: block;
    height: auto;
    overflow: visible;
    padding: 0;
    background: #fff;
  }

  .script-page {
    width: 100%;
    min-height: 0;
    padding: 0;
    border: 0;
    box-shadow: none;
  }

  .script-row {
    break-inside: avoid;
  }

  .segment {
    break-before: auto;
    break-inside: avoid-page;
  }

  textarea {
    resize: none !important;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
