:root {
  --bg: #0b1020;
  --panel: rgba(255, 255, 255, 0.06);
  --panel-2: rgba(255, 255, 255, 0.08);
  --border: rgba(255, 255, 255, 0.12);
  --text: rgba(255, 255, 255, 0.92);
  --muted: rgba(255, 255, 255, 0.62);
  --muted-2: rgba(255, 255, 255, 0.45);
  --accent: #5b8cff;
  --accent-2: #7c5cff;
  --danger: #ff4d6d;
  --success: #2dd4bf;
  --shadow: 0 24px 60px rgba(0, 0, 0, 0.35);
  --radius: 16px;
  --radius-sm: 12px;
  --transition: 160ms ease;
  --sidebar: 360px;
  --top: 64px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, Arial, "Noto Sans";
  background:
    radial-gradient(1200px 600px at 20% 0%, rgba(91, 140, 255, 0.25), transparent 60%),
    radial-gradient(900px 500px at 100% 20%, rgba(124, 92, 255, 0.22), transparent 55%),
    radial-gradient(900px 700px at 50% 120%, rgba(45, 212, 191, 0.12), transparent 55%),
    var(--bg);
  color: var(--text);
  overflow: hidden;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }

.hidden { display: none !important; }

/* Layout */
.app {
  height: 100vh;
  display: grid;
  grid-template-rows: var(--top) 1fr;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 18px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(to bottom, rgba(255,255,255,0.08), rgba(255,255,255,0.04));
  backdrop-filter: blur(10px);
}

.brand { display: flex; align-items: center; gap: 10px; }
.brand__logo {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 10px 20px rgba(91, 140, 255, 0.22);
}
.brand__title { font-weight: 700; letter-spacing: 0.2px; }
.brand__subtitle { font-size: 12px; color: var(--muted); margin-top: 1px; }

.topbar__right { display: flex; align-items: center; gap: 10px; }

.pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
  color: var(--muted);
  font-size: 13px;
}

.iconbtn {
  width: 40px;
  height: 40px;
  border: 1px solid var(--border);
  background: rgba(255, 255, 255, 0.06);
  border-radius: 12px;
  display: grid;
  place-items: center;
  transition: transform var(--transition), background var(--transition), border-color var(--transition);
}
.iconbtn:hover { background: rgba(255, 255, 255, 0.09); border-color: rgba(255, 255, 255, 0.18); }
.iconbtn:active { transform: scale(0.98); }

.main {
  display: grid;
  grid-template-columns: var(--sidebar) 1fr;
  height: calc(100vh - var(--top));
  min-height: 0;
}

@media (max-width: 760px) {
  body { overflow: auto; }
  .main { grid-template-columns: 1fr; height: auto; }

  .chat__back { display: grid; }

  /* 2-screen mobile UX */
  #root.is-chat-open .sidebar { display: none; }
  #root.is-chat-open .chat { display: grid; }
  #root:not(.is-chat-open) .chat { display: none; }
}

/* Sidebar */
.sidebar {
  border-right: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  backdrop-filter: blur(10px);
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto 1fr;
}

.sidebar__header {
  padding: 14px 14px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.profile {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 14px;
  background: linear-gradient(135deg, rgba(255,255,255,0.2), rgba(255,255,255,0.06));
  border: 1px solid var(--border);
  display: grid;
  place-items: center;
  flex: 0 0 auto;
}

 .avatar--chat {
   position: relative;
   overflow: hidden;
 }

 .avatar__dot {
   position: absolute;
   right: -2px;
   bottom: -2px;
   width: 12px;
   height: 12px;
   border-radius: 999px;
   border: 2px solid rgba(20, 26, 44, 0.96);
   background: rgba(255,255,255,0.35);
 }

 .avatar__dot.is-online {
   background: var(--success);
 }

.profile__meta { min-width: 0; }
.profile__name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.profile__status { font-size: 12px; color: var(--muted); }

.sidebar__actions { display: flex; gap: 8px; }

.sidebar__search {
  padding: 0 14px 12px;
}

.search {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: rgba(255,255,255,0.06);
}
.search input {
  background: transparent;
  border: 0;
  outline: none;
  width: 100%;
  color: var(--text);
}
.search input::placeholder { color: var(--muted-2); }

.sidebar__list {
  overflow: auto;
  padding: 8px;
}

.card {
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.05);
  border-radius: var(--radius);
  box-shadow: 0 12px 30px rgba(0,0,0,0.18);
}

.list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.item {
  display: grid;
  grid-template-columns: 40px 1fr auto;
  gap: 10px;
  padding: 10px;
  border-radius: 14px;
  transition: background var(--transition), border-color var(--transition);
  border: 1px solid transparent;
  background: transparent;
  color: var(--text);
  text-align: left;
  appearance: none;
}
.item:hover { background: rgba(255,255,255,0.06); }
.item.is-active { border-color: rgba(91,140,255,0.45); background: rgba(91,140,255,0.12); }
.item:focus-visible { outline: 2px solid rgba(91,140,255,0.55); outline-offset: 2px; }
.item__title { font-weight: 700; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item__sub { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.item__time { font-size: 12px; color: var(--muted-2); padding-top: 2px; }

 .badge {
   min-width: 18px;
   height: 18px;
   padding: 0 6px;
   border-radius: 999px;
   display: inline-flex;
   align-items: center;
   justify-content: center;
   font-size: 11px;
   font-weight: 900;
   color: rgba(255,255,255,0.95);
   background: linear-gradient(135deg, var(--accent), var(--accent-2));
   border: 1px solid rgba(255,255,255,0.14);
   box-shadow: 0 12px 24px rgba(91, 140, 255, 0.16);
 }

/* Chat */
.chat {
  min-height: 0;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.chat__header {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  backdrop-filter: blur(10px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.chat__title { min-width: 0; }
.chat__name { font-weight: 800; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.chat__meta { font-size: 12px; color: var(--muted); }
 .chat__typing { font-size: 12px; color: rgba(255,255,255,0.78); }

.chat__actions { display: flex; gap: 8px; }

 .chat__back {
   display: none;
 }

.messages {
  overflow: auto;
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.bubble {
  max-width: min(680px, 78%);
  padding: 10px 12px;
  border-radius: 16px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
}
.bubble--own {
  margin-left: auto;
  background: linear-gradient(135deg, rgba(91,140,255,0.35), rgba(124,92,255,0.24));
  border-color: rgba(91,140,255,0.4);
}
.bubble__meta {
  display: flex;
  align-items: baseline;
  gap: 10px;
  margin-bottom: 6px;
}
.bubble__author { font-weight: 800; font-size: 12px; color: rgba(255,255,255,0.92); }
.bubble__time { font-size: 11px; color: rgba(255,255,255,0.55); }
.bubble__text { white-space: pre-wrap; word-break: break-word; font-size: 13px; line-height: 1.35; }

.composer {
  padding: 14px 16px;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,0.04);
  backdrop-filter: blur(10px);
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  position: relative;
}

.textarea {
  width: 100%;
  min-height: 44px;
  max-height: 140px;
  resize: none;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  outline: none;
}
.textarea::placeholder { color: var(--muted-2); }

.primary {
  height: 44px;
  padding: 0 14px;
  border-radius: 14px;
  border: 1px solid rgba(91, 140, 255, 0.55);
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  box-shadow: 0 14px 30px rgba(91, 140, 255, 0.18);
  transition: transform var(--transition), filter var(--transition);
}
.primary:hover { filter: brightness(1.05); }
.primary:active { transform: scale(0.98); }
.primary:disabled { opacity: 0.55; cursor: not-allowed; }

 .emoji {
   position: absolute;
   right: 16px;
   bottom: calc(100% + 10px);
   width: min(360px, calc(100vw - 32px));
   border: 1px solid var(--border);
   background: rgba(20, 26, 44, 0.96);
   backdrop-filter: blur(10px);
   border-radius: 18px;
   box-shadow: var(--shadow);
   padding: 10px;
   display: none;
 }

 .emoji.is-open {
   display: block;
 }

 .emoji__head {
   display: flex;
   align-items: center;
   justify-content: space-between;
   gap: 10px;
   padding: 4px 4px 10px;
 }

 .emoji__title {
   font-weight: 900;
   font-size: 13px;
 }

 .emoji__section {
   padding: 0 4px 10px;
 }

 .emoji__search {
   padding: 0 4px 10px;
 }

 .emoji__search input {
   width: 100%;
   height: 40px;
   border-radius: 14px;
   border: 1px solid var(--border);
   background: rgba(255,255,255,0.06);
   outline: none;
   padding: 0 12px;
 }

 .emoji__search input::placeholder { color: var(--muted-2); }

 .emoji__tabs {
   display: grid;
   grid-template-columns: repeat(5, 1fr);
   gap: 6px;
   padding: 0 4px 10px;
 }

 .emoji__tab {
   height: 34px;
   border-radius: 12px;
   border: 1px solid var(--border);
   background: rgba(255,255,255,0.06);
   color: var(--text);
   transition: background var(--transition), border-color var(--transition);
 }

 .emoji__tab:hover { background: rgba(255,255,255,0.10); }
 .emoji__tab.is-active { border-color: rgba(91,140,255,0.45); background: rgba(91,140,255,0.14); }

 .emoji__label {
   font-size: 12px;
   color: var(--muted);
   margin: 6px 0 8px;
 }

 .emoji__grid {
   display: grid;
   grid-template-columns: repeat(8, 1fr);
   gap: 6px;
 }

 .emoji__btn {
   height: 36px;
   border-radius: 12px;
   border: 1px solid var(--border);
   background: rgba(255,255,255,0.06);
   display: grid;
   place-items: center;
   font-size: 18px;
   transition: transform var(--transition), background var(--transition);
 }

 .emoji__btn:hover {
   background: rgba(255,255,255,0.10);
 }

 .emoji__btn:active {
   transform: scale(0.98);
 }

 @media (max-width: 420px) {
   .emoji__grid { grid-template-columns: repeat(7, 1fr); }
 }

/* Auth */
.auth {
  height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}

.auth__card {
  width: min(420px, 100%);
  border: 1px solid var(--border);
  border-radius: 20px;
  background: rgba(255,255,255,0.06);
  backdrop-filter: blur(10px);
  box-shadow: var(--shadow);
  padding: 18px;
}

.tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 14px; }
.tab {
  height: 42px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  transition: background var(--transition), border-color var(--transition);
}
.tab.is-active { background: rgba(91,140,255,0.16); border-color: rgba(91,140,255,0.45); }

.field { display: grid; gap: 8px; margin-top: 12px; }
.label { font-size: 12px; color: var(--muted); }
.input {
  height: 44px;
  padding: 0 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
  outline: none;
}
.input::placeholder { color: var(--muted-2); }

.link { color: rgba(91,140,255,0.95); text-decoration: none; font-weight: 700; font-size: 13px; }
.link:hover { text-decoration: underline; }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0,0,0,0.55);
}
.modal.is-open { display: flex; }
.modal__dialog {
  width: min(520px, 100%);
  border-radius: 18px;
  border: 1px solid var(--border);
  background: rgba(20, 26, 44, 0.92);
  box-shadow: var(--shadow);
  overflow: hidden;
}
.modal__head {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--border);
}
.modal__title { font-weight: 900; font-size: 14px; }
.modal__body { padding: 16px; color: var(--muted); font-size: 13px; }
.modal__actions { padding: 14px 16px; display: flex; justify-content: flex-end; gap: 10px; border-top: 1px solid var(--border); }

.ghost {
  height: 40px;
  padding: 0 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
}
.danger {
  border-color: rgba(255,77,109,0.5);
  background: rgba(255,77,109,0.12);
}

/* Toasts */
.toasts {
  position: fixed;
  right: 14px;
  top: 14px;
  display: grid;
  gap: 10px;
  z-index: 9999;
}
.toast {
  border: 1px solid var(--border);
  background: rgba(20, 26, 44, 0.92);
  backdrop-filter: blur(10px);
  border-radius: 16px;
  padding: 10px 12px;
  box-shadow: 0 18px 45px rgba(0,0,0,0.28);
  display: flex;
  gap: 10px;
  align-items: flex-start;
}
.toast__title { font-weight: 900; font-size: 12px; }
.toast__msg { font-size: 12px; color: var(--muted); margin-top: 2px; }
.toast__close {
  margin-left: auto;
  width: 30px;
  height: 30px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: rgba(255,255,255,0.06);
}
.toast__close:hover { background: rgba(255,255,255,0.09); }
