/* ==========================================================================
   chat-room Modern Design System
   ========================================================================== */

:root {
  --bg-primary: #0b0f19;
  --bg-surface: #131b2e;
  --bg-surface-hover: #1b2640;
  --bg-card: rgba(19, 27, 46, 0.85);
  --bg-card-border: rgba(255, 255, 255, 0.08);
  --bg-glass: rgba(19, 27, 46, 0.75);

  --accent-primary: #4f46e5;
  --accent-primary-hover: #4338ca;
  --accent-gradient: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
  --accent-gradient-warm: linear-gradient(135deg, #f59e0b 0%, #d97706 100%);
  --accent-gradient-danger: linear-gradient(135deg, #ef4444 0%, #dc2626 100%);
  --accent-gradient-success: linear-gradient(135deg, #10b981 0%, #059669 100%);

  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;

  --border-color: rgba(255, 255, 255, 0.1);
  --border-focus: #6366f1;

  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.2);
  --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 16px 40px rgba(0, 0, 0, 0.5);

  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 18px;
  --radius-full: 9999px;

  --font-sans: system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
    "Helvetica Neue", Arial, sans-serif;
  --font-mono: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

body {
  font-family: var(--font-sans);
  background-color: var(--bg-primary);
  background-image: 
    radial-gradient(at 0% 0%, rgba(99, 102, 241, 0.12) 0px, transparent 50%),
    radial-gradient(at 100% 100%, rgba(79, 70, 229, 0.08) 0px, transparent 50%);
  color: var(--text-primary);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

/* App Header */
.header {
  position: sticky;
  top: 0;
  z-index: 40;
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  background: var(--bg-glass);
  border-bottom: 1px solid var(--border-color);
  padding: 0.85rem 1.5rem;
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.brand {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  text-decoration: none;
  color: var(--text-primary);
  font-weight: 700;
  font-size: 1.15rem;
  letter-spacing: -0.02em;
}

.brand-icon {
  width: 34px;
  height: 34px;
  background: var(--accent-gradient);
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.1rem;
  box-shadow: var(--shadow-sm);
}

.user-profile {
  display: flex;
  align-items: center;
  gap: 1rem;
}

.user-badge {
  display: inline-flex;
  align-items: center;
  gap: 0.5rem;
  background: rgba(255, 255, 255, 0.06);
  padding: 0.35rem 0.85rem;
  border-radius: var(--radius-full);
  font-size: 0.875rem;
  color: var(--text-secondary);
  border: 1px solid var(--border-color);
}

.user-avatar {
  width: 22px;
  height: 22px;
  background: var(--accent-gradient);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 700;
  color: #fff;
}

/* Container */
.container {
  width: 100%;
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem;
  flex: 1;
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  font-family: inherit;
  font-size: 0.9rem;
  font-weight: 600;
  padding: 0.6rem 1.2rem;
  border-radius: var(--radius-sm);
  border: none;
  cursor: pointer;
  transition: all 0.18s ease;
  text-decoration: none;
  outline: none;
}

.btn-primary {
  background: var(--accent-gradient);
  color: #ffffff;
  box-shadow: 0 4px 14px rgba(79, 70, 229, 0.35);
}

.btn-primary:hover {
  background: var(--accent-primary-hover);
  transform: translateY(-1px);
  box-shadow: 0 6px 18px rgba(79, 70, 229, 0.45);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.08);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.14);
}

.btn-danger {
  background: var(--accent-gradient-danger);
  color: #ffffff;
}

.btn-danger:hover {
  filter: brightness(1.1);
}

.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
  min-height: 36px;
}

.btn-icon {
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  min-width: 44px;
  min-height: 44px;
}

/* Room List View */
.page-toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 2rem;
  flex-wrap: wrap;
  gap: 1rem;
}

.page-title {
  font-size: 1.6rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.page-desc {
  font-size: 0.9rem;
  color: var(--text-secondary);
  margin-top: 0.2rem;
}

.rooms-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
  gap: 1.5rem;
}

.room-card {
  background: var(--bg-card);
  border: 1px solid var(--bg-card-border);
  border-radius: var(--radius-md);
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  transition: all 0.22s ease;
  position: relative;
  overflow: hidden;
  box-shadow: var(--shadow-sm);
}

.room-card:hover {
  transform: translateY(-3px);
  border-color: rgba(99, 102, 241, 0.4);
  box-shadow: var(--shadow-md);
}

.room-card-header {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 1rem;
  gap: 0.75rem;
}

.room-name {
  font-size: 1.2rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1.3;
  word-break: break-word;
}

.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.3rem;
  padding: 0.25rem 0.6rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  white-space: nowrap;
}

.badge-owner {
  background: rgba(245, 158, 11, 0.15);
  color: #fbbf24;
  border: 1px solid rgba(245, 158, 11, 0.3);
}

.badge-member {
  background: rgba(99, 102, 241, 0.15);
  color: #a5b4fc;
  border: 1px solid rgba(99, 102, 241, 0.3);
}

.badge-online {
  background: rgba(16, 185, 129, 0.15);
  color: #34d399;
  border: 1px solid rgba(16, 185, 129, 0.3);
}

.room-meta {
  margin-bottom: 1.25rem;
  font-size: 0.85rem;
  color: var(--text-secondary);
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
}

.room-meta-item {
  display: flex;
  align-items: center;
  gap: 0.45rem;
}

.room-card-actions {
  display: flex;
  gap: 0.75rem;
  margin-top: auto;
  padding-top: 1rem;
  border-top: 1px solid var(--border-color);
  align-items: center;
}

.room-card-actions .btn {
  flex: 1;
}

.room-card-actions .destroy-btn {
  flex: 0 0 auto;
  padding: 0.5rem 0.75rem;
  font-size: 0.95rem;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 44px;
  min-height: 40px;
}

/* Empty State */
.empty-state {
  text-align: center;
  padding: 4rem 2rem;
  background: var(--bg-surface);
  border: 1px dashed var(--border-color);
  border-radius: var(--radius-lg);
  grid-column: 1 / -1;
}

.empty-state-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
  opacity: 0.8;
}

.empty-state-title {
  font-size: 1.25rem;
  font-weight: 700;
  margin-bottom: 0.5rem;
}

.empty-state-text {
  color: var(--text-secondary);
  font-size: 0.9rem;
  margin-bottom: 1.5rem;
  max-width: 400px;
  margin-left: auto;
  margin-right: auto;
  word-break: break-word;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(5, 8, 15, 0.75);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 1rem;
  opacity: 0;
  visibility: hidden;
  transition: all 0.2s ease;
}

.modal-backdrop.active {
  opacity: 1;
  visibility: visible;
}

.modal {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow-lg);
  overflow: hidden;
  transform: scale(0.96);
  transition: transform 0.2s ease;
}

.modal-backdrop.active .modal {
  transform: scale(1);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.modal-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 1.5rem;
  cursor: pointer;
  line-height: 1;
  width: 44px;
  height: 44px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: var(--radius-sm);
  transition: color 0.15s ease, background 0.15s ease;
}

.modal-close:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.08);
}

.modal-body {
  padding: 1.5rem;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  justify-content: flex-end;
  gap: 0.75rem;
  background: rgba(0, 0, 0, 0.15);
}

/* Forms & Inputs */
.form-group {
  margin-bottom: 1.25rem;
}

.form-label {
  display: block;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 0.4rem;
}

.form-control {
  width: 100%;
  background: rgba(0, 0, 0, 0.3);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.7rem 1rem;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.15s ease;
}

.form-control:focus {
  outline: none;
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.2);
}

.form-hint {
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-top: 0.4rem;
}

.code-input {
  font-family: var(--font-mono);
  font-size: 1.5rem;
  letter-spacing: 0.35em;
  text-align: center;
  text-transform: uppercase;
  font-weight: 700;
}

/* Chat Room View */
.chat-container {
  display: flex;
  flex-direction: column;
  height: calc(100vh - 72px);
  height: calc(100dvh - 72px);
  max-width: 1000px;
  width: 100%;
  margin: 0 auto;
  padding: 1rem;
}

.chat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  display: flex;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  box-shadow: var(--shadow-md);
  min-height: 0;
}

.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(0, 0, 0, 0.2);
  gap: 0.75rem;
  flex-wrap: wrap;
}

.chat-room-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  flex-wrap: wrap;
  min-width: 0;
  flex: 1 1 auto;
}

.chat-room-title {
  font-size: 1.15rem;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 100%;
}

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-wrap: wrap;
  flex-shrink: 0;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  scroll-behavior: smooth;
  min-height: 0;
}

/* Message Bubbles */
.message-row {
  display: flex;
  flex-direction: column;
  max-width: 75%;
}

.message-row.self {
  align-self: flex-end;
  align-items: flex-end;
}

.message-row.other {
  align-self: flex-start;
  align-items: flex-start;
}

.message-sender {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-bottom: 0.25rem;
  display: flex;
  gap: 0.4rem;
}

.message-bubble {
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  font-size: 0.95rem;
  line-height: 1.45;
  word-break: break-word;
  box-shadow: var(--shadow-sm);
  position: relative;
}

.message-row.self .message-bubble {
  background: var(--accent-gradient);
  color: #ffffff;
  border-bottom-right-radius: 2px;
}

.message-row.other .message-bubble {
  background: var(--bg-surface-hover);
  color: var(--text-primary);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 2px;
}

.message-time {
  font-size: 0.7rem;
  color: rgba(255, 255, 255, 0.6);
  margin-top: 0.25rem;
  text-align: right;
}

.message-row.other .message-time {
  color: var(--text-muted);
}

.system-message {
  align-self: center;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid rgba(255, 255, 255, 0.08);
  border-radius: var(--radius-full);
  padding: 0.25rem 0.85rem;
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: center;
  margin: 0.5rem 0;
  max-width: 90%;
  word-break: break-word;
}

.typing-indicator-bar {
  padding: 0.35rem 1.5rem;
  font-size: 0.8rem;
  color: var(--text-muted);
  min-height: 24px;
  font-style: italic;
}

/* Chat Input Bar */
.chat-input-area {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  background: rgba(0, 0, 0, 0.2);
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.emoji-bar {
  display: flex;
  gap: 0.4rem;
  flex-wrap: wrap;
  align-items: center;
}

.emoji-btn {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.25rem 0.5rem;
  font-size: 1.1rem;
  cursor: pointer;
  transition: transform 0.1s ease;
  min-width: 38px;
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.emoji-btn:hover {
  transform: scale(1.12);
  background: rgba(255, 255, 255, 0.12);
}

.input-row {
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.chat-input {
  flex: 1;
  background: rgba(0, 0, 0, 0.35);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1rem;
  color: var(--text-primary);
  font-family: inherit;
  font-size: 0.95rem;
  resize: none;
  outline: none;
  min-height: 44px;
}

.chat-input:focus {
  border-color: var(--border-focus);
}

.char-counter {
  font-size: 0.75rem;
  color: var(--text-muted);
  text-align: right;
}

/* Members List in Modal */
.members-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  max-height: 280px;
  overflow-y: auto;
}

.member-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.6rem 0.8rem;
  background: rgba(255, 255, 255, 0.03);
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-color);
  gap: 0.5rem;
}

.member-info {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Invitation Page Card */
.invite-container {
  max-width: 440px;
  width: 100%;
  margin: 4rem auto;
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 2.5rem 2rem;
  box-shadow: var(--shadow-lg);
  text-align: center;
}

.invite-icon {
  font-size: 3rem;
  margin-bottom: 1rem;
}

/* Toast Component */
.toast-container {
  position: fixed;
  bottom: 2rem;
  right: 2rem;
  z-index: 200;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  pointer-events: none;
}

.toast {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-sm);
  padding: 0.75rem 1.25rem;
  color: var(--text-primary);
  font-size: 0.9rem;
  box-shadow: var(--shadow-md);
  display: flex;
  align-items: center;
  gap: 0.6rem;
  animation: toastIn 0.25s ease forwards;
  pointer-events: auto;
  max-width: 380px;
  word-break: break-word;
}

.toast-success {
  border-left: 4px solid #10b981;
}

.toast-error {
  border-left: 4px solid #ef4444;
}

.toast-info {
  border-left: 4px solid #6366f1;
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(12px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

/* ==========================================================================
   Responsive Breakpoints System (AGENTS.md 4.9.1 规范)
   - 平板端: 768px <= width <= 1024px
   - 手机端: < 768px
   - 极窄屏: < 360px
   ========================================================================== */

/* 1. 平板适配 (768px – 1024px) */
@media (min-width: 768px) and (max-width: 1024px) {
  .container {
    padding: 1.5rem 1.25rem;
  }
  .rooms-grid {
    grid-template-columns: repeat(2, 1fr);
    gap: 1.25rem;
  }
  .chat-container {
    padding: 0.75rem;
    height: calc(100vh - 68px);
    height: calc(100dvh - 68px);
  }
  .chat-header {
    padding: 0.85rem 1.25rem;
  }
}

/* 2. 手机适配 (< 768px) */
@media (max-width: 767px) {
  .header {
    padding: 0.65rem 1rem;
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .brand {
    font-size: 1.05rem;
    gap: 0.5rem;
  }

  .brand-icon {
    width: 30px;
    height: 30px;
    font-size: 1rem;
  }

  .user-profile {
    gap: 0.5rem;
    flex-wrap: wrap;
  }

  .user-badge {
    padding: 0.25rem 0.6rem;
    font-size: 0.8rem;
  }

  .container {
    padding: 1rem 0.85rem;
  }

  .page-toolbar {
    margin-bottom: 1.25rem;
    flex-direction: column;
    align-items: stretch;
    gap: 0.75rem;
  }

  .page-toolbar > div:last-child {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
    width: 100%;
  }

  .page-toolbar > div:last-child .btn {
    width: 100%;
    min-height: 44px;
  }

  .page-title {
    font-size: 1.35rem;
  }

  .rooms-grid {
    grid-template-columns: 1fr;
    gap: 1rem;
  }

  .room-card {
    padding: 1.25rem 1rem;
  }

  .room-card-actions {
    flex-wrap: wrap;
    gap: 0.5rem;
  }

  .room-card-actions .btn {
    min-height: 44px;
  }

  /* 聊天室页面移动端铺满视口 */
  .chat-container {
    padding: 0;
    height: calc(100vh - 60px);
    height: calc(100dvh - 60px);
  }

  .chat-card {
    border-radius: 0;
    border-left: none;
    border-right: none;
    border-bottom: none;
  }

  .chat-header {
    padding: 0.65rem 0.85rem;
    gap: 0.5rem;
  }

  .chat-room-info {
    width: 100%;
    justify-content: flex-start;
  }

  .chat-header-actions {
    width: 100%;
    justify-content: space-between;
  }

  .chat-header-actions .btn {
    flex: 1;
    min-height: 38px;
    padding: 0.4rem 0.5rem;
    font-size: 0.8rem;
  }

  .chat-messages {
    padding: 0.85rem 0.75rem;
    gap: 0.75rem;
  }

  .message-row {
    max-width: 90%;
  }

  .chat-input-area {
    padding: 0.65rem 0.75rem;
    gap: 0.5rem;
  }

  .emoji-bar {
    overflow-x: auto;
    flex-wrap: nowrap;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 0.25rem;
  }

  .emoji-btn {
    min-width: 44px;
    min-height: 40px;
    flex-shrink: 0;
    font-size: 1.15rem;
  }

  .input-row .btn {
    min-height: 44px;
    min-width: 68px;
    padding: 0.6rem 1rem;
  }

  .typing-indicator-bar {
    padding: 0.25rem 0.85rem;
  }

  /* 邀请与秘密卡片 */
  .invite-container {
    margin: 1.5rem auto;
    padding: 1.75rem 1.25rem;
    border-radius: var(--radius-md);
  }

  .invite-icon {
    font-size: 2.5rem;
    margin-bottom: 0.75rem;
  }

  /* 弹窗在移动端适配 */
  .modal-backdrop {
    padding: 0.5rem;
    align-items: flex-end;
  }

  .modal {
    max-width: 100%;
    margin: 0;
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
  }

  .modal-header {
    padding: 1rem 1.25rem;
  }

  .modal-body {
    padding: 1.25rem;
  }

  .modal-footer {
    padding: 0.85rem 1.25rem;
    flex-direction: column-reverse;
    gap: 0.6rem;
  }

  .modal-footer .btn {
    width: 100%;
    min-height: 44px;
  }

  /* Toast 移动端居中 */
  .toast-container {
    left: 1rem;
    right: 1rem;
    bottom: 1rem;
    align-items: center;
  }

  .toast {
    width: 100%;
    max-width: 100%;
  }
}

/* 3. 极窄屏适配 (< 360px) */
@media (max-width: 359px) {
  .brand span {
    font-size: 0.95rem;
  }

  .code-input {
    font-size: 1.2rem;
    letter-spacing: 0.18em;
  }

  .message-row {
    max-width: 94%;
  }

  .message-bubble {
    font-size: 0.9rem;
    padding: 0.6rem 0.75rem;
  }
}
