/* Block styles - reading + editor */

/* Read-only blocks */
.block-stack { display: flex; flex-direction: column; gap: 28px; max-width: 720px; }
.block-stack > * { margin: 0; }

.block-paragraph {
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.65;
  color: var(--ink);
}
.block-paragraph p, .block-paragraph div {
  margin: 0 0 1.1em;
}
.block-paragraph p:last-child, .block-paragraph div:last-child { margin-bottom: 0; }
.block-paragraph sub, .block-paragraph sup { font-size: 0.72em; }

.block-heading {
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  margin: 0;
}
.block-heading.lvl-2 { font-size: 28px; line-height: 1.15; }
.block-heading.lvl-3 { font-size: 22px; line-height: 1.2; }

.block-image {
  margin: 0;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 8px;
  overflow: hidden;
}
.block-image img {
  display: block;
  width: 100%;
  height: auto;
  max-height: 520px;
  object-fit: contain;
  background: var(--paper-2);
}
.block-image figcaption {
  padding: 10px 16px 12px;
  font-family: var(--serif);
  font-style: italic;
  font-size: 14px;
  color: var(--ink-2);
  text-align: center;
  border-top: 1px solid var(--rule);
}

.block-table-wrap {
  overflow-x: auto;
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--card);
}
.block-table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--sans);
  font-size: 14.5px;
}
.block-table th, .block-table td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--rule);
  vertical-align: top;
}
.block-table th {
  background: var(--paper-2);
  font-weight: 600;
  font-family: var(--mono);
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--ink-2);
}
.block-table tr:last-child td { border-bottom: 0; }

/* Graph */
.block-graph {
  margin: 0;
  background: var(--card);
  border: 1px solid var(--rule);
  border-radius: 8px;
  padding: 18px 20px 20px;
}
.graph-title {
  font-family: var(--serif);
  font-weight: 600;
  font-size: 17px;
  margin-bottom: 14px;
  color: var(--ink);
}
.graph-bars { display: flex; flex-direction: column; gap: 8px; }
.graph-row {
  display: grid;
  grid-template-columns: 140px 1fr;
  gap: 12px;
  align-items: center;
}
.graph-label {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-2);
  text-align: right;
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.graph-track {
  background: var(--paper-2);
  border-radius: 4px;
  height: 26px;
  position: relative;
  overflow: hidden;
}
.graph-bar {
  height: 100%;
  border-radius: 4px;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding: 0 10px;
  min-width: 30px;
  transition: width 0.3s ease;
}
.graph-value {
  color: white;
  font-family: var(--mono);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
  text-shadow: 0 1px 0 rgba(0,0,0,0.12);
}

/* Block editor */
.block-editor {
  display: flex;
  flex-direction: column;
  gap: 14px;
}
.block-edit-row {
  border: 1px solid var(--rule);
  border-radius: 8px;
  background: var(--card);
  overflow: hidden;
}
.block-edit-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 5px 10px;
  background: var(--paper-2);
  border-bottom: 1px solid var(--rule);
}
.block-edit-type {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}
.block-edit-actions { display: flex; gap: 4px; }
.block-edit-iconbtn {
  background: transparent;
  border: 1px solid var(--rule);
  border-radius: 5px;
  padding: 4px 9px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  line-height: 1;
  font-family: var(--mono);
}
.block-edit-iconbtn:hover:not(:disabled) {
  background: var(--paper);
  border-color: var(--rule-2);
  color: var(--ink);
}
.block-edit-iconbtn:disabled { opacity: 0.3; cursor: not-allowed; }
.block-edit-iconbtn.danger:hover:not(:disabled) { background: oklch(0.95 0.04 25); color: var(--bad); border-color: var(--bad); }
.block-edit-body { padding: 14px 16px; }
.block-edit-body textarea,
.block-edit-body input {
  width: 100%;
  background: var(--paper);
  border: 1px solid var(--rule-2);
  border-radius: 6px;
  padding: 9px 12px;
  font-size: 14px;
  font-family: var(--sans);
  color: var(--ink);
  outline: none;
}
.block-edit-body textarea {
  font-family: var(--serif);
  font-size: 15px;
  line-height: 1.5;
}
.block-edit-body input:focus,
.block-edit-body textarea:focus { border-color: var(--accent); background: #fff; }

.block-add-bar {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
  padding: 14px;
  border: 1px dashed var(--rule-2);
  border-radius: 8px;
  background: rgba(0,0,0,0.015);
}

/* Image editor */
.image-preview {
  border-radius: 6px;
  background: var(--paper-2);
  overflow: hidden;
  max-height: 240px;
  display: flex;
  align-items: center;
  justify-content: center;
}
.image-preview img { max-width: 100%; max-height: 240px; display: block; }
.image-drop {
  border: 1.5px dashed var(--rule-2);
  border-radius: 8px;
  padding: 30px 14px;
  text-align: center;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  transition: all 0.15s ease;
}
.image-drop:hover { border-color: var(--accent); background: rgba(198,106,61,0.04); }

/* Table editor */
.table-editor { display: flex; flex-direction: column; gap: 8px; }
.table-edit-wrap { overflow-x: auto; }
.table-edit {
  border-collapse: collapse;
  width: 100%;
}
.table-edit td {
  padding: 0;
  border: 1px solid var(--rule);
  vertical-align: middle;
}
.table-edit td input {
  border: 0 !important;
  border-radius: 0 !important;
  padding: 8px 10px !important;
  width: 100% !important;
  min-width: 90px;
  background: transparent !important;
  font-family: var(--sans);
}
.table-edit td input:focus { background: var(--accent-2) !important; }
.table-edit tr.is-header td { background: var(--paper-2); }
.table-edit tr.is-header td input { font-weight: 600; font-family: var(--mono); font-size: 12px; text-transform: uppercase; }
.table-edit td.row-action, .table-edit td.col-action {
  border: 0;
  text-align: center;
  padding: 2px;
  width: 32px;
}

.graph-editor { display: flex; flex-direction: column; }

.chart-type-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.chart-type-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--paper);
  border: 1px solid var(--rule-2);
  border-radius: 6px;
  padding: 7px 11px;
  font-size: 13px;
  color: var(--ink-2);
  cursor: pointer;
  font-family: var(--sans);
  transition: all 0.12s ease;
}
.chart-type-btn:hover { border-color: var(--ink-3); color: var(--ink); }
.chart-type-btn.active {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.chart-type-icon { font-size: 14px; line-height: 1; }

/* Vertical bars */
.graph-vbars {
  display: flex;
  align-items: flex-end;
  justify-content: space-around;
  gap: 14px;
  height: 240px;
  padding: 14px 6px 0;
  border-bottom: 1px solid var(--rule);
}
.vbar-col {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  height: 100%;
  min-width: 32px;
}
.vbar-track {
  flex: 1;
  width: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  max-width: 60px;
}
.vbar-fill {
  width: 100%;
  border-radius: 4px 4px 0 0;
  transition: height 0.3s ease;
  min-height: 4px;
}
.vbar-value {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-2);
  font-weight: 500;
}
.vbar-label {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
  width: 100%;
  text-align: center;
  margin-top: 4px;
}

/* SVG charts */
.graph-svg {
  width: 100%;
  height: auto;
  display: block;
}
.svg-axis-label {
  font-family: var(--mono);
  font-size: 11px;
  fill: var(--ink-3);
}
.svg-value-label {
  font-family: var(--mono);
  font-size: 11px;
  fill: var(--ink-2);
  font-weight: 500;
}
.svg-pie-center {
  font-family: var(--serif);
  font-size: 22px;
  fill: var(--ink);
  font-weight: 600;
}

.graph-pie-wrap {
  display: flex;
  align-items: center;
  gap: 24px;
  flex-wrap: wrap;
  justify-content: center;
}
.graph-pie-wrap .graph-svg { flex: 0 0 auto; }
.graph-legend {
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex: 1;
  min-width: 180px;
}
.legend-row {
  display: grid;
  grid-template-columns: 14px 1fr auto;
  gap: 10px;
  align-items: center;
  font-size: 13.5px;
  color: var(--ink);
}
.legend-swatch {
  width: 14px; height: 14px;
  border-radius: 3px;
}
.legend-label {
  font-family: var(--sans);
  text-overflow: ellipsis;
  overflow: hidden;
  white-space: nowrap;
}
.legend-value {
  font-family: var(--mono);
  font-size: 12px;
  color: var(--ink-2);
}
.legend-value em { color: var(--ink-3); font-style: normal; }

/* ---- Rich text editor ---- */
.rich-wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
}
.rich-toolbar {
  display: flex;
  align-items: center;
  gap: 2px;
  padding: 5px 7px;
  background: var(--paper-2);
  border: 1px solid var(--rule-2);
  border-bottom: none;
  border-radius: 6px 6px 0 0;
}
.rich-wrap:focus-within .rich-toolbar { border-color: var(--accent); }

.rich-btn {
  -webkit-appearance: none;
  appearance: none;
  width: 28px;
  height: 26px;
  padding: 0;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  font-size: 13px;
  font-family: var(--sans);
  cursor: pointer;
  color: var(--ink-2);
  line-height: 1;
  outline: none;
  transition: background 0.1s ease, color 0.1s ease, border-color 0.1s ease;
}
.rich-btn:hover { background: rgba(28,26,23,0.07); border-color: var(--rule); color: var(--ink); }
.rich-btn.on { background: var(--ink); color: var(--paper); border-color: var(--ink); }

.rich-sep {
  width: 1px;
  height: 14px;
  background: var(--rule-2);
  margin: 0 3px;
  flex-shrink: 0;
  align-self: center;
}
.rich-editor {
  background: var(--card);
  border: 1px solid var(--rule-2);
  border-radius: 0 0 6px 6px;
  padding: 10px 12px;
  font-size: 14px;
  color: var(--ink);
  outline: none;
  font-family: var(--sans);
  line-height: 1.6;
  word-break: break-word;
  overflow-wrap: break-word;
  cursor: text;
  transition: border-color 0.15s ease, background 0.15s ease;
}
.rich-wrap:focus-within .rich-editor { border-color: var(--accent); background: #fff; }
.rich-editor:empty::before {
  content: attr(data-placeholder);
  color: var(--ink-3);
  pointer-events: none;
  font-style: italic;
}
.rich-editor sub, .rich-editor sup { font-size: 0.72em; }

/* Paragraph block editor: match reading-view typography */
.block-edit-body .rich-editor div,
.block-edit-body .rich-editor p {
  margin: 0 0 1.1em;
}
.block-edit-body .rich-editor div:last-child,
.block-edit-body .rich-editor p:last-child { margin-bottom: 0; }
.block-edit-body .rich-toolbar {
  background: var(--paper-2);
  border-color: var(--rule);
  border-radius: 6px 6px 0 0;
  margin-bottom: 0;
}
.block-edit-body .rich-wrap:focus-within .rich-toolbar { border-color: var(--accent); }
.block-edit-body .rich-editor {
  font-family: var(--serif);
  font-size: 19px;
  line-height: 1.65;
  background: var(--paper);
  border-color: var(--rule);
}

/* Heading editor input: styled like actual headings */
.heading-edit-wrap {
  display: flex;
  align-items: baseline;
  gap: 10px;
}
.heading-edit-level {
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  background: var(--paper-2);
  border: 1px solid var(--rule-2);
  border-radius: 5px;
  padding: 4px 8px;
  cursor: pointer;
  align-self: center;
  flex-shrink: 0;
}
.heading-edit-input {
  flex: 1;
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
  background: transparent;
  border: none;
  border-bottom: 2px dashed var(--rule-2);
  border-radius: 0;
  padding: 4px 0;
  outline: none;
  width: 100%;
}
.heading-edit-input:focus { border-bottom-color: var(--accent); }
.heading-edit-input::placeholder { color: var(--ink-3); font-style: italic; font-weight: 400; }
/* Override .block-edit-body input for style controls */
.block-edit-body .block-style-input {
  background: var(--paper);
  border: 1px solid var(--rule-2);
  border-radius: 6px;
  padding: 5px 6px;
  font-size: 13px;
  font-family: var(--sans);
}
.block-edit-body .block-style-input:focus { background: var(--paper); border-color: var(--accent); }
.block-edit-body .heading-edit-input {
  background: transparent;
  border: none;
  border-bottom: 2px dashed var(--rule-2);
  border-radius: 0;
  padding: 4px 0;
}
.block-edit-body .heading-edit-input:focus { background: transparent; border-color: transparent; border-bottom-color: var(--accent); }

/* Block style controls (font / size / spacing) */
.block-style-row {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 10px;
  margin-bottom: 10px;
  padding-bottom: 10px;
  border-bottom: 1px solid var(--rule);
}
.block-style-label {
  font-family: var(--mono);
  font-size: 11px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  white-space: nowrap;
}
.block-style-input {
  background: var(--paper);
  border: 1px solid var(--rule-2);
  border-radius: 6px;
  padding: 5px 6px;
  font-size: 13px;
  font-family: var(--sans);
  color: var(--ink);
  width: 58px;
}
.block-style-input:focus { outline: none; border-color: var(--accent); }

/* Font picker */
.font-picker { position: relative; }
.font-picker-btn {
  -webkit-appearance: none;
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--paper);
  border: 1px solid var(--rule-2);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
  font-family: var(--sans);
  color: var(--ink);
  cursor: pointer;
  white-space: nowrap;
  line-height: 1.4;
}
.font-picker-btn:focus { outline: none; border-color: var(--accent); }
.font-picker-arrow { font-size: 10px; color: var(--ink-3); }
.font-picker-dropdown {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  background: var(--card);
  border: 1px solid var(--rule-2);
  border-radius: 8px;
  box-shadow: 0 4px 16px rgba(0,0,0,0.12);
  overflow: hidden;
  z-index: 200;
  min-width: 170px;
  display: flex;
  flex-direction: column;
}
.font-picker-opt {
  width: 100%;
  text-align: left;
  padding: 9px 14px;
  font-size: 14px;
  background: transparent;
  border: none;
  border-bottom: 1px solid var(--rule);
  color: var(--ink);
  cursor: pointer;
}
.font-picker-opt:last-child { border-bottom: none; }
.font-picker-opt:hover { background: var(--paper-2); }
.font-picker-opt.active { background: var(--accent-2); color: var(--accent); }
