:root {
  --bg: #F1F1F1;
  --ink: #111;
  --muted: #6b6b6b;
  --line: #ddd;
  --card: #fff;
  --accent: #111;
  --bubble-me: #111;
  --bubble-me-text: #F1F1F1;
  --bubble-them: #fff;
  --warn: #b3261e;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg); color: var(--ink);
  -webkit-font-smoothing: antialiased;
}
.hidden { display: none !important; }
button { font: inherit; cursor: pointer; }
input, textarea, select { font: inherit; }
label { display: block; font-size: 13px; color: var(--muted); margin: 10px 0; }
label input, label textarea { display: block; width: 100%; margin-top: 4px; padding: 10px; border: 1px solid var(--line); border-radius: 8px; background: #fff; color: var(--ink); }
.error { color: var(--warn); font-size: 13px; min-height: 16px; }
.hint { font-size: 12.5px; color: var(--muted); }

.btn { border: 1px solid var(--ink); background: #fff; color: var(--ink); border-radius: 999px; padding: 8px 16px; }
.btn.primary { background: var(--accent); color: var(--bubble-me-text); }
.btn.small { padding: 5px 12px; font-size: 13px; }
.btn.full { width: 100%; padding: 12px; }
.iconBtn { background: none; border: none; font-size: 22px; line-height: 1; padding: 6px 10px; color: var(--ink); }

/* ---------- brand ---------- */
.brandMark {
  width: 54px; height: 54px; border-radius: 12px; background: #111; color: #F1F1F1;
  display: flex; align-items: center; justify-content: center; font-weight: 800; letter-spacing: 1px; margin: 0 auto;
}
.brandMark.small { width: 26px; height: 26px; border-radius: 6px; font-size: 11px; margin: 0; }
.wordmark { letter-spacing: 4px; font-weight: 800; text-align: center; margin: 12px 0 2px; }
.wordmark.small { font-size: 14px; letter-spacing: 2px; margin: 0; text-align: left; }
.slogan { text-align: center; font-size: 11px; letter-spacing: 2.5px; color: var(--muted); margin: 0 0 14px; }

/* ---------- login ---------- */
.centerView { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.loginCard { width: 100%; max-width: 360px; background: var(--card); border: 1px solid var(--line); border-radius: 16px; padding: 28px 24px; }
.loginCard h2 { text-align: center; }
.demoBox { margin-top: 18px; font-size: 13px; }
.demoBox summary { cursor: pointer; color: var(--muted); }
.demoAcct { display: block; width: 100%; text-align: left; background: var(--bg); border: 1px solid var(--line); border-radius: 8px; padding: 8px 10px; margin: 6px 0; }
.demoAcct b { display: block; font-size: 13.5px; }
.demoAcct span { font-size: 12px; color: var(--muted); }

/* ---------- app frame ---------- */
#appView { display: flex; flex-direction: column; height: 100dvh; }
#appHeader {
  position: relative; display: flex; align-items: center; justify-content: space-between;
  padding: 8px 10px; border-bottom: 1px solid var(--line); background: var(--bg); flex: 0 0 auto;
}
.headerBrand { display: flex; align-items: center; gap: 8px; }
.headerUser { display: flex; align-items: center; gap: 4px; font-size: 13px; color: var(--muted); }
.badge { background: var(--warn); color: #fff; border-radius: 999px; font-size: 11px; padding: 1px 7px; font-weight: 700; }
#mainSplit { flex: 1; display: flex; min-height: 0; }

/* thread list */
#threadPane { width: 340px; border-right: 1px solid var(--line); display: flex; flex-direction: column; background: var(--bg); }
.searchRow { padding: 10px; }
.searchRow input { width: 100%; padding: 9px 12px; border: 1px solid var(--line); border-radius: 999px; background: #fff; }
#threadList { overflow-y: auto; flex: 1; }
.threadRow { display: flex; gap: 10px; padding: 11px 12px; border-bottom: 1px solid var(--line); cursor: pointer; align-items: center; }
.threadRow.active { background: #e7e7e7; }
.threadRow .avatar { width: 38px; height: 38px; border-radius: 50%; background: #111; color: #F1F1F1; display: flex; align-items: center; justify-content: center; font-size: 12px; font-weight: 700; flex: 0 0 auto; }
.threadRow .meta { flex: 1; min-width: 0; }
.threadRow .name { font-weight: 600; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.threadRow .preview { font-size: 12.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.threadRow .side { text-align: right; flex: 0 0 auto; }
.threadRow .time { font-size: 11px; color: var(--muted); }

/* chat */
#chatPane { flex: 1; display: flex; flex-direction: column; min-width: 0; background: var(--bg); }
.chatEmpty { margin: auto; color: var(--muted); font-size: 14px; padding: 20px; text-align: center; }
#chatMain { display: flex; flex-direction: column; flex: 1; min-height: 0; }
#chatHead { display: flex; align-items: center; justify-content: space-between; padding: 10px 14px; border-bottom: 1px solid var(--line); }
#chatTitle { font-weight: 700; font-size: 15px; }
.chatSub { font-size: 12px; color: var(--muted); }
.reassignBar, .feedbackBar { display: flex; align-items: center; gap: 8px; padding: 8px 14px; background: #fff; border-bottom: 1px solid var(--line); font-size: 13px; flex-wrap: wrap; }
.reassignBar select { padding: 6px; border: 1px solid var(--line); border-radius: 8px; }
#messages { flex: 1; overflow-y: auto; padding: 14px; display: flex; flex-direction: column; gap: 8px; }
.msgRow { display: flex; flex-direction: column; max-width: 82%; }
.msgRow.me { align-self: flex-end; align-items: flex-end; }
.msgRow.them { align-self: flex-start; align-items: flex-start; }
.msgRow.system { align-self: center; max-width: 92%; align-items: center; }
.msgSender { font-size: 11px; color: var(--muted); margin: 0 2px 2px; }
.bubble { padding: 9px 12px; border-radius: 14px; font-size: 14.5px; line-height: 1.4; white-space: pre-wrap; word-break: break-word; }
.msgRow.me .bubble { background: var(--bubble-me); color: var(--bubble-me-text); border-bottom-right-radius: 4px; }
.msgRow.them .bubble { background: var(--bubble-them); border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.systemBubble { background: #e7e7e7; color: #444; font-size: 12px; padding: 6px 10px; border-radius: 999px; text-align: center; }
.msgMeta { font-size: 10.5px; color: var(--muted); margin: 2px 2px 0; }
.editedTag { font-style: italic; }
.cardBox { background: #fff; border: 1px solid var(--line); border-left: 4px solid #111; border-radius: 10px; padding: 10px 12px; min-width: 210px; }
.cardBox .cardKind { font-size: 11px; letter-spacing: 1px; color: var(--muted); text-transform: uppercase; }
.cardBox .cardTitle { font-weight: 700; margin: 2px 0; }
.cardBox .cardDetail { font-size: 13px; color: #333; white-space: pre-wrap; }
.apptBtns, .invBtns { display: flex; gap: 8px; margin-top: 8px; flex-wrap: wrap; }
.statusPill { font-size: 11px; font-weight: 700; padding: 2px 8px; border-radius: 999px; background: #e7e7e7; }
.statusPill.ok { background: #111; color: #F1F1F1; }
.statusPill.warn { background: #f3d9d7; color: var(--warn); }
.invoiceBox { background: #fff; border: 1.5px solid #111; border-radius: 10px; padding: 14px; min-width: 250px; max-width: 340px; font-size: 13px; }
.invoiceBox h4 { margin: 0 0 2px; letter-spacing: 2px; }
.invoiceBox table { width: 100%; border-collapse: collapse; margin: 8px 0; }
.invoiceBox td, .invoiceBox th { padding: 3px 0; border-bottom: 1px solid var(--line); text-align: left; font-size: 12.5px; }
.invoiceBox td.n, .invoiceBox th.n { text-align: right; }
.invoiceBox .totalRow td { font-weight: 800; border-bottom: none; }
.invoiceBox .payBlock { background: var(--bg); border-radius: 8px; padding: 8px; font-size: 12px; margin-top: 8px; }

/* composer */
#composer { position: relative; display: flex; gap: 8px; padding: 10px; border-top: 1px solid var(--line); background: var(--bg); align-items: center; }
#composerInput { flex: 1; padding: 11px 14px; border: 1px solid var(--line); border-radius: 999px; background: #fff; min-width: 0; }
#plusBtn { font-size: 26px; border: 1px solid var(--line); border-radius: 50%; width: 40px; height: 40px; background: #fff; flex: 0 0 auto; }

/* dropdowns & overlays */
.dropdown { position: absolute; right: 8px; top: calc(100% + 4px); background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 8px 28px rgba(0,0,0,.14); min-width: 220px; z-index: 50; padding: 6px; }
.dropdown.up { top: auto; bottom: calc(100% + 6px); right: auto; left: 8px; }
.dropdownItem { display: block; width: 100%; text-align: left; background: none; border: none; padding: 9px 10px; border-radius: 8px; font-size: 14px; }
.dropdownItem:hover { background: var(--bg); }
.dropdownHead { font-size: 11px; letter-spacing: 1px; color: var(--muted); text-transform: uppercase; padding: 8px 10px 2px; }
.overlay { position: fixed; inset: 0; background: rgba(0,0,0,.4); display: flex; align-items: flex-end; justify-content: center; z-index: 100; }
.sheet { background: var(--bg); width: 100%; max-width: 520px; max-height: 88dvh; overflow-y: auto; border-radius: 16px 16px 0 0; padding: 18px; }
.sheet.wide { max-width: 640px; }
.sheetHead { display: flex; align-items: center; justify-content: space-between; }
.sheetHead h2 { margin: 0; font-size: 17px; }
.acctRow { display: flex; align-items: center; gap: 10px; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; margin: 8px 0; }
.acctRow .meta { flex: 1; min-width: 0; }
.acctRow .meta b { display: block; font-size: 14px; }
.acctRow .meta span { font-size: 12px; color: var(--muted); }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 12px; }
.invItemRow { display: grid; grid-template-columns: 2fr .7fr .7fr .8fr auto; gap: 6px; margin: 6px 0; }
.invItemRow input { padding: 8px; border: 1px solid var(--line); border-radius: 8px; width: 100%; }
.invTotal { font-weight: 800; font-size: 15px; }
.ratingRow { display: flex; gap: 8px; margin: 10px 0; }
.ratingRow button { flex: 1; padding: 12px 0; border: 1px solid var(--ink); background: #fff; border-radius: 10px; font-weight: 700; }
.ratingRow button.sel { background: #111; color: #F1F1F1; }

/* ---------- mobile ---------- */
@media (max-width: 760px) {
  #threadPane { width: 100%; border-right: none; }
  #chatPane.hiddenMobile { display: none; }
  #threadPane.hiddenMobile { display: none; }
  #meLabel { display: none; }
  .sheet { border-radius: 16px 16px 0 0; }
  .invItemRow { grid-template-columns: 1fr 1fr; }
}
@media (min-width: 761px) {
  .overlay { align-items: center; }
  .sheet { border-radius: 16px; }
  #backBtn { display: none !important; }
}
