* { box-sizing: border-box; }
html, body {
  height: 100%;
  overflow: hidden;
}
body {
  margin: 0;
  font-family: "Segoe UI", "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 14px;
  color: #1c1917;
  background: #f5f5f4;
}
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  align-items: center;
  padding: 8px 10px;
  background: #1c1917;
  color: #fafaf9;
}
.brand {
  font-weight: 650;
  letter-spacing: 0.01em;
  margin-right: 4px;
}
.toolbar button, .file-name input, #md-list {
  font: inherit;
  font-size: 13px;
}
.toolbar button {
  background: #44403c;
  color: #fafaf9;
  border: 1px solid #57534e;
  border-radius: 4px;
  padding: 5px 9px;
  cursor: pointer;
}
.toolbar button:hover { background: #57534e; }
.toolbar button.primary {
  background: #1d4ed8;
  border-color: #1e40af;
}
.toolbar button.primary:hover { background: #1e40af; }
.toolbar button#btn-bold { font-weight: 700; }
.sep {
  width: 1px;
  height: 22px;
  background: #44403c;
  margin: 0 2px;
}
.file-name {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-left: auto;
  color: #e7e5e4;
  font-size: 13px;
}
.file-name input, #md-list {
  background: #292524;
  color: #fafaf9;
  border: 1px solid #57534e;
  border-radius: 4px;
  padding: 4px 6px;
  min-width: 12em;
}
.banner, .notice {
  margin: 0;
  padding: 6px 12px;
  font-size: 13px;
  line-height: 1.35;
}
.banner { background: #e7e5e4; color: #44403c; }
.notice { background: #fef3c7; color: #78350f; }
.mode-toggle {
  display: none;
  gap: 6px;
  padding: 6px 10px;
  background: #f5f5f4;
}
.mode-toggle button {
  font: inherit;
  border: 1px solid #d6d3d1;
  background: #fff;
  border-radius: 4px;
  padding: 4px 8px;
}
.mode-toggle button.active {
  background: #1c1917;
  color: #fff;
  border-color: #1c1917;
}
.workspace {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(280px, 1fr) minmax(280px, 1fr);
}
.editor-pane, .preview-pane { min-height: 0; min-width: 0; overflow-anchor: none; }
.editor-pane {
  position: relative;
  overflow: hidden;
  background: #fffefb;
}
textarea {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  display: block;
  width: 100%;
  height: 100%;
  margin: 0;
  border: 0;
  resize: none;
  overflow: auto;
  overflow-anchor: none;
  padding: 16px 18px;
  font-family: ui-monospace, "Cascadia Mono", "Segoe UI Mono", Consolas, monospace;
  font-size: 14px;
  line-height: 1.45;
  color: #1c1917;
  background: transparent;
}
textarea:focus { outline: none; }
.preview-pane {
  overflow: auto;
  overflow-anchor: none;
  overscroll-behavior: contain;
  background: #d6d3d1;
  padding: 16px 0 32px;
}
.document {
  max-width: 210mm;
  margin: 0 auto;
  padding: 2.5cm;
  background: #fff;
  color: #111;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12);
  font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
  font-size: 11pt;
  line-height: 1.25;
  text-align: justify;
  hyphens: auto;
}
.document:empty::before {
  content: "Apri un file Markdown oppure inizia a scrivere. L'anteprima compare qui.";
  display: block;
  color: #64748b;
  text-align: left;
}
.doc-title {
  text-align: center;
  font-size: 1.35em;
  font-weight: bold;
  margin-bottom: 0.5cm;
}
.doc-title div { margin: 0.15em 0; }
.section-title {
  text-align: center;
  font-weight: bold;
  text-transform: uppercase;
  font-size: 1em;
  margin: 1.2em 0 0.6em;
}
.sub-title {
  text-align: center;
  font-weight: normal;
  margin: 1em 0 0.5em;
}
.document p { margin: 0 0 0.4em; text-indent: 0; }
.document .spacer { margin: 0.8em 0; }
.right-align { text-align: right; }
.center-align { text-align: center; }
.image-block { text-align: center; margin: 1em 0; }
.image-block img {
  max-width: 100%;
  height: auto;
  display: block;
  margin: 0 auto;
}
.img-alt { font-size: 0.85em; margin-top: 0.4em; }
.image-missing {
  margin: 1em 0;
  padding: 0.6em 0.8em;
  text-align: center;
  color: #9a3412;
  background: #fff7ed;
  border: 1px dashed #fdba74;
}
table.md-table {
  width: 100%;
  border-collapse: collapse;
  margin: 1em 0;
}
table.md-table th, table.md-table td {
  border: 1px solid #333;
  padding: 0.4em 0.6em;
  text-align: justify;
}
table.md-table th { font-weight: bold; }
ul.md-list, ol.md-list, ul.task-list {
  margin: 0.8em 0 0.8em 2em;
  padding-left: 0.5em;
}
ul.md-list { list-style-type: disc; list-style-position: outside; }
ol.md-list { list-style-type: decimal; list-style-position: outside; }
ul.task-list {
  list-style-type: none;
  margin-left: 1.5em;
  padding-left: 0;
}
ul.md-list li, ol.md-list li, ul.task-list li {
  display: list-item;
  margin: 0.2em 0;
}
ul.task-list li label { display: inline; cursor: default; }
ul.task-list input[type="checkbox"] {
  margin-right: 0.35em;
  vertical-align: middle;
}
blockquote {
  margin: 0.8em 0 0.8em 1.5em;
  padding: 0.4em 0 0.4em 1em;
  border-left: 3px solid #94a3b8;
  color: #334155;
  font-style: italic;
}
code.md-code {
  font-family: Consolas, "DejaVu Sans Mono", monospace;
  font-size: 0.9em;
  background: #f1f5f9;
  padding: 0.1em 0.35em;
  border-radius: 3px;
}
pre {
  margin: 0.8em 0;
  padding: 0.8em 1em;
  background: #f8fafc;
  border: 1px solid #e2e8f0;
  border-radius: 4px;
  overflow-x: auto;
  text-align: left;
}
pre code.md-fence {
  font-family: Consolas, "DejaVu Sans Mono", monospace;
  font-size: 0.85em;
  white-space: pre;
}
hr {
  border: none;
  border-top: 1px solid #94a3b8;
  margin: 1.2em 0;
}
.document a { color: #1d4ed8; text-decoration: underline; }
del { color: #64748b; }
.status {
  flex: none;
  padding: 6px 12px;
  background: #292524;
  color: #e7e5e4;
  font-size: 12px;
}
.workspace.mode-source .preview-pane { display: none; }
.workspace.mode-preview .editor-pane { display: none; }
@media (max-width: 800px) {
  .mode-toggle { display: flex; }
  .workspace { grid-template-columns: 1fr; }
  .workspace.mode-both { grid-template-rows: minmax(180px, 1fr) minmax(180px, 1fr); }
  .file-name { margin-left: 0; }
  .document { padding: 1.2cm; }
}
@media print {
  html, body { overflow: visible; height: auto; }
  .toolbar, .banner, .notice, .status, .mode-toggle, .editor-pane { display: none !important; }
  .app, .workspace, .preview-pane { display: block; height: auto; overflow: visible; background: #fff; }
  .document { box-shadow: none; max-width: none; }
}
