@font-face { font-family: "BoonBaan"; src: url("/fonts/BoonBaan-Regular.ttf") format("truetype"); font-weight: 400; font-display: swap; }
@font-face { font-family: "BoonBaan"; src: url("/fonts/BoonBaan-Bold.ttf") format("truetype"); font-weight: 700; font-display: swap; }

:root {
  --ink: #13284f;
  --blue: #1f56b3;
  --blue-deep: #0f3a80;
  --flame: #f28c18;
  --flame-deep: #d97706;
  --paper: #f2f4f8;
  --card: #ffffff;
  --line: #d8deea;
  --muted: #5b6885;
  --bed: #0e2a57;
  --ok: #1d8a57;
  --danger: #c0392b;
  --radius-s: 6px;
  --radius-m: 10px;
  --font: "BoonBaan", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { font-family: var(--font); color: var(--ink); background: var(--paper); font-size: 15px; line-height: 1.55; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid color-mix(in srgb, var(--flame) 70%, transparent); outline-offset: 2px; }

/* ---------- top bar ---------- */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 24px; padding: 0 24px; height: 60px; background: var(--blue-deep); color: #fff; }
.brand { display: flex; align-items: center; gap: 12px; text-decoration: none; color: #fff; font-weight: 700; white-space: nowrap; }
.brand img { height: 34px; border-radius: 6px; }
.brand span { font-size: 15px; opacity: .9; }
.tabs { display: flex; gap: 4px; height: 100%; }
.tabs a { display: flex; align-items: center; padding: 0 16px; color: rgba(255,255,255,.75); text-decoration: none; border-bottom: 3px solid transparent; font-weight: 700; }
.tabs a:hover { color: #fff; }
.tabs a.active { color: #fff; border-bottom-color: var(--flame); }
.userbox { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.userbox .who { font-size: 14px; opacity: .85; }

/* ---------- buttons & inputs ---------- */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 40px; padding: 0 16px; border-radius: var(--radius-s); border: 1px solid var(--line); background: var(--card); color: var(--ink); font-weight: 700; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { border-color: var(--blue); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.primary { background: var(--blue); border-color: var(--blue); color: #fff; }
.btn.primary:hover { background: var(--blue-deep); }
.btn.print { background: var(--flame); border-color: var(--flame); color: #fff; }
.btn.print:hover { background: var(--flame-deep); border-color: var(--flame-deep); }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: rgba(31,86,179,.08); }
.btn.danger { color: var(--danger); }
.btn.danger:hover { border-color: var(--danger); }
.topbar .btn.ghost { color: #fff; }
.topbar .btn.ghost:hover { background: rgba(255,255,255,.12); }
.btn.small { min-height: 32px; padding: 0 10px; font-size: 14px; }
.btn svg { width: 18px; height: 18px; }

label.field { display: grid; gap: 4px; }
.field > span { font-size: 13px; font-weight: 700; color: var(--muted); }
.field small { color: var(--muted); font-size: 12.5px; }
input[type=text], input[type=password], input[type=search], input[type=email], input[type=url], select, textarea {
  width: 100%; min-height: 40px; padding: 8px 12px; border: 1px solid var(--line); border-radius: var(--radius-s); background: #fff;
}
textarea { resize: vertical; min-height: 64px; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--blue); box-shadow: 0 0 0 3px rgba(31,86,179,.15); }
input[type=range] { width: 100%; accent-color: var(--blue); }
.check { display: inline-flex; align-items: center; gap: 8px; cursor: pointer; font-weight: 700; }
.check input { width: 18px; height: 18px; accent-color: var(--blue); }

/* ---------- list view ---------- */
.page { max-width: 1200px; margin: 0 auto; padding: 28px 24px 64px; }
.page-head { display: flex; align-items: flex-end; gap: 16px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head h1 { margin: 0; font-size: 28px; line-height: 1.2; }
.page-head .count { color: var(--muted); font-size: 15px; margin-left: 4px; }
.page-head .actions { margin-left: auto; display: flex; gap: 8px; flex-wrap: wrap; }
.toolbar { display: flex; gap: 12px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.toolbar input[type=search] { max-width: 340px; }
.toolbar .sel-info { color: var(--muted); font-size: 14px; }

.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-m); overflow: hidden; }
.row { display: grid; grid-template-columns: 40px 52px minmax(0, 2.2fr) minmax(0, 1.6fr) minmax(0, 1fr) 110px; gap: 12px; align-items: center; padding: 10px 16px; border-top: 1px solid var(--line); cursor: pointer; }
.row:first-child { border-top: 0; }
.row:hover { background: #f7f9fc; }
.row.head { cursor: default; background: #f7f9fc; font-size: 13px; font-weight: 700; color: var(--muted); padding-top: 8px; padding-bottom: 8px; }
.row .thumb { width: 44px; height: 46px; border-radius: 8px 8px 0 0; background: #e6ecf5 center/cover no-repeat; border-bottom: 3px solid var(--flame); }
.biz .row .thumb { border-radius: 4px; width: 52px; height: 32px; border-bottom: 0; border-left: 6px solid var(--blue); background: #fff; box-shadow: inset 0 0 0 1px var(--line); }
.row .name { font-weight: 700; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .sub { color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .code { font-variant-numeric: tabular-nums; }
.tag { display: inline-block; padding: 1px 8px; border-radius: 999px; font-size: 12.5px; font-weight: 700; background: #e8eefb; color: var(--blue); }
.tag.off { background: #f5e6e4; color: var(--danger); }
.tag.qr { background: #fff1e0; color: var(--flame-deep); }
.empty { padding: 56px 24px; text-align: center; }
.empty h2 { margin: 0 0 6px; font-size: 20px; }
.empty p { margin: 0 0 18px; color: var(--muted); }

/* ---------- editor ---------- */
.editor { display: grid; grid-template-columns: minmax(340px, 440px) 1fr; height: calc(100vh - 60px); }
.editor .form-pane { overflow: hidden; }
.editor .bed { overflow: auto; }
.form-pane { background: var(--card); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-width: 0; }
.form-head { display: flex; align-items: center; gap: 8px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.form-head h1 { font-size: 19px; margin: 0; }
.form-body { padding: 8px 20px 24px; overflow-y: auto; flex: 1; }
.form-foot { position: sticky; bottom: 0; display: flex; gap: 8px; flex-wrap: wrap; padding: 14px 20px; border-top: 1px solid var(--line); background: var(--card); }
.form-foot .spacer { flex: 1; }
fieldset { border: 0; border-top: 1px solid var(--line); margin: 0; padding: 18px 0 6px; display: grid; gap: 14px; }
fieldset:first-of-type { border-top: 0; }
legend { font-weight: 700; font-size: 16px; padding: 0; margin-bottom: 2px; float: left; width: 100%; }
legend + * { clear: both; }
.two { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.photo-row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.hint { font-size: 13px; color: var(--muted); margin: 0; }
.contact-row, .qr-slot { display: grid; grid-template-columns: 130px 1fr 36px; gap: 8px; align-items: center; }
.qr-slot { grid-template-columns: 1fr; padding: 12px; border: 1px dashed var(--line); border-radius: var(--radius-s); gap: 10px; }
.qr-slot .slot-head { display: flex; align-items: center; justify-content: space-between; font-weight: 700; }
.icon-btn { width: 36px; height: 36px; border-radius: var(--radius-s); border: 1px solid var(--line); background: #fff; cursor: pointer; display: grid; place-items: center; color: var(--muted); }
.icon-btn:hover { color: var(--danger); border-color: var(--danger); }
.qr-thumb { width: 72px; height: 72px; border: 1px solid var(--line); border-radius: 4px; object-fit: contain; background: #fff; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: var(--radius-s); overflow: hidden; }
.seg button { border: 0; background: #fff; padding: 8px 14px; cursor: pointer; font-weight: 700; color: var(--muted); }
.seg button.on { background: var(--blue); color: #fff; }

/* print bed: the card sits on a cutting mat at true proportions */
.bed {
  position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 40px; padding: 48px 32px 56px;
  background-color: var(--bed);
  background-image:
    linear-gradient(rgba(255,255,255,.07) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.07) 1px, transparent 1px),
    linear-gradient(rgba(255,255,255,.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255,255,255,.03) 1px, transparent 1px);
  background-size: 50px 50px, 50px 50px, 10px 10px, 10px 10px;
  color: #dbe5f7; min-width: 0;
}
.bed .sheet { position: relative; }
.bed canvas { display: block; box-shadow: 0 18px 40px rgba(0,0,0,.45), 0 2px 6px rgba(0,0,0,.3); border-radius: 3px; touch-action: none; }
.bed canvas.draggable { cursor: grab; }
.bed canvas.dragging { cursor: grabbing; }
.dim { position: absolute; font-size: 12.5px; color: #b9c9e6; display: flex; align-items: center; gap: 6px; white-space: nowrap; }
.dim.w { left: 0; right: 0; top: -26px; justify-content: center; }
.dim.w::before, .dim.w::after { content: ""; flex: 1; height: 1px; background: rgba(185,201,230,.5); }
.dim.h { top: 0; bottom: 0; right: -30px; writing-mode: vertical-rl; justify-content: center; }
.dim.h::before, .dim.h::after { content: ""; flex: 1; width: 1px; background: rgba(185,201,230,.5); }
.bed .side-label { position: absolute; left: 0; bottom: -26px; font-size: 13px; color: #b9c9e6; }
.bed .photo-tools { display: flex; align-items: center; gap: 12px; width: min(380px, 100%); background: rgba(255,255,255,.06); border: 1px solid rgba(255,255,255,.12); border-radius: var(--radius-m); padding: 10px 14px; font-size: 14px; }
.bed .photo-tools input { flex: 1; }
.bed .photo-tools .btn { min-height: 32px; background: transparent; color: #fff; border-color: rgba(255,255,255,.3); }

/* ---------- modal / toast ---------- */
dialog { border: 0; border-radius: var(--radius-m); padding: 0; width: min(520px, calc(100vw - 32px)); color: var(--ink); box-shadow: 0 30px 80px rgba(9,24,52,.35); }
dialog::backdrop { background: rgba(9,24,52,.55); }
.modal-head { padding: 20px 24px 0; }
.modal-head h2 { margin: 0; font-size: 20px; }
.modal-body { padding: 16px 24px; display: grid; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 0 24px 20px; }
.choice { display: grid; grid-template-columns: 20px 1fr; gap: 10px; padding: 12px 14px; border: 1px solid var(--line); border-radius: var(--radius-s); cursor: pointer; }
.choice:has(input:checked) { border-color: var(--blue); background: #f3f7ff; }
.choice input { margin-top: 4px; accent-color: var(--blue); }
.choice b { display: block; }
.choice span { color: var(--muted); font-size: 13.5px; }
.progress { height: 8px; border-radius: 99px; background: var(--line); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0; background: var(--flame); transition: width .2s; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 18px; border-radius: var(--radius-s); box-shadow: 0 10px 30px rgba(0,0,0,.25); z-index: 100; max-width: calc(100vw - 32px); }
.toast.error { background: var(--danger); }

/* ---------- users ---------- */
.users .row { grid-template-columns: minmax(0, 1.4fr) minmax(0, 1.4fr) 110px 110px minmax(0, 1fr) 150px; cursor: default; }
.users .row .acts { display: flex; gap: 6px; justify-content: flex-end; }

/* ---------- login / verify ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.auth-art { background: #1a4ea6 url("/img/logo-on-blue.jpg") center 38% / min(80%, 460px) no-repeat; background-color: #1d4fa5; position: relative; }
.auth-art p { position: absolute; left: 48px; right: 48px; bottom: 48px; margin: 0; color: #d7e3fa; font-size: 17px; max-width: 34ch; }
.auth-form { display: flex; align-items: center; justify-content: center; padding: 32px; background: #fff; }
.auth-form form { width: min(360px, 100%); display: grid; gap: 16px; }
.auth-form h1 { margin: 0; font-size: 26px; }
.auth-form .lead { margin: -8px 0 4px; color: var(--muted); }
.auth-form .error { color: var(--danger); font-size: 14px; min-height: 1.4em; margin: 0; }
.auth-form .btn { width: 100%; min-height: 46px; }

@media (max-width: 960px) {
  .editor { grid-template-columns: 1fr; }
  .form-pane { border-right: 0; order: 2; }
  .bed { order: 1; padding: 40px 16px 48px; min-height: 70vh; }
  .editor { height: auto; }
  .editor .form-pane, .editor .bed { overflow: visible; }
  .row { grid-template-columns: 32px 46px minmax(0, 1fr) 90px; }
  .row > :nth-child(4), .row > :nth-child(5) { display: none; }
  .users .row { grid-template-columns: 1fr 1fr 120px; }
  .users .row > :nth-child(3), .users .row > :nth-child(5) { display: none; }
  .auth { grid-template-columns: 1fr; }
  .auth-art { min-height: 200px; background-size: min(70%, 320px); }
  .auth-art p { display: none; }
}
@media (max-width: 640px) {
  .topbar { flex-wrap: wrap; height: auto; gap: 0 8px; padding: 8px 12px 0; }
  .brand span, .userbox .who, #btn-password { display: none; }
  .tabs { order: 3; width: 100%; height: 44px; margin-top: 6px; }
  .tabs a { padding: 0 12px; font-size: 14px; white-space: nowrap; }
  .editor { min-height: auto; }
  .page { padding: 20px 14px 48px; }
  .two { grid-template-columns: 1fr; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
