:root {
  --primary-color: #3390ec;
  --primary-color-rgb: 51, 144, 236;
  --sidebar-bg: #ffffff;
  --chat-bg: #96afc0; /* Placeholder for pattern */
  --chat-header-bg: #ffffff;
  --chat-header-text: #000000;
  --text-color: #000000;
  --text-muted: #707579;
  --bubble-in-bg: #ffffff;
  --bubble-out-bg: #eeffde;
  --bubble-shadow: 0 1px 2px rgba(114, 114, 114, 0.25);
  --input-bg: #ffffff;
  --border-color: #dfe1e5;
  --accent-blue: #0088cc;
  --creator-grad: linear-gradient(90deg, #ff375f, #ff9f0a, #32d74b, #0a84ff, #bf5af2);
}

* { box-sizing: border-box; -webkit-font-smoothing: antialiased; }

body {
  margin: 0;
  height: 100vh;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color: var(--text-color);
  background: #f4f4f5;
  overflow: hidden;
}

.app {
  width: 100%;
  max-width: 1600px;
  margin: 0 auto;
  height: 100vh;
  display: flex;
  background: var(--sidebar-bg);
}

/* Auth / Login Card */
.login-card {
  margin: auto;
  width: 100%;
  max-width: 400px;
  padding: 40px;
  background: #fff;
  border-radius: 20px;
  box-shadow: 0 10px 25px rgba(0,0,0,0.05);
  text-align: center;
}

.login-card h1 { font-size: 24px; margin-bottom: 8px; }
.login-card p { color: var(--text-muted); margin-bottom: 24px; }

/* Main Layout */
.layout {
  display: flex;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

/* Sidebar */
.sidebar {
  width: 320px;
  min-width: 320px;
  height: 100%;
  background: var(--sidebar-bg);
  border-right: 1px solid var(--border-color);
  display: flex;
  flex-direction: column;
  z-index: 10;
}

.sidebar-header {
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 16px;
  height: 56px;
}

.burger-menu {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  gap: 4px;
  cursor: pointer;
  transition: background 0.2s;
}

.burger-menu:hover { background: rgba(0,0,0,0.05); }

.burger-line { width: 18px; height: 2px; background: var(--text-muted); border-radius: 1px; }

.search-bar {
  flex: 1;
  background: #f4f4f5;
  border-radius: 22px;
  padding: 8px 16px;
  display: flex;
  align-items: center;
}

.search-bar input {
  border: none;
  background: transparent;
  outline: none;
  width: 100%;
  font-size: 15px;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 4px 0;
}

.chat-item {
  display: flex;
  padding: 8px 12px;
  margin: 0 8px;
  border-radius: 12px;
  cursor: pointer;
  transition: background 0.1s;
  align-items: center;
  gap: 12px;
}

.chat-item:hover { background: #f4f4f5; }
.chat-item.active { background: var(--primary-color); color: #fff; }

.chat-item-avatar {
  width: 54px;
  height: 54px;
  border-radius: 50%;
  background: var(--primary-color);
  display: grid;
  place-items: center;
  font-size: 20px;
  color: #fff;
  flex-shrink: 0;
}

.chat-item-info {
  flex: 1;
  min-width: 0;
}

.chat-item-top {
  display: flex;
  justify-content: space-between;
  margin-bottom: 2px;
}

.chat-item-name { font-weight: 600; font-size: 16px; }
.chat-item-time { font-size: 13px; color: var(--text-muted); }
.active .chat-item-time { color: #fff; opacity: 0.8; }

.chat-item-msg {
  font-size: 15px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.active .chat-item-msg { color: #fff; opacity: 0.9; }

/* Online List in Sidebar */
.sidebar-online-section {
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
}

.sidebar-online-title {
  font-size: 14px;
  font-weight: 600;
  color: var(--primary-color);
  margin-bottom: 12px;
}

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

.online-user {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 8px;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
}

.online-user:hover { background: #f4f4f5; }

.online-avatar-shell {
  position: relative;
  width: 32px;
  height: 32px;
}

.online-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  object-fit: cover;
}

.online-status-dot {
  position: absolute;
  right: -1px;
  bottom: -1px;
  width: 10px;
  height: 10px;
  background: #31b333;
  border: 2px solid #fff;
  border-radius: 50%;
}

.online-name { font-size: 14px; font-weight: 500; }

/* Chat Main Area */
.chat-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  background-color: var(--chat-bg);
  background-image: url('https://telegram.org/img/t_wallpaper.png'); /* Standard pattern */
  background-attachment: fixed;
  position: relative;
  overflow: hidden;
}

.chat-head {
  height: 56px;
  background: var(--chat-header-bg);
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  padding: 0 20px;
  z-index: 5;
}

.chat-info {
  flex: 1;
  display: flex;
  flex-direction: column;
}

.chat-title { font-size: 16px; font-weight: 600; color: #000; }
.chat-state { font-size: 13px; color: var(--text-muted); }

/* Messages Area */
.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  scroll-behavior: smooth;
}

.messages::-webkit-scrollbar { width: 6px; }
.messages::-webkit-scrollbar-thumb { background: rgba(0,0,0,0.2); border-radius: 3px; }

.msg {
  max-width: 85%;
  display: flex;
  align-items: flex-end;
  gap: 8px;
  margin-bottom: 4px;
}

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

.msg .avatar {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  flex-shrink: 0;
}

.bubble {
  padding: 6px 12px 6px;
  border-radius: 12px;
  background: var(--bubble-in-bg);
  box-shadow: 0 1px 2px rgba(114, 114, 114, 0.25);
  position: relative;
  min-width: 80px;
  max-width: 100%;
}

.msg.own-msg .bubble {
  background: var(--bubble-out-bg);
  border-bottom-right-radius: 2px;
}

.msg:not(.own-msg) .bubble {
  border-bottom-left-radius: 2px;
}

.bubble .meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 2px;
}

.bubble .meta strong { font-size: 13.5px; font-weight: 600; color: #3390ec; }
.bubble .meta span { display: none; }
.bubble .meta time {
  font-size: 11px;
  color: #a0acb6;
  position: absolute;
  right: 8px;
  bottom: 4px;
  pointer-events: none;
}

.msg.own-msg .bubble .meta time { color: #5f9b5f; }
.msg.own-msg .bubble .meta strong { display: none; }

.text {
  font-size: 15px;
  line-height: 1.45;
  word-break: break-word;
  padding-right: 30px; /* Space for time */
  color: #000;
}

/* Attachments */
.media-card {
  margin-top: 4px;
  border-radius: 8px;
  overflow: hidden;
  max-width: 100%;
  cursor: pointer;
  background: #f1f1f1;
}

/* Input Area */
.send-container {
  padding: 0 0 20px 0;
  display: flex;
  justify-content: center;
  background: transparent;
  pointer-events: none;
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  z-index: 10;
}

.send-form {
  pointer-events: all;
  width: 100%;
  max-width: 700px;
  background: var(--input-bg);
  border-radius: 12px;
  display: flex;
  align-items: flex-end;
  padding: 8px 12px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.1);
  gap: 8px;
  margin: 0 10px;
}

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px 100px; /* Padding for input */
  display: flex;
  flex-direction: column;
  gap: 6px;
  scroll-behavior: smooth;
}

.file-pick {
  width: 40px;
  height: 40px;
  display: grid;
  place-items: center;
  cursor: pointer;
  color: var(--text-muted);
  font-size: 24px;
  border-radius: 50%;
  transition: background 0.2s;
}

.file-pick:hover { background: #f4f4f5; }

.send-form input[type="text"] {
  flex: 1;
  border: none;
  outline: none;
  padding: 10px 4px;
  font-size: 16px;
  background: transparent;
  max-height: 120px;
}

.send-btn {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: none;
  background: transparent;
  color: var(--primary-color);
  cursor: pointer;
  display: grid;
  place-items: center;
  transition: background 0.2s, transform 0.2s;
}

.send-btn:hover { background: #f4f4f5; transform: scale(1.05); }

.send-btn svg { width: 24px; height: 24px; fill: currentColor; }

/* Toast & Viewer Styles... (simplified or kept) */
.toast-stack { position: fixed; bottom: 80px; left: 50%; transform: translateX(-50%); z-index: 100; display: flex; flex-direction: column; gap: 8px; }
.toast { background: rgba(0,0,0,0.7); color: #fff; padding: 8px 20px; border-radius: 20px; font-size: 14px; animation: toast-in 0.2s ease-out; }

@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

.media-viewer { position: fixed; inset: 0; z-index: 1000; background: rgba(0,0,0,0.9); display: flex; flex-direction: column; align-items: center; justify-content: center; }
.media-viewer.hidden { display: none; }
.media-close { position: absolute; top: 20px; right: 20px; color: #fff; font-size: 30px; cursor: pointer; background: transparent; border: none; }

.sidebar-footer {
  padding: 12px 16px;
  border-top: 1px solid var(--border-color);
  margin-top: auto;
}

.logout-btn {
  width: 100%;
  padding: 10px;
  border-radius: 8px;
  border: 1px solid #f2f2f2;
  background: #fff;
  cursor: pointer;
  color: #e53935;
  font-weight: 500;
  font-size: 14px;
  transition: background 0.2s;
}

.logout-btn:hover {
  background: #fff5f5;
  border-color: #ffcdd2;
}
  .sidebar { display: none; }
  .app { margin: 0; height: 100vh; }
  .send-container { padding: 8px; }
  .msg { max-width: 92%; }
}
