/* =========================================================
   สายตรงผู้อำนวยการ — UI v3 (responsive: PC / Tablet / Mobile)
   ========================================================= */
:root {
  --c1: #1e2a78;          /* สีหลัก */
  --c2: #3949ab;          /* สีรอง */
  --tint: #eef1ff;        /* พื้นอ่อน */
  --ink: #1f2430;
  --muted: #667085;
  --line: #e4e7ec;
  --bg: #f4f6fb;
  --card: #fff;
  --green: #16a34a; --green-bg: #e9f8ee;
  --red: #dc2626;   --red-bg: #fdecec;
  --amber: #d97706; --amber-bg: #fff4e0;
  --blue: #0369a1;  --blue-bg: #e6f4fb;
  --r: 14px;
  --shadow: 0 1px 2px rgba(16,24,40,.05), 0 6px 18px rgba(16,24,40,.06);
}
.theme-admin { --c1: #7f1d1d; --c2: #b91c1c; --tint: #fdf0ef; }
.theme-boss  { --c1: #3f2a1d; --c2: #8a5a3b; --tint: #f7f0e9; }

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body {
  font-family: 'Sarabun', 'Prompt', system-ui, sans-serif;
  font-size: 16px; line-height: 1.6; color: var(--ink); background: var(--bg);
  min-height: 100vh; display: flex; flex-direction: column;
}
a { color: var(--c2); }
img { max-width: 100%; }
h1, h2, h3, .brand b { font-family: 'Prompt', 'Sarabun', sans-serif; font-weight: 600; line-height: 1.3; }

/* ---------- Top bar ---------- */
.topbar {
  background: linear-gradient(120deg, var(--c1), var(--c2));
  color: #fff; position: sticky; top: 0; z-index: 50;
  box-shadow: 0 2px 10px rgba(0,0,0,.12);
}
.topbar-in {
  max-width: 1180px; margin: 0 auto; padding: 10px 18px;
  display: flex; align-items: center; gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; color: #fff; text-decoration: none; min-width: 0; }
.brand img { width: 42px; height: 42px; object-fit: contain; background: #fff; border-radius: 50%; padding: 3px; flex: none; }
.brand span { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.brand b { font-size: 17px; white-space: nowrap; }
.brand small { font-size: 12px; opacity: .8; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a {
  color: #fff; text-decoration: none; opacity: .85; padding: 8px 14px; border-radius: 999px;
  display: flex; align-items: center; gap: 8px; font-weight: 500; white-space: nowrap; transition: .2s;
}
.nav a:hover { background: rgba(255,255,255,.12); opacity: 1; }
.nav a.on { background: rgba(255,255,255,.2); opacity: 1; }
.userbox { display: flex; align-items: center; gap: 8px; padding-left: 12px; border-left: 1px solid rgba(255,255,255,.25); }
.who { display: flex; align-items: center; gap: 8px; font-size: 14px; }
.who i { font-size: 22px; }
.who > span { display: flex; flex-direction: column; line-height: 1.15; }
.who small { opacity: .75; font-size: 11px; }
.icon-btn { color: #fff; width: 38px; height: 38px; border-radius: 50%; display: grid; place-items: center; background: rgba(255,255,255,.12); text-decoration: none; }
.icon-btn:hover { background: rgba(255,255,255,.25); }

/* ---------- Layout ---------- */
.wrap { width: 100%; max-width: 1180px; margin: 0 auto; padding: 24px 18px 40px; flex: 1; }
.wrap.narrow { max-width: 760px; }
.page-title { margin-bottom: 18px; }
.page-title h1 { font-size: 26px; color: var(--c1); }
.page-title p { color: var(--muted); }
.card { background: var(--card); border-radius: var(--r); box-shadow: var(--shadow); padding: 22px; margin-bottom: 18px; border: 1px solid var(--line); }
.card h2 { font-size: 18px; color: var(--c1); margin-bottom: 14px; display: flex; align-items: center; gap: 8px; }
.cols { display: grid; grid-template-columns: minmax(0, 1.6fr) minmax(0, 1fr); gap: 18px; align-items: start; }
.center { text-align: center; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.row.end { justify-content: flex-end; }
.spacer { flex: 1; }

/* ---------- Hero / Home ---------- */
.hero {
  background: linear-gradient(135deg, var(--c1), var(--c2)); color: #fff; border-radius: 20px;
  padding: 34px 28px; text-align: center; position: relative; overflow: hidden; margin-bottom: 22px;
}
.hero::after { content: ""; position: absolute; width: 340px; height: 340px; border-radius: 50%; background: rgba(255,255,255,.07); right: -120px; top: -140px; }
.hero img { width: 110px; height: 110px; object-fit: contain; background: #fff; border-radius: 50%; padding: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.2); }
.hero h1 { font-size: 30px; margin: 14px 0 6px; }
.hero p { opacity: .9; max-width: 560px; margin: 0 auto; }
.menu-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 16px; }
.menu-tile {
  display: flex; gap: 16px; align-items: center; padding: 22px; background: var(--card); border-radius: var(--r);
  text-decoration: none; color: var(--ink); box-shadow: var(--shadow); border: 1px solid var(--line); transition: .2s;
}
.menu-tile:hover { transform: translateY(-3px); box-shadow: 0 12px 28px rgba(16,24,40,.12); border-color: var(--c2); }
.menu-tile .ico { width: 56px; height: 56px; border-radius: 16px; display: grid; place-items: center; font-size: 24px; background: var(--tint); color: var(--c2); flex: none; }
.menu-tile b { display: block; font-size: 18px; font-family: 'Prompt', sans-serif; font-weight: 600; }
.menu-tile span { color: var(--muted); font-size: 14px; }
.menu-tile .count { margin-left: auto; background: var(--c2); color: #fff; border-radius: 999px; padding: 2px 12px; font-weight: 700; }

/* ---------- Forms ---------- */
.field { margin-bottom: 16px; }
.field > label { display: block; font-weight: 600; margin-bottom: 6px; color: var(--ink); }
.field > label i { color: var(--c2); width: 20px; }
.req::after { content: " *"; color: var(--red); }
.hint { font-size: 13px; color: var(--muted); margin-top: 5px; display: flex; gap: 6px; align-items: baseline; }
.hint.lock { color: var(--green); }
input[type=text], input[type=password], input[type=url], input[type=tel], select, textarea {
  width: 100%; font: inherit; padding: 12px 14px; border: 1.5px solid var(--line); border-radius: 10px;
  background: #fff; color: var(--ink); transition: .15s; min-height: 48px;
}
textarea { min-height: 140px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--c2); box-shadow: 0 0 0 4px color-mix(in srgb, var(--c2) 15%, transparent); }
input[readonly] { background: #f8f9fb; color: var(--muted); }
.field.err input, .field.err select, .field.err textarea { border-color: var(--red); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chips label { cursor: pointer; }
.chips input { position: absolute; opacity: 0; pointer-events: none; }
.chips span { display: inline-flex; align-items: center; gap: 6px; padding: 10px 16px; border-radius: 999px; border: 1.5px solid var(--line); background: #fff; font-weight: 500; transition: .15s; }
.chips input:checked + span { background: var(--c2); border-color: var(--c2); color: #fff; }
.chips input:focus-visible + span { box-shadow: 0 0 0 4px color-mix(in srgb, var(--c2) 20%, transparent); }
.counter { text-align: right; font-size: 12px; color: var(--muted); margin-top: 4px; }

.upload {
  border: 2px dashed #c9cfdb; border-radius: 12px; padding: 22px; text-align: center; cursor: pointer;
  background: #fafbfd; transition: .2s; display: block;
}
.upload:hover, .upload.drag { border-color: var(--c2); background: var(--tint); }
.upload i { font-size: 34px; color: var(--c2); }
.upload b { display: block; margin-top: 6px; }
.upload input { display: none; }
.preview { display: none; margin-top: 12px; position: relative; width: fit-content; }
.preview.show { display: block; }
.preview img { max-height: 220px; border-radius: 12px; border: 1px solid var(--line); display: block; }
.preview button { position: absolute; top: 8px; right: 8px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 11px 20px; min-height: 44px;
  border-radius: 999px; border: 1.5px solid transparent; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; transition: .18s; white-space: nowrap; line-height: 1.2;
}
.btn:hover { transform: translateY(-1px); }
.btn:disabled { opacity: .6; cursor: wait; transform: none; }
.btn-primary { background: linear-gradient(120deg, var(--c1), var(--c2)); color: #fff; box-shadow: 0 6px 16px color-mix(in srgb, var(--c2) 30%, transparent); }
.btn-ghost { background: #fff; color: var(--c2); border-color: var(--line); }
.btn-ghost:hover { border-color: var(--c2); }
.btn-success { background: var(--green); color: #fff; }
.btn-danger { background: #fff; color: var(--red); border-color: #f3c4c4; }
.btn-danger:hover { background: var(--red-bg); }
.btn-warn { background: var(--amber); color: #fff; }
.btn-sm { padding: 7px 14px; min-height: 36px; font-size: 14px; }
.btn-lg { padding: 14px 28px; font-size: 18px; }
.btn-block { width: 100%; }
.btn-round { width: 34px; height: 34px; min-height: 0; padding: 0; border-radius: 50%; background: rgba(0,0,0,.6); color: #fff; border: 0; }

/* ---------- Alerts / badges ---------- */
.alert { display: flex; gap: 10px; align-items: flex-start; padding: 12px 16px; border-radius: 12px; margin-bottom: 16px; font-weight: 500; }
.alert i { margin-top: 4px; }
.alert-success { background: var(--green-bg); color: #14532d; }
.alert-error { background: var(--red-bg); color: #7f1d1d; }
.alert-warn { background: var(--amber-bg); color: #78350f; }
.alert-info { background: var(--blue-bg); color: #0c4a6e; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 12.5px; font-weight: 600; white-space: nowrap; }
.b-green { background: var(--green-bg); color: var(--green); }
.b-red { background: var(--red-bg); color: var(--red); }
.b-amber { background: var(--amber-bg); color: var(--amber); }
.b-blue { background: var(--blue-bg); color: var(--blue); }
.b-gray { background: #f0f2f5; color: #555; }

/* ---------- Tabs & stats ---------- */
.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; margin-bottom: 16px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a { flex: none; display: inline-flex; align-items: center; gap: 8px; padding: 9px 16px; border-radius: 999px; background: #fff; border: 1.5px solid var(--line); color: var(--ink); text-decoration: none; font-weight: 600; }
.tabs a.on { background: var(--c2); border-color: var(--c2); color: #fff; }
.tabs a em { font-style: normal; background: rgba(0,0,0,.08); padding: 0 8px; border-radius: 999px; font-size: 13px; }
.tabs a.on em { background: rgba(255,255,255,.25); }
.stats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; margin-bottom: 18px; }
.stat { background: #fff; border-radius: var(--r); padding: 16px; border: 1px solid var(--line); box-shadow: var(--shadow); display: flex; gap: 12px; align-items: center; text-decoration: none; color: var(--ink); }
.stat .ico { width: 44px; height: 44px; border-radius: 12px; display: grid; place-items: center; font-size: 18px; flex: none; }
.stat b { font-size: 24px; display: block; line-height: 1.1; font-family: 'Prompt', sans-serif; }
.stat span { font-size: 13px; color: var(--muted); }
.search { display: flex; gap: 8px; margin-bottom: 16px; }
.search input { flex: 1; }

/* ---------- List (ตาราง → การ์ดบนมือถือ) ---------- */
.list { display: flex; flex-direction: column; gap: 12px; }
.item {
  background: #fff; border: 1px solid var(--line); border-radius: var(--r); padding: 16px 18px; box-shadow: var(--shadow);
  display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px 18px; align-items: center;
  border-left: 4px solid var(--c2);
}
.item.st-pending { border-left-color: var(--amber); }
.item.st-rejected { border-left-color: var(--red); }
.item.st-done { border-left-color: var(--green); }
.item h3 { font-size: 17px; margin-bottom: 4px; word-break: break-word; }
.item h3 a { color: var(--ink); text-decoration: none; }
.item h3 a:hover { color: var(--c2); }
.meta { display: flex; flex-wrap: wrap; gap: 4px 14px; color: var(--muted); font-size: 13.5px; }
.meta i { width: 15px; color: var(--c2); opacity: .8; }
.excerpt { color: #475467; font-size: 14.5px; margin-top: 6px; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
.device { font-size: 12px; color: #98a2b3; margin-top: 6px; word-break: break-all; }

/* ---------- Detail ---------- */
.kv { display: grid; grid-template-columns: 170px minmax(0, 1fr); border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.kv > div { padding: 12px 14px; border-bottom: 1px solid var(--line); word-break: break-word; }
.kv > div:nth-last-child(-n+2) { border-bottom: 0; }
.kv .k { background: var(--tint); font-weight: 600; color: var(--c1); }
.kv .k i { width: 20px; }
.bubble { padding: 16px 18px; border-radius: 14px; background: #f8f9fb; border: 1px solid var(--line); white-space: normal; word-break: break-word; }
.bubble.reply { background: var(--green-bg); border-color: #bfe7cc; }
.bubble-h { font-weight: 600; margin: 18px 0 8px; display: flex; align-items: center; gap: 8px; color: var(--c1); }
.pic { display: inline-block; border-radius: 12px; overflow: hidden; border: 1px solid var(--line); cursor: zoom-in; }
.pic img { display: block; max-height: 280px; width: auto; }
.ext-link { display: inline-flex; gap: 6px; align-items: center; word-break: break-all; }
.timeline { list-style: none; position: relative; padding-left: 22px; }
.timeline::before { content: ""; position: absolute; left: 7px; top: 6px; bottom: 6px; width: 2px; background: var(--line); }
.timeline li { position: relative; margin-bottom: 14px; font-size: 14px; }
.timeline li::before { content: ""; position: absolute; left: -20px; top: 6px; width: 12px; height: 12px; border-radius: 50%; background: #cfd4dc; border: 2px solid #fff; box-shadow: 0 0 0 1px #cfd4dc; }
.timeline li.ok::before { background: var(--green); box-shadow: 0 0 0 1px var(--green); }
.timeline li.no::before { background: var(--red); box-shadow: 0 0 0 1px var(--red); }
.timeline li.wait::before { background: var(--amber); box-shadow: 0 0 0 1px var(--amber); }
.timeline b { display: block; }

/* ---------- Empty / pager / misc ---------- */
.empty { text-align: center; padding: 48px 20px; color: var(--muted); background: #fff; border-radius: var(--r); border: 1px dashed #d0d5dd; }
.empty i { font-size: 40px; color: #c1c7d0; margin-bottom: 10px; display: block; }
.empty .btn { margin-top: 14px; }
.pager { display: flex; justify-content: center; align-items: center; gap: 6px; margin: 22px 0 6px; flex-wrap: wrap; }
.pager a, .pager span { min-width: 40px; height: 40px; border-radius: 999px; display: grid; place-items: center; background: #fff; border: 1px solid var(--line); color: var(--c2); text-decoration: none; padding: 0 12px; }
.pager a:hover { border-color: var(--c2); }
.pager .off { opacity: .4; }
.pager .now { background: var(--tint); font-weight: 600; color: var(--c1); }
.note { background: var(--amber-bg); border-radius: 12px; padding: 14px 16px; font-size: 14.5px; color: #6b4a14; }
.note b { display: block; margin-bottom: 4px; }
.steps { list-style: none; counter-reset: s; }
.steps li { counter-increment: s; display: flex; gap: 12px; margin-bottom: 12px; font-size: 14.5px; }
.steps li::before { content: counter(s); flex: none; width: 28px; height: 28px; border-radius: 50%; background: var(--tint); color: var(--c2); display: grid; place-items: center; font-weight: 700; }
.success-ico { width: 96px; height: 96px; border-radius: 50%; background: var(--green-bg); color: var(--green); display: grid; place-items: center; font-size: 46px; margin: 10px auto 16px; animation: pop .4s ease-out; }
@keyframes pop { from { transform: scale(.5); opacity: 0; } to { transform: scale(1); opacity: 1; } }
.login-box { max-width: 420px; margin: 20px auto; }
table.simple { width: 100%; border-collapse: collapse; }
table.simple th, table.simple td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; }
table.simple th { background: var(--tint); color: var(--c1); }

/* dialog */
dialog { border: 0; border-radius: 18px; padding: 0; width: min(520px, calc(100% - 28px)); box-shadow: 0 30px 80px rgba(0,0,0,.3); }
dialog::backdrop { background: rgba(15,20,35,.55); }
dialog form { padding: 22px; }
dialog h3 { margin-bottom: 12px; color: var(--c1); }

/* lightbox */
.lightbox { position: fixed; inset: 0; background: rgba(0,0,0,.88); z-index: 100; display: grid; place-items: center; padding: 20px; }
.lightbox[hidden] { display: none; }
.lightbox img { max-width: 100%; max-height: 90vh; border-radius: 8px; }
.lightbox button { position: absolute; top: 14px; right: 14px; width: 44px; height: 44px; border-radius: 50%; border: 0; background: rgba(255,255,255,.15); color: #fff; font-size: 20px; cursor: pointer; }

/* footer */
.foot { text-align: center; color: var(--muted); font-size: 13px; padding: 20px 16px 28px; }
.foot .ver { font-weight: 600; color: var(--c2); margin-top: 2px; }

/* ---------- Tablet ---------- */
@media (max-width: 960px) {
  .cols { grid-template-columns: 1fr; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .nav a span { display: none; }
  .nav a { padding: 10px 12px; }
  .who > span { display: none; }
}

/* ---------- Mobile: เมนูล่างแบบแอป ---------- */
@media (max-width: 720px) {
  body { padding-bottom: calc(68px + env(safe-area-inset-bottom)); }
  .topbar-in { padding: 8px 14px; }
  .brand img { width: 36px; height: 36px; }
  .brand b { font-size: 16px; }
  .nav {
    position: fixed; left: 0; right: 0; bottom: 0; margin: 0; z-index: 60; background: #fff;
    border-top: 1px solid var(--line); box-shadow: 0 -4px 16px rgba(0,0,0,.06);
    padding: 6px 6px calc(6px + env(safe-area-inset-bottom)); justify-content: space-around; gap: 0;
  }
  .nav a { flex: 1; flex-direction: column; gap: 2px; color: var(--muted); opacity: 1; font-size: 11.5px; padding: 6px 2px; border-radius: 12px; }
  .nav a span { display: block; }
  .nav a i { font-size: 19px; }
  .nav a.on { background: var(--tint); color: var(--c2); }
  .nav a:hover { background: var(--tint); }
  .userbox { margin-left: auto; border: 0; padding: 0; }
  .wrap { padding: 16px 12px 28px; }
  .page-title h1 { font-size: 22px; }
  .card { padding: 16px; }
  .hero { padding: 26px 18px; border-radius: 16px; }
  .hero h1 { font-size: 24px; }
  .hero img { width: 88px; height: 88px; }
  .grid2 { grid-template-columns: 1fr; }
  .item { grid-template-columns: 1fr; }
  .actions { justify-content: stretch; }
  .actions .btn { flex: 1; }
  .kv { grid-template-columns: 1fr; }
  .kv .k { border-bottom: 0; padding-bottom: 4px; }
  .kv > div:nth-last-child(2) { border-bottom: 0; }
  .stats { gap: 10px; }
  .stat { padding: 12px; }
  .stat b { font-size: 20px; }
  .btn-lg { width: 100%; }
  .menu-tile { padding: 18px; }
}
@media (prefers-reduced-motion: reduce) { * { transition: none !important; animation: none !important; } }
@media (max-width: 720px) { .hide-sm { display: none; } }
/* upload states & thumbnails */
.upload.busy { opacity: .7; pointer-events: none; position: relative; }
.upload.busy::after { content: "กำลังเตรียมรูป..."; position: absolute; inset: 0; display: grid; place-items: center; background: rgba(255,255,255,.8); border-radius: 12px; font-weight: 600; color: var(--c2); }
.pic-info { font-size: 12.5px; color: var(--muted); margin-top: 6px; }
.thumb { display: inline-block; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; border: 1px solid var(--line); flex: none; cursor: zoom-in; background: #f3f4f6; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.item-body { display: flex; gap: 14px; align-items: flex-start; min-width: 0; }
.item-body > div { min-width: 0; flex: 1; }
.pic-missing { display: inline-flex; gap: 6px; align-items: center; color: var(--muted); font-size: 13px; padding: 8px 12px; border: 1px dashed var(--line); border-radius: 10px; }
@media (max-width: 720px) { .thumb { width: 56px; height: 56px; } }
