:root {
  color-scheme: dark;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  --bg: #070b16;
  --bg-soft: #0d1324;
  --surface: rgba(14, 21, 39, .70);
  --surface-strong: rgba(18, 27, 49, .92);
  --surface-hover: rgba(255, 255, 255, .08);
  --border: rgba(255, 255, 255, .11);
  --border-strong: rgba(255, 255, 255, .18);
  --text: #f5f7ff;
  --text-soft: #aeb8d0;
  --muted: #7f8aa4;
  --primary: #7c6cff;
  --primary-2: #5d9cff;
  --primary-soft: rgba(124, 108, 255, .18);
  --success: #42d8a0;
  --warning: #f6bf5b;
  --danger: #ff6b7a;
  --shadow: 0 24px 80px rgba(0, 0, 0, .38);
  --glass-blur: 24px;
  --radius-xl: 26px;
  --radius-lg: 20px;
  --radius-md: 14px;
}

html[data-theme="light"] {
  color-scheme: light;
  --bg: #eef2ff;
  --bg-soft: #f8faff;
  --surface: rgba(255, 255, 255, .68);
  --surface-strong: rgba(255, 255, 255, .93);
  --surface-hover: rgba(31, 41, 78, .06);
  --border: rgba(53, 68, 118, .12);
  --border-strong: rgba(53, 68, 118, .20);
  --text: #182038;
  --text-soft: #536078;
  --muted: #7f8aa0;
  --primary: #6557e8;
  --primary-2: #3f83e5;
  --primary-soft: rgba(101, 87, 232, .13);
  --success: #179d70;
  --warning: #bf7a17;
  --danger: #dc4055;
  --shadow: 0 24px 70px rgba(57, 71, 120, .18);
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; }
body {
  overflow: hidden;
  background: linear-gradient(145deg, var(--bg), var(--bg-soft));
  color: var(--text);
  transition: background .25s ease, color .25s ease;
}
button, input, textarea, select { font: inherit; }
button, a, label { -webkit-tap-highlight-color: transparent; }
button { cursor: pointer; }
.hidden { display: none !important; }

.ambient { position: fixed; inset: 0; overflow: hidden; pointer-events: none; z-index: -1; }
.orb { position: absolute; border-radius: 50%; filter: blur(6px); opacity: .48; animation: drift 15s ease-in-out infinite alternate; }
.orb-a { width: 38vw; height: 38vw; min-width: 380px; min-height: 380px; left: -12vw; top: -14vw; background: radial-gradient(circle, rgba(108, 91, 255, .56), rgba(108, 91, 255, 0) 68%); }
.orb-b { width: 42vw; height: 42vw; min-width: 420px; min-height: 420px; right: -15vw; top: 14vh; background: radial-gradient(circle, rgba(40, 150, 255, .40), rgba(40, 150, 255, 0) 68%); animation-delay: -5s; }
.orb-c { width: 34vw; height: 34vw; min-width: 360px; min-height: 360px; left: 26vw; bottom: -20vw; background: radial-gradient(circle, rgba(190, 80, 255, .28), rgba(190, 80, 255, 0) 68%); animation-delay: -9s; }
@keyframes drift { from { transform: translate3d(-2%, -2%, 0) scale(.96); } to { transform: translate3d(4%, 5%, 0) scale(1.08); } }

.glass {
  background: var(--surface);
  border: 1px solid var(--border);
  box-shadow: var(--shadow);
  backdrop-filter: blur(var(--glass-blur)) saturate(145%);
  -webkit-backdrop-filter: blur(var(--glass-blur)) saturate(145%);
}
.muted { color: var(--text-soft); }
.eyebrow { display: block; color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: .18em; text-transform: uppercase; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 24px; }
.login-card { width: min(450px, 100%); padding: 34px; border-radius: 30px; display: grid; gap: 16px; animation: cardIn .55s cubic-bezier(.2,.8,.2,1); }
@keyframes cardIn { from { opacity: 0; transform: translateY(18px) scale(.98); } to { opacity: 1; transform: none; } }
.brand-row, .brand-inline { display: flex; align-items: center; gap: 13px; }
.brand-mark { width: 54px; height: 54px; border-radius: 18px; display: grid; place-items: center; color: white; font-size: 22px; font-weight: 900; background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 14px 32px rgba(93, 108, 255, .32), inset 0 1px rgba(255,255,255,.35); }
.brand-mark.small { width: 38px; height: 38px; border-radius: 13px; font-size: 16px; }
.login-card h1 { margin: 3px 0 0; font-size: 27px; letter-spacing: -.04em; }
.login-card p { margin: 0 0 4px; line-height: 1.65; font-size: 14px; }
.login-foot { display: flex; justify-content: center; align-items: center; gap: 7px; color: var(--muted); font-size: 12px; }
.security-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 5px rgba(66, 216, 160, .12); }

.field { display: grid; gap: 7px; color: var(--text-soft); font-size: 13px; font-weight: 650; }
input, textarea, select {
  width: 100%; border: 1px solid var(--border); border-radius: 14px; padding: 12px 13px; outline: 0;
  color: var(--text); background: rgba(255,255,255,.055); transition: border .18s, background .18s, box-shadow .18s;
}
html[data-theme="light"] input, html[data-theme="light"] textarea, html[data-theme="light"] select { background: rgba(255,255,255,.68); }
input::placeholder, textarea::placeholder { color: var(--muted); }
input:focus, textarea:focus, select:focus { border-color: rgba(124,108,255,.78); background: rgba(124,108,255,.07); box-shadow: 0 0 0 4px rgba(124,108,255,.13); }
select option { color: #111827; background: white; }

.primary, .secondary, .danger, .icon-button, .tool-button, .mini-button, .close-button, .send-button, .image-toolbar button, .image-toolbar a {
  border: 0; border-radius: 12px; transition: transform .15s ease, background .15s ease, opacity .15s ease, border .15s ease;
}
.primary { padding: 11px 15px; color: white; font-weight: 760; background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 10px 24px rgba(100, 92, 235, .22); }
.primary:hover, .send-button:hover { transform: translateY(-1px); filter: brightness(1.06); }
.primary:active, .send-button:active { transform: translateY(0) scale(.98); }
.secondary { padding: 9px 12px; color: var(--text); background: var(--surface-hover); border: 1px solid var(--border); }
.secondary:hover { background: var(--primary-soft); border-color: rgba(124,108,255,.34); }
.danger { padding: 9px 12px; color: #fff; background: linear-gradient(135deg, #e84d65, #ff7584); }
.wide-button { width: 100%; }
.form-error { min-height: 20px; color: var(--danger); font-size: 13px; }

.app-shell { height: 100dvh; display: grid; grid-template-rows: auto 1fr; padding: 12px; gap: 12px; }
.topbar { min-height: 62px; padding: 10px 14px; border-radius: 19px; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; z-index: 20; }
.brand-copy { display: grid; }
.brand-copy strong { font-size: 15px; }
.brand-copy span { margin-top: 2px; color: var(--muted); font-size: 11px; }
.top-center { display: flex; justify-content: center; }
.top-actions { justify-self: end; display: flex; align-items: center; gap: 7px; }
.icon-button { min-width: 40px; height: 40px; padding: 0 11px; display: inline-flex; align-items: center; justify-content: center; gap: 6px; color: var(--text); background: rgba(255,255,255,.06); border: 1px solid var(--border); }
.icon-button:hover { background: var(--surface-hover); border-color: var(--border-strong); transform: translateY(-1px); }
.icon-button b { font-size: 12px; font-weight: 700; }
.danger-soft { color: var(--danger); }
.status { display: inline-flex; align-items: center; gap: 8px; min-width: 132px; justify-content: center; padding: 7px 12px; border-radius: 999px; font-size: 12px; font-weight: 740; border: 1px solid transparent; }
.status i { width: 7px; height: 7px; border-radius: 50%; background: currentColor; box-shadow: 0 0 0 5px color-mix(in srgb, currentColor 14%, transparent); }
.status.online { color: var(--success); background: color-mix(in srgb, var(--success) 10%, transparent); border-color: color-mix(in srgb, var(--success) 22%, transparent); }
.status.warn { color: var(--warning); background: color-mix(in srgb, var(--warning) 11%, transparent); border-color: color-mix(in srgb, var(--warning) 22%, transparent); }
.status.slow, .status.offline { color: var(--danger); background: color-mix(in srgb, var(--danger) 10%, transparent); border-color: color-mix(in srgb, var(--danger) 22%, transparent); }
.status.offline i { animation: blink 1s infinite; }
@keyframes blink { 50% { opacity: .25; } }

.chat-wrap { min-height: 0; display: grid; place-items: stretch center; }
.chat-panel { position: relative; width: min(1180px, 100%); min-height: 0; border-radius: var(--radius-xl); overflow: hidden; display: grid; grid-template-rows: auto 1fr auto; }
.chat-head { min-height: 68px; padding: 15px 22px; display: flex; align-items: center; justify-content: space-between; border-bottom: 1px solid var(--border); background: rgba(255,255,255,.018); }
.chat-head h2 { margin: 3px 0 0; font-size: 18px; letter-spacing: -.03em; }
.chat-hint { color: var(--muted); font-size: 12px; }
.messages { min-height: 0; overflow-y: auto; padding: 24px clamp(14px, 4vw, 52px); scroll-behavior: smooth; scrollbar-width: thin; scrollbar-color: rgba(130,140,180,.28) transparent; }
.messages::-webkit-scrollbar { width: 8px; }
.messages::-webkit-scrollbar-thumb { background: rgba(130,140,180,.24); border-radius: 20px; }
.message { position: relative; display: flex; margin: 13px 0; animation: messageIn .24s ease-out; }
@keyframes messageIn { from { opacity: 0; transform: translateY(7px); } to { opacity: 1; transform: none; } }
.message.mine { justify-content: flex-end; }
.message.pending { opacity: .76; }
.message.failed { opacity: 1; }
.bubble { position: relative; max-width: min(720px, 82%); }
.meta { margin: 0 6px 6px; color: var(--muted); font-size: 11px; }
.message.mine .meta { text-align: right; }
.content { position: relative; padding: 12px 15px; border-radius: 18px 18px 18px 6px; color: var(--text); background: rgba(255,255,255,.075); border: 1px solid var(--border); box-shadow: 0 9px 25px rgba(0,0,0,.10); white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.56; }
html[data-theme="light"] .content { background: rgba(255,255,255,.78); }
.message.mine .content { color: #fff; background: linear-gradient(135deg, rgba(112, 93, 236, .96), rgba(62, 126, 225, .96)); border-color: rgba(255,255,255,.18); border-radius: 18px 18px 6px 18px; box-shadow: 0 13px 30px rgba(65, 84, 195, .23); }
.message-actions { position: absolute; top: -12px; right: 8px; display: flex; gap: 4px; opacity: 0; transform: translateY(4px); transition: .15s; z-index: 3; }
.message:not(.mine) .message-actions { right: auto; left: 8px; }
.message:hover .message-actions, .message:focus-within .message-actions { opacity: 1; transform: none; }
.message-actions button { width: 29px; height: 29px; border-radius: 9px; border: 1px solid var(--border); color: var(--text); background: var(--surface-strong); box-shadow: 0 6px 18px rgba(0,0,0,.16); }
.message-actions button:hover { background: var(--primary-soft); }
.reply-preview { display: grid; gap: 3px; margin: -2px -2px 9px; padding: 8px 10px; border-left: 3px solid rgba(255,255,255,.65); border-radius: 8px; background: rgba(0,0,0,.13); cursor: pointer; }
.message:not(.mine) .reply-preview { border-left-color: var(--primary); background: rgba(124,108,255,.10); }
.reply-preview strong { font-size: 11px; }
.reply-preview span { max-width: 420px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; opacity: .78; font-size: 11px; }
.message-image { display: block; max-width: min(520px, 100%); max-height: 540px; border-radius: 13px; object-fit: contain; background: rgba(0,0,0,.11); cursor: zoom-in; transition: transform .18s ease, filter .18s ease; }
.message-image:hover { transform: scale(1.012); filter: brightness(1.04); }
.file-card { display: flex; align-items: center; gap: 12px; min-width: min(300px, 70vw); color: inherit; text-decoration: none; }
.file-icon { width: 46px; height: 46px; flex: 0 0 46px; border-radius: 13px; display: grid; place-items: center; background: rgba(255,255,255,.12); font-size: 22px; }
.file-card small { opacity: .72; }
.receipt { margin-top: 5px; min-height: 15px; color: var(--muted); font-size: 10px; text-align: right; }
.message.mine .receipt { color: color-mix(in srgb, var(--text-soft) 75%, transparent); }
.delivery-state.failed { color: var(--danger); }
.retry-message { margin-left: 6px; color: var(--danger); text-decoration: underline; cursor: pointer; }
.unread-divider { display: flex; align-items: center; gap: 10px; margin: 21px 0; color: var(--primary-2); font-size: 11px; font-weight: 800; letter-spacing: .06em; }
.unread-divider::before, .unread-divider::after { content: ""; height: 1px; flex: 1; background: linear-gradient(90deg, transparent, rgba(93,156,255,.55)); }
.unread-divider::after { background: linear-gradient(90deg, rgba(93,156,255,.55), transparent); }

.composer-shell { position: relative; padding: 12px 14px max(12px, env(safe-area-inset-bottom)); border-top: 1px solid var(--border); background: rgba(5, 9, 18, .28); }
html[data-theme="light"] .composer-shell { background: rgba(255,255,255,.24); }
.composer { position: relative; min-height: 54px; display: grid; grid-template-columns: 1fr auto; align-items: end; gap: 10px; padding: 6px 7px 6px 15px; border-radius: 18px; background: rgba(255,255,255,.065); border: 1px solid var(--border); transition: border .18s, box-shadow .18s; }
.composer:focus-within { border-color: rgba(124,108,255,.5); box-shadow: 0 0 0 4px rgba(124,108,255,.09); }
.composer textarea { min-height: 40px; max-height: 150px; padding: 10px 0 7px; border: 0; border-radius: 0; resize: none; background: transparent !important; box-shadow: none !important; }
.composer-actions { display: flex; align-items: center; gap: 6px; }
.tool-button { width: 38px; height: 38px; display: grid; place-items: center; color: var(--text-soft); background: transparent; font-size: 21px; }
.tool-button:hover { color: var(--text); background: var(--surface-hover); }
.send-button { width: 42px; height: 42px; display: grid; place-items: center; color: white; background: linear-gradient(135deg, var(--primary), var(--primary-2)); box-shadow: 0 10px 22px rgba(88, 94, 225, .28); font-size: 17px; }
.composer-tip { margin: 7px 5px 0; color: var(--muted); font-size: 10px; }
.reply-composer { margin-bottom: 9px; padding: 9px 11px; display: flex; align-items: center; justify-content: space-between; gap: 12px; border-radius: 13px; background: var(--primary-soft); border: 1px solid rgba(124,108,255,.24); }
.reply-composer > div { min-width: 0; }
.reply-composer span { color: var(--primary-2); font-size: 10px; font-weight: 800; }
.reply-composer strong { margin-left: 6px; font-size: 11px; }
.reply-composer p { margin: 3px 0 0; max-width: 720px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-soft); font-size: 11px; }
.mini-button, .close-button { color: var(--text); background: var(--surface-hover); }
.mini-button { width: 28px; height: 28px; }
.close-button { width: 38px; height: 38px; font-size: 24px; }
.emoji-panel { position: absolute; right: 12px; bottom: 68px; width: 286px; padding: 11px; border-radius: 18px; display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; z-index: 15; }
.emoji-panel button { border: 0; border-radius: 10px; padding: 7px 4px; background: transparent; font-size: 20px; }
.emoji-panel button:hover { background: var(--surface-hover); transform: scale(1.08); }
.new-message { position: absolute; right: 22px; bottom: 105px; z-index: 10; padding: 9px 14px; display: inline-flex; gap: 7px; align-items: center; color: white; border: 1px solid rgba(255,255,255,.18); border-radius: 999px; background: linear-gradient(135deg, rgba(92,81,218,.96), rgba(47,116,211,.96)); box-shadow: 0 12px 30px rgba(0,0,0,.28); }
.new-message b { min-width: 18px; height: 18px; padding: 0 5px; display: grid; place-items: center; border-radius: 999px; background: rgba(255,255,255,.18); font-size: 10px; }
.upload-progress { position: absolute; left: 50%; bottom: 108px; transform: translateX(-50%); z-index: 13; padding: 9px 13px; display: flex; align-items: center; gap: 9px; border-radius: 12px; color: #fff; background: rgba(7, 11, 22, .86); border: 1px solid rgba(255,255,255,.12); box-shadow: 0 10px 30px rgba(0,0,0,.26); }
.spinner { width: 15px; height: 15px; border: 2px solid rgba(255,255,255,.28); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.drop-overlay { position: absolute; inset: 70px 12px 100px; z-index: 30; display: grid; place-items: center; border: 2px dashed rgba(124,108,255,.62); border-radius: 22px; background: rgba(8, 12, 25, .78); backdrop-filter: blur(18px); }
.drop-overlay > div { text-align: center; }
.drop-overlay span { display: grid; place-items: center; width: 62px; height: 62px; margin: 0 auto 12px; border-radius: 21px; color: #fff; background: linear-gradient(135deg, var(--primary), var(--primary-2)); font-size: 34px; }
.drop-overlay strong, .drop-overlay small { display: block; }
.drop-overlay small { margin-top: 7px; color: var(--text-soft); }

.toast { position: fixed; top: 82px; left: 50%; z-index: 1000; max-width: min(92vw, 480px); transform: translate(-50%, -14px); opacity: 0; pointer-events: none; padding: 10px 14px; border-radius: 12px; color: #fff; background: rgba(8,12,24,.92); border: 1px solid rgba(255,255,255,.14); box-shadow: 0 16px 40px rgba(0,0,0,.30); transition: .2s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.modal { position: fixed; inset: 0; z-index: 80; display: grid; place-items: center; padding: 18px; background: rgba(3, 6, 15, .64); backdrop-filter: blur(8px); }
.modal-card { width: min(1120px, 100%); max-height: min(92dvh, 920px); overflow: auto; border-radius: 26px; }
.modal-head { position: sticky; top: 0; z-index: 4; padding: 18px 22px; display: flex; align-items: center; justify-content: space-between; background: var(--surface-strong); border-bottom: 1px solid var(--border); backdrop-filter: blur(22px); }
.modal-head h2 { margin: 4px 0 0; font-size: 21px; }
.settings-grid { padding: 18px; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.admin-grid { padding: 18px; display: grid; grid-template-columns: 310px minmax(0, 1fr); gap: 16px; align-items: start; }
.panel-card { padding: 17px; border-radius: 18px; background: rgba(255,255,255,.045); border: 1px solid var(--border); }
.full-span { grid-column: 1 / -1; }
.create-user-panel { position: sticky; top: 94px; grid-row: 1 / span 3; }
.admin-main { grid-column: 2; }
.section-title { margin-bottom: 13px; display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.section-title h3 { margin: 0; font-size: 15px; }
.section-title p { margin: 4px 0 0; color: var(--muted); font-size: 11px; line-height: 1.5; }
.stack-form { display: grid; gap: 10px; }
.check-row { display: flex; align-items: center; gap: 9px; color: var(--text-soft); font-size: 12px; }
.check-row input { width: auto; }
.setting-row { min-height: 60px; display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 11px 0; border-bottom: 1px solid var(--border); }
.setting-row:last-of-type { border-bottom: 0; }
.setting-row strong, .setting-row small { display: block; }
.setting-row strong { font-size: 13px; }
.setting-row small { margin-top: 3px; color: var(--muted); font-size: 10px; }
.setting-row select { width: 140px; padding: 8px 10px; }
.switch { appearance: none; width: 43px; height: 24px; flex: 0 0 43px; padding: 0; border-radius: 999px; background: rgba(130,140,170,.25); position: relative; cursor: pointer; }
.switch::after { content: ""; position: absolute; width: 18px; height: 18px; left: 3px; top: 2px; border-radius: 50%; background: white; box-shadow: 0 2px 6px rgba(0,0,0,.22); transition: .18s; }
.switch:checked { background: linear-gradient(135deg, var(--primary), var(--primary-2)); }
.switch:checked::after { transform: translateX(18px); }
.card-list { display: grid; gap: 9px; }
.data-card { padding: 13px 14px; display: grid; grid-template-columns: minmax(0, 1fr) auto; align-items: center; gap: 12px; border-radius: 15px; background: rgba(255,255,255,.045); border: 1px solid var(--border); }
.data-card:hover { border-color: var(--border-strong); background: rgba(255,255,255,.065); }
.data-card h4 { margin: 0; font-size: 13px; }
.data-card p { margin: 5px 0 0; color: var(--muted); font-size: 10px; line-height: 1.55; }
.data-card .card-actions { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; justify-content: flex-end; }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 5px 8px; border-radius: 999px; font-size: 10px; font-weight: 760; background: var(--surface-hover); border: 1px solid var(--border); }
.badge.online { color: var(--success); }
.badge.warn { color: var(--warning); }
.badge.offline { color: var(--muted); }
.badge.danger { color: var(--danger); }
.audit-list { display: grid; gap: 8px; max-height: 360px; overflow: auto; }
.audit-item { padding: 11px 12px; border-left: 2px solid var(--primary); border-radius: 0 12px 12px 0; background: rgba(255,255,255,.035); }
.audit-item strong { display: block; font-size: 11px; }
.audit-item p { margin: 4px 0 0; color: var(--muted); font-size: 10px; line-height: 1.5; }
.empty-state { padding: 22px; text-align: center; color: var(--muted); font-size: 12px; }

.image-modal { position: fixed; inset: 0; z-index: 120; display: grid; grid-template-rows: auto 1fr; padding: 13px; background: rgba(2,4,10,.94); }
.image-toolbar { padding: 10px 13px; display: flex; align-items: center; justify-content: space-between; gap: 15px; border-radius: 16px; }
.image-toolbar > div { display: flex; gap: 6px; }
.image-toolbar button, .image-toolbar a { height: 34px; min-width: 38px; padding: 0 10px; display: grid; place-items: center; color: var(--text); background: var(--surface-hover); border: 1px solid var(--border); text-decoration: none; }
.image-stage { min-height: 0; display: grid; place-items: center; overflow: auto; padding: 20px; }
.image-stage img { max-width: 92vw; max-height: calc(100dvh - 110px); object-fit: contain; transform-origin: center; transition: transform .13s ease; user-select: none; }

@media (max-width: 900px) {
  .desktop-label { display: none; }
  .topbar { grid-template-columns: 1fr auto; }
  .top-center { grid-column: 1 / -1; grid-row: 2; margin-top: 7px; }
  .app-shell { padding: 8px; gap: 8px; }
  .topbar { min-height: auto; }
  .chat-head { display: none; }
  .chat-panel { border-radius: 20px; }
  .settings-grid, .admin-grid { grid-template-columns: 1fr; }
  .full-span, .admin-main { grid-column: 1; }
  .create-user-panel { position: static; grid-row: auto; }
}

@media (max-width: 620px) {
  body { overflow: hidden; }
  .app-shell { padding: 0; gap: 0; }
  .topbar { border-radius: 0; border-left: 0; border-right: 0; border-top: 0; padding: max(8px, env(safe-area-inset-top)) 10px 8px; }
  .brand-mark.small { width: 34px; height: 34px; }
  .brand-copy span { display: none; }
  .top-actions { gap: 4px; }
  .icon-button { min-width: 35px; height: 35px; padding: 0 8px; }
  .chat-panel { border-radius: 0; border: 0; box-shadow: none; }
  .messages { padding: 16px 11px; }
  .bubble { max-width: 89%; }
  .content { padding: 10px 12px; }
  .message-image { max-height: 390px; }
  .message-actions { opacity: .82; top: -10px; }
  .composer-shell { padding: 8px 8px max(8px, env(safe-area-inset-bottom)); }
  .composer-tip { display: none; }
  .composer { padding-left: 12px; }
  .emoji-panel { right: 4px; width: min(286px, calc(100vw - 24px)); }
  .new-message { bottom: 84px; right: 12px; }
  .upload-progress { bottom: 86px; }
  .modal { padding: 0; align-items: end; }
  .modal-card { width: 100%; max-height: 94dvh; border-radius: 24px 24px 0 0; border-bottom: 0; }
  .settings-grid, .admin-grid { padding: 12px; gap: 11px; }
  .panel-card { padding: 14px; }
  .data-card { grid-template-columns: 1fr; }
  .data-card .card-actions { justify-content: flex-start; }
  .login-card { padding: 26px 22px; border-radius: 24px; }
  .image-toolbar strong { max-width: 120px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .image-toolbar { align-items: flex-start; }
  .image-toolbar > div { flex-wrap: wrap; justify-content: flex-end; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; animation-duration: .01ms !important; animation-iteration-count: 1 !important; transition-duration: .01ms !important; }
}

.icon-button.active { color: var(--success); border-color: color-mix(in srgb, var(--success) 28%, transparent); background: color-mix(in srgb, var(--success) 10%, transparent); }
.message.flash .content { animation: messageFlash 1.25s ease; }
@keyframes messageFlash { 0%,100% { box-shadow: 0 9px 25px rgba(0,0,0,.10); } 35% { box-shadow: 0 0 0 5px rgba(124,108,255,.25), 0 15px 38px rgba(84,94,225,.26); } }

/* V1.3 message tools, reliable uploads and operations */
.pinned-bar {
  margin: 10px 18px 0; padding: 10px 13px; display: grid; grid-template-columns: auto 1fr auto;
  align-items: center; gap: 10px; text-align: left; color: var(--text); border: 1px solid color-mix(in srgb, var(--warning) 28%, var(--border));
  border-radius: 14px; background: color-mix(in srgb, var(--warning) 9%, transparent);
}
.pinned-bar > span { font-size: 18px; }
.pinned-bar strong, .pinned-bar small { display: block; }
.pinned-bar strong { font-size: 11px; }
.pinned-bar small { margin-top: 2px; max-width: 72vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; color: var(--text-soft); font-size: 10px; }
.pinned-bar b { color: var(--warning); font-size: 10px; }
.return-latest { position: absolute; top: 84px; right: 22px; z-index: 12; padding: 8px 12px; color: white; border: 1px solid rgba(255,255,255,.16); border-radius: 999px; background: rgba(10,15,30,.82); backdrop-filter: blur(14px); }

.upload-queue { position: absolute; right: 18px; bottom: 108px; z-index: 28; width: min(390px, calc(100% - 36px)); display: grid; gap: 8px; }
.upload-item { padding: 10px 11px; display: grid; grid-template-columns: minmax(0,1fr) auto; gap: 10px; align-items: center; color: #fff; border: 1px solid rgba(255,255,255,.13); border-radius: 14px; background: rgba(7,11,23,.9); box-shadow: 0 12px 34px rgba(0,0,0,.28); backdrop-filter: blur(18px); }
.upload-copy { min-width: 0; }
.upload-copy strong, .upload-copy small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.upload-copy strong { font-size: 11px; }
.upload-copy small { margin-top: 3px; color: rgba(255,255,255,.65); font-size: 9px; }
.upload-track { height: 3px; margin-top: 7px; overflow: hidden; border-radius: 99px; background: rgba(255,255,255,.12); }
.upload-track i { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, #7c6cff, #45b5ff); transition: width .16s; }
.upload-item.failed .upload-track i { background: var(--danger); }
.upload-actions { display: flex; gap: 5px; }
.upload-actions button { padding: 6px 8px; color: #fff; border: 1px solid rgba(255,255,255,.15); border-radius: 8px; background: rgba(255,255,255,.08); font-size: 9px; }

.rich-text { overflow-wrap: anywhere; line-height: 1.62; }
.rich-text a { color: #70b7ff; text-decoration: underline; text-underline-offset: 3px; }
.code-block { margin: 9px 0; overflow: hidden; border: 1px solid rgba(135,145,190,.22); border-radius: 12px; background: rgba(4,8,18,.72); }
.code-head { padding: 7px 9px; display: flex; justify-content: space-between; align-items: center; color: rgba(255,255,255,.62); border-bottom: 1px solid rgba(255,255,255,.08); font-size: 9px; }
.code-head button { padding: 4px 7px; color: #fff; border: 1px solid rgba(255,255,255,.13); border-radius: 7px; background: rgba(255,255,255,.07); font-size: 9px; }
.code-block pre { margin: 0; padding: 12px; overflow: auto; white-space: pre; tab-size: 4; }
.code-block code { color: #dce6ff; font: 12px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.collapsed-text { position: relative; max-height: 320px; overflow: hidden; padding-bottom: 32px; }
.collapsed-text:not(.expanded)::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 70px; background: linear-gradient(transparent, color-mix(in srgb, var(--surface-strong) 96%, transparent)); pointer-events: none; }
.collapsed-text.expanded { max-height: none; }
.expand-text { position: absolute; left: 50%; bottom: 3px; z-index: 2; transform: translateX(-50%); padding: 5px 10px; color: var(--primary-2); border: 1px solid var(--border); border-radius: 99px; background: var(--surface-strong); font-size: 9px; }
.message-actions button.active { color: #ffd36b; background: rgba(255,211,107,.12); }
.message-image { background: rgba(255,255,255,.04); }

.tools-card { width: min(1040px, 100%); }
.tools-grid { padding: 18px; display: grid; grid-template-columns: repeat(2,minmax(0,1fr)); gap: 16px; }
.search-form { display: grid; grid-template-columns: minmax(220px,1fr) repeat(2,minmax(130px,.45fr)) 130px auto; gap: 8px; }
.result-list { margin-top: 13px; display: grid; gap: 8px; max-height: 430px; overflow: auto; }
.result-list.compact { max-height: 390px; }
.result-card { width: 100%; padding: 11px 12px; display: grid; grid-template-columns: 30px minmax(0,1fr); align-items: center; gap: 9px; text-align: left; color: var(--text); border: 1px solid var(--border); border-radius: 13px; background: rgba(255,255,255,.035); }
.result-card:hover { border-color: var(--border-strong); background: var(--surface-hover); transform: translateY(-1px); }
.result-icon { width: 29px; height: 29px; display: grid; place-items: center; border-radius: 9px; background: var(--primary-soft); }
.result-card strong, .result-card small, .result-card em { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.result-card strong { font-size: 11px; }
.result-card small { margin-top: 3px; color: var(--text-soft); font-size: 10px; }
.result-card em { margin-top: 4px; color: var(--muted); font-size: 8px; font-style: normal; }

.health-grid { display: grid; grid-template-columns: repeat(4,minmax(0,1fr)); gap: 9px; }
.health-card { min-width: 0; padding: 12px; display: flex; gap: 9px; align-items: flex-start; border: 1px solid var(--border); border-radius: 14px; background: rgba(255,255,255,.04); }
.health-card > i { width: 8px; height: 8px; margin-top: 4px; flex: 0 0 8px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 5px color-mix(in srgb,var(--success) 12%,transparent); }
.health-card.bad > i { background: var(--danger); box-shadow: 0 0 0 5px color-mix(in srgb,var(--danger) 12%,transparent); }
.health-card strong, .health-card b, .health-card small { display: block; }
.health-card strong { color: var(--text-soft); font-size: 9px; }
.health-card b { margin-top: 4px; overflow: hidden; text-overflow: ellipsis; font-size: 13px; }
.health-card small { margin-top: 3px; overflow: hidden; text-overflow: ellipsis; color: var(--muted); font-size: 8px; }
.button-link { display: inline-grid; place-items: center; text-decoration: none; }

@media (max-width: 900px) {
  .search-form { grid-template-columns: 1fr 1fr; }
  .search-form > :first-child { grid-column: 1 / -1; }
  .health-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
}
@media (max-width: 620px) {
  .tools-grid { grid-template-columns: 1fr; padding: 12px; }
  .tools-grid .full-span { grid-column: auto; }
  .search-form { grid-template-columns: 1fr; }
  .search-form > :first-child { grid-column: auto; }
  .health-grid { grid-template-columns: 1fr 1fr; }
  .pinned-bar { margin: 7px 9px 0; }
  .pinned-bar small { max-width: 58vw; }
  .upload-queue { right: 9px; bottom: 102px; width: calc(100% - 18px); }
  .return-latest { top: 78px; right: 12px; }
}

/* V1.3.1 — message integrity */
.meta { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; }
.message.mine .meta { justify-content: flex-end; }
.meta-identity { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.integrity-badge {
  min-height: 22px; padding: 3px 7px; display: inline-flex; align-items: center; gap: 4px;
  border: 1px solid var(--border); border-radius: 999px; color: var(--muted);
  background: rgba(255,255,255,.04); font-size: 9px; font-weight: 800; cursor: help;
}
.integrity-badge i { width: 14px; height: 14px; display: grid; place-items: center; border-radius: 50%; font-style: normal; }
.integrity-badge.valid { color: var(--success); border-color: color-mix(in srgb, var(--success) 28%, transparent); background: color-mix(in srgb, var(--success) 9%, transparent); }
.integrity-badge.valid i { color: #06130e; background: var(--success); }
.integrity-badge.invalid { color: var(--danger); border-color: color-mix(in srgb, var(--danger) 38%, transparent); background: color-mix(in srgb, var(--danger) 12%, transparent); }
.integrity-badge.invalid i { color: white; background: var(--danger); }
.integrity-badge.unsigned { color: var(--warning); border-color: color-mix(in srgb, var(--warning) 34%, transparent); background: color-mix(in srgb, var(--warning) 10%, transparent); }
.integrity-badge.unsigned i { color: #1a1203; background: var(--warning); }
.integrity-blocked { min-width: min(420px, 74vw); border-color: color-mix(in srgb, var(--danger) 40%, var(--border)) !important; background: color-mix(in srgb, var(--danger) 8%, var(--surface-strong)) !important; }
.integrity-warning { display: grid; gap: 5px; }
.integrity-warning strong { color: var(--danger); font-size: 12px; }
.integrity-warning span { color: var(--text-soft); font-size: 10px; line-height: 1.55; }
.integrity-warning.unsigned strong { color: var(--warning); }
.reply-preview.integrity-invalid { border-left-color: var(--danger) !important; }
.message-actions button:disabled { opacity: .38; cursor: not-allowed; filter: grayscale(1); }
.file-card strong { font-size: 12px; }

.mobile-dock { display: none; }

/* V1.3.1 — mobile interface rebuilt as an app layout */
@media (max-width: 700px) {
  :root { --glass-blur: 14px; --radius-xl: 0; }
  html, body { height: 100%; overscroll-behavior: none; }
  body { background: #080d18; }
  html[data-theme="light"] body { background: #f4f6fb; }
  .ambient { opacity: .42; }
  .orb-a { min-width: 260px; min-height: 260px; left: -150px; top: -120px; }
  .orb-b { min-width: 280px; min-height: 280px; right: -180px; top: 22vh; }
  .orb-c { display: none; }

  .app-shell {
    height: 100dvh; min-height: 100dvh; padding: 0 0 calc(66px + env(safe-area-inset-bottom)); gap: 0;
    grid-template-rows: 58px minmax(0, 1fr);
  }
  .topbar {
    min-height: 58px; padding: max(7px, env(safe-area-inset-top)) 12px 7px;
    grid-template-columns: minmax(0,1fr) auto; border: 0; border-bottom: 1px solid var(--border);
    border-radius: 0; box-shadow: none; background: rgba(8,13,24,.88);
    backdrop-filter: blur(18px) saturate(135%); -webkit-backdrop-filter: blur(18px) saturate(135%);
  }
  html[data-theme="light"] .topbar { background: rgba(248,250,255,.92); }
  .brand-inline { min-width: 0; gap: 9px; }
  .brand-mark.small { width: 34px; height: 34px; flex: 0 0 34px; border-radius: 11px; font-size: 14px; box-shadow: 0 8px 20px rgba(80,87,220,.22); }
  .brand-copy { min-width: 0; }
  .brand-copy strong { max-width: 52vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
  .brand-copy span { display: block; max-width: 52vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 9px; }
  .top-center { grid-column: auto; grid-row: auto; margin: 0; justify-self: end; }
  .status { min-width: auto; padding: 6px 8px; gap: 5px; font-size: 9px; }
  .status i { width: 6px; height: 6px; box-shadow: 0 0 0 3px color-mix(in srgb, currentColor 13%, transparent); }
  .top-actions { display: none; }

  .chat-wrap { min-height: 0; display: block; }
  .chat-panel {
    width: 100%; height: 100%; min-height: 0; border: 0; border-radius: 0; box-shadow: none;
    background: transparent; backdrop-filter: none; -webkit-backdrop-filter: none;
    grid-template-rows: auto minmax(0,1fr) auto;
  }
  .chat-head { display: none; }
  .pinned-bar {
    margin: 7px 9px 0; padding: 8px 10px; border-radius: 12px; box-shadow: 0 6px 18px rgba(0,0,0,.1);
  }
  .pinned-bar > span { font-size: 15px; }
  .pinned-bar strong { font-size: 10px; }
  .pinned-bar small { max-width: 62vw; font-size: 9px; }
  .return-latest { top: 10px; right: 10px; padding: 7px 10px; font-size: 10px; }
  .messages {
    padding: 12px 9px 16px; scroll-padding-bottom: 92px; scrollbar-width: none;
    -webkit-overflow-scrolling: touch;
  }
  .messages::-webkit-scrollbar { display: none; }
  .message { margin: 10px 0; }
  .bubble { max-width: 88%; }
  .meta { margin: 0 5px 5px; gap: 5px; font-size: 9px; }
  .meta-identity { max-width: calc(100% - 62px); }
  .integrity-badge { min-height: 18px; padding: 2px 5px; font-size: 8px; }
  .integrity-badge i { width: 11px; height: 11px; }
  .integrity-badge span { display: none; }
  .content {
    padding: 10px 12px; border-radius: 17px 17px 17px 5px; font-size: 14px; line-height: 1.52;
    box-shadow: 0 5px 17px rgba(0,0,0,.10);
  }
  .message.mine .content { border-radius: 17px 17px 5px 17px; }
  .integrity-blocked { min-width: min(290px, 82vw); }
  .message-image { max-width: 100%; max-height: 46dvh; border-radius: 12px; }
  .file-card { min-width: min(245px, 72vw); gap: 10px; }
  .file-icon { width: 40px; height: 40px; flex-basis: 40px; border-radius: 11px; font-size: 19px; }
  .receipt { margin-right: 4px; font-size: 8px; }
  .reply-preview { margin-bottom: 7px; padding: 7px 8px; }
  .reply-preview strong, .reply-preview span { font-size: 9px; }

  .message-actions {
    position: static; margin-top: 7px; padding-top: 6px; display: flex; justify-content: flex-end;
    opacity: 1; transform: none; border-top: 1px solid rgba(255,255,255,.08);
  }
  .message:not(.mine) .message-actions { justify-content: flex-start; }
  .message-actions button { width: 27px; height: 25px; border: 0; border-radius: 8px; box-shadow: none; background: rgba(255,255,255,.07); font-size: 11px; }

  .composer-shell {
    padding: 7px 8px 8px; border-top: 1px solid var(--border); background: rgba(8,13,24,.94);
    backdrop-filter: blur(18px) saturate(140%); -webkit-backdrop-filter: blur(18px) saturate(140%);
  }
  html[data-theme="light"] .composer-shell { background: rgba(248,250,255,.95); }
  .composer { min-height: 48px; gap: 5px; padding: 4px 5px 4px 12px; border-radius: 16px; background: rgba(255,255,255,.065); }
  .composer textarea { min-height: 38px; max-height: 112px; padding: 9px 0 6px; font-size: 14px; }
  .composer-actions { gap: 2px; }
  .tool-button { width: 34px; height: 36px; font-size: 19px; }
  .send-button { width: 38px; height: 38px; border-radius: 13px; font-size: 15px; }
  .composer-tip { display: none; }
  .reply-composer { margin-bottom: 6px; padding: 7px 9px; border-radius: 11px; }
  .reply-composer p { max-width: 70vw; }
  .emoji-panel { right: 7px; bottom: 61px; width: calc(100vw - 14px); grid-template-columns: repeat(7,1fr); border-radius: 17px; }
  .new-message { right: 12px; bottom: 76px; padding: 8px 11px; font-size: 10px; }
  .upload-queue { right: 8px; bottom: 75px; width: calc(100% - 16px); }
  .upload-item { border-radius: 12px; }
  .drop-overlay { display: none !important; }

  .mobile-dock {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 55; height: calc(62px + env(safe-area-inset-bottom));
    padding: 5px 6px env(safe-area-inset-bottom); display: flex; align-items: stretch; justify-content: space-around;
    border: 0; border-top: 1px solid var(--border); border-radius: 0; box-shadow: 0 -8px 24px rgba(0,0,0,.18);
    background: rgba(8,13,24,.94); backdrop-filter: blur(20px) saturate(145%); -webkit-backdrop-filter: blur(20px) saturate(145%);
  }
  html[data-theme="light"] .mobile-dock { background: rgba(249,250,255,.96); }
  .mobile-dock-button {
    min-width: 52px; flex: 1; padding: 4px 2px; display: grid; place-items: center; align-content: center; gap: 1px;
    color: var(--muted); border: 0; border-radius: 12px; background: transparent;
  }
  .mobile-dock-button span { font-size: 18px; line-height: 1; }
  .mobile-dock-button b { font-size: 9px; font-weight: 720; }
  .mobile-dock-button.active, .mobile-dock-button:active { color: var(--primary-2); background: var(--primary-soft); }

  .modal { padding: 0; align-items: stretch; background: var(--bg); backdrop-filter: none; }
  .modal-card {
    width: 100%; height: 100dvh; max-height: none; border: 0; border-radius: 0; box-shadow: none;
    background: var(--bg-soft); overflow: auto; overscroll-behavior: contain;
  }
  .modal-head {
    min-height: 58px; padding: max(10px, env(safe-area-inset-top)) 14px 10px; border-radius: 0;
    background: color-mix(in srgb, var(--surface-strong) 96%, transparent);
  }
  .modal-head .eyebrow { display: none; }
  .modal-head h2 { margin: 0; font-size: 17px; }
  .close-button { width: 36px; height: 36px; border-radius: 12px; }
  .tools-grid, .settings-grid, .admin-grid { padding: 10px 10px calc(20px + env(safe-area-inset-bottom)); display: grid; grid-template-columns: 1fr; gap: 10px; }
  .full-span, .admin-main { grid-column: 1; }
  .create-user-panel { position: static; grid-row: auto; }
  .panel-card { padding: 13px; border-radius: 16px; background: var(--surface); }
  .section-title { align-items: flex-start; }
  .section-title h3 { font-size: 14px; }
  .section-title p { font-size: 10px; }
  .search-form { grid-template-columns: 1fr 1fr; }
  .search-form input:first-child { grid-column: 1 / -1; }
  .search-form button { grid-column: 1 / -1; }
  .data-card { grid-template-columns: 1fr; gap: 9px; }
  .data-card .card-actions { justify-content: flex-start; }
  .health-grid { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .result-list { max-height: none; }
  .audit-list { max-height: none; }
  .toast { top: max(68px, calc(env(safe-area-inset-top) + 60px)); max-width: calc(100vw - 24px); }

  .login-shell { min-height: 100dvh; padding: max(18px, env(safe-area-inset-top)) 14px max(18px, env(safe-area-inset-bottom)); align-items: center; }
  .login-card { width: 100%; padding: 24px 18px; gap: 14px; border-radius: 22px; box-shadow: 0 20px 52px rgba(0,0,0,.28); }
  .login-card h1 { font-size: 23px; }
  .login-card p { font-size: 12px; }
  .brand-mark { width: 48px; height: 48px; border-radius: 15px; }
  .field { font-size: 12px; }
  input, textarea, select { font-size: 16px; }
}
@media (max-width: 700px) {
  body.keyboard-open .mobile-dock { display: none; }
  body.keyboard-open .app-shell { padding-bottom: 0; }
}
.security-alert {
  position: fixed; top: 12px; left: 50%; z-index: 1500; width: min(760px, calc(100vw - 24px));
  transform: translateX(-50%); padding: 12px 14px; display: flex; align-items: center; justify-content: space-between; gap: 14px;
  color: #fff; border: 1px solid rgba(255,107,122,.48); border-radius: 15px; background: rgba(64,10,20,.94);
  box-shadow: 0 18px 48px rgba(0,0,0,.38); backdrop-filter: blur(18px);
}
.security-alert strong, .security-alert span { display: block; }
.security-alert strong { font-size: 12px; }
.security-alert span { margin-top: 3px; color: rgba(255,255,255,.74); font-size: 10px; line-height: 1.5; }
.security-alert button { flex: 0 0 auto; padding: 8px 11px; color: #fff; border: 1px solid rgba(255,255,255,.2); border-radius: 10px; background: rgba(255,255,255,.1); }
@media (max-width: 700px) {
  .security-alert { top: max(7px, env(safe-area-inset-top)); align-items: stretch; flex-direction: column; gap: 8px; }
  .security-alert button { width: 100%; }
}
.mobile-only { display: none; }
@media (max-width: 700px) { .mobile-only { display: block; } }
