* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  font-family: -apple-system, "Hiragino Sans", "Noto Sans JP", sans-serif;
  background: #f4f4f4;
  color: #222;
}
body {
  display: flex;
  flex-direction: column;
}
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  background: #2f6f4f;
  color: #fff;
}
.topbar a.brand {
  color: #fff;
  font-weight: bold;
  text-decoration: none;
  font-size: 1.1rem;
}
.topbar a.back-link {
  color: #fff;
  text-decoration: none;
}
main {
  flex: 1;
  min-height: 0;
}
.login-wrap {
  max-width: 720px;
  margin: 0 auto;
  padding: 1rem;
}

.app-layout {
  display: flex;
  height: 100%;
  min-height: 0;
}
#sidebar {
  width: 280px;
  flex-shrink: 0;
  background: #fff;
  border-right: 1px solid #ddd;
  padding: 1rem;
  overflow-y: auto;
}
#sidebar h2 {
  font-size: 0.95rem;
  margin: 1rem 0 0.5rem;
}
#main-pane {
  flex: 1;
  min-width: 0;
  padding: 1rem 1.5rem;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
}
#room-panel-content {
  flex: 1;
  min-height: 0;
  display: flex;
  flex-direction: column;
}
.mobile-back-link {
  display: none;
  color: #2f6f4f;
  text-decoration: none;
  font-size: 0.9rem;
}

@media (max-width: 768px) {
  .app-layout {
    position: relative;
  }
  #sidebar,
  #main-pane {
    width: 100%;
  }
  .app-layout.room-active #sidebar {
    display: none;
  }
  .app-layout:not(.room-active) #main-pane {
    display: none;
  }
  .mobile-back-link {
    display: inline-block;
    margin-bottom: 0.5rem;
  }
}

.empty-panel {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #888;
}
.login-box {
  max-width: 320px;
  margin: 4rem auto;
  background: #fff;
  padding: 2rem;
  border-radius: 8px;
}
.login-box label {
  display: block;
  margin-bottom: 1rem;
}
.login-box input {
  width: 100%;
  padding: 0.5rem;
  margin-top: 0.25rem;
}
.error { color: #c0392b; }

.room-list { list-style: none; padding: 0; }
.room-item a {
  display: flex;
  justify-content: space-between;
  padding: 0.75rem;
  margin-bottom: 0.5rem;
  background: #f4f4f4;
  border-radius: 8px;
  text-decoration: none;
  color: #222;
}
.room-item.active a {
  background: #2f6f4f;
  color: #fff;
}
.badge {
  background: #e74c3c;
  color: #fff;
  border-radius: 999px;
  padding: 0.1rem 0.6rem;
  font-size: 0.8rem;
}

#chat-socket {
  flex: 1;
  min-height: 0;
  display: flex;
}
#messages {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  background: #fff;
  border-radius: 8px;
  padding: 1rem;
  margin-bottom: 1rem;
}
.message {
  max-width: 80%;
  background: #eee;
  border-radius: 8px;
  padding: 0.5rem 0.75rem;
  align-self: flex-start;
}
.message.mine {
  background: #d4f0dc;
  align-self: flex-end;
}
.message-meta {
  font-size: 0.75rem;
  color: #666;
  display: flex;
  justify-content: space-between;
  gap: 0.5rem;
}
.message-body {
  white-space: pre-wrap;
  word-break: break-word;
}
.read-receipt {
  font-size: 0.7rem;
  color: #2f6f4f;
  text-align: right;
  min-height: 1em;
}
.message:not(.mine) .read-receipt {
  display: none;
}
.attachment-image {
  max-width: 100%;
  border-radius: 4px;
  margin-top: 0.25rem;
}

#send-form {
  margin-bottom: 0.75rem;
}
.send-row {
  display: flex;
  align-items: flex-end;
  gap: 0.5rem;
}
.send-row textarea {
  flex: 1;
  padding: 0.5rem;
  font-family: inherit;
  font-size: 1rem;
  resize: none;
  max-height: 160px;
  line-height: 1.4;
}
.attach-button {
  cursor: pointer;
  font-size: 1.25rem;
  padding: 0.25rem;
}
.attach-button input[type="file"] {
  display: none;
}
.attach-button.has-file {
  background: #d4f0dc;
  border-radius: 4px;
}

.file-preview[hidden] {
  display: none;
}
.file-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  background: #d4f0dc;
  border-radius: 6px;
  padding: 0.4rem 0.6rem;
  margin-bottom: 0.4rem;
  font-size: 0.9rem;
}
.file-preview-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
#remove-file-button {
  border: none;
  background: none;
  cursor: pointer;
  font-size: 1rem;
  color: #555;
  padding: 0 0.25rem;
}

.logout-form {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}
