* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, sans-serif;
  background: #fff;
  color: #18181b;
  min-height: 100vh;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
}
.hidden { display: none !important; }

#auth-screen {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  background: #fff;
}
.auth-box {
  width: 100%;
  max-width: 320px;
}
.auth-box h1 { font-size: 1.5rem; margin-bottom: 0.5rem; color: #18181b; }
.auth-box .hint {
  font-size: 0.875rem;
  color: #52525b;
  margin-bottom: 1rem;
}
.auth-box input {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 1rem;
  border: 1px solid #e4e4e7;
  border-radius: 8px;
  background: #fafafa;
  color: #18181b;
  margin-bottom: 0.75rem;
}
.auth-box input:focus {
  outline: none;
  border-color: #6366f1;
}
.auth-box button {
  width: 100%;
  padding: 0.75rem;
  font-size: 1rem;
  border: none;
  border-radius: 8px;
  background: #6366f1;
  color: #fff;
  cursor: pointer;
}
.auth-box button:hover { background: #5558e3; }
.error { color: #dc2626; font-size: 0.875rem; margin-top: 0.5rem; }

#unlock-screen {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
  padding-top: max(1rem, env(safe-area-inset-top));
  padding-bottom: max(1rem, env(safe-area-inset-bottom));
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}
#unlock-screen .auth-box {
  width: 100%;
  max-width: 320px;
  margin: auto;
}
body.unlock-visible #app .search-wrap,
body.unlock-visible #app .search-dropdown,
body.unlock-visible #app .thread-list { display: none !important; }
.auth-box .unlock-subtitle { margin-bottom: 0.5rem; }
@media (max-width: 360px) {
  #unlock-screen { padding: 0.75rem; padding-left: max(0.75rem, env(safe-area-inset-left)); padding-right: max(0.75rem, env(safe-area-inset-right)); }
  #unlock-screen .auth-box h1 { font-size: 1.35rem; }
  #unlock-screen .auth-box .hint { font-size: 0.8125rem; }
}

#app {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100dvh;
  max-height: 100vh;
  max-height: 100dvh;
  overflow-x: hidden;
  background: #fff;
}
.header {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid rgba(0,0,0,0.06);
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  background: #fff;
  color: #18181b;
}
.status { font-size: 0.875rem; color: #52525b; }
.status.connected { color: #16a34a; }
.status.error { color: #dc2626; }
#logout-btn {
  padding: 0.35rem 0.75rem;
  font-size: 0.875rem;
  border: 1px solid #e4e4e7;
  border-radius: 6px;
  background: #fff;
  color: #52525b;
  cursor: pointer;
}
#logout-btn:hover { background: #f4f4f5; color: #18181b; }

#view-threads,
#view-users {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  background: #fff;
}

#view-chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  background: #fff;
}

.messages {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 1rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  background: #fff;
}
.msg {
  max-width: 85%;
  padding: 0.6rem 0.9rem;
  border-radius: 12px;
  font-size: 0.95rem;
  line-height: 1.4;
  word-break: break-word;
}
.msg.sent {
  align-self: flex-end;
  background: #6366f1;
  color: #fff;
  border-bottom-right-radius: 4px;
}
.msg.recv {
  align-self: flex-start;
  background: #f4f4f5;
  border: 1px solid #e4e4e7;
  color: #18181b;
  border-bottom-left-radius: 4px;
}
.msg .time {
  font-size: 0.7rem;
  opacity: 0.8;
  margin-top: 0.25rem;
}

.compose {
  padding: 0.75rem 1rem;
  padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
  border-top: 1px solid rgba(0,0,0,0.06);
  display: flex;
  gap: 0.5rem;
  align-items: flex-end;
  flex-shrink: 0;
  background: #fff;
}

.attach-wrap {
  position: relative;
  flex-shrink: 0;
  display: flex;
  align-items: flex-end;
}
.attach-btn {
  width: 44px;
  height: 44px;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 10px;
  border: 1px solid #e4e4e7;
  background: #fafafa;
  color: #52525b;
  cursor: pointer;
  padding: 0;
}
.attach-btn:hover { background: #f4f4f5; color: #18181b; }
.attach-btn svg { width: 22px; height: 22px; }
.attach-dropdown {
  position: absolute;
  left: 0;
  bottom: 52px;
  width: 170px;
  background: #fff;
  border: 1px solid rgba(0,0,0,0.08);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0,0,0,0.18);
  padding: 0.25rem 0;
  z-index: 80;
}
.attach-item {
  width: 100%;
  background: none;
  border: none;
  cursor: pointer;
  text-align: left;
  padding: 0.65rem 0.85rem;
  color: #18181b;
  font-size: 0.95rem;
}
.attach-item:hover { background: rgba(0,0,0,0.04); }

#message-input {
  flex: 1;
  min-height: 44px;
  max-height: 120px;
  padding: 0.6rem 0.9rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid #e4e4e7;
  border-radius: 10px;
  background: #fafafa;
  color: #18181b;
  resize: none;
}
#message-input:focus {
  outline: none;
  border-color: #6366f1;
}
#send-btn {
  padding: 0.6rem 1rem;
  font-size: 1rem;
  border: none;
  border-radius: 10px;
  background: #6366f1;
  color: #fff;
  cursor: pointer;
  flex-shrink: 0;
}
#send-btn:hover { background: #5558e3; }
#send-btn:disabled { opacity: 0.5; cursor: not-allowed; }
