:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --text: var(--tg-theme-text-color, #14171a);
  --hint: var(--tg-theme-hint-color, #7d858f);
  --link: var(--tg-theme-link-color, #2481cc);
  --btn: var(--tg-theme-button-color, #2481cc);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --sec: var(--tg-theme-secondary-bg-color, #f2f3f5);
  --line: color-mix(in srgb, var(--hint) 22%, transparent);
  --mine: color-mix(in srgb, var(--btn) 16%, var(--bg));
  --theirs: var(--sec);
  --green: #34a853; --red: #e5484d; --amber: #e0a020;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
#app { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; }
.center { margin: auto; text-align: center; padding: 24px; color: var(--hint); }
.spinner { width: 28px; height: 28px; margin: auto; border-radius: 50%;
  border: 3px solid var(--line); border-top-color: var(--btn); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* header */
.top { display: flex; align-items: center; gap: 10px; padding: 10px 14px; border-bottom: 1px solid var(--line); min-height: 52px; }
.top .back { font-size: 22px; line-height: 1; padding: 4px 8px 4px 0; color: var(--link); }
.top .title { font-weight: 600; font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.top .sub { font-size: 12.5px; color: var(--hint); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.top .grow { flex: 1; min-width: 0; }

/* badges */
.badge { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 20px; }
.badge.new { background: color-mix(in srgb, var(--btn) 18%, transparent); color: var(--link); }
.badge.wait { background: color-mix(in srgb, var(--red) 16%, transparent); color: var(--red); }
.badge.work { background: color-mix(in srgb, var(--amber) 20%, transparent); color: #b27a00; }
.badge.closed { background: color-mix(in srgb, var(--green) 18%, transparent); color: var(--green); }

/* chips */
.chips { display: flex; gap: 8px; padding: 10px 14px 4px; overflow-x: auto; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chip { flex: none; padding: 7px 13px; border-radius: 20px; background: var(--sec); font-size: 14px; white-space: nowrap; }
.chip b { margin-left: 5px; font-weight: 600; opacity: .75; }
.chip.on { background: var(--btn); color: var(--btn-text); }
.chip.hot:not(.on) b { color: var(--red); opacity: 1; }
.search { margin: 8px 14px 6px; }
.search input { width: 100%; padding: 10px 14px; border: 0; border-radius: 12px; background: var(--sec); color: var(--text); font: inherit; outline: none; }

/* list */
.scroll { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.item { display: flex; gap: 12px; padding: 12px 14px; width: 100%; text-align: left; border-bottom: 1px solid var(--line); }
.item:active { background: var(--sec); }
.avatar { flex: none; width: 44px; height: 44px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 600; font-size: 17px; color: #fff; }
.item .body { flex: 1; min-width: 0; }
.item .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.item .name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.item .name small { color: var(--hint); font-weight: 400; }
.item .time { font-size: 12px; color: var(--hint); flex: none; }
.item .prev { color: var(--hint); font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 1px; }
.item .meta { margin-top: 5px; display: flex; gap: 6px; align-items: center; font-size: 12px; color: var(--hint); }
.empty { padding: 48px 24px; text-align: center; color: var(--hint); }
.empty .big { font-size: 40px; margin-bottom: 8px; }
.more { display: block; margin: 14px auto; padding: 9px 20px; border-radius: 12px; background: var(--sec); }

/* chat */
.actions { display: flex; gap: 8px; padding: 8px 14px; border-bottom: 1px solid var(--line); }
.actions:empty { display: none; }
.btn { padding: 9px 16px; border-radius: 12px; background: var(--btn); color: var(--btn-text); font-weight: 600; font-size: 14px; }
.btn.ghost { background: var(--sec); color: var(--text); }
.btn.ok { background: var(--green); color: #fff; }
.btn:disabled { opacity: .5; }
.msgs { flex: 1; overflow-y: auto; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; -webkit-overflow-scrolling: touch; }
.day { align-self: center; margin: 10px 0 6px; font-size: 12px; color: var(--hint); background: var(--sec); padding: 3px 11px; border-radius: 20px; }
.bubble { max-width: 82%; padding: 7px 11px 6px; border-radius: 16px; background: var(--theirs); word-break: break-word; white-space: pre-wrap; }
.bubble.mine { align-self: flex-end; background: var(--mine); border-bottom-right-radius: 5px; }
.bubble.theirs { align-self: flex-start; border-bottom-left-radius: 5px; }
.bubble .who { font-size: 12.5px; font-weight: 600; color: var(--link); margin-bottom: 1px; }
.bubble .t { display: block; text-align: right; font-size: 11px; color: var(--hint); margin-top: 2px; }
.bubble.media { font-style: italic; }
.composer { display: flex; gap: 8px; align-items: flex-end; padding: 8px 10px calc(8px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--bg); }
.composer textarea { flex: 1; resize: none; max-height: 130px; border: 0; border-radius: 18px; background: var(--sec); color: var(--text);
  padding: 10px 14px; font: inherit; outline: none; }
.composer .send { flex: none; width: 42px; height: 42px; border-radius: 50%; background: var(--btn); color: var(--btn-text); font-size: 18px; }
.composer .send:disabled { opacity: .45; }
.closedbar { padding: 12px 14px calc(12px + var(--safe-b)); border-top: 1px solid var(--line); text-align: center; color: var(--hint); }
.closedbar .btn { margin-top: 8px; }

/* customer home */
.card { margin: 14px; padding: 16px; border-radius: 16px; background: var(--sec); }
.card h2 { margin: 0 0 4px; font-size: 18px; }
.card p { margin: 0 0 12px; color: var(--hint); }
.card textarea { width: 100%; min-height: 110px; resize: vertical; border: 0; border-radius: 12px; padding: 12px; font: inherit;
  background: var(--bg); color: var(--text); outline: none; margin-bottom: 10px; }
.card .btn { width: 100%; padding: 12px; }
.section { padding: 8px 14px 2px; color: var(--hint); font-size: 13px; text-transform: uppercase; letter-spacing: .04em; }

.toast { position: fixed; left: 50%; bottom: calc(76px + var(--safe-b)); transform: translateX(-50%); max-width: 88%;
  background: #222; color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 14px; z-index: 10; text-align: center; }
