/* ===========================
   Global reset & layout
   =========================== */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  font-family: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: #f2f2f7;
  color: #111;
  overflow: hidden; /* Stop body scrolling; we control scrolling in containers */
}

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
}

/* Utility */
.hidden {
  display: none !important;
}

/* ===========================
   Screens
   =========================== */

.screen {
  flex: 1;
  display: flex;
  background: #f2f2f7;
}

/* Generic inner container */
.screen-inner {
  flex: 1;
  display: flex;
  flex-direction: column;
  padding-top: env(safe-area-inset-top);
  padding-bottom: env(safe-area-inset-bottom);
  min-height: 100%;
}

/* Auth screen centered */
.screen-inner.center {
  align-items: center;
  justify-content: center;
  padding: 24px 20px;
}

/* ===========================
   Typography & forms
   =========================== */

.app-title {
  font-size: 28px;
  font-weight: 700;
  margin-bottom: 24px;
}

.top-bar-title {
  font-size: 18px;
  font-weight: 600;
  margin: 0;
  text-align: center;
  flex: 1;
}

.form-group {
  width: 100%;
  max-width: 360px;
  margin-bottom: 16px;
}

.field-label {
  font-size: 13px;
  color: #555;
  display: block;
  margin-bottom: 4px;
}

.text-input,
.select-input {
  width: 100%;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid #d0d0d5;
  font-size: 15px;
  outline: none;
  background: #fff;
}

.text-input:focus,
.select-input:focus {
  border-color: #0b93f6;
  box-shadow: 0 0 0 2px rgba(11,147,246,0.2);
}

/* Auth buttons */

.button-row {
  width: 100%;
  max-width: 360px;
  margin-top: 8px;
}

.primary-button,
.secondary-button,
.danger-button {
  width: 100%;
  border-radius: 12px;
  padding: 11px 16px;
  font-size: 15px;
  border: none;
  cursor: pointer;
}

.primary-button {
  background: #0b93f6;
  color: #fff;
}

.primary-button:active {
  background: #0a7cd1;
}

.secondary-button {
  background: #fff;
  color: #0b93f6;
  border: 1px solid #0b93f6;
}

.secondary-button:active {
  background: #f0f7ff;
}

.danger-button {
  margin-top: 24px;
  background: #ff3b30;
  color: #fff;
}

.danger-button:active {
  background: #e23329;
}

.error {
  margin-top: 8px;
  color: #ff3b30;
  font-size: 13px;
}

/* ===========================
   Top bar
   =========================== */

.top-bar {
  height: 48px;
  padding: 8px 12px;
  display: flex;
  align-items: center;
  background: #fff;
  border-bottom: 1px solid #e5e5ea;
  flex-shrink: 0; /* never collapse */
}

.icon-button {
  border: none;
  background: transparent;
  padding: 4px 8px;
  font-size: 18px;
  cursor: pointer;
}

/* ===========================
   Main screen: chats + settings
   =========================== */

.content-view {
  position: relative;
  flex: 1;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}

/* Scrollable chat list */
.chats-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0 80px 0; /* bottom space for tabs/FAB on mobile */
}

/* Chat item */

#chats-list .chat-item {
  padding: 10px 14px;
  background: #fff;
  border-bottom: 1px solid #eee;
  cursor: pointer;
}

.chat-item-title {
  font-weight: 600;
  margin-bottom: 2px;
  font-size: 15px;
}

.chat-item-preview {
  font-size: 13px;
  color: #555;
  margin-bottom: 4px;
}

.chat-item-meta {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: #999;
}

/* Floating new-chat + button */

.floating-action-button {
  position: fixed;
  right: 16px;
  bottom: calc(66px + env(safe-area-inset-bottom));
  width: 48px;
  height: 48px;
  border-radius: 24px;
  border: none;
  background: #0b93f6;
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 8px 16px rgba(0,0,0,0.2);
  cursor: pointer;
  z-index: 30;
}

.fab-icon {
  font-size: 28px;
  line-height: 1;
}

/* Bottom tab bar on mobile */

.bottom-tab-bar {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  height: calc(52px + env(safe-area-inset-bottom));
  padding-bottom: env(safe-area-inset-bottom);
  display: flex;
  background: #fff;
  border-top: 1px solid #e5e5ea;
  z-index: 20;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  font-size: 13px;
  color: #666;
  display: flex;
  align-items: center;
  justify-content: center;
}

.tab.active {
  color: #0b93f6;
  font-weight: 600;
}

/* Settings content */

.settings-content {
  padding: 16px;
  overflow-y: auto;
}

/* ===========================
   Chat screen
   =========================== */

/* Chat layout:
   [top bar]
   [messages-container]
   [message-input-bar]
*/

#chat-screen .screen-inner {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
}

/* Scrollable messages area */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 8px 8px 8px 8px;
  background: #e5e5ea;
}

/* Messages */

.message-row {
  display: flex;
  margin-bottom: 4px;
}

.message-row.me {
  justify-content: flex-end;
}

.message-row.other {
  justify-content: flex-start;
}

.message-bubble {
  max-width: 78%;
  padding: 8px 10px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
}

.message-row.me .message-bubble {
  background: #0b93f6;
  color: #fff;
  border-bottom-right-radius: 4px;
}

.message-row.other .message-bubble {
  background: #fff;
  border-bottom-left-radius: 4px;
}

/* Message input bar stays at bottom of chat screen */

.message-input-bar {
  flex-shrink: 0;
  padding: 6px 8px calc(6px + env(safe-area-inset-bottom)) 8px;
  background: rgba(242,242,247,0.98);
  border-top: 1px solid #d1d1d6;
  display: flex;
  align-items: center;
  gap: 6px;
}

/* Rounded text input inside bar */

.message-input {
  flex: 1;
  border-radius: 999px;
  border: 1px solid #d0d0d5;
  padding: 10px 14px;
  background: #fff;
  font-size: 15px;
}

.message-input:focus {
  border-color: #0b93f6;
  box-shadow: 0 0 0 2px rgba(11,147,246,0.2);
}

/* Send button */

.send-button {
  width: 40px;
  height: 40px;
  border-radius: 20px;
  border: none;
  background: #0b93f6;
  color: #fff;
  font-size: 18px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}

.send-button:disabled {
  background: #c5c7cf;
  cursor: default;
}

/* ===========================
   Desktop two-column layout
   =========================== */

@media (min-width: 900px) {
  #app {
    flex-direction: row;
  }

  /* Auth screen: full width if shown */
  #auth-screen {
    width: 100%;
  }

  /* Main and chat side-by-side */
  #main-screen,
  #chat-screen {
    display: flex !important;
  }

  #main-screen .screen-inner,
  #chat-screen .screen-inner {
    height: 100vh;
    height: 100dvh;
    padding-bottom: 0;
  }

  /* Left column: resizable */
  #main-screen {
    max-width: 300px;
    min-width: 260px;
    resize: horizontal;
    overflow: hidden;
    border-right: 1px solid #e5e5ea;
  }

  #chat-screen {
    flex: 1;
  }

  /* Hide mobile-only UI on desktop */
  .bottom-tab-bar,
  .floating-action-button {
    display: none !important;
  }

  /* Adjust chat bottom padding (no safe-area) */
  .message-input-bar {
    padding-bottom: 8px;
  }

  .messages-container {
    padding-bottom: 8px;
  }
}
