/* OneBase Editor v1.0.0 */
/* https://github.com/onebase/editor */

/* ===== THEME ===== */
/* Theme variables are scoped to .ob-editor container below */
/* Dark theme override: add class .ob-editor--dark to the editor container */
.ob-editor--dark {
  --bg: #0c0c0e; --surface: #141418; --surface-2: #1c1c22;
  --surface-3: #24242c; --border: #2a2a34; --border-hover: #3a3a48;
  --text: #e8e8ec; --text-muted: #8888a0; --text-dim: #555568;
  --accent: #3D9142; --accent-hover: #4aa650; --accent-glow: rgba(61,145,66,.12);
  --danger: #d44; --danger-bg: rgba(221,68,68,.08);
  --toolbar-bg: #18181e; --toolbar-border: #2a2a34;
  --selection: rgba(61,145,66,.2);
  --code-bg: #1a1a22;
}

/* Global reset removed — editor is embedded in existing pages */

/* ===== EDITOR CONTAINER ===== */
.ob-editor {
  /* Light theme defaults (scoped to editor) */
  --bg: #f8f8fa; --surface: #ffffff; --surface-2: #f0f0f4;
  --surface-3: #e8e8ee; --border: #dddde4; --border-hover: #ccccdd;
  --text: #1a1a2e; --text-muted: #6e6e88; --text-dim: #aaaabc;
  --accent: #2563eb; --accent-hover: #3b82f6; --accent-glow: rgba(37,99,235,.08);
  --danger: #cc3333; --danger-bg: rgba(204,51,51,.06);
  --toolbar-bg: #ffffff; --toolbar-border: #e0e0e8;
  --selection: rgba(37,99,235,.15);
  --code-bg: #f4f4f8;
  --font-display: 'Bricolage Grotesque', sans-serif;
  --font-body: 'Inter', sans-serif;
  --font-mono: monospace;
  --radius: 8px;

  max-width: 100%; margin: 0 auto;
  border: 1px solid var(--border); border-radius: 12px;
  overflow: hidden; background: var(--surface);
  box-shadow: 0 2px 20px rgba(0,0,0,.06);
  transition: border-color .3s, background .3s;
  box-sizing: border-box;
}
.ob-editor:focus-within { border-color: var(--accent); }

/* ===== TOOLBAR ===== */
.ob-toolbar {
  background: var(--toolbar-bg); border-bottom: 1px solid var(--toolbar-border);
  padding: 6px 8px; display: flex; flex-wrap: wrap; gap: 2px; align-items: center;
  position: sticky; top: 0; z-index: 10; transition: background .3s;
}
.ob-toolbar-group {
  display: flex; gap: 1px; align-items: center;
  padding: 0 4px;
}
.ob-toolbar-group + .ob-toolbar-group { border-left: 1px solid var(--border); margin-left: 4px; padding-left: 8px; }

.ob-btn {
  background: none; border: 1px solid transparent; border-radius: 6px;
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  cursor: pointer; color: var(--text-muted); font-size: 14px; font-weight: 600;
  transition: all .15s; position: relative; font-family: var(--font-body);
}
.ob-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border); }
.ob-btn.active { background: var(--accent-glow); color: var(--accent); border-color: transparent; }
.ob-btn[disabled] { opacity: .3; cursor: not-allowed; }
.ob-btn svg { width: 16px; height: 16px; stroke: currentColor; fill: none; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* Dropdown select */
.ob-select {
  background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 4px 8px; font-size: 12px; font-weight: 600; color: var(--text-muted);
  cursor: pointer; font-family: var(--font-body); height: 32px; transition: all .2s;
  -webkit-appearance: none; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23888' fill='none' stroke-width='1.5'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 8px center; padding-right: 24px;
}
.ob-select:hover { border-color: var(--accent); color: var(--text); }
.ob-select:focus { outline: none; border-color: var(--accent); }
.ob-select option { background: var(--surface); color: var(--text); }

/* Color picker button */
.ob-color-wrap { position: relative; }
.ob-color-wrap input[type="color"] {
  position: absolute; bottom: 0; left: 50%; transform: translateX(-50%);
  width: 0; height: 0; padding: 0; border: 0; opacity: 0;
}
.ob-btn .color-dot {
  width: 12px; height: 12px; border-radius: 3px; border: 1.5px solid var(--border);
}

/* ===== CONTENT AREA ===== */
.ob-content {
  min-height: 400px; max-height: 70vh; overflow-y: auto;
  padding: 32px 40px; outline: none;
  font-size: 15px; line-height: 1.75; color: var(--text);
  caret-color: var(--accent);
}
.ob-content::selection, .ob-content *::selection { background: var(--selection); }

/* Content typography */
.ob-content h1 { font-family: var(--font-display); font-size: 28px; font-weight: 800; letter-spacing: -0.5px; margin: 24px 0 12px; line-height: 1.3; }
.ob-content h2 { font-family: var(--font-display); font-size: 22px; font-weight: 700; letter-spacing: -0.3px; margin: 20px 0 10px; line-height: 1.3; }
.ob-content h3 { font-family: var(--font-display); font-size: 18px; font-weight: 700; margin: 16px 0 8px; line-height: 1.4; }
.ob-content h4 { font-size: 15px; font-weight: 700; margin: 14px 0 6px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.ob-content p { margin: 0 0 12px; }
.ob-content p:last-child { margin-bottom: 0; }

.ob-content strong { font-weight: 700; }
.ob-content em { font-style: italic; }
.ob-content u { text-decoration: underline; text-underline-offset: 2px; }
.ob-content s { text-decoration: line-through; color: var(--text-muted); }
.ob-content a { color: var(--accent); text-decoration: underline; text-underline-offset: 2px; cursor: pointer; }
.ob-content a:hover { color: var(--accent-hover); }
.ob-content a[target="_blank"]::after { content: ' ↗'; font-size: 10px; opacity: .5; vertical-align: super; }

.ob-content code {
  font-family: var(--font-mono); font-size: 13px; background: var(--code-bg);
  border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px;
}
.ob-content pre {
  font-family: var(--font-mono); font-size: 13px; background: var(--code-bg);
  border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px;
  margin: 16px 0; overflow-x: auto; line-height: 1.6;
}
.ob-content pre code { background: none; border: none; padding: 0; }

.ob-content blockquote {
  border-left: 3px solid var(--accent); margin: 16px 0; padding: 8px 20px;
  background: var(--accent-glow); border-radius: 0 8px 8px 0;
  color: var(--text-muted); font-style: italic;
}

.ob-content ul, .ob-content ol { margin: 8px 0 12px 24px; }
.ob-content li { margin: 4px 0; }

.ob-content hr {
  border: none; height: 1px; background: var(--border); margin: 24px 0;
}

.ob-content img {
  max-width: 100%; height: auto; border-radius: 8px; margin: 12px 0;
  border: 1px solid var(--border);
}

.ob-content table {
  width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 14px;
}
.ob-content table th, .ob-content table td {
  border: 1px solid var(--border); padding: 8px 12px; text-align: left;
}
.ob-content table th { background: var(--surface-2); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }

/* Placeholder */
.ob-content:empty::before {
  content: attr(data-placeholder);
  color: var(--text-dim);
  font-style: italic;
  pointer-events: none;
}

/* ===== STATUSBAR ===== */
.ob-statusbar {
  background: var(--toolbar-bg); border-top: 1px solid var(--toolbar-border);
  padding: 6px 12px; display: flex; justify-content: space-between; align-items: center;
  font-size: 11px; color: var(--text-dim); transition: background .3s;
}
.ob-statusbar .path { font-family: var(--font-mono); }

/* ===== LINK DIALOG ===== */
.ob-dialog-overlay {
  display: none; position: fixed; inset: 0; background: rgba(0,0,0,.5);
  z-index: 1000; align-items: center; justify-content: center;
  backdrop-filter: blur(4px);
}
.ob-dialog-overlay.open { display: flex; }
.ob-dialog {
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 24px; min-width: 400px; max-width: 90vw;
  box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.ob-dialog h3 { font-family: var(--font-display); font-size: 16px; font-weight: 700; margin-bottom: 16px; }
.ob-dialog label { display: block; font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 4px; }
.ob-dialog input {
  width: 100%; background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; color: var(--text);
  font-family: var(--font-body); font-size: 14px; margin-bottom: 12px; outline: none;
  transition: border-color .2s;
}
.ob-dialog input:focus { border-color: var(--accent); }
.ob-dialog-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 8px; }
.ob-dialog-actions button {
  padding: 8px 16px; border-radius: 8px; font-size: 13px; font-weight: 700;
  cursor: pointer; font-family: var(--font-body); transition: all .2s; border: none;
}
.ob-dialog-actions .cancel { background: var(--surface-2); color: var(--text-muted); border: 1px solid var(--border); }
.ob-dialog-actions .cancel:hover { border-color: var(--text-muted); }
.ob-dialog-actions .confirm { background: var(--accent); color: #fff; }
.ob-dialog-actions .confirm:hover { background: var(--accent-hover); }

/* ===== SOURCE VIEW ===== */
.ob-source {
  display: none; min-height: 400px; max-height: 70vh;
  padding: 20px; font-family: var(--font-mono); font-size: 13px;
  line-height: 1.6; color: var(--text); background: var(--code-bg);
  border: none; outline: none; resize: none; width: 100%;
  tab-size: 2;
}
.ob-source.visible { display: block; }
.ob-content.hidden { display: none; }

/* ===== PREVIEW MODE ===== */
.ob-preview {
  display: none; min-height: 400px; max-height: 70vh; overflow-y: auto;
  padding: 32px 40px; font-size: 15px; line-height: 1.75; color: var(--text);
  user-select: text; cursor: default;
}
.ob-preview.visible { display: block; }
.ob-preview h1,.ob-preview h2,.ob-preview h3,.ob-preview h4,
.ob-preview p,.ob-preview ul,.ob-preview ol,.ob-preview li,
.ob-preview strong,.ob-preview em,.ob-preview u,.ob-preview s,
.ob-preview a,.ob-preview code,.ob-preview pre,.ob-preview blockquote,
.ob-preview hr,.ob-preview img,.ob-preview table,.ob-preview th,.ob-preview td {
  /* Inherits all .ob-content styles */
}
/* Preview copies all content typography */
.ob-preview h1 { font-family: var(--font-display); font-size: 28px; font-weight: 800; letter-spacing: -0.5px; margin: 24px 0 12px; line-height: 1.3; }
.ob-preview h2 { font-family: var(--font-display); font-size: 22px; font-weight: 700; letter-spacing: -0.3px; margin: 20px 0 10px; line-height: 1.3; }
.ob-preview h3 { font-family: var(--font-display); font-size: 18px; font-weight: 700; margin: 16px 0 8px; line-height: 1.4; }
.ob-preview h4 { font-size: 15px; font-weight: 700; margin: 14px 0 6px; text-transform: uppercase; letter-spacing: 0.5px; color: var(--text-muted); }
.ob-preview p { margin: 0 0 12px; }
.ob-preview a { color: var(--accent); text-decoration: underline; }
.ob-preview a[target="_blank"]::after { content: ' ↗'; font-size: 11px; opacity: .6; }
.ob-preview code { font-family: var(--font-mono); font-size: 13px; background: var(--code-bg); border: 1px solid var(--border); border-radius: 4px; padding: 1px 6px; }
.ob-preview pre { font-family: var(--font-mono); font-size: 13px; background: var(--code-bg); border: 1px solid var(--border); border-radius: 8px; padding: 16px 20px; margin: 16px 0; overflow-x: auto; }
.ob-preview pre code { background: none; border: none; padding: 0; }
.ob-preview blockquote { border-left: 3px solid var(--accent); margin: 16px 0; padding: 8px 20px; background: var(--accent-glow); border-radius: 0 8px 8px 0; color: var(--text-muted); font-style: italic; }
.ob-preview ul, .ob-preview ol { margin: 8px 0 12px 24px; }
.ob-preview li { margin: 4px 0; }
.ob-preview hr { border: none; height: 1px; background: var(--border); margin: 24px 0; }
.ob-preview img { max-width: 100%; height: auto; border-radius: 8px; margin: 12px 0; border: 1px solid var(--border); }
.ob-preview table { width: 100%; border-collapse: collapse; margin: 16px 0; font-size: 14px; }
.ob-preview table th, .ob-preview table td { border: 1px solid var(--border); padding: 8px 12px; text-align: left; }
.ob-preview table th { background: var(--surface-2); font-weight: 700; font-size: 12px; text-transform: uppercase; letter-spacing: 0.5px; }

/* Preview info bar */
.ob-preview-bar {
  display: none; padding: 8px 16px; background: var(--accent-glow);
  border-bottom: 1px solid var(--accent); font-size: 12px; font-weight: 600;
  color: var(--accent); text-align: center; letter-spacing: 0.3px;
}
.ob-preview-bar.visible { display: block; }

/* ===== TABLE CONTEXT MENU ===== */
.ob-table-menu {
  display: none; position: absolute; z-index: 50;
  background: var(--surface); border: 1px solid var(--border); border-radius: 10px;
  padding: 6px; min-width: 180px; box-shadow: 0 8px 30px rgba(0,0,0,.25);
}
.ob-table-menu.open { display: block; }
.ob-table-menu button {
  display: flex; align-items: center; gap: 8px; width: 100%;
  background: none; border: none; border-radius: 6px; padding: 8px 12px;
  font-size: 13px; font-weight: 500; color: var(--text-muted);
  cursor: pointer; font-family: var(--font-body); text-align: left; transition: all .15s;
}
.ob-table-menu button:hover { background: var(--surface-2); color: var(--text); }
.ob-table-menu button.danger { color: var(--danger); }
.ob-table-menu button.danger:hover { background: var(--danger-bg); }
.ob-table-menu .sep { height: 1px; background: var(--border); margin: 4px 0; }
.ob-table-menu .icon { font-size: 14px; width: 20px; text-align: center; flex-shrink: 0; }

/* Active table cell highlight */
.ob-content td.ob-cell-active, .ob-content th.ob-cell-active {
  outline: 2px solid var(--accent); outline-offset: -2px;
}

/* ===== FILE UPLOAD ===== */
.ob-upload-zone {
  border: 2px dashed var(--border); border-radius: 12px; padding: 32px;
  text-align: center; cursor: pointer; transition: all .2s; margin-bottom: 12px;
}
.ob-upload-zone:hover, .ob-upload-zone.dragover {
  border-color: var(--accent); background: var(--accent-glow);
}
.ob-upload-zone .icon { font-size: 32px; margin-bottom: 8px; }
.ob-upload-zone .label { font-size: 14px; font-weight: 600; color: var(--text); }
.ob-upload-zone .hint { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.ob-upload-preview { margin-top: 12px; }
.ob-upload-preview img { max-width: 100%; max-height: 200px; border-radius: 8px; border: 1px solid var(--border); }
.ob-upload-file-info {
  display: flex; align-items: center; gap: 10px; padding: 10px 14px;
  background: var(--surface-2); border-radius: 8px; margin-top: 8px;
  font-size: 13px;
}
.ob-upload-file-info .fname { font-weight: 600; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ob-upload-file-info .fsize { color: var(--text-muted); font-size: 11px; }
.ob-upload-file-info .fremove {
  background: none; border: none; color: var(--danger); cursor: pointer; font-size: 16px; padding: 2px 6px;
}

/* Drag over editor area */
.ob-content.dragover { background: var(--accent-glow); }

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  body { padding: 12px; }
  .demo-header { flex-direction: column; gap: 12px; align-items: flex-start; }
  .ob-content { padding: 20px; }
  .ob-toolbar { padding: 4px; }
  .ob-btn { width: 28px; height: 28px; font-size: 12px; }
  .ob-dialog { min-width: auto; margin: 12px; }
}
/* Hláška editoru — např. „obrázek jsme dali do příloh". Skrytá, dokud není co říct. */
.ob-editor .ob-hint {
  display: none;
  padding: 8px 12px;
  font-size: 13px;
  line-height: 1.4;
  border-top: 1px solid var(--ob-border, #e2e8f0);
  background: var(--ob-hint-bg, #eff6ff);
  color: var(--ob-hint-fg, #1e40af);
}
.ob-editor .ob-hint.open { display: block; }
.ob-editor .ob-hint--warn {
  background: var(--ob-hint-warn-bg, #fef3c7);
  color: var(--ob-hint-warn-fg, #92400e);
}
