* {
  box-sizing: border-box;
}

:root {
  --app-height: 100vh;
  --keyboard-offset: 0px;
}

[hidden] {
  display: none !important;
}

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f3f5f9;
  color: #18202a;
  min-height: var(--app-height);
  height: var(--app-height);
  overflow: hidden;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

button,
input,
textarea {
  font: inherit;
}

.page {
  min-height: var(--app-height);
  height: var(--app-height);
  display: grid;
  grid-template-columns: 320px 1fr;
}

.page.sidebar-hidden {
  grid-template-columns: 1fr;
}

.sidebar {
  padding: max(16px, env(safe-area-inset-top)) 16px max(16px, env(safe-area-inset-bottom));
  background: #0f1722;
  color: #f8fbff;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.card {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 16px;
  padding: 16px;
}

.card h1 {
  margin: 0 0 8px;
  font-size: 24px;
}

.muted {
  margin: 8px 0 0;
  color: #bdd0ea;
  font-size: 14px;
  line-height: 1.5;
}

label,
.room-meta,
.online-header {
  display: block;
  margin-bottom: 8px;
  font-size: 14px;
  color: #dce8f7;
}

input,
textarea {
  width: 100%;
  border: 1px solid #cad6e2;
  border-radius: 12px;
  padding: 12px 14px;
  background: #ffffff;
  color: #18202a;
  font-size: 16px;
  -webkit-appearance: none;
  appearance: none;
}

textarea {
  resize: none;
  min-height: 80px;
  max-height: 128px;
  overflow-y: hidden;
}

.button-row,
.invite-box,
.composer-actions {
  display: flex;
  gap: 10px;
  margin-top: 12px;
}

.composer-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  align-items: stretch;
}

button,
.file-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin: 0;
  border: none;
  border-radius: 12px;
  padding: 12px 14px;
  min-height: 46px;
  background: #2a7fff;
  color: #ffffff;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
  text-align: center;
  line-height: 1.2;
  text-decoration: none;
  -webkit-appearance: none;
  appearance: none;
}

button:hover,
.file-button:hover {
  opacity: 0.92;
  transform: translateY(-1px);
}

button.secondary {
  background: #334155;
}

.invite-box {
  flex-direction: column;
}

.online-header,
.room-meta {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.user-list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.user-list li {
  padding: 10px 12px;
  border-radius: 10px;
  background: rgba(255, 255, 255, 0.1);
  font-size: 14px;
}

.chat-panel {
  display: flex;
  flex-direction: column;
  min-height: 0;
  height: 100%;
  overflow: hidden;
}

.pinned-notice {
  margin: 14px 20px 0;
  padding: 12px 14px;
  border-radius: 14px;
  background: #fff7d6;
  border: 1px solid #f0dc8b;
  color: #5a4300;
  box-shadow: 0 4px 14px rgba(90, 67, 0, 0.08);
}

.pinned-notice strong {
  display: block;
  font-size: 14px;
  margin-bottom: 6px;
}

.pinned-notice p {
  margin: 0;
  font-size: 14px;
  line-height: 1.5;
}

.pinned-notice p + p {
  margin-top: 4px;
}

.message-list {
  flex: 1;
  min-height: 0;
  padding: 20px;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message {
  max-width: min(75%, 620px);
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.message-author {
  font-size: 12px;
  color: #888;
  margin: 0 4px;
}

.message.self .message-author {
  display: none;
}

.message-bubble {
  width: fit-content;
  background: #ffffff;
  border-radius: 10px;
  padding: 6px 12px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.1);
  display: flex;
  flex-direction: column;
}

.message-bubble.image-only {
  padding: 0;
  overflow: hidden;
}

.message.system {
  align-self: center;
  flex-direction: row;
}

.message.system .message-bubble {
  background: rgba(0, 0, 0, 0.05);
  border-radius: 6px;
  padding: 4px 10px;
  color: #666;
  box-shadow: none;
}

.message.system .message-header {
  display: none;
}

.message.system .message-author {
  display: none;
}

.message.self {
  align-self: flex-end;
  align-items: flex-end;
}

.message.self .message-bubble {
  background: #d6e8ff;
  border-radius: 10px 2px 10px 10px;
  color: #16324f;
}

.message.self .message-time {
  color: #43617f;
}

.message.other {
  align-self: flex-start;
  align-items: flex-start;
}

.message.other .message-bubble {
  background: #fce8f0;
  border-radius: 2px 10px 10px 10px;
  color: #4d2735;
}

.message.recalled .message-bubble {
  opacity: 0.72;
}

.message.recalled .message-body {
  font-style: italic;
}

.message-header {
  display: flex;
  justify-content: flex-end;
  margin-top: 4px;
}

.message-time {
  font-size: 11px;
  color: #99aab5;
  white-space: nowrap;
}

.message-body {
  word-break: break-word;
  font-size: 15px;
  line-height: 1.4;
}

.message-body.image-only {
  line-height: 0;
}

.message-body img {
  max-width: min(100%, 300px);
  width: auto;
  max-height: 360px;
  border-radius: 10px;
  display: block;
  object-fit: cover;
  cursor: zoom-in;
}

.message-actions {
  margin-top: 4px;
  display: flex;
  justify-content: flex-end;
}

.message-recall-button {
  display: none;
  padding: 6px 10px;
  border-radius: 999px;
  font-size: 12px;
  background: rgba(15, 23, 34, 0.08);
  color: inherit;
}

.message.self .message-recall-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 255, 255, 0.16);
}

.message.system .message-recall-button,
.message.recalled .message-recall-button {
  display: none;
}

.composer {
  padding: 16px 20px calc(20px + env(safe-area-inset-bottom));
  border-top: 1px solid #dde5ef;
  background: #ffffff;
  flex-shrink: 0;
}

.composer-actions {
  justify-content: space-between;
  align-items: stretch;
}

.composer-actions button,
.composer-actions .file-button {
  width: 100%;
  min-width: 0;
  height: 48px;
  min-height: 48px;
  padding: 0 14px;
  border-radius: 14px;
  font-size: 15px;
  font-weight: 600;
  box-shadow: 0 6px 18px rgba(42, 127, 255, 0.18);
  white-space: nowrap;
}

.image-viewer {
  position: fixed;
  inset: 0;
  z-index: 999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.image-viewer[hidden] {
  display: none;
}

.image-viewer-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 23, 34, 0.84);
}

.image-viewer-panel {
  position: relative;
  z-index: 1;
  width: min(96vw, 1100px);
  max-height: 92vh;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.image-viewer-toolbar {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.image-viewer-stage {
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 16px;
  min-height: 60vh;
  max-height: calc(92vh - 64px);
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  touch-action: none;
  cursor: grab;
}

.image-viewer-image {
  max-width: none;
  max-height: none;
  transform-origin: center center;
  transition: transform 0.08s linear;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.image-viewer-stage:active {
  cursor: grabbing;
}

@media (max-width: 900px) {
  .page {
    grid-template-columns: 1fr;
  }

  .chat-panel {
    min-height: 0;
  }

  .message-list {
    min-height: 0;
  }
}

@media (max-width: 520px) {
  .sidebar,
  .composer,
  .message-list {
    padding: 14px;
  }

  .pinned-notice {
    margin: 10px 14px 0;
    padding: 10px 12px;
    border-radius: 12px;
  }

  .pinned-notice strong,
  .pinned-notice p {
    font-size: 13px;
  }

  .composer {
    padding-bottom: calc(14px + env(safe-area-inset-bottom));
  }

  .message-list {
    gap: 10px;
  }

  .message {
    max-width: min(85%, 320px);
    padding: 0;
  }

  .message-bubble {
    border-radius: 10px;
    padding: 6px 10px;
  }

  .message.self .message-bubble {
    border-radius: 10px 2px 10px 10px;
  }

  .message.other .message-bubble {
    border-radius: 2px 10px 10px 10px;
  }

  .message-header {
    margin-top: 2px;
  }

  .message-author {
    font-size: 11px;
  }

  .message-time {
    font-size: 10px;
  }

  .message-body {
    font-size: 15px;
    line-height: 1.4;
  }

  .message-body img {
    max-width: min(100%, 220px);
    max-height: 280px;
    border-radius: 8px;
  }

  .message-actions {
    margin-top: 4px;
  }

  .button-row {
    flex-direction: column;
  }

  .composer-actions button,
  .composer-actions .file-button {
    height: 44px;
    min-height: 44px;
    padding: 0 12px;
    font-size: 15px;
  }

  .composer-actions {
    align-items: stretch;
    gap: 10px;
  }

  .image-viewer-toolbar {
    flex-wrap: wrap;
  }
}
