:root {
  --bg: #12090f;
  --panel: rgba(28, 15, 24, 0.86);
  --panel-2: rgba(39, 23, 33, 0.92);
  --line: rgba(191, 124, 53, 0.35);
  --accent: #ff9a3d;
  --accent-2: #7d3cff;
  --accent-3: #5aff95;
  --text: #f7e8da;
  --muted: #cfb49c;
  --danger: #ff6f7d;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at top, rgba(125, 60, 255, 0.22), transparent 30%),
    radial-gradient(circle at bottom right, rgba(90, 255, 149, 0.13), transparent 30%),
    linear-gradient(180deg, #1b0b11, #0f0710);
}
button, input { font: inherit; }
body { min-height: 100vh; }

.login-overlay {
  position: fixed; inset: 0; display: grid; place-items: center;
  background: rgba(7, 3, 7, 0.62); backdrop-filter: blur(8px); z-index: 20; padding: 16px;
}
.login-card {
  position: relative;
  width: min(460px, 100%);
  background: linear-gradient(180deg, rgba(37,21,31,.96), rgba(20,10,18,.96));
  border: 1px solid var(--line);
  border-radius: 24px;
  padding: 28px;
  box-shadow: 0 20px 60px rgba(0,0,0,.38), 0 0 40px rgba(125, 60, 255, .18);
}
.auth-badge {
  position: absolute; top: 18px; right: 18px; padding: 6px 10px; border-radius: 999px;
  background: rgba(125, 60, 255, .16); color: #d8c1ff; border: 1px solid rgba(125,60,255,.36);
  font-size: 12px; font-weight: 700; letter-spacing: .08em;
}
.login-card h1 { margin: 12px 0 8px; font-size: 34px; }
.login-card p { margin: 0 0 18px; color: var(--muted); }
.logo {
  width: 62px; height: 62px; display: grid; place-items: center;
  background: linear-gradient(180deg, rgba(125,60,255,.26), rgba(255,154,61,.18));
  border-radius: 18px; font-size: 30px; border: 1px solid var(--line);
}
.login-card form { display: grid; gap: 12px; }
input {
  width: 100%; border: 1px solid rgba(255,255,255,.08); background: rgba(255,255,255,.06); color: white;
  border-radius: 14px; padding: 13px 14px; outline: none;
}
input::placeholder { color: #af96a9; }
input:focus { border-color: rgba(255,154,61,.7); box-shadow: 0 0 0 4px rgba(255,154,61,.12); }
button {
  border: 0; background: linear-gradient(180deg, var(--accent), #b85a10); color: white;
  border-radius: 14px; padding: 12px 14px; cursor: pointer; font-weight: 700;
}
button:hover { filter: brightness(1.05); }

.app-shell { height: 100vh; display: grid; grid-template-rows: 64px 1fr; }
.topbar {
  display: flex; align-items: center; justify-content: space-between; padding: 0 16px;
  background: linear-gradient(180deg, rgba(88,36,14,.95), rgba(58,18,8,.95)); color: white; border-bottom: 1px solid rgba(255,154,61,.18);
}
.subtitle { margin-left: 8px; color: #f4dac0; font-size: 13px; }
.top-actions { display: flex; gap: 8px; }
.top-actions button { padding: 10px 12px; background: rgba(255,255,255,0.09); border: 1px solid rgba(255,255,255,.06); }

.layout { display: grid; grid-template-columns: 250px 1fr 280px; gap: 12px; padding: 12px; min-height: 0; }
.sidebar, .chat-panel {
  background: var(--panel); backdrop-filter: blur(8px); border: 1px solid var(--line);
  border-radius: 22px; min-height: 0; box-shadow: 0 10px 30px rgba(0,0,0,.24);
}
.sidebar { padding: 12px; display: grid; grid-template-rows: auto auto 1fr; }
.panel-title { font-weight: 700; margin-bottom: 10px; color: #ffc692; }
.create-room { display: grid; grid-template-columns: 1fr 44px; gap: 8px; margin-bottom: 10px; }
.room-list, .users-list { overflow: auto; display: grid; gap: 8px; align-content: start; }
.room-item, .user-item {
  padding: 12px 12px; background: var(--panel-2); border: 1px solid rgba(255,255,255,.05); border-radius: 14px; cursor: pointer;
}
.room-item { display: flex; justify-content: space-between; align-items: center; }
.room-item small { color: var(--muted); }
.room-item.active { background: rgba(255,154,61,.12); border-color: rgba(255,154,61,.4); font-weight: 700; }
.user-item small { display: block; color: var(--muted); margin-top: 4px; }
.user-line { display: flex; align-items: center; gap: 10px; }

.chat-panel { display: grid; grid-template-rows: auto 1fr auto; min-height: 0; }
.chat-head { padding: 16px; border-bottom: 1px solid var(--line); display: flex; justify-content: space-between; gap: 12px; align-items: center; }
.current-room { font-size: 28px; font-weight: 800; color: #ffbe77; }
.current-user, .legend { color: var(--muted); font-size: 13px; }
.messages { padding: 16px; overflow: auto; display: grid; gap: 10px; align-content: start; }
.message {
  background: rgba(255,255,255,.04); border: 1px solid rgba(255,255,255,.05); border-radius: 16px; padding: 12px 14px;
}
.message.system { border-style: dashed; color: #c9b3b3; background: rgba(255,255,255,.03); }
.message-row { display: flex; gap: 12px; }
.message-body-wrap { min-width: 0; flex: 1; }
.message-head { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin-bottom: 6px; }
.message-head strong { color: #ffcf9a; }
.message-head span { color: var(--muted); font-size: 12px; }
.message-text { white-space: pre-wrap; word-break: break-word; line-height: 1.45; }
.message-box { padding: 12px; border-top: 1px solid var(--line); display: grid; grid-template-columns: 1fr 140px; gap: 10px; }
.private-toast {
  position: fixed; right: 16px; bottom: 16px; max-width: 360px; background: #26121d; color: white;
  padding: 14px 16px; border-radius: 16px; box-shadow: 0 15px 40px rgba(0,0,0,.25); border: 1px solid rgba(125,60,255,.35);
}
.hidden { display: none !important; }

.auth-card { max-width: 460px; }
.auth-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin: 16px 0 12px; }
.auth-tab { background: rgba(255,255,255,.05); color: #ffc692; border: 1px solid rgba(255,255,255,.06); }
.auth-tab.active { background: linear-gradient(180deg, var(--accent), #b85a10); color: white; border-color: transparent; }
.auth-form { display: grid; gap: 12px; }
.auth-message { margin: 0 0 12px; padding: 10px 12px; border-radius: 12px; font-size: 14px; }
.auth-message.error { background: rgba(255,111,125,.12); color: #ff9ca5; border: 1px solid rgba(255,111,125,.22); }
.auth-message.success { background: rgba(90,255,149,.10); color: #94ffc6; border: 1px solid rgba(90,255,149,.2); }
.auth-hint { margin-top: 14px; color: var(--muted); font-size: 12px; }
.avatar {
  width: 38px; height: 38px; border-radius: 12px; display: grid; place-items: center; font-weight: 800;
  background: linear-gradient(180deg, rgba(125,60,255,.24), rgba(255,154,61,.18)); border: 1px solid rgba(255,255,255,.08); color: #fff0e1;
}
.avatar.large { width: 42px; height: 42px; border-radius: 14px; flex: 0 0 auto; }
.role-chip {
  padding: 4px 8px; border-radius: 999px; font-size: 11px; text-transform: uppercase; letter-spacing: .04em; font-weight: 700;
}
.role-chip.admin { background: rgba(125,60,255,.18); color: #d6c2ff; border: 1px solid rgba(125,60,255,.26); }
.role-chip.member { background: rgba(255,154,61,.12); color: #ffd2a8; border: 1px solid rgba(255,154,61,.2); }

@media (max-width: 980px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar.left, .sidebar.right {
    position: fixed; top: 76px; bottom: 12px; width: min(320px, calc(100vw - 24px)); z-index: 15;
    box-shadow: 0 18px 40px rgba(0,0,0,.18); transition: transform .25s ease;
  }
  .sidebar.left { left: 12px; transform: translateX(-120%); }
  .sidebar.right { right: 12px; transform: translateX(120%); }
  .sidebar.open { transform: translateX(0); }
}

@media (max-width: 640px) {
  .topbar { padding: 0 10px; }
  .subtitle, .legend { display: none; }
  .current-room { font-size: 22px; }
  .message-box { grid-template-columns: 1fr 100px; }
  .login-card { padding: 22px; }
  .login-card h1 { font-size: 28px; }
}
