/* ===== RESET ===== */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

/* ===== BASE ===== */
body {
  font-family: "Segoe UI", system-ui, Arial, sans-serif;
  background: #0a0a0a;
  color: #eaeaea;
  height: 100vh;
  overflow: hidden;
}

/* ===== LAYOUT ===== */
.shell {
  display: flex;
  height: 100vh;
}

/* ===== SIDEBAR (PC) ===== */
.sidebar {
  width: 80px;
  background: #0f0f0f;
  border-right: 1px solid #1f1f1f;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 16px 0;
  gap: 16px;
}

.logo {
  font-weight: bold;
  margin-bottom: 20px;
}

.side-btn {
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: transparent;
  border: none;
  color: #aaa;
  font-size: 18px;
  cursor: pointer;
}

.side-btn:hover {
  background: #1f1f1f;
  color: #fff;
}

/* ===== APP ===== */
.app {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: #0b0b0b;
  height: 100vh;
  overflow: hidden;
}

/* ===== HEADER ===== */
.chat-header {
  padding: 14px 18px;
  border-bottom: 1px solid #1f1f1f;
  display: flex;
  justify-content: space-between;
  align-items: center;
  position: sticky;
  top: 0;
  z-index: 5;
  background: #0b0b0b;
}

.title {
  font-size: 15px;
  font-weight: 600;
}

.subtitle {
  font-size: 11px;
  color: #9e9e9e;
}

.header-actions {
  display: flex;
  gap: 8px;
}

.header-actions button {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: #1a1a1a;
  border: 1px solid #333;
  color: #ccc;
  cursor: pointer;
}

.header-actions button:hover {
  background: #2a2a2a;
}

/* ===== CHAT ===== */
.chat {
  flex: 1;
  padding: 16px;
  overflow-y: auto;
  overscroll-behavior: contain;
}

/* ===== MESSAGES ===== */
.message {
  max-width: 75%;
  padding: 12px 14px;
  border-radius: 14px;
  margin-bottom: 12px;
}

.my {
  background: #1f3b4d;
  margin-left: auto;
}

.other {
  background: #1a1a1a;
}

.system {
  text-align: center;
  font-size: 12px;
  color: #888;
  margin: 10px 0;
}

/* ===== INPUT ===== */
.input-bar {
  display: flex;
  gap: 8px;
  padding: 12px;
  border-top: 1px solid #1f1f1f;
  position: sticky;
  bottom: 0;
  z-index: 5;
  background: #0b0b0b;
}

.input-bar button {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: #1a1a1a;
  border: 1px solid #333;
  color: #ccc;
  cursor: pointer;
}

.input-bar input {
  flex: 1;
  background: #111;
  border: 1px solid #333;
  border-radius: 20px;
  padding: 12px 14px;
  color: #fff;
  font-size: 16px;
  line-height: 1.4;
}

/* SEND */
#send-btn {
  background: #00bcd4;
  color: #000;
}

/* ===== INFO PANEL ===== */
.info-panel {
  width: 260px;
  background: #0f0f0f;
  border-left: 1px solid #1f1f1f;
  padding: 16px;
  transform: translateX(100%);
  transition: 0.3s;
}

.info-panel.open {
  transform: translateX(0);
}

.close-info {
  position: absolute;
  top: 12px;
  right: 12px;
  background: #1a1a1a;
  border: 1px solid #333;
  color: #ccc;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  font-size: 18px;
  cursor: pointer;
}

/* ===== LOBBY VIEW ===== */
.lobby-view {
  width: 100%;
  height: 100vh;
  background: linear-gradient(135deg, #0a0a0a 0%, #1a1a2e 100%);
  overflow-y: auto;
}

.lobby-container {
  max-width: 1200px;
  margin: 0 auto;
  padding: 40px 20px;
}

.lobby-header {
  text-align: center;
  margin-bottom: 40px;
}

.lobby-header h1 {
  font-size: 42px;
  margin-bottom: 10px;
  background: linear-gradient(90deg, #00bcd4, #2196f3);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
}

.lobby-subtitle {
  color: #9e9e9e;
  font-size: 16px;
}

.lobby-actions {
  display: flex;
  gap: 16px;
  margin-bottom: 30px;
  flex-wrap: wrap;
}

.btn-primary {
  background: #00bcd4;
  color: #000;
  border: none;
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: 0.2s;
}

.btn-primary:hover {
  background: #00acc1;
  transform: translateY(-2px);
}

.search-box {
  flex: 1;
  min-width: 250px;
}

.search-box input {
  width: 100%;
  background: #1a1a1a;
  border: 1px solid #333;
  padding: 12px 16px;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
}

/* ===== ROOMS GRID ===== */
.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  gap: 20px;
}

.room-card {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 12px;
  padding: 20px;
  cursor: pointer;
  transition: 0.2s;
  position: relative;
}

.room-card:hover {
  border-color: #00bcd4;
  transform: translateY(-4px);
  box-shadow: 0 8px 24px rgba(0, 188, 212, 0.2);
}

.room-card-header {
  display: flex;
  justify-content: space-between;
  align-items: start;
  margin-bottom: 12px;
}

.room-name {
  font-size: 18px;
  font-weight: 600;
  color: #fff;
  margin-bottom: 4px;
}

.room-owner {
  font-size: 12px;
  color: #9e9e9e;
}

.room-owner::before {
  content: "👑 ";
}

.room-privacy {
  font-size: 20px;
}

.room-stats {
  display: flex;
  gap: 16px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid #333;
}

.room-stat {
  font-size: 13px;
  color: #9e9e9e;
}

.room-full {
  opacity: 0.5;
  cursor: not-allowed;
}

.room-full:hover {
  transform: none;
  border-color: #333;
}

/* ===== MODAL ===== */
.modal {
  display: none;
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0, 0, 0, 0.8);
  z-index: 1000;
  align-items: center;
  justify-content: center;
}

.modal.active {
  display: flex;
}

.modal-content {
  background: #1a1a1a;
  border: 1px solid #333;
  border-radius: 16px;
  padding: 30px;
  max-width: 450px;
  width: 90%;
  position: relative;
}

.modal-content h2 {
  margin-bottom: 24px;
  font-size: 24px;
}

.modal-close {
  position: absolute;
  top: 16px;
  right: 16px;
  background: transparent;
  border: none;
  color: #ccc;
  font-size: 24px;
  cursor: pointer;
}

.form-group {
  margin-bottom: 20px;
}

.form-group label {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  color: #ccc;
}

.form-group input {
  width: 100%;
  background: #0f0f0f;
  border: 1px solid #333;
  padding: 12px;
  border-radius: 8px;
  color: #fff;
  font-size: 14px;
}

.checkbox-group {
  display: flex;
  align-items: center;
  gap: 8px;
}

.checkbox-group input {
  width: auto;
}

/* ===== TYPING INDICATOR ===== */
.typing-indicator {
  padding: 8px 16px;
  font-size: 12px;
  color: #9e9e9e;
  font-style: italic;
  min-height: 28px;
  background: #0b0b0b;
  border-top: 1px solid #1f1f1f;
}

/* ===== CHAT VIEW ===== */
.chat-view {
  display: flex;
  width: 100%;
  height: 100vh;
}

/* ================= MOBILE FIX ================= */
@media (max-width: 768px) {
  body {
    background: #000;
  }

  .shell {
    flex-direction: column;
  }

  .sidebar {
    display: none;
  }

  .app {
    width: 100%;
    height: 100vh;
  }

  .chat {
    padding: 12px;
  }

  .message {
    max-width: 85%;
  }

  .input-bar button {
    width: 44px;
    height: 44px;
  }

  .info-panel {
    position: fixed;
    top: 0;
    right: 0;
    width: 100%;
    height: 100%;
    z-index: 10;
  }

  .lobby-container {
    padding: 20px 12px;
  }

  .lobby-header h1 {
    font-size: 28px;
  }

  .rooms-grid {
    grid-template-columns: 1fr;
  }

  .modal-content {
    padding: 20px;
  }
}

/* ================= MOBILE FINAL FIX ================= */
@media (max-width: 600px) {
  html, body {
    width: 100%;
    overflow-x: hidden;
    font-size: 14px;
  }

  .shell {
    flex-direction: column;
    width: 100vw;
    height: 100vh;
  }

  .sidebar {
    display: none !important;
  }

  .app {
    width: 100vw;
    height: 100vh;
  }

  .chat-header {
    padding: 10px 12px;
  }

  .title {
    font-size: 14px;
  }

  .subtitle {
    font-size: 10px;
  }

  .chat {
    padding: 10px;
  }

  .message {
    max-width: 90%;
    padding: 10px 12px;
    font-size: 13px;
    line-height: 1.4;
  }

  .input-bar {
    padding: 8px;
    gap: 6px;
  }

  .input-bar input {
    padding: 10px 12px;
    min-width: 0;
  }

  .input-bar button,
  .header-actions button {
    width: 42px;
    height: 42px;
    font-size: 18px;
    flex-shrink: 0;
  }

  #send-btn {
    width: 44px;
    height: 44px;
    font-size: 20px;
  }

  .info-panel {
    width: 100vw;
    height: 100vh;
    position: fixed;
    top: 0;
    right: 0;
    z-index: 100;
  }
}

/* ===== ANDROID INPUT ZOOM FIX ===== */
@media screen and (max-width: 600px) {
  input,
  textarea,
  select {
    font-size: 16px !important;
    transform: scale(1);
  }
}

/* ===== iOS SAFARI FIX ===== */
input {
  -webkit-text-size-adjust: 100%;
}

/* ===== MOBILE SAFE AREA FIX ===== */
@supports (padding: env(safe-area-inset-bottom)) {
  .input-bar {
    padding-bottom: calc(12px + env(safe-area-inset-bottom));
  }
}

/* ===== FINAL MOBILE INPUT FIX ===== */
@media (max-width: 600px) {
  .input-bar {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #0b0b0b;
  }

  .chat {
    padding-bottom: 80px;
  }
}

/* ===== iOS HEADER FIX (CORRECTED) ===== */
@supports (-webkit-touch-callout: none) {
  .chat-header {
    position: fixed;
    top: env(safe-area-inset-top);
    left: 0;
    right: 0;
    z-index: 10;
    background: #0b0b0b;
    height: 48px;
  }

  .app {
    padding-top: calc(48px + env(safe-area-inset-top));
  }

  .chat {
    padding-top: 0;
  }
}

/* ===== ANDROID HEADER FIX ===== */
@media (max-width: 600px) {
  .chat-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 10;
    background: #0b0b0b;
    height: 48px;
  }

  .app {
    padding-top: 48px;
  }

  .chat {
    padding-top: 0;
  }
}

/* ===== TYPING INDICATOR MOBILE FIX ===== */
@media (max-width: 600px) {
  .typing-indicator {
    position: fixed;
    bottom: 60px;
    left: 0;
    right: 0;
    z-index: 4;
    padding: 6px 12px;
    font-size: 11px;
  }
  
  .chat {
    padding-bottom: 100px;
  }
}