/* 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; }


/* ---- Stock app additions ---- */
.badge.cond-ok { background: #e2f1d8; color: #3d4a00; }
.badge.cond-faulty { background: #f9dcdb; color: #9c1c19; }
.badge.cond-repairing { background: #fbf0d0; color: #7a5800; }
.badge.life-disposed, .badge.life-voided, .badge.st-cancelled { background: #eceff1; color: #4b5d63; }
.badge.st-draft { background: #fbf0d0; color: #7a5800; }
.badge.st-confirmed { background: #e2f1d8; color: #3d4a00; }
.badge.mode-quantity { background: #dcebf7; color: #1d6aa3; }
.badge.mode-individual { background: #e8e9f7; color: #4a4f9c; }
.badge.where-store { background: #e0f3f1; color: #1f7f78; }
.badge.where-out { background: #fbe4da; color: #a03a0e; }
.badge.legacy { background: #ede4d3; color: #6b4e16; }
.badge .bi { margin-right: .3em; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.unit { color: var(--bs-secondary-color); font-size: .85em; margin-left: .25em; }
.muted-zero { color: #a8b4b8; }
.tab-pills .nav-link { display: flex; align-items: center; gap: .45rem; padding: .45rem 1rem; }
.tab-pills .badge { background: #eceff1; color: #4b5d63; }
.tab-pills .nav-link.active .badge { background: rgba(255,255,255,.25); color: #fff; }
.filters .form-control, .filters .form-select { min-width: 9rem; }
.kv { display: grid; grid-template-columns: 11rem 1fr; gap: .35rem 1rem; margin: 0; }
.kv dt { font-weight: 500; color: #5f7177; }
.kv dd { margin: 0; }
.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li { position: relative; padding: 0 0 1rem 1.6rem; border-left: 2px solid var(--bs-border-color); margin-left: .5rem; }
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before { content: ""; position: absolute; left: -.45rem; top: .3rem; width: .75rem; height: .75rem; border-radius: 50%; background: var(--accent); border: 2px solid #fff; box-shadow: 0 0 0 1px var(--accent); }
.timeline .when { font-size: .8rem; color: var(--bs-secondary-color); }
.line-form { background: #fafbfc; border: 1px dashed var(--bs-border-color); border-radius: .5rem; padding: 1rem; }
.step-note { font-size: .85rem; color: var(--bs-secondary-color); }
.pick-list { max-height: 22rem; overflow-y: auto; }
.secret { font-family: var(--bs-font-monospace); font-size: 1.2rem; user-select: all; }
.thumb { width: 7rem; height: 7rem; object-fit: contain; background: #f8fafc; border: 1px solid #e2e8f0; border-radius: .5rem; }
.logo-preview { height: 4rem; width: auto; }
.w-qty { width: 7.5rem; }
.empty-state { text-align: center; color: var(--bs-secondary-color); padding: 2rem 1rem; }
.empty-state .bi { display: block; font-size: 2rem; color: #c3ced2; margin-bottom: .4rem; }
form.busy button[type=submit] { opacity: .65; pointer-events: none; }
.act-form { display: inline-flex; flex-wrap: wrap; gap: .25rem; align-items: center; margin-bottom: .25rem; }
.act-note { width: 10rem; min-width: 8rem; }
.draft-banner { border-left: 4px solid #b58900; }
.cancel-banner { border-left: 4px solid #dc322f; }

/* ---- Printable documents (A4, Sarabun) ---- */
.paper { position: relative; max-width: 210mm; margin: 0 auto 1.5rem; padding: 14mm 14mm 12mm; background: #fff; color: #000; border: 1px solid #cbd5e1; border-radius: .5rem; font-family: "Sarabun", system-ui, sans-serif; font-size: 13pt; line-height: 1.5; }
.paper p { margin: 0 0 .15rem; }
.paper .lg { display: block; height: 22mm; width: auto; margin: 0 auto 2mm; }
.paper .ttl { text-align: center; font-size: 17pt; font-weight: 700; }
.paper .c { text-align: center; }
.paper .r { text-align: right; }
.paper .indent { text-indent: 12mm; }
.paper .gap { margin-bottom: 3mm; }
.paper .fl { display: inline-block; min-width: 30mm; padding: 0 2mm; border-bottom: 1px dotted #000; text-align: center; }
.paper .fl.w-s { min-width: 30mm; } .paper .fl.w-m { min-width: 48mm; } .paper .fl.w-l { min-width: 60mm; }
.paper table { width: 100%; border-collapse: collapse; margin: 3mm 0; }
.paper thead { display: table-header-group; }  /* the header row repeats on every printed page */
.paper th, .paper td { border: 1px solid #000; padding: 1mm 2mm; vertical-align: top; }
.paper th { text-align: center; font-weight: 700; }
.paper td.cn, .paper th.cn { text-align: center; white-space: nowrap; }
.paper td.rn { text-align: right; white-space: nowrap; }
.paper .c-no { width: 13mm; } .paper .c-unit { width: 21mm; } .paper .c-q { width: 23mm; } .paper .c-note { width: 26mm; }
.paper tr.blank td { height: 8.2mm; }
.paper .codes { font-size: 10.5pt; color: #222; }
.paper .sigs { display: grid; grid-template-columns: 1fr 1fr; gap: 6mm 8mm; margin-top: 8mm; text-align: center; break-inside: avoid; }
.paper .sigs .wide { grid-column: 1 / -1; }
.paper .sigs .right-col { grid-column: 2; }
.paper .meta { font-size: 10pt; color: #333; margin-top: 4mm; }
.paper .kvp { display: grid; grid-template-columns: 1fr 1fr; gap: 0 8mm; margin-bottom: 2mm; }
.paper .small { font-size: 11pt; }
/* Draft / cancelled: a mark across every page, on screen and on paper. */
.watermark { position: fixed; top: 38%; left: 0; right: 0; text-align: center; font-family: "Sarabun", sans-serif; font-size: 96pt; font-weight: 800; color: rgba(190, 30, 30, .16); transform: rotate(-24deg); pointer-events: none; z-index: 5; letter-spacing: .1em; }
.paper .stamp { border: 2px solid #b3221f; color: #b3221f; padding: 1mm 3mm; display: inline-block; font-weight: 700; }
body.print-page { background: #e9edef; }
.print-bar { max-width: 210mm; margin: 1rem auto; display: flex; gap: .5rem; align-items: center; }
/* 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; }
}


@media (max-width: 991.98px) {
  .app-content { padding: 1.25rem 1rem 2.5rem; }
  .topbar { padding: .65rem 1rem; }
}
@media (max-width: 575.98px) {
  .page-header h1 { font-size: 1.4rem; }
  .kv { grid-template-columns: 1fr; gap: 0; }
  .kv dd { margin-bottom: .5rem; }
  .paper { padding: 6mm; font-size: 11pt; }
  .watermark { font-size: 54pt; }
}

@page { size: A4 portrait; margin: 12mm 12mm 12mm; }
@media print {
  .print-letterhead { align-items: center; gap: 4mm; margin: 0 0 4mm; padding-bottom: 2mm; border-bottom: 1px solid #000; font-family: "Sarabun", system-ui, sans-serif; color: #000; }
  .print-letterhead img { height: 16mm; width: auto; }
  body, body.app, body.print-page { background: #fff; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  .app-shell { display: block; min-height: 0; }
  .app-content { padding: 0; }
  .paper { max-width: none; margin: 0; padding: 0; border: 0; border-radius: 0; }
  .paper tr, .paper .sigs, .paper .keep { break-inside: avoid; }
  .card { border: 0; box-shadow: none; }
  a { color: inherit; text-decoration: none; }
  .table { font-size: 10pt; }
}
