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

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: #f0f2f5;
  color: #1c1e21;
  font-size: 15px;
  line-height: 1.4;
  height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ================= UTILITY & BUTTONS ================= */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 8px 16px;
  font-size: 14px;
  font-weight: 600;
  border-radius: 4px;
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
}

.btn-primary {
  background-color: #0066cc;
  color: #ffffff;
}

.btn-primary:hover {
  background-color: #0052a3;
}

.btn-secondary {
  background-color: #e4e6eb;
  color: #050505;
}

.btn-secondary:hover {
  background-color: #d8dadf;
}

.btn-outline {
  background-color: transparent;
  border-color: #bcc0c4;
  color: #333;
}

.btn-outline:hover {
  background-color: #e4e6eb;
}

.btn-danger {
  background-color: #d93025;
  color: #ffffff;
}

.btn-danger:hover {
  background-color: #b3261e;
}

.btn-outline-danger {
  background-color: transparent;
  border-color: #d93025;
  color: #d93025;
}

.btn-outline-danger:hover {
  background-color: #ffebe8;
}

.btn-sm {
  padding: 4px 10px;
  font-size: 13px;
}

.btn-block {
  width: 100%;
}

.icon-btn {
  background: none;
  border: none;
  font-size: 20px;
  cursor: pointer;
  padding: 4px 8px;
  color: #333;
  line-height: 1;
}

.alert-error {
  background-color: #ffebe8;
  border: 1px solid #dd3c10;
  color: #b92b27;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 13px;
  margin-bottom: 12px;
}

.text-muted {
  color: #65676b;
}

/* ================= AUTHENTICATION VIEW ================= */
.view-container {
  width: 100%;
  height: 100%;
}

#authView {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

.auth-card {
  background: #ffffff;
  border: 1px solid #ccd0d5;
  border-radius: 8px;
  padding: 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.08);
}

.auth-card h2 {
  font-size: 22px;
  text-align: center;
  margin-bottom: 4px;
}

.auth-subtitle {
  text-align: center;
  color: #65676b;
  margin-bottom: 18px;
  font-size: 13px;
}

.auth-tabs {
  display: flex;
  border-bottom: 1px solid #ccd0d5;
  margin-bottom: 18px;
}

.tab-btn {
  flex: 1;
  background: none;
  border: none;
  padding: 10px 0;
  font-size: 14px;
  font-weight: 600;
  color: #65676b;
  cursor: pointer;
  border-bottom: 3px solid transparent;
}

.tab-btn.active {
  color: #0066cc;
  border-bottom-color: #0066cc;
}

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

.form-group label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: #4b4f56;
}

.form-group input {
  width: 100%;
  padding: 9px 12px;
  border: 1px solid #ccd0d5;
  border-radius: 4px;
  font-size: 14px;
}

.form-group input:focus {
  outline: none;
  border-color: #0066cc;
}

/* ================= APP LAYOUT ================= */
#appView {
  display: flex;
  flex-direction: column;
}

.app-header {
  background: #ffffff;
  border-bottom: 1px solid #ccd0d5;
  height: 52px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 14px;
  flex-shrink: 0;
}

.header-title {
  font-size: 18px;
  font-weight: bold;
}

.header-user-info {
  display: flex;
  align-items: center;
  gap: 10px;
}

.user-badge {
  background: #e4e6eb;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 13px;
  font-weight: 600;
}

.app-body {
  display: flex;
  flex: 1;
  overflow: hidden;
  position: relative;
}

/* ================= SIDEBAR ================= */
.sidebar {
  width: 260px;
  background: #ffffff;
  border-right: 1px solid #ccd0d5;
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
  transition: transform 0.15s ease-in-out;
  z-index: 100;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  border-bottom: 1px solid #f0f2f5;
}

.sidebar-header h3 {
  font-size: 15px;
}

.close-btn {
  display: none;
}

.sidebar-actions {
  padding: 12px 14px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  border-bottom: 1px solid #f0f2f5;
}

.sidebar-section {
  flex: 1;
  overflow-y: auto;
  padding: 12px 14px;
}

.sidebar-section h4 {
  font-size: 12px;
  text-transform: uppercase;
  color: #65676b;
  margin-bottom: 8px;
  letter-spacing: 0.5px;
}

.room-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.room-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  border-radius: 4px;
  background: #f7f8fa;
  cursor: pointer;
  border: 1px solid #eaedf0;
}

.room-item:hover {
  background: #e4e6eb;
}

.room-item.active {
  background: #e7f3ff;
  border-color: #0066cc;
  font-weight: 600;
}

.room-item-name {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.room-item-lock {
  font-size: 12px;
  color: #65676b;
}

.sidebar-backdrop {
  display: none;
}

/* ================= MAIN CONTENT ================= */
.main-content {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background-color: #ffffff;
}

/* Hub */
.hub-container {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: #f0f2f5;
}

.hub-welcome-box {
  background: #ffffff;
  border: 1px solid #ccd0d5;
  border-radius: 8px;
  padding: 30px;
  text-align: center;
  max-width: 450px;
  width: 100%;
}

.hub-welcome-box h2 {
  margin-bottom: 8px;
}

.hub-welcome-box p {
  color: #65676b;
  margin-bottom: 20px;
}

.hub-quick-actions {
  display: flex;
  gap: 12px;
  justify-content: center;
}

/* ================= ROOM VIEW ================= */
.room-container {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100%;
  overflow: hidden;
}

.room-header {
  height: 52px;
  background: #ffffff;
  border-bottom: 1px solid #ccd0d5;
  padding: 0 14px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

.room-header-left {
  display: flex;
  align-items: center;
  gap: 12px;
}

.room-title {
  font-size: 16px;
  line-height: 1.2;
}

.room-layout {
  display: flex;
  flex: 1;
  overflow: hidden;
}

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

/* Notice box */
.catbox-notice {
  background: #eef3fc;
  border-bottom: 1px solid #ccd0d5;
  color: #1a4f8b;
  font-size: 13px;
  padding: 8px 14px;
  flex-shrink: 0;
}

.catbox-notice a {
  color: #0066cc;
  text-decoration: underline;
  font-weight: 600;
}

/* Messages container */
.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.message-item {
  display: flex;
  flex-direction: column;
  max-width: 85%;
  align-self: flex-start;
}

.message-item.own-message {
  align-self: flex-end;
}

.message-meta {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 2px;
  font-size: 12px;
  color: #65676b;
}

.message-item.own-message .message-meta {
  justify-content: flex-end;
}

.message-sender {
  font-weight: 600;
  color: #1c1e21;
}

.message-time {
  font-size: 11px;
  color: #8a8d91;
  white-space: nowrap;
  cursor: default;
}

.message-bubble {
  background: #f0f2f5;
  padding: 8px 12px;
  border-radius: 8px;
  border-top-left-radius: 2px;
  color: #050505;
  word-break: break-word;
}

.message-item.own-message .message-bubble {
  background: #0066cc;
  color: #ffffff;
  border-top-left-radius: 8px;
  border-top-right-radius: 2px;
}

/* Links inside chat: Blue and clickable */
.message-bubble a {
  color: #0066cc;
  text-decoration: underline;
  word-break: break-all;
}

.message-item.own-message .message-bubble a {
  color: #99d1ff;
}

/* Inline Catbox Image Display */
.chat-image-preview {
  margin-top: 8px;
  display: block;
}

.chat-image-preview img {
  max-width: 100%;
  max-height: 280px;
  border-radius: 6px;
  border: 1px solid #ccd0d5;
  object-fit: contain;
  background-color: #000;
  display: block;
}

/* Chat Input Bar */
.chat-input-bar {
  display: flex;
  padding: 10px 14px;
  background: #ffffff;
  border-top: 1px solid #ccd0d5;
  gap: 8px;
  flex-shrink: 0;
}

.chat-input-bar input {
  flex: 1;
  padding: 9px 12px;
  border: 1px solid #ccd0d5;
  border-radius: 4px;
  font-size: 14px;
}

.chat-input-bar input:focus {
  outline: none;
  border-color: #0066cc;
}

/* ================= ROOM INFO PANEL (MEMBERS & ONLINE) ================= */
.room-info-panel {
  width: 240px;
  background: #f7f8fa;
  border-left: 1px solid #ccd0d5;
  display: flex;
  flex-direction: column;
  overflow-y: auto;
  flex-shrink: 0;
}

.room-panel-section {
  padding: 12px 14px;
  border-bottom: 1px solid #e4e6eb;
}

.panel-section-title {
  display: flex;
  align-items: center;
  gap: 6px;
  margin-bottom: 8px;
}

.panel-section-title h4 {
  font-size: 13px;
  text-transform: uppercase;
  color: #65676b;
  letter-spacing: 0.5px;
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
}

.status-online {
  background-color: #31a24c;
}

.user-list {
  list-style: none;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.user-list-item {
  font-size: 14px;
  padding: 4px 6px;
  border-radius: 4px;
  display: flex;
  align-items: center;
  gap: 6px;
  color: #333;
}

.user-list-item.is-self {
  font-weight: 600;
}

.empty-state {
  font-size: 13px;
  color: #8a8d91;
  padding: 6px 0;
  font-style: italic;
}

/* ================= MODALS ================= */
.modal-overlay {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: rgba(0, 0, 0, 0.5);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 1000;
}

.modal-box {
  background: #ffffff;
  border-radius: 8px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
  display: flex;
  flex-direction: column;
}

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 16px;
  border-bottom: 1px solid #e4e6eb;
}

.modal-header h3 {
  font-size: 16px;
}

.modal-close {
  background: none;
  border: none;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}

.modal-body {
  padding: 16px;
}

.modal-footer {
  padding: 12px 16px;
  border-top: 1px solid #e4e6eb;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

/* ================= MOBILE RESPONSIVENESS ================= */
@media (max-width: 768px) {
  .sidebar {
    position: absolute;
    top: 0;
    bottom: 0;
    left: 0;
    transform: translateX(-100%);
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.15);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .close-btn {
    display: block;
  }

  .sidebar-backdrop.active {
    display: block;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.35);
    z-index: 90;
  }

  .room-info-panel {
    display: none;
    position: absolute;
    top: 52px;
    right: 0;
    bottom: 0;
    width: 220px;
    z-index: 50;
    box-shadow: -2px 0 8px rgba(0, 0, 0, 0.15);
  }

  .room-info-panel.open {
    display: flex;
  }
}
