/* เว็บจัดการออฟฟิศ: แบ่งจอแบบกล่องแชต โทนสีตามแบรนด์ทักคับ */
@font-face { font-family: Mitr; src: url(/manage/mitr-regular.woff2) format("woff2"); font-weight: 400; font-display: swap; }
@font-face { font-family: Mitr; src: url(/manage/mitr-medium.woff2) format("woff2"); font-weight: 500; font-display: swap; }

:root {
  --coral: #ff795e;
  --coral-soft: #fff1eb;
  --peach: #ffd9cd;
  --plum: #42243d;
  --ink: #42243d;
  --muted: #7a6476;
  --line: #f0e2da;
  --bg: #fffaf6;
  --card: #ffffff;
  --danger: #c8373f;
  --danger-soft: #fdecec;
  --ok: #1f8a5b;
  --ok-soft: #e8f6ef;
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; background: var(--bg); color: var(--ink); font: 400 15px/1.55 Mitr, system-ui, sans-serif; }
#app { height: 100%; }
h1 { font-size: 22px; font-weight: 500; margin: 0 0 4px; }
h2 { font-size: 16px; font-weight: 500; margin: 0 0 10px; }
p { margin: 0 0 10px; }
.muted { color: var(--muted); font-size: 13px; }
button, input, textarea, select { font: inherit; color: inherit; }
button { border: 1px solid var(--line); background: var(--card); border-radius: 10px; padding: 8px 14px; cursor: pointer; min-height: 40px; }
button:hover:not(:disabled) { background: var(--coral-soft); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--coral); border-color: var(--coral); font-weight: 500; }
button.primary:hover:not(:disabled) { background: #ff8c75; }
button.danger { color: var(--danger); border-color: #f2c9cb; }
button.danger:hover:not(:disabled) { background: var(--danger-soft); }
button:focus-visible, input:focus-visible, textarea:focus-visible, select:focus-visible, a:focus-visible { outline: 2px solid var(--coral); outline-offset: 2px; }
input, textarea, select { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: #fff; }
textarea { resize: none; display: block; }
label { display: block; font-size: 13px; color: var(--muted); margin: 0 0 14px; }
label input, label textarea { margin-top: 4px; color: var(--ink); font-size: 15px; }

.error { background: var(--danger-soft); color: var(--danger); border-radius: 10px; padding: 8px 12px; margin: 0 0 12px; font-size: 14px; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--plum); color: #fff; padding: 10px 16px; border-radius: 12px; z-index: 30; max-width: calc(100vw - 32px); }

/* หน้าเข้าสู่ระบบ */
.login { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(#fff, var(--coral-soft)); }
.login-card { width: 100%; max-width: 400px; background: var(--card); border: 1px solid var(--line); border-radius: 18px; padding: 24px; }
.login-card img { width: 56px; height: 56px; display: block; margin-bottom: 12px; }
.login-card button.primary { width: 100%; min-height: 46px; }

/* โครงหลัก */
.shell { height: 100%; display: grid; grid-template-columns: 84px minmax(0, 1fr); }
.rail { background: var(--plum); color: #fff; display: flex; flex-direction: column; align-items: stretch; padding: 12px 8px; gap: 4px; }
.rail img { width: 40px; height: 40px; align-self: center; margin-bottom: 10px; }
.rail button { background: transparent; border: 0; color: #f6e7ee; border-radius: 12px; padding: 8px 2px; font-size: 13px; position: relative; }
.rail button:hover:not(:disabled) { background: rgba(255, 255, 255, .12); }
.rail button.on { background: var(--coral); color: var(--plum); font-weight: 500; }
.rail .gap { flex: 1; }
.rail .dot { position: absolute; top: -4px; right: 0; background: #fff; color: var(--plum); border-radius: 999px; font-size: 11px; line-height: 16px; min-width: 16px; padding: 0 4px; }
.page { min-width: 0; min-height: 0; height: 100%; overflow: auto; }
.pad { padding: 24px; max-width: 980px; margin: 0 auto; }

/* กล่องแชต */
.chat { height: 100%; display: grid; grid-template-columns: 340px minmax(0, 1fr); }
.list { border-right: 1px solid var(--line); background: var(--card); display: flex; flex-direction: column; min-height: 0; }
.list-head { padding: 14px 14px 8px; }
.list-head h1 { font-size: 18px; display: flex; align-items: center; gap: 6px; }
.chips { display: flex; gap: 6px; margin-top: 8px; flex-wrap: wrap; }
.chips button { min-height: 32px; padding: 3px 10px; border-radius: 999px; font-size: 13px; }
.chips button.on { background: var(--coral); border-color: var(--coral); }
.rows { flex: 1; overflow-y: auto; }
.row { display: grid; grid-template-columns: 44px minmax(0, 1fr) auto; gap: 10px; width: 100%; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; text-align: left; padding: 10px 14px; background: transparent; align-items: center; }
.row.on { background: var(--coral-soft); }
.row .name { font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .prev { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.row .side { text-align: right; font-size: 12px; color: var(--muted); }
.count { display: inline-block; background: var(--coral); color: var(--plum); border-radius: 999px; font-size: 12px; font-weight: 500; line-height: 18px; min-width: 18px; padding: 0 5px; text-align: center; }
.avatar { width: 44px; height: 44px; border-radius: 50%; background: var(--peach); display: flex; align-items: center; justify-content: center; font-weight: 500; overflow: hidden; flex: none; }
.avatar img { width: 100%; height: 100%; object-fit: cover; display: block; }
.empty { padding: 32px 20px; text-align: center; color: var(--muted); }

.talk { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.talk-head { display: flex; align-items: center; gap: 10px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); min-height: 64px; }
.talk-head .who { flex: 1; min-width: 0; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.back { display: none; }
.stream { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 6px; }
.day { align-self: center; font-size: 12px; color: var(--muted); background: var(--coral-soft); padding: 2px 10px; border-radius: 999px; margin: 8px 0; }
.msg { max-width: min(72%, 560px); display: flex; flex-direction: column; align-items: flex-start; align-self: flex-start; }
.msg.mine { align-self: flex-end; align-items: flex-end; }
.bubble { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 8px 12px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.mine .bubble { background: var(--peach); border-color: var(--peach); }
.msg.pending .bubble { opacity: .6; }
.stamp { font-size: 11px; color: var(--muted); margin: 2px 4px 0; }
.shot { display: block; padding: 0; border: 0; background: var(--line); border-radius: 12px; overflow: hidden; }
.shot img { display: block; max-width: 280px; max-height: 320px; width: auto; height: auto; min-width: 120px; min-height: 80px; object-fit: cover; }
.composer { padding: 10px 12px; background: var(--card); border-top: 1px solid var(--line); display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 8px; align-items: end; }
.composer textarea { max-height: 160px; min-height: 44px; }
.composer button { min-height: 44px; }
.notice { padding: 14px 16px; background: var(--coral-soft); color: var(--muted); text-align: center; font-size: 14px; }
.more { align-self: center; min-height: 32px; font-size: 13px; }
.progress { font-size: 13px; color: var(--muted); padding: 0 16px 6px; background: var(--card); }

/* รูปเต็มจอ */
.viewer { position: fixed; inset: 0; background: rgba(32, 16, 28, .88); display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.viewer img { max-width: 100%; max-height: 100%; }
.viewer button { position: absolute; top: 12px; right: 12px; }

/* การ์ด ประกาศ สถิติ ตั้งค่า */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 16px; margin: 0 0 14px; }
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 12px; margin-bottom: 14px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 14px; }
.tile .value { font-size: 26px; font-weight: 500; line-height: 1.25; }
.ann { display: flex; flex-direction: column; gap: 8px; }
.ann .meta { display: flex; justify-content: space-between; gap: 12px; color: var(--muted); font-size: 13px; flex-wrap: wrap; }
.ann .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.pad > .actions { margin: 0 0 14px; }
.actions input { flex: 1; min-width: 180px; }
.tag { background: var(--coral-soft); border-radius: 999px; padding: 1px 8px; font-size: 12px; font-weight: 400; }
.tag.ok { background: var(--ok-soft); color: var(--ok); }
.tag.danger { background: var(--danger-soft); color: var(--danger); }
.bigface { width: 88px; height: 88px; font-size: 30px; }
.linkbox { display: flex; gap: 8px; align-items: center; }
.linkbox code { flex: 1; min-width: 0; background: var(--coral-soft); padding: 8px 10px; border-radius: 10px; overflow-wrap: anywhere; font-size: 14px; }

/* กราฟ */
.chart-wrap { position: relative; }
.chart { display: block; width: 100%; height: 170px; }
.chart .grid { stroke: var(--line); stroke-width: 1; }
.chart .label { fill: var(--muted); font-size: 11px; font-family: Mitr, system-ui, sans-serif; }
.chart .bar { fill: var(--coral); }
.chart .hit { fill: transparent; }
.chart g.on .bar { fill: var(--plum); }
.tip { position: absolute; top: 0; background: var(--plum); color: #fff; border-radius: 8px; padding: 4px 8px; font-size: 12px; pointer-events: none; white-space: nowrap; transform: translateX(-50%); }
table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: right; padding: 6px 8px; border-bottom: 1px solid var(--line); font-weight: 400; white-space: nowrap; }
th:first-child, td:first-child { text-align: left; }
th { color: var(--muted); font-size: 13px; }
.scroll-x { overflow-x: auto; }
summary { cursor: pointer; font-weight: 500; }

/* มือถือ แสดงทีละหน้า และย้ายเมนูลงล่าง */
@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) auto; }
  .rail { order: 2; flex-direction: row; padding: 6px; }
  .rail img, .rail .gap { display: none; }
  .rail button { flex: 1; }
  .chat { grid-template-columns: minmax(0, 1fr); }
  .chat.open .list { display: none; }
  .chat:not(.open) .talk { display: none; }
  .list { border-right: 0; }
  .back { display: inline-block; }
  .pad { padding: 16px; }
  .msg { max-width: 86%; }
  .shot img { max-width: 220px; }
}

/* หน้าเข้าสู่ระบบกลาง */
.login-tabs { display: flex; gap: 6px; margin: 12px 0 16px; }
.login-tabs button { flex: 1; min-height: 40px; padding: 6px 4px; font-size: 14px; }
.login-tabs button.on { background: var(--coral); border-color: var(--coral); font-weight: 500; }
.login-qr { text-align: center; }
.login-qr img { width: 240px; height: 240px; max-width: 100%; display: block; margin: 0 auto 10px; background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 8px; box-sizing: content-box; }
.login-pin { font-size: 40px; font-weight: 500; letter-spacing: .18em; text-align: center; background: var(--coral-soft); border-radius: 14px; padding: 14px 8px; margin: 0 0 12px; font-variant-numeric: tabular-nums; }
.login-actions { display: flex; gap: 8px; }
.login-actions button { flex: 1; }
.login-demo { background: var(--coral-soft); border-radius: 10px; padding: 8px 10px; font-size: 13px; }
.login-extra { text-align: center; margin: 16px 0 0; font-size: 13px; }
.login-extra button { border: 0; background: transparent; text-decoration: underline; color: var(--muted); min-height: 32px; font-size: 13px; }

/* เครื่องหมายสถานะ และข้อความตอบด่วน */
.tag.wait { background: var(--peach); }
.tag.work { background: #fff3d6; color: #8a5a00; }
.tag.done { background: #eee9ef; color: var(--muted); }
.row .tag { display: inline-block; margin-top: 3px; }
.mark-select { width: auto; flex: none; min-height: 40px; padding: 6px 8px; font-size: 14px; }
.composer { grid-template-columns: auto auto minmax(0, 1fr) auto; }
.composer button.on { background: var(--coral-soft); border-color: var(--coral); }
.quick { background: var(--card); border-top: 1px solid var(--line); padding: 10px 12px; max-height: 240px; overflow-y: auto; }
.quick h3, .reply-group h3 { font-size: 13px; font-weight: 500; color: var(--muted); margin: 6px 0; }
.quick-row { display: flex; flex-wrap: wrap; gap: 6px; }
.quick-item { display: inline-flex; }
.quick-item button { min-height: 36px; font-size: 14px; padding: 4px 10px; }
.quick-send { border-radius: 10px 0 0 10px; background: var(--coral-soft); border-color: var(--peach); }
.quick-edit { border-radius: 0 10px 10px 0; border-left: 0; color: var(--muted); }
.reply-row { display: flex; gap: 8px; align-items: center; padding: 8px 0; border-bottom: 1px solid var(--line); }
.reply-text { flex: 1; min-width: 0; overflow-wrap: anywhere; white-space: pre-wrap; }
.reply-text strong { font-weight: 500; }
.reply-group { margin-bottom: 14px; }
@media (max-width: 760px) {
  .talk-head { flex-wrap: wrap; }
  .talk-head .tag { display: none; }
  .mark-select { max-width: 140px; }
}

/* แถบข้อมูลลูกค้าฝั่งขวา */
.chat { grid-template-columns: 320px minmax(0, 1fr) 280px; }
.side { border-left: 1px solid var(--line); background: var(--card); padding: 16px; overflow-y: auto; min-height: 0; }
.side-face { text-align: center; margin-bottom: 14px; overflow-wrap: anywhere; }
.side-face .avatar { margin: 0 auto 8px; }
.side-face strong { font-weight: 500; }
.side-label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.side-close, .side-toggle { display: none; }
.tag-list { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
.tag.cust { background: #eef0fb; color: #3b4170; display: inline-flex; align-items: center; gap: 2px; }
.tag.cust button { border: 0; background: transparent; padding: 0 2px; min-height: 22px; min-width: 22px; line-height: 1; color: inherit; }
.tag-add { display: flex; gap: 6px; margin-bottom: 6px; }
.tag-add input { flex: 1; min-width: 0; }
.row-tags { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px; }
.row .tag { margin-top: 0; }
.tag-filter { margin-top: 8px; padding: 6px 8px; font-size: 14px; }
.side textarea, .side input { font-size: 14px; }
/* จอเล็กกว่านี้ ซ่อนแถบไว้หลังปุ่ม */
@media (max-width: 1180px) {
  .chat { grid-template-columns: 320px minmax(0, 1fr); }
  .side { display: none; }
  .side-toggle { display: inline-block; flex: none; }
  .chat.side-open .side { display: block; position: fixed; top: 0; right: 0; bottom: 0; width: min(320px, 100vw); z-index: 10; box-shadow: -4px 0 16px rgba(66, 36, 61, .18); }
  .side-close { display: block; margin-left: auto; }
}
@media (max-width: 760px) {
  .chat { grid-template-columns: minmax(0, 1fr); }
  .side-toggle { padding: 6px 8px; font-size: 13px; }
}

/* ปุ่มสถานะแชต แต่ละสถานะมีสีประจำ และมีคำกำกับเสมอ */
.mark-bar { display: flex; gap: 8px; padding: 8px 16px; background: var(--card); border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.mark { flex: 1 1 110px; font-weight: 500; font-size: 14px; min-height: 40px; }
.mark.working { color: #8a5a00; background: #fff8e6; border-color: #f2d48a; }
.mark.done { color: #1f6f4c; background: #e8f6ef; border-color: #a9dcc3; }
.mark.spam { color: var(--danger); background: var(--danger-soft); border-color: #f2c9cb; }
.mark.working:hover:not(:disabled) { background: #ffefc2; }
.mark.done:hover:not(:disabled) { background: #cdeedd; }
.mark.spam:hover:not(:disabled) { background: #fbd9db; }
.mark.working.on { background: #e9a100; border-color: #e9a100; color: #2c1d00; }
.mark.done.on { background: #1f8a5b; border-color: #1f8a5b; color: #fff; }
.mark.spam.on { background: var(--danger); border-color: var(--danger); color: #fff; }
.tag.work { background: #fff3d6; color: #8a5a00; }
.tag.done { background: var(--ok-soft); color: #1f6f4c; }
/* หน้านักพัฒนา */
.secret-box { border-color: var(--coral); background: var(--coral-soft); }
.checks { display: grid; gap: 4px; margin: 0 0 14px; }
label.check { display: flex; align-items: center; gap: 8px; margin: 0; color: var(--ink); font-size: 14px; }
label.check input { width: auto; margin: 0; }
h3.sub { font-size: 15px; font-weight: 500; margin: 16px 0 8px; }

/* รายการตอบกลับแบบเลื่อนลง */
.quick { padding: 0; max-height: min(320px, 45vh); display: flex; flex-direction: column; overflow: hidden; }
.quick-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); }
.quick-head strong { font-weight: 500; }
.quick-manage { min-height: 34px; padding: 3px 12px; font-size: 14px; }
.quick-list { overflow-y: auto; padding: 0 8px 8px; }
.quick-list h3 { position: sticky; top: 0; background: var(--card); margin: 0; padding: 8px 4px 4px; }
button.quick-row { display: block; width: 100%; text-align: left; border: 0; border-radius: 10px; padding: 8px 10px; min-height: 44px; background: transparent; }
.quick-title { display: block; font-weight: 500; font-size: 14px; }
.quick-text { display: block; color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.var-row { margin: 0 0 8px; }
.var-row button { min-height: 34px; padding: 3px 12px; font-size: 14px; }
.reply-preview { background: var(--coral-soft); border-radius: 10px; padding: 8px 12px; font-size: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.reply-preview:empty { display: none; }
.rail button { font-size: 12px; line-height: 1.3; }

/* เมนูแฮมเบอร์เกอร์ด้านซ้าย ใช้เหมือนกันทุกขนาดจอ */
.shell { display: grid; height: 100%; grid-template-columns: minmax(0, 1fr); grid-template-rows: 52px minmax(0, 1fr); position: relative; }
.page { grid-row: 2; }
.topbar { grid-row: 1; display: flex; align-items: center; gap: 10px; padding: 0 12px; background: var(--plum); color: #fff; min-width: 0; }
.topbar strong { font-weight: 500; white-space: nowrap; }
.topbar-office { color: #e6d3de; margin-left: auto; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.burger { position: relative; flex: none; width: 44px; height: 44px; min-height: 44px; padding: 0; border: 0; border-radius: 10px; background: transparent; color: #fff; display: flex; align-items: center; justify-content: center; }
.burger:hover:not(:disabled) { background: rgba(255, 255, 255, .14); }
.bars { display: flex; flex-direction: column; gap: 4px; }
.bars i { display: block; width: 20px; height: 2px; border-radius: 2px; background: currentColor; }
.burger .dot { position: absolute; top: 2px; right: 0; background: var(--coral); color: var(--plum); border-radius: 999px; font-size: 11px; line-height: 16px; min-width: 16px; padding: 0 4px; font-weight: 500; }
.scrim { position: fixed; inset: 0; background: rgba(32, 16, 28, .42); opacity: 0; pointer-events: none; transition: opacity .18s; z-index: 24; }
.scrim.open { opacity: 1; pointer-events: auto; }
.rail { position: fixed; top: 0; bottom: 0; left: 0; order: 0; width: min(280px, 84vw); flex-direction: column; padding: 14px 12px; gap: 4px; transform: translateX(-102%); transition: transform .18s; z-index: 25; visibility: hidden; }
.rail.open { transform: none; visibility: visible; }
.rail button { flex: none; text-align: left; padding: 10px 14px; min-height: 46px; font-size: 15px; display: flex; align-items: center; justify-content: space-between; }
.rail .gap { display: block; flex: 1; }
.rail .dot { position: static; }
.rail img { display: block; width: 32px; height: 32px; margin: 0; align-self: auto; }
.rail-brand { display: flex; align-items: center; gap: 10px; padding: 4px 8px 14px; font-weight: 500; overflow-wrap: anywhere; }
@media (prefers-reduced-motion: reduce) {
  .rail, .scrim { transition: none; }
}
