:root {
  color-scheme: dark;
  --bg: #121214;
  --surface: #1b1b1f;
  --surface-2: #24242a;
  --border: #2f2f36;
  --text: #e6e6ea;
  --muted: #8b8b94;
  --maroon: #b0263f;
  --maroon-soft: #2a171b;
  --blue: #1aa3e8;
  --radius: 6px;
}

/* Modo claro */
:root.light {
  color-scheme: light;
  --bg: #f4f4f6;
  --surface: #ffffff;
  --surface-2: #f0f0f2;
  --border: #d9d9de;
  --text: #1f1f1f;
  --muted: #777;
  --maroon: #7d0a1e;
  --maroon-soft: #f6e9eb;
}

* { box-sizing: border-box; }

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

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; justify-content: space-between;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.topbar h1 { margin: 0; font-size: 20px; letter-spacing: .3px; }
.topbar h1 span { color: var(--maroon); }
.actions { display: flex; align-items: center; gap: 8px; }
.save-status { font-size: 12px; color: var(--muted); min-width: 80px; text-align: right; }

.btn {
  font: inherit; cursor: pointer;
  border: 2px solid var(--text); background: var(--surface); color: var(--text);
  border-radius: var(--radius); padding: 6px 12px;
}
.btn:hover { background: var(--surface-2); }
.btn.ghost { border-color: var(--border); font-size: 14px; }
.btn.add { font-size: 24px; line-height: 1; width: 44px; height: 40px; padding: 0; font-weight: 600; }
.btn.add.big { width: auto; height: auto; font-size: 18px; padding: 12px 22px; }
.btn.small { font-size: 13px; padding: 3px 8px; border-width: 1px; border-color: var(--border); }
.btn.small.on { border-color: var(--blue); color: var(--blue); }
.btn.danger:hover { background: #3a1518; border-color: #e5484d; color: #ff8a8f; }

.btn.ghost.on { border-color: var(--blue); color: var(--blue); }

/* Modo lectura: sin barra de herramientas ni botones de edición */
.btn.ghost.reading { border-color: #e0a100; color: #e0a100; }
body.read-mode .jodit-toolbar__box,
body.read-mode .head-btns [data-act="rename"],
body.read-mode .head-btns [data-act="delete"],
body.read-mode .diagram-bar button,
body.read-mode .diagram-empty,
body.read-mode .grip { display: none; }

/* Cuadro de diálogo propio */
.modal {
  position: fixed; inset: 0; z-index: 200;
  background: rgba(0, 0, 0, .55);
  display: flex; align-items: center; justify-content: center;
}
.modal[hidden] { display: none; }
.modal-box {
  background: var(--surface); color: var(--text);
  border: 3px solid var(--maroon); border-radius: var(--radius);
  padding: 20px; width: min(420px, 90vw);
  display: flex; flex-direction: column; gap: 14px;
}
.modal-msg { margin: 0; font-size: 16px; }
.modal-input {
  font: inherit; font-size: 16px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 4px;
  background: var(--bg); color: var(--text);
}
.modal-input:focus { outline: none; border-color: var(--blue); }
.modal-btns { display: flex; justify-content: flex-end; gap: 8px; }

/* Aviso "Copiado" */
.toast {
  position: fixed; left: 50%; bottom: 28px; z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  background: var(--blue); color: #fff; font-size: 14px;
  padding: 8px 16px; border-radius: 20px;
  transition: opacity .15s, transform .15s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Empty state ---------- */
.empty { text-align: center; margin-top: 18vh; color: var(--muted); }

/* ---------- List of scripts ---------- */
.list { padding: 20px 24px 60px; display: flex; flex-direction: column; gap: 14px; max-width: 1600px; margin: 0 auto; }

.card {
  border: 3px solid var(--maroon);
  border-radius: var(--radius);
  background: var(--surface);
}
.card.dragging { opacity: .4; }
.card.drop-before { box-shadow: 0 -4px 0 var(--blue); }
.card.drop-after { box-shadow: 0 4px 0 var(--blue); }

.card-head {
  display: flex; align-items: center; gap: 10px;
  padding: 14px 16px;
  cursor: pointer; user-select: none;
}
.card-head:hover { background: var(--maroon-soft); }
.card.open .card-head { border-bottom: 3px solid var(--maroon); }

.grip { cursor: grab; color: #555; font-size: 18px; padding: 0 2px; }
.chev { width: 16px; color: var(--maroon); transition: transform .15s; }
.card.open .chev { transform: rotate(90deg); }
.name { flex: 1; font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.name-input { flex: 1; font: inherit; font-size: 17px; font-weight: 600; padding: 2px 6px; border: 1px solid var(--blue); border-radius: 4px; background: var(--bg); color: var(--text); }
.meta { font-size: 12px; color: var(--muted); }
.head-btns { display: flex; gap: 6px; }
.card:not(.open) [data-act="diagram"] { display: none; }

/* ---------- Expanded body ---------- */
.card-body {
  display: flex;
  height: calc(100vh - 170px);
  min-height: 420px;
  padding: 12px;
  gap: 0;
}
.pane-editor { min-width: 260px; display: flex; flex-direction: column; }
.pane-editor .jodit-container { flex: 1; display: flex; flex-direction: column; }
.pane-editor .jodit-workplace { flex: 1; }

/* Jodit en oscuro, con los colores de la página */
.jodit_theme_dark.jodit-container,
.jodit_theme_dark .jodit-workplace,
.jodit_theme_dark .jodit-wysiwyg { background: var(--bg) !important; color: var(--text) !important; }
.jodit_theme_dark .jodit-toolbar__box,
.jodit_theme_dark .jodit-status-bar { background: var(--surface-2) !important; border-color: var(--border) !important; }
.jodit_theme_dark.jodit-container { border-color: var(--border) !important; }
.jodit_theme_dark .jodit-wysiwyg td,
.jodit_theme_dark .jodit-wysiwyg th { border-color: #555; }

/* Diagrama oculto: el editor ocupa todo el ancho */
.card-body.no-diagram .pane-editor { flex: 1 1 auto !important; }
.card-body.no-diagram .splitter,
.card-body.no-diagram .pane-diagram { display: none; }

.splitter {
  width: 12px; flex: none; cursor: col-resize;
  display: flex; align-items: center; justify-content: center;
}
.splitter::before { content: ""; width: 3px; height: 40px; border-radius: 2px; background: #444; }
.splitter:hover::before { background: var(--blue); }

.pane-diagram {
  flex: 1; min-width: 260px;
  border: 3px solid var(--blue); border-radius: var(--radius);
  display: flex; flex-direction: column; overflow: hidden;
  background: var(--surface);
}
.diagram-bar {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 8px; font-size: 13px; color: var(--muted);
  border-bottom: 1px solid var(--border);
}
.pane-diagram iframe { flex: 1; width: 100%; border: 0; background: var(--surface); }
.diagram-empty { flex: 1; display: flex; align-items: center; justify-content: center; }

body.resizing, body.resizing * { cursor: col-resize !important; user-select: none; }
body.resizing iframe { pointer-events: none; }
