:root {
  --bg: #f1f5f2; --card: #fff; --text: #14231a; --muted: #62736a; --line: #dfe8e2;
  --primary: #0f8a3f; --primary-dark: #0a6d30; --brand-deep: #06361a; --blue: #2563eb;
  --good: #16a34a; --issue: #d97706; --broken: #dc2626;
  --radius: 14px;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #0b130e; --card: #131f17; --text: #e6efe9; --muted: #92a69a; --line: #243629; --primary: #19a853; --primary-dark: #128a42; }
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font-family: "Sarabun", "Noto Sans Thai", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-size: 16px; line-height: 1.5;
}
.wrap { max-width: 760px; margin: 0 auto; padding: 16px; }
.wrap.wide { max-width: 1280px; }
header.top { display: flex; align-items: center; gap: 12px; margin: 8px 0 18px; }
header.top .logo { width: 42px; height: 42px; border-radius: 12px; background: var(--primary); color: #fff; display: grid; place-items: center; font-size: 22px; flex: none; }
header.top h1 { font-size: 20px; margin: 0; line-height: 1.2; }
header.top p { margin: 0; color: var(--muted); font-size: 13px; }
header.top .grow { flex: 1; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; margin-bottom: 14px; }
.card h2 { font-size: 16px; margin: 0 0 12px; }
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 4px; font-weight: 600; }
.req::after { content: " *"; color: var(--broken); }
input, select, textarea {
  width: 100%; padding: 11px 12px; font: inherit; color: var(--text); background: var(--bg);
  border: 1px solid var(--line); border-radius: 10px; outline: none; min-height: 44px;
}
input:focus, select:focus, textarea:focus { border-color: var(--primary); box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 25%, transparent); }
input[readonly] { opacity: .75; }
textarea { min-height: 70px; resize: vertical; }
.grid { display: grid; gap: 12px; grid-template-columns: 1fr 1fr; }
.grid .full { grid-column: 1 / -1; }
@media (max-width: 560px) { .grid { grid-template-columns: 1fr; } }
.field { margin-bottom: 0; }
button, .btn {
  font: inherit; font-weight: 600; cursor: pointer; border: 0; border-radius: 10px; padding: 10px 16px; min-height: 44px;
  background: var(--primary); color: #fff; display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-decoration: none;
}
button:hover, .btn:hover { background: var(--primary-dark); }
button:disabled { opacity: .55; cursor: not-allowed; }
.btn.ghost, button.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.ghost:hover, button.ghost:hover { background: var(--bg); }
.btn.danger, button.danger { background: var(--broken); }
.btn.small, button.small { min-height: 34px; padding: 5px 11px; font-size: 14px; }
.btn.block { width: 100%; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.end { justify-content: flex-end; }
.muted { color: var(--muted); font-size: 14px; }
.item-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 10px; }
.item-head b { font-size: 15px; }
.photos { display: flex; gap: 8px; flex-wrap: wrap; margin-top: 8px; }
.thumb { position: relative; width: 84px; height: 84px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); background: var(--bg); }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb button { position: absolute; top: 3px; right: 3px; min-height: 0; width: 24px; height: 24px; padding: 0; border-radius: 50%; background: rgba(0,0,0,.65); font-size: 14px; }
.thumb.loading::after { content: "⏳"; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.35); font-size: 22px; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; color: #fff; }
.badge.good { background: var(--good); } .badge.issue { background: var(--issue); } .badge.broken { background: var(--broken); }
.mine { display: grid; gap: 8px; }
.mine .it { display: flex; gap: 12px; align-items: center; padding: 10px; border: 1px solid var(--line); border-radius: 12px; background: var(--bg); }
.mine .it img { width: 56px; height: 56px; object-fit: cover; border-radius: 8px; flex: none; }
.mine .it .ph { width: 56px; height: 56px; border-radius: 8px; background: var(--line); display: grid; place-items: center; flex: none; }
.mine .it .t { flex: 1; min-width: 0; }
.mine .it .t div { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #111; color: #fff; padding: 12px 20px; border-radius: 12px; z-index: 99; max-width: 90vw; box-shadow: 0 8px 30px rgba(0,0,0,.3); }
.toast.err { background: var(--broken); }
.success { text-align: center; padding: 28px 12px; }
.success .big { font-size: 56px; }
.sticky-bar { position: sticky; bottom: 0; background: linear-gradient(transparent, var(--bg) 30%); padding: 18px 0 12px; }
.hidden { display: none !important; }

/* admin */
nav.tabs { display: flex; gap: 6px; overflow-x: auto; margin-bottom: 14px; padding-bottom: 2px; }
nav.tabs button { background: var(--card); color: var(--text); border: 1px solid var(--line); white-space: nowrap; }
nav.tabs button.on { background: var(--primary); color: #fff; border-color: var(--primary); }
.stats { display: grid; gap: 12px; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 14px; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; }
.stat b { display: block; font-size: 30px; line-height: 1.1; }
.stat span { color: var(--muted); font-size: 13px; }
.bar { display: flex; align-items: center; gap: 10px; margin: 6px 0; font-size: 14px; }
.bar .n { width: 190px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bar .b { flex: 1; height: 10px; background: var(--bg); border-radius: 99px; overflow: hidden; }
.bar .b i { display: block; height: 100%; background: var(--primary); border-radius: 99px; }
.bar .v { width: 34px; text-align: right; font-weight: 700; }
.table-wrap { overflow-x: auto; border: 1px solid var(--line); border-radius: var(--radius); background: var(--card); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { padding: 10px 12px; text-align: left; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: var(--bg); position: sticky; top: 0; }
tr:last-child td { border-bottom: 0; }
td .thumbs { display: flex; gap: 4px; }
td .thumbs img { width: 38px; height: 38px; object-fit: cover; border-radius: 6px; border: 1px solid var(--line); }
td.act { white-space: nowrap; text-align: right; }
.filters { display: grid; gap: 10px; grid-template-columns: 2fr 1.3fr 1.3fr 1fr; margin-bottom: 12px; }
@media (max-width: 800px) { .filters { grid-template-columns: 1fr 1fr; } }
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.55); z-index: 50; display: flex; align-items: flex-start; justify-content: center; overflow-y: auto; padding: 20px 12px; }
.modal { background: var(--card); border-radius: var(--radius); width: 100%; max-width: 640px; padding: 18px; border: 1px solid var(--line); }
.modal h2 { margin: 0 0 14px; font-size: 18px; }
.login { max-width: 380px; margin: 14vh auto 0; }
.inactive { opacity: .5; }

/* ───────── brand refresh ───────── */
.brand-logo { display: inline-block; vertical-align: top; width: 46px; height: 46px; border-radius: 50%; overflow: hidden; flex: none; box-shadow: 0 0 0 2px #fff, 0 4px 14px rgba(6,54,26,.35); background: #fff; }
.brand-logo img { width: 140%; height: 140%; margin: -20%; display: block; max-width: none; }
.brand-logo.xl { width: 96px; height: 96px; box-shadow: 0 4px 16px rgba(6,54,26,.25); }
header.top {
  background: linear-gradient(120deg, var(--brand-deep), #0b5a29 60%, #0f8a3f);
  color: #fff; padding: 14px 16px; border-radius: 18px; margin: 4px 0 20px;
  box-shadow: 0 10px 28px -12px rgba(6,54,26,.55); position: relative; overflow: hidden;
}
header.top > * { position: relative; }
header.top h1 { font-size: 19px; letter-spacing: .2px; }
header.top p { color: rgba(255,255,255,.78); }
header.top .btn.ghost, header.top button.ghost { color: #fff; border-color: rgba(255,255,255,.4); background: rgba(255,255,255,.08); }
header.top .btn.ghost:hover, header.top button.ghost:hover { background: rgba(255,255,255,.2); }
.card { box-shadow: 0 1px 2px rgba(10,40,20,.04), 0 8px 24px -16px rgba(10,40,20,.25); border-radius: 18px; }
.card h2 { display: flex; align-items: center; gap: 8px; }
.card h2::before { content: ""; width: 4px; height: 16px; border-radius: 3px; background: var(--primary); }
.success h2::before, .card.auth-card h2::before { display: none; }
input, select, textarea { transition: border-color .15s, box-shadow .15s; background: color-mix(in srgb, var(--bg) 60%, var(--card)); }
button, .btn { background: linear-gradient(180deg, var(--primary), var(--primary-dark)); box-shadow: 0 4px 12px -4px color-mix(in srgb, var(--primary) 70%, transparent); transition: transform .08s, filter .15s; }
button:hover, .btn:hover { background: linear-gradient(180deg, var(--primary), var(--primary-dark)); filter: brightness(1.08); }
button:active, .btn:active { transform: translateY(1px); }
.btn.ghost, button.ghost { background: transparent; box-shadow: none; }
.btn.danger, button.danger { background: var(--broken); box-shadow: none; }
.item-head b { display: flex; align-items: center; gap: 8px; }
.item-head b span[data-n] { display: inline-grid; place-items: center; width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 13px; }
.mine .it { transition: border-color .15s, transform .15s; }
.mine .it:hover { border-color: var(--primary); }
.sticky-bar { background: linear-gradient(transparent, var(--bg) 35%); }
nav.tabs button { border-radius: 99px; box-shadow: none; background: var(--card); }
nav.tabs button.on { background: linear-gradient(180deg, var(--primary), var(--primary-dark)); }
.stat { position: relative; overflow: hidden; border-radius: 18px; }
.stat::after { content: ""; position: absolute; right: -18px; top: -18px; width: 70px; height: 70px; border-radius: 50%; background: color-mix(in srgb, var(--primary) 12%, transparent); }
.stat b { color: var(--primary); }
th { background: color-mix(in srgb, var(--primary) 7%, var(--card)); }
tbody tr:hover td { background: color-mix(in srgb, var(--primary) 5%, transparent); }
.table-wrap { border-radius: 18px; box-shadow: 0 8px 24px -18px rgba(10,40,20,.3); }
.modal { border-radius: 20px; box-shadow: 0 30px 80px rgba(0,0,0,.4); }
.toast { background: var(--brand-deep); }

/* login / change-password screen */
body.auth {
  min-height: 100vh;
}
body.auth header.top { display: none; }
body.auth .auth-card { margin-top: 8vh; padding: 30px 24px 24px; border-radius: 24px; }
.auth-brand { text-align: center; margin: 0 0 14px; }
.auth-brand h1 { font-size: 22px; margin: 14px 0 2px; }
.auth-brand p { margin: 0; color: var(--muted); font-size: 14px; }
.foot { text-align: center; color: var(--muted); font-size: 12px; margin: 26px 0 8px; }

button.block { width: 100%; }
.mini { width: 100%; border-collapse: collapse; font-size: 14px; }
.mini th, .mini td { padding: 8px 10px; text-align: left; vertical-align: top; position: static; }
.mini th { font-size: 12px; }
.scroll-y { max-height: 460px; overflow: auto; border: 1px solid var(--line); border-radius: 12px; }

.guide { border: 1px dashed color-mix(in srgb, var(--primary) 55%, var(--line)); border-radius: 12px; background: color-mix(in srgb, var(--primary) 5%, transparent); }
.guide summary { cursor: pointer; padding: 10px 12px; font-weight: 600; font-size: 14px; color: var(--primary); list-style: none; }
.guide summary::-webkit-details-marker { display: none; }
.guide[open] summary { border-bottom: 1px dashed var(--line); }
.guide-body { padding: 12px; }
.guide-img { position: relative; max-width: 460px; margin: 0 auto; }
.guide-img img { width: 100%; display: block; border-radius: 10px; border: 1px solid var(--line); }
.guide-img .box { position: absolute; border: 3px solid var(--primary); border-radius: 8px; box-shadow: 0 0 0 2px #fff; }
.guide-img .box em { position: absolute; top: -13px; left: -13px; width: 24px; height: 24px; border-radius: 50%; background: var(--primary); color: #fff; font-weight: 700; font-size: 13px; line-height: 24px; text-align: center; font-style: normal; box-shadow: 0 0 0 2px #fff; }
.guide-img .b1 { left: 5%; top: 46.5%; width: 88.5%; height: 9.5%; }
.guide-img .b2 { left: 4%; top: 74.5%; width: 41.5%; height: 18%; }
.guide-img .b3 { left: 58%; top: 76%; width: 33.5%; height: 17%; }
.guide-steps { padding-left: 20px; margin: 12px 0 0; font-size: 14px; }
.guide-steps li { margin-bottom: 8px; }
.guide-steps code { background: var(--line); padding: 1px 6px; border-radius: 6px; font-size: 13px; }

.nb { display: inline-grid; place-items: center; width: 18px; height: 18px; margin-right: 6px; border-radius: 50%; background: var(--primary); color: #fff; font-size: 11px; font-weight: 700; vertical-align: 1px; }

td { overflow-wrap: anywhere; }
@media (max-width: 820px) {
  .wrap { padding: 12px; }
  .wrap.wide { padding: 12px; }
  header.top { flex-wrap: wrap; gap: 10px; padding: 12px; }
  header.top .grow { flex: 1 1 60%; min-width: 0; }
  header.top h1 { font-size: 17px; }
  .grid.cols { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .stat b { font-size: 26px; }
  nav.tabs { margin-left: -12px; margin-right: -12px; padding: 0 12px 4px; }
  .row .btn, .row button { flex: 1 1 auto; }

  /* tables → cards */
  .table-wrap, .scroll-y { border: 0; background: transparent; box-shadow: none; overflow: visible; max-height: none; }
  table, thead, tbody, tr, td { display: block; width: 100%; }
  thead { display: none; }
  tbody tr {
    display: flex; flex-direction: column; margin-bottom: 12px; padding: 12px 14px;
    background: var(--card); border: 1px solid var(--line); border-radius: 16px;
    box-shadow: 0 6px 18px -14px rgba(10,40,20,.35);
  }
  td { border: 0 !important; padding: 5px 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; text-align: right; }
  td[data-label]::before { content: attr(data-label); flex: none; color: var(--muted); font-size: 13px; text-align: left; }
  td.ttl { order: -1; display: block; text-align: left; font-size: 16px; padding: 0 0 8px; margin-bottom: 6px; border-bottom: 1px solid var(--line) !important; }
  td.act { order: 99; display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; padding-top: 10px; }
  td.act button { flex: 1 1 auto; }
  tbody tr:hover td { background: transparent; }
  .mini tbody tr { box-shadow: none; background: var(--bg); }
  td .thumbs { justify-content: flex-end; }
  td[colspan] { display: block; text-align: center; }
  .modal-bg { padding: 10px 8px; }
  .modal { padding: 14px; border-radius: 16px; }
}
