:root {
  --bg: #edf1eb;
  --surface: #ffffff;
  --panel: #f7f8f4;
  --line: #d0d8cc;
  --border: var(--line);
  --ink: #172119;
  --muted: #687466;
  --accent: #23694f;
  --accent-ink: #ffffff;
  --accent-soft: #e4f0e9;
  --warning: #a96522;
  --warning-soft: #f4e4d0;
  --danger: #a43c31;
  --danger-soft: #f1dcd8;
  --shadow: 0 12px 28px rgba(30, 44, 34, 0.075);
  --input-bg: #ffffff;
  --preview-bg: #fffdf6;
  --readonly-bg: #eef2f6;
  --modal-backdrop: rgba(24, 32, 42, 0.5);
  --radius: 8px;
}

body.theme-dark {
  --bg: #11161c;
  --surface: #1a2129;
  --panel: #161c23;
  --line: #2d3744;
  --border: var(--line);
  --ink: #edf2f7;
  --muted: #9aa8ba;
  --accent: #4ba96d;
  --accent-ink: #0c1117;
  --accent-soft: #20362a;
  --warning-soft: #3a2b1d;
  --danger: #ff7d7d;
  --danger-soft: #3a2023;
  --shadow: 0 12px 32px rgba(0, 0, 0, 0.32);
  --input-bg: #161c23;
  --preview-bg: #1d242c;
  --readonly-bg: #202833;
  --modal-backdrop: rgba(0, 0, 0, 0.68);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 13px/1.36 "IBM Plex Sans", "Segoe UI", Tahoma, sans-serif;
}

.app {
  min-height: 100vh;
  display: grid;
  grid-template-rows: auto auto minmax(0, 1fr);
}

a { color: inherit; }

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

.topbar {
  position: sticky;
  top: 0;
  z-index: 1000;
  min-height: 49px;
  display: grid;
  grid-template-columns: auto minmax(340px, 1fr) auto;
  align-items: center;
  gap: 12px;
  padding: 8px 14px;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(12px);
}

.page-actions,
.nav,
.review-actions,
.users-form-row,
.field-tools,
.panel-title,
.preview-tabs {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.brand {
  color: var(--ink);
  font-weight: 700;
  font-size: 15px;
  text-decoration: none;
  white-space: nowrap;
}

.main-toolbar {
  justify-content: center;
}

.nav {
  justify-content: flex-end;
}

.nav a {
  text-decoration: none;
}

.ui-icon {
  width: 16px;
  height: 16px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
}

.ui-icon svg {
  width: 16px;
  height: 16px;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.nav form {
  margin: 0;
}

.shell {
  width: min(1560px, 100%);
  margin: 0 auto;
  padding: 8px 14px 14px;
}

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

input,
button,
select {
  min-height: 32px;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 4px 10px;
  background: var(--input-bg);
  color: var(--ink);
}

textarea {
  width: 100%;
  min-height: 340px;
  padding: 10px;
  resize: none;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--ink);
}

textarea[readonly] {
  background: var(--readonly-bg);
  color: var(--muted);
}

button {
  cursor: pointer;
}

button:disabled {
  opacity: 0.62;
  cursor: wait;
}

.button,
.button-link,
.icon-button {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--input-bg);
  color: var(--ink);
  text-decoration: none;
  white-space: nowrap;
}

.button,
.button-link {
  gap: 7px;
  padding: 4px 10px;
}

.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}

.warn {
  border-color: color-mix(in srgb, var(--warning) 32%, var(--border));
  background: var(--warning-soft);
  color: #754719;
}

body.theme-dark .warn {
  color: #f2c28d;
}

.danger,
.danger-button {
  color: var(--danger);
}

.icon-button {
  width: 32px;
  min-width: 32px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
}

.inline {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.date-input {
  width: 132px;
}

.segmented,
.preview-tabs {
  display: inline-grid;
  grid-auto-flow: column;
  gap: 3px;
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
}

.segmented button,
.preview-tabs button {
  min-width: 64px;
  min-height: 24px;
  border: 0;
  border-radius: 5px;
  background: transparent;
}

.segmented .active,
.preview-tabs .active {
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(30, 44, 34, 0.08);
}

.toggle-pill {
  min-height: 32px;
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 0 10px;
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  border-radius: 6px;
  background: var(--accent-soft);
  color: var(--accent);
  white-space: nowrap;
}

.toggle-pill input {
  min-height: 0;
  margin: 0;
}

.toggle-button.active {
  border-color: color-mix(in srgb, var(--accent) 35%, var(--border));
  background: var(--accent-soft);
  color: var(--accent);
}

.settings-bar {
  display: flex;
  align-items: center;
  gap: 16px;
  flex-wrap: wrap;
  margin: 0 auto;
  padding: 10px 14px 0;
}

.settings-link {
  text-decoration: none;
  font-weight: 600;
}

.muted {
  color: var(--muted);
}

.surface,
.panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.panel {
  padding: 14px;
}

.panel h1 {
  margin: 0 0 10px;
  font-size: 16px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(500px, 1.35fr) minmax(330px, 0.75fr);
  gap: 12px;
  min-height: 0;
}

.menu-input,
.preview-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  height: calc((100vh - 78px) * 0.95);
  min-height: 0;
  overflow: hidden;
}

.panel-head,
.preview-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 9px 12px;
  border-bottom: 1px solid var(--border);
}

.panel-title,
.field-tools {
  min-width: 0;
}

.field-tools {
  justify-content: flex-end;
}

.panel-title h1,
.preview-title h2 {
  margin: 0;
  font-size: 15px;
  line-height: 1.2;
}

.preview-actions {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  min-width: 0;
}

.counter {
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}

.editor-wrap {
  min-height: 0;
  padding: 10px;
  background: var(--panel);
}

.editor-wrap textarea {
  height: 100%;
  min-height: 0;
  padding: 13px 15px;
  background: #fffefb;
  font-size: 14.5px;
  line-height: 1.45;
}

body.theme-dark .editor-wrap textarea {
  background: var(--input-bg);
}

.page-area {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 10px;
  overflow: hidden;
  background: var(--panel);
}

.preview-page {
  --preview-scale: 1;
  width: var(--preview-page-width, min(100%, 375px));
  height: var(--preview-page-height, auto);
  margin: 0 auto;
  aspect-ratio: 210 / 297;
  flex: 0 0 auto;
}

.preview-surface {
  position: relative;
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  width: 100%;
  height: 100%;
  overflow: hidden;
  border: 1px solid #cbc5b4;
  background: var(--preview-bg);
  color: #101418;
  box-shadow: 0 16px 32px rgba(30, 44, 34, 0.12);
  font-family: "Times New Roman", "Liberation Serif", serif;
}

.preview-bg,
.preview-overlay {
  position: absolute;
  inset: 0;
}

.preview-bg {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.preview-overlay {
  background: rgba(255, 255, 255, 0.72);
}

body.theme-dark .preview-overlay {
  background: rgba(13, 18, 24, 0.62);
}

body.theme-dark .preview-surface {
  border-color: #384451;
  color: #edf2f7;
  box-shadow: 0 16px 32px rgba(0, 0, 0, 0.28);
}

.preview-doc {
  position: relative;
  z-index: 1;
  min-height: 0;
  display: grid;
  align-content: center;
  justify-items: center;
  padding: calc(24px * var(--preview-scale)) calc(21px * var(--preview-scale)) calc(8px * var(--preview-scale));
  text-align: center;
  white-space: pre-wrap;
  font-size: clamp(11px, calc(13.75px * var(--preview-scale)), 19px);
  line-height: 1.36;
}

.preview-doc .group,
.preview-doc .dish {
  display: block;
  width: 100%;
  max-width: 100%;
  overflow-wrap: anywhere;
  text-align: center;
}

.preview-doc .group {
  margin-top: calc(14px * var(--preview-scale));
  font-weight: 700;
}

.preview-doc .group:first-child {
  margin-top: 0;
}

.preview-doc .dish {
  margin-top: calc(2px * var(--preview-scale));
}

body.theme-dark .preview-doc .dish {
  color: #edf2f7;
}

.preview-doc .unknown {
  color: var(--danger);
  font-weight: 700;
}

.preview-footer {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  gap: calc(10px * var(--preview-scale));
  padding: 0 calc(21px * var(--preview-scale)) calc(19px * var(--preview-scale));
  font-size: clamp(8px, calc(9.5px * var(--preview-scale)), 13px);
  color: #101418;
}

body.theme-dark .preview-footer {
  color: #cbd5e1;
}

.preview-footer > :last-child {
  white-space: nowrap;
}

.suggest-box {
  position: fixed;
  z-index: 2500;
  max-height: 260px;
  overflow: auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.suggest-item {
  display: block;
  width: 100%;
  min-height: 0;
  text-align: left;
  border: 0;
  border-bottom: 1px solid var(--border);
  border-radius: 0;
  background: var(--surface);
  color: var(--ink);
}

.suggest-item:hover,
.suggest-item.active {
  background: color-mix(in srgb, var(--accent) 12%, var(--surface));
}

.editor-workspace {
  display: grid;
  grid-template-columns: 280px minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.editor-sidebar,
.desk-panel {
  overflow: hidden;
}

.filter-section {
  padding: 14px 16px;
}

.filter-section h1 {
  margin: 0 0 12px;
  font-size: 15px;
}

.segment-row {
  display: grid;
  gap: 10px;
  margin-bottom: 10px;
}

.mode-toggle {
  justify-content: center;
}

.editor-search {
  width: 100%;
  margin-bottom: 10px;
}

.editor-table-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
}

.editor-table-head h1 {
  margin: 0;
  font-size: 16px;
}

.table-shell,
.table-panel {
  overflow: auto;
}

.table-shell {
  max-height: calc(100vh - 176px);
}

table {
  width: 100%;
  min-width: 980px;
  border-collapse: collapse;
  table-layout: fixed;
}

thead th {
  position: sticky;
  top: 0;
  z-index: 2;
  padding: 10px;
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  text-align: left;
  color: var(--muted);
  font-size: 12px;
}

tbody td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: top;
}

tbody tr:hover {
  background: color-mix(in srgb, var(--accent-soft) 35%, transparent);
}

tbody tr.new-row {
  box-shadow: inset 3px 0 0 var(--accent);
}

tbody tr.dirty-row {
  box-shadow: inset 3px 0 0 var(--warning);
}

tbody tr.error-row {
  box-shadow: inset 3px 0 0 var(--danger);
}

tbody tr.auto-translated-row {
  background: color-mix(in srgb, var(--warning-soft) 72%, transparent);
}

body.theme-dark tbody tr.auto-translated-row {
  background: rgba(245, 158, 11, 0.16);
}

.table-sort {
  min-height: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: inherit;
  font-weight: 700;
}

.table-sort.active {
  color: var(--accent);
}

.compact-input,
td input,
td select {
  width: 100%;
}

.number-head,
.number-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(54px, 58px));
  gap: 6px;
  justify-content: center;
  text-align: center;
}

.number-field {
  min-width: 0;
  max-width: 58px;
  padding-inline: 6px;
  text-align: right;
  font-variant-numeric: tabular-nums;
  appearance: textfield;
  -moz-appearance: textfield;
}

.number-field::-webkit-inner-spin-button,
.number-field::-webkit-outer-spin-button {
  margin: 0;
  -webkit-appearance: none;
}

.translate-col,
.translate-cell {
  text-align: center;
}

.translate-cell .icon-button {
  margin-inline: auto;
}

.action-col {
  text-align: center;
}

.auth-panel {
  max-width: 460px;
  margin: 48px auto;
}

.auth-form {
  justify-items: center;
}

.auth-field {
  width: min(320px, 100%);
}

.stack {
  display: grid;
  gap: 10px;
}

.form-field span {
  font-weight: 600;
}

.compact-field {
  min-width: 260px;
  flex: 1 1 280px;
}

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  max-width: 420px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
  color: var(--ink);
  background: var(--surface);
  box-shadow: var(--shadow);
  z-index: 3000;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 2600;
}

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: var(--modal-backdrop);
}

.modal-dialog {
  position: relative;
  width: min(900px, calc(100% - 32px));
  max-height: calc(100vh - 48px);
  margin: 24px auto;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  overflow: hidden;
}

.users-dialog {
  width: min(980px, calc(100% - 32px));
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
}

.modal-header h2,
.users-create h3,
.users-list-wrap h3 {
  margin: 0;
}

.modal-body {
  max-height: calc(100vh - 150px);
  overflow: auto;
  padding: 14px;
}

.review-list,
.users-list {
  display: grid;
  gap: 10px;
}

.review-item,
.users-item,
.users-result {
  display: grid;
  gap: 6px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 10px;
  background: var(--input-bg);
}

.review-item {
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: start;
}

.review-compare,
.users-body,
.users-create,
.users-list-wrap,
.users-meta {
  display: grid;
  gap: 12px;
}

.review-source,
.review-target {
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.review-actions-column {
  flex-direction: column;
  align-items: stretch;
  min-width: 110px;
}

.review-score {
  color: var(--muted);
  font-size: 13px;
}

.users-meta strong {
  font-size: 16px;
}

.document-stack {
  display: grid;
  gap: 20px;
  justify-items: center;
}

.document-page {
  width: min(210mm, 100%);
}

.document-surface {
  position: relative;
  min-height: 297mm;
  padding: 18mm 14mm 18mm;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fff;
  color: #101418;
  box-shadow: var(--shadow);
  overflow: hidden;
}

.document-bg,
.document-overlay {
  position: absolute;
  inset: 0;
}

.document-bg {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.document-overlay {
  background: rgba(255, 255, 255, 0.72);
}

.document-content,
.document-footer {
  position: relative;
  z-index: 1;
}

.document-content {
  min-height: calc(297mm - 54mm);
  display: grid;
  align-content: center;
  justify-items: center;
  text-align: center;
  font-family: "Times New Roman", "Liberation Serif", serif;
  font-size: 20pt;
  line-height: 1.4;
}

.document-group {
  margin-top: 20pt;
  font-weight: 700;
}

.document-group:first-child {
  margin-top: 0;
}

.document-dish {
  margin-top: 2pt;
}

.document-nowrap {
  white-space: nowrap;
}

.document-group + .document-dish {
  margin-top: 6pt;
}

.document-footer {
  margin-top: 10mm;
  display: flex;
  justify-content: space-between;
  gap: 16px;
  font-family: "Times New Roman", "Liberation Serif", serif;
  font-size: 11pt;
}

.document-footer-left {
  min-width: 0;
}

.document-footer-right {
  white-space: nowrap;
}

@media (max-width: 1180px) {
  .topbar {
    grid-template-columns: 1fr;
  }

  .main-toolbar,
  .nav {
    justify-content: flex-start;
  }

  .workspace,
  .editor-workspace {
    grid-template-columns: 1fr;
  }

  .menu-input,
  .preview-shell {
    height: auto;
    min-height: 560px;
  }

  .table-shell {
    max-height: none;
  }
}

@media (max-width: 760px) {
  .topbar {
    position: static;
    padding: 9px 10px;
  }

  .shell {
    padding: 10px;
  }

  .panel-head,
  .preview-title,
  .editor-table-head {
    align-items: stretch;
    flex-direction: column;
  }

  .field-tools {
    justify-content: flex-start;
  }

  .menu-input,
  .preview-shell {
    min-height: 520px;
  }

  .editor-wrap textarea {
    font-size: 14px;
    padding: 12px;
  }

  .preview-footer,
  .document-footer {
    flex-direction: column;
  }

  .modal-dialog,
  .users-dialog {
    width: calc(100% - 16px);
    margin: 8px auto;
  }

  .review-item {
    grid-template-columns: 1fr;
  }

  .review-actions-column {
    min-width: 0;
  }

  .document-surface {
    min-height: auto;
    padding: 16px 14px 18px;
  }

  .document-content {
    min-height: 0;
    font-size: 17pt;
  }
}

@media (pointer: coarse) and (max-width: 900px) {
  .document-open-desktop {
    display: none;
  }
}

@media print {
  .topbar,
  .settings-bar,
  .toast {
    display: none !important;
  }

  body {
    background: #fff;
  }

  .shell {
    width: auto;
    margin: 0;
    padding: 0;
  }

  .document-stack {
    gap: 0;
  }

  .document-page {
    width: auto;
    break-after: page;
    page-break-after: always;
  }

  .document-page:last-child {
    break-after: auto;
    page-break-after: auto;
  }

  .document-surface {
    min-height: 297mm;
    border: 0;
    border-radius: 0;
    box-shadow: none;
  }
}
