@font-face { font-family: Sarabun; src: url(/fonts/Sarabun-Regular.ttf); font-weight: 400; }
@font-face { font-family: Sarabun; src: url(/fonts/Sarabun-SemiBold.ttf); font-weight: 600; }
@font-face { font-family: Sarabun; src: url(/fonts/Sarabun-Bold.ttf); font-weight: 700; }
:root {
  --dark: #194C36; --green: #307547; --green-2: #3d8a57; --teal: #73DAC9; --blue: #589EC9; --blue-l: #8DBEE2;
  --bg: #F4F8F6; --card: #fff; --ink: #1f2d27; --muted: #5d6f67; --line: #DCE8E2; --soft: #EEF6F3;
  --warn: #b45309; --warn-bg: #fff7ed; --red: #c0392b; --red-bg: #fdecea; --ok-bg: #e8f6ef;
  --r: 10px; --shadow: 0 1px 2px rgba(25,76,54,.06), 0 4px 14px rgba(25,76,54,.06);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font-family: Sarabun, "Noto Sans Thai", Tahoma, sans-serif; font-size: 15px; color: var(--ink); background: var(--bg); line-height: 1.45; }
a { color: var(--green); }
h1 { font-size: 22px; margin: 0 0 4px; color: var(--dark); }
h2 { font-size: 17px; margin: 0 0 10px; color: var(--dark); }
h3 { font-size: 15px; margin: 14px 0 6px; color: var(--dark); }
.muted { color: var(--muted); } .small { font-size: 13px; } .nowrap { white-space: nowrap; } .r { text-align: right; } .c { text-align: center; }
.hidden { display: none !important; }

/* layout */
.topbar { position: fixed; top: 0; left: 0; right: 0; height: 56px; background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 10px; padding: 0 14px; z-index: 20; }
.topbar::after { content: ''; position: absolute; left: 0; right: 0; bottom: -3px; height: 3px; background: linear-gradient(90deg, var(--dark), var(--green), var(--teal), var(--blue)); }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--dark); font-size: 18px; font-weight: 600; }
.brand img { height: 32px; }
.brand b { color: var(--green); }
.top-actions { margin-left: auto; display: flex; gap: 6px; }
.menu-btn { display: none; border: 0; background: none; font-size: 22px; color: var(--dark); cursor: pointer; }
.sidebar { position: fixed; top: 59px; bottom: 0; left: 0; width: 230px; background: var(--dark); padding: 12px 0; overflow-y: auto; z-index: 15; }
.sidebar a { display: flex; align-items: center; justify-content: space-between; color: #d7ebe2; text-decoration: none; padding: 10px 20px; font-size: 15px; border-left: 3px solid transparent; }
.sidebar a:hover { background: rgba(255,255,255,.06); color: #fff; }
.sidebar a.active { background: rgba(115,218,201,.12); color: #fff; border-left-color: var(--teal); font-weight: 600; }
.badge { background: var(--teal); color: var(--dark); border-radius: 999px; font-size: 12px; font-weight: 700; padding: 0 7px; min-width: 20px; text-align: center; }
.badge:empty { display: none; }
main { margin: 59px 0 0 230px; padding: 22px 26px 60px; max-width: 1400px; }
.loading { padding: 40px; color: var(--muted); }
@media (max-width: 900px) {
  .menu-btn { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; width: 260px; }
  .sidebar.open { transform: none; box-shadow: 0 0 40px rgba(0,0,0,.3); }
  main { margin-left: 0; padding: 16px 12px 60px; }
  .top-actions .btn { padding: 6px 8px; font-size: 13px; }
  .brand span { display: none; }
}

/* components */
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; box-shadow: var(--shadow); margin-bottom: 16px; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.grid { display: grid; gap: 16px; }
.g2 { grid-template-columns: 1fr 1fr; } .g3 { grid-template-columns: repeat(3, 1fr); } .g4 { grid-template-columns: repeat(4, 1fr); }
.split { display: grid; grid-template-columns: minmax(300px, 380px) 1fr; gap: 16px; align-items: start; }
@media (max-width: 1100px) { .split { grid-template-columns: 1fr; } .g4 { grid-template-columns: 1fr 1fr; } }
@media (max-width: 700px) { .g2, .g3, .g4 { grid-template-columns: 1fr; } }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--r); padding: 14px 16px; box-shadow: var(--shadow); text-decoration: none; color: inherit; display: block; }
.stat .k { color: var(--muted); font-size: 13px; } .stat .v { font-size: 24px; font-weight: 700; color: var(--dark); } .stat .s { font-size: 13px; color: var(--muted); }
.stat.hl { border-top: 3px solid var(--teal); }
.btn { display: inline-flex; align-items: center; gap: 6px; border: 1px solid var(--green); background: var(--green); color: #fff; font: inherit; font-weight: 600; padding: 8px 14px; border-radius: 8px; cursor: pointer; text-decoration: none; font-size: 14px; }
.btn:hover { background: var(--dark); border-color: var(--dark); }
.btn.ghost { background: #fff; color: var(--green); }
.btn.ghost:hover { background: var(--soft); }
.btn.line { background: #06C755; border-color: #06C755; }
.btn.danger { background: #fff; color: var(--red); border-color: #e7b8b2; }
.btn.danger:hover { background: var(--red-bg); }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.chip { display: inline-block; padding: 1px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600; background: var(--soft); color: var(--dark); white-space: nowrap; }
.chip.draft, .chip.needs_info { background: var(--warn-bg); color: var(--warn); }
.chip.sent, .chip.issued, .chip.approved { background: #e6f1fa; color: #1d5f8f; }
.chip.won, .chip.accepted, .chip.paid { background: var(--ok-bg); color: var(--green); }
.chip.customer_replied, .chip.partial { background: #e9f9f6; color: #0f766e; }
.chip.rejected, .chip.void { background: #f1f1f1; color: #888; }
.dot { display: inline-block; width: 8px; height: 8px; border-radius: 50%; background: var(--teal); margin-left: 4px; }
.alert { padding: 10px 14px; border-radius: 8px; margin-bottom: 12px; border-left: 4px solid; }
.alert.warn { background: var(--warn-bg); border-color: #f59e0b; color: #7c3a03; }
.alert.info { background: #eef6fb; border-color: var(--blue); }
.alert.ok { background: var(--ok-bg); border-color: var(--green); }
.alert.err { background: var(--red-bg); border-color: var(--red); }

/* tables */
.tbl-wrap { overflow-x: auto; }
table.tbl { width: 100%; border-collapse: collapse; font-size: 14px; }
.tbl th { text-align: left; background: var(--soft); color: var(--dark); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
.tbl td { padding: 8px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr.click { cursor: pointer; } .tbl tr.click:hover td { background: #f8fcfa; }
.tbl td.num, .tbl th.num { text-align: right; white-space: nowrap; }
.tbl tfoot td { font-weight: 700; background: var(--soft); }

/* forms */
label.f { display: block; font-size: 13px; color: var(--muted); margin-bottom: 10px; }
label.f > span { display: block; margin-bottom: 3px; }
input, select, textarea { font: inherit; font-size: 14px; color: var(--ink); border: 1px solid #c9dad2; border-radius: 7px; padding: 7px 9px; background: #fff; width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(115,218,201,.6); border-color: var(--green); }
textarea { resize: vertical; min-height: 70px; }
input[type=checkbox] { width: auto; }
.inline { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.inline > * { width: auto; }
.lines input { padding: 5px 6px; }
.lines td { padding: 5px 6px; }
.lines .desc-in { min-width: 220px; }
.lines .n-in { width: 90px; text-align: right; }
.lines .u-in { width: 70px; }
.line-note { font-size: 12.5px; color: var(--warn); margin-top: 2px; }
.totals { margin-left: auto; width: 320px; max-width: 100%; }
.totals div { display: flex; justify-content: space-between; padding: 3px 0; }
.totals .grand { border-top: 2px solid var(--dark); font-weight: 700; font-size: 17px; color: var(--dark); padding-top: 6px; margin-top: 4px; }

/* chat */
.chat { max-height: 560px; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; padding: 4px; background: #f6faf8; border-radius: 8px; }
.msg { max-width: 85%; padding: 7px 11px; border-radius: 14px; white-space: pre-wrap; word-break: break-word; font-size: 14px; }
.msg.in { background: #fff; border: 1px solid var(--line); align-self: flex-start; border-bottom-left-radius: 4px; }
.msg.out { background: #d9f5e3; align-self: flex-end; border-bottom-right-radius: 4px; }
.msg .t { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.msg img { max-width: 220px; border-radius: 8px; display: block; }
.chat-day { align-self: center; font-size: 12px; color: var(--muted); }

/* modal & toast */
.modal { position: fixed; inset: 0; background: rgba(15,40,30,.45); display: flex; align-items: center; justify-content: center; z-index: 50; padding: 16px; }
.modal-box { background: #fff; border-radius: 12px; padding: 20px; width: 520px; max-width: 100%; max-height: 90vh; overflow-y: auto; }
#toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 6px; }
.toast { background: var(--dark); color: #fff; padding: 10px 16px; border-radius: 8px; box-shadow: var(--shadow); max-width: 90vw; }
.toast.err { background: var(--red); }

/* login */
.login { max-width: 380px; margin: 10vh auto; }
.login img { height: 90px; display: block; margin: 0 auto 10px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 14px; flex-wrap: wrap; }
.tabs a { padding: 8px 14px; text-decoration: none; color: var(--muted); border-bottom: 2px solid transparent; font-weight: 600; }
.tabs a.active { color: var(--dark); border-bottom-color: var(--teal); }
.kv { display: grid; grid-template-columns: 120px 1fr; gap: 4px 10px; font-size: 14px; }
.kv .k { color: var(--muted); }
.empty { padding: 24px; text-align: center; color: var(--muted); }
.bar { height: 8px; background: var(--soft); border-radius: 4px; overflow: hidden; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--green), var(--teal)); }
.split > *, .grid > * { min-width: 0; }
@media (max-width: 1100px) { .split > #docCard { order: -1; } }
