/* ============================================================
   ລະບົບຈັດການ ແລະ ຕິດຕາມສາງອາໄຫຼ່  —  Stylesheet
   Theme anchor: #1A2CA3 (deep indigo)
   Font: Noto Sans Lao Looped
   ============================================================ */

:root {
  /* Brand */
  --brand:       #1A2CA3;
  --brand-700:   #15217E;
  --brand-800:   #101A66;
  --brand-50:    #EEF0FB;
  --brand-100:   #DCE0F6;
  --brand-200:   #BFC6EE;

  /* Neutrals */
  --ink:         #1B1E2B;
  --muted:       #6A7180;
  --muted-2:     #9097A6;
  --line:        #E4E7F0;
  --line-2:      #EEF0F5;
  --bg:          #F5F6FB;
  --surface:     #FFFFFF;
  --surface-2:   #FAFBFD;

  /* Status */
  --ok:          #138A52;  --ok-bg:     #E6F4EC;
  --warn:        #B26A00;  --warn-bg:   #FBF0DB;
  --danger:      #C5303A;  --danger-bg: #FBE9EA;
  --info:        #1A2CA3;  --info-bg:   #EEF0FB;

  /* Shape */
  --radius:      12px;
  --radius-sm:   8px;
  --radius-lg:   16px;
  --shadow-sm:   0 1px 2px rgba(20,26,70,.06), 0 1px 3px rgba(20,26,70,.05);
  --shadow:      0 4px 14px rgba(20,26,70,.08);
  --shadow-lg:   0 18px 50px rgba(16,22,60,.22);

  --sidebar-w:   248px;
  --topbar-h:    62px;

  --font: 'Noto Sans Lao Looped', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

h1, h2, h3, h4 { margin: 0; font-weight: 700; line-height: 1.25; }
a { color: var(--brand); text-decoration: none; }
button { font-family: inherit; }
.num { font-variant-numeric: tabular-nums; }
.mono { font-variant-numeric: tabular-nums; letter-spacing: .02em; }

.hidden { display: none !important; }

/* Scrollbars */
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #C9CEDC; border-radius: 20px; border: 2px solid var(--bg); }
::-webkit-scrollbar-thumb:hover { background: #B2B9CC; }

/* ============================================================
   LOGIN
   ============================================================ */
.login-wrap {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr .95fr;
  background: var(--bg);
}
.login-aside {
  position: relative;
  background: linear-gradient(160deg, var(--brand) 0%, var(--brand-700) 60%, var(--brand-800) 100%);
  color: #fff;
  padding: 56px 60px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  overflow: hidden;
}
.login-aside::after {
  content: "";
  position: absolute; inset: 0;
  background-image:
    radial-gradient(circle at 85% 15%, rgba(255,255,255,.10), transparent 38%),
    radial-gradient(circle at 10% 90%, rgba(255,255,255,.07), transparent 40%);
  pointer-events: none;
}
.login-aside .brand-lockup { display: flex; align-items: center; gap: 14px; position: relative; z-index: 1; }
.login-aside .brand-name { font-size: 18px; font-weight: 700; letter-spacing: .2px; }
.login-hero { position: relative; z-index: 1; }
.login-hero h1 { font-size: 30px; line-height: 1.3; margin-bottom: 14px; }
.login-hero p { color: rgba(255,255,255,.82); font-size: 15px; max-width: 30ch; }
.login-feat { position: relative; z-index: 1; display: flex; flex-direction: column; gap: 12px; }
.login-feat div { display: flex; align-items: center; gap: 11px; color: rgba(255,255,255,.9); font-size: 14px; }
.login-feat i { width: 30px; height: 30px; display: grid; place-items: center; background: rgba(255,255,255,.13); border-radius: 8px; font-size: 13px; }

.login-main { display: grid; place-items: center; padding: 32px; }
.login-card { width: 100%; max-width: 380px; }
.login-card .lc-head { margin-bottom: 26px; }
.login-card h2 { font-size: 22px; margin-bottom: 6px; }
.login-card .lc-sub { color: var(--muted); font-size: 14px; }
.login-card .brand-lockup-sm { display: none; align-items: center; gap: 12px; margin-bottom: 26px; }

.login-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #F3C9CC;
  padding: 11px 13px;
  border-radius: var(--radius-sm);
  font-size: 13.5px;
  margin-bottom: 16px;
  display: flex; align-items: center; gap: 9px;
}

.nav-badge {
  margin-left: auto;
  background: var(--danger);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 1px 7px;
  border-radius: 99px;
  min-width: 20px;
  text-align: center;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.notif-wrap {
  position: relative;
}

.notif-btn {
  background: var(--surface-2);
  border: 1px solid var(--line);
  width: 38px;
  height: 38px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  position: relative;
}
.notif-btn i {
  font-size: 15px;
  color: var(--ink);
}
.notif-btn:hover {
  background: var(--brand-50);
}

.notif-dot {
  position: absolute;
  top: -4px;
  right: -4px;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  border-radius: 99px;
  background: var(--danger);
  color: #fff;
  font-size: 10px;
  font-weight: 700;
  display: none;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--surface-1);
}

.notif-panel {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  width: 280px;
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: var(--radius-md);
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  z-index: 1000;
  max-height: 320px;
  overflow-y: auto;
}

.notif-panel.hidden {
  display: none;
}
.notif-head {
  padding: 12px 14px;
  font-weight: 700;
  font-size: 13px;
  border-bottom: 1px solid var(--line-2);
}
.notif-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 11px 14px;
  cursor: pointer;
  font-size: 13px;
  border-bottom: 1px solid var(--line-2);
}
.notif-item:hover {
  background: var(--surface-2);
}
.notif-item:last-child {
  border-bottom: none;
}
.notif-empty {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 20px 14px;
  color: var(--muted);
  font-size: 13px;
  justify-content: center;
}

/* ============================================================
   BRAND MARK (stacked crates glyph)
   ============================================================ */
.brand-mark {
  flex: none;
  display: grid;
  place-items: center;
  background: #fff;
  border-radius: 11px;
  box-shadow: 0 2px 8px rgba(16,22,60,.18);
}
.brand-mark svg { display: block; }

/* ============================================================
   APP SHELL
   ============================================================ */
.app { display: flex; min-height: 100vh; }

/* Sidebar */
.sidebar {
  width: var(--sidebar-w);
  flex: none;
  background: linear-gradient(180deg, var(--brand) 0%, var(--brand-700) 78%, var(--brand-800) 100%);
  color: #EAEDFB;
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 50;
}
.sb-head {
  display: flex; align-items: center; gap: 12px;
  padding: 16px 18px;
  height: var(--topbar-h);
  border-bottom: 1px solid rgba(255,255,255,.10);
}
.sb-head .brand-name { font-size: 15px; font-weight: 700; color: #fff; line-height: 1.2; }
.sb-head .brand-name small { display: block; font-size: 11px; font-weight: 500; color: rgba(255,255,255,.62); }

.sb-nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.sb-nav::-webkit-scrollbar-thumb { background: rgba(255,255,255,.18); border-color: transparent; }
.nav-section-label {
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .9px;
  color: rgba(255,255,255,.45); padding: 14px 12px 7px; font-weight: 600;
}
.nav-item {
  display: flex; align-items: center; gap: 12px;
  padding: 9px 12px; margin: 2px 0;
  border-radius: var(--radius-sm);
  color: rgba(255,255,255,.82);
  font-size: 14px; font-weight: 500;
  cursor: pointer;
  transition: background .14s, color .14s;
  user-select: none;
}
.nav-item i { width: 18px; text-align: center; font-size: 14.5px; opacity: .9; }
.nav-item:hover { background: rgba(255,255,255,.10); color: #fff; }
.nav-item.active { background: #fff; color: var(--brand); font-weight: 600; }
.nav-item.active i { opacity: 1; }

.sb-foot { padding: 12px 12px 14px; border-top: 1px solid rgba(255,255,255,.10); }
.sb-user {
  display: flex; align-items: center; gap: 11px;
  padding: 8px 10px; border-radius: var(--radius-sm);
  cursor: pointer; transition: background .14s;
}
.sb-user:hover { background: rgba(255,255,255,.10); }
.sb-avatar {
  width: 36px; height: 36px; flex: none; border-radius: 50%;
  background: rgba(255,255,255,.18); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 14px;
}
.sb-user-meta { min-width: 0; flex: 1; }
.sb-user-meta b { display: block; color: #fff; font-size: 13.5px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user-meta span { display: block; color: rgba(255,255,255,.6); font-size: 11.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sb-user .fa-chevron-down { color: rgba(255,255,255,.55); font-size: 11px; }

/* Sidebar overlay (mobile) */
.sb-overlay {
  display: none; position: fixed; inset: 0;
  background: rgba(16,22,60,.45); z-index: 49;
}

/* Main */
.main {
  flex: 1; min-width: 0;
  margin-left: var(--sidebar-w);
  display: flex; flex-direction: column;
}

.topbar {
  height: var(--topbar-h);
  position: sticky; top: 0; z-index: 30;
  background: rgba(255,255,255,.86);
  backdrop-filter: saturate(180%) blur(8px);
  border-bottom: 1px solid var(--line);
  display: flex; align-items: center; gap: 14px;
  padding: 0 22px;
}
.menu-btn {
  display: none; border: none; background: transparent; color: var(--ink);
  font-size: 19px; padding: 8px; border-radius: 8px; cursor: pointer;
}
.menu-btn:hover { background: var(--brand-50); }
.topbar h1 { font-size: 18px; font-weight: 700; }
.topbar .tb-sub { color: var(--muted); font-size: 12.5px; margin-top: 1px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 9px; }

.content { padding: 22px; flex: 1; }
.content-narrow { max-width: 1180px; }

/* ============================================================
   BUTTONS
   ============================================================ */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 9px 15px; border-radius: var(--radius-sm);
  border: 1px solid transparent; background: var(--surface);
  color: var(--ink); font-size: 13.5px; font-weight: 600;
  cursor: pointer; white-space: nowrap;
  transition: background .14s, border-color .14s, box-shadow .14s, opacity .14s;
}
.btn i { font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-primary { background: var(--brand); color: #fff; box-shadow: var(--shadow-sm); }
.btn-primary:hover:not(:disabled) { background: var(--brand-700); }
.btn-outline { background: var(--surface); border-color: var(--line); color: var(--ink); }
.btn-outline:hover:not(:disabled) { border-color: var(--brand-200); background: var(--brand-50); color: var(--brand); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover:not(:disabled) { background: var(--brand-50); color: var(--brand); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { background: #A8262F; }
.btn-danger-soft { background: var(--danger-bg); color: var(--danger); }
.btn-danger-soft:hover:not(:disabled) { background: #F6D9DB; }
.btn-sm { padding: 6px 11px; font-size: 12.5px; border-radius: 7px; }
.btn-icon { padding: 7px 9px; }
.btn-block { width: 100%; }

/* icon-only action button in tables */
.act-btn {
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  width: 30px; height: 30px; border-radius: 7px; cursor: pointer;
  display: inline-grid; place-items: center; font-size: 12.5px;
  transition: all .14s;
}
.act-btn:hover { color: var(--brand); border-color: var(--brand-200); background: var(--brand-50); }
.act-btn.danger:hover { color: var(--danger); border-color: #F0C7CA; background: var(--danger-bg); }

/* ============================================================
   CARDS / PANELS
   ============================================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.card-pad { padding: 18px; }
.panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.panel-head {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 18px; border-bottom: 1px solid var(--line);
}
.panel-head h3 { font-size: 15px; }
.panel-head .ph-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; }
.panel-body { padding: 18px; }
.panel-body.flush { padding: 0; }

/* Stat cards */
.stat-grid {
  display: grid; gap: 16px;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  margin-bottom: 18px;
}
.stat {
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 16px 18px;
  box-shadow: var(--shadow-sm);
  position: relative; overflow: hidden;
}
.stat::before {
  content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px;
  background: var(--brand);
}
.stat.ok::before { background: var(--ok); }
.stat.warn::before { background: var(--warn); }
.stat.danger::before { background: var(--danger); }
.stat-top { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.stat-label { color: var(--muted); font-size: 13px; font-weight: 500; }
.stat-ico {
  width: 38px; height: 38px; border-radius: 10px; display: grid; place-items: center;
  background: var(--brand-50); color: var(--brand); font-size: 16px;
}
.stat.ok .stat-ico { background: var(--ok-bg); color: var(--ok); }
.stat.warn .stat-ico { background: var(--warn-bg); color: var(--warn); }
.stat.danger .stat-ico { background: var(--danger-bg); color: var(--danger); }
.stat-value { font-size: 26px; font-weight: 700; letter-spacing: -.4px; font-variant-numeric: tabular-nums; }
.stat-value small { font-size: 13px; font-weight: 600; color: var(--muted); margin-left: 3px; }
.stat-foot { color: var(--muted-2); font-size: 12px; margin-top: 4px; }

.grid-2 { display: grid; grid-template-columns: 1.4fr 1fr; gap: 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 16px; }

/* ============================================================
   TABLES
   ============================================================ */
.table-scroll { width: 100%; overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 13.5px; }
table.tbl thead th {
  text-align: left; font-weight: 600; color: var(--muted);
  font-size: 12px; text-transform: uppercase; letter-spacing: .4px;
  padding: 11px 14px; background: var(--surface-2);
  border-bottom: 1px solid var(--line); white-space: nowrap;
}
table.tbl tbody td {
  padding: 11px 14px; border-bottom: 1px solid var(--line-2);
  vertical-align: middle;
}
table.tbl tbody tr:last-child td { border-bottom: none; }
table.tbl tbody tr { transition: background .12s; }
table.tbl tbody tr:hover { background: var(--brand-50); }
table.tbl tfoot td {
  padding: 13px 14px;
  background: var(--surface-2);
  border-top: 2px solid var(--line);
}
table.tbl td.right, table.tbl th.right { text-align: right; padding-right: 18px; }
table.tbl td.center, table.tbl th.center { text-align: center; }
table.tbl td.num { font-variant-numeric: tabular-nums; }
.cell-strong { font-weight: 600; color: var(--ink); }
.cell-sub { color: var(--muted); font-size: 12px; }
.cell-code {
  font-variant-numeric: tabular-nums; letter-spacing: .03em;
  font-weight: 600; color: var(--brand);
}
.row-actions { display: flex; gap: 6px; justify-content: flex-end; }

/* ============================================================
   BADGES / PILLS
   ============================================================ */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 9px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
  background: var(--brand-50); color: var(--brand);
}
.badge i { font-size: 8px; }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.badge.muted { background: #EEF0F5; color: var(--muted); }
.badge.in { background: var(--ok-bg); color: var(--ok); }
.badge.out { background: var(--danger-bg); color: var(--danger); }
.badge.adjust { background: var(--brand-50); color: var(--brand); }
.badge.transfer { background: var(--warn-bg); color: var(--warn); }

/* ============================================================
   FORMS
   ============================================================ */
.form-grid { display: grid; gap: 15px; }
.form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field.span-2 { grid-column: 1 / -1; }
.field label { font-size: 13px; font-weight: 600; color: var(--ink); }
.field label .req { color: var(--danger); margin-left: 2px; }
.field .hint { font-size: 11.5px; color: var(--muted); }

.input, .select, .textarea {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  font-family: inherit; font-size: 14px; color: var(--ink);
  background: var(--surface);
  transition: border-color .14s, box-shadow .14s;
}
.input:focus, .select:focus, .textarea:focus {
  outline: none; border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(26,44,163,.12);
}
.input::placeholder, .textarea::placeholder { color: var(--muted-2); }
.textarea { resize: vertical; min-height: 78px; }
select.select { appearance: none; background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'><path d='M2 4l4 4 4-4' stroke='%236A7180' stroke-width='1.6' fill='none' stroke-linecap='round' stroke-linejoin='round'/></svg>"); background-repeat: no-repeat; background-position: right 12px center; padding-right: 32px; }
.input-icon { position: relative; }
.input-icon i { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted-2); font-size: 13px; }
.input-icon .input { padding-left: 34px; }

.checkbox-row { display: flex; align-items: center; gap: 9px; }
.checkbox-row input { width: 17px; height: 17px; accent-color: var(--brand); }
.checkbox-row label { font-weight: 500; font-size: 13.5px; }

/* Toolbar above tables */
.toolbar {
  display: flex; align-items: center; gap: 10px; flex-wrap: nowrap;
  margin-bottom: 16px;
}
.toolbar .grow { flex: 1; min-width: 180px; }
.toolbar .search { max-width: 320px; flex: 1; min-width: 160px; }
.toolbar select.select {
  flex: 0 0 auto;
  width: auto;
  max-width: 220px;
}
.filter-chips { display: flex; gap: 7px; flex-wrap: nowrap; flex-shrink: 0; }
.chip {
  padding: 6px 13px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--muted); font-size: 13px; font-weight: 500; cursor: pointer;
  transition: all .14s; white-space: nowrap; flex-shrink: 0;
}
.chip:hover { border-color: var(--brand-200); color: var(--brand); }
.chip.active { background: var(--brand); color: #fff; border-color: var(--brand); }

/* ============================================================
   MODAL
   ============================================================ */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(16,22,60,.48);
  display: grid; place-items: center; padding: 20px;
  animation: fade .16s ease;
}
@keyframes fade { from { opacity: 0; } }
.modal {
  background: var(--surface); border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%; max-width: 540px;
  max-height: 90vh; display: flex; flex-direction: column;
  animation: pop .18s cubic-bezier(.2,.8,.3,1.1);
}
.modal.lg { max-width: 880px; }
.modal.sm { max-width: 420px; }
@keyframes pop { from { transform: translateY(10px) scale(.98); opacity: 0; } }
.modal-head {
  display: flex; align-items: center; gap: 12px;
  padding: 17px 20px; border-bottom: 1px solid var(--line);
}
.modal-head h3 { font-size: 16.5px; flex: 1; }
.modal-head .x {
  border: none; background: transparent; color: var(--muted);
  width: 32px; height: 32px; border-radius: 8px; cursor: pointer; font-size: 15px;
}
.modal-head .x:hover { background: var(--brand-50); color: var(--brand); }
.modal-body { padding: 20px; overflow-y: auto; }
.modal-foot {
  display: flex; gap: 10px; justify-content: flex-end;
  padding: 15px 20px; border-top: 1px solid var(--line);
  background: var(--surface-2); border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ============================================================
   TOAST
   ============================================================ */
.toast-wrap {
  position: fixed; bottom: 22px; right: 22px; z-index: 200;
  display: flex; flex-direction: column; gap: 10px;
}
.toast {
  display: flex; align-items: center; gap: 11px;
  background: var(--ink); color: #fff;
  padding: 12px 16px; border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg); font-size: 13.5px; font-weight: 500;
  min-width: 240px; max-width: 380px;
  animation: toastIn .22s cubic-bezier(.2,.8,.3,1.1);
}
@keyframes toastIn { from { transform: translateX(20px); opacity: 0; } }
.toast.out-anim { animation: toastOut .2s ease forwards; }
@keyframes toastOut { to { transform: translateX(20px); opacity: 0; } }
.toast i { font-size: 15px; }
.toast.ok i { color: #5EE0A0; }
.toast.err i { color: #FF8A92; }
.toast.info i { color: #9DB0FF; }

/* ============================================================
   EMPTY / LOADING
   ============================================================ */
.empty {
  text-align: center; padding: 48px 24px; color: var(--muted);
}
.empty .ei {
  width: 60px; height: 60px; border-radius: 16px; margin: 0 auto 14px;
  background: var(--brand-50); color: var(--brand-200);
  display: grid; place-items: center; font-size: 24px;
}
.empty h4 { color: var(--ink); font-size: 15px; margin-bottom: 5px; }
.empty p { font-size: 13.5px; max-width: 36ch; margin: 0 auto 16px; }

.skeleton { padding: 40px; display: grid; place-items: center; color: var(--muted); }
.spinner {
  width: 30px; height: 30px; border: 3px solid var(--brand-100);
  border-top-color: var(--brand); border-radius: 50%;
  animation: spin .7s linear infinite; margin-bottom: 12px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Page-load splash */
#boot {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: var(--bg); z-index: 500;
}
#boot .spinner { width: 38px; height: 38px; }

/* ============================================================
   DOCUMENT EDITOR — items table
   ============================================================ */
.items-editor { border: 1px solid var(--line); border-radius: var(--radius-sm); overflow: hidden; }
.items-editor table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.items-editor th {
  background: var(--surface-2); text-align: left; font-size: 11.5px; font-weight: 600;
  color: var(--muted); text-transform: uppercase; letter-spacing: .4px;
  padding: 9px 10px; border-bottom: 1px solid var(--line);
}
.items-editor td { padding: 6px 8px; border-bottom: 1px solid var(--line-2); vertical-align: middle; }
.items-editor tr:last-child td { border-bottom: none; }
.items-editor .input, .items-editor .select { padding: 7px 9px; font-size: 13px; }
.items-editor td.amt { font-variant-numeric: tabular-nums; font-weight: 600; text-align: right; white-space: nowrap; }
.items-foot { display: flex; justify-content: space-between; align-items: center; padding: 12px 14px; background: var(--surface-2); }
.items-total { font-size: 15px; font-weight: 700; }
.items-total span { color: var(--muted); font-weight: 500; font-size: 13px; margin-right: 8px; }

/* permission matrix */
.matrix-wrap { overflow-x: auto; }
table.matrix { border-collapse: collapse; width: 100%; font-size: 13px; }
table.matrix th, table.matrix td { border: 1px solid var(--line); padding: 8px 10px; }
table.matrix thead th { background: var(--surface-2); font-weight: 600; color: var(--muted); font-size: 12px; }
table.matrix .mod-cell { font-weight: 600; color: var(--ink); white-space: nowrap; background: var(--surface-2); }
table.matrix td.center { text-align: center; }
table.matrix input[type=checkbox] { width: 17px; height: 17px; accent-color: var(--brand); cursor: pointer; }
table.matrix .perm-label { font-size: 11px; color: var(--muted); display: block; margin-top: 2px; }

.role-list { display: flex; flex-direction: column; gap: 8px; }
.role-item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px;
  border: 1px solid var(--line); border-radius: var(--radius-sm); cursor: pointer;
  transition: all .14s; background: var(--surface);
}
.role-item:hover { border-color: var(--brand-200); background: var(--brand-50); }
.role-item.active { border-color: var(--brand); background: var(--brand-50); box-shadow: 0 0 0 1px var(--brand); }
.role-ico { width: 38px; height: 38px; border-radius: 10px; background: var(--brand-50); color: var(--brand); display: grid; place-items: center; font-size: 15px; flex: none; }
.role-item.active .role-ico { background: var(--brand); color: #fff; }
.role-meta { flex: 1; min-width: 0; }
.role-meta b { display: block; font-size: 14px; }
.role-meta span { font-size: 12px; color: var(--muted); }

/* description list (document detail) */
.dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 18px; font-size: 13.5px; }
.dl dt { color: var(--muted); }
.dl dd { margin: 0; font-weight: 500; }

.section-title { font-size: 13px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .5px; margin: 4px 0 12px; }

/* ============================================================
   RESPONSIVE
   ============================================================ */
@media (max-width: 980px) {
  :root { --sidebar-w: 0px; }
  .sidebar {
    transform: translateX(-100%);
    transition: transform .22s ease;
    width: 264px;
    box-shadow: var(--shadow-lg);
  }
  body.nav-open .sidebar { transform: translateX(0); }
  body.nav-open .sb-overlay { display: block; }
  .main { margin-left: 0; }
  .menu-btn { display: inline-grid; place-items: center; }
  .grid-2, .grid-3 { grid-template-columns: 1fr; }
  .form-grid.cols-2 { grid-template-columns: 1fr; }
  .content { padding: 16px; }
  .topbar { padding: 0 14px; }

  .toolbar {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 4px;
  }
  .toolbar .search { min-width: 140px; }

  .stat-grid {
    grid-template-columns: repeat(2, 1fr);
  }

  .items-editor { overflow-x: auto; }
  .items-editor table { min-width: 640px; }
}

@media (max-width: 780px) {
  .login-wrap { grid-template-columns: 1fr; }
  .login-aside { display: none; }
  .login-card .brand-lockup-sm { display: flex; }

  .dl { grid-template-columns: 1fr; gap: 2px 0; }
  .dl dt { margin-top: 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .3px; }
  .dl dt:first-child { margin-top: 0; }

  .modal, .modal.lg, .modal.xl, .modal.xxl {
    max-width: 100%;
    width: calc(100% - 24px);
    max-height: 92vh;
  }
}
@media (max-width: 520px) {
  .topbar h1 { display: none; }
  .topbar .tb-sub { display: none; }
  .stat-value { font-size: 22px; }
  .modal-foot { flex-direction: column-reverse; }
  .modal-foot .btn { width: 100%; }
  .topbar-actions .btn span.btn-text { display: none; }

  .topbar > div:not(.topbar-actions):not(.menu-btn) {
    flex: 0 0 auto;
  }
  .topbar-actions {
    flex: 1;
    justify-content: flex-end;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }
  .roles-layout, .settings-grid {
    grid-template-columns: 1fr;
  }
  .form-grid { gap: 12px; }
  .notif-panel {
    width: calc(100vw - 32px);
    right: -8px;
  }
  .date-range { flex-wrap: wrap; }
  .date-range .input { min-width: 120px; flex: 1; }

  /* ===== toolbar stack ເປັນຖັນໃນຈໍນ້ອຍ ===== */
  .toolbar {
    flex-wrap: wrap;
    overflow-x: visible;
  }
  .toolbar .input-icon.search,
  .toolbar .search {
    flex: 1 1 100%;
    max-width: 100%;
    min-width: 0;
  }
  .toolbar select.select {
    flex: 1 1 100%;
    max-width: 100%;
    width: 100%;
  }
  .filter-chips {
    flex: 1 1 100%;
    flex-wrap: wrap;
  }
  .toolbar > div[style*="margin-left:auto"] {
    flex: 1 1 100%;
    margin-left: 0 !important;
  }
  .toolbar .btn { width: 100%; }

  /* ===== card view ===== */
  table.tbl.cardable thead { display: none; }
  table.tbl.cardable, table.tbl.cardable tbody, table.tbl.cardable tr, table.tbl.cardable td {
    display: block; width: 100%;
  }
  table.tbl.cardable tr {
    margin-bottom: 12px;
    border: 1px solid var(--line);
    border-radius: var(--radius-sm);
    padding: 10px 12px;
    background: var(--surface);
  }
  table.tbl.cardable tr:hover { background: var(--surface); }
  table.tbl.cardable td {
    border: none;
    padding: 7px 0;
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 10px;
    text-align: right;
  }
  table.tbl.cardable td::before {
    content: attr(data-label);
    font-size: 11.5px;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: .3px;
    text-align: left;
    flex-shrink: 0;
  }
  table.tbl.cardable td.right, table.tbl.cardable td.center { text-align: right; padding-right: 0; }
  table.tbl.cardable td.row-actions-cell {
    justify-content: flex-end;
  }
  table.tbl.cardable td.row-actions-cell::before { content: none; }
  table.tbl.cardable .row-actions { justify-content: flex-end; flex-wrap: wrap; }
  table.tbl.cardable tfoot { display: block; }
  table.tbl.cardable tfoot tr { background: var(--surface-2); }
}

/* ============================================================
   PRINT  —  A4 official document
   ============================================================ */
.print-only { display: none; }

@media print {
  @page { size: A4; margin: 14mm 14mm 16mm; }
  body { background: #fff; font-size: 12pt; color: #000; }
  body * { visibility: hidden; }
  #print-area, #print-area * { visibility: visible; }
  #print-area { position: absolute; inset: 0; width: 100%; }
  .no-print, .sidebar, .topbar, .sb-overlay, .toast-wrap, .modal-overlay { display: none !important; }
  .print-only { display: block; }
}

/* Document print layout (also used for on-screen preview) */
.doc-sheet {
  background: #fff; color: #111;
  width: 210mm; min-height: 297mm;
  margin: 0 auto; padding: 16mm;
  font-size: 13px; line-height: 1.55;
}
.doc-sheet.preview {
  box-shadow: var(--shadow); border: 1px solid var(--line);
  border-radius: 6px; max-width: 100%;
}
.doc-head {
  display: flex; justify-content: space-between; align-items: center;
  border-bottom: 2px solid var(--brand); padding-bottom: 12px; margin-bottom: 6px;
}
.doc-org { display: flex; gap: 14px; align-items: center; }
.doc-org .doc-logo {
  width: 90px; height: 90px; border-radius: 50%; background: transparent; color: #fff;
  display: grid; place-items: center; flex: none; overflow: hidden;
}

.doc-org h2 { font-size: 17px; color: var(--brand); margin-bottom: 2px; }
.doc-org .org-line { font-size: 11.5px; color: #444; }
.doc-meta-top { text-align: right; font-size: 11.5px; color: #333; }
.doc-title-bar { text-align: center; margin: 14px 0 4px; }
.doc-title-bar h1 { font-size: 20px; letter-spacing: .5px; color: #111; }
.doc-title-bar .doc-no { font-size: 12px; color: var(--brand); font-weight: 600; margin-top: 3px; }

.doc-info {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px 24px;
  margin: 16px 0; font-size: 12.5px;
}
.doc-info .di { display: flex; gap: 6px; }
.doc-info .di b { min-width: 70px; color: #555; font-weight: 600; flex-shrink: 0; }

table.doc-items { width: 100%; border-collapse: collapse; margin: 10px 0; font-size: 12px; }
table.doc-items th, table.doc-items td { border: 1px solid #BFC4D8; padding: 7px 9px; }
table.doc-items th { background: var(--brand-50); color: var(--brand); font-weight: 700; text-align: left; }
table.doc-items td.r { text-align: right; font-variant-numeric: tabular-nums; }
table.doc-items td.c { text-align: center; }
table.doc-items tfoot td { font-weight: 700; background: #F4F5FB; }

.doc-note { font-size: 12px; margin: 12px 0; }
.doc-note b { color: #555; }

.doc-signs {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 24px;
  margin-top: 40px; text-align: center; font-size: 12px;
}
.doc-signs .sign b { display: block; margin-bottom: 54px; font-weight: 600; }
.doc-signs .sign .line { border-top: 1px dotted #888; padding-top: 5px; color: #555; }
.doc-foot-note { margin-top: 26px; font-size: 10.5px; color: #888; text-align: center; border-top: 1px solid #E0E0E0; padding-top: 8px; }

.doc-signs-2 {
  display: flex;
  justify-content: space-between;
}
.doc-signs-2 .sign {
  flex: 0 0 auto;
  min-width: 160px;
}

/* ===== additions: wide modals, date-range filter ===== */
.modal.xl  { max-width: 1080px; }
.modal.xxl { max-width: 1240px; }

.date-range { display: flex; align-items: center; gap: 6px; }
.date-range .input { width: auto; min-width: 140px; }
.dr-label { font-size: 12.5px; color: var(--muted); font-weight: 500; }

@media (max-width: 600px) {
  .date-range { flex-wrap: wrap; }
  .date-range .input { min-width: 120px; flex: 1; }
}

/* ===== additions: panel foot/title, settings + roles layout, avatar, notice ===== */
.panel-foot {
  display: flex; align-items: center; justify-content: flex-end; gap: 10px;
  padding: 14px 18px; border-top: 1px solid var(--line); background: var(--surface);
}
.ph-title { display: flex; align-items: center; gap: 10px; font-size: 15px; font-weight: 700; }
.ph-title i { color: var(--brand); font-size: 15px; }

.settings-grid { display: grid; grid-template-columns: 1.2fr .8fr; gap: 18px; align-items: start; }

/* roles page */
.roles-layout { display: grid; grid-template-columns: 320px 1fr; gap: 18px; align-items: start; }
.role-pane { min-width: 0; }
.matrix-pane { min-width: 0; }
.pane-title-row { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; }
.pane-head { display: flex; align-items: flex-start; gap: 14px; }
.pane-foot { display: flex; gap: 10px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--line); }
.role-ico.lg { width: 48px; height: 48px; border-radius: 13px; font-size: 19px; }

.notice {
  display: flex; align-items: flex-start; gap: 10px;
  background: var(--brand-50); border: 1px solid var(--brand-100);
  color: var(--brand-700); padding: 12px 14px; border-radius: var(--radius-sm); font-size: 13.5px;
}
.notice i { margin-top: 1px; }

/* avatar (used in users table) */
.user-cell { display: flex; align-items: center; gap: 11px; }
.avatar {
  width: 40px; height: 40px; flex: none; border-radius: 50%;
  background: var(--brand-50); color: var(--brand);
  display: grid; place-items: center; font-weight: 700; font-size: 15px; text-transform: uppercase;
}
.avatar.sm { width: 32px; height: 32px; font-size: 13px; }

@media (max-width: 980px) {
  .settings-grid { grid-template-columns: 1fr; }
  .roles-layout { grid-template-columns: 1fr; }
}