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

:root {
  --bg-dark: #0a0c0f;
  --card-bg: #151921;
  --input-bg: #1e2330;
  --green: #5de06b;
  --green-hover: #4bc95a;
  --text: #e2e8f0;
  --text-muted: #8892a4;
  --border: #2a3040;
  --msg-user: #056162;
  --msg-admin: #1e2330;
  --danger: #e05d5d;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg-dark);
  color: var(--text);
  min-height: 100vh;
  overflow: hidden;
}

/* ========== LOGIN PAGE ========== */
.login-page {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 100vh;
  background: var(--bg-dark);
  background-image: radial-gradient(ellipse at top, rgba(139, 69, 19, 0.15) 0%, transparent 60%);
}

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

.login-logo img {
  width: 100px;
  height: 100px;
  border-radius: 20px;
  object-fit: cover;
  margin-bottom: 16px;
}

.login-title {
  font-size: 28px;
  font-weight: 700;
  color: #ffd700;
  margin-bottom: 8px;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
  line-height: 1.5;
}

.phone-input-group {
  display: flex;
  gap: 8px;
  margin-bottom: 20px;
}

.phone-prefix {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 0 14px;
  font-size: 15px;
  color: var(--text);
  white-space: nowrap;
}

.phone-prefix .flag {
  font-size: 20px;
}

.phone-input {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 16px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.phone-input:focus {
  border-color: var(--green);
}

.phone-input::placeholder {
  color: #4a5568;
}

.btn-start {
  width: 100%;
  background: var(--green);
  color: #000;
  border: none;
  border-radius: 12px;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, transform 0.1s;
}

.btn-start:hover {
  background: var(--green-hover);
}

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

.btn-start:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

.login-note {
  color: #4a5568;
  font-size: 12px;
  margin-top: 16px;
}

.shake {
  animation: shake 0.5s ease-in-out;
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-8px); }
  75% { transform: translateX(8px); }
}

/* ========== CHAT PAGE ========== */
.chat-page {
  height: 100vh;
  height: 100dvh;
}

.chat-container {
  display: flex;
  flex-direction: column;
  height: 100vh;
  height: 100dvh;
  max-width: 500px;
  margin: 0 auto;
  background: var(--bg-dark);
}

.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--card-bg);
  border-bottom: 1px solid var(--border);
  z-index: 10;
  flex-shrink: 0;
}

.back-btn {
  color: var(--text);
  text-decoration: none;
  display: flex;
  align-items: center;
  opacity: 0.7;
  transition: opacity 0.2s;
}

.back-btn:hover {
  opacity: 1;
}

.header-avatar {
  position: relative;
  flex-shrink: 0;
}

.header-avatar img {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  object-fit: cover;
}

.online-dot {
  position: absolute;
  bottom: 0;
  right: 0;
  width: 12px;
  height: 12px;
  background: var(--green);
  border-radius: 50%;
  border: 2px solid var(--card-bg);
}

.header-info {
  flex: 1;
}

.header-name {
  font-size: 16px;
  font-weight: 600;
}

.header-status {
  font-size: 13px;
  color: var(--green);
}

/* Messages area */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  position: relative;
  scroll-behavior: smooth;
}

.chat-bg {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: url('/img/chat-bg.png') center/cover no-repeat;
  opacity: 0.08;
  pointer-events: none;
  z-index: 0;
}

.messages-list {
  position: relative;
  z-index: 1;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  min-height: 100%;
}

.message {
  max-width: 80%;
  animation: msgIn 0.2s ease-out;
}

@keyframes msgIn {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.message-user {
  align-self: flex-end;
}

.message-admin {
  align-self: flex-start;
}

.message-bubble {
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 15px;
  line-height: 1.4;
  word-break: break-word;
}

.message-user .message-bubble {
  background: var(--msg-user);
  border-bottom-right-radius: 4px;
  color: #fff;
}

.message-admin .message-bubble {
  background: var(--msg-admin);
  border-bottom-left-radius: 4px;
  color: var(--text);
}

.message-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 4px;
  padding: 0 4px;
}

.message-user .message-time {
  text-align: right;
}

/* Input area */
.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.chat-input {
  flex: 1;
  background: var(--input-bg);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 12px 18px;
  font-size: 15px;
  color: var(--text);
  outline: none;
  transition: border-color 0.2s;
}

.chat-input:focus {
  border-color: var(--green);
}

.chat-input::placeholder {
  color: #4a5568;
}

.send-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: var(--green);
  border: none;
  color: #000;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: background 0.2s, transform 0.1s;
}

.send-btn:hover {
  background: var(--green-hover);
}

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

/* Media buttons */
.media-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  transition: all 0.2s;
  align-self: center;
}

.media-btn:hover {
  color: var(--green);
  border-color: var(--green);
  background: rgba(93, 224, 107, 0.08);
}

.media-btn.recording {
  color: #fff;
  border-color: #e05d5d;
  background: #e05d5d;
  animation: none;
  width: auto;
  border-radius: 24px;
  padding: 0 14px;
  min-width: 70px;
}

.rec-timer {
  font-size: 14px;
  font-weight: 600;
  font-family: monospace;
}

.send-btn.recording-send {
  background: var(--green);
  animation: pulse-send 1s infinite;
}

@keyframes pulse-send {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.1); }
}

/* Image messages */
.message-image img {
  max-width: 260px;
  max-height: 300px;
  border-radius: 12px;
  cursor: pointer;
  display: block;
  object-fit: cover;
}

.message-user .message-image img {
  border-bottom-right-radius: 4px;
}

.message-admin .message-image img {
  border-bottom-left-radius: 4px;
}

/* Voice messages */
.message-voice audio {
  max-width: 240px;
  height: 36px;
  border-radius: 18px;
}

/* Recording bar */
.recording-bar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  background: var(--card-bg);
  border-top: 1px solid var(--border);
}

.recording-dot {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #e05d5d;
  animation: blink 1s infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.3; }
}

.recording-time {
  font-size: 15px;
  color: var(--text);
  min-width: 40px;
}

.record-cancel {
  padding: 6px 16px;
  border-radius: 20px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  font-size: 13px;
  margin-left: auto;
}

.record-cancel:hover {
  border-color: var(--danger);
  color: var(--danger);
}

.record-stop {
  padding: 6px 16px;
  border-radius: 20px;
  border: none;
  background: var(--green);
  color: #000;
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
}

.record-stop:hover {
  background: var(--green-hover);
}

/* ========== ADMIN PAGE ========== */
.admin-page {
  height: 100vh;
}

.admin-panel {
  display: flex;
  height: 100vh;
}

/* Sidebar */
.admin-sidebar {
  width: 360px;
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  flex-shrink: 0;
}

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

.sidebar-header h2 {
  font-size: 20px;
  font-weight: 600;
}

.chat-count {
  background: var(--green);
  color: #000;
  font-size: 13px;
  font-weight: 600;
  padding: 2px 10px;
  border-radius: 12px;
}

.chat-list {
  flex: 1;
  overflow-y: auto;
}

.empty-chats {
  text-align: center;
  color: var(--text-muted);
  padding: 40px 20px;
  font-size: 14px;
}

.chat-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px;
  cursor: pointer;
  transition: background 0.15s;
  border-bottom: 1px solid rgba(255,255,255,0.04);
}

.chat-item:hover {
  background: rgba(255,255,255,0.04);
}

.chat-item.active {
  background: rgba(93, 224, 107, 0.08);
  border-left: 3px solid var(--green);
}

.chat-item-avatar {
  flex-shrink: 0;
}

.avatar-circle {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  color: #fff;
}

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

.chat-item-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
}

.chat-item-phone {
  font-size: 15px;
  font-weight: 500;
}

.chat-item-time {
  font-size: 12px;
  color: var(--text-muted);
  flex-shrink: 0;
}

.chat-item-bottom {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

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

.unread-badge {
  background: var(--green);
  color: #000;
  font-size: 12px;
  font-weight: 600;
  min-width: 22px;
  height: 22px;
  border-radius: 11px;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0 6px;
  flex-shrink: 0;
  margin-left: 8px;
}

/* Admin chat area */
.admin-chat {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg-dark);
}

.no-chat-selected {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-muted);
  font-size: 16px;
}

.admin-chat-view {
  flex-direction: column;
  height: 100vh;
}

.admin-chat-header {
  background: var(--card-bg);
}

.admin-messages {
  flex: 1;
  overflow-y: auto;
}

.mobile-back {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
}

/* ========== RESPONSIVE ========== */
@media (max-width: 768px) {
  .login-card {
    margin: 16px;
    padding: 32px 24px;
  }

  .chat-container {
    max-width: 100%;
  }

  /* Admin mobile */
  .admin-sidebar {
    width: 100%;
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 5;
  }

  .admin-chat {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 10;
    transform: translateX(100%);
    transition: transform 0.25s ease;
  }

  .admin-panel {
    position: relative;
    overflow: hidden;
  }

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

  .mobile-back {
    display: flex;
    color: var(--text);
  }
}

@media (max-width: 400px) {
  .login-card {
    border-radius: 16px;
    padding: 28px 20px;
  }

  .login-title {
    font-size: 24px;
  }

  .phone-prefix {
    padding: 0 10px;
    font-size: 14px;
  }
}

/* Scrollbar */
::-webkit-scrollbar {
  width: 6px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: rgba(255,255,255,0.15);
  border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
  background: rgba(255,255,255,0.25);
}
