/* =====================================================================
   style.css — ระบบเบิกจ่ายเงินสดย่อยสาขา
   ===================================================================== */
:root {
  --bg: #f2f5fa;
  --panel: #ffffff;
  --ink: #0f172a;
  --ink-soft: #334155;
  --muted: #64748b;
  --line: #e3e9f2;
  --brand: #0d9488;
  --brand-2: #0f766e;
  --accent: #4f46e5;
  --success: #16a34a;
  --warn: #d97706;
  --danger: #dc2626;
  --info: #2563eb;
  --side: #0b1b2b;
  --side-2: #12283d;
  --radius: 14px;
  --shadow: 0 1px 2px rgba(15, 23, 42, .05), 0 10px 26px rgba(15, 23, 42, .06);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Sarabun', 'Segoe UI', 'Leelawadee UI', system-ui, -apple-system, sans-serif;
  font-size: 15px;
  line-height: 1.55;
}

h1, h2, h3, h4 { margin: 0; font-weight: 600; }
p { margin: 0; }
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

.muted { color: var(--muted); }
.hidden { display: none !important; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

/* ------------------------------ layout ------------------------------ */
.app {
  display: grid;
  grid-template-columns: 268px 1fr;
  min-height: 100vh;
}

.sidebar {
  position: sticky;
  top: 0;
  align-self: start;
  height: 100vh;
  display: flex;
  flex-direction: column;
  gap: 18px;
  padding: 22px 18px;
  background: linear-gradient(180deg, var(--side) 0%, var(--side-2) 100%);
  color: #e2e8f0;
  overflow-y: auto;
}

.brand { display: flex; align-items: center; gap: 12px; }

/* ---------------- กล่องผู้ใช้ (มุมบนซ้ายของ Sidebar) ---------------- */
.user-box {
  display: flex; flex-direction: column; gap: 9px;
  padding: 10px 11px;
  border-radius: 12px;
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .1);
  max-width: 340px;
}
.user-box:empty { display: none; }
.user-box .ub-top { display: flex; align-items: center; gap: 9px; min-width: 0; }
.user-box .ub-ava {
  width: 34px; height: 34px; flex: 0 0 34px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #14b8a6, #0ea5e9);
  color: #042522; font-weight: 700; font-size: 14px;
  box-shadow: 0 4px 12px rgba(20, 184, 166, .3);
}
.user-box .ub-who { min-width: 0; display: flex; flex-direction: column; line-height: 1.3; }
.user-box .ub-who strong {
  font-size: 13px; font-weight: 600; color: #f1f5f9;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-box .ub-who span {
  font-size: 10.5px; color: #8fb0c9;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.user-box .ub-actions { display: flex; gap: 6px; }
.user-box .ub-btn {
  flex: 1; min-width: 0;
  display: inline-flex; align-items: center; justify-content: center; gap: 4px;
  padding: 6px 6px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, .16);
  background: rgba(255, 255, 255, .08);
  color: #dbe6ef; font: inherit; font-size: 11.5px; font-weight: 500;
  cursor: pointer; white-space: nowrap;
  transition: background .15s, border-color .15s, color .15s;
}
.user-box .ub-btn:hover { background: rgba(255, 255, 255, .18); color: #fff; }
.user-box .ub-btn.danger { color: #fecaca; border-color: rgba(248, 113, 113, .32); }
.user-box .ub-btn.danger:hover { background: rgba(239, 68, 68, .2); color: #fff; }
.user-box .ub-btn .ico { font-size: 12.5px; }
.brand-logo {
  width: 42px; height: 42px; border-radius: 12px;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #14b8a6, #0f766e);
  color: #fff; font-size: 22px; font-weight: 700;
  box-shadow: 0 6px 18px rgba(20, 184, 166, .35);
}
.brand-text { display: flex; flex-direction: column; line-height: 1.25; }
.brand-text strong { font-size: 15px; letter-spacing: .1px; }
.brand-text span { font-size: 11.5px; color: #7c9cb8; letter-spacing: .4px; text-transform: uppercase; }

.nav { display: flex; flex-direction: column; gap: 4px; }
.nav-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px;
  border: 0; border-radius: 10px;
  background: transparent; color: #b6c8d9;
  font-size: 14.5px; text-align: left; cursor: pointer;
  transition: background .15s, color .15s, transform .1s;
}
.nav-item:hover { background: rgba(255, 255, 255, .07); color: #fff; }
.nav-item.active { background: linear-gradient(90deg, rgba(20, 184, 166, .22), rgba(20, 184, 166, .06)); color: #fff; box-shadow: inset 3px 0 0 #14b8a6; }
.nav-item .ico { font-size: 16px; width: 20px; text-align: center; }
.nav-count {
  margin-left: auto;
  min-width: 22px; height: 20px; padding: 0 6px;
  border-radius: 999px; background: #ef4444; color: #fff;
  font-size: 11.5px; font-weight: 600;
  display: grid; place-items: center;
}
.nav-count.zero { display: none; }

.fund-mini {
  background: rgba(255, 255, 255, .06);
  border: 1px solid rgba(255, 255, 255, .08);
  border-radius: 12px;
  padding: 12px 14px;
}
.fund-mini .lbl { font-size: 11.5px; color: #8fb0c9; letter-spacing: .3px; }
.fund-mini .val { font-size: 20px; font-weight: 600; color: #5eead4; font-variant-numeric: tabular-nums; }
.fund-mini .bar { height: 6px; border-radius: 999px; background: rgba(255, 255, 255, .12); margin-top: 8px; overflow: hidden; }
.fund-mini .bar > i { display: block; height: 100%; background: linear-gradient(90deg, #14b8a6, #22d3ee); }
.fund-mini .sub { font-size: 11.5px; color: #7c9cb8; margin-top: 6px; }

.role-box { display: flex; flex-direction: column; gap: 8px; }
.role-box label { font-size: 11.5px; color: #8fb0c9; letter-spacing: .3px; }
.role-box select {
  width: 100%;
  padding: 9px 10px;
  border-radius: 9px;
  border: 1px solid rgba(255, 255, 255, .14);
  background: rgba(255, 255, 255, .07);
  color: #e2e8f0;
  font-size: 13.5px;
}
.role-box select option { color: #0f172a; }
.role-hint { font-size: 11.5px; color: #7c9cb8; line-height: 1.45; }

/* ---------------- ผู้ใช้ที่เข้าสู่ระบบ / หน้า login ---------------- */
.user-chip {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px; border-radius: 10px;
  background: rgba(255, 255, 255, .07);
  border: 1px solid rgba(255, 255, 255, .12);
}
.user-chip .ava {
  width: 32px; height: 32px; flex: 0 0 32px; border-radius: 50%;
  display: grid; place-items: center;
  background: linear-gradient(135deg, #14b8a6, #0ea5e9);
  color: #04201d; font-weight: 700; font-size: 14px;
}
.user-chip .who { min-width: 0; display: flex; flex-direction: column; }
.user-chip .who strong { font-size: 13px; color: #e2e8f0; font-weight: 600; }
.user-chip .who span { font-size: 11px; color: #8fb0c9; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.btn-block { width: 100%; justify-content: center; }

.login-gate {
  position: fixed; inset: 0; z-index: 90;
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  background:
    radial-gradient(1200px 600px at 15% 0%, #10344a 0%, rgba(15, 23, 42, 0) 60%),
    linear-gradient(160deg, #0b2231 0%, #0f172a 55%, #0b1f2a 100%);
}
.login-gate[hidden] { display: none; }
.login-card {
  width: 100%; max-width: 420px;
  background: #fff; border-radius: 16px;
  padding: 26px 26px 22px;
  box-shadow: 0 24px 60px rgba(2, 15, 25, .45);
  display: flex; flex-direction: column; gap: 12px;
}
.login-brand { display: flex; align-items: center; gap: 12px; margin-bottom: 6px; }
.login-brand .brand-logo { width: 42px; height: 42px; border-radius: 12px; font-size: 20px; }
.login-brand strong { display: block; font-size: 15.5px; color: #0f172a; }
.login-brand span { font-size: 11.5px; color: #64748b; letter-spacing: .4px; }
.login-card .btn.lg { margin-top: 4px; }
.login-error {
  background: #fef2f2; border: 1px solid #fecaca; color: #b91c1c;
  border-radius: 9px; padding: 8px 12px; font-size: 13px;
}
.login-hint { font-size: 11.5px; color: #64748b; line-height: 1.6; text-align: center; margin-top: 4px; }
.login-hint code { background: #f1f5f9; border: 1px solid #e2e8f0; border-radius: 4px; padding: 0 4px; }

.sidebar-foot { margin-top: auto; font-size: 11px; color: #5f7d97; line-height: 1.5; }

/* ------------------------------- main ------------------------------- */
.main { padding: 22px 26px 60px; min-width: 0; }

.topbar {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 18px; flex-wrap: wrap;
}
.topbar h1 { font-size: 22px; }
.topbar-left p { font-size: 13.5px; margin-top: 2px; }
.topbar-right { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.date-pill, .balance-pill {
  padding: 8px 14px; border-radius: 999px;
  font-size: 13.5px; border: 1px solid var(--line); background: var(--panel);
  box-shadow: var(--shadow);
}
.balance-pill { font-weight: 600; color: var(--brand-2); border-color: #b7e6e0; background: #f0fdfa; font-variant-numeric: tabular-nums; }

.view { display: none; }
.view.active { display: block; animation: fade .18s ease-out; }
@keyframes fade { from { opacity: 0; transform: translateY(4px); } to { opacity: 1; transform: none; } }

/* ------------------------------- cards ------------------------------ */
.card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 16px;
}
.card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 12px; margin-bottom: 14px; flex-wrap: wrap;
}
.card-head h2 { font-size: 16.5px; }
.card-head .muted { font-size: 13px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 14px;
  margin-bottom: 16px;
}
/* หน้ารับเงิน: การ์ด 4 ใบ แบ่งเป็น 2×2 */
.kpi-grid.k2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
@media (max-width: 720px) { .kpi-grid.k2 { grid-template-columns: 1fr; } }
.kpi {
  position: relative;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  overflow: hidden;
}
.kpi::before {
  content: ''; position: absolute; inset: 0 auto 0 0; width: 4px;
  background: var(--brand);
}
.kpi.k-warn::before { background: var(--warn); }
.kpi.k-info::before { background: var(--info); }
.kpi.k-accent::before { background: var(--accent); }
.kpi .kpi-lbl { font-size: 13px; color: var(--muted); }
.kpi .kpi-val { font-size: 26px; font-weight: 600; margin-top: 4px; font-variant-numeric: tabular-nums; letter-spacing: -.3px; }
.kpi .kpi-sub { font-size: 12.5px; color: var(--muted); margin-top: 2px; }

/* carry-forward strip */
.carry {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 6px;
  align-items: stretch;
}
.carry-item {
  background: #f8fafc;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 12px 14px;
}
.carry-item .lbl { font-size: 12px; color: var(--muted); }
.carry-item .val { font-size: 18px; font-weight: 600; font-variant-numeric: tabular-nums; margin-top: 2px; }
.carry-item.plus .val { color: var(--success); }
.carry-item.minus .val { color: var(--danger); }
.carry-item.result { background: #f0fdfa; border-color: #b7e6e0; }
.carry-item.result .val { color: var(--brand-2); }

/* ------------------------------ tables ------------------------------ */
.table-wrap { overflow-x: auto; }
table.data-table, table.mini-table {
  width: 100%; border-collapse: collapse; font-size: 14px;
}
table.data-table { min-width: 700px; }
table.data-table.table-compact { min-width: 0; font-size: 13px; }
table.data-table.table-compact th,
table.data-table.table-compact td { padding: 7px 6px; }
table.data-table.table-compact .btn.sm { padding: 4px 9px; font-size: 12px; }
table.data-table td:first-child,
table.data-table th:first-child { white-space: nowrap; }
table.data-table th, table.data-table td,
table.mini-table th, table.mini-table td {
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}
table.data-table thead th {
  background: #f8fafc;
  font-size: 12.5px;
  color: var(--muted);
  font-weight: 600;
  white-space: nowrap;
  position: sticky; top: 0;
}
table.data-table tbody tr:hover { background: #fbfdff; }
table.data-table tfoot td { font-weight: 600; background: #f8fafc; }
.table-actions { white-space: nowrap; }
.table-actions .btn { margin-left: 2px; }
table.mini-table { font-size: 13.5px; }
table.mini-table th { font-size: 12px; color: var(--muted); font-weight: 600; }
table.mini-table .total-row td { font-weight: 600; background: #f8fafc; }

.empty {
  padding: 26px; text-align: center; color: var(--muted); font-size: 14px;
  background: #fbfdff; border: 1px dashed var(--line); border-radius: 12px;
}

/* ------------------------------ badges ------------------------------ */
.badge {
  display: inline-block;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
  white-space: nowrap;
  border: 1px solid transparent;
}
.badge.warn { background: #fff7ed; color: #b45309; border-color: #fed7aa; }
.badge.info { background: #eff6ff; color: #1d4ed8; border-color: #bfdbfe; }
.badge.success { background: #f0fdf4; color: #15803d; border-color: #bbf7d0; }
.badge.danger { background: #fef2f2; color: #b91c1c; border-color: #fecaca; }
.badge.muted { background: #f1f5f9; color: #475569; border-color: #e2e8f0; }

/* ------------------------------ buttons ----------------------------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 9px 16px;
  border-radius: 10px;
  border: 1px solid var(--line);
  background: #fff;
  color: var(--ink-soft);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  transition: all .15s;
  white-space: nowrap;
}
.btn:hover { border-color: #cbd5e1; background: #f8fafc; }
.btn.primary {
  background: linear-gradient(135deg, #0d9488, #0f766e);
  border-color: transparent; color: #fff;
  box-shadow: 0 6px 16px rgba(13, 148, 136, .28);
}
.btn.primary:hover { filter: brightness(1.06); }
.btn.accent { background: var(--accent); border-color: transparent; color: #fff; }
.btn.ghost { background: #fff; }
.btn.danger { background: #fff; border-color: #fecaca; color: var(--danger); }
.btn.danger:hover { background: #fef2f2; }
.btn.danger-solid {
  background: linear-gradient(135deg, #ef4444, #dc2626);
  border-color: transparent; color: #fff;
  box-shadow: 0 6px 16px rgba(220, 38, 38, .25);
}
.btn.danger-solid:hover { filter: brightness(1.06); }
.btn.warn {
  background: #f59e0b;
  border-color: #f59e0b;
  color: #3f2a00;
  font-weight: 600;
}
.btn.warn:hover { background: #fbbf24; border-color: #fbbf24; color: #3f2a00; }
.btn.lg { padding: 12px 26px; font-size: 15px; }
.btn.sm { padding: 6px 12px; font-size: 13px; border-radius: 8px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.icon-btn {
  width: 30px; height: 30px; border-radius: 8px;
  border: 1px solid var(--line); background: #fff;
  cursor: pointer; color: var(--muted);
  display: inline-grid; place-items: center; font-size: 13px;
}
.icon-btn:hover { background: #f8fafc; color: var(--ink); }
.icon-btn.danger:hover { color: var(--danger); border-color: #fecaca; background: #fef2f2; }

/* ------------------------------- forms ------------------------------ */
.form { display: flex; flex-direction: column; gap: 14px; }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 14px; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 14px; }

.field { display: flex; flex-direction: column; gap: 5px; }
.field > span { font-size: 13px; color: var(--ink-soft); font-weight: 500; }
.field > span .req { color: var(--danger); }
.req { color: var(--danger); font-style: normal; font-weight: 700; }
.field input, .field select, .field textarea {
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: #fff;
  font-size: 14.5px;
  transition: border-color .15s, box-shadow .15s;
  width: 100%;
}
.field input:focus, .field select:focus, .field textarea:focus {
  outline: none; border-color: #5eead4; box-shadow: 0 0 0 3px rgba(20, 184, 166, .15);
}
/* ช่องที่แก้ไขไม่ได้ → พื้นหลังสีเทา */
.field input:disabled, .field select:disabled, .field textarea:disabled,
.field input[readonly], .field select[readonly], .field textarea[readonly],
input:disabled, select:disabled, textarea:disabled {
  background: #f1f5f9 !important;
  color: #64748b !important;
  border-color: #e2e8f0 !important;
  cursor: not-allowed;
  box-shadow: none !important;
}
.field .hint { font-size: 12px; color: var(--muted); }

.inline { display: inline-flex; align-items: center; gap: 6px; font-size: 13px; color: var(--ink-soft); }
.inline input { padding: 7px 10px; border: 1px solid var(--line); border-radius: 9px; background: #fff; }

.items-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-top: 4px; }
.items-head strong { font-size: 14.5px; }
.items-head .muted { font-size: 12.5px; }

table.items-table { width: 100%; border-collapse: collapse; }
table.items-table th {
  font-size: 12.5px; color: var(--muted); font-weight: 600; text-align: left;
  padding: 8px 8px; border-bottom: 1px solid var(--line); background: #f8fafc;
}
table.items-table th.num { text-align: right; }
table.items-table td { padding: 6px 8px; border-bottom: 1px solid var(--line); }
table.items-table input {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 9px; background: #fff; font-size: 14px;
}
table.items-table select {
  width: 100%; padding: 8px 10px;
  border: 1px solid var(--line); border-radius: 9px; background: #fff; font-size: 13.5px;
}
table.items-table select:focus { outline: none; border-color: #5eead4; box-shadow: 0 0 0 3px rgba(20, 184, 166, .15); }
table.items-table input:focus { outline: none; border-color: #5eead4; box-shadow: 0 0 0 3px rgba(20, 184, 166, .15); }
table.items-table input.num-input { text-align: right; font-variant-numeric: tabular-nums; }

.items-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; }
.grand-total { font-size: 15px; color: var(--ink-soft); }
.grand-total strong { font-size: 22px; color: var(--brand-2); font-variant-numeric: tabular-nums; margin-left: 4px; }
.form-actions { display: flex; justify-content: flex-end; gap: 10px; padding-top: 4px; }

/* ---------------------------- request card -------------------------- */
.req-card { border-left: 4px solid var(--brand); }
.req-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; flex-wrap: wrap; }
.req-head h3 { font-size: 15.5px; display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.req-head p { font-size: 13px; margin-top: 2px; }
.req-amount { font-size: 22px; font-weight: 600; color: var(--brand-2); font-variant-numeric: tabular-nums; }
.req-meta { margin: 12px 0; gap: 12px; }
.req-meta > div { display: flex; flex-direction: column; }
.req-meta .lbl { font-size: 11.5px; color: var(--muted); letter-spacing: .2px; }
.req-meta strong { font-size: 14px; font-weight: 500; }
.req-note { font-size: 13.5px; background: #fffbeb; border: 1px solid #fde68a; color: #92400e; padding: 8px 12px; border-radius: 10px; margin-top: 10px; }
.req-actions { display: flex; gap: 10px; justify-content: flex-end; margin-top: 14px; flex-wrap: wrap; }
.req-timeline { font-size: 12.5px; color: var(--muted); margin-top: 10px; border-top: 1px dashed var(--line); padding-top: 8px; }
.req-timeline div { margin-top: 2px; }

/* ------------------------------ reports ----------------------------- */
.report-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  gap: 14px; flex-wrap: wrap; margin-bottom: 16px;
}
.tabs { display: inline-flex; gap: 4px; padding: 4px; background: #f1f5f9; border-radius: 11px; }
.tabs button {
  border: 0; background: transparent; padding: 8px 16px; border-radius: 8px;
  font-size: 13.5px; color: var(--muted); cursor: pointer; font-weight: 500;
}
.tabs button.active { background: #fff; color: var(--ink); box-shadow: 0 1px 3px rgba(15, 23, 42, .1); }
.toolbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.report-title { font-size: 15px; font-weight: 600; margin-bottom: 4px; }
.report-sub { font-size: 13px; color: var(--muted); margin-bottom: 12px; }
.report-section-title { font-size: 14.5px; font-weight: 600; margin: 22px 0 8px; }

/* ------------------------------ settings ---------------------------- */
.settings-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; }
.setting-block { display: flex; flex-direction: column; gap: 12px; }
.setting-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 0; border-bottom: 1px dashed var(--line); }
.setting-row:last-child { border-bottom: 0; }
.setting-row .lbl { font-size: 13.5px; color: var(--ink-soft); }
.setting-row .lbl small { display: block; color: var(--muted); font-size: 12px; }
.stack { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------------------------- attachments --------------------------- */
.attach-cell { white-space: nowrap; vertical-align: top; }
.attach-list { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.attach-chip {
  display: inline-flex; align-items: center; gap: 2px;
  border: 1px solid var(--line); border-radius: 999px;
  background: #f8fafc; padding: 2px 4px 2px 8px;
  font-size: 12px; max-width: 100%;
}
.attach-chip .chip-main {
  border: 0; background: transparent; cursor: pointer;
  padding: 2px 2px; font-size: 12px; color: var(--info);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 180px;
}
.attach-chip .chip-main:hover { text-decoration: underline; }
.attach-chip .chip-x {
  border: 0; background: transparent; cursor: pointer;
  color: var(--muted); font-size: 11px; padding: 2px 4px; border-radius: 999px;
}
.attach-chip .chip-x:hover { color: var(--danger); background: #fef2f2; }
.modal.modal-wide { max-width: 880px; }
.attach-view { text-align: center; }
.attach-view img { max-width: 100%; max-height: 58vh; border-radius: 10px; border: 1px solid var(--line); }
.attach-frame { width: 100%; height: 58vh; border: 1px solid var(--line); border-radius: 10px; background: #f8fafc; }

/* --------------------------- promptpay qr --------------------------- */
.transfer-grid {
  display: grid;
  grid-template-columns: 268px 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 760px) {
  .transfer-grid { grid-template-columns: 1fr; }
}
.qr-panel {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
  text-align: center;
  box-shadow: inset 0 0 0 1px #f8fafc;
}
.qr-head { display: flex; justify-content: center; align-items: center; gap: 8px; margin-bottom: 8px; }
.qr-box {
  background: #fff;
  border-radius: 10px;
  padding: 4px;
  display: grid;
  place-items: center;
  min-height: 150px;
}
.qr-box svg { width: 100%; height: auto; max-width: 240px; display: block; }
.qr-amount {
  font-size: 19px; font-weight: 600; color: var(--brand-2);
  font-variant-numeric: tabular-nums; margin-top: 8px;
}
.qr-id { font-size: 13px; color: var(--ink-soft); letter-spacing: .3px; font-variant-numeric: tabular-nums; }
.qr-actions { display: flex; justify-content: center; margin-top: 10px; }
.qr-actions .btn { width: 100%; justify-content: center; }
.qr-hint { font-size: 11.5px; line-height: 1.45; margin-top: 6px; }
.qr-error { color: var(--danger); font-size: 12.5px; padding: 12px 8px; line-height: 1.5; }
.transfer-fields { display: flex; flex-direction: column; gap: 14px; }

/* --------------------------- transfer slip -------------------------- */
.slip-box {
  border: 1px dashed #cbd5e1;
  border-radius: 12px;
  padding: 12px 14px;
  background: #fbfdff;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.slip-box .slip-head {
  display: flex; justify-content: space-between; align-items: baseline;
  gap: 10px; flex-wrap: wrap; font-size: 13.5px;
}
.slip-box .slip-head .muted { font-size: 12px; }
.slip-box .attach-list { margin-top: 0; }
.slip-box .slip-required { font-size: 12px; color: var(--danger); }
.slip-box.required-error {
  border-color: #fca5a5;
  background: #fef2f2;
  animation: slipShake .35s ease-in-out;
}
@keyframes slipShake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  50% { transform: translateX(4px); }
  75% { transform: translateX(-3px); }
}

/* ------------------------------- modal ------------------------------ */
#modalRoot .modal-backdrop {
  position: fixed; inset: 0; z-index: 60;
  background: rgba(15, 23, 42, .45);
  display: grid; place-items: center;
  padding: 20px;
  animation: fade .15s ease-out;
}
.modal {
  width: 100%; max-width: 520px;
  background: #fff; border-radius: 16px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .28);
  max-height: 90vh; display: flex; flex-direction: column;
  overflow: hidden;
}
.modal header {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 16px 20px; border-bottom: 1px solid var(--line);
  flex: 0 0 auto;
}
.modal header h3 { font-size: 16px; }
.modal-body { padding: 18px 20px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; min-height: 0; }
.modal footer {
  display: flex; justify-content: flex-end; gap: 10px;
  padding: 14px 20px; border-top: 1px solid var(--line); background: #fbfdff;
  flex: 0 0 auto;
}
.modal .summary-box { background: #f8fafc; border: 1px solid var(--line); border-radius: 12px; padding: 12px 14px; font-size: 13.5px; }
.modal .summary-box .row { display: flex; justify-content: space-between; gap: 12px; padding: 3px 0; }
.modal .summary-box .row strong { font-variant-numeric: tabular-nums; }

/* ------------------------------- toast ------------------------------ */
.toast-wrap {
  position: fixed; right: 20px; bottom: 20px; z-index: 90;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.toast {
  background: #0f172a; color: #fff;
  padding: 11px 16px; border-radius: 11px;
  font-size: 13.5px; max-width: 380px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, .3);
  animation: slideIn .2s ease-out;
  border-left: 4px solid var(--brand);
}
.toast.warn { border-left-color: #f59e0b; }
.toast.error { border-left-color: #ef4444; }
.toast.success { border-left-color: #22c55e; }
@keyframes slideIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* -------------------- คำเตือนกลางจอ (center alert) ------------------- */
.center-alert {
  position: fixed; inset: 0; z-index: 95;
  display: grid; place-items: center;
  padding: 20px;
  background: rgba(15, 23, 42, .4);
  animation: fade .15s ease-out;
}
.center-alert .ca-card {
  width: 100%; max-width: 430px;
  background: #fff; border-radius: 16px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, .3);
  padding: 22px 22px 18px;
  text-align: center;
  border-top: 5px solid var(--brand);
}
.center-alert .ca-card.ca-warn { border-top-color: #f59e0b; }
.center-alert .ca-icon { font-size: 30px; line-height: 1; margin-bottom: 8px; }
.center-alert h4 { font-size: 16.5px; margin: 0 0 8px; }
.center-alert .ca-msg { font-size: 13.8px; color: #475569; line-height: 1.6; }
.center-alert .ca-msg strong { color: #b45309; font-variant-numeric: tabular-nums; }
.center-alert .ca-actions { margin-top: 16px; display: flex; justify-content: center; }

/* ---------------------------- responsive ---------------------------- */
@media (max-width: 1000px) {
  .app { grid-template-columns: 1fr; }
  .sidebar { position: static; height: auto; flex-direction: column; }
  .nav { flex-direction: row; flex-wrap: wrap; }
  .nav-item { flex: 1 1 auto; }
  .main { padding: 18px 14px 50px; }
}

/* ============== ใบสรุปการเบิก–จ่ายเงินสดย่อย (แบบฟอร์ม) ============== */
.ds-toolbar {
  display: flex; align-items: flex-end; gap: 14px; flex-wrap: wrap;
  background: #fff; border: 1px solid var(--line); border-radius: 12px;
  padding: 12px 14px; margin-bottom: 14px;
  box-shadow: var(--shadow-sm, 0 2px 10px rgba(15, 23, 42, .05));
}
.ds-toolbar .field { min-width: 200px; }
.ds-toolbar-actions { margin-left: auto; display: flex; gap: 8px; }

.ds-sheet {
  background: #fff; border: 1px solid #94a3b8; border-radius: 4px;
  padding: 14px 16px 18px; margin-bottom: 20px;
  color: #0f172a; font-size: 13px;
  max-width: 1100px;
}
.ds-sheet table { width: 100%; border-collapse: collapse; table-layout: fixed; }
.ds-sheet td, .ds-sheet th {
  border: 1px solid #94a3b8; padding: 5px 7px; vertical-align: middle;
  overflow-wrap: anywhere;
}
.ds-sheet tbody td { background: #fff; }

/* -------- หัวฟอร์ม -------- */
.ds-head { margin-bottom: 0; }
.ds-head .ds-company { font-weight: 700; text-align: center; }
.ds-head .ds-title { font-weight: 700; text-align: center; font-size: 14.5px; background: #e2e8f0; }
.ds-head .ds-code { font-weight: 700; }

/* -------- เนื้อหาหลัก 2 คอลัมน์ -------- */
.ds-main { display: flex; gap: 10px; margin-top: 10px; align-items: flex-start; }
.ds-left { flex: 1 1 auto; }
.ds-right { flex: 0 0 40%; }
.ds-sheet .lbl { text-align: left; }
.ds-sheet .c { text-align: center; }
.ds-sheet .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.ds-sheet .head-y { background: #fef08a !important; font-weight: 600; }
.ds-sheet .box { background: #e2e8f0 !important; font-weight: 600; }
.ds-sheet .strong-red { color: #b91c1c; font-weight: 700; }
.ds-sheet .doc-red { background: #fecaca !important; color: #7f1d1d; font-weight: 600; }

/* -------- ช่องกรอกในตาราง -------- */
.ds-sheet .ds-in {
  width: 100%; border: 0; background: transparent; padding: 2px 0;
  font: inherit; font-size: 13px; color: #0f172a; text-align: inherit;
}
.ds-sheet .ds-in.num { text-align: right; }
.ds-sheet .ds-in:focus { outline: 2px solid #5eead4; outline-offset: 1px; background: #f0fdfa; }

/* -------- ตารางรายละเอียดรายวัน -------- */
.ds-detail-title { text-align: center; font-weight: 700; margin: 16px 0 6px; }
.ds-sheet .ds-detail th { background: #e2e8f0; text-align: center; font-weight: 600; }
.ds-sheet .ds-detail td { height: 24px; }
.ds-sheet .ds-detail .ds-sum td { background: #e2e8f0; font-weight: 600; }

/* -------- ลายเซ็น -------- */
.ds-sheet .ds-sign { margin-top: 10px; }
.ds-sheet .ds-sign td { border: 1px solid #94a3b8; padding: 10px; line-height: 2.2; }

@media print {
  .ds-toolbar { display: none !important; }
  .ds-sheet { border: 1px solid #64748b; box-shadow: none; max-width: none; padding: 0; font-size: 11px; }
  .ds-sheet .ds-in { font-size: 11px; }
  .ds-sheet td, .ds-sheet th { padding: 3px 5px; }
  .ds-sheet .head-y, .ds-sheet .box, .ds-sheet .doc-red { -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  @page { size: A4 portrait; margin: 10mm; }
}

/* ------------------------------ print ------------------------------- */
@media print {
  body { background: #fff; font-size: 12px; }
  .sidebar, .topbar-right, .report-toolbar .toolbar-right, .nav, .role-box, .fund-mini, .sidebar-foot, .toast-wrap { display: none !important; }
  .app { display: block; }
  .main { padding: 0; }
  .view { display: none !important; }
  .view.active { display: block !important; }
  .card { box-shadow: none; border: 0; padding: 0; }
  table.data-table { font-size: 11.5px; }
  table.data-table thead th { background: #f1f5f9 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
}

.fund-branch-list {
  max-height: 200px; overflow-y: auto; margin-top: 6px;
  border: 1px solid var(--line); border-radius: 10px; padding: 4px 6px;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 2px 8px;
  background: #fbfdfe;
}
.fund-branch {
  display: flex; align-items: center; gap: 8px;
  padding: 5px 8px; border-radius: 7px;
  font-size: 13px; text-align: left; cursor: pointer;
  transition: background .12s;
}
.fund-branch:hover { background: #eef7f6; }
.fund-branch input[type="checkbox"] {
  width: 15px; height: 15px; flex: 0 0 15px; margin: 0;
  accent-color: #0d9488; cursor: pointer;
}
.fund-branch span {
  flex: 1 1 auto; min-width: 0; text-align: left;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.fund-branch small { font-size: 11px; font-weight: 400; }

.ds-cash-check { display: flex; flex-direction: column; gap: 6px; margin-top: 8px; }
.ds-cash-check .btn { align-self: flex-start; }
.ds-cash-status { font-size: 11.5px; color: #64748b; }
.ds-cash-status.ok { color: #0f766e; font-weight: 600; }

/* -------- วงเงิน: บล็อกบัญชี (บริษัท / บุคคล) -------- */
.acc-block {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px 12px 6px;
  margin-top: 10px;
  background: #fbfdfe;
}
.acc-block-head {
  font-weight: 700;
  font-size: 13px;
  color: #0f766e;
  margin-bottom: 6px;
}
.fund-acc-line { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin: 2px 0; }
.fund-acc-line .badge { flex: 0 0 auto; }
