/* ===== Global Reset & Variables ===== */

:root {
  --color-bg: #f0f2f5;
  --color-surface: #ffffff;
  --color-primary: #4f46e5;
  --color-primary-hover: #4338ca;
  --color-text: #1e1e2f;
  --color-text-light: #6b7280;
  --color-border: #e5e7eb;
  --color-error: #dc2626;
  --color-success: #16a34a;
  --color-own-msg: #eef2ff;
  --sidebar-width: 260px;
  --radius: 8px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen,
    Ubuntu, Cantarell, 'Helvetica Neue', sans-serif;
  background: var(--color-bg);
  color: var(--color-text);
  min-height: 100vh;
}

.hidden { display: none !important; }

/* ===== Auth Page ===== */

.auth-container {
  max-width: 400px;
  margin: 80px auto;
  padding: 32px;
  background: var(--color-surface);
  border-radius: var(--radius);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.auth-container h1 {
  text-align: center;
  margin-bottom: 24px;
  font-size: 28px;
  color: var(--color-primary);
}

/* Tabs */
.tabs {
  display: flex;
  margin-bottom: 24px;
  border-bottom: 2px solid var(--color-border);
}

.tab {
  flex: 1;
  padding: 10px;
  background: none;
  border: none;
  cursor: pointer;
  font-size: 15px;
  font-weight: 500;
  color: var(--color-text-light);
  transition: color 0.2s;
}

.tab.active {
  color: var(--color-primary);
  border-bottom: 2px solid var(--color-primary);
  margin-bottom: -2px;
}

/* Forms */
.auth-form label {
  display: block;
  margin-bottom: 4px;
  font-size: 14px;
  font-weight: 500;
}

.auth-form input {
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 16px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
}

.auth-form input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.btn-primary {
  width: 100%;
  padding: 10px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-primary:hover { background: var(--color-primary-hover); }

.error { color: var(--color-error); font-size: 13px; margin-top: 8px; }
.success { color: var(--color-success); font-size: 13px; margin-top: 8px; }

/* ===== Chat Page ===== */

.chat-wrapper {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.sidebar {
  width: var(--sidebar-width);
  background: var(--color-surface);
  border-right: 1px solid var(--color-border);
  display: flex;
  flex-direction: column;
}

.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px;
  border-bottom: 1px solid var(--color-border);
}

.sidebar-header h2 {
  font-size: 18px;
}

.btn-icon {
  background: none;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  width: 32px;
  height: 32px;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.2s;
}

.btn-icon:hover { background: var(--color-bg); }

/* Room list */
.room-list {
  flex: 1;
  list-style: none;
  overflow-y: auto;
  padding: 8px 0;
}

.room-list li {
  padding: 10px 16px;
  cursor: pointer;
  font-size: 14px;
  transition: background 0.15s;
}

.room-list li:hover { background: var(--color-bg); }
.room-list li.active {
  background: var(--color-primary);
  color: #fff;
  font-weight: 600;
}

/* Sidebar footer */
.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--color-border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-size: 13px;
}

.user-email {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 140px;
  color: var(--color-text-light);
}

.btn-small {
  padding: 6px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  background: var(--color-surface);
  cursor: pointer;
  font-size: 12px;
  transition: background 0.2s;
}

.btn-small:hover { background: var(--color-bg); }

/* Chat main */
.chat-main {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chat-header {
  padding: 16px 20px;
  border-bottom: 1px solid var(--color-border);
  background: var(--color-surface);
}

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

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

.message {
  max-width: 70%;
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--color-surface);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06);
  align-self: flex-start;
}

.message.own {
  align-self: flex-end;
  background: var(--color-own-msg);
}

.message-author {
  display: block;
  font-size: 12px;
  font-weight: 600;
  color: var(--color-primary);
  margin-bottom: 2px;
}

.message-text {
  display: block;
  font-size: 14px;
  word-wrap: break-word;
}

.message-time {
  display: block;
  font-size: 11px;
  color: var(--color-text-light);
  text-align: right;
  margin-top: 4px;
}

/* Message input */
.message-form {
  display: flex;
  padding: 12px 20px;
  border-top: 1px solid var(--color-border);
  background: var(--color-surface);
  gap: 8px;
}

.message-form input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
}

.message-form input:focus {
  outline: none;
  border-color: var(--color-primary);
  box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.15);
}

.btn-send {
  padding: 10px 20px;
  background: var(--color-primary);
  color: #fff;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s;
}

.btn-send:hover { background: var(--color-primary-hover); }
.btn-send:disabled,
.message-form input:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* Dialog */
.dialog-overlay {
  position: fixed;
  top: 0; left: 0; right: 0; bottom: 0;
  background: rgba(0, 0, 0, 0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}

.dialog {
  background: var(--color-surface);
  padding: 24px;
  border-radius: var(--radius);
  width: 360px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
}

.dialog h3 { margin-bottom: 16px; }

.dialog input {
  width: 100%;
  padding: 10px 12px;
  border: 1px solid var(--color-border);
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 12px;
}

.dialog input:focus {
  outline: none;
  border-color: var(--color-primary);
}

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

/* ===== Responsive ===== */

@media (max-width: 640px) {
  .chat-wrapper { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    max-height: 200px;
    border-right: none;
    border-bottom: 1px solid var(--color-border);
  }
  .room-list { display: flex; overflow-x: auto; padding: 0 8px; }
  .room-list li { white-space: nowrap; }
  .message { max-width: 90%; }
}
