:root {
  --ink: #111;
  --paper: #fff;
  --bg: #ededed;
  --panel: #f7f7f7;
  --rule: #d8d8d8;
  --field-border: #c8c8c8;
  --muted: #777;
  --muted-2: #555;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--ink);
  font-size: 13px;
  -webkit-font-smoothing: antialiased;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.5rem 1rem;
  background: #fff;
  border-bottom: 1px solid #ddd;
}

.toolbar h1 {
  font-size: 1rem;
  font-weight: 600;
  margin: 0;
  flex: 1;
}

.toolbar-actions > button,
.filemenu > button {
  height: 32px;
  padding: 0 0.9rem;
  border: 1px solid var(--ink);
  background: var(--paper);
  color: var(--ink);
  border-radius: 2px;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0.02em;
  display: inline-flex;
  align-items: center;
  box-sizing: border-box;
  transition: background 0.1s, color 0.1s;
}

.toolbar-actions > button:hover:not(:disabled) {
  background: var(--ink);
  color: var(--paper);
}

.toolbar-actions > button:disabled {
  opacity: 0.4;
  cursor: not-allowed;
}

.toolbar-actions > button.primary {
  background: var(--ink);
  color: var(--paper);
}

.toolbar-actions > button.primary:hover:not(:disabled) {
  background: #333;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.filemenu {
  position: relative;
}

.filemenu > button:hover:not(:disabled) {
  background: var(--ink);
  color: var(--paper);
}
.filemenu > button:disabled {
  opacity: 0.4; cursor: not-allowed;
}

.filemenu-list {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 140px;
  background: var(--paper);
  border: 1px solid var(--ink);
  border-radius: 2px;
  box-shadow: 0 4px 12px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.filemenu-list > button {
  padding: 0.5rem 0.9rem;
  border: none;
  background: transparent;
  color: var(--ink);
  text-align: left;
  cursor: pointer;
  font-family: inherit;
  font-size: 12px;
  font-weight: 500;
}
.filemenu-list > button:hover:not(:disabled) {
  background: #f3f3f3;
}
.filemenu-list > button:disabled {
  opacity: 0.4; cursor: not-allowed;
}

.preview-toolbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.4rem 0.75rem;
  border-bottom: 1px solid #e5e5e5;
  background: #fafafa;
}

.error {
  padding: 0.5rem 1rem;
  background: #fee;
  color: #900;
  border-bottom: 1px solid #fcc;
  font-size: 0.85rem;
}

.body {
  flex: 1;
  display: grid;
  grid-template-columns: 440px 4px 1fr;
  overflow: hidden;
}

.left {
  border-right: 1px solid #ddd;
  background: #fff;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.splitter {
  background: #ddd;
  cursor: col-resize;
  user-select: none;
}

.splitter:hover {
  background: #999;
}

.tabs {
  display: flex;
  border-bottom: 1px solid #ddd;
  background: #fafafa;
  flex-shrink: 0;
}

.tab {
  flex: 1;
  padding: 0.6rem 0.3rem;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 500;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: #777;
  cursor: pointer;
  border: none;
  background: transparent;
  border-bottom: 2px solid transparent;
  font-family: inherit;
}

.tab.active {
  color: #111;
  border-bottom-color: #111;
  background: #fff;
}

.tab:hover:not(.active) {
  color: #333;
  background: #f0f0f0;
}

.form {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 1rem;
}

.form h2 {
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #888;
  margin: 1rem 0 0.5rem;
  font-weight: 600;
}

.form h2:first-child {
  margin-top: 0;
}

.field {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  margin-bottom: 0.4rem;
  font-size: 0.85rem;
}

.field label {
  flex: 0 0 110px;
  color: #555;
}

.field input[type="text"] {
  flex: 1;
  padding: 0.25rem 0.4rem;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 0.85rem;
  background: #fff;
}

.field input[readonly] {
  background: #f7f7f7;
  color: #444;
}

.field.checkbox label {
  flex: 1;
}

.field.checkbox input {
  margin: 0;
}

.preview-pane {
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background: var(--bg);
  min-width: 0;
}

.preview-canvas {
  flex: 1;
  overflow: auto;
  padding: 1rem;
  display: flex;
  justify-content: center;
  align-items: flex-start;
}

.preview-canvas img {
  background: var(--paper);
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.1);
  display: block;
}

.placeholder {
  color: #888;
  padding: 2rem;
}

.row {
  border: 1px solid #e0e0e0;
  border-radius: 4px;
  padding: 0.4rem 0.5rem;
  margin-bottom: 0.4rem;
  background: #fafafa;
}

.row-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.3rem;
  font-size: 0.75rem;
  color: #666;
  font-weight: 600;
}

.row-fields {
  display: flex;
  flex-direction: column;
  gap: 0.2rem;
}

.row-label {
  font-size: 0.7rem;
  color: #888;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  margin-top: 0.3rem;
}

.row-label:first-child {
  margin-top: 0;
}

button.expand-toggle {
  background: none;
  border: none;
  color: #555;
  cursor: pointer;
  font-size: 0.75rem;
  text-align: left;
  padding: 0.3rem 0;
  margin-top: 0.2rem;
  font-family: inherit;
}

button.expand-toggle:hover {
  color: #111;
}

.row-fields input,
.row-fields select,
.row-fields textarea {
  padding: 0.25rem 0.4rem;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 0.8rem;
  background: #fff;
  font-family: inherit;
  width: 100%;
  box-sizing: border-box;
}

.row-fields textarea {
  resize: vertical;
}

.field-pair {
  display: flex;
  gap: 0.3rem;
}

.field-pair input,
.field-pair select {
  flex: 1;
  min-width: 0;
}

.field-triple {
  display: flex;
  gap: 0.3rem;
}

.field-triple input {
  flex: 1;
  min-width: 0;
}

button.del {
  background: none;
  border: none;
  color: #c00;
  cursor: pointer;
  font-size: 1rem;
  padding: 0 0.3rem;
  line-height: 1;
}

button.del:hover {
  color: #f00;
}

button.add {
  width: 100%;
  padding: 0.4rem;
  border: 1px dashed #999;
  background: #fff;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.85rem;
  color: #444;
  margin-bottom: 0.5rem;
}

button.add:hover {
  background: #f0f0f0;
}

.page-info {
  font-size: 0.85rem;
  color: #888;
  font-variant-numeric: tabular-nums;
}

.zoom {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-size: 0.8rem;
  color: var(--muted-2);
  font-variant-numeric: tabular-nums;
}

.zoom button {
  width: 24px;
  height: 24px;
  padding: 0;
  border: 1px solid #ccc;
  background: var(--paper);
  cursor: pointer;
  border-radius: 3px;
  font-size: 0.95rem;
  line-height: 1;
}

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

.zoom span {
  min-width: 3rem;
  text-align: center;
}

.pages {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  align-items: center;
}

textarea.notes {
  width: 100%;
  padding: 0.4rem;
  border: 1px solid #ccc;
  border-radius: 3px;
  font-size: 0.85rem;
  font-family: inherit;
  box-sizing: border-box;
  resize: vertical;
}
