:root, [data-theme="workshop"] {
  --bg: #0b0e13;
  --bg2: #10151d;
  --panel: #141b25;
  --panel2: #1b2431;
  --line: #2a3545;
  --text: #eef3fa;
  --muted: #8b97a8;
  --accent: #f0a23a;
  --accent-dim: rgba(240, 162, 58, 0.16);
  --good: #3ecf8e;
  --danger: #ef5b5b;
  --me: #2a3a2e;
  --shadow: 0 18px 50px rgba(0, 0, 0, .45);
  --radius: 16px;
  --glow: rgba(240,162,58,.14);
}
[data-theme="graphite"] {
  --bg: #0a0a0b; --bg2: #121214; --panel: #17171a; --panel2: #202024;
  --line: #2e2e33; --text: #f3f3f5; --muted: #8d8d96; --accent: #a8b4c4;
  --accent-dim: rgba(168,180,196,.16); --me: #1d2228; --glow: rgba(168,180,196,.1);
}
[data-theme="midnight"] {
  --bg: #070b18; --bg2: #0c1224; --panel: #11182c; --panel2: #182240;
  --line: #2a3560; --text: #e8eeff; --muted: #8b97c8; --accent: #6ea8ff;
  --accent-dim: rgba(110,168,255,.18); --me: #15203a; --glow: rgba(110,168,255,.16);
}
[data-theme="forest"] {
  --bg: #0a130e; --bg2: #101a14; --panel: #15241b; --panel2: #1c3024;
  --line: #2b4634; --text: #e8f6ec; --muted: #8eae98; --accent: #5dce7a;
  --accent-dim: rgba(93,206,122,.16); --me: #1a3322; --glow: rgba(93,206,122,.14);
}
[data-theme="ocean"] {
  --bg: #061318; --bg2: #0b1c22; --panel: #10262d; --panel2: #16333c;
  --line: #24515c; --text: #e6f7f8; --muted: #86aeb4; --accent: #2fd3c8;
  --accent-dim: rgba(47,211,200,.16); --me: #14343a; --glow: rgba(47,211,200,.14);
}
[data-theme="berry"] {
  --bg: #140910; --bg2: #1c0f18; --panel: #26141f; --panel2: #331b2a;
  --line: #553047; --text: #fbeaf3; --muted: #c197ad; --accent: #ff6ea8;
  --accent-dim: rgba(255,110,168,.16); --me: #3a1c2c; --glow: rgba(255,110,168,.14);
}
[data-theme="light"] {
  color-scheme: light;
  --bg: #eef1f6; --bg2: #f7f8fb; --panel: #ffffff; --panel2: #eef2f7;
  --line: #d5dde8; --text: #1b2430; --muted: #667285; --accent: #c67a12;
  --accent-dim: rgba(198,122,18,.12); --me: #e8f3ea; --glow: rgba(198,122,18,.1);
  --shadow: 0 18px 50px rgba(30, 40, 55, .12);
}
[data-theme="contrast"] {
  --bg: #000; --bg2: #000; --panel: #111; --panel2: #1a1a1a;
  --line: #fff; --text: #fff; --muted: #ddd; --accent: #ffe600;
  --accent-dim: rgba(255,230,0,.2); --me: #1a1a00; --glow: rgba(255,230,0,.2);
}
html[data-density="compact"] .item { padding: 5px; }
html[data-density="compact"] .msg { padding: 0; }
html[data-density="compact"] .bubble { padding: 6px 8px; }
html[data-density="compact"] .composer textarea { min-height: 36px; }

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font: 15px/1.45 "Segoe UI", system-ui, sans-serif;
  background:
    radial-gradient(1200px 600px at 10% -10%, var(--glow), transparent 50%),
    radial-gradient(900px 500px at 100% 0%, rgba(61,214,198,.08), transparent 46%),
    var(--bg);
  color: var(--text);
  overflow: hidden;
}

button, input, textarea, select { font: inherit; color: inherit; color-scheme: dark; }
select option { background: #1b2431; color: #eef3fa; }
[data-theme="light"] select option { background: #ffffff; color: #1b2430; }
button { cursor: pointer; }
.screen, .app { height: 100%; }
[hidden] { display: none !important; }

.theme-dots { display: flex; flex-wrap: wrap; gap: 8px; }
.theme-dot {
  width: 34px; height: 34px; border-radius: 50%; border: 2px solid var(--line); padding: 0;
}
.theme-dot.on { outline: 2px solid var(--accent); }
.pin-bar {
  margin: 8px 16px 0; padding: 8px 10px; border-radius: 12px;
  background: var(--accent-dim); border: 1px solid var(--line); font-size: 13px;
}
.mention-box {
  position: absolute; bottom: 70px; left: 60px; right: 70px;
  background: var(--panel2); border: 1px solid var(--line); border-radius: 12px;
  max-height: 180px; overflow: auto; z-index: 6;
}
.emoji-bar { display: flex; gap: 4px; padding: 0 12px 6px; flex-wrap: wrap; }
.rec-on { background: var(--danger) !important; color: #fff !important; }
.filter-row { display: flex; gap: 6px; padding: 0 12px 8px; }
.filter-row .btn { flex: 1; min-width: 0; }
.login-card {
  width: min(560px, calc(100% - 32px));
  margin: 6vh auto;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 28px;
  padding: 28px;
  box-shadow: var(--shadow);
}
.brand { display: flex; gap: 16px; align-items: flex-start; margin-bottom: 22px; }
.logo {
  width: 56px; height: 56px; border-radius: 16px;
  background: linear-gradient(160deg, #f6c36a, #d6851b);
  color: #2a1a00; display: grid; place-items: center;
  font-weight: 800; font-size: 28px; flex: none;
}
.logo.big { width: 72px; height: 72px; font-size: 34px; margin: 0 auto 12px; }
.brand h1, .empty-main h2 { margin: 0 0 6px; }
.brand p, .empty-main p { margin: 0; color: var(--muted); }
.login-form { display: grid; gap: 10px; }
.login-form label, .form-grid label { display: grid; gap: 6px; color: var(--muted); font-size: 13px; }
.form-grid .check-line {
  display: flex; align-items: center; gap: 10px; color: var(--text); font-size: 14px;
}
.form-grid .check-line input { width: 18px; height: 18px; margin: 0; accent-color: var(--accent); }
input, textarea, select {
  background: var(--panel); border: 1px solid var(--line); border-radius: 12px;
  padding: 11px 12px; outline: none; color: var(--text);
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
.btn {
  border: 1px solid var(--line); background: var(--panel2); border-radius: 12px;
  padding: 10px 14px; color: var(--text);
}
.btn.primary { background: var(--accent); color: #2a1a00; border-color: transparent; font-weight: 700; }
.btn.wide { width: 100%; }
.btn.small { padding: 6px 10px; font-size: 13px; }
.btn.ghost { background: transparent; }
.btn.danger { background: #3a1b1b; color: #ffd0d0; border-color: #5a2a2a; }
.error { color: #ffb4b4; font-size: 13px; }
.demo-hint { margin: 18px 0 8px; color: var(--muted); font-size: 13px; }
.demo-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.demo-card {
  text-align: left; background: #0f1620; border: 1px solid var(--line);
  border-radius: 14px; padding: 10px 12px;
}
.demo-card:hover { border-color: var(--accent); }
.demo-card b { display: block; }
.demo-card span { color: var(--muted); font-size: 12px; }

.app { display: grid; grid-template-columns: 320px 1fr 360px; height: 100%; min-height: 0; }
.app.no-panel { grid-template-columns: 320px 1fr; }
.sidebar, .panel {
  background: rgba(16, 21, 29, .92);
  border-right: 1px solid var(--line);
  display: flex; flex-direction: column; min-width: 0; overflow: hidden;
}
.panel { border-right: 0; border-left: 1px solid var(--line); }
.side-head, .chat-head, .panel-head {
  display: flex; align-items: center; justify-content: space-between;
  gap: 8px; padding: 12px 12px 8px; min-width: 0;
}
.chat-head { flex-wrap: wrap; }
.chat-head #chat-title { min-width: 0; flex: 1; }
.me-chip { display: flex; align-items: center; gap: 10px; min-width: 0; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; display: grid; place-items: center;
  font-weight: 700; color: #111; flex: none;
}
.avatar.sm { width: 28px; height: 28px; font-size: 12px; }
.avatar-wrap { position: relative; width: 36px; height: 36px; flex: none; }
.online-dot {
  position: absolute; right: -1px; bottom: -1px;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--good); border: 2px solid var(--panel);
  box-shadow: 0 0 0 1px rgba(62,207,142,.25);
}
.me-chip .who { min-width: 0; }
.me-chip b, .chat-head b { display: block; white-space: normal; overflow: visible; word-break: break-word; }
.me-chip .role-line, .people-text .role-line {
  display: block;
  margin-top: 2px;
  color: var(--accent);
  font-size: 12px;
  font-weight: 700;
  line-height: 1.25;
}
.me-chip small, .muted, .chat-head small { color: var(--muted); font-size: 12px; }
.icon-row { display: flex; flex-wrap: wrap; gap: 4px; }
.actions-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.actions-grid .btn { width: 100%; text-align: center; }
.icon-btn {
  width: 36px; height: 36px; border: 0; border-radius: 10px; background: transparent; color: var(--text);
}
.icon-btn:hover { background: var(--panel2); }
.filter { margin: 0 12px 8px; }
.tabs { display: flex; gap: 6px; padding: 0 12px 10px; }
.tabs button {
  flex: 1; border: 0; background: #0e141c; color: var(--muted); border-radius: 10px; padding: 8px;
}
.tabs button.on { background: var(--accent-dim); color: var(--accent); }
.list { overflow-x: hidden; overflow-y: auto; padding: 0 8px 16px; flex: 1; }
.item {
  width: 100%; display: grid; grid-template-columns: 40px minmax(0, 1fr) auto; gap: 8px; align-items: start;
  text-align: left; border: 0; background: transparent; border-radius: 14px; padding: 8px;
  min-width: 0; overflow: visible;
}
.item:hover, .item.active { background: var(--panel2); }
.item .top { display: flex; justify-content: space-between; gap: 8px; min-width: 0; align-items: flex-start; }
.item .top b { min-width: 0; overflow: visible; text-overflow: unset; white-space: normal; word-break: break-word; line-height: 1.3; }
.item .top small { flex: none; color: var(--muted); }
.item .preview {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.3;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
  white-space: normal;
  word-break: break-word;
}
.badge {
  min-width: 20px; height: 20px; padding: 0 6px; border-radius: 999px; background: var(--accent);
  color: #2a1a00; font-size: 11px; font-weight: 700; display: grid; place-items: center;
}
.dot { width: 8px; height: 8px; border-radius: 50%; background: #445; display: inline-block; }
.dot.on { background: var(--good); box-shadow: 0 0 0 3px rgba(62,207,142,.15); }
.role-pick {
  max-width: 120px; font-size: 11px; color: var(--text);
  background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 4px 6px;
}
.people-row {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 8px;
  padding: 8px;
}
.people-row .item-main {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  background: transparent;
  border: 0;
  color: inherit;
  text-align: left;
  cursor: pointer;
  min-width: 0;
  padding: 0;
  width: 100%;
}
.people-text {
  min-width: 0;
  flex: 1;
}
.people-text b {
  display: block;
  white-space: normal;
  word-break: break-word;
  line-height: 1.3;
}
.people-admin {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  padding-left: 50px;
}
.watch-hint { margin-top: 8px; font-size: 12px; line-height: 1.35; }
.vol-line { display: grid; gap: 6px; }
.vol-row { display: flex; align-items: center; gap: 8px; }
.vol-row input[type="range"] { flex: 1; }

.main {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  background: var(--bg2);
}
.empty-main { margin: auto; text-align: center; max-width: 420px; padding: 24px; }
.quick { display: flex; justify-content: center; gap: 8px; margin-top: 16px; }
#chat-view {
  display: flex;
  flex-direction: column;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  height: auto;
}
.chat-head, .pin-bar, .typing, .reply-bar, .order-preview, .pending-files, .composer {
  flex-shrink: 0;
}
.messages {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 16px 20px 8px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.item .title-line {
  font-size: 13px;
  font-weight: 600;
  line-height: 1.35;
  white-space: normal;
  overflow: visible;
}
.item .title-line .num {
  color: var(--muted);
  font-weight: 500;
}
.item .title-line .badge-rework {
  display: inline-block;
  margin: 0 4px;
  padding: 1px 6px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.02em;
  color: #1a1208;
  background: #f0a23a;
  vertical-align: middle;
}
.panel-head h3 { margin: 0; font-size: 14px; font-weight: 600; }
.kv { display: grid; grid-template-columns: 118px 1fr; gap: 5px 10px; font-size: 12px; }
.day { align-self: center; color: var(--muted); font-size: 12px; margin: 10px 0; }
.msg { max-width: min(680px, 86%); display: grid; gap: 4px; padding: 2px 0; position: relative; }
.msg.me { align-self: end; }
.msg .bubble {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px 16px 16px 6px;
  padding: 8px 10px;
}
.msg.me .bubble { background: #243028; border-color: #2f4636; border-radius: 16px 16px 6px 16px; }
.quote {
  border-left: 3px solid var(--accent); padding: 4px 8px; margin-bottom: 6px;
  color: var(--muted); font-size: 12px; background: rgba(0,0,0,.18); border-radius: 0 8px 8px 0;
}
.msg-actions { display: flex; gap: 4px; opacity: 0; transition: opacity .15s; }
.msg:hover .msg-actions { opacity: 1; }
.pending-files { display: flex; gap: 8px; flex-wrap: wrap; margin: 0 16px 8px; }
.pending-item {
  display: flex; align-items: center; gap: 6px; background: var(--panel); border: 1px solid var(--line);
  border-radius: 10px; padding: 4px 8px; color: var(--text);
}
.pending-item img { width: 36px; height: 36px; object-fit: cover; border-radius: 6px; }
.msg .meta { display: flex; gap: 8px; align-items: baseline; font-size: 12px; color: var(--muted); }
.msg .text { white-space: pre-wrap; word-break: break-word; }
.order-chip, .file-chip, .reacts {
  display: inline-flex; align-items: center; gap: 6px; margin-top: 6px;
  background: var(--accent-dim); color: #ffd089; border: 1px solid rgba(240,162,58,.25);
  border-radius: 10px; padding: 5px 8px; font-size: 12px; cursor: pointer;
}
.file-chip { color: var(--text); background: #0f1620; }
.thumbs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.thumbs img { max-width: 220px; max-height: 180px; border-radius: 10px; cursor: zoom-in; }
.reacts { background: #0f1620; color: var(--text); border-color: var(--line); }
.deleted { color: var(--muted); font-style: italic; }
.typing { padding: 0 20px 6px; color: var(--muted); font-size: 12px; }
.reply-bar, .order-preview, .drop-hint {
  margin: 0 16px 8px; padding: 8px 10px; border-radius: 12px; background: var(--panel);
  border: 1px solid var(--line); color: var(--muted); font-size: 13px;
}
.drop-hint { border-style: dashed; color: var(--accent); text-align: center; }
.composer {
  display: flex; align-items: flex-end; gap: 8px; padding: 10px 12px 14px;
  border-top: 1px solid var(--line); background: #10161f;
}
.composer textarea {
  flex: 1; resize: none; max-height: 160px; min-height: 42px; border-radius: 14px;
}
.send { width: 42px; height: 42px; padding: 0; border-radius: 14px; }

#panel-body { overflow-x: hidden; overflow-y: auto; padding: 0 16px 20px; }
.card {
  background: var(--panel2); border: 1px solid var(--line); border-radius: 16px; padding: 12px; margin-bottom: 10px;
}
.card h4 { margin: 0 0 8px; }
.kv span { color: var(--muted); }
.person {
  display: flex; justify-content: space-between; gap: 8px; align-items: center;
  padding: 8px 0; border-top: 1px solid var(--line);
}
.person:first-of-type { border-top: 0; }
.status {
  display: inline-block; padding: 2px 8px; border-radius: 999px; background: var(--accent-dim); color: var(--accent); font-size: 12px;
}
.items { margin: 0; padding-left: 16px; color: var(--muted); font-size: 13px; }

.modal {
  position: fixed; inset: 0; background: rgba(0,0,0,.55); display: grid; place-items: center; z-index: 20;
}
.tpl-list { display: grid; gap: 8px; max-height: 46vh; overflow: auto; margin-top: 8px; }
.tpl-item {
  display: block; width: 100%; text-align: left; background: var(--panel2);
  border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; color: var(--text);
}
.tpl-item b { display: block; margin-bottom: 4px; }
.tpl-item p { margin: 0; color: var(--muted); white-space: pre-wrap; word-break: break-word; line-height: 1.4; }
.tpl-item:hover { border-color: var(--accent); }
.modal-card {
  width: min(640px, calc(100% - 24px)); max-height: 86vh; overflow: auto;
  background: #151c26; border: 1px solid var(--line); border-radius: 20px; padding: 18px; box-shadow: var(--shadow);
}
.form-grid { display: grid; gap: 10px; }
.check-list { display: grid; gap: 6px; max-height: 240px; overflow: auto; }
.check-list label { display: flex; gap: 8px; align-items: center; color: var(--text); }
.lightbox {
  position: fixed; inset: 0; background: rgba(0,0,0,.82); display: grid; place-items: center; z-index: 30;
}
.lightbox img { max-width: 92vw; max-height: 92vh; border-radius: 12px; }
.toast {
  position: fixed; right: 16px; bottom: 16px; background: #1c2734; border: 1px solid var(--line);
  padding: 10px 14px; border-radius: 12px; z-index: 40; max-width: 320px;
}
.hl { color: var(--accent); cursor: pointer; }
a { color: #8ecbff; }

@media (max-width: 980px) {
  .app { grid-template-columns: 1fr; position: relative; }
  .sidebar {
    display: flex;
    position: absolute;
    inset: 0;
    z-index: 4;
    width: 100%;
    max-width: none;
    border-right: 0;
  }
  .app.chat-open .sidebar { display: none; }
  .app.chat-open .main { display: flex; flex-direction: column; min-height: 0; height: 100%; }
  .main { display: none; min-height: 0; }
  .app:not(.chat-open) .main { display: none; }
  .app.chat-open .main { display: flex; flex-direction: column; }
  .panel { position: absolute; inset: 0; z-index: 6; width: 100%; max-width: none; }
  .demo-grid { grid-template-columns: 1fr; }
  .icon-btn, .btn.small, .composer .icon-btn, .composer .send {
    min-width: 44px;
    min-height: 44px;
  }
  .composer {
    padding: 8px 8px calc(8px + env(safe-area-inset-bottom, 0px));
    gap: 4px;
  }
  .composer textarea { font-size: 16px; }
  .chat-head .back { display: inline-flex !important; }
  .login-card { margin: 12px; max-width: none; padding: 18px; }
  .toast {
    left: 12px; right: 12px; bottom: calc(12px + env(safe-area-inset-bottom, 0px));
    max-width: none;
  }
}

@media (min-width: 981px) {
  .chat-head .back { display: none; }
}
