/* -----------------------------------------------------------------------------
 * main.css - styling for the Markdown editor SPA.
 *
 * The theme is driven by CSS custom properties defined on :root and overridden
 * under [data-theme="dark"]. The layout is a full-height flex column: header,
 * toolbar, a two-column workspace that grows to fill the viewport, and a footer.
 * --------------------------------------------------------------------------- */

:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #f0f2f5;
  --text: #1f2328;
  --text-muted: #57606a;
  --border: #d8dee4;
  --accent: #2f6feb;
  --accent-contrast: #ffffff;
  --code-bg: rgba(175, 184, 193, 0.22);
  --shadow: 0 1px 3px rgba(16, 24, 40, 0.08), 0 1px 2px rgba(16, 24, 40, 0.06);
  --radius: 10px;
  --mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, Consolas, monospace;
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

[data-theme="dark"] {
  --bg: #0d1117;
  --surface: #161b22;
  --surface-2: #1c232c;
  --text: #e6edf3;
  --text-muted: #8b949e;
  --border: #30363d;
  --accent: #58a6ff;
  --accent-contrast: #0d1117;
  --code-bg: rgba(110, 118, 129, 0.28);
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}

* { box-sizing: border-box; }

html, body { height: 100%; }

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  font-family: var(--sans);
  color: var(--text);
  background: var(--bg);
  transition: background 0.2s ease, color 0.2s ease;
}

/* --- Header --------------------------------------------------------------- */
.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.brand { display: flex; align-items: center; gap: 0.75rem; }

.brand-mark {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  border-radius: var(--radius);
  background: var(--accent);
  color: var(--accent-contrast);
  font-weight: 700;
  font-size: 1.1rem;
}

.app-header h1 { margin: 0; font-size: 1.1rem; line-height: 1.2; }
.tagline { margin: 0; font-size: 0.78rem; color: var(--text-muted); }

.header-actions { display: flex; align-items: center; gap: 0.4rem; flex-wrap: wrap; }

button {
  font-family: inherit;
  font-size: 0.85rem;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.4rem 0.7rem;
  cursor: pointer;
  transition: background 0.15s ease, border-color 0.15s ease, transform 0.05s ease;
}

button:hover { border-color: var(--accent); }
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.divider {
  width: 1px;
  height: 22px;
  background: var(--border);
  margin: 0 0.25rem;
}

/* --- Toolbar -------------------------------------------------------------- */
.toolbar {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.5rem 1.25rem;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
}

.toolbar button {
  min-width: 2.2rem;
  padding: 0.35rem 0.55rem;
}
.toolbar code { font-size: 0.75rem; }

/* --- Workspace ------------------------------------------------------------ */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 1fr 1fr;
  min-height: 0;
}

.pane {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
}
.pane-editor { border-right: 1px solid var(--border); }

.pane-label {
  font-size: 0.7rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--text-muted);
  padding: 0.5rem 1.25rem;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
}

#editor {
  flex: 1;
  width: 100%;
  resize: none;
  border: none;
  outline: none;
  padding: 1.25rem;
  font-family: var(--mono);
  font-size: 0.95rem;
  line-height: 1.7;
  color: var(--text);
  background: var(--surface);
  tab-size: 2;
}

.preview {
  flex: 1;
  overflow-y: auto;
  padding: 1.25rem 1.5rem;
  line-height: 1.65;
  background: var(--bg);
}

/* --- Rendered Markdown ---------------------------------------------------- */
.preview > *:first-child { margin-top: 0; }
.preview h1, .preview h2, .preview h3,
.preview h4, .preview h5, .preview h6 {
  line-height: 1.25;
  margin: 1.5em 0 0.6em;
}
.preview h1 { font-size: 1.8rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.preview h2 { font-size: 1.45rem; border-bottom: 1px solid var(--border); padding-bottom: 0.3em; }
.preview h3 { font-size: 1.2rem; }

.preview p { margin: 0 0 1em; }
.preview a { color: var(--accent); text-decoration: none; }
.preview a:hover { text-decoration: underline; }
.preview img { max-width: 100%; border-radius: 8px; }

.preview code {
  font-family: var(--mono);
  font-size: 0.88em;
  background: var(--code-bg);
  padding: 0.15em 0.4em;
  border-radius: 6px;
}

.preview pre {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1rem;
  overflow-x: auto;
}
.preview pre code { background: none; padding: 0; font-size: 0.85rem; }

.preview blockquote {
  margin: 1em 0;
  padding: 0.2em 1em;
  color: var(--text-muted);
  border-left: 0.25em solid var(--accent);
  background: var(--surface-2);
  border-radius: 0 8px 8px 0;
}

.preview ul, .preview ol { padding-left: 1.5rem; margin: 0 0 1em; }
.preview li { margin: 0.25em 0; }
.preview input[type="checkbox"] { margin-right: 0.4rem; }

.preview hr { border: none; border-top: 1px solid var(--border); margin: 1.5em 0; }

.preview table {
  border-collapse: collapse;
  width: 100%;
  margin: 1em 0;
  display: block;
  overflow-x: auto;
}
.preview th, .preview td {
  border: 1px solid var(--border);
  padding: 0.5rem 0.75rem;
}
.preview th { background: var(--surface-2); }
.preview del { color: var(--text-muted); }

/* --- Footer --------------------------------------------------------------- */
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.5rem 1.25rem;
  background: var(--surface);
  border-top: 1px solid var(--border);
  font-size: 0.78rem;
  color: var(--text-muted);
}

.status {
  opacity: 0;
  transform: translateY(4px);
  transition: opacity 0.2s ease, transform 0.2s ease;
  color: var(--accent);
  font-weight: 600;
}
.status.visible { opacity: 1; transform: translateY(0); }

/* --- Responsive ----------------------------------------------------------- */
@media (max-width: 720px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 1fr 1fr; }
  .pane-editor { border-right: none; border-bottom: 1px solid var(--border); }
  .app-header h1 { font-size: 1rem; }
}
