:root {
  --c: #0f766e;
  --bg: #f3f4f6;
  --line: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 15px; line-height: 1.4; color: var(--text); background: var(--bg);
}
[hidden] { display: none !important; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--c); }
code { background: #e5e7eb; padding: 1px 5px; border-radius: 4px; }

.center { min-height: 100%; display: flex; align-items: center; justify-content: center; padding: 16px; color: var(--muted); }
.card { background: #fff; border: 1px solid var(--line); border-radius: 12px; padding: 20px; display: flex; flex-direction: column; gap: 10px; }
#login-form { width: 100%; max-width: 340px; color: var(--text); }
#login-form h1 { margin: 0 0 6px; font-size: 22px; color: var(--c); }
input, select, textarea { border: 1px solid #d1d5db; border-radius: 8px; padding: 9px 11px; background: #fff; width: 100%; font-size: 16px; }
input[type=checkbox] { width: auto; }
input[type=color] { padding: 2px; height: 40px; width: 70px; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--c); outline-offset: 0; border-color: var(--c); }
.primary { background: var(--c); color: #fff; border: 0; border-radius: 8px; padding: 10px 16px; font-weight: 600; }
.primary:disabled { opacity: .55; }
.ghost { background: transparent; border: 1px solid #d1d5db; border-radius: 8px; padding: 6px 12px; }
.ghost:hover { background: #f3f4f6; }
.error { color: #b91c1c; font-size: 13px; min-height: 18px; }
.badge { display: inline-flex; align-items: center; justify-content: center; min-width: 20px; height: 20px; padding: 0 6px; border-radius: 10px; background: #dc2626; color: #fff; font-size: 12px; font-weight: 700; }

#app { height: 100%; display: flex; flex-direction: column; }
.top { display: flex; align-items: center; gap: 10px; padding: 8px 12px; padding-top: calc(8px + env(safe-area-inset-top)); background: #fff; border-bottom: 1px solid var(--line); flex: none; }
.brand { color: var(--c); font-size: 17px; white-space: nowrap; }
.top nav { display: flex; gap: 4px; }
.nav-btn { background: transparent; border: 0; border-radius: 8px; padding: 7px 11px; font-weight: 600; color: var(--muted); display: inline-flex; gap: 6px; align-items: center; }
.nav-btn.active { background: #ecfdf5; color: var(--c); }
.spacer { flex: 1; }
.conn { color: #9ca3af; font-size: 12px; }
.conn.on { color: #16a34a; }
.conn.off { color: #dc2626; }

.inbox { flex: 1; display: flex; min-height: 0; }
.list-pane { width: 340px; flex: none; background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.filters { padding: 10px; display: flex; flex-direction: column; gap: 8px; border-bottom: 1px solid var(--line); }
.tabs { display: flex; background: var(--bg); border-radius: 8px; padding: 3px; }
.tab { flex: 1; border: 0; background: transparent; border-radius: 6px; padding: 6px 4px; font-size: 14px; color: var(--muted); }
.tab.active { background: #fff; color: var(--text); font-weight: 600; box-shadow: 0 1px 2px rgba(0,0,0,.1); }
.conv-list { list-style: none; margin: 0; padding: 0; overflow-y: auto; flex: 1; }
.conv { display: block; width: 100%; text-align: left; background: #fff; border: 0; border-bottom: 1px solid var(--line); padding: 10px 12px; }
.conv:hover { background: #f9fafb; }
.conv.active { background: #ecfdf5; }
.conv-top { display: flex; align-items: center; gap: 6px; }
.conv-name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.conv.unread .conv-name { font-weight: 800; }
.conv-time { font-size: 12px; color: var(--muted); flex: none; }
.conv-preview { color: var(--muted); font-size: 13.5px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.conv.unread .conv-preview { color: var(--text); }
.conv-bottom { display: flex; align-items: center; gap: 6px; margin-top: 4px; }
.store-tag { display: inline-block; font-size: 11.5px; font-weight: 600; color: #fff; background: var(--muted); border-radius: 5px; padding: 1px 7px; }
.status-tag { font-size: 11.5px; color: var(--muted); border: 1px solid var(--line); border-radius: 5px; padding: 0 6px; }
.empty { color: var(--muted); text-align: center; padding: 24px 12px; }
.empty.big { flex: 1; display: flex; align-items: center; justify-content: center; }

.chat-pane { flex: 1; display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.chat { flex: 1; display: flex; flex-direction: column; min-height: 0; }
.chat-head { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: #fff; border-bottom: 1px solid var(--line); }
.back { display: none; }
.who { flex: 1; min-width: 0; }
.c-name { font-weight: 700; }
.who-sub { font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.context { background: #fff; border-bottom: 1px solid var(--line); padding: 6px 12px; font-size: 13px; }
.context summary { cursor: pointer; color: var(--muted); }
.context dl { display: grid; grid-template-columns: max-content 1fr; gap: 2px 12px; margin: 8px 0 4px; max-height: 180px; overflow-y: auto; }
.context dt { color: var(--muted); }
.context dd { margin: 0; overflow-wrap: anywhere; }
.msgs { flex: 1; overflow-y: auto; padding: 14px 12px; display: flex; flex-direction: column; gap: 8px; }
.msg { max-width: 76%; padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.customer { align-self: flex-start; background: #fff; border: 1px solid var(--line); border-bottom-left-radius: 4px; }
.msg.agent { align-self: flex-end; background: var(--c); color: #fff; border-bottom-right-radius: 4px; }
.msg.bot { align-self: flex-end; background: #4f46e5; color: #fff; border-bottom-right-radius: 4px; }
.msg-meta { font-size: 11px; opacity: .75; margin-top: 3px; }
.reply { display: flex; gap: 8px; padding: 10px 12px; padding-bottom: calc(10px + env(safe-area-inset-bottom)); background: #fff; border-top: 1px solid var(--line); align-items: flex-end; }
.reply textarea { resize: none; }
#reply-error { padding: 0 12px; background: #fff; }
#reply-error:empty { display: none; }

.stores { flex: 1; overflow-y: auto; padding: 16px; max-width: 900px; width: 100%; margin: 0 auto; }
.stores h2 { margin: 0 0 12px; }
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--line); border-radius: 12px; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: 9px 12px; border-bottom: 1px solid var(--line); font-size: 14px; }
tr:last-child td { border-bottom: 0; }
.swatch { display: inline-block; width: 18px; height: 18px; border-radius: 5px; vertical-align: middle; border: 1px solid rgba(0,0,0,.15); }
.store-form { max-width: 520px; }
.store-form label { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; }
.store-form label.check { flex-direction: row; align-items: center; gap: 8px; }
.row { display: flex; gap: 8px; }
.hint { color: var(--muted); font-size: 14px; }
.code { background: #111827; color: #e5e7eb; padding: 12px; border-radius: 10px; overflow-x: auto; font-size: 13px; white-space: pre-wrap; word-break: break-all; }

@media (max-width: 760px) {
  .list-pane { width: 100%; border-right: 0; }
  .chat-pane { display: none; }
  .inbox.show-chat .list-pane { display: none; }
  .inbox.show-chat .chat-pane { display: flex; }
  .back { display: inline-block; }
  .brand { display: none; }
  .msg { max-width: 88%; }
  .top { gap: 6px; padding-left: 8px; padding-right: 8px; }
  .top button { white-space: nowrap; font-size: 14px; }
  .nav-btn { padding: 7px 8px; }
  .lbl { display: none; }
  #logout { padding: 6px 8px; }
}
