:root {
  --bg: #ece5d6; --bar: #f6f1e5; --line: #cfc5ae; --text: #1c1a17; --muted: #5e574b;
  --accent: #2a4a8a; --accent-soft: rgba(42, 74, 138, .13); --view: #4f4a43; --menu: #fdfbf5;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; } /* inaczej display:flex poniżej pokazałby ukryte warstwy */
html, body { margin: 0; height: 100%; }
body { display: flex; flex-direction: column; font: 13px "Segoe UI", system-ui, sans-serif; color: var(--text); background: var(--bg); }
.bar { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; padding: 4px 8px; background: var(--bar); border-bottom: 1px solid var(--line); }
.bar label { display: inline-flex; align-items: center; gap: 4px; }
.sep { width: 1px; height: 20px; background: var(--line); margin: 0 4px; }
button { font: inherit; padding: 3px 8px; border: 1px solid transparent; border-radius: 2px; background: transparent; color: var(--text); cursor: pointer; }
button:hover { background: #e6dec9; border-color: #bdb29a; }
button:disabled { color: #a79f8e; background: transparent; border-color: transparent; cursor: default; }
button.active, button.toggle.on { background: var(--accent); color: #fff; border-color: var(--accent); }
select, input[type=number], input[type=text], input[type=password] { font: inherit; padding: 2px 4px; border: 1px solid #b9ae96; border-radius: 2px; background: #fdfbf5; }
input[type=number] { width: 60px; }
input[type=color] { width: 28px; height: 22px; padding: 0; border: 1px solid #999; background: none; }
#tabs { display: flex; gap: 2px; padding: 4px 8px 0; background: var(--bg); border-bottom: 1px solid var(--line); overflow-x: auto; }
.tab { display: flex; align-items: center; gap: 6px; padding: 4px 10px; border: 1px solid var(--line); border-bottom: none; border-radius: 0; background: #e0d8c4; cursor: pointer; white-space: nowrap; }
.tab.cur { background: var(--bar); font-weight: 600; box-shadow: inset 0 2px 0 var(--text); }
.tab .x { border: none; padding: 0 4px; line-height: 1; }
#main { flex: 1; display: flex; min-height: 0; }
#side { width: 180px; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: #f9f5ea; }
#side-head { padding: 4px 8px; border-bottom: 1px solid var(--line); color: var(--muted); }
#thumbs { flex: 1; overflow-y: auto; padding: 6px; outline: none; }
.thumb { display: flex; align-items: center; gap: 8px; padding: 4px; border-radius: 0; cursor: pointer; }
.thumb:hover { background: #eee7d6; }
.thumb.cur { box-shadow: inset 3px 0 0 var(--accent); }
.thumb.sel { background: var(--accent-soft); }
.thumb img { width: 110px; border: 1px solid #8f8775; background: #fff; }
.thumb.drop-before { box-shadow: inset 0 3px 0 var(--accent); }
.thumb.drop-after { box-shadow: inset 0 -3px 0 var(--accent); }
.thumb.dragging { opacity: .45; }
.tab.drop { outline: 2px solid var(--accent); background: var(--accent-soft); }
a.home { color: var(--text); text-decoration: none; padding: 1px 8px; font: 700 15px "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif; }
a.home { display: inline-flex; align-items: center; gap: 7px; }
a.home img { display: block; border-radius: 5px; }
a.home:hover { background: #e6dec9; }
.mlist { list-style: none; padding: 0; margin: 6px 0; max-height: 300px; overflow: auto; border: 1px solid var(--line); }
.mlist li { display: flex; align-items: center; gap: 8px; padding: 5px 8px; border-bottom: 1px solid #e6dec9; }
.mlist li span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.mlist li button { padding: 1px 6px; }
#view { flex: 1; overflow: auto; background: var(--view); outline: none; position: relative; }
#pages { display: flex; flex-direction: column; align-items: center; gap: 16px; padding: 16px; min-width: max-content; }
.page { position: relative; background: #fff; box-shadow: 5px 5px 0 rgba(0,0,0,.28); flex: none; }
.page > img { position: absolute; inset: 0; width: 100%; height: 100%; user-select: none; -webkit-user-drag: none; pointer-events: none; }
.page > .ov { position: absolute; inset: 0; }
.box { position: absolute; pointer-events: none; }
.box.sel { border: 1.5px dashed var(--accent); background: rgba(42,74,138,.09); margin: -2px; }
.handle { position: absolute; width: 10px; height: 10px; background: #fff; border: 1.5px solid var(--accent); pointer-events: auto; }
.handle.nw { left: -6px; top: -6px; cursor: nwse-resize; }
.handle.se { right: -6px; bottom: -6px; cursor: nwse-resize; }
.handle.ne { right: -6px; top: -6px; cursor: nesw-resize; }
.handle.sw { left: -6px; bottom: -6px; cursor: nesw-resize; }
.box.hover { border: 1.5px solid #8fa3cc; margin: -2px; }
.box.hover.edit { background: rgba(42,74,138,.10); border-color: var(--accent); }
.box.band { border: 1.5px dashed var(--accent); background: rgba(42,74,138,.12); }
.box.hit { background: rgba(255,230,0,.35); border: 1px solid #b59f00; }
.box.hit.cur { background: rgba(255,140,0,.45); }
.ghost { position: absolute; pointer-events: none; opacity: .7; background-repeat: no-repeat; }
svg.draw { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }
textarea.ed { position: absolute; z-index: 5; border: 1px dashed var(--accent); background: rgba(255,255,255,.94); resize: none; padding: 0; margin: 0; outline: none; overflow: hidden; white-space: pre-wrap; }
textarea.ed.nowrap { white-space: pre; }
#status { display: flex; gap: 16px; padding: 3px 8px; border-top: 1px solid var(--line); background: var(--bar); color: var(--muted); }
#st-msg { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.menu { position: fixed; z-index: 50; min-width: 200px; padding: 4px 0; background: var(--menu); border: 1px solid var(--text); box-shadow: 4px 4px 0 rgba(0,0,0,.2); }
.menu .mi { padding: 5px 16px; cursor: pointer; white-space: nowrap; position: relative; }
.menu .mi:hover { background: var(--accent-soft); }
.menu .mi.dis { color: #a79f8e; pointer-events: none; }
.menu .msep { height: 1px; background: var(--line); margin: 4px 0; }
.menu .sub { display: none; position: absolute; left: 100%; top: -4px; }
.menu .mi:hover > .sub { display: block; }
#dialog-back { position: fixed; inset: 0; z-index: 60; display: flex; align-items: center; justify-content: center; background: rgba(28,26,23,.4); }
#dialog { min-width: 360px; max-width: 560px; background: var(--menu); border: 1px solid var(--text); padding: 18px; box-shadow: 6px 6px 0 rgba(0,0,0,.25); }
#dialog h3 { margin: 0 0 10px; font: 400 19px "Palatino Linotype", "Book Antiqua", Palatino, Georgia, serif; }
#dialog .row { display: flex; align-items: center; gap: 8px; margin: 6px 0; }
#dialog .row > label { min-width: 110px; }
#dialog .row input[type=text], #dialog .row input[type=password], #dialog textarea { flex: 1; }
#dialog textarea { width: 100%; min-height: 90px; font: inherit; }
#dialog .btns { display: flex; justify-content: flex-end; gap: 6px; margin-top: 12px; }
#dialog .btns button { border-color: #a89f8b; }
#dialog .btns button.primary { background: var(--accent); color: #fff; border-color: var(--accent); }
#dialog .info { color: var(--muted); margin-top: 6px; min-height: 1.2em; }
#drop { position: fixed; inset: 0; z-index: 70; display: flex; align-items: center; justify-content: center; font-size: 22px; color: #fff; background: rgba(42,74,138,.6); pointer-events: none; }
@media (max-width: 700px) {
  #side { display: none; }
  .bar { gap: 2px; padding: 3px 4px; }
}
