:root {
  color-scheme: light;
  --bg: #f8f5f0;
  --panel: #fff;
  --ink: #2c211d;
  --mute: #695750;
  --line: #e9e0d8;
  --brand: #a0381c;
  --brand-ink: #fff8f1;
  --bad: #9f281f;
  --ok: #246143;
  --them: #f2ebe4;
  --selected: #f7ebe5;
  --sidebar: #2c211d;
  --sidebar-ink: #fff7ee;
  --sidebar-mute: #ded0c6;
  --sidebar-line: #5b463c;
  --shadow: 0 2px 5px rgb(60 35 22 / 5%);
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #1a1411;
  --panel: #271d19;
  --ink: #f7eee7;
  --mute: #cfbdb0;
  --line: #493930;
  --brand: #ff9b78;
  --brand-ink: #36190f;
  --bad: #ffaaa2;
  --ok: #94d6af;
  --them: #42332b;
  --selected: #472d23;
  --sidebar: #241b17;
  --shadow: none;
}
* { box-sizing: border-box; }
body { margin: 0; font: 1rem/1.55 system-ui, "Noto Sans Thai", Tahoma, sans-serif; background: var(--bg); color: var(--ink); }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 1px solid var(--line); background: var(--panel); padding: .45rem .8rem; border-radius: .55rem; }
button.primary { background: var(--brand); color: var(--brand-ink); border-color: var(--brand); }
button.danger, .err { color: var(--bad); }
button:disabled { opacity: .55; cursor: default; }
input, select, textarea { border: 1px solid var(--line); background: var(--panel); border-radius: .55rem; padding: .5rem .7rem; width: 100%; }
textarea { resize: vertical; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; }
.muted { color: var(--mute); }
.ok { color: var(--ok); }
.login { width: min(28rem, calc(100% - 2rem)); margin: 10vh auto; padding: 1.75rem; background: var(--panel); border: 1px solid var(--line); border-radius: 1.1rem; box-shadow: var(--shadow); display: grid; gap: .8rem; }
.login .logo { justify-self: center; border-radius: 1rem; }
.login h1 { margin: 0 0 .45rem; font-size: 1.4rem; text-align: center; }
.phone { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: .55rem; background: var(--panel); overflow: hidden; }
.phone:focus-within { outline: 2px solid var(--brand); outline-offset: -1px; }
.phone .cc { display: flex; align-items: center; gap: .5rem; padding: 0 .75rem; border-right: 1px solid var(--line); color: var(--mute); white-space: nowrap; }
.phone .flag { width: 24px; height: 16px; border-radius: 2px; background: linear-gradient(to bottom,#a51931 0 16.67%,#f4f5f8 16.67% 33.33%,#2d2a4a 33.33% 66.67%,#f4f5f8 66.67% 83.33%,#a51931 83.33% 100%); }
.phone input { border: 0; border-radius: 0; background: transparent; outline: 0; flex: 1; min-width: 0; }

.workspace { display: grid; grid-template-columns: clamp(13rem, 18vw, 17.5rem) minmax(0, 1fr); min-height: 100vh; }
.sidebar { position: sticky; top: 0; height: 100dvh; overflow: auto; background: var(--sidebar); color: var(--sidebar-ink); display: flex; flex-direction: column; padding: 1.25rem .95rem; }
.sidebar-head, .brand { display: flex; align-items: center; gap: .7rem; }
.sidebar-head { justify-content: space-between; padding: .2rem .2rem 1.15rem; }
.brand-logo { width: clamp(2.75rem, 4.25vw, 4rem); height: auto; border-radius: .8rem; }
.brand strong, .brand span { display: block; }
.brand strong { font-size: 1.35rem; line-height: 1.15; }
.brand span { font-size: .875rem; color: var(--sidebar-mute); margin-top: .1rem; }
.sidebar-content { display: flex; flex-direction: column; flex: 1; }
.tabs { flex: 1; }
.nav-group { display: grid; gap: .23rem; padding: .85rem 0; border-top: 1px solid var(--sidebar-line); }
.nav-group p { color: var(--sidebar-mute); font-size: .875rem; margin: 0 .65rem .3rem; font-weight: 650; }
.tabs button, .nav-toggle { border: 0; background: transparent; color: var(--sidebar-ink); text-align: left; }
.icon { display: inline-block; width: 1.35rem; height: 1.35rem; flex: none; fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }
.tabs button { display: flex; align-items: center; gap: .75rem; padding: .65rem .75rem; }
.tabs button:hover { background: #4c372e; }
.tabs button.on { background: #a0381c; font-weight: 650; }
.sidebar :focus-visible { outline-color: #ffb695; }
.nav-toggle { display: none; border: 1px solid var(--sidebar-line); }
.account { display: grid; justify-items: start; padding-top: .75rem; border-top: 1px solid var(--sidebar-line); gap: .4rem; }
.account button:not(.primary) { background: transparent; color: var(--sidebar-ink); border-color: var(--sidebar-line); }

.page-heading, .page { max-width: 94rem; margin: 0 auto; padding-inline: clamp(1rem, 2.3vw, 2.4rem); }
.page-heading { padding-top: 1.8rem; padding-bottom: 1.2rem; display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: .6rem 1rem; }
.page-heading h1 { margin: 0; font-size: clamp(1.65rem, 3vw, 3.15rem); line-height: 1.25; letter-spacing: -.025em; }
.page-heading h1:focus { outline: none; }
.theme-toggle { flex: none; min-height: 2.6rem; color: var(--mute); font-size: .875rem; }
.theme-toggle[aria-pressed="true"] { color: var(--ink); background: var(--them); }
.login .theme-toggle { justify-self: end; }
.page { padding-bottom: 2rem; }
.store-field { position: relative; margin-bottom: .8rem; }
.store-field .icon { position: absolute; left: .8rem; top: .7rem; pointer-events: none; }
.store-switcher {
  width: 100%;
  background: var(--sidebar);
  border-color: var(--sidebar-line);
  color: var(--sidebar-ink);
  padding-inline-start: 2.55rem;
  color-scheme: dark;
}
.account { font-size: .875rem; color: var(--sidebar-mute); }
.tabs button .badge { margin-inline-start: auto; }
.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.3rem;
  height: 1.3rem;
  padding-inline: .3rem;
  border-radius: 99px;
  background: var(--brand);
  color: var(--brand-ink);
  font-size: .75rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
}
.tabs button.on .badge { background: #fff2e4; color: #792913; }
.page { overflow: auto; }
.inbox {
  display: grid;
  grid-template-columns: clamp(14rem, 23vw, 23rem) minmax(0, 1fr);
  min-height: 32rem;
  height: calc(100dvh - 8.5rem);
  border: 1px solid var(--line);
  border-radius: .95rem;
  background: var(--panel);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.list { min-width: 0; min-height: 0; border-inline-end: 1px solid var(--line); display: flex; flex-direction: column; }
.filters { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .5rem; padding: .85rem; border-bottom: 1px solid var(--line); }
.search-field { grid-column: 1/-1; position: relative; }
.search-field .icon { position: absolute; left: .7rem; top: .65rem; color: var(--mute); pointer-events: none; }
.search-field input { padding-inline-start: 2.35rem; background: var(--bg); }
.filters input, .filters select { font-size: .9rem; min-width: 0; }
.rows { overflow: auto; flex: 1; }
.rows .row {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  gap: .65rem;
  align-items: center;
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
  background: transparent;
  padding: .85rem .75rem;
  text-align: start;
}
.rows .row:focus-visible { outline-offset: -3px; }
.rows .row:hover, .rows .row.sel { background: var(--selected); }
.avatar { position: relative; display: grid; place-items: center; flex: 0 0 auto; width: 2.75rem; height: 2.75rem; border-radius: 50%; overflow: hidden; color: var(--brand); background: var(--them); font-weight: 750; }
.avatar img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.row .avatar { width: clamp(2.5rem, 4vw, 3.45rem); height: auto; aspect-ratio: 1; }
.row-text, .row-meta { display: grid; gap: .17rem; min-width: 0; }
.row .nm, .row .pv { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .nm { font-size: 1.0625rem; font-weight: 750; }
.row .pv, .row-meta { color: var(--mute); font-size: .9rem; }
.row-meta { justify-items: end; }
.row-meta time { max-width: 5.2rem; text-align: right; }
.row-tags { display: flex; gap: .25rem; flex-wrap: wrap; }
.row-tags:empty { display: none; }
.tag, .case-status { border-radius: 99px; color: var(--mute); background: var(--them); padding: .15rem .5rem; font-size: .8rem; overflow-wrap: anywhere; }
.case-status { font-size: .875rem; white-space: nowrap; }
.case-status.open { background: #e6f1e7; color: #225a3d; }
.chat { min-width: 0; min-height: 0; display: grid; }
.chat:has(.case-details) { grid-template-columns: minmax(0, 1fr) clamp(12rem, 19vw, 19rem); }
.chat-thread { min-width: 0; min-height: 0; display: flex; flex-direction: column; }
.chat-heading { display: flex; align-items: center; gap: .55rem; min-height: 4.6rem; padding: .85rem 1rem; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.chat-heading h2, .case-details h2 { margin: 0; font-size: clamp(1.1rem, 1.7vw, 1.5rem); }
.chat-heading h2 { overflow-wrap: anywhere; min-width: 0; }
.chat-heading h2:focus { outline: 0; }
.back-to-inbox { display: none; }
.case-details {
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 1.2rem;
  border-inline-start: 1px solid var(--line);
  padding: 1.05rem;
  overflow: auto;
}
.case-details h2 { display: flex; align-items: center; min-height: 4.6rem; margin: -1.05rem -1.05rem 0; padding: .85rem 1.05rem; border-bottom: 1px solid var(--line); }
.case-details label { display: grid; gap: .35rem; font-weight: 650; min-width: 0; }
.case-details label :is(input, select, textarea) { font-weight: 400; font-size: .9375rem; min-width: 0; }
.case-details textarea { min-height: 7rem; }
.case-details .ln button { width: 100%; color: var(--brand); border-color: var(--brand); }
.msgs { flex: 1; overflow: auto; padding: 1.15rem; display: flex; flex-direction: column; gap: .85rem; }
.message { display: flex; align-self: flex-start; gap: .6rem; align-items: start; max-width: 88%; }
.message.outgoing { align-self: flex-end; }
.message .avatar { width: 2.3rem; height: 2.3rem; }
.message-content { display: grid; justify-items: start; min-width: 0; }
.outgoing .message-content { justify-items: end; }
.m { padding: .58rem .85rem; border-radius: .8rem; background: var(--them); font-size: 1.0625rem; white-space: pre-wrap; overflow-wrap: anywhere; }
.outgoing .m { color: var(--brand-ink); background: var(--brand); }
.message-meta { display: flex; flex-wrap: wrap; gap: .25rem .5rem; margin-top: .22rem; color: var(--mute); font-size: .8rem; }
.outgoing .message-meta { justify-content: end; }
.composer { padding: .75rem; }
.compose-field { display: flex; align-items: end; gap: .6rem; padding: .4rem; border: 1px solid var(--line); border-radius: .75rem; }
.composer textarea { min-width: 0; border: 0; background: transparent; }
.composer textarea:focus-visible { outline-offset: -2px; }
.composer button { min-height: 2.5rem; padding-inline: 1.15rem; }
.empty { margin: auto; color: var(--mute); text-align: center; padding: 1.25rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 12rem), 1fr)); gap: .75rem; margin-bottom: 1rem; }
.card, .panel { min-width: 0; border: 1px solid var(--line); border-radius: .9rem; background: var(--panel); padding: 1rem; box-shadow: var(--shadow); }
.card .v { font-size: 1.5rem; font-weight: 750; }
.panel { margin-bottom: 1rem; display: grid; gap: .65rem; overflow: auto; }
.panel h3 { margin: 0; }
table { width: 100%; border-collapse: collapse; background: var(--panel); border: 1px solid var(--line); font-size: .9rem; }
th, td { padding: .65rem .75rem; border-bottom: 1px solid var(--line); text-align: start; vertical-align: top; }
th { color: var(--mute); font-weight: 650; white-space: nowrap; }
.grid2 { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: .65rem; }
.toast { position: fixed; bottom: 1rem; left: 50%; transform: translateX(-50%); max-width: calc(100% - 2rem); width: max-content; background: var(--ink); color: var(--bg); padding: .55rem 1rem; border-radius: .7rem; z-index: 5; }
.toast.err { background: #8f2419; color: #fff; }
pre { overflow-x: auto; }

@media (min-width: 1151px) {
  .workspace { grid-template-columns: clamp(13.5rem, 18.75vw, 18rem) minmax(0, 1fr); }
  .sidebar { padding: 2.25rem 1rem 1.25rem; }
  .sidebar-head { padding: 0 .7rem 2rem; }
  .brand-logo { width: clamp(3.25rem, 4.8vw, 4.625rem); }
  .brand strong { font-size: clamp(1.45rem, 2.1vw, 2.05rem); }
  .brand span { font-size: .95rem; }
  .sidebar .nav-group p { margin-inline: 1.05rem; font-size: 1.04rem; }
  .sidebar .tabs button { gap: 1rem; min-height: 3.2rem; padding: .55rem 1rem; font-size: clamp(1rem, 1.25vw, 1.2rem); }
  .sidebar .tabs button .icon { width: 1.55rem; height: 1.55rem; }
  .store-field { margin-bottom: 1rem; }
  .store-field .icon { inset-block-start: .95rem; }
  .store-switcher { min-height: 3.65rem; font-size: 1.05rem; }

  [data-view="inbox"] .page-heading { min-height: 8.75rem; max-width: 100rem; padding: 1rem clamp(1.5rem, 2.5vw, 2.4rem); }
  [data-view="inbox"] .page { max-width: 100rem; padding-inline: clamp(.85rem, .98vw, 1.25rem); }
  .inbox { grid-template-columns: clamp(15rem, 24.3vw, 23.375rem) minmax(0, 1fr); height: calc(100dvh - 11rem); }
  .chat:has(.case-details) { grid-template-columns: minmax(0, 1fr) clamp(14rem, 19.8vw, 19rem); }
  .filters { gap: .75rem; padding: 1.4rem .9rem 1.55rem; }
  .filters input, .filters select { min-height: 3rem; font-size: 1rem; }
  .filters input[type="search"] { min-height: 3.25rem; }
  .search-field .icon { top: .95rem; }
  .rows .row { min-height: 6.35rem; gap: .9rem; padding-inline: .9rem; }
  .row .avatar { width: clamp(2.75rem, 4.05vw, 3.95rem); }
  .row .nm { font-size: 1.25rem; }
  .row .pv, .row-meta { font-size: 1rem; }
  .chat-heading, .case-details h2 { min-height: 5.15rem; }
  .chat-heading { gap: .85rem; padding-inline: 1.25rem; }
  .chat-heading .avatar { width: 3.2rem; height: 3.2rem; }
  .chat-heading h2, .case-details h2 { font-size: 1.66rem; }
  .case-details { gap: 1.45rem; padding: 1.35rem; }
  .case-details h2 { margin: -1.35rem -1.35rem 0; padding-inline: 1.35rem; }
  .case-details label { gap: .55rem; font-size: 1.1rem; }
  .case-details label :is(input, select, textarea) { min-height: 3.2rem; font-size: 1rem; }
  .case-details label textarea { min-height: 8.2rem; }
  .case-details .ln button { min-height: 3.3rem; font-size: 1.125rem; font-weight: 700; }
  .msgs { gap: 1.1rem; padding: 2.4rem 1.4rem 1.25rem; }
  .message .avatar { width: 2.9rem; height: 2.9rem; }
  .m { padding: .65rem 1rem; font-size: 1.2rem; }
  .message-meta { font-size: .92rem; }
  .composer { padding: 1rem; }
  .compose-field { padding: .5rem; }
  .composer button { min-height: 3rem; min-width: 5rem; font-weight: 700; }
}

@media (max-width: 1150px) {
  .inbox { height: auto; min-height: 31rem; }
  .chat:has(.case-details) { grid-template-columns: minmax(0, 1fr); }
  .chat-thread { height: clamp(28rem, 65dvh, 38rem); }
  .case-details { border-inline-start: 0; border-top: 1px solid var(--line); }
}
@media (max-width: 760px) {
  .workspace { display: block; }
  .sidebar { position: static; height: auto; padding: .7rem 1rem; }
  .sidebar-head { padding: 0; }
  .nav-toggle { display: block; }
  .sidebar-content { display: none; }
  .sidebar.expanded .sidebar-content { display: flex; margin-top: .85rem; }
  .inbox { grid-template-columns: minmax(0, 1fr); min-height: 23rem; }
  .inbox.in-conversation .list, .inbox:not(.in-conversation) .chat { display: none; }
  .list { border-inline-end: 0; }
  .back-to-inbox { display: inline-block; }
  .grid2 { grid-template-columns: minmax(0, 1fr); }
}

/* โปรไฟล์ร้าน: ปก + โลโก้ */
.shop-cover { position: relative; aspect-ratio: 3 / 1; min-height: 8rem; border-radius: .8rem; overflow: hidden; background: linear-gradient(135deg, var(--selected), var(--them)); border: 1px solid var(--line); display: grid; place-items: center; color: var(--mute); }
.shop-cover img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.shop-head { display: flex; align-items: flex-end; gap: 1rem; margin: -2.2rem 1rem 0; position: relative; flex-wrap: wrap; }
.shop-logo { width: 5.5rem; height: 5.5rem; border-radius: 50%; border: 4px solid var(--bg); background: var(--them); overflow: hidden; display: grid; place-items: center; font-size: 2rem; font-weight: 750; color: var(--brand); flex: 0 0 auto; position: relative; }
.shop-logo img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.img-actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.img-actions input[type=file] { display: none; }
.img-actions .btn { cursor: pointer; border: 1px solid var(--line); background: var(--panel); border-radius: .55rem; padding: .45rem .8rem; }
.img-actions .btn:hover { border-color: var(--brand); }
.hint { font-size: .85rem; color: var(--mute); }
.pill { display: inline-block; font-size: .75rem; padding: .1rem .5rem; border-radius: 99px; background: var(--them); margin-left: .4rem; }
