:root {
  color-scheme: dark;
  --bg: #0d1117;
  --surface: #151b23;
  --surface-2: #1b2430;
  --border: #2a3442;
  --text: #edf2f7;
  --muted: #96a2b4;
  --accent: #91e64a;
  --accent-strong: #49b92b;
  --accent-soft: rgba(106, 214, 67, .14);
  --danger: #ff7b72;
  --shadow: 0 14px 38px rgba(0, 0, 0, .22);
  --editor-bg: #10161e;
  --code-bg: #0b1016;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f6fa;
  --surface: #ffffff;
  --surface-2: #f7f9fc;
  --border: #dce3ec;
  --text: #172033;
  --muted: #68758a;
  --accent: #2d8a27;
  --accent-strong: #24751f;
  --accent-soft: rgba(45, 138, 39, .10);
  --danger: #cf222e;
  --shadow: 0 14px 35px rgba(32, 47, 68, .10);
  --editor-bg: #fbfcfe;
  --code-bg: #f6f8fa;
}

* { box-sizing: border-box; }

html, body { min-height: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

button, textarea, input { font: inherit; }
button { color: inherit; }

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
  padding: 14px clamp(18px, 3vw, 42px);
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(16px);
}

.brand { display: flex; align-items: center; gap: 12px; min-width: 0; }
.brand-logo {
  width: 48px; height: 48px; object-fit: contain; flex: 0 0 auto;
  filter: drop-shadow(0 5px 12px rgba(0, 0, 0, .22));
}
.brand strong { display: block; font-size: 16px; }
.brand span { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; }

.header-actions { display: flex; align-items: center; gap: 16px; }
.switch-row { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); font-size: 13px; cursor: pointer; user-select: none; }
.switch-row input { position: absolute; opacity: 0; pointer-events: none; }
.switch {
  position: relative; width: 42px; height: 24px; border-radius: 999px;
  background: var(--border); transition: .2s ease;
}
.switch::after {
  content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 3px;
  border-radius: 50%; background: white; transition: .2s ease;
}
.switch-row input:checked + .switch { background: var(--accent-strong); }
.switch-row input:checked + .switch::after { transform: translateX(18px); }

.icon-button {
  width: 40px; height: 40px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); cursor: pointer;
}
.icon-button:hover { border-color: var(--accent); background: var(--accent-soft); }

.app-shell {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  gap: 18px;
  padding: 22px clamp(18px, 3vw, 42px) 16px;
  min-height: calc(100vh - 126px);
}

.panel {
  min-width: 0;
  display: flex;
  flex-direction: column;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  overflow: hidden;
  box-shadow: var(--shadow);
}

.panel-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 16px;
  padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border);
}
.panel-header h1, .panel-header h2 { margin: 0; font-size: 17px; }
.title-row { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; }
.sync-badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 4px 7px; border: 1px solid color-mix(in srgb, var(--accent) 42%, var(--border));
  border-radius: 999px; background: var(--accent-soft); color: var(--accent);
  font-size: 10px; font-weight: 750; letter-spacing: .01em;
}
.button:disabled { opacity: .45; cursor: not-allowed; transform: none; }

.panel-header p { margin: 5px 0 0; color: var(--muted); font-size: 12px; line-height: 1.4; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: flex-end; }

.button {
  border: 1px solid transparent;
  border-radius: 9px;
  padding: 9px 12px;
  font-size: 13px;
  font-weight: 650;
  cursor: pointer;
  transition: .15s ease;
}
.button:hover { transform: translateY(-1px); }
.button.primary { background: var(--accent-strong); color: white; }
.button.primary:hover { filter: brightness(1.06); }
.button.secondary { border-color: var(--border); background: var(--surface-2); }
.button.secondary:hover { border-color: var(--accent); }
.button.ghost { background: transparent; color: var(--muted); }
.button.ghost:hover { background: var(--surface-2); color: var(--text); }

.drop-zone, .output-area { position: relative; flex: 1; min-height: 0; }
#markdownInput, .code-output {
  width: 100%; height: 100%; min-height: 560px; border: 0; outline: 0; resize: none;
  padding: 22px; background: var(--editor-bg); color: var(--text);
  font-family: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  font-size: 14px; line-height: 1.65; tab-size: 2;
}
#markdownInput:focus, .code-output:focus { box-shadow: inset 0 0 0 2px var(--accent-soft); }

.drop-overlay {
  position: absolute; inset: 12px; z-index: 5; display: none; place-items: center;
  border: 2px dashed var(--accent); border-radius: 14px; background: color-mix(in srgb, var(--surface) 91%, transparent);
  pointer-events: none;
}
.drop-zone.dragging .drop-overlay { display: grid; }
.drop-message { text-align: center; padding: 30px; }
.drop-message strong, .drop-message span { display: block; }
.drop-message strong { font-size: 18px; }
.drop-message span { margin-top: 7px; color: var(--muted); font-size: 13px; }
.drop-icon { font-size: 34px; color: var(--accent); margin-bottom: 8px; }

.tabs {
  display: flex; gap: 4px; padding: 10px 12px; border-bottom: 1px solid var(--border); background: var(--surface-2);
}
.tab {
  border: 0; border-radius: 8px; padding: 8px 12px; background: transparent; color: var(--muted);
  cursor: pointer; font-size: 13px; font-weight: 650;
}
.tab:hover { color: var(--text); background: var(--accent-soft); }
.tab.active { color: var(--accent); background: var(--accent-soft); }

.rich-output {
  width: 100%; height: 100%; min-height: 560px; overflow: auto; outline: 0;
  padding: 26px 30px; background: var(--editor-bg); color: var(--text); line-height: 1.65;
}
.rich-output:focus { box-shadow: inset 0 0 0 2px var(--accent-soft); }
.rich-output:empty::before { content: "El resultado aparecerá aquí…"; color: var(--muted); pointer-events: none; }
.rich-output h1, .rich-output h2, .rich-output h3, .rich-output h4 { line-height: 1.25; margin-top: 1.4em; margin-bottom: .55em; }
.rich-output h1:first-child, .rich-output h2:first-child, .rich-output h3:first-child { margin-top: 0; }
.rich-output p { margin: .85em 0; }
.rich-output blockquote { margin: 1em 0; padding: .25em 1em; border-left: 4px solid var(--accent); color: var(--muted); background: var(--accent-soft); }
.rich-output code { padding: .15em .35em; border-radius: 5px; background: var(--code-bg); font-family: "SFMono-Regular", Consolas, monospace; }
.rich-output pre { overflow: auto; padding: 15px; border: 1px solid var(--border); border-radius: 9px; background: var(--code-bg); }
.rich-output pre code { padding: 0; background: transparent; }
.rich-output table { width: 100%; border-collapse: collapse; margin: 1em 0; }
.rich-output th, .rich-output td { border: 1px solid var(--border); padding: 8px 10px; text-align: left; }
.rich-output th { background: var(--surface-2); }
.rich-output img { max-width: 100%; height: auto; border-radius: 8px; }
.rich-output a { color: var(--accent); }
.rich-output hr { border: 0; border-top: 1px solid var(--border); margin: 1.5em 0; }
.rich-output input[type="checkbox"] { margin-right: 7px; }

.code-output { min-height: 560px; white-space: pre; }
.hidden { display: none !important; }

.panel-footer {
  display: flex; justify-content: space-between; gap: 16px; align-items: center;
  padding: 10px 16px; border-top: 1px solid var(--border); color: var(--muted); font-size: 11px;
}
.privacy-note { text-align: right; }
.source-meta { display: inline-flex; align-items: center; justify-content: flex-end; gap: 7px; min-width: 0; }
#currentFileDisplay {
  display: inline-flex; align-items: center;
  max-width: 240px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
  padding: 3px 9px; border: 1px solid var(--border); border-radius: 999px;
  background: var(--surface-2); color: var(--muted); font-size: 11px; font-weight: 650;
  /* Mismo tamaño aproximado que el sync-badge para no aumentar la altura del header */
}

body.modal-open { overflow: hidden; }
.modal-backdrop {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px;
  background: rgba(0, 0, 0, .62); backdrop-filter: blur(4px);
}
.modal {
  width: min(460px, 100%); overflow: hidden; border: 1px solid var(--border); border-radius: 14px;
  background: var(--surface); color: var(--text); box-shadow: 0 24px 70px rgba(0, 0, 0, .38);
}
.modal-header {
  display: flex; align-items: center; justify-content: space-between; gap: 18px;
  padding: 17px 18px 13px; border-bottom: 1px solid var(--border);
}
.modal-header h2 { margin: 0; font-size: 16px; }
.modal-close {
  width: 34px; height: 34px; border: 0; border-radius: 8px; background: transparent;
  color: var(--muted); font-size: 24px; line-height: 1; cursor: pointer;
}
.modal-close:hover { background: var(--surface-2); color: var(--text); }
.modal-body { padding: 17px 18px 4px; color: var(--muted); font-size: 13px; line-height: 1.6; }
.modal-body p { margin: 0 0 12px; }
.modal-body strong { color: var(--text); }
.modal-file { overflow-wrap: anywhere; color: var(--danger); }
.modal-actions { display: flex; justify-content: flex-end; padding: 10px 18px 18px; }

.site-footer {
  display: flex; justify-content: space-between; gap: 20px;
  padding: 5px clamp(18px, 3vw, 42px) 18px; color: var(--muted); font-size: 11px;
}

.toast {
  position: fixed; right: 22px; bottom: 22px; z-index: 50;
  max-width: 360px; padding: 11px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
  opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s ease;
  font-size: 13px;
}
.toast.show { opacity: 1; transform: translateY(0); }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  #markdownInput, .code-output, .rich-output { min-height: 430px; }
  .switch-row > span:first-child { display: none; }
}

@media (max-width: 620px) {
  .topbar { align-items: flex-start; }
  .brand span { display: none; }
  .panel-header, .output-header { flex-direction: column; }
  .panel-actions { width: 100%; justify-content: flex-start; }
  .panel-footer, .site-footer { flex-direction: column; align-items: flex-start; }
  .source-meta { justify-content: flex-start; flex-wrap: wrap; }
  .privacy-note { text-align: left; }
}
