/* ============================================
   LayerChat Admin Panel
   ============================================ */

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

/* Always respect hidden state for dynamic UI sections */
[hidden] {
  display: none !important;
}

body {
  font-family: 'Poppins', system-ui, -apple-system, sans-serif;
  background: #f1f5f9;
  color: #1e293b;
  min-height: 100vh;
}

/* ---- Login ---- */

.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  padding: 1rem;
  background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
  position: relative;
  overflow: hidden;
}

.login-page::before {
  content: '';
  position: absolute;
  top: -50%;
  left: -50%;
  width: 200%;
  height: 200%;
  background: radial-gradient(circle at 30% 50%, rgba(37, 99, 235, 0.08) 0%, transparent 50%),
              radial-gradient(circle at 70% 50%, rgba(99, 102, 241, 0.06) 0%, transparent 50%);
  animation: loginBgShift 20s ease-in-out infinite alternate;
}

@keyframes loginBgShift {
  0% { transform: translate(0, 0) rotate(0deg); }
  100% { transform: translate(-2%, -2%) rotate(5deg); }
}

.login-card {
  position: relative;
  width: 100%;
  max-width: 26rem;
  padding: 2.5rem;
  background: rgba(255, 255, 255, 0.97);
  border-radius: 1rem;
  box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
  text-align: center;
  animation: loginCardIn 0.4s ease-out;
}

@keyframes loginCardIn {
  from {
    opacity: 0;
    transform: translateY(1.25rem) scale(0.97);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.login-card .login-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 3.5rem;
  height: 3.5rem;
  border-radius: 1rem;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  margin-bottom: 1.25rem;
}

.login-card .login-icon svg {
  width: 1.75rem;
  height: 1.75rem;
  color: #fff;
}

.login-card h1 {
  font-size: 1.5rem;
  font-weight: 700;
  margin-bottom: 0.25rem;
  color: #0f172a;
}

.login-card .login-subtitle {
  font-size: 0.875rem;
  color: #64748b;
  margin-bottom: 2rem;
}

.login-card .input-group {
  position: relative;
  margin-bottom: 1rem;
  text-align: left;
}

.login-card .input-group label {
  display: block;
  font-size: 0.75rem;
  font-weight: 600;
  color: #475569;
  margin-bottom: 0.375rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.login-card .input-group .input-wrapper {
  position: relative;
  display: flex;
  align-items: center;
}

.login-card .input-group .input-wrapper .input-icon {
  position: absolute;
  left: 0.875rem;
  width: 1.125rem;
  height: 1.125rem;
  color: #94a3b8;
  pointer-events: none;
  flex-shrink: 0;
}

.login-card .input-group input {
  width: 100%;
  padding: 0.75rem 1rem 0.75rem 2.75rem;
  border: 1.5px solid #e2e8f0;
  border-radius: 0.625rem;
  font-family: inherit;
  font-size: 0.875rem;
  color: #0f172a;
  background: #f8fafc;
  outline: none;
  transition: all 0.2s ease;
}

.login-card .input-group input:focus {
  border-color: #6366f1;
  background: #fff;
  box-shadow: 0 0 0 4px rgba(99, 102, 241, 0.1);
}

.login-card .input-group input::placeholder {
  color: #94a3b8;
}

.login-card .login-btn {
  width: 100%;
  padding: 0.8125rem;
  margin-top: 0.5rem;
  border: none;
  border-radius: 0.625rem;
  font-family: inherit;
  font-size: 0.9375rem;
  font-weight: 600;
  color: #fff;
  background: linear-gradient(135deg, #2563eb, #4f46e5);
  cursor: pointer;
  transition: all 0.2s ease;
  position: relative;
  overflow: hidden;
}

.login-card .login-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 8px 25px -5px rgba(79, 70, 229, 0.4);
}

.login-card .login-btn:active {
  transform: translateY(0);
}

.login-card .login-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

.login-card .login-btn .btn-spinner {
  display: none;
  width: 1.25rem;
  height: 1.25rem;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  margin: 0 auto;
}

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

.login-card .login-btn.loading .btn-text { display: none; }
.login-card .login-btn.loading .btn-spinner { display: block; }

.login-error {
  color: #dc2626;
  font-size: 0.8125rem;
  margin-top: 0.75rem;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
}

.login-error svg {
  width: 0.875rem;
  height: 0.875rem;
  flex-shrink: 0;
}

/* ---- Layout ---- */

.admin-layout {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* Respect native hidden attribute to avoid login/admin overlap */
#login-page[hidden],
.admin-layout[hidden],
#chat-area[hidden] {
  display: none !important;
}

/* ---- Sidebar ---- */

.sidebar {
  width: 22rem;
  min-width: 22rem;
  background: #fff;
  border-right: 1px solid #e2e8f0;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.sidebar-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid #e2e8f0;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.sidebar-header h1 {
  font-size: 1.125rem;
  font-weight: 600;
}

.sidebar-header .status-dot {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #22c55e;
  margin-right: 0.375rem;
}

.sidebar-header button {
  padding: 0.375rem 0.75rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.375rem;
  font-size: 0.75rem;
  font-weight: 500;
  color: #64748b;
  background: #fff;
  cursor: pointer;
  transition: all 0.15s ease;
}

.sidebar-header button:hover {
  background: #f8fafc;
  border-color: #cbd5e1;
}

.conversations-list {
  flex: 1;
  overflow-y: auto;
  padding: 0.5rem;
}

.conv-item {
  padding: 0.875rem;
  border-radius: 0.5rem;
  cursor: pointer;
  transition: background 0.15s ease;
  border: 1px solid transparent;
  margin-bottom: 0.375rem;
}

.conv-item:hover {
  background: #f8fafc;
}

.conv-item--active {
  background: #eef2ff;
  border-color: #a5b4fc;
}

.conv-item--waiting {
  border-left: 3px solid #f59e0b;
}

.conv-item--active-session {
  border-left: 3px solid #22c55e;
}

.conv-item__header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.25rem;
}

.conv-item__name {
  font-size: 0.875rem;
  font-weight: 600;
  color: #0f172a;
}

.conv-item__time {
  font-size: 0.6875rem;
  color: #94a3b8;
}

.conv-item__meta {
  display: flex;
  gap: 0.5rem;
  align-items: center;
  margin-bottom: 0.25rem;
}

.conv-item__motive {
  font-size: 0.6875rem;
  padding: 0.125rem 0.375rem;
  border-radius: 9999px;
  background: #f1f5f9;
  color: #475569;
}

.conv-item__status {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
}

.conv-item__status--waiting {
  color: #d97706;
}

.conv-item__status--active {
  color: #16a34a;
}

.conv-item__preview {
  font-size: 0.75rem;
  color: #64748b;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.conv-item__unread {
  display: inline-block;
  width: 0.5rem;
  height: 0.5rem;
  border-radius: 50%;
  background: #ef4444;
  margin-left: auto;
  flex-shrink: 0;
}

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: #94a3b8;
  text-align: center;
  padding: 2rem;
}

.empty-state svg {
  width: 3rem;
  height: 3rem;
  margin-bottom: 1rem;
  opacity: 0.4;
}

.empty-state p {
  font-size: 0.875rem;
}

/* ---- Chat area ---- */

.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  height: 100vh;
}

.chat-placeholder {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  flex: 1;
  color: #94a3b8;
  text-align: center;
  padding: 2rem;
}

.chat-placeholder svg {
  width: 4rem;
  height: 4rem;
  margin-bottom: 1rem;
  opacity: 0.3;
}

.chat-placeholder h2 {
  font-size: 1.25rem;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 0.5rem;
}

.chat-placeholder p {
  font-size: 0.875rem;
}

.chat-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e2e8f0;
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.chat-header__info h2 {
  font-size: 1rem;
  font-weight: 600;
}

.chat-header__info p {
  font-size: 0.75rem;
  color: #64748b;
}

.chat-header__actions {
  display: flex;
  gap: 0.5rem;
}

.btn-close-chat {
  padding: 0.5rem 1rem;
  border: 1px solid #fca5a5;
  border-radius: 0.375rem;
  font-size: 0.8125rem;
  font-weight: 500;
  color: #dc2626;
  background: #fff;
  cursor: pointer;
  transition: all 0.15s ease;
}

.btn-close-chat:hover {
  background: #fef2f2;
  border-color: #f87171;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 1rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

.admin-msg {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  flex-direction: row-reverse;
}

.admin-msg__avatar {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  color: #fff;
  background-color: #2563eb;
  font-size: 0.75rem;
  font-weight: 600;
}

.admin-msg__body {
  max-width: 70%;
  padding: 0.75rem 0.875rem;
  border-radius: 0.625rem 0.625rem 0.125rem 0.625rem;
  background-color: #2563eb;
  color: #fff;
}

.admin-msg__body p {
  font-size: 0.875rem;
  line-height: 1.5;
  white-space: pre-line;
}

.admin-msg__time {
  font-size: 0.625rem;
  color: #bfdbfe;
  margin-top: 0.25rem;
  display: block;
}

.client-msg {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
}

.client-msg__avatar {
  display: inline-flex;
  flex-shrink: 0;
  align-items: center;
  justify-content: center;
  width: 2rem;
  height: 2rem;
  border-radius: 9999px;
  color: #475569;
  background-color: #f1f5f9;
  font-size: 0.75rem;
  font-weight: 600;
}

.client-msg__body {
  max-width: 70%;
  padding: 0.75rem 0.875rem;
  border-radius: 0.625rem 0.625rem 0.625rem 0.125rem;
  background-color: #f1f5f9;
}

.client-msg__body p {
  font-size: 0.875rem;
  line-height: 1.5;
  color: #1e293b;
  white-space: pre-line;
}

.client-msg__body .client-name {
  display: block;
  font-size: 0.6875rem;
  font-weight: 600;
  color: #64748b;
  margin-bottom: 0.25rem;
}

.client-msg__time {
  font-size: 0.625rem;
  color: #94a3b8;
  margin-top: 0.25rem;
  display: block;
}

.chat-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid #e2e8f0;
  background: #fff;
  display: flex;
  gap: 0.75rem;
  align-items: center;
}

.chat-footer input {
  flex: 1;
  padding: 0.75rem 1rem;
  border: 1px solid #e2e8f0;
  border-radius: 0.5rem;
  font-family: inherit;
  font-size: 0.875rem;
  color: #0f172a;
  background: #fff;
  outline: none;
  transition: border-color 0.15s ease;
}

.chat-footer input:focus {
  border-color: #93c5fd;
  box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.15);
}

.chat-footer button {
  padding: 0.75rem 1.25rem;
  border: none;
  border-radius: 0.5rem;
  font-family: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  color: #fff;
  background-color: #2563eb;
  cursor: pointer;
  transition: background 0.15s ease;
  white-space: nowrap;
}

.chat-footer button:hover {
  background-color: #1d4ed8;
}

.chat-footer button:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

/* ---- Scrollbar ---- */

.conversations-list::-webkit-scrollbar,
.chat-messages::-webkit-scrollbar {
  width: 0.375rem;
}

.conversations-list::-webkit-scrollbar-track,
.chat-messages::-webkit-scrollbar-track {
  background: transparent;
}

.conversations-list::-webkit-scrollbar-thumb,
.chat-messages::-webkit-scrollbar-thumb {
  background: #cbd5e1;
  border-radius: 9999px;
}
