/* ============================================================
   TempComm — Global Styles (Fluent Design System)
   ============================================================ */

/* ── Reset ──────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
}

body {
  font-family: var(--font-family);
  font-size: var(--font-base);
  color: var(--text-primary);
  background: var(--bg-primary);
  transition: background var(--transition-base), color var(--transition-base);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  outline: none;
  background: none;
  color: inherit;
}
button:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

input, textarea {
  font-family: inherit;
  font-size: inherit;
  color: var(--text-primary);
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  outline: none;
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}
input:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-light);
}
input::placeholder, textarea::placeholder {
  color: var(--text-tertiary);
}

::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: var(--border-strong);
  border-radius: 3px;
}
::-webkit-scrollbar-thumb:hover { background: var(--text-tertiary); }

/* ── Layout ─────────────────────────────────────────── */

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

#navbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--navbar-height);
  min-height: var(--navbar-height);
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  z-index: var(--z-navbar);
  transition: background var(--transition-base), border-color var(--transition-base);
}

.navbar-left, .navbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.navbar-brand {
  font-size: var(--font-lg);
  font-weight: 600;
  color: var(--text-primary);
  display: flex;
  align-items: center;
  gap: 8px;
}

.navbar-brand svg { color: var(--accent); }

.navbar-username {
  display: flex;
  align-items: center;
  gap: 6px;
}
.navbar-username input {
  width: 140px;
  height: 32px;
  padding: 4px 8px;
  font-size: var(--font-sm);
  background: var(--bg-tertiary);
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  transition: all var(--transition-fast);
}
.navbar-username input:hover { border-color: var(--border); }
.navbar-username input:focus {
  border-color: var(--accent);
  background: var(--bg-primary);
}

#theme-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}
#theme-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

/* ── Main layout: sidebar + content ─────────────────── */

#main {
  display: flex;
  flex: 1;
  min-height: 0;
}

#sidebar {
  width: var(--sidebar-width);
  min-width: var(--sidebar-width);
  display: flex;
  flex-direction: column;
  background: var(--bg-secondary);
  border-right: 1px solid var(--border);
  transition: all var(--transition-base);
  z-index: var(--z-sidebar);
}

.sidebar-header {
  padding: 12px 16px;
  font-size: var(--font-sm);
  font-weight: 600;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

#room-list {
  flex: 1;
  overflow-y: auto;
  padding: 0 8px;
}

.room-card {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  margin-bottom: 2px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  position: relative;
  border-left: 3px solid transparent;
}

.room-card:hover {
  background: var(--bg-tertiary);
}

.room-card.active {
  background: var(--accent-light);
  border-left-color: var(--accent);
}

.room-card.destroyed {
  opacity: 0.5;
  cursor: default;
}
.room-card.destroyed:hover {
  background: transparent;
}

.room-status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  flex-shrink: 0;
}
.room-status-dot.online {
  background: var(--online);
  animation: pulse-dot 2s infinite;
}
.room-status-dot.offline {
  background: var(--offline);
}

@keyframes pulse-dot {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

.room-card-info {
  flex: 1;
  min-width: 0;
}

.room-card-code {
  font-family: var(--font-mono);
  font-size: var(--font-base);
  font-weight: 600;
  color: var(--text-primary);
  letter-spacing: 1px;
}

.room-card-meta {
  font-size: var(--font-xs);
  color: var(--text-tertiary);
  margin-top: 1px;
}

.room-card-delete {
  opacity: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border-radius: var(--radius-sm);
  color: var(--text-tertiary);
  transition: all var(--transition-fast);
}
.room-card:hover .room-card-delete { opacity: 1; }
.room-card-delete:hover {
  background: var(--danger-light);
  color: var(--danger);
}

.sidebar-actions {
  padding: 8px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  border-top: 1px solid var(--border);
}

.sidebar-btn {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: var(--radius-md);
  font-size: var(--font-sm);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}
.sidebar-btn:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}
.sidebar-btn svg { width: 16px; height: 16px; }

/* ── Content area ───────────────────────────────────── */

#content {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-width: 0;
  background: var(--bg-primary);
  transition: background var(--transition-base);
}

/* Welcome / Setup view */
.view-welcome, .view-home, .view-success, .view-chat {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
}

.view-centered {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 1;
}

/* ── Welcome Card (first-time setup) ────────────────── */

.welcome-card {
  width: 100%;
  max-width: 400px;
  padding: 32px;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
  text-align: center;
}
.welcome-card h1 {
  font-size: var(--font-xl);
  font-weight: 600;
  margin-bottom: 8px;
}
.welcome-card p {
  color: var(--text-secondary);
  font-size: var(--font-base);
  margin-bottom: 24px;
  line-height: 1.5;
}
.welcome-card .input-group {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 16px;
  transition: border-color var(--transition-fast);
}
.welcome-card .input-group:focus-within {
  border-color: var(--accent);
}
.welcome-card .input-group svg {
  color: var(--text-tertiary);
  flex-shrink: 0;
}
.welcome-card .input-group input {
  flex: 1;
  border: none;
  padding: 10px 0;
  background: transparent;
  box-shadow: none;
}
.welcome-card .input-group input:focus {
  box-shadow: none;
}

/* ── Home / Create Room Cards ───────────────────────── */

.home-cards {
  display: flex;
  gap: 24px;
  max-width: 640px;
  width: 100%;
}

.action-card {
  flex: 1;
  padding: 24px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  text-align: center;
  transition: box-shadow var(--transition-fast);
}
.action-card:hover {
  box-shadow: var(--shadow-md);
}

.action-card-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border-radius: var(--radius-lg);
  background: var(--accent-light);
  color: var(--accent);
  margin-bottom: 12px;
}
.action-card-icon svg { width: 24px; height: 24px; }

.action-card h2 {
  font-size: var(--font-lg);
  font-weight: 600;
  margin-bottom: 4px;
}

.action-card .desc {
  font-size: var(--font-sm);
  color: var(--text-secondary);
  margin-bottom: 16px;
  line-height: 1.4;
}

.action-card .room-limit {
  font-size: var(--font-xs);
  color: var(--text-tertiary);
  margin-bottom: 12px;
}

.limit-bar {
  height: 4px;
  background: var(--bg-tertiary);
  border-radius: 2px;
  margin-bottom: 16px;
  overflow: hidden;
}
.limit-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  transition: width var(--transition-slow);
}
.limit-bar-fill.full { background: var(--danger); }

.action-card .code-input-wrapper {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 10px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  margin-bottom: 12px;
  transition: border-color var(--transition-fast);
}
.action-card .code-input-wrapper:focus-within {
  border-color: var(--accent);
}
.action-card .code-input-wrapper svg {
  color: var(--text-tertiary);
  flex-shrink: 0;
}
.action-card .code-input-wrapper input {
  flex: 1;
  border: none;
  padding: 9px 0;
  background: transparent;
  font-family: var(--font-mono);
  font-size: var(--font-lg);
  letter-spacing: 2px;
  text-transform: uppercase;
  text-align: center;
  box-shadow: none;
}
.action-card .code-input-wrapper input:focus { box-shadow: none; }

/* ── Buttons ─────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  padding: 8px 20px;
  border-radius: var(--radius-md);
  font-size: var(--font-base);
  font-weight: 500;
  transition: all var(--transition-fast);
  white-space: nowrap;
}

.btn-primary {
  background: var(--accent);
  color: #FFFFFF;
}
.btn-primary:hover {
  background: var(--accent-hover);
  box-shadow: var(--shadow-sm);
}
.btn-primary:active {
  background: var(--accent-pressed);
}
.btn-primary:disabled {
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  cursor: not-allowed;
  box-shadow: none;
}

.btn-secondary {
  background: transparent;
  color: var(--text-primary);
  border: 1px solid var(--border-strong);
}
.btn-secondary:hover {
  background: var(--bg-tertiary);
}
.btn-secondary:active {
  background: var(--border);
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
}
.btn-ghost:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}

.btn-accent-text {
  background: transparent;
  color: var(--accent-text);
}
.btn-accent-text:hover {
  background: var(--accent-light);
}

.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  transition: all var(--transition-fast);
}
.btn-icon:hover {
  background: var(--bg-tertiary);
  color: var(--text-primary);
}
.btn-icon svg { width: 18px; height: 18px; }

.btn-block { width: 100%; }

/* ── Success Card ────────────────────────────────────── */

.success-card {
  text-align: center;
  max-width: 420px;
  width: 100%;
  padding: 32px;
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-md);
}

.success-icon {
  animation: scale-in 0.35s cubic-bezier(0.16, 1, 0.3, 1);
  margin-bottom: 16px;
}
@keyframes scale-in {
  from { transform: scale(0); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.success-card h2 {
  font-size: var(--font-xl);
  font-weight: 600;
  margin-bottom: 4px;
}

.success-card .hint {
  font-size: var(--font-sm);
  color: var(--text-secondary);
  margin-bottom: 20px;
}

.room-code-display {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 24px;
}

.code-block {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 56px;
  background: var(--bg-tertiary);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  font-family: var(--font-mono);
  font-size: var(--font-2xl);
  font-weight: 600;
  letter-spacing: 1px;
  color: var(--text-primary);
}

.code-separator {
  color: var(--text-tertiary);
  font-size: var(--font-lg);
  font-weight: 300;
}

.success-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── Chat View ───────────────────────────────────────── */

#chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--chat-header-height);
  min-height: var(--chat-header-height);
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  transition: background var(--transition-base), border-color var(--transition-base);
}

.chat-header-room {
  display: flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
  color: var(--text-primary);
  transition: color var(--transition-fast);
}
.chat-header-room:hover { color: var(--accent); }
.chat-header-room .code {
  font-family: var(--font-mono);
  font-weight: 600;
  letter-spacing: 0.5px;
}
.chat-header-room .copy-icon { opacity: 0.4; }
.chat-header-room:hover .copy-icon { opacity: 1; }

.chat-header-status {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: var(--font-sm);
  color: var(--text-secondary);
}

.chat-header-spacer { flex: 1; }

.chat-header-actions {
  display: flex;
  align-items: center;
  gap: 4px;
}

/* ── Message List ────────────────────────────────────── */

#message-list {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.system-msg {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 0;
  font-size: var(--font-sm);
  color: var(--text-tertiary);
}
.system-msg::before, .system-msg::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--divider);
}

.msg-row {
  display: flex;
  gap: 10px;
  padding: 4px 0;
  max-width: 75%;
  animation: msg-in 0.15s ease-out;
}
@keyframes msg-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.msg-row.self {
  align-self: flex-end;
  flex-direction: row-reverse;
}

.msg-avatar {
  width: 32px;
  height: 32px;
  min-width: 32px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: var(--font-sm);
  font-weight: 600;
  color: #FFFFFF;
  background: var(--accent);
  flex-shrink: 0;
}

.msg-body {
  display: flex;
  flex-direction: column;
}

.msg-sender {
  font-size: var(--font-xs);
  font-weight: 600;
  color: var(--text-secondary);
  margin-bottom: 2px;
}
.msg-row.self .msg-sender { text-align: right; }

.msg-bubble {
  padding: 8px 14px;
  border-radius: var(--radius-lg);
  font-size: var(--font-base);
  line-height: 1.5;
  word-break: break-word;
  white-space: pre-wrap;
}

.msg-row:not(.self) .msg-bubble {
  background: var(--bg-secondary);
  color: var(--text-primary);
  border-top-left-radius: var(--radius-sm);
}

.msg-row.self .msg-bubble {
  background: var(--accent-light);
  color: var(--text-primary);
  border-top-right-radius: var(--radius-sm);
}

.msg-time {
  font-size: var(--font-xs);
  color: var(--text-tertiary);
  margin-top: 2px;
}
.msg-row.self .msg-time { text-align: right; }

.msg-image {
  max-width: 280px;
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: transform var(--transition-fast);
  border: 2px solid var(--border);
}
.msg-image:hover {
  transform: scale(1.02);
  border-color: var(--accent);
}

/* ── Input Area ──────────────────────────────────────── */

#chat-input-area {
  display: flex;
  align-items: flex-end;
  gap: 8px;
  padding: 10px 16px;
  min-height: var(--input-min-height);
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  transition: background var(--transition-base), border-color var(--transition-base);
}

#chat-input-area textarea {
  flex: 1;
  resize: none;
  min-height: 36px;
  max-height: 120px;
  padding: 8px 14px;
  background: var(--bg-tertiary);
  border: 1px solid transparent;
  border-radius: var(--radius-lg);
  font-size: var(--font-base);
  line-height: 1.4;
}
#chat-input-area textarea:focus {
  border-color: var(--accent);
  background: var(--bg-primary);
}

#send-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: var(--accent);
  color: #FFFFFF;
  transition: all var(--transition-fast);
  flex-shrink: 0;
}
#send-btn:hover { background: var(--accent-hover); transform: scale(1.05); }
#send-btn:active { background: var(--accent-pressed); transform: scale(0.95); }
#send-btn:disabled {
  background: var(--bg-tertiary);
  color: var(--text-tertiary);
  transform: none;
  cursor: not-allowed;
}

/* ── Reconnect Banner ────────────────────────────────── */

#reconnect-banner {
  display: none;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 8px 16px;
  background: var(--warning-light);
  color: var(--warning);
  font-size: var(--font-sm);
  font-weight: 500;
  border-bottom: 1px solid var(--warning);
  animation: slide-down 0.2s ease-out;
}
#reconnect-banner.visible { display: flex; }
@keyframes slide-down {
  from { transform: translateY(-100%); opacity: 0; }
  to { transform: translateY(0); opacity: 1; }
}

/* ── Room Destroyed Empty State ──────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  gap: 12px;
  color: var(--text-tertiary);
}
.empty-state svg { color: var(--text-tertiary); opacity: 0.5; }
.empty-state h3 {
  font-size: var(--font-lg);
  font-weight: 600;
  color: var(--text-secondary);
}
.empty-state p {
  font-size: var(--font-sm);
  color: var(--text-tertiary);
}

/* ── Toast Notifications ─────────────────────────────── */

#toast-container {
  position: fixed;
  top: 60px;
  right: 16px;
  z-index: var(--z-toast);
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  background: var(--bg-elevated);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-lg);
  font-size: var(--font-sm);
  pointer-events: auto;
  animation: toast-in 0.3s ease-out, toast-out 0.25s ease-in forwards;
  animation-delay: 0s, 3s;
  max-width: 360px;
}
@keyframes toast-in {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}
@keyframes toast-out {
  from { transform: translateX(0); opacity: 1; }
  to { transform: translateX(100%); opacity: 0; }
}

.toast-success { border-left: 3px solid var(--success); }
.toast-error { border-left: 3px solid var(--danger); }
.toast-info { border-left: 3px solid var(--info); }

/* ── Modal Overlay ───────────────────────────────────── */

.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: var(--z-modal);
  align-items: center;
  justify-content: center;
  animation: fade-in 0.2s ease-out;
}
.modal-overlay.visible { display: flex; }
@keyframes fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-box {
  background: var(--bg-elevated);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: 24px;
  min-width: 360px;
  max-width: 480px;
  animation: modal-in 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.95); }
  to { opacity: 1; transform: scale(1); }
}

.modal-box h3 {
  font-size: var(--font-lg);
  font-weight: 600;
  margin-bottom: 12px;
}

.modal-box .modal-body {
  margin-bottom: 16px;
  font-size: var(--font-base);
  color: var(--text-secondary);
}

.modal-actions {
  display: flex;
  gap: 8px;
  justify-content: flex-end;
}

/* ── Lightbox (image viewer) ─────────────────────────── */

#lightbox {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  z-index: var(--z-lightbox);
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
#lightbox.visible { display: flex; }

#lightbox img {
  max-width: 90vw;
  max-height: 90vh;
  border-radius: var(--radius-md);
  box-shadow: var(--shadow-xl);
}

#lightbox .close-btn {
  position: absolute;
  top: 16px;
  right: 16px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: rgba(255,255,255,0.15);
  color: #FFFFFF;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition-fast);
}
#lightbox .close-btn:hover { background: rgba(255,255,255,0.25); }

/* ── Status Bar ──────────────────────────────────────── */

#statusbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: var(--statusbar-height);
  min-height: var(--statusbar-height);
  padding: 0 12px;
  background: var(--bg-secondary);
  border-top: 1px solid var(--border);
  font-size: var(--font-xs);
  color: var(--text-tertiary);
}

/* ── Responsive: Mobile (≤768px) ─────────────────────── */

@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    left: 0;
    top: var(--navbar-height);
    bottom: 0;
    transform: translateX(-100%);
    box-shadow: var(--shadow-lg);
  }
  #sidebar.open { transform: translateX(0); }

  #sidebar-toggle {
    display: flex !important;
  }

  .home-cards {
    flex-direction: column;
    max-width: 100%;
    padding: 16px;
  }

  .msg-row { max-width: 90%; }

  #chat-input-area {
    padding: 8px 10px;
    gap: 6px;
  }

  .navbar-brand span { display: none; }
  .navbar-username input { width: 100px; }
}

#sidebar-toggle {
  display: none;
}

/* ── Utils ───────────────────────────────────────────── */

.hidden { display: none !important; }
.flex-center { display: flex; align-items: center; justify-content: center; }
.text-mono { font-family: var(--font-mono); }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
