/* ============ app interface (screens only; documents are styled further down) ============ */
  :root {
    --bg: #f3f5fb; --card: #fff; --ink: #1e2340; --muted: #6b7394; --line: #e3e7f2;
    --brand: #4f46e5; --brand-2: #0ea5e9; --brand-soft: #eef0ff; --brand-ink: #3730a3;
    --grad: linear-gradient(120deg, #4338ca 0%, #4f46e5 40%, #0ea5e9 100%);
    --ok: #059669; --ok-soft: #d1fae5; --warn: #b45309; --warn-soft: #fef3c7; --bad: #e11d48; --bad-soft: #ffe4e6;
    --radius: 14px; --shadow: 0 1px 2px rgba(30,35,90,.05), 0 8px 24px rgba(30,35,90,.07);
    --ui-font: "Noto Sans Thai", "Sarabun", "Thonburi", "Tahoma", system-ui, sans-serif;
    --head-font: "Kanit", "Noto Sans Thai", "Thonburi", "Tahoma", sans-serif;
    --doc-font: "SMO Sarabun", "TH SarabunPSK", "TH Sarabun New", sans-serif;
  }
  * { box-sizing: border-box; }
  body { margin: 0; color: var(--ink); font: 15px/1.55 var(--ui-font);
    background: radial-gradient(1100px 420px at 5% -10%, #e0e7ff 0%, transparent 60%),
                radial-gradient(900px 420px at 105% -5%, #e0f2fe 0%, transparent 55%), var(--bg);
    background-attachment: fixed; }
  button, select, input, textarea { font: inherit; color: inherit; }
  svg.i { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }

  /* header */
  header.topbar { background: var(--grad); color: #fff; padding: 12px 22px; display: flex; flex-wrap: wrap; align-items: center; gap: 12px 18px;
    box-shadow: 0 6px 24px rgba(67,56,202,.25); position: relative; overflow: hidden; }
  header.topbar::after { content: ""; position: absolute; right: -80px; top: -120px; width: 320px; height: 320px; border-radius: 50%;
    background: radial-gradient(circle, rgba(255,255,255,.18), transparent 70%); pointer-events: none; }
  .brand { display: flex; align-items: center; gap: 12px; }
  .logos { display: flex; gap: 6px; }
  .logos img, .logos .logo-default { height: 48px; width: auto; max-width: 96px; object-fit: contain; background: #fff; border-radius: 12px; padding: 4px;
    box-shadow: 0 4px 12px rgba(15,23,42,.18); }
  .logos .logo-default { width: 48px; padding: 0; }
  header h1 { margin: 0; font: 600 20px/1.2 var(--head-font); letter-spacing: .2px; }
  #hdr-sub { font-size: 13px; opacity: .9; display: block; margin-top: 2px; }
  header .spacer { flex: 1; }
  .ctxbar { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
  .ctxbar .pill { display: inline-flex; align-items: center; gap: 6px; background: rgba(255,255,255,.16); border: 1px solid rgba(255,255,255,.32);
    border-radius: 999px; padding: 3px 6px 3px 12px; font-size: 13px; }
  .ctxbar select { background: transparent; border: none; color: #fff; padding: 4px 2px; font-weight: 500; cursor: pointer; }
  .ctxbar select:focus { outline: none; }
  .ctxbar select option { color: #111; }
  .user { display: flex; align-items: center; gap: 8px; min-width: 0; max-width: 100%; }
  .user .me { display: flex; align-items: center; gap: 10px; min-width: 0; margin-right: 2px; cursor: pointer; }
  .avatar { flex: none; width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font: 600 17px var(--head-font);
    background: rgba(255,255,255,.22); border: 2px solid rgba(255,255,255,.55); overflow: hidden; }
  .avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
  /* the profile / logout buttons carry their names in words (easier than bare icons) */
  .hbtn { flex: none; display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px 0 11px; border-radius: 999px;
    background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.4); color: #fff; font-size: 13.5px; font-weight: 500; white-space: nowrap; }
  .hbtn:hover { background: rgba(255,255,255,.3); border-color: rgba(255,255,255,.6); }
  .hbtn svg.i { width: 16px; height: 16px; }
  /* photos elsewhere: the users table and the ข้อมูลส่วนตัว dialog */
  .uname { display: inline-flex; align-items: center; gap: 8px; }
  .avatar.sm { width: 28px; height: 28px; border-width: 1px; font-size: 13px; background: var(--brand-soft); border-color: #dfe3f7; color: var(--brand-ink); }
  .avatar.xl { width: 96px; height: 96px; border-width: 3px; font-size: 38px; background: var(--brand-soft); border-color: #dfe3f7; color: var(--brand-ink); }
  .prof-top { display: flex; align-items: center; gap: 18px; margin-bottom: 16px; }
  .prof-top .hint { margin: 8px 0 0; }
  .prof-btns { display: flex; flex-wrap: wrap; gap: 8px; }
  .prof-btns svg.i { width: 15px; height: 15px; vertical-align: -2px; }
  .prof-h { margin: 18px 0 10px; padding-top: 14px; border-top: 1px solid var(--line); font: 600 15px var(--head-font); }
  .prof-h .hint { font: 400 13px var(--ui-font); }
  .who { line-height: 1.25; min-width: 0; }
  .who b { display: block; font-size: 14px; }
  .who span { font-size: 12px; opacity: .85; }
  .who b, .who span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .icon-btn { width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; padding: 0; cursor: pointer;
    background: rgba(255,255,255,.15); border: 1px solid rgba(255,255,255,.32); color: #fff; transition: .15s; }
  .icon-btn:hover { background: rgba(255,255,255,.3); }
  .badge { display: inline-block; font-size: 12px; border-radius: 99px; padding: 1px 9px; background: #fde68a; color: #78350f; font-weight: 500; }

  /* menu: left sidebar; a slide-out drawer on narrow screens */
  #app { min-height: 100vh; display: flex; flex-direction: column; }
  .shell { flex: 1; display: flex; }
  nav#tabs { flex: none; width: 252px; background: rgba(255,255,255,.8); backdrop-filter: blur(8px); border-right: 1px solid var(--line); transition: width .2s ease; }
  /* compact, so the longest menu (the admin's 17 items) fits a 1366×768 screen without scrolling */
  nav .side-inner { position: sticky; top: 0; max-height: 100vh; overflow-y: auto; padding: 8px 10px; display: flex; flex-direction: column; gap: 1px; }
  .nav-group { font-size: 11.5px; font-weight: 600; color: #9097b8; letter-spacing: .3px; padding: 9px 12px 3px; }
  .nav-group:first-child { padding-top: 2px; }
  nav button { display: flex; align-items: center; gap: 10px; width: 100%; text-align: left; border: none; background: transparent; padding: 6px 12px;
    border-radius: 10px; color: #474e72; font-size: 14px; line-height: 1.3; font-weight: 500; white-space: nowrap; cursor: pointer; transition: .15s; }
  nav button svg.i { width: 17px; height: 17px; }
  nav button svg.i { color: #7c83b3; transition: .15s; }
  nav button:hover { background: var(--brand-soft); color: var(--brand-ink); }
  nav button:hover svg.i { color: var(--brand); }
  nav button.on { background: var(--grad); color: #fff; box-shadow: 0 4px 14px rgba(79,70,229,.32); }
  nav button.on svg.i { color: #fff; }
  .side-foot { margin-top: auto; padding: 22px 12px 0; font-size: 12px; line-height: 1.5; color: #a1a7c4; }
  @media (max-height: 860px) { .side-foot { display: none; } }   /* short screens: room for the menu instead */
  @media (min-width: 901px) and (max-height: 780px) {             /* shorter windows (browser bars, taskbar): tighter still */
    nav .side-inner { padding: 6px 10px; }
    .nav-group { padding: 6px 12px 2px; }
    nav button { padding: 4px 12px; }
  }
  @media (min-width: 901px) and (max-height: 680px) {
    .nav-group { padding: 4px 12px 1px; font-size: 11px; }
    nav button { padding: 3px 12px; font-size: 13px; line-height: 1.25; }
    nav button svg.i { width: 16px; height: 16px; }
  }
  .content { flex: 1; min-width: 0; display: flex; flex-direction: column; }
  main { flex: 1; min-width: 0; padding: 20px 24px 40px; }
  footer.credit { padding: 14px 24px 18px; border-top: 1px solid var(--line); text-align: center; font-size: 13px; color: var(--muted); }
  footer.credit b, .login-credit b { font-weight: 600; }
  footer.credit b { color: var(--brand-ink); }
  .nav-scrim { display: none; }
  @media (min-width: 901px) {   /* icon strip */
    body.nav-mini nav#tabs { width: 70px; }
    body.nav-mini nav .side-inner { padding: 14px 10px 20px; overflow-x: hidden; }
    body.nav-mini nav button { justify-content: center; padding: 7px 0; }
    body.nav-mini nav button span, body.nav-mini .side-foot { display: none; }
    body.nav-mini .nav-group { font-size: 0; padding: 5px 6px; }
    body.nav-mini .nav-group::before { content: ""; display: block; height: 1px; background: var(--line); }
    body.nav-mini .nav-group:first-child { display: none; }
  }
  /* wider than a phone: the user and the password / logout buttons always stay on the first row at the right. The system
     name and the term picker stay whole; the line under the name and the user's name shorten (…) first. Between 901
     and 1099 px the term picker moves to a row of its own. */
  @media (min-width: 901px) {
    header.topbar { flex-wrap: nowrap; }
    header.topbar .menu-btn, .logos { flex: none; }
    .brand { flex: 0 4 auto; min-width: var(--brand-min, 0); }   /* --brand-min / --ctx-min: set by fitHeader(); the line under the name shortens before the user's name */
    .brand > div:last-child { min-width: 0; }
    header h1 { white-space: nowrap; }
    #hdr-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
    .ctxbar { flex: 0 3 auto; flex-wrap: nowrap; min-width: var(--ctx-min, 0); }
    .ctxbar .pill { flex: none; }
    header .spacer { min-width: 0; }
    .user { flex: 0 1 auto; min-width: var(--user-min, 360px); }   /* photo + at least 70 px of name + both buttons (fitHeader) */
    .who { min-width: 70px; max-width: 220px; }
  }
  @media (min-width: 901px) and (max-width: 1099px) {
    header.topbar { flex-wrap: wrap; row-gap: 10px; }
    .ctxbar { order: 10; flex: 1 1 100%; }
    /* the row breaks by the parts' smallest widths, so the user stays beside the name; the user part then grows to its
       full width first and the name part takes the rest */
    .brand { flex: 1 1 0; }
    header .spacer { display: none; }
    .user { flex: 1 1 var(--user-min, 360px); max-width: max-content; }
  }
  .nav-tip { position: fixed; z-index: 70; left: 0; top: 0; transform: translate(-4px, -50%); opacity: 0; pointer-events: none;
    background: #1e1b4b; color: #fff; font-size: 13.5px; font-weight: 500; white-space: nowrap; padding: 6px 12px; border-radius: 9px;
    box-shadow: 0 8px 24px rgba(30,27,75,.3); transition: opacity .12s, transform .12s; }
  .nav-tip::before { content: ""; position: absolute; left: -5px; top: 50%; margin-top: -5px;
    border-style: solid; border-width: 5px 5px 5px 0; border-color: transparent #1e1b4b transparent transparent; }
  .nav-tip.on { opacity: 1; transform: translate(0, -50%); }
  @media (max-width: 900px) {
    header .brand { flex: 1 1 0; min-width: 0; }   /* stay on the ☰ row */
    .ctxbar { flex: 1 1 100%; }                     /* the pickers get their own row, never squeezing the name */
    nav#tabs { position: fixed; z-index: 60; left: 0; top: 0; bottom: 0; width: 270px; max-width: 86vw; background: #fff; backdrop-filter: none;
      transform: translateX(-104%); transition: transform .25s ease; box-shadow: 0 0 40px rgba(15,23,42,.25); }
    nav .side-inner { max-height: none; height: 100%; padding-top: 18px; }
    body.nav-open nav#tabs { transform: none; }
    body.nav-open .nav-scrim { display: block; position: fixed; inset: 0; z-index: 55; background: rgba(15,23,42,.38); }
  }
  main > section { display: none; animation: fade .2s ease; }
  main > section.on { display: block; }
  @keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

  /* building blocks */
  .panel { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; box-shadow: var(--shadow); }
  .panel h3 { margin: 0 0 12px; font: 600 17px var(--head-font); display: flex; align-items: center; gap: 8px; }
  .panel h3::before { content: ""; width: 4px; height: 18px; border-radius: 4px; background: var(--grad); }
  .hint { color: var(--muted); font-size: 13px; }
  .count { background: var(--brand-soft); color: var(--brand-ink); border-radius: 99px; padding: 0 9px; font: 500 13px var(--ui-font); }
  button { cursor: pointer; border: 1px solid var(--line); background: #fff; border-radius: 10px; padding: 6px 14px; transition: .15s; }
  button:hover { border-color: #c7cdf0; background: #f7f8ff; }
  button.primary { background: var(--grad); color: #fff; border-color: transparent; box-shadow: 0 4px 12px rgba(79,70,229,.28); }
  button.primary:hover { filter: brightness(1.06); transform: translateY(-1px); }
  button.danger { color: var(--bad); border-color: #fecdd3; }
  button.danger:hover { background: #fff1f2; }
  button.small { padding: 3px 11px; font-size: 13px; border-radius: 8px; }
  button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
  :where(input:not([type=checkbox]):not([type=radio]):not([type=file])), select, textarea {   /* :where = low priority, specific rules win */
    padding: 7px 11px; border: 1px solid var(--line); border-radius: 10px; background: #fff; transition: border-color .15s, box-shadow .15s; }
  input:focus, select:focus, textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(79,70,229,.15); }
  input[readonly] { background: #f7f8fc; }
  .toolbar { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
  .tag { display: inline-block; white-space: nowrap; font-size: 12px; border-radius: 99px; padding: 1px 9px; background: var(--ok-soft); color: var(--ok); margin-left: 4px; font-weight: 500; }
  .tag.warn { background: var(--warn-soft); color: var(--warn); }
  .tag.bad { background: var(--bad-soft); color: var(--bad); }
  .tag.own { background: var(--brand-soft); color: var(--brand-ink); }
  .locked { display: inline-flex; align-items: center; gap: 5px; font-size: 13px; color: var(--muted); }
  .locked svg.i { width: 15px; height: 15px; }
  .note { border-radius: 10px; padding: 9px 14px; font-size: 14px; margin-top: 8px; border-left: 4px solid; }
  .note.warn { background: var(--warn-soft); color: #92400e; border-color: #f59e0b; }
  .note.info { background: #eef2ff; color: var(--brand-ink); border-color: var(--brand); }
  .readonly-note { background: var(--warn-soft); color: #92400e; border-left: 4px solid #f59e0b; border-radius: 10px; padding: 9px 14px; margin-bottom: 14px; font-size: 14px; }
  .wrap { overflow-x: auto; }
  .panel.wrap { padding: 0; overflow: hidden; }
  table.list { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 14px; background: #fff; }
  table.list th { background: #f5f7ff; color: #3f4478; font-weight: 600; text-align: left; padding: 9px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; position: sticky; top: 0; }
  table.list td { padding: 7px 10px; border-bottom: 1px solid #eef1f8; vertical-align: top; }
  table.list tr:hover td { background: #fafbff; }
  table.list tr.picked td { background: #ecfdf5; }
  table.list tr.off td { color: var(--muted); }
  table.list td.n { text-align: right; white-space: nowrap; }
  table.list .sub { color: var(--muted); font-size: 12.5px; }
  table.list td input, table.list td select { width: 100%; padding: 5px 8px; }
  .cols { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(340px, 100%), 1fr)); gap: 18px; align-items: start; }
  .cols > *, .layout > * { min-width: 0; }   /* let wide tables scroll inside their card instead of widening the page */
  .form { display: grid; grid-template-columns: 170px 1fr; gap: 9px 12px; align-items: center; }
  .form label { color: var(--muted); font-size: 14px; }
  .form label small { font-size: 13px; color: #4b5275; line-height: 1.3; }
  #tab-settings .cols { grid-template-columns: repeat(auto-fit, minmax(min(460px, 100%), 1fr)); }   /* room for names */
  .cols > .span-all { grid-column: 1 / -1; }
  @media (min-width: 1100px) { #tab-people > .cols { grid-template-columns: minmax(0, 3fr) minmax(0, 2fr); } }
  table.whead td, table.teachers td { vertical-align: middle; }
  table.whead td:first-child { width: 52%; }
  td.head-cell { font-size: 14px; }
  /* position of a teacher: department head tick, the works they head (chips), and a picker to add one */
  .pos { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
  .pos-chk { display: inline-flex; align-items: center; gap: 5px; white-space: nowrap; font-size: 14px; cursor: pointer; }
  .pos-chip { display: inline-flex; align-items: center; gap: 4px; background: var(--brand-soft); color: var(--brand-ink); border-radius: 99px;
    padding: 2px 4px 2px 10px; font-size: 13px; font-weight: 500; }
  .pos-chip button { border: none; background: transparent; padding: 0 5px; border-radius: 99px; color: inherit; font-size: 12px; line-height: 1.4; }
  .pos-chip button:hover { background: rgba(79,70,229,.15); }
  table.list .pos select { width: auto; max-width: 260px; padding: 3px 8px; font-size: 13px; color: var(--muted); }
  table.list .pos input[type=checkbox] { width: auto; padding: 0; }
  .form input { width: 100%; }
  table.data { width: 100%; border-collapse: collapse; }
  table.data td { padding: 3px; }
  table.data input, table.data select { width: 100%; }
  .addrow { display: flex; gap: 8px; margin-top: 10px; }
  .addrow input { flex: 1; min-width: 0; }
  .addrow input.abbr { flex: 0 0 110px; }

  /* overview */
  .kpi { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; margin-bottom: 18px; }
  .kpi > div { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; box-shadow: var(--shadow);
    display: flex; align-items: center; gap: 14px; }
  .kpi .ki { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; color: #fff; flex: none; }
  .kpi .ki svg.i { width: 22px; height: 22px; }
  .kpi .k1 { background: linear-gradient(135deg, #6366f1, #8b5cf6); } .kpi .k2 { background: linear-gradient(135deg, #0ea5e9, #22d3ee); }
  .kpi .k3 { background: linear-gradient(135deg, #10b981, #34d399); } .kpi .k4 { background: linear-gradient(135deg, #f59e0b, #f97316); }
  .kpi b { display: block; font: 600 24px/1.1 var(--head-font); }
  .kpi span { color: var(--muted); font-size: 13px; }

  /* งานวิทยบริการฯ pages: department picker, document heading, "รายการหนังสือที่แผนกเลือก" */
  .deptpick { display: inline-flex; align-items: center; gap: 6px; background: #fff; border: 1px solid #d5daf0; border-radius: 999px;
    padding: 2px 6px 2px 12px; color: var(--brand-ink); box-shadow: var(--shadow); max-width: 100%; }
  .deptpick select { border: none; background: transparent; box-shadow: none; padding: 6px 4px; font-weight: 600; color: var(--ink); min-width: 0; max-width: 100%; cursor: pointer; }
  .deptpick select:focus { box-shadow: none; }
  .doc-head { margin-bottom: 10px; }
  .doc-head h2 { margin: 0 6px 0 0; font: 600 20px/1.3 var(--head-font); }
  .grow { flex: 1; }
  .ch-stats { display: inline-flex; flex-wrap: wrap; gap: 6px; }
  .ch-stats > span { background: #fff; border: 1px solid var(--line); border-radius: 99px; padding: 4px 12px; font-size: 13.5px; color: var(--muted); }
  .ch-stats b { color: var(--ink); }
  table.chosen .ch-g td { background: #f1f3ff; border-top: 1px solid var(--line); padding: 9px 10px; }
  table.chosen .ch-g .sub { margin-left: 8px; }
  table.chosen .ch-sub { min-width: 150px; }
  table.chosen .ch-sub .code { font-family: ui-monospace, Menlo, monospace; font-size: 13px; color: var(--brand-ink); }
  table.chosen .ch-books { min-width: 240px; }
  table.chosen .ch-books ol { margin: 0; padding-left: 20px; }
  table.chosen .ch-books li { margin-bottom: 4px; color: var(--muted); }
  table.chosen .ch-books li.first { color: var(--ink); }
  table.chosen .ch-books li b { font-weight: 500; }
  table.chosen .sub { font-size: 12.5px; color: var(--muted); }
  table.chosen .nw { white-space: nowrap; }
  table.chosen td.n, table.chosen th.n { text-align: right; white-space: nowrap; }
  table.chosen .tag { margin: 0 0 2px; }

  /* สอศ. catalog: one header row per subject, its books below */
  .cat-panel { padding: 0; overflow-x: auto; container-type: inline-size; }
  table.cat th { padding: 10px 14px; }
  table.cat th.n { text-align: right; }
  table.cat td { padding: 9px 14px; vertical-align: top; }
  table.cat tr.cat-g td { background: #f5f7ff; border-top: 1px solid var(--line); border-bottom: 1px solid #e6e9f5; padding: 10px 14px; }
  table.cat tbody tr.cat-g:first-child td { border-top: none; }
  table.cat tr.cat-g:hover td { background: #f5f7ff; }
  .cat-gh { display: flex; flex-wrap: wrap; align-items: center; gap: 6px 10px; }
  .cat-gh .code { font: 600 13px var(--head-font); letter-spacing: .3px; color: #fff; background: var(--brand); border-radius: 7px; padding: 2px 9px; }
  .cat-gh b { font-size: 15px; }
  .cat-gh .grow { flex: 1; }
  .cat-gh .tag { display: inline-flex; align-items: center; gap: 4px; }
  .cat-gh .tag svg.i { width: 13px; height: 13px; stroke-width: 2.8; }
  table.cat tr.cat-b td:first-child { position: relative; padding-left: 32px; min-width: 200px; }
  table.cat tr.cat-b td:first-child::before { content: ""; position: absolute; left: 18px; top: 0; bottom: 0; width: 2px; background: #dfe3f3; }
  table.cat td.n { white-space: nowrap; color: var(--muted); }
  table.cat td.n b { font: 600 15px var(--head-font); color: var(--ink); }
  table.cat td.cat-act { width: 1%; text-align: right; white-space: nowrap; }
  table.cat .nw { white-space: nowrap; }
  @container (max-width: 760px) {   /* narrow: each book becomes a small card */
    table.cat thead { display: none; }
    table.cat, table.cat tbody, table.cat tr.cat-g, table.cat tr.cat-g td { display: block; }
    table.cat tr.cat-b { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 14px; position: relative; padding: 10px 14px 12px 32px; border-bottom: 1px solid #eef1f8; }
    table.cat tr.cat-b::before { content: ""; position: absolute; left: 18px; top: 0; bottom: 0; width: 2px; background: #dfe3f3; }
    table.cat tr.cat-b td { display: block; padding: 0; border: none; background: none !important; }
    table.cat tr.cat-b td:first-child { grid-column: 1 / -1; padding-left: 0; min-width: 0; font-weight: 500; }
    table.cat tr.cat-b td:first-child::before { display: none; }
    table.cat td[data-label]::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
    table.cat td.n { text-align: left; }
    table.cat td.cat-act { grid-column: 1 / -1; width: auto; text-align: left; }
  }

  /* overview */
  .ov-filter { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; margin-bottom: 12px; }
  .ov-chip { display: inline-flex; align-items: center; gap: 7px; border-radius: 999px; padding: 5px 8px 5px 14px; font-size: 14px; }
  .ov-chip b { min-width: 24px; text-align: center; border-radius: 99px; padding: 0 7px; font-size: 12.5px; background: var(--brand-soft); color: var(--brand-ink); }
  .ov-chip.doing b { background: var(--warn-soft); color: var(--warn); }
  .ov-chip.todo b { background: #eef1f6; color: #64748b; }
  .ov-chip.done b { background: var(--ok-soft); color: var(--ok); }
  .ov-chip.on { background: var(--ink); border-color: var(--ink); color: #fff; }
  .ov-legend { margin-left: auto; display: inline-flex; flex-wrap: wrap; align-items: center; gap: 4px 14px; }
  .ov-legend > span { white-space: nowrap; }
  .ov-legend .lg { width: 12px; height: 8px; border-radius: 4px; background: #e3e7f0; display: inline-block; margin-right: 5px; }
  .ov-legend .lg.ok { background: #10b981; } .ov-legend .lg.warn { background: #fbbf24; }
  .ov-panel { padding: 0; overflow-x: auto; container-type: inline-size; }
  table.ov th { padding: 11px 16px; }
  table.ov th.n { text-align: right; }
  table.ov td { padding: 14px 16px; vertical-align: middle; }
  table.ov td.n { font-size: 14px; color: var(--muted); }
  table.ov td.n b { font: 600 17px var(--head-font); color: var(--ink); margin-right: 2px; }
  table.ov td.n b.money { color: var(--brand-ink); }
  .ov-dept { display: flex; align-items: center; gap: 12px; min-width: 190px; }
  .ov-dept b { font-size: 15px; }
  .ov-av { width: 46px; height: 46px; padding: 0 3px; border-radius: 13px; flex: none; display: grid; place-items: center; color: #fff;
    font: 600 17px var(--head-font); white-space: nowrap; overflow: hidden; box-shadow: 0 4px 10px rgba(30,35,90,.15); }
  .ov-av.l3 { font-size: 14px; }
  .ov-av.l4 { font-size: 11.5px; }
  .ov-prog { min-width: 240px; }
  .ov-top { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin-bottom: 7px; }
  .ov-prog > .sub { margin-top: 6px; }
  .bar { height: 9px; border-radius: 99px; background: #e9edf5; overflow: hidden; display: flex; }
  .bar i { display: block; height: 100%; }
  .bar i.ok { background: linear-gradient(90deg, #10b981, #34d399); }
  .bar i.warn { background: #fbbf24; }
  .st { display: inline-flex; align-items: center; gap: 4px; border-radius: 99px; padding: 2px 11px; font-size: 13px; font-weight: 600; white-space: nowrap; }
  .st svg.i { width: 14px; height: 14px; stroke-width: 2.8; }
  .st.done { background: var(--ok-soft); color: var(--ok); }
  .st.doing { background: var(--warn-soft); color: var(--warn); }
  .st.todo { background: #eef1f6; color: #64748b; }
  .ov-act { text-align: right; white-space: nowrap; }
  .ov-act button { display: inline-flex; align-items: center; gap: 5px; }
  .ov-act svg.i { width: 15px; height: 15px; }
  table.ov tr.ov-total td { background: #f5f7ff; color: #3f4478; font-weight: 600; border-bottom: none; padding-top: 12px; padding-bottom: 12px; }
  table.ov tr.ov-total td.n { color: #3f4478; font-size: 15px; }
  @container (max-width: 820px) {   /* narrow: one card per department */
    table.ov thead { display: none; }
    table.ov, table.ov tbody { display: block; }
    table.ov tr { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px 14px; padding: 14px 16px; border-bottom: 1px solid var(--line); }
    table.ov td { display: block; padding: 0; border: none; background: none !important; }
    table.ov td:nth-child(1), table.ov td:nth-child(2), table.ov td.ov-act { grid-column: 1 / -1; }
    table.ov td.n { text-align: left; }
    table.ov td.n::before { content: attr(data-label); display: block; font-size: 12px; color: var(--muted); font-weight: 400; }
    table.ov td.ov-act { text-align: left; }
    table.ov td.ov-act:empty { display: none; }
    table.ov tr.ov-total { background: #f5f7ff; }
    .ov-dept, .ov-prog { min-width: 0; }
  }

  /* choosing books */
  .layout { display: grid; grid-template-columns: 340px 1fr; gap: 18px; align-items: start; }
  @media (max-width: 1100px) { .layout { grid-template-columns: 1fr; } }
  @media (max-width: 600px) { main { padding: 14px 12px 32px; } footer.credit { padding: 12px 14px 16px; } header.topbar { padding: 12px 14px; } .form { grid-template-columns: 1fr; } }
  @media (max-width: 600px) {   /* phones: photo and name on one row, the two buttons side by side under them */
    .user { flex: 1 1 100%; flex-wrap: wrap; row-gap: 10px; }
    .user .me { flex: 1 1 100%; }
    .hbtn { flex: 1 1 0; justify-content: center; min-width: 0; }
    .prof-top { gap: 14px; }
    .avatar.xl { width: 80px; height: 80px; font-size: 32px; }
  }
  .addsub { position: relative; margin-bottom: 12px; }
  .addsub input { width: 100%; }
  .dropdown { position: absolute; z-index: 20; left: 0; right: 0; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 12px;
    box-shadow: 0 16px 40px rgba(30,35,90,.18); max-height: 360px; overflow: auto; display: none; }
  .dropdown.on { display: block; }
  .dropdown div { padding: 8px 12px; cursor: pointer; font-size: 14px; border-bottom: 1px solid #f1f3f9; }
  .dropdown div:hover { background: var(--brand-soft); }
  .dropdown div.have { color: var(--muted); }
  .dropdown small { color: var(--muted); }
  .subitem { border: 1px solid var(--line); border-left: 5px solid var(--c, var(--line)); border-radius: 12px; padding: 9px 12px; margin-bottom: 8px;
    cursor: pointer; background: #fff; transition: .15s; }
  .subitem:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(30,35,90,.08); }
  .subitem.sel { outline: 2px solid var(--brand); outline-offset: 1px; background: var(--brand-soft); }
  .subitem.ok { --c: #10b981; } .subitem.warn { --c: #f59e0b; } .subitem.bad { --c: #f43f5e; }
  .subitem .nm { font-weight: 600; font-size: 14px; }
  .subitem .meta { font-size: 12.5px; color: var(--muted); display: flex; gap: 10px; flex-wrap: wrap; }
  .detail h2 { margin: 0; font: 600 21px var(--head-font); }
  .detail .sec { margin-top: 20px; }
  .detail .sec > b { display: block; margin-bottom: 8px; font: 500 15.5px var(--head-font); color: var(--brand-ink); }
  .detail .grp { font-size: 13px; color: var(--muted); margin: 8px 0 4px; }
  .pickfilter { font-size: 14px; color: var(--muted); margin-bottom: 8px; }
  .pickfilter select { padding: 3px 8px; max-width: 100%; }   /* a long department name must not widen a phone screen */
  .chips { display: flex; flex-wrap: wrap; gap: 7px; }
  .chip { border: 1px solid var(--line); background: #fff; border-radius: 999px; padding: 4px 13px; font-size: 14px; }
  .chip:hover { border-color: var(--brand); }
  .chip.on { background: var(--grad); color: #fff; border-color: transparent; box-shadow: 0 3px 10px rgba(79,70,229,.25); }
  .chip small { opacity: .75; }
  .chip.warnchip { border-color: #f59e0b; }
  .chip.warnchip.on { background: linear-gradient(120deg, #d97706, #f59e0b); }
  .slot { display: grid; grid-template-columns: 36px 1fr auto; gap: 12px; align-items: start; border: 1px solid var(--line); border-radius: 12px;
    padding: 10px 12px; margin-bottom: 8px; background: #fff; }
  .slot.first { border-color: #a7f3d0; background: linear-gradient(180deg, #ecfdf5, #fff); }
  .slot.empty { border-style: dashed; color: var(--muted); background: #fafbfe; }
  .rank { width: 32px; height: 32px; border-radius: 50%; background: var(--brand-soft); color: var(--brand); font: 600 15px var(--head-font); display: grid; place-items: center; }
  .slot.first .rank { background: linear-gradient(135deg, #059669, #34d399); color: #fff; }
  .slot .bk { font-size: 14px; }
  .slot .bk .spec { color: var(--muted); font-size: 13px; }
  .slot input { width: 100%; margin-top: 6px; }
  .slot .tools { display: flex; gap: 3px; }
  .slot .tools button { padding: 0 8px; }

  /* dialogs, printing bar, toasts */
  dialog { border: none; border-radius: 18px; padding: 0; box-shadow: 0 30px 80px rgba(15,23,42,.35); max-width: min(640px, 94vw); width: 100%; overflow: hidden; }
  dialog::backdrop { background: rgba(30,27,75,.45); backdrop-filter: blur(3px); }
  dialog .dh { padding: 14px 20px; background: var(--grad); color: #fff; font: 600 17px var(--head-font); }
  dialog .db { padding: 16px 20px; max-height: 65vh; overflow: auto; }
  dialog .df { padding: 12px 20px; border-top: 1px solid var(--line); display: flex; justify-content: flex-end; gap: 8px; background: #fafbfe; }
  ol.steps { margin: 10px 0 14px; padding-left: 22px; line-height: 1.6; }
  ol.steps li { margin-bottom: 4px; }
  .printbar { position: sticky; top: 0; z-index: 5; background: rgba(243,245,251,.92); backdrop-filter: blur(6px); padding: 6px 0 12px; }
  /* document picker on the print tab: pills that wrap onto a second row instead of squeezing their labels */
  .seg { display: flex; flex-wrap: wrap; gap: 6px; }
  .seg button { white-space: nowrap; border-radius: 999px; padding: 6px 14px; box-shadow: 0 1px 2px rgba(30,35,90,.05); }
  .seg button.on { background: var(--grad); color: #fff; border-color: transparent; box-shadow: 0 4px 12px rgba(79,70,229,.28); }
  .s3pick { grid-column: 1 / -1; }
  .s3pick .pick3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr)); gap: 8px 14px; }
  .s3pick .pick3 label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 3px; }
  .s3pick .pick3 select { width: 100%; }
  .s3pick .pick3 input[data-s3f] { width: 100%; }
  .docfields .pick3 input { width: 100%; }
  .s3sum { grid-column: 1 / -1; }
  .phf input { width: 100%; }
  .phs { display: flex; flex-wrap: wrap; gap: 12px; margin: 14px 0 10px; }
  .phs figure { margin: 0; width: 160px; }
  .phs img { display: block; width: 160px; height: 120px; object-fit: cover; border-radius: 10px; border: 1px solid var(--line); background: #fafbff; }
  .phs figcaption { display: flex; justify-content: space-between; align-items: center; font-size: 13px; color: var(--muted); margin-top: 4px; }
  .phadd { width: 160px; height: 120px; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 6px;
    border: 2px dashed #cfd5ee; border-radius: 10px; background: #fafbff; color: var(--muted); cursor: pointer; font: inherit; }
  .phadd:hover { border-color: var(--brand); color: var(--brand); }
  #preview { overflow-x: auto; padding: 22px 0 30px; background: #e6e9f4; border-radius: 16px; box-shadow: inset 0 2px 8px rgba(30,35,90,.08); }
  .sumtbl { border-collapse: collapse; font-size: 14px; }
  .sumtbl td, .sumtbl th { padding: 4px 12px; border-bottom: 1px solid var(--line); text-align: left; }
  .sumtbl td.n { text-align: right; }
  .toast { position: fixed; right: 18px; bottom: 18px; background: #1e1b4b; color: #fff; border-radius: 999px; padding: 9px 18px; font-size: 14px;
    opacity: 0; transform: translateY(8px); transition: .25s; pointer-events: none; z-index: 50; box-shadow: 0 10px 30px rgba(30,27,75,.35); }
  .toast.on { opacity: .95; transform: none; }
  .toast.err { background: var(--bad); }

  /* logos in settings */
  .logo-slots { display: grid; gap: 14px; }
  .logo-slot { display: flex; gap: 14px; align-items: center; }
  .logo-prev { width: 76px; height: 76px; border: 2px dashed #cfd5ee; border-radius: 16px; display: grid; place-items: center; color: #aab2d6; background: #fafbff; flex: none; }
  .logo-prev img { max-width: 64px; max-height: 64px; }
  .logo-prev.wide { width: 128px; }
  .logo-prev.wide img { max-width: 120px; max-height: 68px; border-radius: 8px; object-fit: cover; }
  .logo-prev svg.i { width: 28px; height: 28px; }

  /* login */
  .login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 24px 24px 76px; background: var(--grad); position: relative; overflow: hidden; }
  .login-credit { position: absolute; left: 16px; right: 16px; bottom: 16px; text-align: center; font-size: 13px; line-height: 1.5;
    color: rgba(255,255,255,.94); text-shadow: 0 1px 3px rgba(15,23,42,.45); }
  .blob { position: absolute; border-radius: 50%; filter: blur(50px); opacity: .5; pointer-events: none; }
  .blob.b1 { width: 420px; height: 420px; background: #a78bfa; top: -120px; left: -100px; }
  .blob.b2 { width: 480px; height: 480px; background: #22d3ee; bottom: -160px; right: -120px; }
  /* frosted glass: see-through, but only a little */
  .login { position: relative; width: min(410px, 100%); background: rgba(255,255,255,.74); backdrop-filter: blur(16px) saturate(1.4);
    -webkit-backdrop-filter: blur(16px) saturate(1.4); border: 1px solid rgba(255,255,255,.55); border-radius: 24px;
    padding: 30px 32px 24px; box-shadow: 0 30px 80px rgba(15,23,42,.3); text-align: center; }
  .login-wrap.has-bg { background: linear-gradient(135deg, rgba(49,46,129,.45), rgba(14,165,233,.25)), var(--login-bg) center / cover no-repeat; }
  .login-wrap.has-bg .blob { opacity: .25; }
  .login .field input { background: rgba(255,255,255,.9); }
  .login-logos { display: flex; justify-content: center; gap: 12px; margin-bottom: 12px; }
  .login-logos img, .login-logos .logo-default { height: 76px; width: auto; max-width: 150px; object-fit: contain; }
  .login-logos .logo-default { width: 76px; border-radius: 20px; box-shadow: 0 10px 24px rgba(79,70,229,.3); }
  .login h1 { margin: 4px 0 0; font: 600 25px var(--head-font); background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
  .login p { margin: 4px 0 20px; color: var(--muted); }
  .login label { display: block; text-align: left; font-size: 14px; color: var(--muted); margin: 12px 0 5px; }
  .login .field { position: relative; }
  .login .field svg.i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: #9aa2c8; }
  .login .field input { width: 100%; padding: 10px 12px 10px 40px; border-radius: 12px; }
  .login button { width: 100%; margin-top: 22px; padding: 11px; border-radius: 12px; font: 600 16px var(--head-font); }
  .login .err { background: var(--bad-soft); color: var(--bad); border-radius: 10px; padding: 8px 12px; margin-top: 14px; font-size: 14px; }
  .login-foot { margin-top: 18px; font-size: 12.5px; color: var(--muted); }

  /* ---------- printable pages ---------- */
  .page { background: #fff; color: #000; box-shadow: 0 2px 12px rgba(0,0,0,.18); margin: 0 auto 18px; position: relative; overflow: hidden; }
  .page.land { width: 297mm; height: 210mm; padding: 9mm 12mm; }
  .page.port { width: 210mm; height: 297mm; padding: 15mm 20mm 20mm 30mm; }   /* memo margins: top 1.5 cm (ครุฑ), left 3 cm, right 2 cm, bottom 2 cm */
  .page.port.slim { padding: 9mm 10mm 8mm; }
  /* ใบประมาณการ */
  .page.port.est { padding: 10mm 10mm 8mm; }
  .page.est .pgno { text-align: right; font-size: 13pt; line-height: 1; margin-bottom: -1mm; }
  .page.est .est-ttl { text-align: center; font-weight: bold; text-decoration: underline; font-size: 16pt; line-height: 8mm; }
  .page.est .est-l { line-height: 8mm; white-space: nowrap; }
  .page.est .est-l.ind { padding-left: 16mm; }
  .page.est .est-l .gap { display: inline-block; width: 4mm; }
  .page.est .est-l .gap2 { display: inline-block; width: 9mm; }
  .page.est .cbx { display: inline-block; position: relative; width: 3.4mm; height: 3.4mm; border: .75pt solid #000; margin-right: 1.6mm; vertical-align: -.2mm; }
  .page.est .cbx.on::after { content: "✓"; position: absolute; left: .1mm; top: -2.2mm; font-size: 14pt; font-weight: bold; line-height: 1; }
  .doc table.ft.est { margin-top: 2mm; }
  .doc table.ft.est thead th { height: 16mm; }
  .doc table.ft.est td { height: 7.2mm; padding: .3mm 1.5mm 0; vertical-align: top; overflow-wrap: normal; }
  .doc table.ft.est td.item { font-size: 14pt; line-height: 1.1; padding-top: .6mm; }
  .doc table.ft.est td.item .nw { white-space: nowrap; }   /* the subject code and the publisher never split across lines */
  .doc table.ft.est tr.tot td { font-weight: bold; }
  .page.est .est-sig { margin-top: 6mm; }
  .page.est .est-sig .sigs { margin-top: 0; justify-content: space-around; }
  .page.est .est-sig .sig.mid { margin: 5mm auto 0; width: max-content; }
  /* ใบประมาณการ รวมทุกแผนกวิชา: many signers on the last sheet, three to a row, each ลงชื่อ…… / (name) / position */
  .page.est .est-sig.all { margin-top: 4mm; }
  .page.est .esigs { display: flex; flex-wrap: wrap; justify-content: center; row-gap: 3mm; }
  .page.est .esigs + .esigs { margin-top: 3mm; }
  .page.est .esig { flex: 0 0 33.33%; text-align: center; line-height: 1.2; padding: 0 1mm; }
  .page.est .esig .ln { white-space: nowrap; }
  .page.est .esig .ln:first-child { padding-top: 5mm; }   /* room to sign above the dotted line */
  .page.est .esig .dots { width: 38mm; }
  /* ลงชื่อ / ผู้ขอซื้อ take no width in the line (negative margins), so the dotted line is what is centred */
  .page.est .esig .pre { display: inline-block; width: 14mm; margin-left: -14mm; padding-right: .8mm; text-align: right; box-sizing: border-box; }
  .page.est .esig .post { display: inline-block; width: 18mm; margin-right: -18mm; padding-left: .8mm; text-align: left; box-sizing: border-box; }
  .page.est .esig .epos { font-size: 14pt; text-wrap: balance; }
  .page.est .esigs.wide .esig { flex-basis: 50%; }                  /* officer and head of the work: the work's full name on one line */
  .page.est .esigs.wide .epos { white-space: nowrap; }
  .doc { font-family: var(--doc-font); font-size: 15pt; line-height: 1.18; }
  .doc .fid { text-align: right; font-weight: bold; font-size: 15pt; }
  .doc .ttl { text-align: center; font-weight: bold; font-size: 16pt; }
  .doc .fill { display: inline-block; min-width: 18mm; border-bottom: 1px dotted #000; text-align: center; padding: 0 2mm; line-height: 1.1; }
  .doc .lineinfo { margin-top: 2mm; }
  .doc .lineinfo b { margin-left: 3mm; } .doc .lineinfo b:first-child { margin-left: 0; }
  .doc .lineinfo.one { white-space: nowrap; }   /* สมอ.1: code, subject, level and teachers on one line (fitLine) */
  .doc .lineinfo .tgroup { margin-left: 3mm; }
  .doc .lineinfo.two .tgroup { display: block; margin: .5mm 0 0; }   /* …or the teachers on a line of their own */
  .doc table.ft { width: 100%; border-collapse: collapse; table-layout: fixed; margin-top: 3mm; }
  .doc table.ft th, .doc table.ft td { border: .75pt solid #000; padding: .4mm 1.2mm; vertical-align: middle; overflow-wrap: anywhere; }
  .doc table.ft th { font-weight: bold; text-align: center; line-height: 1.02; overflow-wrap: normal; padding: .4mm .3mm; }
  .doc table.ft td.c { text-align: center; } .doc table.ft td.r { text-align: right; }
  .doc table.ft.s1 tbody td { height: 13mm; }
  .doc table.ft .sm { font-size: 13pt; line-height: 1; }
  .doc table.ft tr.tot td { font-weight: bold; }
  .doc .sigs { display: flex; justify-content: space-around; flex-wrap: wrap; gap: 4mm 10mm; margin-top: 7mm; }
  .doc .sig { text-align: center; white-space: nowrap; }
  .doc .sig, .doc .sgrow { padding-bottom: 1.3em; }
  .page .dots.sgd { position: relative; }
  .page .sgd .under { position: absolute; left: 50%; top: 100%; transform: translateX(-50%); white-space: nowrap; padding-top: .1em; }
  .doc .sig.right { margin: 7mm 0 0 auto; width: max-content; min-width: 120mm; }   /* a long department name widens it leftwards */
  .page .dots { display: inline-block; width: 48mm; border-bottom: 1px dotted #000; }
  .doc table.ft.s2 { font-size: 14pt; }
  .doc table.ft.cmp { font-size: 13.5pt; }
  .doc table.ft.cmp td { padding: .2mm 1mm; line-height: 1.1; }
  .doc table.ft.cmp th.pub { font-size: 10.5pt; line-height: 1; padding: .4mm 0; overflow-wrap: anywhere; }
  .doc .sigs.s1t { justify-content: center; column-gap: 20mm; }   /* สมอ.1 teachers side by side 2 cm apart, not spread over the sheet */
  .doc .sigs.grid4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 3mm 0; margin-top: 6mm; }
  .doc .s2foot .row { display: flex; align-items: baseline; }
  .doc .s2foot .grow { flex: 1; border-bottom: 1px dotted #000; margin-left: 2mm; }
  .doc table.ft.s2 td { padding: .2mm 1.2mm; line-height: 1.1; }
  .doc table.ft.s2 .tn { white-space: nowrap; }   /* a teacher's first name and surname on one line */
  /* สมอ.3 */
  .doc table.ft.s3 { font-size: 15pt; }
  .doc table.ft.s3 th { padding: 1mm .3mm; }
  .doc table.ft.s3 th.sub { font-size: 12.5pt; font-weight: normal; line-height: 1.05; vertical-align: top; }
  .doc table.ft.s3 th.res { font-weight: normal; line-height: 1.25; }
  .doc table.ft.s3 tbody td { height: 11mm; line-height: 1.1; overflow-wrap: normal; }
  .doc table.ft.s3 .nw { white-space: nowrap; }
  .doc .s3pub { margin-top: 1mm; }
  .doc .s3pub .fill { min-width: 150mm; text-align: left; padding-left: 3mm; }
  .doc .s3sig { margin: 8mm 0 0 138mm; }
  .doc .s3sig .sig { text-align: left; padding-bottom: 1.45em; }
  .doc .s3sig.many { display: flex; flex-wrap: wrap; justify-content: center; margin: 7mm 0 0; row-gap: 2mm; }
  .doc .ap { display: inline-block; max-width: 100%; }   /* one author: moves to the next line whole, wraps only if wider than the cell */
  /* คำสั่งแต่งตั้งคณะกรรมการ: the last line of each sheet is kept free for the continuation mark */
  .page.port.ord { padding-bottom: 28mm; }
  .page.ord .ocont { position: absolute; right: 20mm; bottom: 20mm; font: 16pt/1.2 var(--doc-font); }
  .memo.ord .ohead { text-align: center; }
  .memo.ord .blank { display: inline-block; }   /* space for the order number / date written by hand */
  .memo.ord .ohead img { display: block; height: 30mm; margin: 0 auto 3mm; }
  .memo.ord .ohead > div { line-height: 1.45; }
  .memo.ord .osep { width: 60mm; margin: 1.5mm auto 0; border-bottom: 1px dotted #000; }
  .memo.ord .oh { font-weight: bold; margin-top: 4mm; }
  .memo.ord table.om { width: 100%; border-collapse: collapse; table-layout: fixed; }
  .memo.ord table.om col.c1 { width: 17mm; } .memo.ord table.om col.c2 { width: 45mm; } .memo.ord table.om col.c4 { width: 37mm; }
  .memo.ord table.om td { padding: 0 1.5mm 0 0; vertical-align: top; }
  .memo.ord table.om td:first-child { padding-left: 6mm; }
  .memo.ord table.om td:last-child { padding-right: 0; }
  .memo.ord table.om .nw { white-space: nowrap; }
  .memo.ord .oduty { display: grid; grid-template-columns: auto 1fr; column-gap: 2.5mm; margin: .5mm 0 0 6mm; }
  .memo.ord .oduty .u { text-decoration: underline; }
  .memo.ord .oduty .ph { white-space: nowrap; }
  .memo.ord .osign { margin-top: 5mm; }
  .memo.ord .odate { margin-left: 45mm; }
  .memo.ord .osig { margin: 20mm 0 0 50mm; width: 90mm; text-align: center; }
  .ordedit details.panel { margin-bottom: 10px; }
  .ordedit .pick3 { grid-template-columns: minmax(0, 1fr) minmax(0, 2fr); }   /* order no. | day, month, year */
  @media (max-width: 700px) { .ordedit .pick3 { grid-template-columns: 1fr; } }
  .ordedit .odate-in .row3 { display: grid; grid-template-columns: 1fr 1.4fr .8fr; gap: 6px; }
  .ordedit .odate-in .row3 > * { min-width: 0; }
  .ordedit summary { cursor: pointer; display: flex; align-items: center; gap: 8px; font: 500 15px var(--head-font); }
  .ordedit details[open] summary { margin-bottom: 10px; }
  .ordedit table.ordt td { vertical-align: middle; }
  /* สมอ.4 */
  .doc table.ft.s4 { font-size: 15pt; margin-top: 5mm; }
  .doc table.ft.s4 th { padding: 1mm .3mm; }
  .doc table.ft.s4 th.sub { font-weight: normal; }
  .doc table.ft.s4 tbody td { height: 11mm; line-height: 1.1; overflow-wrap: normal; }
  .doc table.ft.s4 .nw { white-space: nowrap; }
  .doc .s4note { margin-top: 4mm; }
  .doc .s4note .dl { border-bottom: 1px dotted #000; height: 7mm; }
  .doc .s4sigs { display: grid; grid-template-columns: repeat(3, 1fr); margin-top: 7mm; text-align: center; }
  .doc .s4sig > div { white-space: nowrap; }
  .doc .s3sig.many .sig { width: 33.33%; text-align: center; }
  .memo { font-family: var(--doc-font); font-size: 16pt; line-height: 1.22; }
  .memo p { margin: 0; }
  .memo .rcv .rcv-t { text-align: center; font-weight: bold; }
  .memo .rcv { position: absolute; top: 7mm; right: 16mm; border: .75pt solid #000; padding: 1mm 3mm; font-size: 14pt; line-height: 1.25; min-width: 52mm; }
  .memo .mh { position: relative; height: 15mm; }
  .memo .mh img { position: absolute; left: 0; top: 0; height: 15mm; }
  .memo .mh .t { position: absolute; left: 0; right: 0; bottom: -1mm; text-align: center; font-weight: bold; font-size: 29pt; }
  .memo .lbl { font-weight: bold; font-size: 20pt; }
  .memo .row2 { display: flex; }
  .memo .row2 > div:first-child { flex: 1; }
  .memo .row2 > div:last-child { width: 72mm; }
  .memo .ind { text-indent: 25mm; }
  .memo .att { display: grid; grid-template-columns: auto 1fr auto; column-gap: 2mm; }
  .memo table.pub { border-collapse: collapse; margin-left: 25mm; }   /* lines up with the paragraph indent (ดังนั้น) */
  .memo table.pub td { padding: 0 2mm 0 0; vertical-align: top; }
  .memo table.pub td:first-child { white-space: nowrap; }
  .memo table.pub td.n { text-align: right; white-space: nowrap; }
  /* signature blocks centred in the right half of the text area: centre line 150 mm from the paper's left edge */
  .memo .msig { text-align: center; margin-left: 67.5mm; width: 105mm; white-space: nowrap; }
  .memo .para .ph, .memo table.pub td.baht { white-space: nowrap; }
  .memo .gap { height: 9mm; }
  .memo .row2d { white-space: nowrap; }
  .memo .row2d .g1, .memo .row2d .g2 { display: inline-block; text-align: center; }
  /* บันทึกข้อความแบบที่ 2 */
  .page.port.m2 { padding-bottom: 5mm; }   /* bottom margin 0.5 cm */
  .memo.f2 .dlr { display: flex; align-items: baseline; white-space: nowrap; }
  .memo.f2 .dlr .dv { flex: 1; min-width: 0; border-bottom: 1px dotted #000; margin-left: 2mm; padding-left: 1mm; line-height: 1.15; }
  .memo.f2 .row2d .mno, .memo.f2 .row2d .g1, .memo.f2 .row2d .g2, .memo.f2 .row2d .mon, .memo.f2 .row2d .fr {
    display: inline-block; border-bottom: 1px dotted #000; line-height: 1.15; }
  .memo.f2 .row2d .mno { padding-left: 1mm; }
  /* ภาพประกอบคณะกรรมการตรวจรับพัสดุ: heading, then two landscape photos per sheet (sized in buildRecvPhotos) */
  .memo.phot { height: 100%; display: flex; flex-direction: column; }
  .memo.phot .phead { text-align: center; line-height: 1.45; }
  .memo.phot .phead .pt { font-weight: bold; font-size: 20pt; margin-bottom: 1mm; }
  .memo.phot .pcol { flex: 1; min-height: 0; display: flex; flex-direction: column; align-items: center; gap: 8mm; margin-top: 6mm; }
  .memo.phot .phc { flex: none; overflow: hidden; display: flex; align-items: center; justify-content: center; }
  .memo.phot .phc img { display: block; width: 100%; height: 100%; object-fit: cover; }   /* landscape frame: a portrait photo is cropped to its middle */
  .memo.phot .phc.empty { border: .75pt dashed #888; color: #888; font-size: 14pt; }
  .memo .sig3 { display: flex; justify-content: space-between; margin-top: 12mm; white-space: nowrap; }
  .memo .sig3 > div { text-align: center; }
  .memo table.appr { width: 100%; border-collapse: collapse; table-layout: fixed; margin-top: 2mm; font-size: 13pt; line-height: 1.1; }
  .memo .pno { text-align: center; margin-bottom: 4mm; }
  .memo table.appr td { border: .75pt solid #000; vertical-align: top; padding: .6mm 2mm 2mm; }
  .memo table.appr .ah { text-align: center; font-weight: bold; text-decoration: underline; }
  .memo table.appr .ah.nou { text-decoration: none; }
  .memo table.appr .c { text-align: center; white-space: nowrap; }
  .memo table.appr .fl { display: flex; align-items: baseline; white-space: nowrap; }
  .memo table.appr .fl i { flex: 1; border-bottom: 1px dotted #000; margin: 0 1mm; }
  .memo table.appr .cl { height: 1.1em; border-bottom: 1px dotted #000; margin: 0 3mm; }
  .memo table.appr .narrow { margin: 0 22%; }
  .memo table.appr .sp { height: 3mm; }
  .memo .cbx { display: inline-block; width: .7em; height: .7em; border: .75pt solid #000; margin: 0 1.5mm 0 2mm; vertical-align: -.05em; }   /* scales with the table text */
  .memo table.pub td:nth-child(2) { padding-left: 6mm; }
  .memo table.pub td:nth-child(4) { padding-left: 1.5mm; }
  /* บันทึกขออนุญาตดำเนินโครงการ / ขออนุมัติจัดซื้อ (งานวิทยบริการฯ) */
  .memo table.pjb { border-collapse: collapse; margin: .5mm 0 0 25mm; }   /* the budget by kind, under the paragraph indent */
  .memo table.pjb td { padding: 0 1.5mm 0 0; white-space: nowrap; }
  .memo table.pjb td.v { min-width: 24mm; text-align: center; border-bottom: 1px dotted #000; line-height: 1.1; }
  .memo table.pjb td:nth-child(5) { padding-left: 3mm; }
  .memo .pjsg { display: grid; grid-template-columns: 1fr 1fr; column-gap: 6mm; }   /* signers two to a row, as in the sample */
  .memo .pjs { text-align: center; }
  .memo .pjs .sl { height: 11mm; }   /* room to sign */
  .memo .pjs .wl { padding-top: 2mm; }   /* an executive's dotted line to write on; the signature goes in .sl under it */
  .memo .pjs .wl .dots { width: 62mm; }
  .memo .pjs .nm, .memo .pjs .ps { white-space: nowrap; }   /* a position on one line, however long (user's request) */
  .memo .pjend .pjs { width: 80mm; }
  .memo .pjdir { margin-top: 3mm; }   /* the director's approval, below the deputies */
  .memo .pjdir .dsig { display: inline-flex; flex-direction: column; align-items: center; }
  .memo .pjdir .dsig .sl { height: 20mm; }   /* the director's signing room */
  .memo .pjdir .nm, .memo .pjdir .ps { white-space: nowrap; }
  .page .cont { position: absolute; right: 20mm; bottom: 12mm; font: 16pt/1 var(--doc-font); }   /* "/ความคิดเห็นของ..." at the foot */
  .memo .publ { margin-left: 25mm; }   /* one publisher a line: name, amount and the amount in words, wrapping only between them */
  .memo .publ > div > span { white-space: nowrap; }
  .memo.pj table.appr { line-height: 1.25; }   /* sheet 3 keeps the table's own size (13 pt, user's choice) */
  .memo table.appr .cbx { flex: none; }        /* a check box never squeezes in a full line */
  .memo table.appr .fl i { min-width: 6mm; }
  .memo.pj table.appr .sp { height: 7mm; }

  @media print {
    body { background: #fff !important; }
    header, nav, .nav-scrim, .nav-tip, footer.credit, .no-print, .toast { display: none !important; }
    #app, .shell, .content { display: block; min-height: 0; }
    main { padding: 0; }
    main > section:not(#tab-print) { display: none !important; }
    main > section { animation: none; }
    #preview { padding: 0; overflow: visible; background: none; box-shadow: none; border-radius: 0; }
    .page { margin: 0 !important; box-shadow: none !important; break-after: page; }
    .page:last-child { break-after: auto; }
    .page.land { height: 209.4mm; }
    .page.port { height: 296.4mm; }
  }

  /* TH SarabunPSK (SIPA) served with the app: Safari only lets pages use fonts that ship with macOS */
  @font-face { font-family: "SMO Sarabun"; font-weight: 400; src: url(fonts/THSarabunPSK.ttf) format("truetype"); }
  @font-face { font-family: "SMO Sarabun"; font-weight: 700; src: url(fonts/THSarabunPSK-Bold.ttf) format("truetype"); }
