:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --line: #e3e6eb;
  --text: #1b1f27;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-soft: #e8efff;
  --code-bg: #0e1117;
  --code-head: #161b22;
  --radius: 8px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font-size: 14px; display: flex; flex-direction: column; }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }

/* ---------- Horná lišta ---------- */
.topbar {
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  flex-wrap: wrap;
}
.brand { font-weight: 700; font-size: 16px; display: flex; align-items: center; gap: 8px; white-space: nowrap; }
.logo { color: var(--accent); font-size: 20px; }
.add { display: flex; align-items: center; gap: 6px; flex: 1; overflow-x: auto; scrollbar-width: thin; padding: 2px 0; }
.add .lbl { color: var(--muted); font-size: 13px; margin-right: 2px; white-space: nowrap; }
.actions { display: flex; gap: 6px; }

.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--text);
  padding: 7px 11px; border-radius: var(--radius); white-space: nowrap;
  transition: background .15s, border-color .15s;
}
.btn:hover { border-color: #c7ccd4; background: #f9fafb; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn.primary:hover { background: #1d4fd8; }
.btn.ghost { background: transparent; }
.btn.danger { color: #c62828; }
.btn.danger:hover { background: #fdecec; border-color: #f2c4c4; }
.btn.sm { padding: 5px 9px; font-size: 13px; }
.btn.dark { background: #21262d; border-color: #30363d; color: #c9d1d9; }
.btn.dark:hover { background: #2d333b; }
.btn.icon { padding: 5px 8px; min-width: 30px; }

/* ---------- Pracovná plocha ---------- */
.workspace {
  flex: 1; min-height: 0;
  display: grid;
  grid-template-columns: minmax(320px, 1fr) minmax(380px, 1.35fr) 300px;
  grid-template-areas: "code preview insp";
}
.pane { display: flex; flex-direction: column; min-height: 0; min-width: 0; }
.pane-head {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  height: 44px; padding: 0 10px; border-bottom: 1px solid var(--line); background: var(--panel);
}
.pane-head.dark { background: var(--code-head); border-color: #21262d; }
.pane-head .title { font-weight: 600; }

/* Kód */
.code-pane { grid-area: code; background: var(--code-bg); }
.tabs { display: flex; gap: 2px; height: 100%; align-items: flex-end; }
.tab {
  border: 0; background: transparent; color: #8b949e; padding: 9px 14px;
  border-radius: 6px 6px 0 0; font-family: ui-monospace, "SF Mono", Menlo, Consolas, monospace; font-size: 13px;
}
.tab.active { background: var(--code-bg); color: #e6edf3; }
.tools { display: flex; gap: 6px; }

.code {
  position: relative; margin: 0; flex: 1; overflow: auto; padding: 14px 12px 40px 0;
  font: 13px/1.6 ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  color: #c9d1d9; counter-reset: ln; tab-size: 2;
}
.code .line {
  display: block; position: relative; padding-left: 3.6em; padding-right: 8px;
  white-space: pre-wrap; word-break: break-all; counter-increment: ln; min-height: 1.6em;
  border-left: 2px solid transparent;
}
.code .line::before {
  content: counter(ln); position: absolute; left: 0; width: 2.6em; text-align: right;
  color: #484f58; user-select: none;
}
.code .line.sel { background: rgba(56, 139, 253, .13); border-left-color: #388bfd; }
.code .line.new { animation: typed .9s ease-out; }
@keyframes typed { from { background: rgba(63, 185, 80, .28); } to { background: transparent; } }
.code .tg { color: #7ee787; }
.code .at { color: #79c0ff; }
.code .st { color: #a5d6ff; }
.code .sel-css { color: #d2a8ff; }
.code .p { color: #79c0ff; }
.code .v { color: #ffa657; }
.code .c { color: #8b949e; font-style: italic; }

/* Náhľad */
.preview-pane { grid-area: preview; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
.devices { display: flex; background: #eef0f3; border-radius: var(--radius); padding: 2px; }
.seg { border: 0; background: transparent; padding: 5px 10px; border-radius: 6px; color: var(--muted); font-size: 13px; }
.seg.active { background: var(--panel); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }
.stage {
  flex: 1; min-height: 0; overflow: auto; padding: 16px; display: flex; justify-content: center;
  background: #e9ebef radial-gradient(#d6d9df 1px, transparent 1px) 0 0 / 16px 16px;
}
#preview {
  width: 100%; height: 100%; min-height: 400px; border: 0; background: #fff;
  border-radius: 6px; box-shadow: 0 2px 12px rgba(0,0,0,.08); transition: width .25s ease;
}

/* Panel vlastností */
.inspector { grid-area: insp; background: var(--panel); overflow-y: auto; }
.insp-head {
  position: sticky; top: 0; z-index: 2; background: var(--panel);
  display: flex; align-items: center; justify-content: space-between; gap: 6px;
  height: 44px; padding: 0 12px; border-bottom: 1px solid var(--line);
}
.insp-head h3 { margin: 0; font-size: 14px; }
.insp-actions { display: flex; gap: 4px; }
.section { padding: 12px; border-bottom: 1px solid var(--line); }
.section > h4 { margin: 0 0 10px; font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); }
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 12px; }
.field:last-child { margin-bottom: 0; }
.field > span { font-size: 12.5px; color: #4b5563; display: flex; justify-content: space-between; }
.field > span b { font-weight: 500; color: var(--muted); font-variant-numeric: tabular-nums; }
.field input[type=text], .field input[type=url], .field textarea, .field select {
  width: 100%; border: 1px solid var(--line); border-radius: 6px; padding: 7px 9px; background: #fff;
}
.field textarea { resize: vertical; min-height: 70px; line-height: 1.45; }
.field input:focus, .field textarea:focus, .field select:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
.field input[type=range] { width: 100%; accent-color: var(--accent); }
.field input[type=color] { width: 44px; height: 30px; border: 1px solid var(--line); border-radius: 6px; padding: 2px; background: #fff; }
.row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.stack { display: flex; flex-direction: column; gap: 6px; }
.inline { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.thumb { width: 100%; max-height: 110px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
.hint { color: var(--muted); font-size: 13px; line-height: 1.5; margin: 0; }

.align { display: flex; border: 1px solid var(--line); border-radius: 6px; overflow: hidden; width: fit-content; }
.align button { border: 0; background: #fff; padding: 6px 12px; border-right: 1px solid var(--line); }
.align button:last-child { border-right: 0; }
.align button.active { background: var(--accent-soft); color: var(--accent); }

.cell-box { border: 1px solid var(--line); border-radius: var(--radius); padding: 10px; margin-bottom: 10px; background: #fafbfc; }
.cell-box .cell-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; font-weight: 600; font-size: 13px; }

.layers { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.layers li {
  display: flex; align-items: center; gap: 8px; padding: 7px 9px; border: 1px solid var(--line);
  border-radius: 6px; cursor: pointer; background: #fff;
}
.layers li:hover { border-color: var(--accent); }
.layers .kind { font-size: 11px; color: var(--accent); background: var(--accent-soft); padding: 1px 6px; border-radius: 4px; white-space: nowrap; }
.layers .name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: #374151; }

/* Hlásenie */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px); opacity: 0;
  background: #111827; color: #fff; padding: 9px 16px; border-radius: 999px; font-size: 13px;
  pointer-events: none; transition: all .2s; z-index: 50;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Menšie obrazovky ---------- */
@media (max-width: 1150px) {
  body { height: auto; }
  .workspace {
    grid-template-columns: 1fr 1.2fr;
    grid-template-areas: "code preview" "insp insp";
  }
  .code-pane, .preview-pane { height: 62vh; }
  .inspector { border-top: 1px solid var(--line); }
  .insp-head { position: static; }
}
@media (max-width: 760px) {
  .topbar { gap: 10px; }
  .add { order: 3; flex-basis: 100%; }
  .actions { margin-left: auto; }
  .workspace { grid-template-columns: 1fr; grid-template-areas: "preview" "insp" "code"; }
  .preview-pane { height: 60vh; border: 0; }
  .code-pane { height: 55vh; }
  .stage { padding: 8px; }
}
