/* ============================================================================
   GLOBAL RESET
   ============================================================================ */
* {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

body {
  font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
  background: #ffffff;
  height: 100vh;
  overflow: hidden;
  overscroll-behavior: none;
}

/* ============================================================================
   LOGIN SCREEN
   ============================================================================ */
.login-screen {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: linear-gradient(269deg, rgb(70, 54, 235), rgb(221, 62, 214));
}

.login-box {
  background: white;
  padding: 40px;
  border-radius: 15px;
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
  width: 100%;
  max-width: 400px;
}

.login-box h1 {
  text-align: center;
  margin-bottom: 30px;
  color: #333;
}

.login-box input {
  width: 100%;
  padding: 12px;
  margin-bottom: 15px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 14px;
  transition: border-color 0.3s;
}

.login-box input:focus {
  outline: none;
  border-color: #667eea;
}

.login-box button {
  width: 100%;
  padding: 12px;
  background: linear-gradient(269deg, rgb(70, 54, 235), rgb(221, 62, 214));
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s;
}

.login-box button:hover {
  transform: translateY(-2px);
}

.error {
  color: #f44336;
  font-size: 14px;
  margin-top: 10px;
  text-align: center;
}

/* ============================================================================
   DASHBOARD
   ============================================================================ */
.dashboard {
  display: flex;
  flex-direction: column;
  height: 100vh;
}

/* ============================================================================
   DASHBOARD HEADER
   ============================================================================ */
.dashboard-header {
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    gap: 3px;
    padding: 1px 15px;
    background: #ffffff;
    box-shadow: 0 2px 36px rgba(0, 0, 0, 0.27);
    position: relative;
    z-index: 10;

}

/* LEFT COLUMN */
.dashboard-header .header-left h1 {
  margin: 0;
  font-size: 16px;
}

/* CENTER COLUMN */
.dashboard-header .center-block {
  display: flex;
  justify-content: center;
  align-items: center;
  width: 100%;
}

.dashboard-header .middle-items {
  display: flex;
  flex-wrap: wrap;
  justify-content: center; /* center all items horizontally */
  align-items: center;     /* center vertically */
  gap: 8px;
  text-align: center;
}

.dashboard-header .middle-items > * {
  flex: 0 1 auto;          /* take only as much width as needed */
  display: flex;
  justify-content: center;
  align-items: center;
}


/* RIGHT COLUMN */
.dashboard-header .header-right {
  display: flex;
  justify-content: flex-end;
  align-items: center;
}


/* BACK BUTTON */
#mobile-back-btn {
    display: none;
    padding: 2px 6px;
    font-size: 19px;
    border-radius: 5px;
    border: 1px solid #a4d1bb;
    background: #c5f0ea;
    color: #000000;
    cursor: pointer;
    width: 20px !important;
    min-width: 25px;
    max-width: 25px;
    height: 25px !important;
    min-height: 25px;
    max-height: 25px;

}


/* Active chats shouldn't take full width */
.active-chats {
    /* flex: 0 1 auto; */
    padding: 2px 5px;
    font-size: 12px;
    border-radius: 5px;
    background: #29b92b;
    color: #fff;
    width: 100px;
    text-align: center;
}


/* Right: menu button */
.dashboard-header #menu-toggle-btn {
  justify-self: end;
  background: transparent;
  font-size: 20px;
  border: none;
  cursor: pointer;
  color: inherit;
}

/* Center block items styling */
.center-block button,
.center-block p,
.center-block .chat-header {
  flex: 1 1 auto;
  min-width: 40px;
}

/* ============================================================================
   HEADER ACTIONS MENU
   ============================================================================ */
.header-actions {
  position: fixed;
  top: 0;
  right: 0;
  width: 280px;
  max-width: 90%;
  height: 100dvh;
  background: #ffffff;
  box-shadow: -6px 0 20px rgba(0,0,0,0.25);
  padding: 16px;
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-auto-rows: min-content;
  gap: 10px;
  transform: translateX(100%);
  transition: transform 0.3s ease;
  z-index: 4000;
}

.header-actions.menu-open {
  transform: translateX(0);
}

.header-actions input,
.header-actions .status {
  grid-column: span 2;
}

.header-actions button {
  font-size: 12px;
  border: 1px solid #ccc;
  border-radius: 5px;
  background: #fff;
  cursor: pointer;
}

.status {
  padding: 3px 6px;
  border-radius: 5px;
  font-size: 12px;
  text-align: center;
}

/* ============================================================================
   DASHBOARD CONTENT
   ============================================================================ */
.dashboard-content {
  display: flex;
  flex: 1;
  overflow: hidden;
}

.sidebar {
  width: 350px;
  background: white;
  border-right: 1px solid #e0e0e0;
  display: flex;
  flex-direction: column;
  padding: 10px;
  overflow-y: auto;
  overflow-x: visible;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
}

button,
.chat-item,
.db-tab {
  touch-action: manipulation;
}

button {
  min-height: 40px;
}

.chat-item {
  padding: 10px 15px 10px 10px;
  margin-bottom: 8px;
  background: #f9f9f9;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.2s;
  position: relative;
}

.chat-item:hover {
  background: #f0f0f0;
}

.chat-item.active {
  background: #c5f0ea;
  border: 1px solid #a4d1bb;
}

.chat-item-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 5px;
}

.chat-item-header strong {
  color: #000;
}

.chat-item-header .time {
  font-size: 12px;
  color: #ffffff;
  padding: 2px 5px;
  background: #64ccd1;
  border-radius: 5px;
  text-align: center;
}

.chat-item-preview {
  font-size: 13px;
  color: #666;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.online-badge {
  background: #29b92b;
  font-size: 12px;
  color: #fff;
  border-radius: 5px;
  padding: 2px 5px;
  margin-right: 5px;
}

.disconnected-badge {
  background: #f44336;
  font-size: 12px;
  color: #fff;
  border-radius: 5px;
  padding: 1px 3px;
}

.no-chats {
  text-align: center;
  color: #999;
  padding: 40px 20px;
  font-size: 14px;
}


/* ============================================================================
   MAIN CHAT AREA
   ============================================================================ */
.main-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: white;
}

.no-chat-selected {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  color: #999;
  font-size: 18px;
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100%;
}

.chat-header {
  display: flex;
}

.current-chat-user,
.current-chat-time {
  margin: 0 6px;
  font-size: 12px;
  color: #fff;
  background: #29b92b;
  border-radius: 5px;
  padding: 2px 5px;
}

.message-area {
  flex: 1;
  overflow-y: auto;
  padding: 20px 30px;
  background: #fff;
}

.message {
  margin-bottom: 20px;
  max-width: 70%;
  animation: fadeIn 0.3s;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

.user-message { margin-right: auto; }
.admin-message { margin-left: auto; }

.message-content {
  background: #f2f2f2;
  padding: 12px 16px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-wrap: break-word;
}

.admin-message .message-content {
  background: #faf9f9;
  color: #000;
  border-radius: 15px;
  padding: 15px 37px 30px 20px;
}

.message-time {
  font-size: 11px;
  color: #999;
  margin-top: 5px;
  padding: 0 5px;
}

.admin-message .message-time { text-align: right; }

.input-area {
  padding: 20px 30px;
  border-top: 1px solid #e0e0e0;
  background: rgb(244, 244, 244);
  display: flex;
  gap: 15px;
  align-items: flex-end;
}

.input-area textarea {
  flex: 1;
  padding: 12px;
  border: 2px solid #e0e0e0;
  border-radius: 8px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  min-height: 50px;
  max-height: 120px;
  transition: border-color 0.3s;
}

.input-area textarea:focus { border-color: #667eea; outline: none; }

.input-area button {
  width: 40px;
  height: 40px;
  background: linear-gradient(269deg, rgb(70, 54, 235), rgb(221, 62, 214));
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.2s;
}

.input-area button:hover { transform: translateY(-2px); }

.agent-name {
    color: #32872b;
    background: #d5fad3;
    padding: 1px 5px 1px 5px;
    border-radius: 5px;
    border: 1px solid #aee0a9;
}

.current-agent.agent-name {
  color: #387e3a;
}


/* ============================================================================
   SCROLLBARS
   ============================================================================ */
.chat-list::-webkit-scrollbar,
.message-area::-webkit-scrollbar { width: 8px; }
.chat-list::-webkit-scrollbar-track,
.message-area::-webkit-scrollbar-track { background: #f1f1f1; }
.chat-list::-webkit-scrollbar-thumb,
.message-area::-webkit-scrollbar-thumb {
  background: #ccc;
  border-radius: 4px;
}
.chat-list::-webkit-scrollbar-thumb:hover,
.message-area::-webkit-scrollbar-thumb:hover { background: #999; }

/* ============================================================================
   DATABASE VIEWER
   ============================================================================ */
.db-modal {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: rgba(0,0,0,0.8);
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
}

.db-modal-content {
  background: white;
  width: 90%;
  max-width: 1200px;
  max-height: 80vh;
  border-radius: 8px;
  display: flex;
  flex-direction: column;
}

.db-modal-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 20px;
  border-bottom: 1px solid #ddd;
}

.db-modal-header h2 {
  margin: 0;
}

.close-btn {
  background: #f44336;
  color: white;
  border: none;
  padding: 8px 15px;
  border-radius: 4px;
  cursor: pointer;
  font-size: 18px;
}

.db-tabs {
  display: flex;
  padding: 10px 20px;
  gap: 10px;
  border-bottom: 1px solid #ddd;
}

.db-tab {
  padding: 10px 20px;
  border: none;
  background: #f0f0f0;
  cursor: pointer;
  border-radius: 4px;
  transition: background 0.3s;
}

.db-tab.active {
  background: #4CAF50;
  color: white;
}

#db-content {
  flex: 1;
  overflow: auto;
  padding: 20px;
}

.db-table-container {
  overflow-x: auto;
  height: 500px;
}

.db-table {
  width: 100%;
  border-collapse: collapse;
  background: white;
}

.db-table th {
  background: #d7d7d7;
  font-size: 16px;
  font-weight: 100;
  color: #000000;
  padding: 10px;
  text-align: left;
  position: sticky;
  top: 0;
}

.db-table td {
  font-size: 14px;
  font-weight: 100;
  color: #000000;
  padding: 10px;
  border-bottom: 1px solid #ddd;
}

.db-table tr:hover {
  background: #f5f5f5;
}

.db-table td:nth-child(4),
.db-table td:nth-child(6) {
  max-width: 300px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ============================================================================
   RESPONSIVE
   ============================================================================ */
@media (max-width: 768px) {
   #mobile-back-btn { display: inline-flex; }

  .dashboard-header .center-block { justify-content: center; flex-wrap: wrap; }
  .dashboard-header h1 { font-size: 16px; }
  .header-actions { width: 100%; flex-direction: column; gap: 6px; }

  .chat-item { padding: 12px; border-radius: 10px; }
  .message-area { padding: 12px; }
  .message { max-width: 88%; }
  .input-area { padding: 8px; gap: 6px; }
  .input-area textarea { min-height: 44px; font-size: 15px; }
  .input-area button { width: 48px; height: 48px; border-radius: 12px; }

    #main-chat {
    position: fixed;
    top: 50px;
    left: 0;
    width: 100%;
    height: calc(100dvh - 50px);
    background: white;
    z-index: 15;
    display: none;
    flex-direction: column;
  }

    #main-chat.active {
    display: flex;
  }

   .sidebar {
    top: 50px;           /* below header */
    left: 0;
    width: 100%;
    height: calc(100dvh - 50px);
    background: white;
    z-index: 20;
    transform: translateX(0);
    transition: transform 0.3s ease;
  }

  .sidebar.hidden {
    transform: translateX(-100%); /* hide off-screen */
  }
}

@media (max-width: 480px) {
  .dashboard-header {
    grid-template-columns: 1fr 1fr;
    grid-template-rows: auto auto;
  }
  .dashboard-header h1 { grid-column: 1 / 2; justify-self: start; }
  .dashboard-header .center-block { grid-column: 1 / -1; justify-content: center; }
  .dashboard-header #menu-toggle-btn { grid-column: 2 / 3; justify-self: end; }
}
