:root {
  color-scheme: dark;
  --bg: #080b12;
  --panel: #111724;
  --panel-2: #171f2f;
  --line: #263248;
  --text: #f5f7fb;
  --muted: #9aa9c0;
  --accent: #6ee7c2;
  --danger: #ff5b6e;
}

* { box-sizing: border-box; }
html { background: var(--bg); }
body {
  margin: 0;
  min-height: 100vh;
  background: radial-gradient(circle at 20% 0, #18233c 0, transparent 38%), var(--bg);
  color: var(--text);
  font: 15px/1.45 Inter, ui-sans-serif, system-ui, -apple-system, sans-serif;
}
a { color: inherit; }
label { display: block; color: var(--muted); font-weight: 650; margin: .8rem 0; }
input, select, textarea { width: 100%; margin-top: .4rem; background: #080d17; color: var(--text); border: 1px solid var(--line); border-radius: 10px; padding: .8rem; outline: none; }
input:focus, select:focus, textarea:focus { border-color: var(--accent); }
button, input, select, textarea { font: inherit; }
button, .file, nav button, .card { transition: transform .16s ease, background .16s ease, border-color .16s ease, opacity .16s ease; }
button {
  border: 0;
  border-radius: 10px;
  background: var(--accent);
  color: #04251b;
  font-weight: 800;
  padding: .75rem 1rem;
  cursor: pointer;
}
button:hover { background: #8af0d1; transform: translateY(-1px); }
button:active { transform: translateY(1px) scale(.97); }
button:focus-visible, input:focus-visible, select:focus-visible, textarea:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: .45; cursor: not-allowed; transform: none; }
.secondary { background: #222d40; color: var(--text); border: 1px solid var(--line); }
.secondary:hover { background: #2c3950; }
.hidden { display: none !important; }
.brand { display: inline-grid; place-items: center; background: var(--accent); color: #03261c; font-weight: 900; border-radius: 8px; padding: .25rem .5rem; margin-right: .6rem; }
.muted { color: var(--muted); }
.site-nav { height: 72px; max-width: 1240px; margin: auto; padding: 0 24px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; }
.site-nav > div { display: flex; align-items: center; gap: .65rem; }
.site-brand { text-decoration: none; display: flex; align-items: center; }
.eyebrow { color: var(--accent); font-size: .72rem; font-weight: 900; letter-spacing: .14em; }

.landing { max-width: 1120px; margin: auto; padding: 5vh 24px 10vh; animation: enter .35s ease both; }
.landing > header { text-align: center; margin-bottom: 2.5rem; }
.landing h1 { font-size: clamp(2.35rem, 7vw, 4.6rem); line-height: 1.02; letter-spacing: -.045em; margin: .8rem 0 1rem; }
.landing h1 span { color: var(--accent); }
.landing header p { color: var(--muted); font-size: 1.1rem; }
.cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 20px; }
.card { background: rgba(17,23,36,.92); border: 1px solid var(--line); border-radius: 18px; padding: 24px; box-shadow: 0 20px 60px #0005; }
.card:hover { border-color: #3a4a67; transform: translateY(-2px); }
.card h2 { margin-top: 0; }
.card label { display: block; margin: 1rem 0; color: var(--muted); font-weight: 650; }
.card input, .card select, .composer textarea, .search input {
  display: block; width: 100%; margin-top: .4rem; background: #080d17; color: var(--text);
  border: 1px solid var(--line); border-radius: 10px; padding: .8rem; outline: none;
}
.card input:focus, .card select:focus, .composer textarea:focus, .search input:focus { border-color: var(--accent); }
.card button { width: 100%; }
.card-icon { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 12px; background: #17362f; color: var(--accent); font-size: 1.4rem; font-weight: 900; }
.hint, .muted { color: var(--muted); font-size: .85rem; }
.error { background: #3b1520; border: 1px solid var(--danger); padding: 1rem; border-radius: 10px; margin-top: 1rem; }
.critical { position: fixed; inset: 0; z-index: 9999; background: #470713; color: white; display: flex; flex-direction: column; align-items: center; justify-content: center; text-align: center; padding: 2rem; }
.critical strong { font-size: clamp(2rem,6vw,5rem); max-width: 1100px; }
.critical span { font-size: 1.2rem; margin-top: 1rem; }

.room { height: 100vh; display: flex; flex-direction: column; animation: enter .25s ease both; }
.topbar { min-height: 64px; display: flex; align-items: center; justify-content: space-between; padding: 10px 18px; background: #0d1320; border-bottom: 1px solid var(--line); gap: 1rem; }
.room-stats { display: flex; gap: 1rem; color: var(--muted); font-variant-numeric: tabular-nums; }
.room-title, .top-actions { display: flex; align-items: center; gap: .5rem; }
.presence-button { padding: .35rem .65rem; font-weight: 700; }
.layout { display: grid; grid-template-columns: 260px 1fr; min-height: 0; flex: 1; }
.sidebar { background: #0d1320; border-right: 1px solid var(--line); padding: 16px; overflow-y: auto; }
.sidebar section { margin-bottom: 1.5rem; }
.section-title { display: flex; justify-content: space-between; align-items: center; color: var(--muted); font-weight: 800; text-transform: uppercase; font-size: .75rem; letter-spacing: .08em; }
.section-title button { padding: .2rem .5rem; background: transparent; color: var(--muted); font-size: 1.2rem; }
nav button { display: block; width: 100%; text-align: left; background: transparent; color: var(--muted); padding: .55rem .7rem; margin: .2rem 0; font-weight: 600; }
nav button.active, nav button:hover { background: var(--panel-2); color: var(--text); transform: translateX(2px); }
.share, .limits { border-top: 1px solid var(--line); padding-top: 1rem; }
.share h3, .limits h3 { font-size: .8rem; color: var(--muted); }
.share button { width: 100%; font-size: .8rem; }
.limits p { font-size: .75rem; color: var(--muted); }
.limits #limit-details { color: var(--accent); font-weight: 800; }
.code { font: 700 .8rem ui-monospace, monospace; margin-bottom: .6rem; color: var(--accent); overflow-wrap: anywhere; }

.content { min-width: 0; min-height: 0; }
.chat-view, .files-view { height: 100%; display: flex; flex-direction: column; animation: page-in .2s ease both; }
.chat-head { min-height: 58px; border-bottom: 1px solid var(--line); padding: 0 20px; display: flex; align-items: center; }
.chat-head h2 { font-size: 1rem; }
.messages { flex: 1; overflow-y: auto; padding: 20px; scroll-behavior: smooth; }
.message { max-width: 850px; padding: .65rem .8rem; margin: .35rem 0; border-radius: 12px; background: var(--panel); animation: message-in .2s ease both; }
.message .meta { font-size: .75rem; color: var(--muted); margin-bottom: .25rem; }
.message .body { white-space: pre-wrap; overflow-wrap: anywhere; }
.message .reply { border-left: 2px solid var(--accent); padding-left: .5rem; color: var(--muted); font-size: .8rem; }
.actions { display: flex; gap: .3rem; margin-top: .4rem; opacity: .65; flex-wrap: wrap; }
.actions button { background: transparent; color: var(--muted); padding: .2rem; font-size: .75rem; }
.reactions button { background: #253249; color: var(--text); padding: .15rem .4rem; margin: .25rem .2rem 0 0; font-size: .75rem; }
.composer { display: flex; gap: 10px; padding: 14px; border-top: 1px solid var(--line); background: #0d1320; }
.composer textarea { resize: none; margin: 0; }
.reply-box { padding: .5rem 1rem; background: #182336; color: var(--muted); }

.file-tools { display: flex; gap: 14px; align-items: center; padding: 14px 20px 0; }
.search { display: flex; align-items: center; flex: 1; max-width: 560px; background: #080d17; border: 1px solid var(--line); border-radius: 11px; padding-left: .8rem; color: var(--muted); }
.search input { border: 0; margin: 0; background: transparent; }
.upload { display: flex; gap: 10px; padding: 14px 20px; }
.upload input { flex: 1; min-width: 0; background: var(--panel); padding: .7rem; border-radius: 10px; }
.files-view progress { width: calc(100% - 40px); margin: 0 20px; accent-color: var(--accent); }
.file-list { padding: 10px 20px 20px; overflow-y: auto; }
.file { display: grid; grid-template-columns: minmax(0,1fr) auto; align-items: center; gap: 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 1rem; margin-bottom: .6rem; animation: file-in .25s ease both; animation-delay: var(--delay); }
.file:hover { border-color: #3b4d6c; background: #141c2b; }
.file strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.file small { display: block; color: var(--muted); margin-top: .2rem; }
.file-actions { display: flex; gap: .5rem; }
.file-actions a { text-decoration: none; }
.empty { color: var(--muted); text-align: center; padding: 4rem 1rem; }

.preview-modal { width: min(1100px, 94vw); height: min(820px, 92vh); padding: 0; border: 1px solid var(--line); border-radius: 18px; background: #0b101b; color: var(--text); box-shadow: 0 30px 100px #000b; overflow: hidden; animation: modal-in .2s ease both; }
.preview-modal::backdrop { background: #02050bd9; backdrop-filter: blur(6px); }
.preview-head { min-height: 64px; display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: 12px 16px; border-bottom: 1px solid var(--line); }
.preview-head strong, .preview-head span { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preview-head > div { min-width: 0; }
.preview-head span { color: var(--muted); font-size: .75rem; }
.icon-button { background: transparent; color: var(--text); font-size: 1.8rem; padding: .2rem .65rem; }
.preview-content { height: calc(100% - 64px); display: grid; place-items: center; overflow: auto; }
.preview-content img { max-width: 100%; max-height: 100%; object-fit: contain; }
.preview-content audio { width: min(680px, 90%); }
.pdf-viewer { width: 100%; height: 100%; display: flex; flex-direction: column; background: #161b24; }
.pdf-tools { min-height: 54px; display: flex; align-items: center; justify-content: center; gap: 1rem; padding: 8px; background: #0d1320; border-bottom: 1px solid var(--line); }
.pdf-tools button { padding: .5rem .8rem; }
.pdf-stage { flex: 1; min-height: 0; overflow: auto; padding: 20px; text-align: center; }
.pdf-stage canvas { background: white; box-shadow: 0 8px 30px #0008; max-width: 100%; height: auto; }
.preview-loading { position: absolute; inset: 64px 0 0; display: grid; place-items: center; color: var(--muted); pointer-events: none; }
.toast { position: fixed; z-index: 10000; right: 20px; bottom: 20px; background: #202c40; border: 1px solid var(--line); border-radius: 10px; padding: 1rem; box-shadow: 0 10px 40px #0008; animation: toast-in .2s ease both; }

.dashboard { max-width: 1240px; margin: auto; padding: 5vh 24px 10vh; animation: enter .3s ease both; }
.dashboard-head { display: flex; justify-content: space-between; align-items: end; gap: 2rem; margin-bottom: 2rem; }
.dashboard-head h1 { margin: .5rem 0 .2rem; font-size: clamp(2rem,5vw,3.4rem); letter-spacing: -.04em; }
.dashboard-head p { color: var(--muted); margin: 0; }
.head-actions { display: flex; gap: .6rem; flex-wrap: wrap; }
.dashboard-grid { display: grid; grid-template-columns: 2fr 1fr; gap: 18px; }
.card.compact { padding: 20px; display: grid; grid-template-columns: 1fr 1fr auto; align-items: end; gap: 12px; }
.card.compact h2 { grid-column: 1/-1; margin-bottom: 0; }
.card.compact label { margin: 0; }
.metric-card { min-height: 170px; border: 1px solid var(--line); border-radius: 18px; padding: 24px; background: linear-gradient(145deg,#173a32,#101925); display: flex; flex-direction: column; justify-content: center; }
.metric-card span { font-size: 3rem; color: var(--accent); font-weight: 900; line-height: 1; }
.metric-card p { color: var(--muted); margin-bottom: 0; }
.dashboard-section { margin-top: 2.5rem; }
.section-heading { display: flex; justify-content: space-between; align-items: center; }
.room-grid { display: grid; grid-template-columns: repeat(auto-fill,minmax(270px,1fr)); gap: 14px; }
.room-card { border: 1px solid var(--line); border-radius: 16px; padding: 18px; background: var(--panel); }
.room-card h3 { font-size: 1.15rem; margin: .8rem 0 .25rem; }
.room-card p { color: var(--muted); min-height: 42px; font-size: .85rem; }
.room-card button { width: 100%; }
.role-badge { display: inline-block; border-radius: 999px; padding: .25rem .55rem; font-size: .7rem; font-weight: 800; background: #243146; color: var(--muted); }
.role-badge.owner { background: #193d34; color: var(--accent); }
.role-badge.admin { background: #302b52; color: #c5b8ff; }
.invite-list { display: grid; gap: 10px; }
.invite-row { display: flex; align-items: center; justify-content: space-between; gap: 1rem; background: var(--panel); border: 1px solid var(--line); border-radius: 13px; padding: 14px; }
.invite-row p { margin: .2rem 0 0; color: var(--muted); }
.invite-row > div:last-child { display: flex; gap: .5rem; }

.modal { width: min(470px,94vw); border: 1px solid var(--line); border-radius: 18px; padding: 0; background: #0d1320; color: var(--text); box-shadow: 0 30px 100px #000c; }
.modal-wide { width: min(900px,95vw); max-height: 92vh; }
.modal::backdrop { background: #02050bd9; backdrop-filter: blur(7px); }
.modal-head { display: flex; align-items: center; justify-content: space-between; padding: 20px 22px; border-bottom: 1px solid var(--line); }
.modal-head h2 { margin: .25rem 0 0; }
.modal-body { padding: 22px; overflow-y: auto; }
.modal-body form > button { width: 100%; margin-top: .5rem; }
.auth-links { display: flex; justify-content: space-between; margin-top: 1rem; }
.text-button { padding: .25rem; background: transparent; color: var(--accent); font-weight: 650; }
.recovery-code, .secret-result code { display: block; padding: 1rem; margin: 1rem 0; border: 1px dashed var(--accent); border-radius: 10px; background: #07110f; color: var(--accent); overflow-wrap: anywhere; user-select: all; }
.manage-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 26px; }
.manage-grid section { min-width: 0; }
.manage-grid h3 { margin-top: 0; }
.span-2 { grid-column: 1/-1; }
.inline-fields { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.member-list, .session-list { display: grid; gap: 8px; }
.member-row { display: flex; justify-content: space-between; align-items: center; gap: 1rem; border: 1px solid var(--line); border-radius: 11px; padding: .75rem; background: var(--panel); }
.member-row strong, .member-row small { display: block; }
.member-row small { color: var(--muted); margin-top: .15rem; }
.tiny { padding: .45rem .65rem; font-size: .75rem; }
.online-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 12px var(--accent); margin-right: auto; }
.danger-zone { border-top: 1px solid #5b2630; padding-top: 20px; }
.danger-zone h3 { color: #ff8795; }
.danger { background: #7d1f2d; color: white; }
.danger:hover { background: #9e2738; }
.hold-button { width: 100%; position: relative; overflow: hidden; isolation: isolate; }
.hold-button span { position: relative; z-index: 2; }
.hold-button i { position: absolute; z-index: 1; inset: 0; width: var(--hold,0%); background: #d83d51; transition: width .05s linear; }
.secret-result { margin-top: 1rem; }

@keyframes enter { from { opacity: 0; transform: translateY(8px); } }
@keyframes page-in { from { opacity: 0; transform: translateX(6px); } }
@keyframes message-in { from { opacity: 0; transform: translateY(4px); } }
@keyframes file-in { from { opacity: 0; transform: translateY(6px); } }
@keyframes modal-in { from { opacity: 0; transform: scale(.98); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; scroll-behavior: auto !important; } }
@media (max-width: 720px) {
  .site-nav { height: auto; min-height: 68px; padding: 10px 14px; }
  .site-nav #guest-nav button:first-child, #nav-username { display: none; }
  .topbar { height: auto; flex-wrap: wrap; }
  .room-stats { order: 3; width: 100%; justify-content: space-between; font-size: .7rem; overflow-x: auto; }
  .layout { grid-template-columns: 106px minmax(0,1fr); }
  .sidebar { padding: 8px; }
  .share, .limits { display: none; }
  .section-title span { font-size: .65rem; }
  .file { grid-template-columns: 1fr; }
  .file-actions { width: 100%; }
  .file-actions > * { flex: 1; }
  .file-actions button { width: 100%; }
  .landing { padding-top: 4vh; }
  .upload { flex-direction: column; }
  .preview-modal { width: 100vw; height: 100vh; max-width: none; max-height: none; border-radius: 0; }
  .dashboard { padding: 3vh 14px 8vh; }
  .dashboard-head { align-items: start; flex-direction: column; }
  .dashboard-grid, .manage-grid { grid-template-columns: 1fr; }
  .card.compact { grid-template-columns: 1fr; }
  .card.compact h2, .span-2 { grid-column: auto; }
  .invite-row { align-items: stretch; flex-direction: column; }
}
