/* Mobile-first CompanyChat Styling */
:root {
  --bg-primary: #0f172a;
  --bg-secondary: #1e293b;
  --bg-tertiary: #334155;
  --text-primary: #f8fafc;
  --text-secondary: #94a3b8;
  --text-muted: #64748b;
  --accent-color: #2563eb;
  --accent-hover: #1d4ed8;
  --bubble-incoming: #1e293b;
  --bubble-outgoing: #1d4ed8;
  --border-color: #334155;
  --online-green: #22c55e;
  --danger-color: #ef4444;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background-color: var(--bg-primary);
  color: var(--text-primary);
  height: 100dvh;
  width: 100vw;
  overflow: hidden;
  user-select: none;
}

#app {
  display: flex;
  height: 100%;
  width: 100%;
  position: relative;
}

/* ==================== LOGIN VIEW ==================== */
.login-overlay {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at top, #1e293b, #0f172a);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
}

.login-card {
  background: var(--bg-secondary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 32px 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.4);
}

.login-icon {
  width: 64px;
  height: 64px;
  background: var(--accent-color);
  border-radius: 18px;
  margin: 0 auto 16px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 32px;
}

.login-title {
  font-size: 22px;
  font-weight: 700;
  margin-bottom: 6px;
}

.login-subtitle {
  font-size: 14px;
  color: var(--text-secondary);
  margin-bottom: 24px;
}

.login-input-group {
  position: relative;
  margin-bottom: 16px;
}

.login-input {
  width: 100%;
  padding: 14px 16px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 12px;
  color: #fff;
  font-size: 16px;
  outline: none;
  transition: border-color 0.2s;
}

.login-input:focus {
  border-color: var(--accent-color);
}

.login-btn {
  width: 100%;
  padding: 14px;
  background: var(--accent-color);
  color: #fff;
  border: none;
  border-radius: 12px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.2s, transform 0.1s;
}

.login-btn:active {
  transform: scale(0.98);
}

.login-error {
  color: var(--danger-color);
  font-size: 13px;
  margin-top: 12px;
  display: none;
}

/* ==================== MAIN LAYOUT ==================== */
.sidebar-panel {
  width: 100%;
  height: 100%;
  display: flex;
  flex-direction: column;
  background: var(--bg-primary);
  border-right: 1px solid var(--border-color);
  padding-top: var(--safe-top);
  z-index: 10;
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-panel {
  position: absolute;
  inset: 0;
  background: var(--bg-primary);
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-top);
  z-index: 20;
  transform: translateX(100%);
  transition: transform 0.25s cubic-bezier(0.16, 1, 0.3, 1);
}

.chat-panel.active {
  transform: translateX(0);
}

@media (min-width: 768px) {
  .sidebar-panel {
    width: 380px;
    flex-shrink: 0;
  }
  .chat-panel {
    position: relative;
    transform: none !important;
    flex: 1;
  }
}

/* ==================== HEADER ==================== */
.app-header {
  height: 60px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  flex-shrink: 0;
}

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

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  object-fit: cover;
  background: var(--bg-tertiary);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 600;
  color: #fff;
  font-size: 16px;
  position: relative;
}

.avatar.online::after {
  content: "";
  position: absolute;
  bottom: 0;
  right: 0;
  width: 11px;
  height: 11px;
  background: var(--online-green);
  border-radius: 50%;
  border: 2px solid var(--bg-secondary);
}

.user-info-text .name {
  font-size: 15px;
  font-weight: 600;
}

.user-info-text .status {
  font-size: 12px;
  color: var(--online-green);
}

.icon-btn {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 20px;
  padding: 8px;
  cursor: pointer;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active {
  background: var(--bg-tertiary);
}

/* ==================== TABS & SEARCH ==================== */
.search-bar {
  padding: 8px 16px;
  background: var(--bg-secondary);
}

.search-input {
  width: 100%;
  padding: 8px 14px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 10px;
  color: #fff;
  font-size: 14px;
  outline: none;
}

.dialog-tabs {
  display: flex;
  padding: 4px 16px 8px;
  background: var(--bg-secondary);
  gap: 8px;
  border-bottom: 1px solid var(--border-color);
}

.tab-btn {
  flex: 1;
  padding: 6px 0;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 13px;
  font-weight: 500;
  border-radius: 8px;
  cursor: pointer;
}

.tab-btn.active {
  background: var(--bg-tertiary);
  color: #fff;
  font-weight: 600;
}

/* ==================== DIALOG LIST ==================== */
.dialog-list {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.dialog-item {
  display: flex;
  align-items: center;
  padding: 12px 16px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.04);
  cursor: pointer;
  gap: 12px;
}

.dialog-item:active, .dialog-item.selected {
  background: var(--bg-secondary);
}

.dialog-content {
  flex: 1;
  min-width: 0;
}

.dialog-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 4px;
}

.dialog-name {
  font-size: 15px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.dialog-time {
  font-size: 11px;
  color: var(--text-muted);
}

.dialog-sub {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.dialog-last-msg {
  font-size: 13px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
}

.unread-badge {
  background: var(--accent-color);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 10px;
  margin-left: 8px;
}

/* ==================== CHAT VIEW ==================== */
.chat-header {
  height: 60px;
  display: flex;
  align-items: center;
  padding: 0 12px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border-color);
  gap: 12px;
}

.chat-title-group {
  flex: 1;
  min-width: 0;
}

.chat-title {
  font-size: 16px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.chat-status {
  font-size: 12px;
  color: var(--text-secondary);
}

.messages-container {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  -webkit-overflow-scrolling: touch;
}

.message-bubble {
  max-width: 82%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  position: relative;
  word-break: break-word;
  user-select: text;
}

.message-bubble.incoming {
  align-self: flex-start;
  background: var(--bubble-incoming);
  border: 1px solid var(--border-color);
  border-bottom-left-radius: 4px;
}

.message-bubble.outgoing {
  align-self: flex-end;
  background: var(--bubble-outgoing);
  border-bottom-right-radius: 4px;
  color: #fff;
}

.msg-sender {
  font-size: 12px;
  font-weight: 600;
  color: #60a5fa;
  margin-bottom: 4px;
}

.msg-quote {
  background: rgba(0, 0, 0, 0.2);
  border-left: 3px solid #60a5fa;
  padding: 4px 8px;
  border-radius: 4px;
  font-size: 12px;
  margin-bottom: 6px;
}

.msg-quote .q-author {
  font-weight: 600;
  color: #93c5fd;
}

.msg-quote .q-text {
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.msg-meta {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  font-size: 10px;
  color: var(--text-muted);
  margin-top: 4px;
}

.message-bubble.outgoing .msg-meta {
  color: rgba(255, 255, 255, 0.7);
}

/* ==================== FILE CARD ==================== */
.file-card {
  display: flex;
  align-items: center;
  background: rgba(0, 0, 0, 0.2);
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 10px;
  padding: 10px;
  margin-top: 6px;
  gap: 10px;
}

.file-icon {
  font-size: 24px;
}

.file-details {
  flex: 1;
  min-width: 0;
}

.file-name {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.file-download-btn {
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: #fff;
  padding: 6px 12px;
  border-radius: 8px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  gap: 4px;
  text-decoration: none;
}

.file-download-btn:active {
  background: rgba(255, 255, 255, 0.3);
}

/* ==================== INPUT BAR ==================== */
.chat-input-wrapper {
  background: var(--bg-secondary);
  border-top: 1px solid var(--border-color);
  padding: 8px 12px;
  padding-bottom: calc(8px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
}

.reply-preview {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: var(--bg-tertiary);
  border-left: 3px solid var(--accent-color);
  padding: 6px 10px;
  border-radius: 6px;
  margin-bottom: 8px;
  font-size: 12px;
}

.reply-preview .rp-text {
  flex: 1;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.reply-preview .rp-close {
  background: transparent;
  border: none;
  color: var(--text-secondary);
  cursor: pointer;
  font-size: 16px;
  padding: 0 4px;
}

.input-row {
  display: flex;
  align-items: flex-end;
  gap: 8px;
}

.chat-input {
  flex: 1;
  max-height: 120px;
  min-height: 40px;
  background: var(--bg-primary);
  border: 1px solid var(--border-color);
  border-radius: 20px;
  padding: 10px 16px;
  color: #fff;
  font-size: 15px;
  outline: none;
  resize: none;
  line-height: 1.3;
}

.send-btn {
  width: 40px;
  height: 40px;
  background: var(--accent-color);
  border: none;
  border-radius: 50%;
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: transform 0.1s;
}

.send-btn:active {
  transform: scale(0.9);
}

/* ==================== SPINNER ==================== */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}
