/* PPN Talk — dark โมเดิร์น มือถือเป็นหลัก
   DNA เมดิเตอร์เรเนียนตีความใหม่: พื้นกรมท่าเข้ม + ฟ้าทะเล accent เดียว */
:root {
  --bg: #0f1420;
  --bg2: #171e2e;
  --card: #1c2437;
  --border: #2a3550;
  --text: #e8ecf4;
  --muted: #8b96ad;
  --accent: #4d96d2;        /* ฟ้าทะเล */
  --accent-deep: #33415c;
  --me: #2b5d8a;            /* (เดิม) */
  --me-green: #15803c;      /* bubble ของฉัน — เขียวแบบ LINE โทนเข้ม */
  --ok: #3dba6f;
  --warn: #e0a93c;
  --bad: #d95d5d;
  --radius: 14px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: var(--bg); color: var(--text);
  font-family: 'Segoe UI', 'Leelawadee UI', system-ui, sans-serif;
  font-size: 16px; overscroll-behavior: none;
}
#app { height: 100dvh; display: flex; flex-direction: column; }
.view { flex: 1; display: flex; flex-direction: column; min-height: 0; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; background: none; border: none; cursor: pointer; }

/* topbar */
.topbar {
  display: flex; align-items: center; gap: 10px;
  padding: calc(env(safe-area-inset-top) + 10px) 14px 10px;
  background: var(--bg2); border-bottom: 1px solid var(--border);
}
.topbar h1 { font-size: 17px; font-weight: 600; flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar-right { display: flex; align-items: center; gap: 10px; }
.icon-btn { font-size: 20px; padding: 4px 8px; border-radius: 10px; }
.icon-btn:active { background: var(--card); }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--ok); }
.dot.off { background: var(--bad); }

/* claim */
.claim-box { margin: auto; text-align: center; padding: 32px; max-width: 340px; }
.claim-box .logo { font-size: 56px; margin-bottom: 12px; }
.claim-box h1 { margin-bottom: 8px; }
.claim-box p { color: var(--muted); margin-bottom: 20px; }

/* room list */
.room-list { list-style: none; overflow-y: auto; flex: 1; }
.room-list li {
  display: flex; align-items: center; gap: 12px;
  padding: 14px 16px; border-bottom: 1px solid var(--border); cursor: pointer;
}
.room-list li:active { background: var(--card); }
.room-avatar {
  width: 46px; height: 46px; border-radius: 50%; flex-shrink: 0;
  background: var(--accent-deep); display: flex; align-items: center; justify-content: center;
  font-size: 20px; color: #fff; font-weight: 700;
}
.room-info { flex: 1; min-width: 0; }
.room-name { font-weight: 600; }
.room-preview { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.room-right { display: flex; flex-direction: column; align-items: flex-end; gap: 4px; flex-shrink: 0; }
.room-time { font-size: 11px; color: var(--muted); }
.badge {
  background: var(--me-green); color: #fff; font-size: 12px; font-weight: 700;
  border-radius: 999px; padding: 2px 8px; min-width: 22px; text-align: center;
}
.empty { color: var(--muted); text-align: center; padding: 40px 20px; }

/* messages — โครงแบบ LINE: avatar ซ้าย · bubble · เวลา+อ่านแล้วข้าง bubble */
.msg-list { flex: 1; overflow-y: auto; padding: 12px 10px 4px; display: flex; flex-direction: column; gap: 3px; }
.mrow { display: flex; align-items: flex-end; gap: 7px; max-width: 100%; }
.mrow.me { flex-direction: row-reverse; }
.avatar {
  width: 34px; height: 34px; border-radius: 50%; flex-shrink: 0; align-self: flex-start;
  display: flex; align-items: center; justify-content: center;
  color: #fff; font-weight: 700; font-size: 15px;
}
.avatar.ghost { background: none !important; }
.mcol { display: flex; flex-direction: column; align-items: flex-start; max-width: 72%; min-width: 0; }
.mrow.me .mcol { align-items: flex-end; }
.sender { font-size: 12px; color: var(--muted); margin: 5px 2px 3px; }
.bubble {
  background: var(--card); border-radius: 16px; border-top-left-radius: 5px; padding: 8px 13px;
  word-wrap: break-word; overflow-wrap: anywhere; white-space: pre-wrap; line-height: 1.45;
}
.mrow.me .bubble {
  background: var(--me-green); color: #fff;
  border-radius: 16px; border-top-right-radius: 5px;
}
.side {
  font-size: 10px; color: var(--muted); flex-shrink: 0;
  display: flex; flex-direction: column; gap: 1px; padding-bottom: 2px;
}
.mrow.me .side { align-items: flex-end; text-align: right; }
.side .read { color: var(--accent); }
.mrow img.photo { max-width: 100%; border-radius: 14px; display: block; }
.sys { align-self: center; color: var(--muted); font-size: 12px; background: var(--bg2); border-radius: 999px; padding: 3px 12px; margin: 4px 0; }
.date-chip {
  align-self: center; color: var(--muted); font-size: 11px;
  background: var(--bg2); border-radius: 999px; padding: 3px 14px; margin: 10px 0 6px;
}

/* การ์ดใบขอราคา */
.price-card {
  background: var(--card); border: 1px solid var(--border); border-left: 4px solid var(--warn);
  border-radius: var(--radius); padding: 12px 14px; min-width: 230px;
}
.price-card.approved { border-left-color: var(--ok); }
.price-card.adjusted { border-left-color: var(--accent); }
.price-card.rejected { border-left-color: var(--bad); }
.price-card .pc-head { font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.price-card .pc-num { font-size: 26px; font-weight: 700; font-variant-numeric: tabular-nums; }
.price-card .pc-sub { font-size: 14px; color: var(--muted); font-variant-numeric: tabular-nums; margin: 2px 0 8px; }
.price-card .pc-status { font-size: 14px; font-weight: 600; }
.price-card .pc-actions { display: flex; gap: 8px; margin-top: 10px; }
.price-card .pc-actions .btn { flex: 1; padding: 8px 4px; font-size: 14px; }

/* composer */
.composer {
  display: flex; align-items: flex-end; gap: 8px;
  padding: 8px 10px calc(env(safe-area-inset-bottom) + 8px);
  background: var(--bg2); border-top: 1px solid var(--border);
}
.composer textarea {
  flex: 1; resize: none; max-height: 110px;
  background: var(--card); color: var(--text); border: 1px solid var(--border);
  border-radius: 20px; padding: 9px 14px; font: inherit; outline: none;
}
.composer textarea:focus { border-color: var(--accent); }
.send-btn {
  background: var(--accent); color: #fff; font-weight: 600;
  border-radius: 20px; padding: 9px 18px;
}
.send-btn:disabled { opacity: .4; }

/* sheet (เมนูแนบ + ฟอร์ม) */
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  background: var(--bg2); border-top: 1px solid var(--border);
  border-radius: 18px 18px 0 0; padding: 16px 16px calc(env(safe-area-inset-bottom) + 16px);
  display: flex; flex-direction: column; gap: 10px;
  box-shadow: 0 -8px 30px rgba(0,0,0,.5);
}
.sheet button { text-align: left; padding: 13px 14px; border-radius: 12px; background: var(--card); font-size: 16px; }
.sheet button:active { background: var(--accent-deep); }
.sheet.form h2 { font-size: 17px; }
.sheet.form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.sheet.form input, .sheet.form select {
  background: var(--card); color: var(--text); border: 1px solid var(--border);
  border-radius: 10px; padding: 10px 12px; font: inherit; font-size: 16px; outline: none;
}
.sheet.form input:focus, .sheet.form select:focus { border-color: var(--accent); }
.pf-total { font-size: 20px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; color: var(--accent); }
.row { display: flex; gap: 10px; }
.row .btn { flex: 1; }
.btn {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 11px 16px; font-weight: 600; text-align: center;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.good { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { background: var(--bad); border-color: var(--bad); color: #fff; }

/* admin */
.admin-body { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 14px; }
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.card h2 { font-size: 15px; margin-bottom: 10px; }
.card table { width: 100%; border-collapse: collapse; font-size: 14px; }
.card td, .card th { padding: 6px 4px; text-align: left; border-bottom: 1px solid var(--border); }
.card .small { font-size: 12px; color: var(--muted); }
.invite-link {
  background: var(--bg); border: 1px dashed var(--accent); border-radius: 10px;
  padding: 10px; font-family: monospace; font-size: 13px; word-break: break-all; margin-top: 8px;
}

/* จอกาง (Fold5 กาง / แท็บเล็ต): two-pane */
@media (min-width: 600px) {
  #app { flex-direction: row; }
  #view-rooms { width: 320px; border-right: 1px solid var(--border); flex: none; }
  #view-chat, #view-admin { flex: 1; }
  #btn-back { display: none; }
  .msg { max-width: 62%; }
}
