:root {
  --bg: #0f1218;
  --panel: #171b24;
  --border: #2a3142;
  --text: #e8eaef;
  --muted: #8b93a7;
  --accent: #c9a227;
  --danger: #c44;
  --font-ui: "DM Sans", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: var(--font-ui); font-size: 14px; }

#app { min-height: 100%; display: flex; flex-direction: column; }

.login-screen {
  max-width: 400px; margin: 4rem auto; padding: 2rem;
  background: var(--panel); border: 1px solid var(--border); border-radius: 12px;
}
.login-screen h1 { margin: 0 0 0.5rem; font-weight: 600; font-size: 1.25rem; }
.login-screen p { color: var(--muted); margin: 0 0 1rem; font-size: 0.9rem; }
.login-screen input[type="password"] {
  width: 100%; padding: 0.65rem 0.75rem; border-radius: 8px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); margin-bottom: 0.75rem;
}
.login-screen button {
  width: 100%; padding: 0.65rem; border: none; border-radius: 8px; background: var(--accent); color: #111;
  font-weight: 600; cursor: pointer;
}
.login-screen button:hover { filter: brightness(1.08); }

.toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 1rem;
  padding: 0.6rem 1rem; border-bottom: 1px solid var(--border); background: var(--panel);
}
.toolbar label { color: var(--muted); font-size: 0.8rem; }
.toolbar select, .toolbar input[type="text"], .toolbar input[type="number"] {
  background: var(--bg); border: 1px solid var(--border); color: var(--text);
  padding: 0.35rem 0.5rem; border-radius: 6px; font-size: 0.85rem;
}
.toolbar button {
  padding: 0.4rem 0.75rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); cursor: pointer; font-size: 0.85rem;
}
.toolbar button.primary { background: var(--accent); color: #111; border-color: transparent; font-weight: 600; }
.toolbar button.danger { border-color: var(--danger); color: #f88; }
.toolbar button:hover { filter: brightness(1.05); }

.layout-main {
  display: grid;
  grid-template-columns: 280px minmax(320px, 1fr) minmax(380px, 1fr);
  flex: 1; min-height: 0;
}
@media (max-width: 1200px) {
  .layout-main { grid-template-columns: 1fr; min-height: auto; }
}

.panel {
  border-right: 1px solid var(--border); display: flex; flex-direction: column; min-height: 0;
  background: var(--panel);
}
.panel:last-child { border-right: none; }
.panel h2 {
  margin: 0; padding: 0.75rem 1rem; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--muted); border-bottom: 1px solid var(--border);
}

.inspector { padding: 0.75rem 1rem; overflow-y: auto; flex: 1; }
.inspector-row { margin-bottom: 0.65rem; }
.inspector-row label { display: block; font-size: 0.75rem; color: var(--muted); margin-bottom: 0.2rem; }
.inspector-row input, .inspector-row select {
  width: 100%; padding: 0.35rem 0.5rem; border-radius: 6px; border: 1px solid var(--border);
  background: var(--bg); color: var(--text); font-size: 0.85rem;
}
.inspector-row input[type="number"] { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0.5rem; }

.layers-list { margin: 0; padding: 0; list-style: none; }
.layers-list li {
  padding: 0.45rem 0.65rem; border: 1px solid var(--border); border-radius: 6px; margin-bottom: 0.35rem;
  cursor: pointer; font-size: 0.85rem; display: flex; justify-content: space-between; align-items: center;
  gap: 0.5rem;
}
.layers-list li:hover { border-color: var(--muted); }
.layers-list li.selected { border-color: var(--accent); background: rgba(201, 162, 39, 0.08); }
.layers-list .z { font-size: 0.7rem; color: var(--muted); }

.center-col { display: flex; flex-direction: column; align-items: center; padding: 1rem; overflow: auto; overflow-x: auto; }
.center-col .hint { color: var(--muted); font-size: 0.8rem; margin-bottom: 0.75rem; text-align: center; }

.artboard-wrap {
  flex-shrink: 0; background: var(--bg); padding: 1.5rem; border-radius: 6px; border: 1px solid var(--border);
  box-shadow: 0 8px 32px rgba(0,0,0,0.35);
}
.artboard { position: relative; background: #fff; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08); overflow: hidden; }
.artboard .layer { position: absolute; box-sizing: border-box; }
.artboard .layer.selected { outline: 2px solid var(--accent); outline-offset: -2px; }
.artboard .layer-image.selected { outline: none; }
.artboard .layer-image { transform-origin: center center; }
.artboard .layer-text {
  overflow: hidden; word-wrap: break-word; line-height: 1.2;
}
.artboard .layer-image {
  overflow: hidden;
}
.artboard .layer-image img {
  display: block; width: 100%; height: 100%; object-fit: contain; object-position: center center; pointer-events: none;
}

.right-col { display: flex; flex-direction: column; min-height: 0; border-left: 1px solid var(--border); }
.right-col .a4-scroll {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: #1a1d26;
}
.a4-zoom-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.35rem 0.5rem;
  padding: 0.5rem 1rem;
  flex-shrink: 0;
  border-bottom: 1px solid var(--border);
}
.a4-zoom-bar .a4-zoom-label-muted { font-size: 0.75rem; color: var(--muted); }
.a4-zoom-bar .a4-zoom-pct { font-size: 0.75rem; color: var(--text); min-width: 2.75rem; }
.a4-zoom-bar button {
  width: 1.75rem;
  height: 1.75rem;
  padding: 0;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  font-size: 1rem;
  line-height: 1;
}
.a4-zoom-bar button:hover { filter: brightness(1.08); }
.a4-zoom-bar input[type='range'] { flex: 1; min-width: 80px; max-width: 14rem; }
.a4-zoom-viewport { flex: 1; overflow: auto; padding: 1rem; min-height: 0; }
.right-col .csv-area { border-top: 1px solid var(--border); padding: 0.75rem 1rem; background: var(--panel); }
.right-col textarea {
  width: 100%; min-height: 80px; font-family: "IBM Plex Mono", monospace; font-size: 0.75rem;
  background: var(--bg); border: 1px solid var(--border); color: var(--text); border-radius: 6px; padding: 0.5rem;
}
.right-col .csv-hint { font-size: 0.75rem; color: var(--muted); margin: 0.35rem 0 0; }

.a4-sheet {
  position: relative; background: #fff; margin: 0 auto 1.5rem; box-shadow: 0 4px 24px rgba(0,0,0,0.35);
  flex-shrink: 0;
}
.a4-sheet .cut-marks { position: absolute; inset: 0; pointer-events: none; color: #888; }
.a4-sheet .cut-marks line { stroke: currentColor; stroke-width: 0.4; vector-effect: non-scaling-stroke; }
.a4-sheet .cut-marks path { stroke: currentColor; stroke-width: 0.4; fill: none; vector-effect: non-scaling-stroke; }

.a4-sheet .grid { position: absolute; box-sizing: border-box; }
.a4-sheet .mini-card { position: absolute; box-sizing: border-box; background: #fff; box-shadow: inset 0 0 0 1px rgba(0,0,0,0.08); overflow: hidden; }

@media print {
  @page {
    size: A4;
    margin: 10mm;
  }
  /* visibility:hidden still reserves layout space — use display:none so content starts on page 1 */
  #app > .toolbar,
  #app > .layout-main {
    display: none !important;
  }
  #app > .print-root {
    display: block !important;
  }
  .print-root {
    position: static !important;
    left: auto !important;
    top: auto !important;
    width: auto !important;
  }
  .no-print { display: none !important; }
  .a4-sheet {
    margin: 0 auto !important;
    box-shadow: none;
    -webkit-print-color-adjust: exact;
    print-color-adjust: exact;
  }
  .a4-sheet:not(:last-of-type) {
    page-break-after: always;
    break-after: page;
  }
  .a4-scroll,
  .a4-zoom-viewport { overflow: visible !important; padding: 0 !important; background: #fff !important; }
  .a4-zoom-bar { display: none !important; }
}

.print-root { display: none; }
body.printing .print-root { display: block; }
