:root {
  color-scheme: light;
  --bg: #f5f6f3;
  --panel: #ffffff;
  --ink: #1e2428;
  --muted: #66717b;
  --line: #d8ddd7;
  --accent: #167c80;
  --accent-strong: #0d5f63;
  --warn: #9b5a19;
  --field: #e9f4ee;
  --paper: #fffefa;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

button,
input,
select {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(260px, 320px) 1fr;
  min-height: 100vh;
}

.sidebar {
  background: #fbfbf8;
  border-right: 1px solid var(--line);
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 18px 14px;
  gap: 18px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  align-items: center;
  background: #25302f;
  border-radius: 6px;
  color: #fff;
  display: inline-flex;
  font-weight: 800;
  height: 44px;
  justify-content: center;
  width: 54px;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.2;
  margin: 0;
}

.brand p,
.muted {
  color: var(--muted);
  font-size: 13px;
  margin: 2px 0 0;
}

.sidebar-section {
  min-height: 0;
}

.section-title {
  align-items: center;
  color: #30383d;
  display: flex;
  font-size: 13px;
  font-weight: 700;
  justify-content: space-between;
  margin-bottom: 8px;
  text-transform: uppercase;
}

.template-list,
.field-list {
  display: grid;
  gap: 8px;
}

.template-item,
.field-item {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  cursor: pointer;
  padding: 10px;
  text-align: left;
  width: 100%;
}

.template-item.active {
  border-color: var(--accent);
  box-shadow: inset 3px 0 0 var(--accent);
}

.template-name {
  display: block;
  font-size: 14px;
  font-weight: 700;
}

.template-meta,
.field-path {
  color: var(--muted);
  display: block;
  font-size: 12px;
  margin-top: 3px;
  overflow-wrap: anywhere;
}

.field-item {
  background: var(--field);
  cursor: default;
}

.counter {
  background: #e3e8e1;
  border-radius: 999px;
  color: #293330;
  font-size: 12px;
  padding: 2px 8px;
}

.workspace {
  display: grid;
  grid-template-rows: auto 1fr;
  min-width: 0;
}

.toolbar {
  align-items: center;
  background: var(--panel);
  border-bottom: 1px solid var(--line);
  display: flex;
  gap: 10px;
  min-height: 58px;
  padding: 10px 16px;
}

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

.push {
  margin-left: auto;
}

.tool-button,
.icon-button,
.primary-button,
.tab {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--ink);
  min-height: 36px;
  padding: 7px 10px;
}

.tool-button {
  min-width: 38px;
}

.tool-button.wide {
  min-width: 58px;
}

.icon-button {
  min-height: 28px;
  min-width: 30px;
  padding: 3px 8px;
}

.primary-button {
  background: var(--accent);
  border-color: var(--accent-strong);
  color: #fff;
  font-weight: 700;
  min-width: 84px;
}

select,
#templateTitle {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #fff;
  min-height: 36px;
  padding: 7px 10px;
}

.editor-grid {
  display: grid;
  grid-template-columns: minmax(420px, 1.08fr) minmax(360px, 0.92fr);
  min-height: 0;
}

.editor-pane,
.preview-pane {
  min-height: 0;
  padding: 16px;
}

.editor-pane {
  border-right: 1px solid var(--line);
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}

.pane-head {
  align-items: center;
  display: flex;
  gap: 10px;
}

#templateTitle {
  flex: 1;
  font-size: 18px;
  font-weight: 700;
  min-width: 0;
}

.editor {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: 8px;
  line-height: 1.56;
  min-height: 0;
  overflow: auto;
  padding: 34px;
}

.editor:focus {
  border-color: var(--accent);
  outline: none;
}

.placeholder {
  background: #dff0f2;
  border: 1px solid #b6d9dd;
  border-radius: 4px;
  color: #13575b;
  padding: 1px 4px;
}

.preview-pane {
  display: grid;
  grid-template-rows: auto 1fr;
  gap: 12px;
}

.tabs {
  display: flex;
  gap: 6px;
}

.tab.active {
  background: #26302f;
  border-color: #26302f;
  color: #fff;
}

.tab-panel {
  display: none;
  min-height: 0;
  overflow: auto;
}

.tab-panel.active {
  display: block;
}

.paper-preview {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 18px 40px rgba(35, 47, 48, 0.08);
  line-height: 1.55;
  margin: 0 auto;
  max-width: 760px;
  min-height: 700px;
  padding: 42px 48px;
}

pre {
  background: #1f2528;
  border-radius: 8px;
  color: #e8efe9;
  font-size: 12px;
  line-height: 1.45;
  margin: 0;
  min-height: 700px;
  overflow: auto;
  padding: 16px;
  white-space: pre-wrap;
}

@media (max-width: 980px) {
  .app-shell,
  .editor-grid {
    grid-template-columns: 1fr;
  }

  .sidebar,
  .editor-pane {
    border-right: 0;
  }

  .sidebar {
    border-bottom: 1px solid var(--line);
  }

  .toolbar {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .push {
    margin-left: 0;
  }

  .paper-preview,
  pre {
    min-height: 420px;
  }
}
