:root {
  --c: #e11d48;
  --c-dark: #be123c;
  --c-soft: #fff1f2;
  --c-softer: #fff7f8;
  --c-ring: rgba(225, 29, 72, .15);
  --c-glow: rgba(225, 29, 72, .18);
  --bg: #f4f6f9;
  --card: #fff;
  --line: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --ok: #16a34a;
  --warn: #d97706;
  --radius: 12px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; }
body { font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--c-dark); }
h1 { font-size: 22px; margin: 0 0 16px; }
h2 { font-size: 17px; margin: 18px 0 8px; }
h3 { font-size: 16px; margin: 8px 0; }
h4 { font-size: 13px; margin: 18px 0 6px; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
code, pre { font-family: Consolas, Menlo, monospace; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.inline { display: inline; margin: 0; }

/* Buttons & forms */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; background: var(--c); color: #fff; border: 0; border-radius: 9px; padding: 9px 16px; font-size: 14px; font-weight: 600; cursor: pointer; text-decoration: none; white-space: nowrap; }
.btn:hover { background: var(--c-dark); }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--line); }
.btn.ghost:hover { background: #f3f4f6; }
.btn.danger, .btn.ghost.danger { color: #dc2626; }
.btn.small { padding: 5px 10px; font-size: 13px; }
input, select, textarea { font: inherit; color: inherit; }
label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; }
label input, label select, label textarea, .field { font-weight: 400; font-size: 14px; border: 1px solid #d1d5db; border-radius: 9px; padding: 9px 11px; background: #fff; width: 100%; }
label input:focus, label select:focus, label textarea:focus { outline: 0; border-color: var(--c); box-shadow: 0 0 0 3px var(--c-ring); }
label.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
label.check input { width: auto; }
.form-grid { display: flex; flex-direction: column; gap: 12px; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.alert { background: #fef2f2; color: #b91c1c; border: 1px solid #fecaca; padding: 10px 14px; border-radius: 9px; margin-bottom: 14px; }
.alert.ok { background: #f0fdf4; color: #166534; border-color: #bbf7d0; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; margin-bottom: 16px; }
.card.ok h2 { color: var(--ok); }
.code { background: #0f172a; color: #e2e8f0; padding: 12px 14px; border-radius: 9px; overflow-x: auto; white-space: pre-wrap; word-break: break-all; font-size: 13px; }
.pill { display: inline-block; background: var(--c); color: #fff; border-radius: 10px; font-size: 11px; font-weight: 700; padding: 0 7px; line-height: 18px; }
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--line); margin-bottom: 16px; flex-wrap: wrap; }
.tabs a { padding: 9px 16px; color: var(--muted); text-decoration: none; font-weight: 600; font-size: 14px; border-bottom: 2px solid transparent; border-radius: 8px 8px 0 0; }
.tabs a:hover { background: #f3f4f6; color: var(--text); }
.tabs a.active { color: var(--c-dark); border-color: var(--c); background: var(--c-softer); }
.lang-pills { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.pill-link { display: inline-block; padding: 6px 14px; border-radius: 999px; border: 1px solid var(--line); background: #fff; color: var(--text); text-decoration: none; font-size: 13px; font-weight: 600; }
.pill-link:hover { border-color: var(--c); }
.pill-link.active { background: var(--c); border-color: var(--c); color: #fff; }
.inline-add { display: flex; gap: 8px; align-items: center; margin-bottom: 6px; }

/* Install / login */
.install { max-width: 720px; margin: 30px auto; padding: 0 16px; }
.login-page { display: flex; align-items: center; justify-content: center; min-height: 100vh; padding: 16px; }
.login.card { width: 100%; max-width: 360px; display: flex; flex-direction: column; gap: 14px; }
.brand { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; font-size: 17px; color: var(--text); text-decoration: none; }
.brand.big { font-size: 22px; justify-content: center; margin-bottom: 6px; }
.brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); box-shadow: 0 0 0 4px var(--c-glow); }
.brand-logo { display: block; max-height: 32px; max-width: 180px; object-fit: contain; }
.brand.big .brand-logo { max-height: 56px; max-width: 240px; margin: 0 auto; }

/* Top bar */
.topbar { position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 18px; height: 56px; padding: 0 16px; background: #fff; border-bottom: 1px solid var(--line); }
.nav { display: flex; gap: 2px; flex: 1; overflow-x: auto; }
.nav a { padding: 7px 12px; border-radius: 8px; color: var(--muted); text-decoration: none; font-weight: 600; white-space: nowrap; }
.nav a:hover { background: #f3f4f6; color: var(--text); }
.nav a.active { background: var(--c-soft); color: var(--c-dark); }
.top-right { display: flex; align-items: center; gap: 6px; }
.icon-btn { background: none; border: 0; font-size: 18px; width: 36px; height: 36px; border-radius: 8px; cursor: pointer; }
.icon-btn:hover { background: #f3f4f6; }
.status-select { border: 1px solid var(--line); border-radius: 20px; padding: 6px 12px; font-weight: 600; background: #fff; cursor: pointer; }
.status-select.s-online { color: var(--ok); border-color: #bbf7d0; background: #f0fdf4; }
.status-select.s-away { color: var(--warn); border-color: #fde68a; background: #fffbeb; }
.status-select.s-offline { color: var(--muted); }
.nav-toggle { display: none; background: none; border: 0; font-size: 22px; cursor: pointer; }

/* Pages */
.wrap { max-width: 1100px; margin: 24px auto; padding: 0 16px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 14px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
table.list { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
table.list th, table.list td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list th { background: #f9fafb; font-size: 12px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
table.list tr.is-unread td { background: var(--c-softer); font-weight: 600; }
.actions { display: flex; gap: 6px; flex-wrap: wrap; }
.filters { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; margin-bottom: 14px; }
.filters label { min-width: 150px; }
.pager { display: flex; gap: 6px; margin-top: 14px; }
.transcript { display: flex; flex-direction: column; gap: 6px; }
.transcript .t-line { padding: 8px 12px; border-radius: 9px; background: #f9fafb; white-space: pre-wrap; word-wrap: break-word; }
.transcript .t-line.operator { background: var(--c-soft); }
.transcript .t-line.system { background: none; color: var(--muted); font-size: 12px; text-align: center; }
.transcript .t-who { font-weight: 700; font-size: 12px; color: var(--muted); }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 4px; vertical-align: middle; margin-right: 6px; }
.status-dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; background: #cbd5e1; margin-right: 6px; }
.status-dot.online { background: var(--ok); }
.status-dot.away { background: var(--warn); }
.tablewrap { overflow-x: auto; }

/* Toast */
.toast { position: fixed; bottom: 20px; right: 20px; z-index: 50; background: #111827; color: #fff; padding: 12px 18px; border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,.25); cursor: pointer; max-width: 360px; }

/* ----------------------------------------------------------------- */
/* Chat app                                                           */
/* ----------------------------------------------------------------- */
.app-page { height: 100vh; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }
.app { flex: 1; display: grid; grid-template-columns: 320px 1fr 290px; min-height: 0; }
.convs { background: #fff; border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.convs-head { padding: 14px 16px 8px; font-weight: 800; font-size: 15px; }
.conv-list { flex: 1; overflow-y: auto; padding: 0 8px 8px; }
.group { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; padding: 12px 8px 4px; }
.conv { display: flex; gap: 10px; align-items: center; width: 100%; text-align: left; background: none; border: 0; padding: 9px 8px; border-radius: 10px; cursor: pointer; color: inherit; font: inherit; }
.conv:hover { background: #f6f7f9; }
.conv.sel { background: var(--c-soft); }
.conv.waiting { box-shadow: inset 3px 0 0 var(--c); }
.conv.closed { opacity: .6; }
.av { position: relative; width: 38px; height: 38px; flex: none; border-radius: 50%; color: #fff; font-weight: 700; font-size: 13px; display: flex; align-items: center; justify-content: center; }
.presence { position: absolute; right: -1px; bottom: -1px; width: 11px; height: 11px; border-radius: 50%; background: #cbd5e1; border: 2px solid #fff; }
.presence.on { background: var(--ok); }
.c-main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.c-top { display: flex; justify-content: space-between; gap: 6px; }
.c-top b { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-time { font-size: 11px; color: var(--muted); flex: none; }
.c-site { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-last { font-size: 12.5px; color: #374151; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.c-last.typing { color: var(--ok); font-style: italic; }
.unread { background: var(--c); color: #fff; border-radius: 10px; min-width: 20px; height: 20px; padding: 0 6px; font-size: 11px; font-weight: 700; display: flex; align-items: center; justify-content: center; flex: none; }
.ops-online { border-top: 1px solid var(--line); padding: 10px 16px 12px; }
.ops-title { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; margin-bottom: 4px; }
.op-line { display: flex; align-items: center; gap: 7px; font-size: 13px; }
.st { width: 8px; height: 8px; border-radius: 50%; background: #cbd5e1; }
.st.s-online { background: var(--ok); }
.st.s-away { background: var(--warn); }
.empty { color: var(--muted); padding: 20px 10px; text-align: center; }
.empty.big { margin: auto; font-size: 15px; }

.chat { display: flex; flex-direction: column; min-height: 0; min-width: 0; background: var(--bg); }
.chat-head { display: flex; align-items: center; gap: 12px; padding: 10px 16px; background: #fff; border-bottom: 1px solid var(--line); flex-wrap: wrap; }
.ch-title { flex: 1; min-width: 160px; }
.ch-title b { font-size: 15px; margin-right: 8px; }
.ch-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.ch-actions select { border: 1px solid var(--line); border-radius: 9px; padding: 8px 10px; background: #fff; }
.chip { display: inline-block; font-size: 11px; font-weight: 700; padding: 1px 8px; border-radius: 10px; text-transform: uppercase; background: #e5e7eb; color: #374151; }
.chip.s-waiting { background: #fee2e2; color: #b91c1c; }
.chip.s-active { background: #dcfce7; color: #166534; }
.back { display: none; background: none; border: 0; font-size: 28px; line-height: 1; cursor: pointer; padding: 0 6px; }
.info-toggle { display: none; }
.msgs { flex: 1; overflow-y: auto; padding: 16px 20px; display: flex; flex-direction: column; gap: 3px; }
.msg { display: flex; flex-direction: column; max-width: 72%; align-self: flex-start; align-items: flex-start; }
.msg.me { align-self: flex-end; align-items: flex-end; }
.who { font-size: 11.5px; color: var(--muted); margin: 10px 4px 3px; }
.bubble { background: #fff; border: 1px solid var(--line); padding: 8px 12px; border-radius: 14px; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; }
.msg.me .bubble { background: var(--c); color: #fff; border-color: transparent; }
.msg.me .bubble a { color: #fff; }
.seen { font-size: 11px; color: var(--muted); margin: 2px 4px 0; }
.sys { align-self: center; font-size: 12px; color: var(--muted); background: #e9edf3; padding: 3px 12px; border-radius: 12px; margin: 10px 0; text-align: center; }
.img img { max-width: 260px; max-height: 260px; border-radius: 12px; border: 1px solid var(--line); display: block; margin: 2px 0; }
.filechip { display: inline-flex; gap: 4px; align-items: center; background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; text-decoration: none; color: var(--text); margin: 2px 0; }
.typing { display: flex; gap: 4px; padding: 12px 14px; }
.typing i { width: 7px; height: 7px; border-radius: 50%; background: #9ca3af; animation: dot 1.2s infinite; }
.typing i:nth-child(2) { animation-delay: .15s; } .typing i:nth-child(3) { animation-delay: .3s; }
@keyframes dot { 0%, 60%, 100% { opacity: .4; transform: none; } 30% { opacity: 1; transform: translateY(-3px); } }

.composer { position: relative; background: #fff; border-top: 1px solid var(--line); padding: 8px 12px 12px; }
.tools { display: flex; gap: 4px; align-items: center; margin-bottom: 6px; }
.tool { background: none; border: 0; font-size: 18px; width: 34px; height: 32px; border-radius: 8px; cursor: pointer; }
.tool:hover { background: #f3f4f6; }
.canned { border: 1px solid var(--line); border-radius: 8px; padding: 5px 8px; background: #fff; max-width: 200px; }
.input-row { display: flex; gap: 8px; align-items: flex-end; }
.input-row textarea { flex: 1; resize: none; border: 1px solid #d1d5db; border-radius: 10px; padding: 9px 12px; max-height: 160px; outline: 0; }
.input-row textarea:focus { border-color: var(--c); }
.input-row textarea:disabled { background: #f3f4f6; }
.emoji-box { position: absolute; bottom: 100%; left: 12px; width: 300px; background: #fff; border: 1px solid var(--line); border-radius: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.15); padding: 8px; display: none; grid-template-columns: repeat(8, 1fr); gap: 2px; }
.emoji-box.show { display: grid; }
.emoji-box button { background: none; border: 0; font-size: 20px; border-radius: 6px; cursor: pointer; padding: 3px; }
.emoji-box button:hover { background: #f3f4f6; }

.info { background: #fff; border-left: 1px solid var(--line); padding: 18px; overflow-y: auto; position: relative; }
.info-av { width: 56px; height: 56px; border-radius: 50%; background: var(--c); color: #fff; font-weight: 800; font-size: 20px; display: flex; align-items: center; justify-content: center; }
.info dl { margin: 0; }
.info dt { font-size: 11px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; margin-top: 10px; }
.info dd { margin: 2px 0 0; word-break: break-word; }
.info .prev { display: block; padding: 4px 0; }
.info-close { position: absolute; top: 8px; right: 8px; }
body.has-waiting .brand .dot { animation: pulse 1s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 8px var(--c-ring); } }

/* ----------------------------------------------------------------- */
/* Responsive                                                         */
/* ----------------------------------------------------------------- */
@media (max-width: 1200px) {
  .app { grid-template-columns: 300px 1fr; }
  .info { display: none; position: fixed; top: 56px; right: 0; bottom: 0; width: 300px; z-index: 15; box-shadow: -10px 0 30px rgba(0,0,0,.12); }
  body.show-info .info { display: block; }
  .info-toggle { display: inline-flex; }
}
@media (max-width: 900px) {
  .topbar { gap: 10px; padding: 0 10px; }
  .nav-toggle { display: block; }
  .nav { display: none; position: absolute; top: 56px; left: 0; right: 0; flex-direction: column; background: #fff; border-bottom: 1px solid var(--line); padding: 8px; box-shadow: 0 10px 20px rgba(0,0,0,.08); }
  body.nav-open .nav { display: flex; }
  .brand { flex: 1; }
  .app { grid-template-columns: 1fr; }
  .chat { display: none; }
  body.show-chat .convs { display: none; }
  body.show-chat .chat { display: flex; }
  .back { display: block; }
  .info { width: 100%; }
  .msg { max-width: 88%; }
  .msgs { padding: 12px; }
  .row2 { grid-template-columns: 1fr; }
  .ch-actions .btn { padding: 7px 10px; font-size: 13px; }
  .input-row textarea { font-size: 16px; }
  .toast { left: 16px; right: 16px; max-width: none; }
}

/* Statistics */
.tiles { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 16px; }
.tile { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.t-label { font-size: 12px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.t-value { font-size: 28px; font-weight: 800; line-height: 1.2; margin-top: 4px; }
.t-sub { font-size: 12px; color: var(--muted); }
.bars { display: flex; align-items: flex-end; gap: 2px; height: 180px; border-bottom: 1px solid #d1d5db; background: repeating-linear-gradient(to top, transparent 0, transparent 44px, #f1f3f6 44px, #f1f3f6 45px); }
.bars.short { height: 120px; }
.bar-col { flex: 1; height: 100%; display: flex; align-items: flex-end; cursor: default; outline: 0; min-width: 0; }
.bar-col:hover .bar, .bar-col:focus .bar { background: var(--c-dark); }
.bar-col:hover, .bar-col:focus { background: var(--c-softer); }
.bar { width: 100%; max-width: 28px; margin: 0 auto; background: var(--c); border-radius: 4px 4px 0 0; }
.bars-axis { display: flex; justify-content: space-between; font-size: 12px; color: var(--muted); margin-top: 6px; }
.bar-tip { position: absolute; z-index: 60; background: #111827; color: #fff; font-size: 12.5px; padding: 6px 10px; border-radius: 7px; pointer-events: none; white-space: nowrap; }

/* Avatar upload */
.avatar-edit { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.avatar-big { width: 72px; height: 72px; border-radius: 50%; object-fit: cover; background: var(--c); color: #fff; font-size: 28px; font-weight: 800; display: flex; align-items: center; justify-content: center; }
.avatar-form { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.c-missed { color: #b45309; font-weight: 700; }

/* On/off switch */
.switch-row { flex-direction: row; align-items: center; gap: 14px; padding: 14px 16px; border: 1px solid var(--line); border-radius: 10px; background: #f9fafb; cursor: pointer; font-weight: 400; font-size: 14px; }
.switch-row b { font-size: 15px; }
.switch { position: relative; flex: none; width: 52px; height: 30px; }
.switch input { position: absolute; opacity: 0; width: 0; height: 0; }
.switch .slider { position: absolute; inset: 0; background: #cbd5e1; border-radius: 30px; transition: background .2s; }
.switch .slider:before { content: ""; position: absolute; left: 3px; top: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: transform .2s; }
.switch input:checked + .slider { background: var(--ok); }
.switch input:checked + .slider:before { transform: translateX(22px); }
.switch input:focus-visible + .slider { box-shadow: 0 0 0 3px rgba(22, 163, 74, .3); }

/* Push notification box */
.push-state { padding: 10px 12px; border-radius: 9px; background: #f3f4f6; }
.push-state.ok { background: #f0fdf4; color: #166534; }
.push-state.warn { background: #fffbeb; color: #92400e; }
@media (display-mode: standalone) { .topbar { padding-top: env(safe-area-inset-top); height: calc(56px + env(safe-area-inset-top)); } }

/* History bulk actions */
.bulk-bar { display: flex; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.btn:disabled { opacity: .45; cursor: default; }
table.list th.cb, table.list td.cb { width: 34px; text-align: center; }
table.list td.cb input, #check-all { width: 16px; height: 16px; cursor: pointer; }
.icon-del { background: none; border: 0; cursor: pointer; font-size: 16px; padding: 4px 6px; border-radius: 6px; opacity: .55; }
.icon-del:hover { opacity: 1; background: #fef2f2; }

table.list td.rating-cell { white-space: nowrap; cursor: default; }
.bulk-sep { width: 1px; background: var(--line); margin: 0 4px; }

/* Branding */
.color-row { display: flex; align-items: center; gap: 10px; }
.color-row input[type=color] { width: 64px; height: 42px; padding: 4px; border: 1px solid #d1d5db; border-radius: 9px; background: #fff; cursor: pointer; }
.brand-preview { max-height: 48px; max-width: 200px; object-fit: contain; border: 1px dashed var(--line); border-radius: 8px; padding: 6px; background: #fff; }
.brand-preview.empty { display: inline-flex; align-items: center; gap: 8px; font-weight: 800; }
.brand-preview .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--c); }

/* Collapsible settings sections */
details.fold > summary { list-style: none; cursor: pointer; display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
details.fold > summary::-webkit-details-marker { display: none; }
details.fold > summary h2 { margin: 0; }
details.fold > summary::after { content: ""; width: 9px; height: 9px; border-right: 2px solid var(--muted); border-bottom: 2px solid var(--muted); transform: rotate(45deg); margin-left: auto; transition: transform .15s; }
details.fold[open] > summary::after { transform: rotate(-135deg); }
details.fold[open] > summary { margin-bottom: 14px; }
.fold-sum { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.fold-sum.ok { color: var(--ok); }
.fold-sum.warn { color: #b45309; }
.fold-body { display: flex; flex-direction: column; gap: 12px; }
.test-row { display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap; padding-top: 12px; border-top: 1px dashed var(--line); }
.test-row label { flex: 1; min-width: 220px; }

/* Top menu: switch to the ☰ button before the items stop fitting */
@media (max-width: 1240px) {
  .topbar { gap: 10px; }
  .nav-toggle { display: block; }
  .brand { flex: 1; }
  .nav { display: none; position: absolute; top: 56px; left: 0; right: 0; flex-direction: column; background: #fff; border-bottom: 1px solid var(--line); padding: 8px; box-shadow: 0 10px 20px rgba(0,0,0,.08); }
  body.nav-open .nav { display: flex; }
}

/* Website texts per language */
.lang-fold { border: 1px solid var(--line); border-radius: 10px; padding: 12px 14px; background: #fafbfc; }
.lang-fold[open] > summary { margin-bottom: 10px; }

/* Mobile: never let the page scroll sideways */
html, body { max-width: 100%; overflow-x: hidden; }
.wrap, .card, .form-grid, .fold-body, .row2 > *, .page-head > * { min-width: 0; }
.card, .tablewrap { max-width: 100%; }
.card pre, .card code, .code { max-width: 100%; overflow-wrap: anywhere; }
.card img { max-width: 100%; height: auto; }
@media (max-width: 600px) {
  .wrap { margin: 14px auto; padding: 0 12px; }
  .card { padding: 14px; }
  .filters label, .test-row label { min-width: 0; flex: 1 1 100%; }
  .topbar { gap: 6px; padding: 0 8px; }
  .top-right { gap: 2px; min-width: 0; }
  .status-select { max-width: 110px; padding: 6px 8px; }
  .brand-logo { max-width: 110px; }
  .switch-row { padding: 12px; gap: 10px; }
  .color-row { flex-wrap: wrap; }
  .emoji-box { width: calc(100vw - 24px); }
}

/* Mobile top bar: logout lives in the ☰ menu, brand never wraps */
.nav-logout { display: none; }
.brand { white-space: nowrap; min-width: 0; }
@media (max-width: 900px) {
  .top-logout { display: none; }
  .nav-logout { display: block; margin-top: 6px; padding-top: 8px; border-top: 1px solid var(--line); }
  .nav-logout button { width: 100%; text-align: left; background: none; border: 0; padding: 9px 12px; font: inherit; font-weight: 600; color: #dc2626; border-radius: 8px; cursor: pointer; }
  .nav-logout button:hover { background: #fef2f2; }
  .nav { max-height: calc(100dvh - 56px); overflow-y: auto; }
  .brand { flex: 1 1 auto; overflow: hidden; }
  .top-right { flex: none; }
}
@media (max-width: 480px) {
  .brand { font-size: 15px; gap: 6px; }
  .status-select { font-size: 13px; max-width: 104px; }
  .icon-btn { width: 32px; height: 36px; font-size: 17px; }
  .chat-head { padding: 8px 12px; gap: 8px; }
  .ch-title { min-width: 0; flex: 1 1 calc(100% - 50px); }
  .ch-actions { width: 100%; }
  .ch-actions .btn { flex: 1; }
  .page-head h1 { font-size: 20px; }
  .btn { padding: 9px 14px; }
  table.list th, table.list td { padding: 8px 9px; }
  .bulk-bar .btn, .actions .btn { flex: 1 1 auto; }
  .filters > * { flex: 1 1 100%; }
  .row2 { gap: 12px; }
  input, select, textarea { font-size: 16px; }
}

/* Phones: tables become one card per row, no sideways scrolling */
@media (max-width: 700px) {
  .tablewrap { overflow-x: visible; }
  table.list, table.list tbody { display: block; width: 100%; background: none; border: 0; }
  table.list tr.head-row { display: none; }
  table.list tr { display: block; background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 6px 14px; margin-bottom: 10px; }
  table.list tr.is-unread { border-color: var(--c); }
  table.list td, table.list tr.is-unread td { display: flex; justify-content: space-between; align-items: flex-start; gap: 14px; text-align: right; padding: 8px 0; border-bottom: 1px solid #f1f3f6; background: none; min-width: 0; overflow-wrap: anywhere; }
  table.list td:last-child { border-bottom: 0; }
  table.list td[data-label]::before { content: attr(data-label); flex: none; max-width: 42%; text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); padding-top: 2px; }
  table.list td > * { min-width: 0; }
  table.list td.cb { width: auto; justify-content: flex-start; }
  table.list td.cb input { width: 20px; height: 20px; }
  table.list td.rating-cell { white-space: normal; }
  table.list td .actions { justify-content: flex-end; }
  table.list td:empty { display: none; }
}
@media (max-width: 700px) {
  table.list td[colspan] { display: block; text-align: left; }
}
@media (max-width: 700px) {
  table.list td:has(.icon-del) { display: block; padding-top: 10px; }
  .icon-del { display: flex; align-items: center; justify-content: center; gap: 8px; width: 100%; opacity: 1; padding: 10px 14px; font-size: 18px; color: #dc2626; background: #fef2f2; border: 1px solid #fecaca; border-radius: 9px; font-weight: 600; }
  .icon-del::after { content: attr(title); font-size: 14px; }
  .icon-del:hover, .icon-del:active { background: #fee2e2; }
}

/* Phone cards: clearer separation and uniform action buttons */
@media (max-width: 700px) {
  table.list tr { box-shadow: 0 2px 8px rgba(17, 24, 39, .08); border-color: #d9dee6; border-left: 4px solid var(--c); }
  table.list td:has(.btn), table.list td:has(.actions) { display: flex; flex-wrap: nowrap; gap: 8px; padding: 12px 0 6px; border-bottom: 0; }
  table.list td .actions { display: flex; flex: 1; gap: 8px; flex-wrap: nowrap; }
  table.list td .actions > *, table.list td > .btn, table.list td > form { flex: 1 1 0; margin: 0; min-width: 0; }
  table.list td .btn, table.list td .inline .btn { width: 100%; min-height: 42px; padding: 9px 10px; font-size: 14px; font-weight: 600; border-radius: 9px; }
  table.list td .btn.ghost { background: var(--c-soft); color: var(--c-dark); border: 1px solid #fecdd3; }
  table.list td .btn.ghost:hover { background: #ffe4e8; }
  table.list td .btn.ghost.danger, table.list td .btn.danger { background: #fff; color: #dc2626; border: 1px solid #fca5a5; }
  table.list td .btn.ghost.danger:hover { background: #fef2f2; }
}

/* Desktop: same button look in table rows as on phones */
@media (min-width: 701px) {
  table.list td:has(.btn), table.list td:has(.actions) { white-space: nowrap; }
  table.list td .actions { flex-wrap: nowrap; }
  table.list td .btn { min-height: 36px; padding: 7px 14px; font-size: 14px; font-weight: 600; border-radius: 9px; }
  table.list td .btn.ghost { background: var(--c-soft); color: var(--c-dark); border: 1px solid var(--c-ring); }
  table.list td .btn.ghost:hover { background: var(--c-ring); }
  table.list td .btn.ghost.danger, table.list td .btn.danger { background: #fff; color: #dc2626; border: 1px solid #fca5a5; }
  table.list td .btn.ghost.danger:hover { background: #fef2f2; }
}
@media (max-width: 700px) {
  table.list td .btn.ghost { border-color: var(--c-ring); }
}

/* File pickers and avatar block */
input[type=file] { font: inherit; font-size: 13px; color: var(--muted); max-width: 100%; }
input[type=file]::file-selector-button { font: inherit; font-weight: 600; font-size: 14px; color: var(--c-dark); background: var(--c-soft); border: 1px solid var(--c-ring); border-radius: 9px; padding: 8px 14px; margin-right: 10px; cursor: pointer; transition: background .15s; }
input[type=file]::file-selector-button:hover { background: var(--c-ring); }
label input[type=file] { padding: 8px; }
.avatar-edit { gap: 18px; align-items: flex-start; }
.avatar-form { flex: 1; min-width: 0; padding: 12px 14px; border: 1px dashed #d1d5db; border-radius: 10px; background: #fafbfc; }
.avatar-form input[type=file] { flex: 1 1 100%; }
.avatar-form .btn, .avatar-edit > form .btn { min-height: 38px; }
.avatar-edit > form:not(.avatar-form) { flex-basis: 100%; }
.avatar-edit > form:not(.avatar-form) .btn { background: #fff; color: #dc2626; border: 1px solid #fca5a5; }
.avatar-edit > form:not(.avatar-form) .btn:hover { background: #fef2f2; }
.push-state { font-size: 14px; }
.card .btn:not(.small) { min-height: 40px; }
@media (max-width: 600px) {
  .avatar-edit { flex-direction: column; align-items: center; text-align: center; }
  .avatar-form { width: 100%; flex-direction: column; align-items: stretch; }
  .avatar-form .btn { width: 100%; }
  .avatar-edit > form:not(.avatar-form) { width: 100%; }
  .avatar-edit > form:not(.avatar-form) .btn { width: 100%; }
  .card > .btn, .card form > .btn:not(.small), .fold-body > .btn { width: 100%; }
}

/* My account: two columns on wide screens, Save stays in view */
.account-grid { display: grid; grid-template-columns: 1fr; gap: 16px; align-items: start; }
.account-col .card:last-child, .account-form { margin-bottom: 16px; }
@media (min-width: 900px) {
  .account-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 20px; }
  .account-form { margin-bottom: 0; }
  .account-form .actions { position: sticky; bottom: 0; background: linear-gradient(to top, #fff 70%, rgba(255,255,255,0)); padding: 14px 0 2px; margin-top: 4px; }
}
