:root {
  color-scheme: dark;
  font: 14px/1.5 system-ui, "Segoe UI", sans-serif;
  --page: #101820;
  --side: #16222c;
  --surface: #1a2935;
  --raised: #223442;
  --field: #101c25;
  --line: #304553;
  --text: #e9f1f5;
  --muted: #a1b6c3;
  --accent: #7bdac5;
  --accent-ink: #0c322d;
  --active: #203f42;
  --active-line: #4a827d;
  --avatar: #2e4658;
  --online: #84d6ac;
  --afk: #edc98e;
  --danger: #ffb6bf;
  --danger-bg: #462a37;
  --scrim: #070d14a8;
}
:root[data-theme="light"] {
  color-scheme: light;
  --page: #f6f8fa;
  --side: #eaf0f4;
  --surface: #ffffff;
  --raised: #e8eff3;
  --field: #ffffff;
  --line: #c9d7df;
  --text: #1b303d;
  --muted: #526b79;
  --accent: #136b60;
  --accent-ink: #ffffff;
  --active: #d7eeea;
  --active-line: #78aaa2;
  --avatar: #d6e2eb;
  --online: #226344;
  --afk: #77501b;
  --danger: #842f42;
  --danger-bg: #f8e0e5;
  --scrim: #172d4280;
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--page); color: var(--text); }
[hidden] { display: none !important; }
button, input, textarea, select { font: inherit; }
button, .attach {
  padding: .55rem .8rem;
  border: 1px solid var(--line);
  border-radius: .55rem;
  background: var(--surface);
  color: inherit;
  cursor: pointer;
}
button:hover, .attach:hover { background: var(--raised); border-color: var(--active-line); }
button:disabled { opacity: .55; cursor: default; }
button.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; font-weight: 700; }
button.primary:hover:not(:disabled) { filter: brightness(.92); }
input, textarea, select {
  width: 100%; min-width: 0; padding: .62rem .72rem;
  border: 1px solid var(--line); border-radius: .5rem; background: var(--field); color: inherit;
}
input::placeholder, textarea::placeholder { color: var(--muted); }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
a { color: var(--accent); }
h1 { font-size: 1.3rem; line-height: 1.25; margin: 0; overflow-wrap: anywhere; }
.icon-button { display: grid; place-items: center; flex: 0 0 36px; width: 36px; height: 36px; padding: 0; font-size: 1.2rem; }
.theme-toggle { color: var(--accent); }
#auth-theme { position: fixed; top: 1rem; right: 1rem; }
#workspace:not([hidden]) ~ #auth-theme { display: none; }

.auth {
  width: min(408px, calc(100% - 2rem)); margin: clamp(4.25rem, 10vh, 7rem) auto 2rem;
  padding: clamp(1.2rem, 5vw, 1.85rem); border: 1px solid var(--line); border-radius: 1rem;
  background: var(--surface);
}
.auth h1 { margin: 1.35rem 0 .7rem; font-size: 1.45rem; }
.auth form, .auth label { display: grid; gap: .55rem; }
.auth form { margin-bottom: .7rem; }
#credentials { margin-bottom: .3rem; }
.auth-help { display: block; margin: 0 auto; padding: .25rem .6rem; border-color: transparent; background: transparent; color: var(--accent); }
.auth-divider { display: flex; align-items: center; gap: .7rem; margin: .6rem 0; color: var(--muted); font-size: .74rem; font-weight: 650; }
.auth-divider::before, .auth-divider::after { content: ""; flex: 1; height: 1px; background: var(--line); }
#toggle { width: 100%; font-weight: 700; }
#toggle[data-registration] .gym-emoji { display: none; }

#workspace { display: grid; grid-template-columns: 270px minmax(0, 1fr); height: 100dvh; }
#sidebar {
  display: flex; flex-direction: column; min-height: 0; gap: .65rem;
  padding: .9rem .8rem .65rem; background: var(--side); border-right: 1px solid var(--line);
}
.sidebar-header, .sidebar-section { display: flex; align-items: center; justify-content: space-between; gap: .35rem; }
.sidebar-header { padding: .15rem .15rem .9rem; }
.brand { display: flex; align-items: center; gap: .65rem; font-size: 1.35rem; font-weight: 800; letter-spacing: -.04em; }
.mark { display: grid; place-items: center; width: 38px; height: 38px; border-radius: .7rem; background: var(--active); color: var(--accent); font-size: 1rem; letter-spacing: 0; }
.sidebar-section { padding-inline: .2rem; }
.aside-title { color: var(--muted); font-size: .75rem; font-weight: 700; }
.create-room-button { background: #286b4d; border-color: #438362; color: #fff; font-weight: 700; }
.create-room-button:hover { background: #317f5c; border-color: #89cfaa; }
.sidebar-section .create-room-button { padding: .3rem .48rem; font-size: .75rem; }
nav { display: grid; gap: .25rem; align-content: start; overflow: auto; min-height: 0; scrollbar-width: thin; }
.room-entry { min-width: 0; }
.room-row { display: flex; min-width: 0; border: 1px solid transparent; border-radius: .55rem; }
.room-row:hover { background: var(--surface); }
.room-row.current { background: var(--active); border-color: var(--active-line); }
.room-row button { border-color: transparent; background: transparent; }
.room-row button:hover { background: var(--raised); }
.room-select { flex: 1; display: flex; align-items: center; min-width: 0; gap: .5rem; padding: .38rem .48rem; text-align: left; }
.room-name, .participant-name, #profile span:last-child { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.room-row.current .room-name { font-weight: 700; }
.room-select .avatar { flex-basis: 23px; height: 23px; border-radius: .38rem; font-size: .72rem; }
.room-gear, .room-expand { display: grid; place-items: center; flex: 0 0 29px; padding: 0; color: var(--muted); }
.room-gear svg { width: 15px; height: 15px; }
.room-expand { flex-basis: 24px; }
.room-expand span { width: .42rem; height: .42rem; border-right: 1.5px solid; border-bottom: 1.5px solid; transform: translateY(-.1rem) rotate(45deg); }
.room-expand[aria-expanded="false"] span { transform: rotate(-45deg); }
.room-limit { margin-left: auto; color: var(--muted); font-size: .7rem; flex: 0 0 auto; }
#participants { list-style: none; margin: .22rem .4rem .3rem .88rem; padding: 0 0 0 .55rem; border-left: 1px solid var(--line); }
#participants li, #profile { display: flex; align-items: center; gap: .55rem; min-width: 0; }
#participants li { padding: .25rem .12rem; font-size: .85rem; }
.avatar {
  display: grid; place-items: center; flex: 0 0 29px; width: 29px; height: 29px;
  border: 2px solid transparent; border-radius: .55rem; background: var(--avatar); color: var(--text); font-weight: 700; overflow: hidden;
}
.avatar img { width: 100%; height: 100%; object-fit: cover; }
.speaking .avatar { border-color: var(--online); box-shadow: 0 0 0 2px var(--active-line); }
.participant-status { margin-left: auto; font-size: .67rem; color: var(--online); }
.participant-audio { flex: 0 0 25px; height: 25px; padding: 0; background: transparent; color: var(--muted); line-height: 1; }
.participant-audio.is-muted { color: var(--danger); }
.participant-volume { display: block; margin: .65rem 0; }
.participant-volume output { float: right; color: var(--muted); }
.participant-volume input { display: block; padding: 0; margin-top: .45rem; accent-color: var(--accent); }
#participant-audio-status { margin: .55rem 0 0; color: var(--muted); }
.afk .participant-status { color: var(--afk); }
footer { margin-top: auto; display: grid; gap: .55rem; }
.voice-panel { display: grid; gap: .5rem; padding: .65rem; border: 1px solid var(--line); border-radius: .7rem; background: var(--surface); }
.voice-actions { display: flex; align-items: stretch; gap: .3rem; }
#join { flex: 1; min-width: 0; padding-inline: .38rem; font-size: .84rem; }
#join.connected { background: var(--danger-bg); color: var(--danger); border-color: var(--line); }
.voice-icon { flex: 0 0 34px; display: grid; place-items: center; padding: .35rem; color: var(--accent); }
.voice-icon svg { width: 16px; height: 16px; }
.voice-icon[aria-pressed="false"] { color: var(--danger); background: var(--danger-bg); }
.icon-slash { display: none; }
.voice-icon[aria-pressed="false"] .icon-slash { display: inline; }
#start-remote-audio { font-size: .8rem; }
.desktop-downloads { display: grid; gap: .18rem; }
.client-download {
  display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .1rem .55rem;
  padding: .4rem .48rem; border: 1px solid transparent; border-radius: .5rem;
  color: var(--text); text-decoration: none; font-size: .79rem; font-weight: 600;
}
.client-download span { color: var(--muted); font-size: .68rem; font-weight: 400; }
.client-download:hover { border-color: var(--active-line); background: var(--surface); }
.auth .client-download { border-color: var(--line); margin-top: .6rem; padding: .55rem .65rem; }
#profile { width: 100%; text-align: left; background: var(--surface); padding: .47rem .55rem; font-weight: 700; }

main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.channel-header {
  display: flex; align-items: center; gap: .75rem; min-height: 64px;
  padding: .75rem clamp(.8rem, 2vw, 1.65rem); border-bottom: 1px solid var(--line); background: var(--surface);
}
.header-room-avatar .avatar { width: 38px; height: 38px; border-radius: .6rem; }
.room-heading { min-width: 0; flex: 1; }
#room-description { margin: .15rem 0 0; color: var(--muted); font-size: .84rem; white-space: pre-wrap; overflow-wrap: anywhere; max-height: 4em; overflow: auto; }
#voice-status, time { color: var(--muted); font-size: .76rem; }
.controls { display: flex; align-items: center; gap: .45rem; flex-shrink: 0; }
#share-quality, #share-source { width: auto; font-size: .8rem; }
.screen-snapshot { display: block; max-width: 100%; max-height: 29vh; margin: auto; border-radius: .5rem; }
.screen-preview-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: .35rem; }
.screen-preview-actions button { padding: .22rem .5rem; font-size: .8rem; }
#open-rooms, #close-rooms, #rooms-backdrop { display: none; }
.chat-heading { padding: .65rem clamp(.85rem, 2.2vw, 1.8rem) .45rem; color: var(--muted); font-weight: 700; font-size: .83rem; }
#screens { display: grid; grid-template-columns: repeat(auto-fit, minmax(min(100%, 235px), 1fr)); gap: .7rem; max-height: 44%; overflow: auto; padding: .7rem 1.35rem; border-bottom: 1px solid var(--line); }
figure { margin: 0; min-width: 0; }
figure video { width: 100%; max-height: 29vh; border-radius: .5rem; background: #090f13; }
.screen-caption { display: flex; align-items: center; justify-content: space-between; gap: .4rem; padding-top: .22rem; color: var(--muted); font-size: .8rem; }
.screen-fullscreen { padding: .22rem .5rem; font-size: .8rem; }
.screen-figure:is(:fullscreen, .is-expanded) { display: grid; grid-template: minmax(0, 1fr) auto / minmax(0, 1fr); overflow: hidden; padding: .75rem; background: #090f13; color: #e9f1f5; }
.screen-figure:is(:fullscreen, .is-expanded) video { display: block; width: 100%; height: 100%; min-height: 0; max-height: none; object-fit: contain; }
.screen-figure:is(:fullscreen, .is-expanded) .screen-caption { color: #a1b6c3; }
.screen-figure.is-expanded { position: fixed; inset: 0; z-index: 8; }
#feed { flex: 1; min-height: 0; overflow-y: auto; padding: .45rem clamp(.85rem, 2.2vw, 1.8rem) 1rem; scrollbar-width: thin; }
#feed[data-ready]:empty::before { content: "Сообщений пока нет"; color: var(--muted); }
.message { display: grid; grid-template-columns: 34px minmax(0, 1fr); gap: .65rem; margin: 0 0 1rem; overflow-wrap: anywhere; }
.message > .avatar { width: 34px; height: 34px; margin-top: .08rem; }
.message-body { min-width: 0; }
.message-meta { display: flex; align-items: baseline; flex-wrap: wrap; gap: .15rem .65rem; }
.message p { margin: .12rem 0 0; white-space: pre-wrap; }
.message-attachment { display: grid; justify-items: start; gap: .35rem; margin-top: .4rem; }
.message-attachment img, .message-attachment video { display: block; max-width: min(100%, 505px); max-height: 340px; border: 1px solid var(--line); border-radius: .6rem; }
.message-attachment audio { max-width: 100%; }
.attachment-link {
  display: flex; align-items: center; gap: .6rem; min-width: min(240px, 100%); max-width: 100%;
  padding: .48rem .65rem; border: 1px solid var(--line); border-radius: .5rem; background: var(--surface);
  color: var(--text); font-size: .84rem; font-weight: 600; text-decoration: none;
}
.attachment-link:hover { border-color: var(--active-line); background: var(--raised); }
.attachment-link > span:first-child { color: var(--accent); font-size: 1rem; }
.attachment-link small { display: block; color: var(--muted); font-weight: 400; }
#composer {
  display: flex; align-items: stretch; gap: .45rem; padding: .7rem clamp(.85rem, 2.2vw, 1.8rem);
  padding-bottom: max(.7rem, env(safe-area-inset-bottom)); border-top: 1px solid var(--line); background: var(--surface);
}
.attach { position: relative; display: grid; place-items: center; flex: 0 0 38px; padding: 0; color: var(--muted); }
.attach svg { width: 18px; height: 18px; }
.attach input, .avatar-upload input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.attach:focus-within, .avatar-upload:focus-within { outline: 2px solid var(--accent); }
#notice { position: fixed; bottom: 1rem; right: 1rem; z-index: 6; max-width: min(440px, 90vw); padding: .65rem .85rem; background: var(--raised); border: 1px solid var(--active-line); border-radius: .6rem; }

dialog {
  width: min(440px, calc(100% - 2rem)); max-height: calc(100dvh - 2rem); padding: 1.35rem; color: inherit;
  background: var(--surface); border: 1px solid var(--line); border-radius: .85rem;
}
dialog::backdrop { background: var(--scrim); }
.dialog-heading, .profile-photo { display: flex; align-items: center; gap: .75rem; }
.dialog-heading { justify-content: space-between; margin-bottom: .9rem; }
.dialog-heading h2, #password-form h3 { margin: 0; font-size: 1.08rem; }
.dialog-heading button { padding: .13rem .6rem; font-size: 1.25rem; }
.profile-photo .avatar { width: 52px; height: 52px; font-size: 1.25rem; }
#nickname-form, #password-form, #profile-email-form, #room-delete-form { display: grid; gap: .55rem; margin-top: .9rem; padding-top: .75rem; border-top: 1px solid var(--line); }
#profile-dialog label:not(.avatar-upload), #room-delete-form label { display: grid; gap: .25rem; }
.room-dialog-info, .room-fields, .room-fields label { display: grid; gap: .55rem; }
.room-dialog-info { justify-items: start; min-width: 0; overflow-wrap: anywhere; }
#room-settings-form { margin-top: 1rem; }
.room-fields textarea { resize: vertical; min-height: 5rem; max-height: 32vh; }
#room-settings-form button, #room-delete-form button, #nickname-form button, #password-form button, #profile-email-form button { justify-self: start; }
#room-delete-form p, #profile-login { margin: 0; color: var(--muted); font-size: .85rem; }
#room-settings-status, #create-room-status, #profile-feedback, #admin-status, #users-status { margin: .45rem 0 0; color: var(--accent); }
button.danger { background: var(--danger-bg); color: var(--danger); }
#profile-roles, #verified-email { margin: .4rem 0; color: var(--muted); font-size: .875rem; }
#profile-login, #auth-status, #recovery-status, #verification-status, #verified-email { overflow-wrap: anywhere; }
#auth-status, #recovery-status, #verification-status { color: var(--muted); }
#logout { margin-top: 1rem; }
.avatar-upload { position: relative; cursor: pointer; color: var(--accent); padding: .5rem .65rem; border: 1px solid var(--line); border-radius: .5rem; }
.admin-sections form { display: grid; gap: .55rem; align-content: start; }
.admin-sections form > label { display: grid; gap: .25rem; }
.admin-sections fieldset { margin: 0; min-width: 0; border: 1px solid var(--line); border-radius: .55rem; padding: .5rem .65rem; }
.admin-sections legend { color: var(--muted); padding-inline: .25rem; font-size: .88rem; }
.admin-sections fieldset label { display: flex; align-items: center; gap: .45rem; padding-block: .15rem; }
.admin-sections input[type="checkbox"] { width: auto; flex: 0 0 auto; accent-color: var(--accent); }
.admin-sections button { justify-self: start; }
.admin-actions { display: flex; flex-wrap: wrap; gap: .35rem; }
#users-dialog { width: min(1080px, calc(100% - 2rem)); }
.users-toolbar, .users-views, #user-matrix-search, .users-pagination { display: flex; align-items: center; gap: .45rem; }
.users-toolbar { justify-content: space-between; flex-wrap: wrap; margin-bottom: .75rem; }
.users-views { flex-wrap: wrap; }
.users-views button[aria-pressed="true"] { background: var(--active); border-color: var(--active-line); color: var(--accent); }
#user-matrix-search { flex: 0 1 290px; }
.users-table-wrap { overflow: auto; max-height: min(58dvh, 565px); border: 1px solid var(--line); border-radius: .6rem; scrollbar-width: thin; }
#users-table { width: 100%; border-spacing: 0; font-size: .85rem; }
#users-table th, #users-table td { padding: .57rem .65rem; border-bottom: 1px solid var(--line); text-align: left; }
#users-table thead th { position: sticky; top: 0; z-index: 2; background: var(--raised); color: var(--text); }
#users-table tr:last-child td, #users-table tbody tr:last-child th { border-bottom: 0; }
#users-table th[scope="row"] { font-weight: 650; min-width: 120px; }
#users-table .account-login { display: block; color: var(--muted); font-weight: 400; }
#users-table .role-cell { text-align: center; min-width: 94px; }
#users-table input[type="checkbox"] { width: 1.05rem; height: 1.05rem; margin: 0; accent-color: var(--accent); vertical-align: middle; }
#users-table td, #users-table th { overflow-wrap: anywhere; }
#users-table button { white-space: nowrap; font-size: .78rem; }
.users-pagination { margin-top: .75rem; }
#users-page { flex: 1; color: var(--muted); font-size: .8rem; }

@media (max-width: 680px) {
  #workspace { grid-template-columns: minmax(0, 1fr); }
  #sidebar { display: none; position: fixed; inset: 0 auto 0 0; width: min(295px, calc(100% - 44px)); z-index: 5; }
  #workspace[data-sidebar-open] #sidebar { display: flex; }
  #workspace[data-sidebar-open] #rooms-backdrop { display: block; position: fixed; inset: 0; z-index: 4; border: 0; border-radius: 0; background: var(--scrim); }
  #open-rooms, #close-rooms { display: grid; }
  .channel-header { gap: .45rem; min-height: 56px; }
  .header-room-avatar { display: none; }
  .channel-header h1 { font-size: 1.04rem; }
  #share-source { max-width: 100px; font-size: .68rem; padding-inline: .2rem; }
  #share { font-size: .74rem; max-width: 100px; padding-inline: .3rem; }
  #share-quality { max-width: 94px; font-size: .68rem; padding-inline: .2rem; }
  #voice-status { font-size: .70rem; }
  .message { gap: .45rem; }
  #users-dialog { width: calc(100% - 1rem); padding: .8rem; }
  #users-table th[scope="row"] { min-width: 95px; }
}
.site-version {
  margin: 6px 0 0;
  font-size: 12px;
  opacity: .7;
}
