:root {
  --bg: #efede8;
  --panel: #ffffff;
  --ink: #1f2a30;
  --ink-2: #5b666d;
  --ink-3: #8b949a;
  --line: #e1ded7;
  --line-2: #cfcbc2;
  --accent: #2d5f7c;
  --accent-ink: #ffffff;
  --accent-soft: #e4eef4;
  --danger: #b4433a;
  --warn: #a8641b;
  --ok: #2f7d4f;
  --radius: 8px;
  color-scheme: light;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--ink);
  background: var(--bg);
}
#app { height: 100%; display: flex; flex-direction: column; }
.loading-screen { margin: auto; color: var(--ink-2); }
button, input, select, textarea { font: inherit; color: inherit; }

/* --- top bar --- */
.top {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-size: 16px; display: flex; align-items: center; gap: 8px; }
.brand b { font-weight: 650; }
.logo { color: var(--accent); font-size: 20px; }
.actions { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }

.btn {
  border: 1px solid var(--line-2); background: var(--panel); border-radius: 6px;
  padding: 6px 11px; cursor: pointer; white-space: nowrap;
}
.btn:hover:not(:disabled) { border-color: var(--ink-3); }
.btn:disabled { opacity: .45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); font-weight: 600; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.1); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover:not(:disabled) { background: var(--bg); border-color: transparent; }
.btn.danger { color: var(--danger); }
.link { border: 0; background: none; padding: 2px 4px; color: var(--accent); cursor: pointer; text-decoration: underline; text-underline-offset: 2px; }
.link.danger { color: var(--danger); }

.menu-wrap { position: relative; }
.menu {
  position: absolute; right: 0; top: calc(100% + 4px); z-index: 20; min-width: 270px;
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: 0 8px 28px rgba(0,0,0,.12); padding: 4px; display: flex; flex-direction: column;
}
.menu button, .menu label { text-align: left; border: 0; background: none; padding: 8px 10px; border-radius: 5px; cursor: pointer; }
.menu button:hover, .menu label:hover { background: var(--bg); }

/* --- work area --- */
.work {
  flex: 1; min-height: 0;
  display: grid; grid-template-columns: 236px minmax(0, 1fr) 360px;
}
.pages {
  overflow-y: auto; padding: 10px 10px 40px; border-right: 1px solid var(--line); background: #f7f6f3;
  display: flex; flex-direction: column; gap: 10px;
}
.pg-label { font-size: 12px; color: var(--ink-2); margin: 0 0 3px 2px; font-weight: 600; }
.pair { display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }
.thumb {
  display: block; width: 100%; padding: 0; border: 2px solid transparent; border-radius: 4px; background: none; cursor: pointer;
}
.thumb svg { display: block; width: 100%; height: auto; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.18); border-radius: 2px; }
.thumb.on { border-color: var(--accent); }
.thumb:hover:not(.on) { border-color: var(--line-2); }
.pg-off { border: 1px dashed var(--line-2); background: none; border-radius: 6px; padding: 8px; color: var(--ink-2); cursor: pointer; }

.stage { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.stage-bar { display: flex; align-items: center; justify-content: center; gap: 10px; padding: 8px; }
.stage-bar .btn { font-size: 18px; line-height: 1; padding: 4px 12px; }
.where { min-width: 260px; text-align: center; font-weight: 600; }
.where small { color: var(--ink-3); font-weight: 400; margin-left: 6px; }
.stage-sheet {
  flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center;
  padding: 4px 24px 24px; container-type: size;
}
.sheet {
  width: min(100cqw, 100cqh * 297 / 210); height: auto; aspect-ratio: 297 / 210;
  background: #fff; box-shadow: 0 2px 6px rgba(0,0,0,.12), 0 12px 36px rgba(0,0,0,.12);
  user-select: none; touch-action: none; overflow: visible;
}

/* editor overlays (mm units) */
.hit { fill: transparent; cursor: pointer; }
.hit.frame.recadrer { cursor: grab; }
.hit.frame.recadrer:active { cursor: grabbing; }
.hit.frame.disposer { cursor: move; }
.hit.frame:hover { stroke: var(--accent); stroke-width: .5; stroke-dasharray: 1.6 1.2; }
.hit.frame.drop { fill: rgba(45,95,124,.18); stroke: var(--accent); stroke-width: .8; }
.hit.text { cursor: move; }
.hit.text:hover, .hit.text.sel { stroke: var(--accent); stroke-width: .35; stroke-dasharray: 1.2 .9; }
.hit.text.empty { stroke: var(--ink-3); stroke-width: .3; stroke-dasharray: 1 1; }
.placeholder { font-size: 3.6px; fill: var(--ink-3); font-family: system-ui, sans-serif; pointer-events: none; }
.sel-outline { fill: none; stroke: var(--accent); stroke-width: .7; pointer-events: none; }
.handle { fill: #fff; stroke: var(--accent); stroke-width: .45; }
.h-nw, .h-se { cursor: nwse-resize; } .h-ne, .h-sw { cursor: nesw-resize; }
.h-n, .h-s { cursor: ns-resize; } .h-e, .h-w { cursor: ew-resize; }
.guide { stroke: #e0453a; stroke-width: .3; stroke-dasharray: 1.5 1; pointer-events: none; }
.empty-frame rect { fill: #eef1f3; stroke: #b8c2ca; stroke-width: .35; stroke-dasharray: 1.6 1.2; }
.empty-frame text { fill: #8a97a1; font-family: system-ui, sans-serif; }

/* --- right panel --- */
.panel { background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.tabs { display: flex; border-bottom: 1px solid var(--line); padding: 0 8px; }
.tabs button {
  flex: 1; border: 0; background: none; padding: 11px 4px 9px; cursor: pointer; color: var(--ink-2);
  border-bottom: 2px solid transparent; font-weight: 600;
}
.tabs button.on { color: var(--accent); border-bottom-color: var(--accent); }
.panel-body { overflow-y: auto; padding: 12px 16px 40px; }
.panel-body h2 { font-size: 17px; margin: 2px 0 10px; }
.panel-body h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-2); margin: 0 0 8px; }
.panel-body section { padding: 12px 0; border-top: 1px solid var(--line); }
.panel-body section:first-of-type { border-top: 0; padding-top: 4px; }
.card { background: #f8f7f4; border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 12px; margin: 8px 0; }
section.card { border-top: 1px solid var(--line); }
.hint { color: var(--ink-2); font-size: 12.5px; margin: 6px 0; }
.hint.warn, .warn { color: var(--warn); }
.banner { background: var(--accent-soft); color: var(--accent); border-radius: 6px; padding: 8px 10px; font-weight: 600; font-size: 13px; }

.field { display: flex; flex-direction: column; gap: 4px; margin: 8px 0; }
.field > span { font-size: 12.5px; color: var(--ink-2); font-weight: 600; }
.field small { color: var(--ink-3); font-size: 12px; }
input:not([type]), input[type=text], input[type=number], input[type=date], select, textarea {
  border: 1px solid var(--line-2); border-radius: 6px; padding: 6px 8px; background: #fff; min-width: 0;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-soft); border-color: var(--accent); }
textarea { resize: vertical; }
input[type=number] { width: 90px; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; margin: 6px 0; }
.row.between { justify-content: space-between; }
.grow { flex: 1; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; margin: 8px 0; }
.btns.right { justify-content: flex-end; }
.check { display: flex; align-items: center; gap: 7px; margin: 5px 0; cursor: pointer; }
.check input { margin: 0; }

.seg { display: inline-flex; border: 1px solid var(--line-2); border-radius: 7px; overflow: hidden; flex-wrap: wrap; }
.seg button { border: 0; background: #fff; padding: 6px 10px; cursor: pointer; border-left: 1px solid var(--line); }
.seg button:first-child { border-left: 0; }
.seg button.on { background: var(--accent); color: #fff; }
.range { display: flex; align-items: center; gap: 10px; }
.range input { flex: 1; accent-color: var(--accent); }
.range output { min-width: 56px; text-align: right; font-variant-numeric: tabular-nums; color: var(--ink-2); font-size: 13px; }
input[type=color] { width: 34px; height: 28px; padding: 2px; border: 1px solid var(--line-2); border-radius: 6px; background: #fff; cursor: pointer; }

.layouts { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-bottom: 10px; }
.layouts button { padding: 3px; border: 2px solid transparent; border-radius: 6px; background: #f3f2ef; cursor: pointer; }
.layouts button.on { border-color: var(--accent); }
.layouts button:hover:not(.on) { border-color: var(--line-2); }
.layout-icon { display: block; width: 100%; height: auto; border-radius: 2px; }

.frame-photo { display: flex; gap: 10px; align-items: center; }
.frame-photo img { width: 72px; height: 54px; object-fit: cover; border-radius: 4px; }
.frame-photo .name { font-size: 12.5px; word-break: break-all; color: var(--ink-2); }
.dpi { font-size: 12.5px; font-weight: 600; }
.dpi.ok { color: var(--ok); } .dpi.meh { color: var(--warn); } .dpi.bad { color: var(--danger); }

.text-form { border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 10px; margin: 8px 0; }
.text-form.sel { border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
.text-form .kind { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink-3); font-weight: 700; }

.drop {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 18px;
  border: 2px dashed var(--line-2); border-radius: var(--radius); cursor: pointer; background: #faf9f7; text-align: center;
}
.drop:hover, .drop.over { border-color: var(--accent); background: var(--accent-soft); }
.drop input { display: none; }
.drop strong { color: var(--accent); }
.drop span { font-size: 12.5px; color: var(--ink-2); }
.photos { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-top: 10px; }
.photo { position: relative; aspect-ratio: 1; border-radius: 6px; overflow: hidden; cursor: grab; background: #eee; border: 2px solid transparent; }
.photo.cur { border-color: var(--accent); }
.photo img { width: 100%; height: 100%; object-fit: cover; display: block; pointer-events: none; }
.photo .loading { width: 100%; height: 100%; background: linear-gradient(90deg, #eee, #f6f6f6, #eee); }
.photo .badge {
  position: absolute; left: 4px; bottom: 4px; background: var(--accent); color: #fff; font-size: 11px; font-weight: 700;
  border-radius: 9px; min-width: 18px; height: 18px; display: grid; place-items: center; padding: 0 5px;
}
.photo .x {
  position: absolute; right: 3px; top: 3px; width: 22px; height: 22px; border-radius: 50%; border: 0;
  background: rgba(0,0,0,.55); color: #fff; cursor: pointer; display: none; line-height: 1; font-size: 15px;
}
.photo:hover .x { display: block; }

.themes { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; margin-bottom: 8px; }
.themes button { border: 2px solid var(--line); border-radius: var(--radius); background: #fff; padding: 10px 4px; cursor: pointer; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.themes button.on { border-color: var(--accent); }
.themes .t { font-size: 20px; }
.themes .s { font-size: 12px; color: var(--ink-2); }
.palettes { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin-bottom: 10px; }
.palettes button { border: 1px solid var(--line); border-radius: 6px; background: #fff; padding: 6px; cursor: pointer; display: flex; flex-wrap: wrap; align-items: center; gap: 0; }
.palettes button:hover { border-color: var(--ink-3); }
.palettes i { width: calc(100% / 12); height: 10px; display: block; }
.palettes i:first-child { border-radius: 3px 0 0 3px; } .palettes i:nth-child(12) { border-radius: 0 3px 3px 0; }
.palettes span { width: 100%; font-size: 12px; color: var(--ink-2); margin-top: 3px; text-align: left; }
.months { display: grid; grid-template-columns: repeat(6, 1fr); gap: 6px 4px; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px 14px; margin: 8px 0; }
.swatch { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 11.5px; color: var(--ink-2); cursor: pointer; }
.swatches .swatch { flex-direction: row; gap: 6px; font-size: 12.5px; }
i.zone { display: inline-block; width: 14px; height: 4px; border-radius: 2px; }

.events { list-style: none; padding: 0; margin: 0; }
.events li { display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 2px 0; }
.events b { display: inline-block; min-width: 22px; }
.periods { width: 100%; border-collapse: collapse; font-size: 12.5px; margin: 6px 0; }
.periods th { text-align: left; color: var(--ink-2); font-weight: 600; padding: 2px; }
.periods td { padding: 2px; }
.periods input, .periods select { padding: 3px 4px; font-size: 12.5px; }
details summary { cursor: pointer; color: var(--accent); margin: 8px 0; }

/* --- dialog --- */
.modal-bg { position: fixed; inset: 0; background: rgba(20,25,30,.42); display: grid; place-items: center; z-index: 50; padding: 16px; }
.modal { background: var(--panel); border-radius: 12px; padding: 18px 22px; width: min(480px, 100%); box-shadow: 0 20px 60px rgba(0,0,0,.25); }
.modal h2 { margin: 0 0 10px; font-size: 18px; }
.bar { height: 8px; background: var(--bg); border-radius: 4px; overflow: hidden; margin: 10px 0; }
.bar i { display: block; height: 100%; background: var(--accent); transition: width .2s; }

/* --- small screens: pages on top, panel under the page --- */
@media (max-width: 1100px) {
  .work { grid-template-columns: 180px minmax(0, 1fr) 320px; }
}
@media (max-width: 860px) {
  .work { display: flex; flex-direction: column; overflow-y: auto; }
  .pages { flex-direction: row; overflow-x: auto; overflow-y: hidden; border-right: 0; border-bottom: 1px solid var(--line); padding: 8px; flex: none; }
  .pg-group { flex: none; width: 150px; }
  .pages .pg-off { flex: none; }
  .stage-sheet { container-type: inline-size; padding: 4px 12px 12px; }
  .sheet { width: 100cqw; }
  .panel { border-left: 0; border-top: 1px solid var(--line); }
  .where { min-width: 0; }
}
