* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  color: #1f2328;
  background: #eef0f3;
}

/* Header */
.topbar {
  position: sticky; top: 0; z-index: 10;
  background: #fff;
  border-bottom: 1px solid #d0d7de;
}
.topbar-row {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 6px 12px; min-height: 52px;
}
.brand { font-size: 18px; margin: 0 auto 0 0; }
.save-status { font-size: 14px; color: #57606a; }
.save-status.error { color: #b42318; }
.nav { display: flex; flex-wrap: wrap; }
.nav a {
  display: inline-flex; align-items: center; min-height: 44px; padding: 0 10px;
  color: #0b57d0; text-decoration: none; font-weight: 600; white-space: nowrap;
}
.nav a[aria-current="page"] { color: #1f2328; box-shadow: inset 0 -3px 0 #0b57d0; }
@media (max-width: 480px) {
  .nav { width: 100%; justify-content: space-between; }
  .nav a { padding: 0 6px; }
}
.tabs { display: flex; }
.tab {
  flex: 1; min-height: 44px; border: 0; border-bottom: 3px solid transparent;
  background: none; font: inherit; font-weight: 600; color: #57606a; cursor: pointer;
}
.tab[aria-selected="true"] { color: #0b57d0; border-bottom-color: #0b57d0; }

/* Layout: tabs on phones, side by side on desktop */
.layout { display: block; }
.pane { min-width: 0; }
body[data-tab="edit"] .pane-preview,
body[data-tab="preview"] .pane-edit { display: none; }

@media (min-width: 900px) {
  .tabs { display: none; }
  .layout {
    display: grid; grid-template-columns: minmax(380px, 1fr) minmax(0, 1.3fr);
    height: calc(100vh - 53px);
  }
  body[data-tab] .pane { display: block; overflow-y: auto; }
  .pane-edit { border-right: 1px solid #d0d7de; }
}

.pane-edit { padding: 12px; }
.pane-preview { padding: 12px; }
.paper-fit { margin: 0 auto; overflow: hidden; }

.loading, .load-error { padding: 24px 8px; text-align: center; color: #57606a; }
.load-error strong { display: block; color: #1f2328; font-size: 18px; margin-bottom: 6px; }

/* Editor */
.card {
  background: #fff; border: 1px solid #d0d7de; border-radius: 10px;
  margin-bottom: 12px; overflow: hidden;
}
.card-head {
  display: flex; align-items: center; gap: 6px; padding: 6px;
  background: #f6f8fa; border-bottom: 1px solid #d0d7de;
}
.card.collapsed .card-head { border-bottom: 0; }
.card.collapsed .card-body { display: none; }
.card-head .title-input { flex: 1; min-width: 0; font-weight: 700; }
.card-body { padding: 10px; }
.card-label { flex: 1; font-weight: 700; padding-left: 6px; }

.entry {
  border: 1px solid #e1e4e8; border-radius: 8px; padding: 8px; margin-bottom: 10px;
  background: #fbfbfc;
}
.entry-head { display: flex; align-items: center; gap: 4px; margin-bottom: 4px; }
.entry-head .entry-name {
  flex: 1; min-width: 0; font-weight: 600; font-size: 14px; color: #57606a;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}

.field { display: block; margin-bottom: 8px; }
.field > span { display: block; font-size: 13px; color: #57606a; margin-bottom: 2px; }
.grid2 { display: grid; grid-template-columns: 1fr; gap: 0 8px; }
@media (min-width: 520px) { .grid2 { grid-template-columns: 1fr 1fr; } }

input[type="text"], input[type="email"], input[type="tel"], input[type="url"], textarea {
  width: 100%; min-height: 44px; padding: 10px; font: inherit; font-size: 16px;
  border: 1px solid #c4cbd3; border-radius: 6px; background: #fff; color: inherit;
}
textarea { resize: vertical; line-height: 1.35; field-sizing: content; min-height: 64px; }
input:focus, textarea:focus { outline: 2px solid #0b57d0; outline-offset: -1px; border-color: #0b57d0; }

.list-item { display: flex; gap: 6px; align-items: flex-start; margin-bottom: 6px; }
.list-item > .grow { flex: 1; min-width: 0; }
.tools { display: flex; flex-wrap: wrap; gap: 2px; }
.list-item .tools { flex-direction: column; }
@media (min-width: 520px) { .list-item .tools { flex-direction: row; } }
.sub { font-size: 13px; font-weight: 600; color: #57606a; margin: 8px 0 4px; }

.btn {
  min-height: 44px; min-width: 44px; padding: 0 14px; font: inherit; font-size: 15px;
  border: 1px solid #c4cbd3; border-radius: 8px; background: #fff; color: #1f2328; cursor: pointer;
}
.btn:active { background: #eef0f3; }
.btn:disabled { opacity: 0.35; cursor: default; }
.btn-icon { padding: 0; width: 44px; font-size: 18px; line-height: 1; }
.btn-small { min-height: 36px; font-size: 14px; }
.btn-add { width: 100%; border-style: dashed; color: #0b57d0; margin-top: 4px; }
.btn-danger { color: #b42318; }
.add-row { display: flex; gap: 8px; flex-wrap: wrap; }
.add-row .btn { flex: 1; }

/* Page counter + export */
#toolbar-extra { display: flex; align-items: center; gap: 8px; }
.page-badge {
  font-size: 13px; font-weight: 600; padding: 3px 9px; border-radius: 999px;
  background: #dafbe1; color: #116329; white-space: nowrap;
}
.page-badge:empty { display: none; }
.page-badge.over { background: #ffebe9; color: #b42318; }

/* Per-bullet lint hints + AI rewrite */
.bullet-tools { display: flex; align-items: flex-start; gap: 8px; margin: 4px 0 2px; }
.bullet-hints { flex: 1; min-width: 0; margin: 0; padding: 0; list-style: none; font-size: 12.5px; color: #9a6700; }
.bullet-hints li::before { content: "⚠ "; }
.btn-rewrite { flex: none; padding: 0 12px; color: #0b57d0; }
.rewrite-result:empty { display: none; }
.rewrite-result { margin: 4px 0 6px; display: flex; flex-direction: column; gap: 6px; }
.rewrite-label { font-size: 12.5px; color: #57606a; }
.rewrite-choice {
  min-height: 44px; padding: 8px 10px; font: inherit; font-size: 14px; line-height: 1.35; text-align: left;
  border: 1px solid #b6d0f7; border-radius: 8px; background: #f2f7ff; color: #1f2328; cursor: pointer;
  overflow-wrap: anywhere;
}
.rewrite-choice:active { background: #dde9fd; }
.rewrite-dismiss { align-self: flex-start; }
.rewrite-error { margin: 0; font-size: 13px; color: #b42318; }
