:root {
  --forest: #1b3324; --forest-2: #24432f; --honey: #b98532; --cream: #f4efe4; --paper: #faf7f0; --sand: #e9dfca;
  --ink: #1c241e; --ink-2: #5a645b; --line: rgba(28, 36, 30, .12); --bg: #f3f1ea; --clay: #a4583a; --ok: #3f7a4a;
  --sans: "IBM Plex Sans Thai", "Noto Sans Thai", "Leelawadee UI", "Thonburi", system-ui, sans-serif;
  --serif: "Noto Serif Thai", "Leelawadee UI", serif;
}
* { box-sizing: border-box; }
body { margin: 0; font-family: var(--sans); font-size: 15px; line-height: 1.7; color: var(--ink); background: var(--bg); -webkit-font-smoothing: antialiased; }
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font: inherit; cursor: pointer; }
h1, h2, h3, h4 { font-family: var(--serif); font-weight: 600; line-height: 1.45; margin: 0; letter-spacing: 0; }

/* buttons */
.b { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid transparent; border-radius: 10px; padding: .55em 1.1em; font-size: .93rem; font-weight: 500; line-height: 1.5; background: #fff; color: var(--ink); transition: background .2s, border-color .2s, opacity .2s; white-space: nowrap; }
.b:disabled { opacity: .45; cursor: not-allowed; }
.b-primary { background: var(--forest); color: #fff; }
.b-primary:not(:disabled):hover { background: var(--forest-2); }
.b-honey { background: var(--honey); color: #fff; }
.b-ghost { border-color: var(--line); background: transparent; }
.b-ghost:hover { background: #fff; }
.b-danger { color: var(--clay); border-color: rgba(164, 88, 58, .3); background: #fff; }
.b-danger:hover { background: #fbefe9; }
.b-sm { padding: .35em .8em; font-size: .85rem; }
.b-icon { width: 36px; height: 36px; padding: 0; border: 1px solid var(--line); background: #fff; font-size: 1.1rem; }
.w100 { width: 100%; }

/* login */
.login { min-height: 100vh; display: grid; grid-template-columns: 1.1fr 1fr; }
.login-art { position: relative; overflow: hidden; }
.login-art img { width: 100%; height: 100%; object-fit: cover; }
.login-art::after { content: ""; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(18, 36, 26, .1), rgba(18, 36, 26, .85)); }
.login-art-copy { position: absolute; z-index: 2; left: 48px; right: 48px; bottom: 48px; color: var(--cream); }
.login-art-copy p { margin: 0; font-style: italic; opacity: .8; }
.login-art-copy h2 { font-size: 2.2rem; }
.login-form { align-self: center; justify-self: center; width: min(400px, 100% - 40px); padding: 40px 0; }
.login-logo { height: 54px; width: auto; margin-bottom: 26px; }
.login-form h1 { font-size: 1.7rem; margin-bottom: 22px; color: var(--forest); }
.msg { min-height: 1.6em; font-size: .9rem; margin: 12px 0; }
.msg.bad { color: var(--clay); }
.back { font-size: .9rem; color: var(--ink-2); }

/* fields */
.f { display: block; margin-bottom: 16px; }
.f > span, .f-label { display: block; font-size: .84rem; font-weight: 500; color: var(--ink-2); margin-bottom: 6px; }
.f-hint { display: block; font-size: .78rem; color: #8a928a; margin-top: 5px; line-height: 1.55; }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=email], input:not([type]), select, textarea {
  width: 100%; font: inherit; font-size: .97rem; line-height: 1.6; padding: .6em .85em; border: 1px solid var(--line); border-radius: 10px; background: #fff; color: var(--ink); transition: border-color .2s, box-shadow .2s;
}
textarea { resize: vertical; min-height: 84px; }
input:focus, select:focus, textarea:focus { outline: 0; border-color: #6b8a55; box-shadow: 0 0 0 3px rgba(86, 112, 63, .15); }
.switch { display: inline-flex; align-items: center; gap: 10px; cursor: pointer; font-size: .92rem; }
.switch input { appearance: none; width: 42px; height: 24px; border-radius: 12px; background: #cfd3cb; position: relative; transition: background .2s; cursor: pointer; margin: 0; }
.switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #fff; transition: transform .2s; box-shadow: 0 1px 3px rgba(0, 0, 0, .2); }
.switch input:checked { background: var(--ok); }
.switch input:checked::after { transform: translateX(18px); }

/* shell */
.shell { display: grid; grid-template-columns: 260px 1fr; min-height: 100vh; }
.side { background: var(--forest); color: var(--cream); display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; }
.side-brand { display: flex; align-items: center; gap: 10px; padding: 20px 22px; border-bottom: 1px solid rgba(255, 255, 255, .08); }
.side-brand img { height: 36px; width: auto; background: var(--paper); border-radius: 8px; padding: 4px 8px; }
.side-brand span { font-size: .78rem; letter-spacing: .14em; text-transform: uppercase; opacity: .7; }
.side nav { flex: 1; overflow-y: auto; padding: 12px 10px; }
.side nav .grp { font-size: .72rem; opacity: .5; padding: 14px 12px 6px; }
.side nav a { display: flex; align-items: center; gap: 10px; padding: .55em 12px; border-radius: 10px; font-size: .94rem; color: rgba(244, 239, 228, .82); transition: background .2s; }
.side nav a:hover { background: rgba(255, 255, 255, .06); }
.side nav a.on { background: var(--cream); color: var(--forest); font-weight: 500; }
.side nav a .ic { width: 20px; text-align: center; opacity: .9; }
.side nav a .badge { margin-left: auto; background: var(--honey); color: #fff; font-size: .72rem; border-radius: 10px; padding: 0 7px; line-height: 20px; }
.side-foot { padding: 16px 18px 22px; border-top: 1px solid rgba(255, 255, 255, .08); display: grid; gap: 10px; }
.side-foot .who { font-size: .84rem; opacity: .75; }
.side-foot .b-ghost { color: var(--cream); border-color: rgba(255, 255, 255, .2); }
.side-foot .b-ghost:hover { background: rgba(255, 255, 255, .08); }
.main { min-width: 0; }
.top { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 16px; padding: 16px 32px; background: rgba(243, 241, 234, .9); backdrop-filter: blur(10px); border-bottom: 1px solid var(--line); }
.top-title { flex: 1; min-width: 0; }
.top-title h1 { font-size: 1.35rem; color: var(--forest); }
.top-title p { margin: 0; font-size: .85rem; color: var(--ink-2); }
.top-actions { display: flex; align-items: center; gap: 10px; }
.dirty { font-size: .82rem; color: var(--honey); display: none; }
.dirty.on { display: inline; }
.burger { display: none; }
.view { padding: 28px 32px 80px; max-width: 1080px; }
.loading { padding: 60px; text-align: center; color: var(--ink-2); }

/* cards */
.card { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 24px; margin-bottom: 20px; }
.card > h3 { font-size: 1.1rem; color: var(--forest); margin-bottom: 4px; }
.card > .card-desc { font-size: .86rem; color: var(--ink-2); margin: 0 0 18px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 18px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 18px; }
.span2 { grid-column: span 2; }

/* image field */
.imgf { display: flex; gap: 14px; align-items: flex-start; }
.imgf .thumb { width: 96px; height: 96px; flex: none; border-radius: 12px; background: var(--sand) center/cover no-repeat; border: 1px solid var(--line); }
.imgf .imgf-r { flex: 1; min-width: 0; display: grid; gap: 8px; }
.imgf .imgf-btns { display: flex; gap: 8px; flex-wrap: wrap; }

/* list field */
.lst-row { display: flex; gap: 8px; margin-bottom: 8px; }
.lst-row input { flex: 1; }

/* repeater */
.rep-item { border: 1px solid var(--line); border-radius: 14px; margin-bottom: 12px; background: var(--paper); }
.rep-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px 10px 16px; cursor: pointer; user-select: none; }
.rep-head .rep-thumb { width: 40px; height: 40px; border-radius: 8px; background: var(--sand) center/cover; flex: none; }
.rep-head .rep-title { flex: 1; min-width: 0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.rep-head .rep-sub { font-size: .8rem; color: var(--ink-2); font-weight: 400; margin-left: 6px; }
.rep-head .rep-tools { display: flex; gap: 4px; }
.rep-head .rep-tools .b-icon { width: 30px; height: 30px; font-size: .9rem; }
.rep-head .chev { transition: transform .2s; color: var(--ink-2); }
.rep-item.open .chev { transform: rotate(90deg); }
.rep-body { display: none; padding: 6px 16px 10px; border-top: 1px solid var(--line); background: #fff; border-radius: 0 0 14px 14px; }
.rep-item.open .rep-body { display: block; padding-top: 18px; }
.rep-off { opacity: .55; }
.rep-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.rep-toolbar input { max-width: 280px; }

/* dashboard */
.kpis { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; margin-bottom: 20px; }
.kpi { background: #fff; border: 1px solid var(--line); border-radius: 16px; padding: 20px; }
.kpi b { display: block; font-family: var(--serif); font-size: 2rem; color: var(--forest); line-height: 1.3; }
.kpi span { font-size: .86rem; color: var(--ink-2); }
.warn { background: #fff6e6; border: 1px solid #f0d6a4; color: #7a5212; border-radius: 14px; padding: 16px 18px; margin-bottom: 20px; display: flex; justify-content: space-between; gap: 14px; align-items: center; flex-wrap: wrap; }
.quick { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.quick a { background: var(--paper); border: 1px solid var(--line); border-radius: 12px; padding: 14px 16px; font-weight: 500; transition: background .2s; }
.quick a:hover { background: var(--cream); }
.quick a small { display: block; font-weight: 400; color: var(--ink-2); font-size: .82rem; }

/* tables */
.tbl { width: 100%; border-collapse: collapse; font-size: .92rem; }
.tbl th { text-align: left; font-weight: 500; color: var(--ink-2); font-size: .8rem; padding: 10px; border-bottom: 1px solid var(--line); }
.tbl td { padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: top; }
.tbl tr:hover td { background: var(--paper); }
.st { display: inline-block; font-size: .76rem; padding: .15em .7em; border-radius: 999px; background: var(--sand); }
.st-new { background: #fdebc8; color: #7a5212; }
.st-confirmed { background: #dfe9f7; color: #24508a; }
.st-shipped { background: #e4e0f5; color: #4a3a8a; }
.st-done, .st-read { background: #dcefdf; color: #2c5e36; }
.st-cancelled { background: #f6e0d8; color: #8a3a22; }
.order-items { margin: 6px 0 0; padding-left: 18px; font-size: .86rem; color: var(--ink-2); }
.empty { text-align: center; color: var(--ink-2); padding: 40px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 30px); background: var(--forest); color: #fff; padding: 12px 22px; border-radius: 12px; opacity: 0; transition: all .3s; z-index: 200; font-size: .94rem; pointer-events: none; }
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.bad { background: var(--clay); }

/* image library */
.lib { position: fixed; inset: 0; z-index: 150; background: rgba(18, 36, 26, .55); display: none; place-items: center; padding: 20px; }
.lib.on { display: grid; }
.lib-card { background: #fff; border-radius: 18px; width: min(980px, 100%); max-height: 86vh; display: flex; flex-direction: column; overflow: hidden; }
.lib-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.lib-head h3 { flex: 1; font-size: 1.15rem; }
.lib-grid { overflow-y: auto; padding: 18px; display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 12px; }
.lib-grid button { border: 2px solid transparent; border-radius: 12px; padding: 0; overflow: hidden; background: var(--sand); aspect-ratio: 1; }
.lib-grid button:hover { border-color: var(--honey); }
.lib-grid img { width: 100%; height: 100%; object-fit: cover; }

@media (max-width: 900px) {
  .login { grid-template-columns: 1fr; }
  .login-art { display: none; }
  .shell { grid-template-columns: 1fr; }
  .side { position: fixed; left: 0; top: 0; bottom: 0; width: 270px; z-index: 60; transform: translateX(-100%); transition: transform .3s; }
  .side.on { transform: none; box-shadow: 20px 0 60px rgba(0, 0, 0, .3); }
  .burger { display: inline-flex; }
  .top { padding: 12px 16px; flex-wrap: wrap; }
  .top-actions { width: 100%; justify-content: flex-end; }
  .top-actions .b-ghost { display: none; }
  .view { padding: 18px 16px 80px; }
  .grid2, .grid3, .kpis, .quick { grid-template-columns: 1fr; }
  .span2 { grid-column: auto; }
  .tbl thead { display: none; }
  .tbl td { display: block; border: 0; padding: 4px 10px; }
  .tbl tr { display: block; border-bottom: 1px solid var(--line); padding: 10px 0; }
}
