:root {
  --bg: #f6f3ec; --panel: #ffffff; --text: #22261f; --muted: #6b6f66; --line: #e3ddd0;
  --brand: #1f7a45; --brand-ink: #ffffff; --gold: #b8892b; --me: #1f7a45; --me-ink: #fff;
  --bot: #ffffff; --warn: #b3412e;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #12160f; --panel: #1b2117; --text: #e9ece4; --muted: #9aa292; --line: #2c3527;
    --brand: #2f9e5d; --gold: #d9b25a; --me: #2f9e5d; --bot: #1f261b; --warn: #e07a63;
  }
}
:root[data-theme="dark"] {
  --bg: #12160f; --panel: #1b2117; --text: #e9ece4; --muted: #9aa292; --line: #2c3527;
  --brand: #2f9e5d; --gold: #d9b25a; --me: #2f9e5d; --bot: #1f261b; --warn: #e07a63;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text);
  font: 15px/1.5 -apple-system, "PingFang SC", "Microsoft YaHei", "Noto Sans Thai", sans-serif;
  display: flex; flex-direction: column; max-width: 640px; margin: 0 auto;
}
header {
  background: var(--brand); color: var(--brand-ink); padding: 12px 16px;
  display: flex; align-items: center; gap: 10px;
}
header .logo { font-size: 26px; }
header h1 { font-size: 17px; margin: 0; }
header p { margin: 0; font-size: 12px; opacity: .85; }
#cart {
  padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line);
  font-size: 14px; color: var(--muted);
}
#cart b { color: var(--text); }
#cart .orderno { float: right; color: var(--gold); font-weight: 700; }
#log { flex: 1; overflow-y: auto; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.msg { max-width: 85%; padding: 9px 13px; border-radius: 14px; word-wrap: break-word; }
.msg.me { align-self: flex-end; background: var(--me); color: var(--me-ink); border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-start; background: var(--bot); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.typing span {
  display: inline-block; width: 6px; height: 6px; margin: 0 2px; border-radius: 50%;
  background: var(--muted); animation: blink 1.2s infinite;
}
.msg.typing span:nth-child(2) { animation-delay: .2s; }
.msg.typing span:nth-child(3) { animation-delay: .4s; }
@keyframes blink { 0%, 80%, 100% { opacity: .2; } 40% { opacity: 1; } }
.msg.pending {
  align-self: stretch; max-width: none; background: var(--panel);
  border: 2px solid var(--gold); border-radius: 12px;
}
.msg.pending.done { border-color: var(--brand); opacity: .75; }
.msg.pending.cancelled, .msg.pending:not(.active):not(.done) { opacity: .5; }
.msg.pending:not(.active) .pbtns { display: none; }
.ptitle { font-weight: 700; margin-bottom: 6px; }
.msg table { width: 100%; border-collapse: collapse; font-size: 14px; }
.msg td { padding: 3px 0; border-bottom: 1px dashed var(--line); }
.msg td:last-child { text-align: right; }
.note { font-size: 13px; color: var(--muted); margin-top: 6px; }
.total { text-align: right; font-weight: 700; margin-top: 6px; font-size: 16px; }
.pbtns { display: flex; gap: 8px; margin-top: 10px; }
.pbtns button { flex: 1; padding: 10px; border-radius: 10px; border: 1px solid var(--line); font-size: 15px; cursor: pointer; }
.pbtns .ok { background: var(--brand); color: #fff; border: none; font-weight: 700; }
.pbtns .cancel { background: transparent; color: var(--text); }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 0 16px 8px; }
.chips button {
  flex: none; padding: 6px 12px; border-radius: 16px; border: 1px solid var(--line);
  background: var(--panel); color: var(--text); font-size: 13px; cursor: pointer;
}
#form { display: flex; gap: 8px; padding: 10px 16px 14px; background: var(--panel); border-top: 1px solid var(--line); }
#input {
  flex: 1; padding: 10px 14px; border-radius: 20px; border: 1px solid var(--line);
  background: var(--bg); color: var(--text); font-size: 16px; min-width: 0;
}
#send { padding: 0 18px; border-radius: 20px; border: none; background: var(--brand); color: #fff; font-size: 15px; cursor: pointer; }
#send:disabled { opacity: .5; }

/* ── 老板页：标签 + 记账 ── */
.tabs { display: flex; background: var(--panel); border-bottom: 1px solid var(--line); }
.tabs button {
  flex: 1; padding: 10px; border: none; background: transparent; color: var(--muted);
  font-size: 15px; cursor: pointer; border-bottom: 3px solid transparent;
}
.tabs button.on { color: var(--brand); font-weight: 700; border-bottom-color: var(--brand); }
.view { display: none; flex: 1; min-height: 0; flex-direction: column; position: relative; }
.view.on { display: flex; }
#ledgerView { overflow-y: auto; padding-bottom: 80px; }
.monthbar { display: flex; justify-content: center; align-items: center; gap: 18px; padding: 12px; }
.monthbar button { border: 1px solid var(--line); background: var(--panel); color: var(--text); width: 36px; height: 36px; border-radius: 18px; font-size: 20px; cursor: pointer; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; padding: 0 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px; text-align: center; }
.card span { display: block; font-size: 12px; color: var(--muted); }
.card b { font-size: 18px; }
.inc { color: var(--brand); }
.exp { color: var(--warn); }
.warn { margin: 8px 16px; padding: 8px 12px; border-radius: 8px; background: var(--panel); border: 1px solid var(--warn); color: var(--warn); font-size: 13px; }
.section-title { padding: 16px 16px 6px; font-size: 13px; color: var(--muted); font-weight: 700; }
.bar { padding: 4px 16px; }
.bar-top { display: flex; justify-content: space-between; font-size: 14px; }
.bar-track { height: 8px; border-radius: 4px; background: var(--line); margin-top: 3px; overflow: hidden; }
.bar-fill { height: 100%; background: var(--gold); border-radius: 4px; }
.day { margin: 8px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px 12px; }
.day-head { display: flex; justify-content: space-between; font-size: 13px; color: var(--muted); padding-bottom: 4px; border-bottom: 1px solid var(--line); }
.day-head b { color: var(--text); }
.rec { display: flex; align-items: center; gap: 8px; padding: 6px 0; font-size: 14px; }
.rcat { flex: none; padding: 1px 8px; border-radius: 10px; background: var(--bg); border: 1px solid var(--line); font-size: 12px; }
.rnote { flex: 1; min-width: 0; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ramt { flex: none; font-weight: 700; }
.del { flex: none; border: none; background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; padding: 4px; }
.empty { padding: 20px 16px; text-align: center; color: var(--muted); font-size: 14px; }
.fab {
  position: sticky; bottom: 16px; align-self: center; margin-top: auto; padding: 12px 26px;
  border: none; border-radius: 26px; background: var(--brand); color: #fff; font-size: 16px; font-weight: 700;
  box-shadow: 0 4px 14px rgba(0,0,0,.25); cursor: pointer;
}
.sheet { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: flex-end; justify-content: center; z-index: 10; }
.sheet[hidden] { display: none; }
.sheet-card { width: 100%; max-width: 640px; background: var(--panel); border-radius: 18px 18px 0 0; padding: 16px; display: flex; flex-direction: column; gap: 10px; }
.sheet-card input { padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 16px; }
#recAmount { font-size: 26px; font-weight: 700; }
.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; padding: 9px; border: none; background: transparent; color: var(--text); font-size: 15px; cursor: pointer; }
.seg button.on { background: var(--brand); color: #fff; font-weight: 700; }
.catchips { display: flex; flex-wrap: wrap; gap: 6px; }
.catchips button { padding: 6px 12px; border-radius: 16px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 14px; cursor: pointer; }
.catchips button.on { background: var(--gold); border-color: var(--gold); color: #fff; font-weight: 700; }

/* 月报 */
#reportView { overflow-y: auto; padding-bottom: 24px; }
.msum { margin: 6px 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 4px 12px; }
.msum summary { display: flex; justify-content: space-between; padding: 8px 0; cursor: pointer; list-style: none; }
.msum summary::-webkit-details-marker { display: none; }
.msum p { margin: 0 0 6px; font-size: 14px; }
.mrow { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--muted); padding-bottom: 8px; }
.chartbox { margin: 0 16px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 8px; }
.chartbox svg { width: 100%; height: auto; display: block; }
.chartbox .grid { stroke: var(--line); stroke-width: 1; }
.chartbox .zero { stroke: var(--muted); stroke-width: 1; stroke-dasharray: 4 3; }
.chartbox .ax { fill: var(--muted); font-size: 11px; }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; padding: 4px 8px 2px; font-size: 13px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 5px; margin-right: 5px; }
.seg.metric { margin: 0 16px 8px; }
.dishpick { padding: 0 16px 8px; }
.tablewrap { margin: 10px 16px 0; overflow-x: auto; }
.dtable { width: 100%; border-collapse: collapse; font-size: 13px; background: var(--panel); border: 1px solid var(--line); }
.dtable th, .dtable td { padding: 6px 8px; text-align: right; border-bottom: 1px solid var(--line); white-space: nowrap; }
.dtable th:first-child, .dtable td:first-child { text-align: left; }
.dtable th { color: var(--muted); font-weight: 600; }

/* 点餐标签 */
#shopView { overflow: hidden; }
.shopbar { display: flex; align-items: center; gap: 10px; padding: 8px 16px; background: var(--panel); border-bottom: 1px solid var(--line); }
.shopseg { flex: 1; }
.shopbar a { flex: none; font-size: 13px; color: var(--brand); text-decoration: none; }
#shopFrame { flex: 1; width: 100%; border: 0; background: #fff; min-height: 0; }

/* 远程访问开关 */
header { position: relative; }
.remote { margin-left: auto; display: flex; align-items: center; gap: 6px; font-size: 12px; cursor: pointer; white-space: nowrap; }
.remote input { width: 16px; height: 16px; accent-color: var(--gold); }

/* 顾客页语音 */
.voicebar { display: flex; align-items: center; gap: 8px; padding: 4px 16px 6px; }
.vlangs { display: flex; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; flex: none; }
.vlangs button { padding: 3px 10px; border: none; background: transparent; color: var(--text); font-size: 13px; cursor: pointer; }
.vlangs button.on { background: var(--brand); color: #fff; font-weight: 700; }
.vhint { flex: 1; min-width: 0; font-size: 13px; color: var(--gold); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vhint[hidden] { display: none; }
.vmute { margin-left: auto; flex: none; border: 1px solid var(--line); background: var(--panel); border-radius: 14px; padding: 2px 10px; font-size: 16px; cursor: pointer; }
.mic {
  flex: none; width: 44px; height: 44px; border-radius: 50%; border: none; cursor: pointer;
  background: var(--brand); color: #fff; font-size: 20px; touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
.mic[hidden] { display: none; }
.mic.rec { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 rgba(179, 65, 46, .5); } 50% { box-shadow: 0 0 0 10px rgba(179, 65, 46, 0); } }
.miclabel { text-align: center; font-size: 12px; color: var(--muted); padding: 0 16px 10px; background: var(--panel); }
.miclabel:empty { display: none; }

/* 顾客页：返回菜单（仅公网 /agent/ 路径显示） */
.backlink { margin-left: auto; flex: none; color: var(--brand-ink); font-size: 13px; text-decoration: none; border: 1px solid rgba(255,255,255,.55); border-radius: 14px; padding: 4px 10px; white-space: nowrap; }
.backlink[hidden] { display: none; }

/* 每条 AI 回复末尾的手动朗读按钮 */
.speakbtn { margin-left: 8px; border: none; background: transparent; font-size: 15px; cursor: pointer; opacity: .65; padding: 0 2px; vertical-align: baseline; }
.speakbtn:active { opacity: 1; }

/* 语音提示（要客人去改设置的长说明），放在聊天区里 */
.msg.sys { align-self: stretch; max-width: none; border: 1px dashed var(--warn); border-radius: 12px; font-size: 14px; background: transparent; color: var(--text); }

.copybtn { margin-top: 8px; padding: 7px 16px; border-radius: 16px; border: 1px solid var(--brand); background: transparent; color: var(--brand); font-size: 14px; font-weight: 700; cursor: pointer; }
.copybtn:active { background: var(--brand); color: #fff; }

/* 朗读开关：显示文字；静音时变成醒目的警示色 */
.vmute { font-size: 13px; font-weight: 700; white-space: nowrap; }
.vmute.off { border-color: var(--warn); color: var(--warn); }

/* 回复里的链接（如地图） */
.msg a { color: var(--brand); font-weight: 700; text-decoration: underline; }

/* 麦克风用不了时：灰色 + 斜杠，点一下看原因（不再凭空消失） */
.mic { position: relative; }
.mic.disabled { background: var(--line); color: var(--muted); }
.mic.disabled span { opacity: .55; }
.mic.disabled::after { content: ''; position: absolute; left: 9px; right: 9px; top: 50%; height: 3px; border-radius: 2px; background: var(--warn); transform: rotate(-45deg); }
.miclabel.micoff { color: var(--warn); }
.msg.sys.flash { animation: sysflash 1.2s ease-out 1; }
@keyframes sysflash { 0%, 60% { background: rgba(179, 65, 46, .22); } 100% { background: transparent; } }

/* 早报（餐厅大脑） */
#brainView { overflow-y: auto; padding-bottom: 24px; }
.brainbar { display: flex; align-items: center; gap: 10px; padding: 10px 16px 0; font-size: 12px; color: var(--muted); }
.brainbar .graphlink { margin-left: auto; padding: 6px 12px; border-radius: 16px; background: #0f1211; color: #f2b33d; font-size: 13px; font-weight: 700; text-decoration: none; white-space: nowrap; }
.brainbar button { padding: 6px 12px; border-radius: 16px; border: 1px solid var(--brand); background: transparent; color: var(--brand); font-size: 13px; font-weight: 700; cursor: pointer; }
.brainbar button:disabled { opacity: .6; cursor: default; }
.brief { margin: 8px 16px 0; padding: 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; white-space: pre-wrap; word-break: break-word; font: inherit; font-size: 14px; }
.section-title small { display: block; font-weight: 400; margin-top: 2px; }
.sg { margin: 8px 16px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-left: 4px solid var(--gold); border-radius: 12px; display: flex; flex-direction: column; gap: 6px; }
.sg.done { border-left-color: var(--line); }
.sg-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.tag { flex: none; font-size: 12px; color: var(--muted); }
.sg-q { font-size: 14px; }
.sg-ex { margin: 0; padding-left: 18px; font-size: 13px; color: var(--muted); }
.sg textarea { padding: 8px 10px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font: inherit; font-size: 15px; resize: vertical; }
.sg-rm { display: flex; align-items: center; gap: 6px; font-size: 13px; }
.sg .warn { margin: 0; }
.sg .pbtns { margin-top: 0; }
.ans { font-size: 13px; color: var(--muted); }
