/* =====================================================================
   OfficeChat — styles (chat app + admin console)
   ===================================================================== */
:root {
  --accent: #3442B8;
  --accent-ink: #232E8A;
  --accent-soft: #EEF0FC;
  --nav: #1B1F3B;
  --nav-2: #2E3466;
  --nav-ink: #A9AED6;
  --bg: #F4F5F8;
  --surface: #FFFFFF;
  --soft: #F1F2F6;
  --hover: #F8F9FB;
  --line: #E3E5EC;
  --line-2: #C3C7D3;
  --ink: #16181D;
  --muted: #5D6270;
  --danger: #E5484D;
  --danger-ink: #C4262E;
  --ok: #30A46C;
  --ok-ink: #1C7A43;
  --warn: #F5A524;
  --warn-ink: #8A5A00;
  --shadow: 0 8px 28px rgba(22, 24, 29, .16);
  --font: 'IBM Plex Sans', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  color: var(--ink);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
a { color: var(--accent); }
a:hover { color: var(--accent-ink); }
input, select, textarea { font: inherit; color: inherit; }
svg { flex: none; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- buttons & fields ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  height: 40px; padding: 0 16px; border-radius: 8px;
  border: 1px solid var(--line-2); background: var(--surface);
  font-weight: 600; font-size: 14px; color: var(--ink); text-decoration: none; white-space: nowrap;
}
.btn:hover { background: var(--hover); color: var(--ink); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.primary:hover { background: var(--accent-ink); }
.btn.dark { background: var(--nav); border-color: var(--nav); color: #fff; }
.btn.danger { color: var(--danger-ink); }
.btn.block { width: 100%; }
.btn.sm { height: 32px; padding: 0 10px; font-size: 13px; }
.btn:disabled { opacity: .55; cursor: not-allowed; }

.icon-btn {
  display: inline-flex; align-items: center; justify-content: center; flex: none;
  width: 38px; height: 38px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--ink);
}
.icon-btn:hover { background: var(--hover); }
.icon-btn.sm { width: 30px; height: 30px; }
.icon-btn.ghost { border-color: transparent; background: transparent; }
.icon-btn.ghost-fill { border-color: transparent; background: var(--soft); }
.icon-btn.accent { background: var(--accent); border-color: var(--accent); color: #fff; }
.icon-btn.round { border-radius: 50%; }
.icon-btn.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent); }

.link-btn { border: 0; background: none; color: var(--accent); font-weight: 600; padding: 8px 0; }

.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; font-size: 13px; font-weight: 600; color: var(--ink); }
.field input, .field select, .field textarea {
  height: 44px; padding: 0 12px; border-radius: 8px; border: 1px solid var(--line-2);
  background: var(--surface); font-size: 15px; font-weight: 400; outline: none;
}
.field textarea { height: auto; min-height: 80px; padding: 10px 12px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.field .hint { font-weight: 400; color: var(--muted); font-size: 12px; }
.form-msg { font-size: 13px; margin: 0 0 12px; padding: 10px 12px; border-radius: 8px; }
.form-msg.error { background: #FCE8E8; color: var(--danger-ink); }
.form-msg.ok { background: #E4F4EA; color: var(--ok-ink); }

.chips { display: flex; gap: 6px; flex-wrap: wrap; padding: 0 16px 10px; }
.chip {
  height: 32px; padding: 0 12px; border-radius: 16px; border: 0; background: var(--soft);
  font-size: 13px; display: inline-flex; align-items: center; gap: 6px;
}
.chip.active { background: var(--nav); color: #fff; font-weight: 600; }

.badge {
  min-width: 18px; height: 18px; border-radius: 9px; padding: 0 5px;
  background: var(--danger); color: #fff; font-size: 11px; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center;
}
.badge.accent { background: var(--accent); }

.switch { position: relative; width: 48px; height: 28px; flex: none; }
.switch input { position: absolute; inset: 0; opacity: 0; margin: 0; cursor: pointer; z-index: 1; }
.switch span { position: absolute; inset: 0; border-radius: 14px; background: var(--line-2); transition: background .15s; }
.switch span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch input:checked + span { background: var(--accent); }
.switch input:checked + span::after { transform: translateX(20px); }
.switch input:focus-visible + span { box-shadow: 0 0 0 3px var(--accent-soft); }

/* ---------- avatars ---------- */
.avatar {
  position: relative; flex: none; border-radius: 50%; color: #fff; font-weight: 700;
  display: inline-flex; align-items: center; justify-content: center; text-transform: uppercase;
}
.avatar .dot { position: absolute; right: -1px; bottom: -1px; width: 30%; height: 30%; min-width: 9px; min-height: 9px; border-radius: 50%; border: 2px solid #fff; background: #9AA0AE; }
.avatar .dot.online { background: var(--ok); }
.chan-icon {
  flex: none; display: inline-flex; align-items: center; justify-content: center;
  border-radius: 8px; background: var(--soft); color: var(--muted); font-weight: 700;
}

/* ---------- loading & auth ---------- */
.loading-screen { position: fixed; inset: 0; display: flex; align-items: center; justify-content: center; background: var(--bg); z-index: 200; }
.spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line); border-top-color: var(--accent); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.auth-view { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px 16px; }
.auth-card { width: 100%; max-width: 400px; background: var(--surface); border: 1px solid var(--line); border-radius: 16px; padding: 32px 28px; }
.brand-mark { width: 52px; height: 52px; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 700; font-size: 20px; display: flex; align-items: center; justify-content: center; margin-bottom: 18px; }
.auth-title { margin: 0; font-size: 24px; }
.auth-sub { margin: 4px 0 24px; color: var(--muted); }

/* ---------- app layout ---------- */
.app { display: flex; height: 100dvh; overflow: hidden; background: var(--bg); }

.rail { width: 68px; flex: none; background: var(--nav); display: flex; flex-direction: column; align-items: center; padding: 16px 0; gap: 8px; }
.rail-logo { width: 40px; height: 40px; border-radius: 10px; background: var(--accent); color: #fff; font-weight: 700; font-size: 15px; display: flex; align-items: center; justify-content: center; margin-bottom: 12px; }
.rail-btn { position: relative; width: 48px; height: 48px; border-radius: 10px; border: 0; background: transparent; color: var(--nav-ink); display: flex; align-items: center; justify-content: center; }
.rail-btn:hover { background: var(--nav-2); color: #fff; }
.rail-btn.active { background: var(--nav-2); color: #fff; }
.rail-btn .badge { position: absolute; top: 4px; right: 3px; }
.rail-spacer { flex: 1; }
.rail-me { border: 0; padding: 0; background: none; border-radius: 50%; }

.sidebar { width: 300px; flex: none; background: var(--surface); border-right: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.sidebar-head { display: flex; align-items: center; gap: 10px; padding: 18px 16px 12px; padding-top: calc(18px + var(--safe-t)); }
.sidebar-titles { flex: 1; min-width: 0; }
.org-name { margin: 0; font-size: 18px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.org-sub { font-size: 12px; color: var(--muted); }
.sidebar-search { padding: 0 16px 10px; }
.search { display: flex; align-items: center; gap: 8px; height: 40px; padding: 0 12px; border-radius: 8px; background: var(--soft); color: var(--muted); }
.search input { flex: 1; min-width: 0; border: 0; background: transparent; outline: none; color: var(--ink); font-size: 14px; }
.sidebar-list { flex: 1; overflow-y: auto; padding: 0 8px 16px; }

.section-label { display: flex; align-items: center; justify-content: space-between; font-size: 11px; font-weight: 600; letter-spacing: .06em; color: var(--muted); padding: 14px 8px 6px; text-transform: uppercase; }
.side-item {
  display: flex; align-items: center; gap: 10px; width: 100%; min-height: 40px; padding: 6px 8px;
  border: 0; border-radius: 8px; background: none; text-align: left; color: var(--ink);
}
.side-item:hover { background: var(--hover); }
.side-item.active { background: var(--accent-soft); color: var(--accent-ink); }
.side-item.active .si-name { font-weight: 600; }
.si-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.si-top { display: flex; align-items: baseline; gap: 8px; }
.si-name { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 14px; }
.si-time { font-size: 11px; color: var(--muted); flex: none; }
.si-preview { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-item.unread .si-name { font-weight: 700; }
.side-item.unread .si-time { color: var(--accent); font-weight: 600; }
.side-item.muted-ch .si-name { color: var(--muted); }
.si-mute { color: var(--muted); display: inline-flex; }
.empty-note { padding: 24px 12px; text-align: center; color: var(--muted); font-size: 13px; line-height: 1.5; }

/* ---------- chat ---------- */
.chat { flex: 1; min-width: 0; display: flex; flex-direction: column; background: var(--surface); position: relative; }
.chat-empty { flex: 1; display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); padding: 24px; }
.chat-empty h2 { color: var(--ink); margin: 12px 0 4px; font-size: 18px; }
.chat-empty p { margin: 0; }
.chat-empty-icon { width: 64px; height: 64px; border-radius: 16px; background: var(--accent-soft); color: var(--accent); display: inline-flex; align-items: center; justify-content: center; }
.chat-inner { flex: 1; display: flex; flex-direction: column; min-height: 0; }

.chat-head { height: 64px; flex: none; display: flex; align-items: center; gap: 10px; padding: 0 16px 0 20px; border-bottom: 1px solid var(--line); }
.back-btn { display: none; }
.chat-head-icon { display: flex; }
.chat-title-btn { flex: 1; min-width: 0; border: 0; background: none; padding: 0; text-align: left; display: flex; flex-direction: column; }
.chat-title { font-size: 17px; font-weight: 700; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat-sub.online { color: var(--ok-ink); }
.head-avatars { display: flex; }
.head-avatars .avatar { border: 2px solid #fff; margin-left: -8px; }
.head-avatars .avatar:first-child { margin-left: 0; }
.head-avatars .more { width: 28px; height: 28px; border-radius: 50%; background: #E1E3EA; border: 2px solid #fff; margin-left: -8px; font-size: 10px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }

.messages { flex: 1; overflow-y: auto; padding: 12px 0 8px; overscroll-behavior: contain; }
.load-more { display: flex; justify-content: center; padding: 8px; }
.day-sep { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; font-weight: 600; margin: 14px 24px 8px; }
.day-sep::before, .day-sep::after { content: ''; flex: 1; height: 1px; background: var(--line); }
.chat-start { padding: 24px 24px 8px; color: var(--muted); }
.chat-start h3 { margin: 0 0 4px; color: var(--ink); font-size: 18px; }

.msg { position: relative; display: flex; gap: 12px; padding: 6px 56px 6px 24px; }
.msg.compact { padding-top: 1px; padding-bottom: 1px; }
.msg:hover, .msg.menu-open { background: var(--hover); }
.msg.flash { animation: flash 1.6s ease; }
@keyframes flash { 0%, 40% { background: #FFF4D6; } 100% { background: transparent; } }
.msg-avatar { width: 38px; flex: none; display: flex; justify-content: center; }
.msg-avatar .hover-time { font-size: 10px; color: var(--muted); opacity: 0; padding-top: 4px; }
.msg:hover .hover-time { opacity: 1; }
.msg-main { flex: 1; min-width: 0; }
.msg-head { display: flex; align-items: baseline; gap: 8px; flex-wrap: wrap; }
.msg-name { font-weight: 600; font-size: 14px; }
.msg-time { font-size: 12px; color: var(--muted); }
.msg-edited { font-size: 12px; color: var(--muted); }
.msg-text { font-size: 14px; line-height: 1.5; white-space: pre-wrap; word-wrap: break-word; overflow-wrap: anywhere; margin-top: 2px; }
.msg-text a { word-break: break-all; }
.mention { color: var(--accent); font-weight: 600; background: var(--accent-soft); border-radius: 4px; padding: 0 2px; }
.mention.me { background: #FFF4D6; color: var(--warn-ink); }
.msg-deleted { font-style: italic; color: var(--muted); font-size: 13px; margin-top: 2px; }
.msg-more {
  position: absolute; top: 4px; right: 16px; width: 32px; height: 32px; border-radius: 8px;
  border: 1px solid var(--line); background: var(--surface); color: var(--muted);
  display: inline-flex; align-items: center; justify-content: center; opacity: 0;
}
.msg:hover .msg-more, .msg.menu-open .msg-more, .msg-more:focus-visible { opacity: 1; }
@media (hover: none) { .msg-more { opacity: .7; border-color: transparent; background: transparent; } }

.quote { margin: 4px 0; padding: 6px 10px; border-left: 3px solid var(--line-2); background: var(--bg); border-radius: 0 6px 6px 0; font-size: 13px; color: var(--muted); cursor: pointer; border-top: 0; border-right: 0; border-bottom: 0; display: block; width: 100%; text-align: left; }
.quote b { color: var(--ink); font-weight: 600; }
.quote span { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.reactions { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 6px; }
.reaction { height: 26px; padding: 0 8px; border-radius: 13px; border: 1px solid var(--line); background: var(--surface); font-size: 12px; display: inline-flex; align-items: center; gap: 4px; }
.reaction.on { border-color: var(--accent); background: var(--accent-soft); color: var(--accent-ink); font-weight: 600; }
.reaction.add { border-style: dashed; color: var(--muted); }

.att-list { display: flex; flex-direction: column; gap: 6px; margin-top: 6px; }
.att-file { display: flex; align-items: center; gap: 12px; width: 100%; max-width: 360px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 10px; background: var(--surface); color: var(--ink); }
.att-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.att-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.att-meta { font-size: 12px; color: var(--muted); }
.att-image { display: block; padding: 0; border: 0; background: #E1E3EA; border-radius: 10px; overflow: hidden; max-width: min(320px, 100%); }
.att-image img { display: block; max-width: 100%; max-height: 260px; min-width: 120px; min-height: 90px; object-fit: cover; }
.file-badge { width: 36px; height: 40px; flex: none; border-radius: 6px; font-size: 10px; font-weight: 700; display: inline-flex; align-items: center; justify-content: center; }
.fb-pdf { background: #FCE8E8; color: #C4262E; }
.fb-doc { background: #E5EDFB; color: #2456B0; }
.fb-xls { background: #E4F4EA; color: #1C7A43; }
.fb-ppt { background: #FDEDE1; color: #B4501A; }
.fb-img { background: #F1EAFB; color: #6B3FC0; }
.fb-zip, .fb-file { background: var(--soft); color: var(--muted); }

.typing { min-height: 18px; padding: 0 24px 2px 74px; font-size: 12px; color: var(--muted); }

.composer-wrap { flex: none; padding: 0 24px 18px; }
.context-bar { display: flex; align-items: center; gap: 8px; padding: 6px 6px 6px 12px; margin-bottom: 8px; border-left: 3px solid var(--accent); background: var(--bg); border-radius: 0 8px 8px 0; font-size: 13px; color: var(--muted); }
.context-bar span { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.staged { display: flex; flex-wrap: wrap; gap: 8px; }
.staged:not(:empty) { margin-bottom: 8px; }
.stage-chip { display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 6px 0 8px; border: 1px solid var(--line); border-radius: 8px; max-width: 260px; background: var(--surface); }
.stage-chip .file-badge { width: 26px; height: 28px; font-size: 9px; }
.stage-chip span { font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.stage-chip.uploading { opacity: .6; }
.composer { border: 1px solid var(--line-2); border-radius: 12px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; background: var(--surface); }
.composer:focus-within { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.composer textarea { border: 0; outline: none; resize: none; width: 100%; font-size: 15px; line-height: 1.45; max-height: 160px; background: transparent; padding: 0; }
.composer-actions { display: flex; align-items: center; gap: 6px; }
.composer-actions .icon-btn { width: 34px; height: 34px; }
.composer-hint { flex: 1; font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.send-btn { height: 36px; }
.archived-note { padding: 12px; text-align: center; color: var(--muted); background: var(--bg); border-radius: 10px; }

.drop-overlay { position: absolute; inset: 0; background: rgba(52, 66, 184, .08); border: 2px dashed var(--accent); display: flex; align-items: center; justify-content: center; z-index: 20; font-weight: 600; color: var(--accent); pointer-events: none; }

/* ---------- files panel ---------- */
.files-panel { width: 320px; flex: none; background: var(--surface); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
.panel-head { height: 64px; flex: none; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; border-bottom: 1px solid var(--line); margin-bottom: 12px; }
.panel-head h2 { margin: 0; font-size: 16px; }
.files-body { flex: 1; overflow-y: auto; padding: 0 8px 12px; }
.img-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; padding: 0 8px 12px; }
.img-grid button { padding: 0; border: 0; border-radius: 8px; overflow: hidden; height: 96px; background: #E1E3EA; }
.img-grid img { width: 100%; height: 100%; object-fit: cover; display: block; }
.file-row { display: flex; align-items: center; gap: 10px; padding: 8px; border-radius: 8px; }
.file-row:hover { background: var(--hover); }
.file-row .att-info .att-name { font-size: 13px; }
.panel-foot { margin: 0 16px 16px; padding: 12px; border-radius: 10px; background: var(--bg); font-size: 12px; color: var(--muted); line-height: 1.5; }
.panel-foot:empty { display: none; }

/* ---------- bottom nav (mobile) ---------- */
.bottom-nav { display: none; }

/* ---------- menus, popovers, modal, toasts ---------- */
.menu-backdrop { position: fixed; inset: 0; z-index: 89; background: transparent; }
.msg-menu { position: fixed; z-index: 90; width: 230px; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 6px; display: flex; flex-direction: column; }
.msg-menu > button { display: flex; align-items: center; gap: 10px; height: 40px; padding: 0 10px; border: 0; background: none; border-radius: 8px; text-align: left; }
.msg-menu > button:hover { background: var(--soft); }
.msg-menu > button.danger { color: var(--danger-ink); }
.emoji-row { display: flex; justify-content: space-between; padding: 4px 4px 8px; margin-bottom: 4px; border-bottom: 1px solid var(--line); }
.emoji-row button { width: 34px; height: 34px; border: 0; background: none; border-radius: 8px; font-size: 20px; padding: 0; }
.emoji-row button:hover { background: var(--soft); }

.emoji-pop { position: fixed; z-index: 90; background: var(--surface); border-radius: 12px; box-shadow: var(--shadow); padding: 8px; display: grid; grid-template-columns: repeat(8, minmax(0, 1fr)); gap: 2px; width: 300px; }
.emoji-pop button { height: 34px; border: 0; background: none; border-radius: 6px; font-size: 20px; padding: 0; }
.emoji-pop button:hover { background: var(--soft); }

.modal-backdrop { position: fixed; inset: 0; z-index: 100; background: rgba(22, 24, 29, .45); display: flex; align-items: center; justify-content: center; padding: 16px; }
.modal { width: 100%; max-width: 520px; max-height: 85dvh; background: var(--surface); border-radius: 14px; display: flex; flex-direction: column; overflow: hidden; }
.modal.wide { max-width: 720px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: 0; font-size: 18px; }
.modal-body { padding: 16px 20px; overflow-y: auto; flex: 1; }
.modal-foot { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px; border-top: 1px solid var(--line); }
.modal-foot:empty { display: none; }

.pick-list { display: flex; flex-direction: column; gap: 2px; max-height: 48dvh; overflow-y: auto; margin: 0 -8px; }
.pick-row { display: flex; align-items: center; gap: 12px; padding: 8px; border-radius: 8px; cursor: pointer; }
.pick-row:hover { background: var(--hover); }
.pick-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.pick-row .si-text { flex: 1; }
.pick-sub { font-size: 12px; color: var(--muted); }

.setting-group { margin-bottom: 20px; }
.setting-group h3 { margin: 0 0 8px; font-size: 12px; font-weight: 600; letter-spacing: .06em; color: var(--muted); text-transform: uppercase; }
.setting-card { border: 1px solid var(--line); border-radius: 12px; overflow: hidden; }
.setting-row { display: flex; align-items: center; gap: 12px; min-height: 56px; padding: 8px 16px; border-bottom: 1px solid #EEF0F4; }
.setting-row:last-child { border-bottom: 0; }
.setting-row .si-text b { font-weight: 500; font-size: 15px; }
.setting-row input[type=radio] { width: 20px; height: 20px; accent-color: var(--accent); }
.setting-row input[type=time] { height: 38px; border: 1px solid var(--line-2); border-radius: 8px; padding: 0 8px; }
.notice { display: flex; gap: 12px; padding: 12px 14px; border-radius: 12px; background: var(--accent-soft); color: var(--accent-ink); font-size: 13px; line-height: 1.45; margin-bottom: 16px; }

.search-results { display: flex; flex-direction: column; gap: 4px; }
.search-hit { display: block; width: 100%; padding: 10px; border: 0; border-radius: 8px; background: none; text-align: left; }
.search-hit:hover { background: var(--hover); }
.search-hit .msg-text { margin-top: 2px; }

.lightbox { position: fixed; inset: 0; z-index: 120; background: rgba(10, 11, 16, .9); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; padding: 56px 16px 24px; }
.lightbox img { max-width: 100%; max-height: 78dvh; border-radius: 8px; }
.lightbox-close { position: absolute; top: calc(12px + var(--safe-t)); right: 12px; }

.toasts { position: fixed; top: 16px; right: 16px; z-index: 150; display: flex; flex-direction: column; gap: 8px; width: 340px; max-width: calc(100vw - 24px); }
.toast { display: flex; gap: 10px; align-items: flex-start; padding: 12px 14px; border-radius: 12px; background: var(--nav); color: #fff; box-shadow: var(--shadow); border: 0; text-align: left; width: 100%; animation: toastIn .2s ease; }
.toast.error { background: var(--danger-ink); }
.toast .t-text { flex: 1; min-width: 0; }
.toast .t-title { font-weight: 600; display: block; }
.toast .t-body { font-size: 13px; color: #D5D8EE; display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
@keyframes toastIn { from { transform: translateY(-8px); opacity: 0; } to { transform: none; opacity: 1; } }

/* ---------- tablet ---------- */
@media (max-width: 1199px) {
  .files-panel { position: fixed; top: 0; right: 0; bottom: 0; z-index: 60; box-shadow: var(--shadow); }
}
@media (max-width: 1023px) {
  .sidebar { width: 280px; }
  .head-avatars { display: none; }
}

/* ---------- mobile ---------- */
@media (max-width: 767px) {
  body { font-size: 15px; }
  .app { flex-direction: column; }
  .rail { display: none; }
  .sidebar { width: 100%; flex: 1; border-right: 0; }
  .org-name { font-size: 24px; }
  .chat { display: none; flex: 1; min-height: 0; }
  .app.in-chat .sidebar, .app.in-chat .bottom-nav { display: none; }
  .app.in-chat .chat { display: flex; }

  .side-item { min-height: 64px; padding: 8px; gap: 12px; }
  .side-item .avatar, .side-item .chan-icon { width: 48px !important; height: 48px !important; font-size: 16px !important; }
  .side-item .chan-icon { border-radius: 12px; }
  .si-name { font-size: 16px; }
  .si-preview { font-size: 14px; }
  .search { height: 44px; border-radius: 22px; }
  .chip { height: 34px; padding: 0 14px; border-radius: 17px; }

  .bottom-nav {
    display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); flex: none;
    height: calc(64px + var(--safe-b)); padding-bottom: var(--safe-b);
    background: var(--surface); border-top: 1px solid var(--line);
  }
  .bottom-nav button { position: relative; border: 0; background: none; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; font-size: 11px; color: var(--muted); }
  .bottom-nav button.active { color: var(--accent); font-weight: 600; }
  .bottom-nav .badge { position: absolute; top: 6px; left: calc(50% + 4px); }

  .chat-head { padding: 0 8px; padding-top: var(--safe-t); height: calc(60px + var(--safe-t)); gap: 6px; }
  .back-btn { display: inline-flex; width: 44px; height: 44px; }
  .chat-head .icon-btn:not(.back-btn) { width: 40px; height: 40px; border-color: transparent; }
  #search-btn { display: none; }
  .chat-title { font-size: 16px; }

  .messages { background: var(--bg); padding: 8px 0; }
  .msg { padding: 3px 12px; gap: 8px; }
  .msg:hover { background: transparent; }
  .msg-avatar { width: 30px; }
  .msg-avatar .avatar { width: 30px !important; height: 30px !important; font-size: 11px !important; }
  .msg-avatar .hover-time { display: none; }
  .msg-main { flex: 0 1 auto; max-width: 80%; background: var(--surface); border: 1px solid var(--line); border-radius: 16px 16px 16px 4px; padding: 8px 12px; }
  .msg-text { font-size: 15px; }
  .msg.mine { flex-direction: row-reverse; }
  .msg.mine .msg-avatar { display: none; }
  .msg.mine .msg-main { background: var(--accent); border-color: var(--accent); color: #fff; border-radius: 16px 16px 4px 16px; }
  .msg.mine .msg-name { display: none; }
  .msg.mine .msg-time, .msg.mine .msg-edited, .msg.mine .msg-deleted { color: rgba(255, 255, 255, .8); }
  .msg.mine .mention { background: rgba(255, 255, 255, .2); color: #fff; }
  .msg.mine .msg-text a { color: #fff; }
  .msg.mine .quote { background: rgba(255, 255, 255, .15); border-left-color: rgba(255, 255, 255, .6); color: rgba(255, 255, 255, .9); }
  .msg.mine .quote b { color: #fff; }
  .msg.mine .att-file { color: var(--ink); }
  .msg-more { position: static; align-self: center; opacity: .6; width: 30px; height: 30px; }
  .msg-head { gap: 6px; }
  .typing { padding: 0 16px; background: var(--bg); }
  .att-file { max-width: 260px; }

  .composer-wrap { padding: 8px 10px calc(10px + var(--safe-b)); border-top: 1px solid var(--line); background: var(--surface); }
  .composer { flex-direction: row; align-items: flex-end; border: 0; padding: 0; gap: 8px; box-shadow: none !important; }
  .composer textarea { order: 2; flex: 1; background: var(--soft); border-radius: 22px; padding: 11px 16px; min-height: 44px; }
  .composer-actions { display: contents; }
  #attach-btn { order: 1; width: 44px; height: 44px; border-radius: 50%; }
  #emoji-btn, .composer-hint { display: none; }
  .send-btn { order: 3; width: 44px; height: 44px; border-radius: 50%; padding: 0; }
  .send-label { display: none; }

  .files-panel { width: 100%; }
  .panel-head { padding-top: var(--safe-t); height: calc(64px + var(--safe-t)); }

  .modal-backdrop { padding: 0; align-items: flex-end; }
  .modal, .modal.wide { max-width: none; max-height: 92dvh; border-radius: 16px 16px 0 0; }
  .modal-foot { padding-bottom: calc(12px + var(--safe-b)); }

  .msg-menu { left: 0 !important; right: 0; bottom: 0; top: auto !important; width: auto; border-radius: 16px 16px 0 0; padding: 8px 8px calc(12px + var(--safe-b)); }
  .msg-menu > button { height: 48px; font-size: 15px; }
  .menu-backdrop { background: rgba(22, 24, 29, .35); }
  .emoji-pop { left: 8px !important; right: 8px; width: auto; bottom: 80px; top: auto !important; }

  .toasts { top: calc(10px + var(--safe-t)); left: 12px; right: 12px; width: auto; }
}

/* =====================================================================
   ADMIN CONSOLE
   ===================================================================== */
.admin-shell { display: flex; min-height: 100dvh; }
.admin-nav { width: 240px; flex: none; background: var(--nav); color: #fff; display: flex; flex-direction: column; padding: 20px 12px; gap: 4px; position: sticky; top: 0; height: 100dvh; }
.admin-brand { display: flex; align-items: center; gap: 10px; padding: 0 8px 20px; }
.admin-brand .rail-logo { margin: 0; width: 36px; height: 36px; }
.admin-brand b { display: block; }
.admin-brand small { color: var(--nav-ink); font-size: 12px; }
.admin-tab { display: flex; align-items: center; gap: 10px; height: 42px; padding: 0 12px; border-radius: 8px; border: 0; background: none; color: var(--nav-ink); text-align: left; text-decoration: none; font-size: 14px; }
.admin-tab:hover { background: var(--nav-2); color: #fff; }
.admin-tab.active { background: var(--nav-2); color: #fff; font-weight: 600; }
.admin-main { flex: 1; min-width: 0; padding: 28px 32px; }
.admin-header { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.admin-header .titles { flex: 1; min-width: 200px; }
.admin-header h1 { margin: 0; font-size: 26px; }
.admin-header p { margin: 2px 0 0; color: var(--muted); }

.stat-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 16px; margin-bottom: 20px; }
.card { background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.stat { padding: 16px 18px; }
.stat .label { font-size: 13px; color: var(--muted); }
.stat .value { font-size: 28px; font-weight: 700; margin-top: 6px; }
.stat .note { font-size: 12px; color: var(--muted); margin-top: 4px; }

.card-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.card-head h2 { margin: 0; font-size: 16px; flex: 1; }
.card-body { padding: 16px 18px; }
.toolbar-search { display: flex; align-items: center; gap: 8px; height: 38px; padding: 0 10px; border-radius: 8px; background: var(--soft); min-width: 200px; }
.toolbar-search input { border: 0; background: transparent; outline: none; flex: 1; min-width: 0; }
.select { height: 38px; border-radius: 8px; border: 1px solid var(--line); padding: 0 10px; background: var(--surface); }

.table-wrap { overflow-x: auto; }
table.data { width: 100%; border-collapse: collapse; font-size: 14px; }
table.data th { text-align: left; font-size: 12px; font-weight: 600; color: var(--muted); background: #F8F9FB; padding: 10px 18px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.data td { padding: 10px 18px; border-bottom: 1px solid #EEF0F4; vertical-align: middle; }
table.data tr:last-child td { border-bottom: 0; }
table.data td.actions { text-align: right; white-space: nowrap; }
.person { display: flex; align-items: center; gap: 10px; }
.person b { display: block; font-weight: 600; }
.person small { color: var(--muted); }
.pill { display: inline-flex; align-items: center; height: 24px; padding: 0 10px; border-radius: 12px; font-size: 12px; font-weight: 600; }
.pill.active { background: #E4F4EA; color: var(--ok-ink); }
.pill.invited { background: #FFF4D6; color: var(--warn-ink); }
.pill.deactivated { background: var(--soft); color: var(--muted); }
.pill.public { background: var(--accent-soft); color: var(--accent-ink); }
.pill.private { background: #F1EAFB; color: #5B3BB0; }
.pill.admin { background: var(--nav); color: #fff; }

.admin-cols { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 16px; align-items: start; }
.bars { display: flex; align-items: flex-end; gap: 10px; height: 160px; padding-top: 8px; }
.bar { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 6px; height: 100%; justify-content: flex-end; }
.bar .fill { width: 100%; background: var(--accent); border-radius: 4px 4px 0 0; min-height: 2px; }
.bar .lbl { font-size: 11px; color: var(--muted); }
.bar .num { font-size: 11px; font-weight: 600; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 16px; }
.dept-list .row, .list-row { display: flex; align-items: center; gap: 10px; padding: 10px 0; border-bottom: 1px solid #EEF0F4; }
.list-row:last-child { border-bottom: 0; }
.list-row .grow { flex: 1; min-width: 0; }
.admin-blocked { min-height: 100dvh; display: flex; align-items: center; justify-content: center; padding: 24px; text-align: center; }

@media (max-width: 1023px) {
  .stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .admin-cols { grid-template-columns: minmax(0, 1fr); }
}
@media (max-width: 767px) {
  .admin-shell { flex-direction: column; }
  .admin-nav { width: 100%; height: auto; position: static; flex-direction: row; overflow-x: auto; padding: 10px; padding-top: calc(10px + var(--safe-t)); gap: 4px; }
  .admin-brand { display: none; }
  .admin-tab { flex: none; height: 40px; }
  .admin-main { padding: 20px 16px; }
  .admin-header h1 { font-size: 22px; }
  .form-grid { grid-template-columns: minmax(0, 1fr); }
  .toolbar-search { min-width: 0; flex: 1 1 100%; }
}
