:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #faf8f4;
  --text: #1f1a16;
  --muted: #6f655c;
  --border: #e4ddd3;
  --accent: #7a4a2b;
  --accent-text: #ffffff;
  --accent-soft: #f3e8df;
  --note: #b97d00;
  --danger: #b3261e;
  --danger-soft: #fbe9e7;
  --warn: #a15c00;
  --warn-soft: #fff1dc;
  --ok: #2e6b3a;
  --ok-soft: #e4f2e6;
  --info: #285a8a;
  --info-soft: #e3eef8;
  --shadow: 0 1px 2px rgba(40, 25, 10, .06), 0 4px 16px rgba(40, 25, 10, .06);
  --radius: 12px;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151210;
    --surface: #1f1b18;
    --surface-2: #26211d;
    --text: #f1ebe4;
    --muted: #a99d91;
    --border: #3a332d;
    --accent: #d39a6a;
    --accent-text: #1a120c;
    --accent-soft: #3a2a1f;
    --note: #f2c94c;
    --danger: #f2827a;
    --danger-soft: #3d1f1c;
    --warn: #f0b35a;
    --warn-soft: #3a2b15;
    --ok: #86c995;
    --ok-soft: #1d3322;
    --info: #8cbdf0;
    --info-soft: #1a2c3d;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 4px 16px rgba(0, 0, 0, .25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

/* ---------- top bar & nav ---------- */
.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 24px;
  padding: 10px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; font-size: 17px; min-width: 0; }
.brand span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.logo { width: 26px; height: 26px; color: var(--accent); }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav button {
  display: flex; align-items: center; gap: 8px;
  padding: 8px 12px; border: 0; border-radius: 8px;
  background: transparent; color: var(--muted); cursor: pointer; font-weight: 500;
}
.nav button:hover { background: var(--surface-2); color: var(--text); }
.nav button.active { background: var(--accent-soft); color: var(--accent); }

main { max-width: 1040px; margin: 0 auto; padding: 24px 24px 120px; }

.fab {
  position: fixed; right: 24px; bottom: 24px; z-index: 20;
  display: flex; align-items: center; gap: 8px;
  padding: 14px 20px; border: 0; border-radius: 999px;
  background: var(--accent); color: var(--accent-text);
  font-weight: 600; box-shadow: var(--shadow); cursor: pointer;
}
.fab:hover { filter: brightness(1.08); }

@media (max-width: 760px) {
  .topbar { padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top)); }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
    justify-content: space-around; gap: 0;
    padding: 6px 4px max(6px, env(safe-area-inset-bottom));
    background: var(--surface); border-top: 1px solid var(--border);
  }
  .nav button { flex-direction: column; gap: 2px; padding: 6px 4px; font-size: 11px; flex: 1; }
  main { padding: 16px 16px 160px; }
  .fab { right: 16px; bottom: calc(76px + env(safe-area-inset-bottom)); padding: 14px; }
  .fab span { display: none; }
}

/* ---------- page header ---------- */
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.page-head h1 { margin: 0; font-size: 24px; }
.page-head .sub { color: var(--muted); margin-top: 2px; }
h2 { font-size: 15px; margin: 28px 0 10px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; font-weight: 600; }
h2 .count { color: var(--text); margin-left: 6px; }

/* ---------- stats ---------- */
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; }
.stat {
  padding: 14px 16px; background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); text-align: left; cursor: pointer;
}
.stat:hover { border-color: var(--accent); }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 26px; font-weight: 700; margin-top: 2px; font-variant-numeric: tabular-nums; }
.stat.alert .value { color: var(--danger); }
.stat.good .value { color: var(--ok); }

/* ---------- cards / banners ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.banner {
  display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px; border-radius: var(--radius); margin-bottom: 16px;
  background: var(--warn-soft); color: var(--text); border: 1px solid transparent;
}
.banner.welcome { background: var(--accent-soft); }
.empty { padding: 28px 16px; text-align: center; color: var(--muted); background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius); }

/* ---------- list rows ---------- */
.list { display: flex; flex-direction: column; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.row {
  display: flex; align-items: center; gap: 12px; width: 100%;
  padding: 12px 16px; border: 0; border-bottom: 1px solid var(--border);
  background: transparent; text-align: left; cursor: pointer;
}
.row:last-child { border-bottom: 0; }
.row:hover { background: var(--surface-2); }
.row-main { flex: 1; min-width: 0; }
.row-title { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-sub { color: var(--muted); font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-side { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex: none; }
.row-side .bal { font-size: 12px; color: var(--warn); font-weight: 600; }
.row.overdue .row-sub .when { color: var(--danger); font-weight: 600; }
.avatar {
  width: 38px; height: 38px; border-radius: 50%; flex: none;
  display: grid; place-items: center; font-weight: 700;
  background: var(--accent-soft); color: var(--accent);
}

/* ---------- pills ---------- */
.pill { display: inline-block; padding: 2px 10px; border-radius: 999px; font-size: 12px; font-weight: 600; white-space: nowrap; background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.s-booked { background: var(--info-soft); color: var(--info); border-color: transparent; }
.s-cutting, .s-stitching { background: var(--accent-soft); color: var(--accent); border-color: transparent; }
.s-fitting { background: var(--warn-soft); color: var(--warn); border-color: transparent; }
.s-ready { background: var(--ok-soft); color: var(--ok); border-color: transparent; }
.s-delivered { background: var(--surface-2); color: var(--muted); }
.s-cancelled { background: var(--danger-soft); color: var(--danger); border-color: transparent; }

/* ---------- toolbar ---------- */
.toolbar { display: flex; flex-direction: column; gap: 10px; margin-bottom: 14px; }
.search {
  width: 100%; padding: 10px 14px; border: 1px solid var(--border); border-radius: 10px;
  background: var(--surface);
}
.chips { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 2px; scrollbar-width: none; }
.chip {
  flex: none; padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border);
  background: var(--surface); color: var(--muted); cursor: pointer; font-size: 13px; font-weight: 500;
}
.chip.active { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.chip .n { opacity: .7; margin-left: 4px; }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 9px 16px; border-radius: 10px; border: 1px solid var(--border);
  background: var(--surface); cursor: pointer; font-weight: 600; white-space: nowrap; text-decoration: none; color: var(--text);
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.danger { color: var(--danger); }
.btn.small { padding: 5px 10px; font-size: 13px; border-radius: 8px; }
.btn svg { width: 16px; height: 16px; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- modal ---------- */
dialog {
  width: min(680px, calc(100vw - 32px)); max-height: calc(100vh - 48px);
  padding: 0; border: 1px solid var(--border); border-radius: 16px;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(20, 12, 6, .45); }
.modal-head {
  position: sticky; top: 0; z-index: 2;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; background: var(--surface); border-bottom: 1px solid var(--border);
}
.modal-head h3 { margin: 0; font-size: 18px; }
.modal-body { padding: 16px 20px; }
.modal-foot {
  position: sticky; bottom: 0; z-index: 2;
  display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap;
  padding: 12px 20px; background: var(--surface); border-top: 1px solid var(--border);
}
.modal-foot .spacer { flex: 1; }
.icon-btn { border: 0; background: transparent; cursor: pointer; padding: 6px; border-radius: 8px; color: var(--muted); display: grid; place-items: center; }
.icon-btn:hover { background: var(--surface-2); color: var(--text); }

@media (max-width: 760px) {
  dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; margin: 0; border-radius: 0; border: 0; }
  .modal-head { padding-top: max(16px, env(safe-area-inset-top)); }
  .modal-foot { padding-bottom: max(12px, env(safe-area-inset-bottom)); }
}

/* ---------- forms ---------- */
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
@media (max-width: 520px) { .form-grid { grid-template-columns: 1fr; } }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); font-weight: 500; }
.field input, .field select, .field textarea {
  padding: 9px 11px; border: 1px solid var(--border); border-radius: 9px;
  background: var(--surface-2); color: var(--text); font-size: 15px; width: 100%;
}
.field textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus, .search:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.req::after { content: " *"; color: var(--danger); }
.check { display: flex; align-items: center; gap: 8px; font-size: 14px; }
fieldset { border: 1px solid var(--border); border-radius: var(--radius); padding: 12px 14px 14px; margin: 0; }
legend { padding: 0 6px; font-weight: 600; font-size: 14px; }
.measure-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 10px; }
.measure-grid .field input { padding: 7px 9px; }
.measure-input { display: flex; }
.measure-input input { flex: 1; min-width: 0; border-top-right-radius: 0 !important; border-bottom-right-radius: 0 !important; }
.unit-btn {
  flex: none; min-width: 42px; padding: 0 10px; cursor: pointer;
  border: 1px solid var(--border); border-left: 0; border-radius: 0 9px 9px 0;
  background: var(--accent-soft); color: var(--accent); font-weight: 600; font-size: 13px;
}
.unit-btn:hover { filter: brightness(.97); }
.measure-tools { display: flex; align-items: center; justify-content: space-between; gap: 8px; flex-wrap: wrap; margin-bottom: 10px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; flex: none; }
.seg button { border: 0; background: var(--surface); color: var(--text); padding: 5px 12px; font-size: 13px; font-weight: 500; cursor: pointer; }
.seg button + button { border-left: 1px solid var(--border); }
.seg button:hover { background: var(--surface-2); }
.hint { font-size: 12px; color: var(--muted); }
.new-customer { display: none; }
.new-customer.show { display: contents; }

/* ---------- detail ---------- */
.detail-section { margin-top: 18px; }
.detail-section:first-child { margin-top: 0; }
.detail-section h4 { margin: 0 0 8px; font-size: 13px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.kv { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px 16px; }
.kv div span { display: block; font-size: 12px; color: var(--muted); }
.kv div strong { font-weight: 600; }
.measure-table { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 6px; }
.measure-table div { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 0 8px; padding: 6px 10px; background: var(--surface-2); border-radius: 8px; font-size: 14px; }
.measure-table div span { color: var(--muted); }
.measure-table div strong { font-variant-numeric: tabular-nums; }
.measure-table small { font-size: 11px; font-weight: 500; color: var(--muted); }
.measure-table em { flex-basis: 100%; text-align: right; font-style: normal; font-size: 12px; color: var(--muted); }
.stepper { display: flex; gap: 6px; flex-wrap: wrap; }
.stepper button { padding: 6px 12px; border-radius: 999px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-size: 13px; font-weight: 500; color: var(--muted); }
.stepper button.done { color: var(--text); }
.stepper button.current { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
.money-box { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.money-box div { padding: 10px 12px; background: var(--surface-2); border-radius: 10px; }
.money-box span { display: block; font-size: 12px; color: var(--muted); }
.money-box strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.money-box .due strong { color: var(--warn); }
.money-box .settled strong { color: var(--ok); }
.payments { margin: 8px 0 0; padding: 0; list-style: none; font-size: 14px; }
.payments li { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 4px 0; border-bottom: 1px dashed var(--border); }
.payments li:last-child { border-bottom: 0; }
.prewrap { white-space: pre-wrap; }
.muted { color: var(--muted); }

/* ---------- schedule ---------- */
.day { margin-bottom: 18px; }
.day-head { display: flex; align-items: baseline; gap: 8px; margin: 0 0 8px; font-weight: 700; }
.day-head .rel { color: var(--muted); font-weight: 500; font-size: 13px; }
.day.overdue .day-head { color: var(--danger); }
.tag { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 6px; text-transform: uppercase; letter-spacing: .03em; flex: none; }
.tag.due { background: var(--info-soft); color: var(--info); }
.tag.fitting { background: var(--warn-soft); color: var(--warn); }

/* ---------- settings ---------- */
.settings-grid { display: grid; gap: 16px; }
.settings-grid .card h3 { margin: 0 0 4px; font-size: 16px; }
.settings-grid .card p { margin: 0 0 12px; color: var(--muted); font-size: 14px; }

/* ---------- toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: 32px; z-index: 100;
  transform: translate(-50%, 20px); opacity: 0; pointer-events: none;
  padding: 10px 18px; border-radius: 10px; max-width: calc(100vw - 32px);
  background: var(--text); color: var(--bg); font-weight: 500; box-shadow: var(--shadow);
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.error { background: var(--danger); color: #fff; }
@media (max-width: 760px) { #toast { bottom: calc(90px + env(safe-area-inset-bottom)); } }

/* ---------- measurement figure ---------- */
.measure-layout { display: grid; grid-template-columns: minmax(150px, 200px) minmax(0, 1fr); gap: 18px; align-items: start; }
.figure-wrap { position: sticky; top: 72px; display: flex; flex-direction: column; align-items: center; gap: 8px; }
.figure-wrap.small { position: static; }
svg.body-fig { width: 100%; max-width: 190px; height: auto; display: block; }
.body-fig .skin {
  fill: var(--surface-2);
  stroke: var(--text);
  stroke-width: 1.35;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.mk { cursor: pointer; }
.mk-hit { fill: none; stroke: transparent; stroke-width: 14; pointer-events: stroke; }
.mk-line { fill: none; stroke: var(--muted); stroke-width: 1.5; stroke-dasharray: 3 3; opacity: .55; }
.mk-dot { fill: var(--muted); stroke: none; opacity: .55; }
.mk.back .mk-line { stroke-dasharray: 1 3; }
.mk.filled .mk-line { stroke: var(--accent); stroke-dasharray: none; opacity: .7; }
.mk.filled .mk-dot { fill: var(--accent); opacity: .7; }
.mk.active .mk-line { stroke: var(--accent); stroke-width: 3; stroke-dasharray: none; opacity: 1; }
.mk.active .mk-dot { fill: var(--accent); opacity: 1; }
.mk:hover .mk-line { opacity: 1; }
.figure-caption { margin: 0; font-size: 12px; line-height: 1.4; color: var(--muted); text-align: center; min-height: 3.6em; max-width: 220px; }
.figure-caption strong { color: var(--text); font-size: 13px; }
.m-groups { display: flex; flex-direction: column; gap: 16px; min-width: 0; }
.m-group-title { display: flex; align-items: center; gap: 8px; margin: 0 0 8px; font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; color: var(--muted); }
.m-group-title::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.seg button.on { background: var(--accent); color: var(--accent-text); }
.measure-table div[data-key] { cursor: pointer; }
.measure-table div.active { box-shadow: inset 0 0 0 2px var(--accent); }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 8px; }
.section-head h4 { margin: 0; }
@media (max-width: 640px) {
  .measure-layout { grid-template-columns: 1fr; gap: 12px; }
  .figure-wrap { top: 56px; z-index: 1; flex-direction: row; gap: 12px; padding: 6px 0; background: var(--surface); border-bottom: 1px solid var(--border); }
  .figure-wrap.small { border-bottom: 0; }
  svg.body-fig { max-width: 112px; flex: none; }
  .m-groups .measure-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .figure-caption { flex: 1; text-align: left; max-width: none; min-height: 0; }
}

/* ---------- notes ---------- */
.note-group h3 { margin: 20px 4px 6px; font-size: 19px; font-weight: 700; }
.note-group:first-child h3 { margin-top: 0; }
.detail-section .note-group h3 { margin: 10px 2px 4px; font-size: 13px; color: var(--muted); }
.note-list { background: var(--surface); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
.note-row {
  display: flex; flex-direction: column; gap: 2px; width: 100%;
  padding: 10px 16px; border: 0; border-bottom: 1px solid var(--border);
  background: transparent; text-align: left; cursor: pointer;
}
.note-row:last-child { border-bottom: 0; }
.note-row:hover { background: var(--surface-2); }
.note-title { display: flex; align-items: center; gap: 4px; font-size: 16px; font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-title .pin { width: 14px; height: 14px; color: var(--note); }
.note-sub { font-size: 14px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-time { color: var(--text); margin-right: 4px; }
.note-for { display: inline-flex; align-items: center; gap: 4px; font-size: 12px; color: var(--muted); }
.note-for svg { width: 12px; height: 12px; }

.note-sheet { display: flex; flex-direction: column; min-height: min(78vh, 680px); }
.note-bar { position: sticky; top: 0; z-index: 2; display: flex; align-items: center; gap: 2px; padding: 10px 10px 6px; background: var(--surface); }
.note-bar .spacer { flex: 1; }
.note-btn { display: inline-flex; align-items: center; gap: 2px; padding: 6px 8px; border: 0; border-radius: 8px; background: transparent; color: var(--note); font-size: 17px; cursor: pointer; }
.note-btn:hover { background: var(--surface-2); }
.note-btn svg { width: 22px; height: 22px; }
.note-btn.back { max-width: 55%; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.note-btn.back svg { width: 24px; height: 24px; stroke-width: 2.5; }
.note-btn.done { font-weight: 600; }
.note-btn.on svg { fill: var(--note); }
.note-meta { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 2px 20px 8px; font-size: 13px; color: var(--muted); }
.note-link { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px; border-radius: 999px; background: var(--surface-2); }
.note-link svg { width: 14px; height: 14px; }
.note-link select { max-width: 200px; padding: 3px 0; border: 0; background: transparent; color: var(--text); font-size: 13px; }

/* ---------- note editor (text + sketches) ---------- */
.ne { display: flex; flex-direction: column; }
.ne-text { min-height: 1.6em; padding: 2px 0; font-size: 17px; line-height: 1.5; white-space: pre-wrap; overflow-wrap: anywhere; outline: none; cursor: text; }
.ne-text.is-empty[data-ph]::before { content: attr(data-ph); color: var(--muted); pointer-events: none; }
#note-editor { flex: 1; padding: 6px 20px 24px; min-height: 45vh; }
#note-editor .ne-text:first-child::first-line { font-size: 1.55em; font-weight: 700; line-height: 1.3; }
#note-editor .ne-text:last-child { flex: 1; min-height: 6em; }
.ne-sketch { position: relative; margin: 8px 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); overflow: hidden; }
svg.sk-svg { display: block; width: 100%; height: auto; color: var(--text); }
.sk-svg path { fill: none; stroke-linecap: round; stroke-linejoin: round; }
.ne-sketch-tools { position: absolute; top: 8px; right: 8px; display: flex; gap: 6px; }
.ne-sketch-tools button { padding: 4px 10px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; }
.ne-sketch-tools button:last-child { color: var(--danger); }
.note-toolbar { position: sticky; bottom: 0; display: flex; align-items: center; gap: 4px; padding: 8px 12px calc(8px + env(safe-area-inset-bottom, 0px)); background: var(--surface); border-top: 1px solid var(--border); }
.note-toolbar .spacer { flex: 1; }
.note-toolbar .note-btn { gap: 6px; font-size: 15px; font-weight: 600; }
.note-links { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
.note-box { border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); overflow: hidden; }
#order-note { padding: 8px 12px; min-height: 90px; color: var(--text); }
#order-note .ne-text { font-size: 15px; }
#order-note .ne-text:last-child { min-height: 3em; }
.note-box-tools { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 8px 12px; border-top: 1px solid var(--border); background: var(--surface); }
.note-preview { display: flex; flex-direction: column; gap: 8px; }
.note-preview p { margin: 0; }
.sk-view { border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); overflow: hidden; max-width: 520px; }

/* note list rows with sketch thumbnails */
.note-row { flex-direction: row; align-items: center; gap: 12px; }
.note-text { display: flex; flex-direction: column; gap: 2px; flex: 1; min-width: 0; }
.note-tags { display: flex; flex-wrap: wrap; gap: 4px 12px; }
.note-thumb { flex: none; width: 64px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); overflow: hidden; }

/* ---------- sketch pad ---------- */
#sketch { width: min(980px, calc(100vw - 32px)); height: min(820px, calc(100dvh - 32px)); max-width: none; max-height: none; padding: 0; border: 1px solid var(--border); border-radius: 16px; background: var(--surface); color: var(--text); }
#sketch::backdrop { background: var(--backdrop, rgba(0, 0, 0, .5)); }
.sk { display: flex; flex-direction: column; height: 100%; }
.sk-bar { display: flex; align-items: center; justify-content: space-between; padding: 10px 12px; border-bottom: 1px solid var(--border); }
.sk-title { font-weight: 700; }
.sk-stage { flex: 1; min-height: 0; display: flex; align-items: center; justify-content: center; padding: 12px; background: var(--bg); }
#sk-canvas { display: block; background: var(--surface); border: 1px solid var(--border); border-radius: 12px; touch-action: none; cursor: crosshair; box-shadow: var(--shadow); }
.sk-tools { display: flex; flex-direction: column; gap: 8px; padding: 10px 12px calc(10px + env(safe-area-inset-bottom, 0px)); border-top: 1px solid var(--border); }
.sk-row { display: flex; align-items: center; justify-content: center; flex-wrap: wrap; gap: 8px; }
.sk-sep { width: 1px; height: 24px; background: var(--border); margin: 0 4px; }
.sk-ink, .sk-w { display: grid; place-items: center; width: 38px; height: 38px; padding: 0; border: 2px solid transparent; border-radius: 50%; background: var(--surface-2); cursor: pointer; }
.sk-ink span { width: 22px; height: 22px; border-radius: 50%; }
.sk-w span { border-radius: 50%; background: var(--text); }
.sk-ink.on, .sk-w.on { border-color: var(--accent); }
.sk-tool { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border: 1px solid var(--border); border-radius: 999px; background: var(--surface); color: var(--text); font-size: 13px; font-weight: 600; cursor: pointer; }
.sk-tool svg { width: 16px; height: 16px; }
.sk-tool.on { background: var(--accent); border-color: var(--accent); color: var(--accent-text); }
@media (max-width: 760px) {
  .note-sheet { min-height: 100dvh; }
}
@media (max-width: 640px) {
  #sketch { width: 100vw; height: 100dvh; border: 0; border-radius: 0; }
  .sk-stage { padding: 8px; }
}

/* ---------- proportional body figure ---------- */
.measure-layout { grid-template-columns: minmax(200px, 270px) minmax(0, 1fr); }
.figure-wrap { position: sticky; }
.figure-wrap .fig-expand {
  position: absolute; top: 0; right: 0; z-index: 1; display: grid; place-items: center;
  width: 34px; height: 34px; padding: 0; border: 1px solid var(--border); border-radius: 50%;
  background: var(--surface); color: var(--text); cursor: pointer;
}
.figure-wrap .fig-expand svg { width: 16px; height: 16px; }
svg.body-fig { max-width: 250px; max-height: 64vh; }
.body-fig .skin, .body-fig .mk-line, .body-fig .mk-hit { vector-effect: non-scaling-stroke; }
.body-fig .mk-label { fill: var(--text); font-weight: 700; paint-order: stroke; stroke: var(--surface); stroke-width: .7; stroke-linejoin: round; pointer-events: none; }
@media (max-width: 640px) {
  .measure-layout { grid-template-columns: 1fr; }
  .figure-wrap .fig-expand { top: 6px; right: 0; }
  svg.body-fig { max-width: 112px; }
}

/* ---------- full-screen viewer ---------- */
#viewer { width: 100vw; height: 100dvh; max-width: none; max-height: none; margin: 0; padding: 0; border: 0; border-radius: 0; background: var(--surface); color: var(--text); }
#viewer::backdrop { background: var(--surface); }
.viewer { display: flex; flex-direction: column; height: 100%; }
.viewer-bar { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 16px; padding-top: calc(10px + env(safe-area-inset-top, 0px)); border-bottom: 1px solid var(--border); }
.viewer-body { flex: 1; min-height: 0; overflow: auto; }
.body-viewer { display: grid; grid-template-columns: minmax(0, 1fr) minmax(260px, 340px); gap: 16px; height: 100%; padding: 16px; }
.bv-figure { display: flex; justify-content: center; min-height: 0; }
.bv-figure svg.body-fig { max-width: none; max-height: none; width: auto; height: 100%; min-height: 420px; }
.bv-side { display: flex; flex-direction: column; gap: 12px; overflow: auto; }
.bv-side .figure-caption { text-align: left; max-width: none; min-height: 0; }
@media (max-width: 760px) {
  .body-viewer { grid-template-columns: 1fr; height: auto; }
  .bv-figure svg.body-fig { width: 100%; height: auto; min-height: 0; max-height: 78dvh; }
}
.photo-viewer { display: grid; place-items: center; height: 100%; padding: 12px; background: var(--bg); }
.photo-viewer img { max-width: 100%; max-height: calc(100dvh - 90px); object-fit: contain; border-radius: 8px; }

/* ---------- photos in notes ---------- */
.ne-photo { position: relative; margin: 8px 0; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); overflow: hidden; }
.ne-photo img { display: block; width: 100%; max-height: 440px; object-fit: contain; }
img[data-photo][data-state="loading"], img[data-photo]:not([src]) { min-height: 80px; background: var(--surface-2); }
img[data-photo][data-state="missing"] { min-height: 60px; }
.ph-view { display: block; padding: 0; border: 1px solid var(--border); border-radius: 10px; background: var(--surface-2); overflow: hidden; cursor: zoom-in; max-width: 520px; }
.ph-view img { display: block; width: 100%; max-height: 360px; object-fit: cover; }
.note-thumb img { display: block; width: 64px; height: 48px; object-fit: cover; }

/* ---------- full-screen measuring ---------- */
.mv .viewer-bar { gap: 8px; }
.mv .viewer-bar strong { flex: 1; text-align: center; }
.mv-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(300px, 380px); gap: 16px; height: 100%; padding: 16px; }
.mv-body .bv-figure { overflow: auto; }
.mv-body .bv-figure svg.body-fig { height: 100%; width: auto; max-width: none; max-height: none; min-height: 420px; }
.mv-body .bv-side { overflow: auto; }
.mv-panel { display: flex; flex-direction: column; gap: 8px; padding: 14px; border: 1px solid var(--border); border-radius: 12px; background: var(--surface-2); }
.mv-head { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }
.mv-head strong { font-size: 18px; }
.mv-step { font-size: 12px; color: var(--muted); white-space: nowrap; }
.mv-how { margin: 0; font-size: 13px; color: var(--muted); }
.mv-value { margin: 0; font-weight: 600; }
.mv-row { display: flex; align-items: stretch; gap: 8px; }
.mv-row .measure-input { flex: 1; min-width: 0; }
.mv-row .measure-input input { padding: 10px 12px; border: 1px solid var(--accent); border-radius: 9px 0 0 9px; background: var(--surface); color: var(--text); font-size: 20px; font-weight: 600; width: 100%; }
.mv-row .unit-btn { border-radius: 0 9px 9px 0; }
.mv-row .btn { padding: 8px 14px; }
.mv-row .btn:disabled { opacity: .4; }
#mv-list .measure-table div.empty strong { color: var(--muted); font-weight: 500; }
.m-empty { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
@media (max-width: 760px) {
  .mv-body { grid-template-columns: 1fr; grid-template-rows: auto auto; height: auto; padding: 12px; }
  .mv-body .bv-side { order: -1; position: sticky; top: 0; z-index: 2; background: var(--surface); padding-bottom: 8px; overflow: visible; }
  .mv-body #mv-list { display: none; }
  .mv-body .bv-figure svg.body-fig { width: 100%; height: auto; min-height: 0; max-height: none; }
}

/* ---------- print ---------- */
#print-area { display: none; }
@media print {
  body { background: #fff; color: #000; }
  body > *:not(#print-area) { display: none !important; }
  #print-area { display: block; font-size: 13px; color: #000; }
  #print-area h1 { font-size: 20px; margin: 0; }
  #print-area .p-head { display: flex; justify-content: space-between; border-bottom: 2px solid #000; padding-bottom: 8px; margin-bottom: 12px; }
  #print-area table { width: 100%; border-collapse: collapse; margin: 8px 0 14px; }
  #print-area td, #print-area th { border: 1px solid #999; padding: 5px 8px; text-align: left; }
  #print-area h4 { margin: 14px 0 4px; }
}

/* ---------- sync badge ---------- */
.sync { font-size: 12px; font-weight: 500; color: var(--muted); padding: 2px 8px; border-radius: 999px; background: var(--surface-2); white-space: nowrap; }
.sync:empty { display: none; }
.sync.warn { color: var(--warn); background: var(--warn-soft); }
.sync.bad { color: var(--danger); background: var(--danger-soft); }
.bad-text { color: var(--danger); }
