/* Layout and theme on top of Bootstrap 5.3. Sidebar colours follow Solarized Dark. */
:root {
  --sb-bg: #0e2a35;
  --sb-bg-hover: #16404f;
  --sb-bg-active: #073642;
  --sb-text: #93a1a1;
  --sb-text-strong: #eee8d5;
  --sb-muted: #7f9aa3;
  --sb-border: rgba(147, 161, 161, .14);
  --accent: #2aa198;
  --brand: #1f7f78;        /* accent darkened for white text on buttons */
  --brand-hover: #19675f;
  --sidebar-w: 270px;
  --bs-body-font-family: system-ui, -apple-system, "Segoe UI", "Noto Sans Thai", "Leelawadee UI", Tahoma, sans-serif;
  --bs-link-color: var(--brand);
  --bs-link-color-rgb: 31, 127, 120;
  --bs-link-hover-color: var(--brand-hover);
  --bs-link-hover-color-rgb: 25, 103, 95;
  --bs-border-radius: .5rem;
  --bs-border-color: #e3e8ea;
}

/* ---- Bootstrap colour overrides ---- */
.btn-primary {
  --bs-btn-bg: var(--brand); --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand-hover); --bs-btn-hover-border-color: var(--brand-hover);
  --bs-btn-active-bg: var(--brand-hover); --bs-btn-active-border-color: var(--brand-hover);
  --bs-btn-disabled-bg: var(--brand); --bs-btn-disabled-border-color: var(--brand);
  --bs-btn-focus-shadow-rgb: 42, 161, 152;
}
.btn-outline-primary {
  --bs-btn-color: var(--brand); --bs-btn-border-color: var(--brand);
  --bs-btn-hover-bg: var(--brand); --bs-btn-hover-border-color: var(--brand);
  --bs-btn-active-bg: var(--brand-hover); --bs-btn-active-border-color: var(--brand-hover);
  --bs-btn-focus-shadow-rgb: 42, 161, 152;
}
.btn-light { --bs-btn-bg: #eef2f3; --bs-btn-border-color: #eef2f3; --bs-btn-hover-bg: #e2e8ea; --bs-btn-hover-border-color: #e2e8ea; }
.text-bg-primary { background-color: var(--brand) !important; }
.form-control:focus, .form-select:focus, .form-check-input:focus {
  border-color: var(--accent); box-shadow: 0 0 0 .2rem rgba(42, 161, 152, .2);
}
.form-check-input:checked { background-color: var(--brand); border-color: var(--brand); }
.pagination { --bs-pagination-color: var(--brand); --bs-pagination-active-bg: var(--brand); --bs-pagination-active-border-color: var(--brand); --bs-pagination-hover-color: var(--brand-hover); --bs-pagination-focus-box-shadow: 0 0 0 .2rem rgba(42, 161, 152, .2); }
.nav-pills { --bs-nav-pills-link-active-bg: var(--brand); --bs-nav-link-color: #4b5d63; --bs-nav-link-hover-color: var(--brand); }
.dropdown-item:active { background-color: var(--brand); }
a { text-underline-offset: .15em; }
.table a, .cat-row a { text-decoration: none; font-weight: 500; }
.table a:hover, .cat-row a:hover { text-decoration: underline; }

/* ---- App shell ---- */
body.app { min-height: 100vh; background: #f5f7f8; }
.app-shell { display: flex; min-height: 100vh; }
.app-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.app-content { padding: 1.75rem 2rem 3rem; flex: 1; }

.sidebar { --bs-offcanvas-width: var(--sidebar-w); --bs-offcanvas-bg: var(--sb-bg); color: var(--sb-text); display: flex; flex-direction: column; }
.offcanvas-lg.sidebar { background-color: var(--sb-bg) !important; }  /* Bootstrap makes it transparent at lg */
@media (min-width: 992px) {
  .sidebar { width: var(--sidebar-w); flex-shrink: 0; position: sticky; top: 0; height: 100vh; }
}
.sidebar-brand { display: flex; align-items: center; justify-content: space-between; gap: .5rem; padding: 1.1rem 1.25rem; border-bottom: 1px solid var(--sb-border); }
.brand { display: flex; align-items: center; gap: .75rem; color: var(--sb-text-strong); text-decoration: none; font-weight: 600; font-size: 1.1rem; line-height: 1.2; }
.brand:hover { color: #fff; }
.brand-text small { display: block; font-size: .72rem; font-weight: 400; color: var(--sb-muted); }
.brand-icon { display: inline-grid; place-items: center; width: 2.4rem; height: 2.4rem; border-radius: .6rem; background: var(--accent); color: #fff; font-size: 1.15rem; flex-shrink: 0; }

.sidebar-nav { flex: 1; overflow-y: auto; padding: .5rem .85rem 1rem; }
.nav-section { margin: 1rem .6rem .35rem; font-size: .72rem; letter-spacing: .08em; text-transform: uppercase; color: var(--sb-muted); }
.sidebar .nav-link { display: flex; align-items: center; gap: .8rem; width: 100%; padding: .6rem .75rem; border: 0; border-radius: .5rem; background: none; color: var(--sb-text); text-align: left; text-decoration: none; font-size: .95rem; transition: background-color .15s, color .15s; }
.sidebar .nav-link > .bi:first-child { font-size: 1.1rem; width: 1.25rem; text-align: center; }
.sidebar .nav-link:hover { background: var(--sb-bg-hover); color: var(--sb-text-strong); }
.sidebar .nav-link.active { background: var(--sb-bg-active); color: var(--sb-text-strong); box-shadow: inset 3px 0 0 var(--accent); }
.sidebar .nav-link:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.nav-toggle .caret { margin-left: auto; font-size: .8rem; transition: transform .2s; }
.nav-toggle.collapsed .caret { transform: rotate(-90deg); }
.subnav { margin: .15rem 0 .35rem 1.35rem; padding-left: .6rem; border-left: 1px solid var(--sb-border); }
.subnav .nav-link { padding: .45rem .7rem; font-size: .9rem; gap: .6rem; }

.sidebar-user { display: flex; align-items: center; gap: .7rem; padding: .9rem 1.1rem; border-top: 1px solid var(--sb-border); }
.sidebar-user .who { flex: 1; min-width: 0; }
.sidebar-user .name { color: var(--sb-text-strong); font-size: .9rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sidebar-user .role { color: var(--sb-muted); font-size: .78rem; }
.btn-icon { color: var(--sb-text); padding: .3rem .5rem; font-size: 1.15rem; }
.btn-icon:hover, .btn-icon:focus-visible { color: #fff; background: var(--sb-bg-hover); }

.avatar { display: inline-grid; place-items: center; width: 2.2rem; height: 2.2rem; border-radius: 50%; background: #268bd2; color: #fff; font-size: .8rem; font-weight: 600; flex-shrink: 0; }

/* ---- Topbar ---- */
.topbar { position: sticky; top: 0; z-index: 1020; display: flex; align-items: center; gap: .75rem; padding: .75rem 2rem; background: #fff; border-bottom: 1px solid var(--bs-border-color); }
.topbar-search { position: relative; flex: 1; max-width: 32rem; }
.topbar-search .bi { position: absolute; left: .85rem; top: 50%; transform: translateY(-50%); color: #8a9a9f; pointer-events: none; }
.topbar-search .form-control { padding-left: 2.4rem; background: #f5f7f8; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: .5rem; }
.user-btn { display: flex; align-items: center; gap: .5rem; border: 1px solid var(--bs-border-color); padding: .25rem .65rem .25rem .3rem; border-radius: 2rem; }
.user-btn .avatar { width: 1.9rem; height: 1.9rem; font-size: .72rem; }

/* ---- Page content ---- */
.page-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 1rem; margin-bottom: 1.5rem; }
.page-header h1 { font-size: 1.75rem; font-weight: 700; margin-bottom: .25rem; }
.page-actions { display: flex; flex-wrap: wrap; gap: .5rem; }
.card { border-color: var(--bs-border-color); box-shadow: 0 1px 2px rgba(16, 42, 53, .04); }
.card-header { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .75rem; padding: 1rem 1.25rem; background: none; }
.card-title { font-size: 1.05rem; font-weight: 600; margin: 0; }
.card-subtitle { font-size: .85rem; color: var(--bs-secondary-color); margin: .15rem 0 0; }
.card-footer { background: none; padding: .75rem 1.25rem; }
.table > :not(caption) > * > * { padding: .7rem 1rem; }
.table thead th { font-size: .8rem; font-weight: 600; color: #5f7177; background: #fafbfc; white-space: nowrap; }
.table-sm > :not(caption) > * > * { padding: .4rem .6rem; }
.form-label { font-weight: 500; font-size: .9rem; }
.form-actions { display: flex; gap: .5rem; padding: 1rem 0; }
.flash { margin-bottom: 1rem; }

/* Stat cards (dashboard) */
.stat-card { text-decoration: none; color: inherit; transition: box-shadow .15s, transform .15s; }
.stat-card:hover { box-shadow: 0 6px 18px rgba(16, 42, 53, .08); transform: translateY(-1px); color: inherit; }
.stat-card .card-body { padding: 1.25rem 1.4rem; }
.stat-head { display: flex; justify-content: space-between; align-items: flex-start; }
.stat-label { color: #4b5d63; font-weight: 500; }
.stat-icon { display: inline-grid; place-items: center; width: 2.6rem; height: 2.6rem; border-radius: .6rem; font-size: 1.2rem; }
.stat-value { font-size: 2rem; font-weight: 700; margin: .6rem 0 .2rem; line-height: 1.1; }
.stat-sub { font-size: .85rem; color: var(--bs-secondary-color); }
.tone-cyan .stat-icon { background: #e0f3f1; color: #1f7f78; }
.tone-green .stat-icon { background: #e6f2dc; color: #5b6b00; }
.tone-yellow .stat-icon { background: #fbf0d0; color: #8a6400; }
.tone-orange .stat-icon { background: #fbe4da; color: #b23f0f; }
.tone-violet .stat-icon { background: #e8e9f7; color: #4a4f9c; }
.tone-blue .stat-icon { background: #dcebf7; color: #1d6aa3; }
.tone-pink .stat-icon { background: #f8e0ec; color: #a32a64; }
.tone-red .stat-icon { background: #f9dcdb; color: #b3221f; }
.tone-olive .stat-icon { background: #edf1d3; color: #647300; }

/* Category rows + progress (native <progress>: no inline style needed under the CSP) */
.cat-row + .cat-row { margin-top: 1.1rem; padding-top: 1.1rem; border-top: 1px dashed var(--bs-border-color); }
.cat-link { color: inherit; text-decoration: none; font-weight: 500; }
.cat-link:hover { color: var(--brand); }
.cat-progress { display: block; width: 100%; height: .5rem; margin-bottom: .35rem; border: 0; border-radius: 1rem; background: #edf1f2; overflow: hidden; appearance: none; }
.cat-progress::-webkit-progress-bar { background: #edf1f2; border-radius: 1rem; }
.cat-progress::-webkit-progress-value { border-radius: 1rem; background: var(--c, var(--accent)); }
.cat-progress::-moz-progress-bar { border-radius: 1rem; background: var(--c, var(--accent)); }

/* Category colours: categories are added by admins, so the colour cycles by id (id % 8)
   through the Solarized accents. Used by dots, badges and progress bars. */
.cat-tone-0 { --c: #dc322f; }
.cat-tone-1 { --c: #2aa198; }
.cat-tone-2 { --c: #268bd2; }
.cat-tone-3 { --c: #6c71c4; }
.cat-tone-4 { --c: #cb4b16; }
.cat-tone-5 { --c: #859900; }
.cat-tone-6 { --c: #d33682; }
.cat-tone-7 { --c: #b58900; }
.dot { display: inline-block; width: .55rem; height: .55rem; border-radius: 50%; background: var(--c, var(--sb-muted)); margin-right: .5rem; flex-shrink: 0; }
.subnav .dot { margin-right: 0; }
.badge { font-weight: 500; padding: .35em .7em; border-radius: 1rem; }
.badge.cat { background: color-mix(in srgb, var(--c) 14%, #fff); color: color-mix(in srgb, var(--c) 70%, #000); }
.badge.status { background: #eceff1; color: #4b5d63; }
.badge.status-0 { background: #e2f1d8; color: #3d4a00; }
.badge.status-1 { background: #fbf0d0; color: #7a5800; }
.badge.status-2 { background: #fbe4da; color: #a03a0e; }
/* 4th status onwards: the category palette, so a longer list still gets distinct colours */
.badge.status-3 { --c: #6c71c4; }
.badge.status-4 { --c: #268bd2; }
.badge.status-5 { --c: #d33682; }
.badge.status-6 { --c: #dc322f; }
.badge.status-7 { --c: #859900; }
.badge.status-3, .badge.status-4, .badge.status-5, .badge.status-6, .badge.status-7 {
  background: color-mix(in srgb, var(--c) 14%, #fff); color: color-mix(in srgb, var(--c) 70%, #000); }
.cat-pills .nav-link { display: flex; align-items: center; padding: .4rem .9rem; font-size: .9rem; }
.cat-pills .nav-link.active .dot { background: #fff; }

/* Order form */
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 1rem; }
.photos img { width: 100%; height: 180px; object-fit: cover; border-radius: .5rem; }
.photo-slot { display: flex; flex-direction: column; gap: .5rem; }
.photo-slot .current { display: flex; flex-direction: column; gap: .5rem; }
.checklist-row { display: grid; grid-template-columns: 1fr 12rem auto; gap: .5rem; align-items: start; margin-bottom: .5rem; }
@media (max-width: 575.98px) {
  .checklist-row { grid-template-columns: 1fr auto; }
  .checklist-row select { grid-column: 1; }
  .checklist-row button { grid-row: 1; grid-column: 2; }
}
.secret { font-family: var(--bs-font-monospace); font-size: 1.2rem; user-select: all; }

/* The annex image height is the most that still leaves page 2 of the A4 print with room to spare
   (measured with headless Chrome: 2 pages up to ~10.2rem with these paddings). Raise it and the
   signatures spill onto a third page. */
/* Printable order form (page 1) and photo annex (page 2), laid out like the PHP version's print */
.doc { max-width: 56rem; margin: 0 auto 1.5rem; padding: 1.5rem; background: #fff; color: #0f172a; border: 1px solid #cbd5e1; border-radius: .75rem; font-family: "Sarabun", system-ui, sans-serif; font-size: .875rem; line-height: 1.4286; }
.doc-head { text-align: center; margin-bottom: 1rem; }
.doc-logo { height: 4rem; width: auto; margin-bottom: .5rem; }
.doc-head h2 { font-size: 1.125rem; line-height: 1.55; font-weight: 700; margin: 0; }
.doc-head p { font-size: .75rem; line-height: 1.33; color: #475569; margin: .15rem 0 0; }
.doc-meta { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; padding-bottom: .75rem; margin-bottom: .75rem; border-bottom: 1px solid #cbd5e1; }
.doc-meta p { margin: 0 0 .25rem; }
.doc-no { color: #4338ca; font-weight: 700; }
.doc-status { color: #047857; font-weight: 700; }
.doc-people { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; padding: .6rem; margin-bottom: .75rem; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: .5rem; }
.doc-block { margin-bottom: .75rem; }
.doc-block > strong { display: block; margin-bottom: .25rem; color: #334155; }
.doc-box { min-height: 2.25rem; padding: .6rem; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: .5rem; white-space: pre-wrap; }
.doc-table { width: 100%; border-collapse: collapse; border: 1px solid #cbd5e1; font-size: .75rem; line-height: 1.33; }
.doc-table th, .doc-table td { padding: .35rem .5rem; border: 1px solid #e2e8f0; }
.doc-table th { background: #f1f5f9; text-align: left; border-color: #cbd5e1; }
.doc-table .c-no { width: 2.75rem; text-align: center; }
.doc-table .c-res { width: 7.5rem; text-align: center; }
.doc-table .res { font-weight: 500; }
.doc-table .res.ok { color: #059669; }
.doc-table .res.bad { color: #e11d48; }
.doc-signs { display: grid; grid-template-columns: 1fr 1fr; gap: 2rem; margin-top: 1rem; padding-top: 1rem; border-top: 1px solid #e2e8f0; text-align: center; }
.sign { padding: 0 .5rem; }
.sign-space { height: 2rem; }
/* Signature: one unbroken dotted line; the rank sits on top of it, its right edge at the left
   edge of the name, moved 5 characters further left (the name block shrinks to the text, so the rank follows the name); the name in
   brackets under the line, the role under the name. Rank, name and role share one size. */
.sign-line { border-bottom: 1.5px dotted #0f172a; margin: 0 1.5cm; }  /* line is inset 1.5 cm from both sides */
.sign-person { position: relative; display: table; margin: .25rem auto 0; }
.sign-person .rank { position: absolute; right: calc(100% + 5ch); bottom: calc(100% + .35rem); font-weight: 600; line-height: 1.15; white-space: nowrap; }
.sign-name { margin: 0; font-weight: 600; }
.sign-role { margin: 0; font-weight: 600; }
.annex-head { text-align: center; margin-bottom: .5rem; padding-bottom: .5rem; border-bottom: 2px solid #1e293b; }
.annex-head h3 { font-size: 1rem; font-weight: 700; margin: 0; text-transform: uppercase; }
.annex-head p { font-size: .75rem; line-height: 1.33; color: #475569; margin: .15rem 0 0; }
.doc-annex { --annex-img-h: 9.75rem; }  /* same on screen and in print, so the preview shows what prints */
.annex-set { margin-bottom: .6rem; }
.annex-title { display: flex; align-items: center; gap: .5rem; margin: 0 0 .4rem; padding: .4rem .75rem; font-size: .875rem; font-weight: 700; border: 1px solid; border-radius: .5rem; }
.annex-title.before { background: #fef3c7; color: #78350f; border-color: #fcd34d; }
.annex-title.after { background: #d1fae5; color: #064e3b; border-color: #6ee7b7; }
.annex-grid { display: grid; grid-template-columns: 1fr 1fr; gap: .5rem; }
.annex-slot { margin: 0; padding: .35rem; background: #f8fafc; border: 1px solid #cbd5e1; border-radius: .5rem; text-align: center; }
.annex-img { display: grid; place-items: center; height: var(--annex-img-h); background: #fff; border: 1px solid #e2e8f0; border-radius: .35rem; overflow: hidden; }
.annex-img img { width: 100%; height: 100%; object-fit: contain; }
.annex-slot.empty .annex-img { border: 1px dashed #94a3b8; color: #94a3b8; font-size: .8rem; }
.annex-slot.empty .annex-img span { display: flex; flex-direction: column; align-items: center; gap: .2rem; }
.annex-slot.empty .annex-img .bi { font-size: 1.8rem; color: #cbd5e1; }
.annex-slot figcaption { margin-top: .2rem; font-size: .75rem; font-weight: 600; }
.annex-slot.empty figcaption { color: #94a3b8; font-weight: 400; }
.annex-signs { margin-top: .6rem; padding-top: .5rem; }

/* Pages without the shell: login, forced password change */
body.plain { min-height: 100vh; background: radial-gradient(circle at top, #164150 0%, var(--sb-bg) 60%); }
.plain-content { max-width: 26rem; margin: 0 auto; padding: 4rem 1rem 2rem; }
.plain-brand { display: flex; align-items: center; justify-content: center; gap: .75rem; margin-bottom: 1.5rem; color: var(--sb-text-strong); font-weight: 600; font-size: 1.25rem; }
.plain-card { border: 0; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); }
.plain-card .card-body { padding: 2rem; }
.plain .btn-link { color: var(--sb-text); }

@media (max-width: 991.98px) {
  .app-content { padding: 1.25rem 1rem 2.5rem; }
  .topbar { padding: .65rem 1rem; }
}
@media (max-width: 575.98px) {
  .doc { padding: 1rem; }
  .doc-meta, .doc-people, .doc-signs { grid-template-columns: 1fr; }
  .doc-meta .text-end { text-align: left !important; }
  .page-header h1 { font-size: 1.4rem; }
}

@page { size: A4 portrait; margin: 8mm; }
@media print {
  body, body.app { background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .app-shell { display: block; min-height: 0; }
  .app-content { padding: 0; }
  .doc { max-width: none; margin: 0; padding: 0; border: 0; border-radius: 0; }
  .doc-annex { break-before: page; }
  .doc-head, .doc-block, .annex-set, .annex-slot, .doc-signs, tr { break-inside: avoid; }
}
