/* ============================================================
   Label Print Studio — UI + print-accurate label rendering
   Design system: blue (#1E40AF) + amber (#F59E0B), Fira Sans,
   light "studio" theme, micro-interactions, SVG icons.
   ============================================================ */

:root {
  --primary: #1e40af;
  --primary-600: #2563eb;
  --primary-500: #3b82f6;
  --primary-050: #eff4ff;
  --accent: #f59e0b;
  --accent-600: #d97706;

  --bg: #f1f5f9;          /* app background */
  --canvas: #e2e8f0;      /* preview canvas (so white sheets pop) */
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --line: #e2e8f0;
  --line-strong: #cbd5e1;

  --txt: #0f172a;
  --txt-2: #334155;
  --muted: #64748b;
  --danger: #dc2626;
  --danger-bg: #fef2f2;
  --ok: #16a34a;

  --radius: 12px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(15,23,42,.06), 0 1px 3px rgba(15,23,42,.10);
  --shadow-md: 0 4px 12px rgba(15,23,42,.08), 0 2px 4px rgba(15,23,42,.06);
  --shadow-lg: 0 12px 32px rgba(15,23,42,.14);
  --ring: 0 0 0 3px rgba(59,130,246,.35);

  --ui-font: "Fira Sans", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --mono-font: "Fira Code", ui-monospace, SFMono-Regular, Menlo, monospace;
  --label-font: "Hiragino Kaku Gothic ProN", "Hiragino Sans", "Noto Sans JP",
    "Yu Gothic", "YuGothic", Meiryo, sans-serif;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--txt);
  font-family: var(--ui-font);
  font-size: 14px;
  -webkit-font-smoothing: antialiased;
}
h1, h2 { margin: 0; font-weight: 700; }
em { font-style: normal; color: var(--muted); }
.mono { font-family: var(--mono-font); }
.hidden { display: none !important; }

/* SVG icon defaults */
.i { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2;
     stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------------- Passcode lock ---------------- */
.lock {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center;
  background: linear-gradient(135deg, #1e3a8a 0%, #3b82f6 100%);
  padding: 20px;
}
.lock.hidden { display: none; }
.lock-card {
  width: 330px; max-width: 92vw; background: #fff; border-radius: 18px;
  padding: 32px 28px; box-shadow: 0 24px 70px rgba(0,0,0,.4);
  display: flex; flex-direction: column; align-items: center; gap: 13px; text-align: center;
}
.lock-logo { width: 52px; height: 52px; border-radius: 14px; }
.lock-card h2 { font-size: 19px; }
.lock-card > p { margin: 0; color: var(--muted); font-size: 13px; }
.lock-card input {
  width: 100%; text-align: center; font-size: 24px; letter-spacing: .45em;
  font-family: var(--mono-font); padding: 13px; margin-top: 4px;
}
.lock-card .btn { width: 100%; justify-content: center; margin-top: 2px; }
.lock-err { color: var(--danger) !important; min-height: 16px; font-size: 12.5px; font-weight: 500; }

/* sync status chip */
.sync { display: inline-flex; align-items: center; gap: 7px; font-size: 12px; color: var(--muted); padding: 0 10px; }
.sync::before { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--muted); transition: background .2s ease; }
.sync.ok::before { background: var(--ok); }
.sync.saving::before { background: var(--accent); }
.sync.err::before { background: var(--danger); }
.btn.icon-only { padding: 9px; }

/* ---------------- Top bar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 50;
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 20px; background: var(--surface);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-logo {
  display: grid; place-items: center; width: 38px; height: 38px;
  border-radius: 11px; color: #fff;
  background: linear-gradient(135deg, var(--primary), var(--primary-500));
  box-shadow: var(--shadow-sm);
}
.brand-text h1 { font-size: 17px; letter-spacing: -.01em; }
.brand-text p { margin: 1px 0 0; font-size: 12px; color: var(--muted); }
.topbar-actions { display: flex; gap: 10px; }

/* ---------------- Buttons ---------------- */
.btn {
  display: inline-flex; align-items: center; gap: 8px;
  font-family: inherit; font-size: 13.5px; font-weight: 600;
  padding: 9px 14px; min-height: 40px; border-radius: 10px;
  border: 1px solid transparent; cursor: pointer;
  transition: background .18s ease, border-color .18s ease, color .18s ease, box-shadow .18s ease;
}
.btn:focus-visible { outline: none; box-shadow: var(--ring); }
.btn .i { width: 16px; height: 16px; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-600); }
.btn-ghost { background: transparent; color: var(--txt-2); border-color: var(--line-strong); }
.btn-ghost:hover { background: var(--surface-2); border-color: var(--muted); }
.btn-soft { background: var(--surface-2); color: var(--txt-2); border-color: var(--line); font-weight: 500; }
.btn-soft:hover { background: #eef2f7; border-color: var(--line-strong); }
.btn-soft.danger { color: var(--danger); }
.btn-soft.danger:hover { background: var(--danger-bg); border-color: #fecaca; }

/* ---------------- Layout ---------------- */
.layout {
  display: grid;
  grid-template-columns: 300px minmax(380px, 1fr) minmax(380px, 0.82fr);
  height: calc(100vh - 63px);
}
.sidebar { overflow-y: auto; padding: 16px; border-right: 1px solid var(--line); background: var(--bg); }
.workspace { overflow: hidden; display: flex; flex-direction: column; border-right: 1px solid var(--line); background: var(--surface-2); min-width: 0; }
.previewpane { display: flex; flex-direction: column; min-width: 0; background: var(--surface); }

/* ---------------- Cards / fields ---------------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 15px; margin-bottom: 14px; box-shadow: var(--shadow-sm); }
.card-title { display: flex; align-items: center; gap: 9px; font-size: 13.5px; margin-bottom: 13px; color: var(--txt); }
.card-title .i { color: var(--primary-500); }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.field.narrow { max-width: 96px; }
.label { font-size: 11.5px; font-weight: 500; color: var(--muted); }
.toggle-label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
.toggle-label input { width: 15px; height: 15px; accent-color: var(--primary); cursor: pointer; flex: none; }
.field-row { display: flex; gap: 10px; flex-wrap: wrap; }
.field-row .field { flex: 1 1 130px; margin-bottom: 12px; }
.hint { font-size: 11.5px; line-height: 1.55; color: var(--muted); margin: 8px 0 0; }

input[type="text"], input[type="number"], input[type="month"], input[type="search"], select {
  width: 100%; font-family: inherit; font-size: 13.5px; color: var(--txt);
  background: var(--surface); border: 1px solid var(--line-strong); border-radius: 9px;
  padding: 9px 10px; min-height: 40px; transition: border-color .15s ease, box-shadow .15s ease;
}
input:focus, select:focus { outline: none; border-color: var(--primary-500); box-shadow: var(--ring); }
input::placeholder { color: #94a3b8; }
input:disabled { background: var(--surface-2); color: var(--muted); cursor: not-allowed; }

.check { display: flex; align-items: center; gap: 9px; font-size: 13px; color: var(--txt-2); cursor: pointer; padding: 4px 0; }
.check.tight { padding: 0; align-self: center; white-space: nowrap; }
.check input { width: 17px; height: 17px; accent-color: var(--primary); cursor: pointer; }

.btn-grid { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 10px; }
.btn-grid .btn { flex: 1; justify-content: center; padding: 8px 10px; min-height: 38px; }

/* ---------------- Segmented control ---------------- */
.seg { display: flex; gap: 8px; }
.seg-btn {
  flex: 1; display: flex; flex-direction: column; gap: 2px; align-items: flex-start;
  padding: 10px 11px; cursor: pointer; text-align: left;
  background: var(--surface); border: 1.5px solid var(--line-strong); border-radius: 10px;
  transition: border-color .15s ease, background .15s ease, box-shadow .15s ease;
}
.seg-btn strong { font-size: 12.5px; color: var(--txt); }
.seg-btn span { font-size: 10.5px; color: var(--muted); font-family: var(--mono-font); }
.seg-btn:hover { border-color: var(--primary-500); }
.seg-btn.active { border-color: var(--primary); background: var(--primary-050); box-shadow: var(--shadow-sm); }
.seg-btn.active strong { color: var(--primary); }

.sidebar-foot { display: block; margin-top: 4px; text-align: center; font-size: 11.5px; font-family: var(--mono-font); color: var(--muted); text-decoration: none; }
.sidebar-foot:hover { color: var(--primary-600); }

/* ---------------- Workspace header ---------------- */
.workspace-head { padding: 16px 18px; border-bottom: 1px solid var(--line); background: var(--surface); }
.wh-title { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; }
.wh-title h2 { font-size: 16px; }
.count { font-size: 12px; font-weight: 600; color: var(--primary); background: var(--primary-050); padding: 2px 9px; border-radius: 999px; }
.wh-tools { display: flex; gap: 10px; }
.search { position: relative; flex: 1; }
.search .i { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); width: 16px; height: 16px; color: var(--muted); }
.search input { padding-left: 34px; }

/* ---------------- Product list ---------------- */
.product-list { flex: 1; overflow-y: auto; padding: 14px 16px; display: flex; flex-direction: column; gap: 11px; }
.empty { flex: 1; display: flex; flex-direction: column; gap: 14px; align-items: center; justify-content: center; color: var(--muted); }

.pcard { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow-sm); transition: box-shadow .18s ease, border-color .18s ease; }
.pcard:hover { box-shadow: var(--shadow-md); border-color: var(--line-strong); }
.pcard.dragging { opacity: .45; }
.pcard.editing { border-color: var(--primary-500); box-shadow: var(--shadow-md); }

.pcard-top { display: flex; align-items: center; gap: 12px; padding: 11px 13px; }
.grip { display: grid; place-items: center; width: 22px; height: 34px; background: none; border: none; color: #cbd5e1; cursor: grab; padding: 0; }
.grip:hover { color: var(--muted); }
.grip .i { width: 18px; height: 18px; stroke: none; }

.thumb { flex: none; border: 1px solid var(--line); border-radius: 7px; overflow: hidden; background: #fff; box-shadow: var(--shadow-sm); }
.thumbcell { container-type: size; background: #fff; display: block; position: relative; overflow: hidden; }

.pcard-meta { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.p-name { font-size: 14px; font-weight: 700; color: var(--txt); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.p-sub { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-height: 14px; }
.chips { display: flex; flex-wrap: wrap; gap: 5px; margin-top: 3px; }
.chip { font-size: 11px; font-weight: 500; padding: 2px 8px; border-radius: 6px; background: var(--surface-2); border: 1px solid var(--line); color: var(--txt-2); white-space: nowrap; }
.chip.size-chip { color: var(--primary); border-color: #c7d7fb; background: var(--primary-050); font-weight: 600; }
.chip.price-chip { color: var(--accent-600); border-color: #fde6c0; background: #fffbeb; font-weight: 600; }
.chip.mono { font-family: var(--mono-font); font-size: 10.5px; }
.chip.exp-chip.off { color: var(--muted); }

.qty { display: flex; flex-direction: column; align-items: stretch; gap: 4px; flex: none; width: 98px; }
.qty-label { font-size: 10.5px; color: var(--muted); font-weight: 500; text-align: center; }
.qty input { width: 100%; text-align: center; padding: 7px 6px; min-height: 36px; }
.qty select { width: 100%; padding: 5px 7px; min-height: 32px; font-size: 11.5px; }
.qty-calc { font-size: 10px; color: var(--muted); text-align: center; min-height: 11px; }

.pcard-actions { display: flex; gap: 2px; flex: none; }
.iconbtn { display: grid; place-items: center; width: 36px; height: 36px; background: none; border: none; border-radius: 8px; color: var(--muted); cursor: pointer; transition: background .15s ease, color .15s ease; }
.iconbtn:hover { background: var(--surface-2); color: var(--txt); }
.iconbtn.del:hover { background: var(--danger-bg); color: var(--danger); }
.iconbtn:focus-visible { outline: none; box-shadow: var(--ring); }
.chev { transition: transform .2s ease; }
.pcard.editing .chev { transform: rotate(180deg); }

.pcard-edit { display: none; padding: 4px 14px 14px; border-top: 1px solid var(--line); margin-top: 2px; }
.pcard.editing .pcard-edit { display: block; animation: reveal .18s ease; }
@keyframes reveal { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: none; } }
.pcard-edit .field-row { margin-top: 12px; }
.exp-row { align-items: end; }
.bc-status { font-size: 11.5px; margin: 10px 0 0; min-height: 14px; font-family: var(--mono-font); }
.bc-status.ok { color: var(--ok); }
.bc-status.err { color: var(--danger); font-family: var(--ui-font); }

/* ---------------- Preview ---------------- */
.preview-toolbar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 13px 18px; border-bottom: 1px solid var(--line); background: var(--surface); }
.sheet-info { font-size: 12.5px; color: var(--muted); }
.zoom { display: flex; align-items: center; gap: 9px; color: var(--muted); }
.zoom .i { width: 16px; height: 16px; }
.zoom input[type="range"] { width: 130px; min-height: auto; padding: 0; accent-color: var(--primary); cursor: pointer; }
.zoom .mono { font-size: 12px; min-width: 38px; text-align: right; color: var(--txt-2); }
.preview-scroll { flex: 1; overflow: auto; padding: 26px; background: var(--canvas); }
.pages { display: flex; flex-direction: column; align-items: center; gap: 24px; }

/* ============================================================
   SHEET + LABEL  (print-accurate — DO NOT restyle proportions)
   ============================================================ */
.sheet { background: #fff; position: relative; box-shadow: var(--shadow-lg); width: 210mm; height: 297mm; overflow: hidden; color: #000; }
.sheet.scaled { transform-origin: top left; }
.cell { position: absolute; overflow: hidden; container-type: size; background: #fff; }
.cell.guides { outline: 1px dashed #c9c9c9; outline-offset: -0.5px; }

/* 20-up only: thin printed frame around each label (cell stays exact size via
   border-box, so the grid alignment is unchanged) */
.sheet.s20 .cell { border: 0.25mm solid #000; }
.sheet.s20 .cell.guides { outline: none; }

.lbl { width: 100%; height: 100%; font-family: var(--label-font); color: #000; line-height: 1.06; display: flex; flex-direction: column; font-feature-settings: "palt" 1; }

/* 20-up: tall cells hold the same horizontal label, rotated 90° to fill them.
   width/height use the cell's swapped dimensions via container-query units. */
.rotwrap {
  position: absolute; left: 50%; top: 50%;
  width: 100cqh; height: 100cqw;
  transform: translate(-50%, -50%) rotate(-90deg);
  transform-origin: center center;
  container-type: size;
}

/* ===========  LANDSCAPE (44-up : 48.3 x 25.4) =========== */
.lbl-land { padding: 3.5cqh 3.5cqw; }
.lbl-land .title { display: flex; align-items: flex-end; gap: 2.6cqw; white-space: nowrap; }
.lbl-land .hinmei { font-size: 13.5cqh; font-weight: 800; letter-spacing: .02em; line-height: 1; }
.lbl-land .pname { display: flex; flex-direction: column; min-width: 0; }
.lbl-land .pname .jp { font-size: 5.2cqh; font-weight: 700; line-height: 1.05; }
.lbl-land .pname .en { font-size: 10cqh; font-weight: 800; letter-spacing: -.01em; line-height: 1.02; }

.lbl-land .mid { display: flex; gap: 2cqw; margin-top: 2cqh; flex: 1; align-items: flex-start; min-width: 0; }
.lbl-land .info { display: flex; flex-direction: column; gap: 0.5cqh; font-size: 5.2cqh; white-space: nowrap; }
.lbl-land .company { display: flex; align-items: flex-start; gap: 1cqw; font-size: 5cqh; white-space: nowrap; }
.lbl-land .company .caddr { display: flex; flex-direction: column; gap: 0.4cqh; }
.lbl-land .price { margin-left: auto; align-self: center; padding-left: 1cqw; }
.lbl-land .yen { display: inline-flex; align-items: center; justify-content: center; border: 0.7cqh solid #000; border-radius: 5cqh; padding: 1cqh 2cqw; font-size: 10.5cqh; font-weight: 800; white-space: nowrap; line-height: 1; }
.lbl-land .barcode { margin-top: auto; }
.lbl-land .barcode svg { width: 100%; height: auto; display: block; }

/* Fit the landscape design into the slightly-taller 20-up rotated box (aspect
   1.77 vs the 44-up's 1.90) so nothing clips. Only affects the rotated 20-up. */
.rotwrap .lbl-land { padding: 4cqh 4cqw; }
.rotwrap .lbl-land .hinmei { font-size: 12.5cqh; }
.rotwrap .lbl-land .pname .jp { font-size: 4.8cqh; }
.rotwrap .lbl-land .pname .en { font-size: 9.3cqh; }
.rotwrap .lbl-land .info { font-size: 4.8cqh; }
.rotwrap .lbl-land .company { font-size: 4.6cqh; }
.rotwrap .lbl-land .yen { font-size: 9.6cqh; padding: 1cqh 1.8cqw; }

/* ===========  PORTRAIT (20-up : 42 x 74.25) =========== */
.lbl-port { padding: 3cqh 7cqw 3.5cqh; }
.lbl-port .title { display: flex; flex-direction: column; align-items: center; text-align: center; }
.lbl-port .hinmei { font-size: 4cqh; font-weight: 800; letter-spacing: .3em; color: #000; }
.lbl-port .pname .jp { font-size: 2.6cqh; font-weight: 700; }
.lbl-port .pname { text-align: center; margin-top: 0.4cqh; display: flex; flex-direction: column; }
.lbl-port .pname .en { font-size: 5.2cqh; font-weight: 800; line-height: 1.05; }
.lbl-port .rule { height: 0; border-top: 0.45cqh solid #000; margin: 1.2cqh 0; }
.lbl-port .pmid { flex: 1; display: flex; flex-direction: column; justify-content: space-evenly; }
.lbl-port .info { display: flex; flex-direction: column; gap: 0.9cqh; font-size: 3.3cqh; }
.lbl-port .company { font-size: 3.1cqh; display: flex; flex-direction: column; gap: 0.6cqh; }
.lbl-port .company .clabel { font-weight: 700; }
.lbl-port .price { text-align: center; }
.lbl-port .yen { display: inline-flex; align-items: center; justify-content: center; border: 0.55cqh solid #000; border-radius: 3cqh; padding: 0.9cqh 5cqw; font-size: 6cqh; font-weight: 800; }
.lbl-port .barcode { margin-top: 1.5cqh; }
.lbl-port .barcode svg { width: 100%; height: auto; display: block; }

/* ============================================================
   PRINT
   ============================================================ */
.print-root { display: none; }
@media print {
  .no-print, .no-print-grid, .topbar, .sidebar, .workspace, .previewpane { display: none !important; }
  html, body { background: #fff; height: auto; }
  .print-root { display: block; }
  .sheet { box-shadow: none; transform: none !important; page-break-after: always; break-after: page; margin: 0; }
  .sheet:last-child { page-break-after: auto; break-after: auto; }
  .cell.guides { outline: none; }
}
@page { size: A4 portrait; margin: 0; }

/* ---------------- Responsive ---------------- */
@media (max-width: 1180px) {
  .layout { grid-template-columns: 280px 1fr; height: auto; min-height: calc(100vh - 63px); }
  .previewpane { grid-column: 1 / -1; border-right: none; border-top: 1px solid var(--line); height: 80vh; }
}
@media (max-width: 760px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { border-right: none; border-bottom: 1px solid var(--line); }
  .workspace { border-right: none; }
  .pcard-top { flex-wrap: wrap; }
  .topbar-actions .btn-ghost span, .brand-text p { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  * { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
