/* ============ ConvyMes Styles — Mobile-first ============ */

:root {
  --fb: #1877f2;
  --viber: #7360f2;
  --line: #06c755;
  --primary: #2563eb;
  --primary-dark: #1d4ed8;
  --bg: #f1f5f9;
  --surface: #ffffff;
  --border: #e2e8f0;
  --text: #0f172a;
  --text-muted: #64748b;
  --danger: #ef4444;
  --success: #22c55e;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

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

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.hidden { display: none !important; }

/* ============ Buttons ============ */
.btn {
  border: none;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.2s, opacity 0.2s;
}
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: rgba(0, 0, 0, 0.05); }
.btn-small { padding: 6px 10px; font-size: 12px; background: var(--bg); color: var(--text); }
.btn-small:hover { background: var(--border); }

/* ============ Login ============ */
.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 20px;
  background: linear-gradient(135deg, #2563eb 0%, #7c3aed 100%);
}
.login-card {
  background: var(--surface);
  border-radius: 16px;
  padding: 32px 24px;
  width: 100%;
  max-width: 380px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.2);
}
.logo { text-align: center; margin-bottom: 24px; }
.logo-icon { font-size: 40px; }
.logo h1 { font-size: 24px; margin-top: 4px; }
.logo p { color: var(--text-muted); font-size: 14px; }
.logo.small { display: flex; align-items: center; gap: 8px; margin: 0; }
.logo.small .logo-icon { font-size: 24px; }
.logo.small h1 { font-size: 18px; margin: 0; }

#login-form { display: flex; flex-direction: column; gap: 12px; }
#login-form input {
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  font-size: 15px;
}
#login-form input:focus { outline: 2px solid var(--primary); border-color: transparent; }
.error-text { color: var(--danger); font-size: 13px; text-align: center; }

/* ============ App Layout ============ */
.app {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

/* ============ Sidebar ============ */
.sidebar {
  width: 100%;
  max-width: 340px;
  min-width: 280px;
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  height: 100%;
}
.sidebar-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
}
.channel-status {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  font-size: 12px;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
}
.channel-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  display: inline-block;
  background: #cbd5e1;
}
.channel-dot[data-channel="facebook"].active { background: var(--facebook, #1877f2); }
.channel-dot[data-channel="viber"].active { background: var(--viber); }
.channel-dot[data-channel="line"].active { background: var(--line); }

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
}
.tab {
  flex: 1;
  padding: 10px;
  background: transparent;
  border: none;
  font-size: 14px;
  font-weight: 600;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
}
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

.conversation-list, .ticket-list {
  flex: 1;
  overflow-y: auto;
}

.conversation-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.1s;
}
.conversation-item:hover { background: var(--bg); }
.conversation-item.active { background: #eff6ff; border-left: 3px solid var(--primary); }

.channel-badge {
  font-size: 11px;
  font-weight: 700;
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.channel-badge.facebook { background: var(--facebook, #1877f2); }
.channel-badge.viber { background: var(--viber); }
.channel-badge.line { background: var(--line); }

.conv-info { flex: 1; min-width: 0; }
.conv-name {
  font-weight: 600;
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-preview {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.conv-meta {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 4px;
  font-size: 11px;
  color: var(--text-muted);
}
.unread-badge {
  background: var(--primary);
  color: #fff;
  border-radius: 10px;
  padding: 1px 6px;
  font-size: 11px;
  font-weight: 700;
}
.status-tag {
  font-size: 10px;
  padding: 1px 6px;
  border-radius: 8px;
  background: var(--bg);
  color: var(--text-muted);
}
.status-tag.open { background: #dbeafe; color: #1d4ed8; }
.status-tag.resolved { background: #dcfce7; color: #15803d; }

/* ============ Ticket list ============ */
.ticket-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
}
.ticket-item:hover { background: var(--bg); }
.ticket-subject { font-weight: 600; font-size: 14px; }
.ticket-meta { font-size: 12px; color: var(--text-muted); margin-top: 4px; }
.ticket-priority {
  font-size: 10px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 8px;
  text-transform: uppercase;
}
.ticket-priority.low { background: #f1f5f9; color: #475569; }
.ticket-priority.normal { background: #dbeafe; color: #1d4ed8; }
.ticket-priority.high { background: #fef3c7; color: #b45309; }
.ticket-priority.urgent { background: #fee2e2; color: #b91c1c; }

/* ============ Chat area ============ */
.chat-area {
  flex: 1;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  min-width: 0;
}
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  text-align: center;
  padding: 20px;
}
.empty-icon { font-size: 56px; margin-bottom: 12px; }
.empty-state h2 { color: var(--text); margin-bottom: 6px; }

.chat-view {
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.chat-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.chat-customer { flex: 1; min-width: 0; }
.customer-name { font-weight: 700; font-size: 16px; display: block; }
.chat-actions { display: flex; gap: 8px; }

.messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.message {
  max-width: 75%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: 14px;
  line-height: 1.4;
  word-wrap: break-word;
  position: relative;
}
.message.in {
  align-self: flex-start;
  background: var(--surface);
  border-bottom-left-radius: 4px;
  box-shadow: var(--shadow);
}
.message.out {
  align-self: flex-end;
  background: var(--primary);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.message-time {
  display: block;
  font-size: 10px;
  margin-top: 4px;
  opacity: 0.7;
}

.reply-form {
  display: flex;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-top: 1px solid var(--border);
}
.reply-form input {
  flex: 1;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 24px;
  font-size: 15px;
}
.reply-form input:focus { outline: 2px solid var(--primary); border-color: transparent; }

/* ============ Toasts ============ */
.toast-container {
  position: fixed;
  top: 16px;
  right: 16px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--text);
  color: #fff;
  padding: 12px 16px;
  border-radius: 8px;
  font-size: 13px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
  animation: slideIn 0.2s ease;
  max-width: 320px;
}
.toast.success { background: var(--success, #16a34a); }
.toast.error { background: var(--danger); }
.toast.warning { background: #d97706; }
@keyframes slideIn {
  from { transform: translateX(100%); opacity: 0; }
  to { transform: translateX(0); opacity: 1; }
}

/* ============ Mobile responsive ============ */
.mobile-only { display: none; }

@media (max-width: 768px) {
  .app { flex-direction: column; }
  .sidebar {
    max-width: none;
    min-width: 0;
    width: 100%;
    height: 100%;
    position: absolute;
    z-index: 10;
    transition: transform 0.25s ease;
  }
  .sidebar.hidden-mobile { transform: translateX(-100%); }
  .chat-area { width: 100%; }
  .mobile-only { display: inline-block; }
  .chat-actions .btn-small { font-size: 11px; padding: 5px 8px; }
  .message { max-width: 85%; }
}