:root {
  --bg: #f5f6f8; --card: #fff; --text: #1d2330; --muted: #667085; --line: #e1e4ea;
  --accent: #2b5fd9; --accent-text: #fff; --danger: #c0352b;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root { --bg: #14171d; --card: #1d222b; --text: #e8eaf0; --muted: #98a2b3; --line: #2f3643; --accent: #5b8cff; --accent-text: #0b1020; --danger: #ff7a6e; }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 16px; overflow-x: hidden; }
[hidden] { display: none !important; }
button, input { font: inherit; color: inherit; }
button { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 8px 12px; min-height: 40px; cursor: pointer; }
button:hover { border-color: var(--accent); }
button:focus-visible, input:focus-visible, a:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button.primary { background: var(--accent); color: var(--accent-text); border-color: var(--accent); }
button.danger { color: var(--danger); }
input { width: 100%; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); min-height: 44px; }
.muted { color: var(--muted); }
.center { text-align: center; padding: 32px 16px; }
.grow { flex: 1 1 auto; min-width: 0; }
.error { color: var(--danger); min-height: 1.3em; margin: 0; }

.login { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: 14px; padding: 24px; width: 100%; max-width: 380px; display: grid; gap: 12px; }
.card h1 { margin: 0; font-size: 1.5rem; }
.card label { display: grid; gap: 4px; font-size: .9rem; color: var(--muted); }

.top { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 16px; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { font-size: 1.1rem; }
.tabs { display: flex; gap: 4px; }
.tab { border-color: transparent; background: transparent; }
.tab.active { background: var(--bg); border-color: var(--line); font-weight: 600; }
#files-view, #trash-view { max-width: 960px; margin: 0 auto; padding: 12px 16px; position: relative; }
.bar { display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: space-between; margin-bottom: 8px; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; }
.crumbs { display: flex; flex-wrap: wrap; gap: 2px 4px; align-items: center; min-width: 0; }
.crumbs button { border: 0; background: none; padding: 4px 6px; min-height: 36px; color: var(--accent); max-width: 60vw; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.crumbs .sep { color: var(--muted); }

.list { list-style: none; margin: 0; padding: 0; background: var(--card); border: 1px solid var(--line); border-radius: 12px; }
.list:empty { display: none; }
.row { display: flex; align-items: center; gap: 8px; padding: 8px 12px; border-bottom: 1px solid var(--line); min-width: 0; }
.row:last-child { border-bottom: 0; }
.row .icon { flex: 0 0 auto; width: 1.6em; text-align: center; }
.row .name { flex: 1 1 auto; min-width: 0; background: none; border: 0; padding: 4px; text-align: left; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .meta { flex: 0 0 auto; color: var(--muted); font-size: .85rem; text-align: right; }
.row .ops { flex: 0 0 auto; display: flex; gap: 4px; }
.row .ops button { padding: 4px 8px; min-height: 36px; font-size: .85rem; }
@media (max-width: 600px) {
  .row { flex-wrap: wrap; }
  .row .name { flex-basis: calc(100% - 3em); }
  .row .meta { flex: 1 1 auto; text-align: left; padding-left: 2em; }
  .row .ops { flex-wrap: wrap; }
}
.drop { position: fixed; inset: 0; background: color-mix(in srgb, var(--accent) 25%, transparent); border: 3px dashed var(--accent); display: grid; place-items: center; font-size: 1.3rem; z-index: 50; pointer-events: none; }
.uploads { display: grid; gap: 6px; margin-bottom: 8px; }
.up { background: var(--card); border: 1px solid var(--line); border-radius: 8px; padding: 6px 10px; font-size: .9rem; }
.up .nm { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.up progress { width: 100%; height: 8px; }
.foot { max-width: 960px; margin: 0 auto; padding: 8px 16px 24px; font-size: .85rem; }

dialog { border: 1px solid var(--line); border-radius: 14px; background: var(--card); color: var(--text); padding: 16px; max-width: min(520px, 94vw); width: 100%; }
dialog::backdrop { background: rgba(0, 0, 0, .5); }
dialog h2 { margin: 0 0 8px; font-size: 1.1rem; }
dialog .actions { justify-content: flex-end; margin-top: 12px; }
.compact { max-height: 40vh; overflow: auto; margin-top: 8px; }
.viewer { max-width: 96vw; width: 96vw; height: 92vh; max-height: 92vh; padding: 8px; display: none; flex-direction: column; }
.viewer[open] { display: flex; }
.viewer-bar { display: flex; gap: 8px; align-items: center; padding: 4px 4px 8px; }
.viewer-bar strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-body { flex: 1 1 auto; min-height: 0; overflow: auto; display: grid; place-items: center; }
.viewer-body img, .viewer-body video { max-width: 100%; max-height: 100%; }
.viewer-body audio { width: 100%; }
.viewer-body pre { align-self: start; justify-self: stretch; margin: 0; white-space: pre-wrap; word-break: break-word; font-size: .9rem; }
.toast { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 10px; z-index: 100; max-width: 92vw; }

/* ---- чат ---- */
#chat-view { max-width: 1100px; margin: 0 auto; padding: 12px 16px; display: grid; grid-template-columns: 280px minmax(0, 1fr); gap: 12px; height: calc(100vh - 120px); min-height: 420px; }
.chat-side, .chat-main { background: var(--card); border: 1px solid var(--line); border-radius: 12px; min-height: 0; display: flex; flex-direction: column; }
.chat-side-head { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.chat-rooms { list-style: none; margin: 0; padding: 0; overflow: auto; flex: 1 1 auto; }
.chat-rooms li button { display: block; width: 100%; text-align: left; border: 0; border-bottom: 1px solid var(--line); border-radius: 0; background: none; padding: 10px 12px; }
.chat-rooms li button.active { background: var(--bg); }
.chat-rooms .rt { display: flex; justify-content: space-between; gap: 8px; }
.chat-rooms .rt b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.chat-rooms .rt small, .chat-rooms .rl { color: var(--muted); font-size: .85rem; }
.chat-rooms .rl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; margin-top: 2px; }
.chat-room { display: flex; flex-direction: column; min-height: 0; flex: 1 1 auto; }
.chat-head { display: flex; align-items: center; gap: 8px; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.chat-head .muted { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 40%; }
.chat-back { display: none; }
.chat-scroll { flex: 1 1 auto; overflow: auto; padding: 12px; min-height: 0; }
.chat-scroll > button { display: block; margin: 0 auto 8px; }
.chat-msgs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.msg { max-width: 78%; align-self: flex-start; background: var(--bg); border: 1px solid var(--line); border-radius: 12px; padding: 6px 10px; }
.msg.mine { align-self: flex-end; background: color-mix(in srgb, var(--accent) 22%, var(--card)); }
.msg .who { font-size: .8rem; color: var(--muted); }
.msg .txt { white-space: pre-wrap; overflow-wrap: anywhere; }
.msg.deleted .txt { color: var(--muted); font-style: italic; }
.msg .foot2 { display: flex; gap: 8px; justify-content: flex-end; align-items: center; font-size: .75rem; color: var(--muted); }
.msg .foot2 button { border: 0; background: none; min-height: 28px; padding: 0 4px; color: var(--muted); }
.msg .att { display: flex; gap: 6px; align-items: center; margin-top: 4px; }
.msg .att a { color: var(--accent); overflow-wrap: anywhere; }
.chat-attached { display: flex; gap: 8px; align-items: center; padding: 6px 12px; border-top: 1px solid var(--line); font-size: .9rem; }
.chat-form { display: flex; gap: 8px; padding: 10px 12px; border-top: 1px solid var(--line); align-items: flex-end; }
.chat-form textarea { flex: 1 1 auto; min-width: 0; resize: none; max-height: 140px; padding: 10px 12px; border: 1px solid var(--line); border-radius: 8px; background: var(--card); font: inherit; color: inherit; min-height: 44px; }
.chk { display: flex; gap: 8px; align-items: center; margin: 4px 0; }
.chk input { width: auto; min-height: 0; }
#chat-new-title { margin-top: 8px; }
@media (max-width: 700px) {
  #chat-view { grid-template-columns: 1fr; height: calc(100vh - 150px); }
  #chat-view.in-room .chat-side { display: none; }
  #chat-view:not(.in-room) .chat-main { display: none; }
  .chat-back { display: inline-block; }
  .msg { max-width: 92%; }
}
.users { padding: 16px; display: grid; gap: 16px; max-width: 760px; margin: 0 auto; }
.users h2, .users h3 { margin: 0; }
.users .card { max-width: 420px; }
