:root {
  --radius: 4px;
  --list-filter-sticky-h: 50px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, sans-serif;
  background: #f4f4f4;
  color: #222;
}

.app {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
}

.topbar {
  border-bottom: 1px solid #ddd;
  background: #fff;
  padding: 10px 260px 10px 10px;
  display: grid;
  gap: 10px;
  position: relative;
}

.topbar-right-image {
  position: absolute;
  right: 10px;
  top: 10px;
  height: calc(100% - 20px);
  max-height: 92px;
  width: auto;
  object-fit: contain;
  pointer-events: none;
}

.top-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.title {
  font-weight: 700;
}

.muted {
  color: #666;
  font-size: 12px;
}

.toolbar {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.toolbar-sep {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  color: #999;
  user-select: none;
}

.mode-switch {
  display: inline-flex;
  border: 1px solid #ccc;
  border-radius: var(--radius);
  overflow: hidden;
  background: #fff;
}

.mode-switch button {
  border: 0;
  border-radius: 0;
  padding: 7px 12px;
}

.mode-switch button + button {
  border-left: 1px solid #ccc;
}

.mode-switch button.active {
  background: #111;
  color: #fff;
}

.toolbar-issues {
  white-space: nowrap;
}

.toolbar-inconsistency {
  white-space: nowrap;
  color: #8d3d08;
}

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

button {
  border: 1px solid #ccc;
  background: #fff;
  border-radius: var(--radius);
  padding: 7px 10px;
  cursor: pointer;
}

button.primary {
  background: #111;
  color: #fff;
  border-color: #111;
}

button.danger {
  background: #8b1e1e;
  color: #fff;
  border-color: #8b1e1e;
}

button:disabled {
  opacity: 0.55;
  cursor: default;
}

.settings {
  border: 1px solid #eee;
  background: #fafafa;
  border-radius: var(--radius);
  padding: 10px;
  display: flex;
  gap: 16px;
  flex-wrap: wrap;
}

.settings label {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  font-size: 13px;
}

.doc-fonts-panel {
  border-top: 1px solid #ddd;
  border-bottom: 1px solid #ddd;
  background: #fff;
  padding: 10px;
}

.doc-fonts-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}

.doc-fonts-head h3 {
  margin: 0;
  font-size: 15px;
}

.doc-fonts-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.doc-fonts-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 12px;
}

.doc-fonts-table th,
.doc-fonts-table td {
  border: 1px solid #e2e2e2;
  padding: 5px 6px;
  vertical-align: top;
}

.doc-fonts-table th {
  background: #f6f6f6;
  text-align: left;
}

.help {
  width: 14px;
  height: 14px;
  border: 1px solid #cfcfcf;
  border-radius: 99px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 10px;
  background: #f7f7f7;
}

.test-mode-panel {
  padding: 14px 0 24px;
}

.test-mode-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.test-mode-head h3 {
  margin: 0 0 4px;
  font-size: 16px;
}

.test-mode-grid {
  display: grid;
  grid-template-columns: 92px 1fr;
  gap: 10px;
  align-items: start;
}

.test-mode-grid label {
  font-size: 13px;
  color: #555;
  padding-top: 6px;
}

.test-mode-grid textarea {
  width: 100%;
  min-width: 0;
  resize: vertical;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 12px;
  line-height: 1.4;
  border: 1px solid #d4d4d4;
  border-radius: var(--radius);
  padding: 8px;
  background: #fff;
}

.test-mode-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.test-warnings {
  margin-top: 12px;
  padding: 9px 10px;
  border: 1px solid #d7bd77;
  border-radius: var(--radius);
  background: #fff8e6;
  color: #5f4514;
  font-size: 13px;
}

.test-warnings-title {
  font-weight: 700;
  margin-bottom: 5px;
}

.test-warning-item + .test-warning-item {
  margin-top: 4px;
}

.test-error {
  margin-top: 12px;
  padding: 9px 10px;
  border: 1px solid #d8a3a3;
  border-radius: var(--radius);
  background: #fff5f5;
  color: #7a1e1e;
  font-size: 13px;
  white-space: pre-wrap;
}

#filltool_viewer {
  padding: 0;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.filltool-viewer-toolbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border-bottom: 1px solid #ddd;
  background: #fff;
}

.filltool-viewer-toolbar button {
  flex: 0 0 auto;
  white-space: nowrap;
}

.filltool-viewer-toolbar button.active {
  background: #111;
  color: #fff;
  border-color: #111;
}

.filltool-viewer-toolbar .muted {
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.filltool-log-view,
.filltool-external-view {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  background: #f7f7f7;
}

.filltool-log-view {
  padding: 10px;
}

.filltool-log-empty {
  color: #666;
  font-size: 13px;
  padding: 12px;
}

.filltool-log-item {
  border: 1px solid #ddd;
  border-radius: var(--radius);
  background: #fff;
  padding: 8px;
  font-size: 13px;
}

.filltool-log-item + .filltool-log-item {
  margin-top: 8px;
}

.filltool-log-item.level-warn {
  border-color: #d7bd77;
  background: #fffaf0;
}

.filltool-log-item.level-error {
  border-color: #d8a3a3;
  background: #fff5f5;
}

.filltool-log-item.level-ok {
  border-color: #9fc69f;
  background: #f5fff5;
}

.filltool-log-line {
  display: flex;
  align-items: center;
  gap: 8px;
}

.filltool-log-time,
.filltool-log-level {
  color: #666;
  font-size: 12px;
}

.filltool-log-level {
  min-width: 42px;
  text-transform: uppercase;
}

.filltool-log-item pre {
  margin: 8px 0 0;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: var(--radius);
  background: #fafafa;
  white-space: pre-wrap;
  font-size: 12px;
  overflow: auto;
}

.filltool-external-view iframe {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  border: 0;
  background: #fff;
}

.test-status {
  margin-top: 12px;
  display: grid;
  gap: 6px;
  font-size: 13px;
}

.test-status a {
  color: #111;
}

.test-status pre {
  max-height: 240px;
  overflow: auto;
  margin: 4px 0 0;
  padding: 8px;
  border: 1px solid #ddd;
  border-radius: var(--radius);
  background: #fafafa;
  font-size: 12px;
  white-space: pre-wrap;
}

.main {
  min-height: 0;
  display: grid;
  grid-template-columns: 460px 560px 1fr;
}

.panel {
  border-right: 1px solid #ddd;
  background: #fff;
  min-height: 0;
  overflow: auto;
  padding: 0 10px 0 10px;
}

.panel:last-child {
  border-right: 0;
}

#page_preview {
  padding-left: 0;
  padding-right: 0;
  position: relative;
  display: flex;
  flex-direction: column;
  overflow: hidden;
}

.preview-status-overlay {
  position: absolute;
  top: 8px;
  right: 10px;
  z-index: 70;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  pointer-events: none;
}

.preview-status-item {
  font-size: 12px;
  color: #222;
  background: rgba(255, 255, 255, 0.96);
  border: 1px solid #d9d9d9;
  border-radius: var(--radius);
  padding: 4px 8px;
  white-space: nowrap;
}

.preview-status-item.clickable {
  cursor: pointer;
  pointer-events: auto;
}

.preview-status-details {
  width: min(520px, calc(100vw - 24px));
  max-height: 45vh;
  overflow: auto;
  pointer-events: auto;
  color: #222;
  background: rgba(255, 255, 255, 0.98);
  border: 1px solid #d9d9d9;
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
  padding: 8px;
}

.status-detail-section + .status-detail-section {
  margin-top: 10px;
  padding-top: 8px;
  border-top: 1px solid #e5e5e5;
}

.status-detail-title {
  font-size: 12px;
  font-weight: 700;
  margin-bottom: 4px;
}

.status-detail-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr);
  gap: 2px;
  padding: 4px 0;
  font-size: 12px;
  line-height: 1.25;
  border-top: 1px solid #f1f1f1;
}

.status-detail-row:first-of-type {
  border-top: 0;
}

.status-detail-row span {
  overflow-wrap: anywhere;
}

.field-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.list-filter-bar {
  display: flex;
  gap: 6px;
  align-items: center;
  padding: 8px 0;
  position: sticky;
  top: 0;
  z-index: 12;
  background: #fff;
}

.list-filter-input {
  flex: 1;
  width: 100%;
  border: 1px solid #cfcfcf;
  border-radius: var(--radius);
  height: 34px;
  box-sizing: border-box;
  padding: 0 10px;
  color: #111;
  background: #fff;
}

.list-filter-clear {
  min-width: 34px;
  height: 34px;
  padding: 0;
  line-height: 1;
}

.field-table th {
  position: sticky;
  top: var(--list-filter-sticky-h);
  background: #eee;
  z-index: 8;
  border: 0;
  text-align: left;
  padding: 8px 6px;
}

.th-sort {
  all: unset;
  display: inline-flex;
  gap: 6px;
  align-items: center;
  cursor: pointer;
  user-select: none;
  font-weight: 600;
}

.sort-ind {
  font-size: 11px;
  color: #666;
  min-width: 10px;
}

.field-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 24px;
  height: 24px;
  margin-right: 6px;
  border-radius: var(--radius);
  border: 1px solid #ddd;
  background: #fff;
  color: #111;
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  vertical-align: middle;
}

.field-icon svg {
  width: 20px;
  height: 20px;
  display: block;
}

.field-table td {
  border-bottom: 1px solid #eee;
  padding: 6px;
}

.status-cell {
  white-space: nowrap;
}

.btn-list-meta {
  margin-top: 2px;
  color: #5f5f5f;
  font-size: 11px;
  line-height: 1.1;
}

.status-row {
  display: flex;
  gap: 6px;
  align-items: center;
  flex-wrap: wrap;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 20px;
  height: 18px;
  padding: 0 6px;
  border: 1px solid #cfcfcf;
  border-radius: 999px;
  font-size: 11px;
  line-height: 1;
  background: #f7f7f7;
  color: #333;
}

.status-pill.issue {
  background: #ffeceb;
  border-color: #f1b5b1;
  color: #a63a32;
}

.status-pill.overlap {
  background: #fff4e5;
  border-color: #f0cf9f;
  color: #8a5a16;
}

.status-pill.shared {
  background: #e9f2ff;
  border-color: #b8d0f5;
  color: #1f4f8a;
}

.status-pill.linked {
  background: #edf7ec;
  border-color: #b9dfb5;
  color: #2f6a2c;
}

.field-table tr.sel {
  outline: 2px solid rgba(255, 140, 0, 0.95);
  outline-offset: -2px;
  background: rgba(255, 196, 0, 0.22);
}

.editor-grid {
  display: grid;
  grid-template-columns: 130px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  padding: 10px 0;
}

.acro-raw-section {
  margin-top: 12px;
  border-top: 1px solid #e6e6e6;
  padding-top: 10px;
}

.acro-raw-section h3 {
  margin: 0 0 8px 0;
  font-size: 14px;
}

.acro-raw-pre {
  margin: 0;
  border: 1px solid #dcdcdc;
  border-radius: var(--radius);
  background: #fafafa;
  color: #222;
  padding: 8px 10px;
  max-height: 320px;
  overflow: auto;
  white-space: pre-wrap;
  font-size: 12px;
  line-height: 1.35;
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.script-check-section {
  margin-top: 12px;
  border-top: 1px solid #e6e6e6;
  padding-top: 10px;
}

.script-check-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  margin-bottom: 8px;
}

.script-check-head h3 {
  margin: 0;
  font-size: 14px;
}

.script-check-list {
  margin-top: 8px;
  border: 1px solid #dcdcdc;
  border-radius: var(--radius);
  background: #fafafa;
  max-height: 220px;
  overflow: auto;
  padding: 6px 8px;
}

.script-check-item {
  padding: 6px 0;
  border-bottom: 1px solid #e8e8e8;
  font-size: 12px;
  line-height: 1.35;
}

.script-check-item:last-child {
  border-bottom: 0;
}

.editor-grid label {
  font-size: 13px;
}

.editor-grid input[type="text"],
.editor-grid input[type="number"],
.editor-grid select {
  width: 100%;
  border: 1px solid #cfcfcf;
  border-radius: var(--radius);
  height: 34px;
  box-sizing: border-box;
  padding: 0 10px;
  line-height: 1.2;
  color: #111;
  background: #fff;
}

.editor-grid select {
  padding-right: 30px;
}

.editor-grid textarea {
  width: 100%;
  border: 1px solid #cfcfcf;
  border-radius: var(--radius);
  min-height: 68px;
  padding: 8px 10px;
}

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

.nudge {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
}

.rect-line input[type="number"] {
  width: 72px;
}

.preview-toolbar {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: nowrap;
  position: sticky;
  top: 0;
  z-index: 50;
  background: #fff;
  padding: 6px 10px 8px 10px;
  border-bottom: 1px solid #e6e6e6;
  width: 100%;
  box-sizing: border-box;
  isolation: isolate;
  flex: 0 0 auto;
}

.preview-scroll {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  padding: 8px 10px 10px 10px;
  background-color: #efefef;
}

.preview-toolbar-spacer {
  margin-left: auto;
}

.grid-cm {
  width: 66px;
}

.preview-help {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.preview-help-icon {
  width: 22px;
  height: 22px;
  border-radius: var(--radius);
  border: 1px solid #d0d0d0;
  background: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 12px;
  font-weight: 700;
  cursor: help;
}

.preview-help-legend {
  position: absolute;
  top: 26px;
  right: 0;
  min-width: 280px;
  border: 1px solid #ddd;
  border-radius: var(--radius);
  background: #fff;
  box-shadow: 0 6px 16px rgba(0, 0, 0, 0.12);
  padding: 8px 10px;
  font-size: 12px;
  z-index: 10;
  display: none;
}

.preview-help:hover .preview-help-legend {
  display: block;
}

.preview-help-legend .item {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 8px;
  margin: 3px 0;
}

.preview-help-legend .k {
  font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

.preview-wrap {
  position: relative;
  display: inline-block;
  background: #fff;
  border: 1px solid #ddd;
  cursor: crosshair;
  touch-action: none;
}

.preview-wrap img {
  display: block;
  max-width: none;
  height: auto;
  user-select: none;
  -webkit-user-drag: none;
}

.overlay {
  position: absolute;
  border: 1px solid rgba(90, 90, 90, 0.65);
  background: rgba(120, 120, 120, 0.12);
  pointer-events: none;
}

.overlay.grid-overlay {
  border: 0;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  background-color: transparent;
}

.overlay.crosshair {
  border: 0;
  background: rgba(0, 140, 255, 0.9);
}

.crosshair-label {
  position: absolute;
  z-index: 30;
  pointer-events: none;
  font-size: 11px;
  line-height: 1;
  color: #0f3b66;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #bcd2ea;
  border-radius: var(--radius);
  padding: 3px 6px;
  white-space: nowrap;
}

.overlay.sel {
  border: 2px solid rgba(255, 140, 0, 0.95);
  background: rgba(255, 196, 0, 0.22);
}

.overlay.bulk {
  border: 2px solid rgba(0, 128, 255, 0.85);
  background: rgba(0, 128, 255, 0.14);
}

.overlay.btn-value-active {
  border: 2px solid rgba(40, 160, 95, 0.95);
  background: rgba(80, 190, 120, 0.22);
}

.overlay-btn-value {
  position: absolute;
  left: 2px;
  top: 2px;
  z-index: 2;
  font-size: 10px;
  line-height: 1;
  color: #1f3f6b;
  background: rgba(255, 255, 255, 0.95);
  border: 1px solid #b8cbe5;
  border-radius: 3px;
  padding: 1px 3px;
  pointer-events: none;
}

.row {
  display: flex;
  gap: 8px;
  align-items: center;
}

.editor-actions {
  grid-column: 1 / -1;
}

.spacer {
  flex: 1;
}
