:root {
  --bg: #f4f6fb;
  --surface: #ffffff;
  --surface-2: #f8fafc;
  --border: #e6e9f0;
  --text: #1e2433;
  --muted: #7a8499;
  --primary: #4f46e5;
  --primary-dark: #4338ca;
  --primary-soft: #eef0fe;
  --danger: #e5484d;
  --shadow: 0 1px 3px rgba(20,30,60,.06), 0 8px 24px rgba(20,30,60,.06);

  /* category colors */
  --c-goods: #4f46e5;
  --c-office: #0ea5e9;
  --c-travel: #f59e0b;
  --c-salary: #10b981;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Noto Sans Thai", system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.55;
}

.app { display: flex; min-height: 100vh; }

/* ===== Sidebar ===== */
.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
  position: sticky;
  top: 0;
  height: 100vh;
}
.brand { display: flex; align-items: center; gap: 12px; padding: 6px 8px 22px; }
.brand-mark {
  width: 40px; height: 40px; border-radius: 11px;
  background: linear-gradient(135deg, var(--primary), #7c6cf2);
  color: #fff; font-size: 22px; font-weight: 700;
  display: grid; place-items: center;
}
.brand-text { display: flex; flex-direction: column; line-height: 1.2; }
.brand-text strong { font-size: 16px; }
.brand-text span { font-size: 11px; color: var(--muted); letter-spacing: .3px; }

.nav { display: flex; flex-direction: column; gap: 4px; flex: 1; }
.nav-item {
  display: flex; align-items: center; gap: 11px;
  padding: 11px 13px; border: none; background: none;
  border-radius: 10px; cursor: pointer; font: inherit;
  color: var(--muted); text-align: left; font-weight: 500;
  transition: .15s;
}
.nav-item .ico { font-size: 16px; }
.nav-item:hover { background: var(--surface-2); color: var(--text); }
.nav-item.active { background: var(--primary-soft); color: var(--primary-dark); }

.sidebar-foot { display: flex; flex-direction: column; gap: 6px; }

/* ===== Main ===== */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 20px 28px; border-bottom: 1px solid var(--border);
  background: var(--surface); position: sticky; top: 0; z-index: 5;
}
.topbar h1 { font-size: 20px; font-weight: 700; }
.topbar-actions { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.custom-range { display: flex; gap: 8px; align-items: center; }
.custom-range .input { padding: 8px 10px; }
.range-sep { color: var(--muted); font-size: 13px; }

.view { padding: 24px 28px; }
.hidden { display: none !important; }

/* ===== Buttons / inputs ===== */
.btn {
  font: inherit; font-weight: 600; cursor: pointer;
  border-radius: 9px; padding: 9px 16px; border: 1px solid transparent;
  transition: .15s; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--muted); border-color: transparent; }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-ghost.danger:hover { color: var(--danger); background: #fdecec; }
.btn-block { width: 100%; text-align: left; }

.select, .input {
  font: inherit; padding: 9px 12px; border: 1px solid var(--border);
  border-radius: 9px; background: var(--surface); color: var(--text);
  outline: none; transition: .15s;
}
.select:focus, .input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
.input.search, .search { width: 320px; max-width: 100%; }

.link { background: none; border: none; color: var(--primary); cursor: pointer; font: inherit; font-weight: 600; }
.icon-btn { background: none; border: none; cursor: pointer; font-size: 18px; color: var(--muted); padding: 4px 8px; border-radius: 6px; }
.icon-btn:hover { background: var(--surface-2); }
.muted { color: var(--muted); }

/* ===== Cards ===== */
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 16px; margin-bottom: 24px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 14px;
  padding: 18px; box-shadow: var(--shadow); position: relative; overflow: hidden;
}
.card::before { content: ""; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--accent, var(--primary)); }
.card .card-label { color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 7px; }
.card .card-value { font-size: 24px; font-weight: 700; margin-top: 8px; }
.card .card-sub { font-size: 12px; color: var(--muted); margin-top: 2px; }
.card.total { background: linear-gradient(135deg, var(--primary), #6d5cf0); color: #fff; }
.card.total::before { display: none; }
.card.total .card-label, .card.total .card-sub { color: rgba(255,255,255,.85); }

/* ===== Panels ===== */
.panel { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 20px; box-shadow: var(--shadow); margin-bottom: 20px; }
.panel.no-pad { padding: 0; overflow: hidden; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.panel-head.pad { padding: 20px 20px 0; }
.panel-head h2 { font-size: 15px; font-weight: 600; }

/* ===== Chart ===== */
.chart { display: flex; flex-direction: column; gap: 14px; }
.bar-row { display: grid; grid-template-columns: 150px 1fr 110px; align-items: center; gap: 14px; }
.bar-label { display: flex; align-items: center; gap: 8px; font-weight: 500; }
.dot { width: 10px; height: 10px; border-radius: 3px; flex-shrink: 0; }
.bar-track { background: var(--surface-2); border-radius: 8px; height: 24px; overflow: hidden; }
.bar-fill { height: 100%; border-radius: 8px; transition: width .6s cubic-bezier(.2,.7,.3,1); min-width: 2px; }
.bar-value { text-align: right; font-variant-numeric: tabular-nums; font-weight: 600; }

/* ===== Table ===== */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { padding: 13px 16px; text-align: left; border-bottom: 1px solid var(--border); white-space: nowrap; }
.table th { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; background: var(--surface-2); }
.table tbody tr:hover { background: var(--surface-2); }
.table .right { text-align: right; }
.table td.amount { font-variant-numeric: tabular-nums; font-weight: 600; }
.table-foot { display: flex; justify-content: space-between; align-items: center; padding: 14px 16px; border-top: 1px solid var(--border); background: var(--surface-2); }
.empty { padding: 40px; text-align: center; color: var(--muted); }

/* ===== Tags / chips / badges ===== */
.tag { display: inline-flex; align-items: center; gap: 6px; padding: 4px 10px; border-radius: 20px; font-size: 12px; font-weight: 600; }
.badge { padding: 3px 10px; border-radius: 20px; font-size: 11px; font-weight: 600; }
.badge-warn { background: #fff4e0; color: #b06f00; }
.badge-erp { background: var(--primary-soft); color: var(--primary-dark); }
.badge-manual { background: #eef2f7; color: #5a6577; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { padding: 7px 14px; border-radius: 20px; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font: inherit; font-weight: 500; color: var(--muted); transition: .15s; }
.chip:hover { border-color: var(--primary); color: var(--primary); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 16px; margin-bottom: 18px; flex-wrap: wrap; }

.del-btn { background: none; border: none; cursor: pointer; color: var(--muted); font-size: 15px; padding: 4px 8px; border-radius: 6px; opacity: .6; }
.del-btn:hover { color: var(--danger); background: #fdecec; opacity: 1; }

.erp-actions { display: flex; align-items: center; gap: 14px; margin: 16px 0; }
.hint { background: var(--surface-2); border: 1px dashed var(--border); border-radius: 10px; padding: 14px 16px; font-size: 13px; color: var(--muted); margin-top: 16px; }
.hint code { background: #e8ebf3; padding: 1px 6px; border-radius: 5px; font-size: 12px; color: var(--primary-dark); }

/* ===== Modal ===== */
.modal-backdrop { position: fixed; inset: 0; background: rgba(20,25,45,.45); display: grid; place-items: center; z-index: 50; padding: 20px; backdrop-filter: blur(2px); }
.modal { background: var(--surface); border-radius: 16px; width: 100%; max-width: 480px; box-shadow: 0 20px 60px rgba(0,0,0,.25); animation: pop .2s ease; }
@keyframes pop { from { transform: scale(.96) translateY(8px); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 20px 22px; border-bottom: 1px solid var(--border); }
.modal-head h2 { font-size: 17px; }
.form { padding: 20px 22px; }
.field { margin-bottom: 15px; display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 600; color: var(--text); }
.field .input, .field .select { width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.modal-foot { display: flex; justify-content: flex-end; gap: 10px; margin-top: 8px; }

/* ===== Toast ===== */
.toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: #1e2433; color: #fff; padding: 12px 22px; border-radius: 10px; font-weight: 500; box-shadow: 0 10px 30px rgba(0,0,0,.25); opacity: 0; transition: .25s; z-index: 100; }
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ===== Nav pending badge ===== */
.nav-badge { margin-left: auto; background: var(--danger); color: #fff; font-size: 11px; font-weight: 700; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; display: inline-grid; place-items: center; }

/* ===== Status badges ===== */
.status { padding: 4px 11px; border-radius: 20px; font-size: 12px; font-weight: 600; display: inline-flex; align-items: center; gap: 5px; }
.status::before { content: ""; width: 7px; height: 7px; border-radius: 50%; background: currentColor; }
.status.pending { background: #fff4e0; color: #b06f00; }
.status.approved { background: #e7f7ee; color: #0a8f50; }
.status.rejected { background: #fdecec; color: #d23a3f; }

/* ===== Segmented control ===== */
.seg { display: inline-flex; background: var(--surface-2); border: 1px solid var(--border); border-radius: 9px; padding: 3px; gap: 2px; }
.seg-btn { border: none; background: none; font: inherit; font-weight: 500; padding: 6px 14px; border-radius: 7px; cursor: pointer; color: var(--muted); }
.seg-btn.active { background: var(--surface); color: var(--text); box-shadow: 0 1px 2px rgba(0,0,0,.08); }

/* ===== Approval action buttons ===== */
.act-btns { display: inline-flex; gap: 6px; }
.mini-btn { border: 1px solid var(--border); background: var(--surface); font: inherit; font-size: 12px; font-weight: 600; padding: 5px 11px; border-radius: 7px; cursor: pointer; transition: .15s; }
.mini-btn.ok { color: #0a8f50; border-color: #b6e6cb; }
.mini-btn.ok:hover { background: #e7f7ee; }
.mini-btn.no { color: #d23a3f; border-color: #f3c4c5; }
.mini-btn.no:hover { background: #fdecec; }

/* ===== Receipt ===== */
.receipt-preview { display: flex; align-items: center; gap: 12px; margin-top: 8px; }
.receipt-preview img { width: 64px; height: 64px; object-fit: cover; border-radius: 8px; border: 1px solid var(--border); cursor: zoom-in; }
.receipt-thumb { width: 34px; height: 34px; object-fit: cover; border-radius: 6px; border: 1px solid var(--border); cursor: zoom-in; vertical-align: middle; }
.link.danger { color: var(--danger); }
.lightbox { position: fixed; inset: 0; background: rgba(10,12,25,.82); display: grid; place-items: center; z-index: 60; padding: 30px; cursor: zoom-out; }
.lightbox img { max-width: 90vw; max-height: 90vh; border-radius: 12px; box-shadow: 0 20px 60px rgba(0,0,0,.5); }

/* ===== Monthly chart (stacked columns) ===== */
.month-chart { display: flex; align-items: flex-end; gap: 18px; height: 240px; padding: 10px 4px 0; overflow-x: auto; }
.month-col { display: flex; flex-direction: column; align-items: center; gap: 8px; flex: 1; min-width: 56px; height: 100%; justify-content: flex-end; }
.month-stack { width: 100%; max-width: 56px; display: flex; flex-direction: column-reverse; border-radius: 7px 7px 0 0; overflow: hidden; transition: height .5s ease; }
.month-seg { width: 100%; transition: .3s; }
.month-name { font-size: 12px; color: var(--muted); font-weight: 600; white-space: nowrap; }
.month-total { font-size: 11px; font-weight: 700; }
.legend { display: flex; flex-wrap: wrap; gap: 18px; margin-top: 18px; padding-top: 16px; border-top: 1px solid var(--border); }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 13px; color: var(--muted); }

@media (max-width: 820px) {
  .sidebar { display: none; }
  .input.search, .search { width: 100%; }
  .grid-2 { grid-template-columns: 1fr; }
  .bar-row { grid-template-columns: 110px 1fr; }
  .bar-value { grid-column: 2; text-align: right; }
}

/* ===== Login screen ===== */
.login-screen {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #eef0fe, #f4f6fb 60%);
}
.login-card {
  width: 100%; max-width: 380px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 32px 28px;
  text-align: center;
}
.login-brand { display: flex; justify-content: center; margin-bottom: 14px; }
.login-brand .brand-mark {
  width: 54px; height: 54px; border-radius: 15px;
  background: linear-gradient(135deg, var(--primary), #7c6cf2);
  color: #fff; font-size: 26px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
}
.login-card h1 { font-size: 19px; margin-bottom: 4px; }
.login-card .muted { margin-bottom: 20px; font-size: 13px; }
.login-card .field { text-align: left; margin-bottom: 14px; }
.login-card .field label { display: block; font-size: 13px; font-weight: 600; margin-bottom: 6px; }
.login-card .field .input { width: 100%; }
.login-error {
  background: #fdecec; color: var(--danger);
  border-radius: 9px; padding: 9px 12px; font-size: 13px; margin-bottom: 14px; text-align: left;
}
.btn-block { width: 100%; justify-content: center; }

/* ===== User bar (sidebar) ===== */
.user-bar {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  background: var(--surface-2); border: 1px solid var(--border);
  border-radius: 12px; padding: 8px 10px; margin-bottom: 16px;
}
.user-info { display: flex; align-items: center; gap: 9px; min-width: 0; }
.user-avatar { font-size: 20px; }
.user-meta { display: flex; flex-direction: column; line-height: 1.25; min-width: 0; }
.user-meta strong { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 130px; }
.user-meta span { font-size: 11px; color: var(--muted); }
#btn-logout { font-size: 17px; color: var(--danger); }

/* รายการที่ไม่ใช่ของเรา = ดูอย่างเดียว */
tr.readonly { cursor: default; opacity: .96; }
tr.editable { cursor: pointer; }
.owner-tag { font-size: 11px; margin-top: 2px; }

/* จัดการคนดูแลกระเป๋า */
.wallet-add { display: flex; gap: 10px; align-items: center; margin: 14px 0 18px; flex-wrap: wrap; }
.wallet-add .select { min-width: 220px; }

/* คู่มือในแอป (iframe) */
.manual-actions { display:flex; justify-content:flex-end; margin-bottom:10px; }
.manual-frame {
  width:100%; height:calc(100vh - 150px); min-height:520px;
  border:1px solid var(--border); border-radius:14px; background:var(--surface);
}

/* แบนเนอร์ตั้งค่าฐานข้อมูล */
.setup-banner {
  margin: 20px 28px 0;
  background: #fff8e6; border: 1px solid #f5d787; border-radius: 12px;
  padding: 16px 18px;
  display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap;
}
.setup-text strong { display: block; margin-bottom: 3px; }
.setup-text p { font-size: 13px; color: var(--muted); margin: 0; max-width: 640px; }
.setup-actions { display: flex; gap: 10px; align-items: center; flex-shrink: 0; }
.setup-actions .btn-ghost { text-decoration: none; }
