*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg: #f7f9fc; --panel: #ffffff; --panel2: #f1f5f9;
  --border: #e3e8f0; --text: #0f172a; --text-muted: #5b6878;
  --brand: #2563eb; --brand-dark: #1d4ed8; --brand-bg: rgba(37,99,235,.08);
  --green: #059669; --yellow: #b45309; --red: #dc2626;
  --radius: 6px; --header-h: 52px; --toolbar-h: 40px;
}

body { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; height: 100vh; display: flex; flex-direction: column; overflow: hidden; }
.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

/* HEADER */
.site-header { height: var(--header-h); background: var(--panel); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 16px; gap: 12px; flex-shrink: 0; }
.header-left { display: flex; align-items: center; gap: 12px; }
.logo { display: flex; align-items: center; gap: 8px; font-size: 16px; font-weight: 800; color: var(--brand); letter-spacing: -.01em; }
.doc-status { display: flex; align-items: center; gap: 6px; font-size: 12px; color: var(--text-muted); }
.status-dot { width: 7px; height: 7px; border-radius: 50%; display: inline-block; }
.status-dot.saved { background: var(--green); }
.status-dot.unsaved { background: var(--yellow); }

.header-actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stats-bar { display: flex; gap: 4px; font-size: 12px; color: var(--text-muted); align-items: center; }
.sep { opacity: .4; }
.view-toggles { display: flex; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.vtbtn { padding: 5px 10px; font-size: 11px; font-weight: 600; background: none; border: none; cursor: pointer; font-family: inherit; color: var(--text-muted); transition: all .12s; }
.vtbtn.active { background: var(--brand-bg); color: var(--brand); }
.vtbtn:hover:not(.active) { background: rgba(15,23,42,.06); }
.btn-icon { width: 32px; height: 32px; border: 1px solid var(--border); border-radius: var(--radius); background: none; color: var(--text-muted); cursor: pointer; font-size: 14px; display: flex; align-items: center; justify-content: center; transition: all .12s; }
.btn-icon:hover { color: var(--brand); border-color: var(--brand); }
.btn-action { padding: 6px 14px; background: var(--brand); border: none; border-radius: var(--radius); color: white; font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit; transition: background .12s; }
.btn-action:hover { background: var(--brand-dark); }
.btn-action.outline { background: none; border: 1px solid var(--border); color: var(--text-muted); }
.btn-action.outline:hover { border-color: var(--red); color: var(--red); }

/* TOOLBAR */
.toolbar-strip { height: var(--toolbar-h); background: var(--panel2); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 12px; gap: 8px; flex-shrink: 0; overflow-x: auto; }
.fmt-btns { display: flex; align-items: center; gap: 2px; }
.fmt { padding: 5px 8px; border: none; border-radius: 4px; background: none; color: var(--text-muted); font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit; transition: all .1s; white-space: nowrap; }
.fmt:hover { background: var(--brand-bg); color: var(--brand); }
.tsep { width: 1px; height: 18px; background: var(--border); margin: 0 4px; flex-shrink: 0; }
.toolbar-right { display: flex; align-items: center; gap: 6px; flex-shrink: 0; }
.lang-sel { background: var(--panel); border: 1px solid var(--border); border-radius: 4px; color: var(--text); padding: 4px 8px; font-size: 11px; font-family: inherit; cursor: pointer; }
.btn-tool-sm { padding: 4px 10px; border: 1px solid var(--border); border-radius: 4px; background: none; color: var(--text-muted); font-size: 11px; font-weight: 600; cursor: pointer; font-family: inherit; transition: all .12s; }
.btn-tool-sm:hover { color: var(--brand); border-color: var(--brand); }

/* MAIN */
.editor-main { flex: 1; display: flex; min-height: 0; }
.editor-col, .preview-col { display: flex; flex-direction: column; flex: 1; min-width: 0; }
.pane-header { display: flex; align-items: center; justify-content: space-between; padding: 6px 14px; border-bottom: 1px solid var(--border); background: var(--panel2); font-size: 11px; flex-shrink: 0; }
.pane-lbl { font-weight: 700; text-transform: uppercase; letter-spacing: .07em; color: var(--text-muted); }
.line-info { font-size: 11px; color: var(--text-muted); font-family: monospace; }
.preview-actions { display: flex; gap: 6px; }

/* EDITOR */
.md-textarea { flex: 1; resize: none; border: none; outline: none; background: var(--panel); color: var(--text); font-family: 'Courier New', Consolas, monospace; font-size: 14px; line-height: 1.7; padding: 20px; tab-size: 2; }
.md-textarea::placeholder { color: var(--text-muted); }

/* RESIZE HANDLE */
.resize-handle { width: 5px; background: var(--border); cursor: col-resize; flex-shrink: 0; transition: background .12s; }
.resize-handle:hover, .resize-handle.dragging { background: var(--brand); }

/* PREVIEW */
.md-preview { flex: 1; overflow-y: auto; padding: 24px 32px; background: var(--panel); }
.md-preview.github-theme { font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 15px; line-height: 1.75; }
.md-preview.minimal { font-family: Georgia, serif; font-size: 16px; line-height: 1.8; }

/* MARKDOWN PREVIEW STYLES */
.md-preview h1 { font-size: 2em; border-bottom: 1px solid var(--border); padding-bottom: .3em; margin: 1em 0 .6em; font-weight: 800; }
.md-preview h2 { font-size: 1.5em; border-bottom: 1px solid var(--border); padding-bottom: .25em; margin: 1em 0 .5em; font-weight: 700; }
.md-preview h3 { font-size: 1.25em; margin: .8em 0 .4em; font-weight: 700; }
.md-preview h4, .md-preview h5, .md-preview h6 { margin: .6em 0 .3em; font-weight: 600; }
.md-preview p { margin: .7em 0; }
.md-preview a { color: var(--brand); text-decoration: underline; }
.md-preview a:hover { color: var(--brand-dark); }
.md-preview code { background: rgba(129,140,248,.15); color: var(--brand); padding: 2px 6px; border-radius: 4px; font-family: monospace; font-size: .9em; }
.md-preview pre { background: var(--panel2); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; overflow-x: auto; margin: .8em 0; }
.md-preview pre code { background: none; color: var(--text); padding: 0; font-size: 13px; line-height: 1.6; }
.md-preview blockquote { border-left: 4px solid var(--brand); padding: 8px 16px; margin: .8em 0; color: var(--text-muted); background: var(--brand-bg); border-radius: 0 var(--radius) var(--radius) 0; }
.md-preview ul, .md-preview ol { margin: .6em 0 .6em 2em; }
.md-preview li { margin: .25em 0; }
.md-preview li input[type="checkbox"] { margin-right: 6px; accent-color: var(--brand); }
.md-preview hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }
.md-preview table { border-collapse: collapse; width: 100%; margin: .8em 0; }
.md-preview th, .md-preview td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.md-preview th { background: var(--panel2); font-weight: 700; }
.md-preview tr:nth-child(even) { background: rgba(15,23,42,.03); }
.md-preview img { max-width: 100%; border-radius: var(--radius); }
.md-preview strong { font-weight: 700; }
.md-preview em { font-style: italic; }
.md-preview del { text-decoration: line-through; color: var(--text-muted); }

/* FOOTER */
.site-footer { background: var(--panel2); border-top: 1px solid var(--border); padding: 8px 16px; font-size: 12px; color: var(--text-muted); text-align: center; flex-shrink: 0; }
.site-footer a { color: var(--brand); text-decoration: none; }

/* RESPONSIVE */
@media (max-width: 700px) {
  .editor-main { flex-direction: column; }
  .resize-handle { width: 100%; height: 5px; cursor: row-resize; }
  .stats-bar { display: none; }
}
