/* ============================================================
   Real-Time Package Tracker — Shared Styles
   ============================================================ */

/* ── Reset & Base ──────────────────────────────────────────── */
*, *::before, *::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --bg:          #0f1117;
  --bg-card:     #1a1d27;
  --bg-card-alt: #222632;
  --border:      #2e3346;
  --text:        #e4e6ef;
  --text-muted:  #8b8fa3;
  --accent:      #6366f1;
  --accent-glow: rgba(99,102,241,.25);
  --green:       #22c55e;
  --green-glow:  rgba(34,197,94,.2);
  --red:         #ef4444;
  --red-glow:    rgba(239,68,68,.2);
  --orange:      #f59e0b;
  --orange-glow: rgba(245,158,11,.2);
  --blue:        #3b82f6;
  --radius:      12px;
  --radius-sm:   8px;
  --shadow:      0 4px 24px rgba(0,0,0,.35);
  --transition:  .25s cubic-bezier(.4,0,.2,1);
  --font:        'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
}

html { font-size: 15px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  min-height: 100vh;
  overflow-x: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ── Utility ───────────────────────────────────────────────── */
.hidden { display: none !important; }

/* ── Connection Indicator ──────────────────────────────────── */
.connection-bar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 10000;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 6px 0;
  font-size: .78rem;
  font-weight: 600;
  letter-spacing: .03em;
  transition: transform var(--transition), background var(--transition);
}
.connection-bar.connected {
  background: var(--green);
  color: #fff;
  transform: translateY(-100%);
}
.connection-bar.disconnected {
  background: var(--red);
  color: #fff;
  transform: translateY(0);
}
.connection-bar .dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: currentColor;
  animation: blink 1.2s infinite;
}
@keyframes blink { 50% { opacity: .3; } }

/* ── Toast Notifications ───────────────────────────────────── */
#toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 10px;
  pointer-events: none;
}
.toast {
  pointer-events: auto;
  padding: 14px 22px;
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  font-size: .85rem;
  box-shadow: var(--shadow);
  animation: slideIn .35s ease forwards;
  max-width: 360px;
}
.toast.success { border-left: 4px solid var(--green); }
.toast.error   { border-left: 4px solid var(--red); }
.toast.info    { border-left: 4px solid var(--blue); }
.toast.fadeOut { animation: slideOut .35s ease forwards; }
@keyframes slideIn  { from { opacity:0; transform:translateX(60px); } to { opacity:1; transform:translateX(0); } }
@keyframes slideOut { from { opacity:1; transform:translateX(0); } to { opacity:0; transform:translateX(60px); } }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 22px;
  border: none;
  border-radius: var(--radius-sm);
  font-family: var(--font);
  font-size: .88rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
  white-space: nowrap;
}
.btn:active { transform: scale(.96); }

.btn-primary {
  background: var(--accent);
  color: #fff;
  box-shadow: 0 2px 12px var(--accent-glow);
}
.btn-primary:hover { background: #818cf8; }

.btn-danger {
  background: var(--red);
  color: #fff;
  box-shadow: 0 2px 12px var(--red-glow);
}
.btn-danger:hover { background: #dc2626; }

.btn-secondary {
  background: var(--bg-card-alt);
  color: var(--text);
  border: 1px solid var(--border);
}
.btn-secondary:hover { background: var(--border); }

.btn-sm { padding: 6px 14px; font-size: .8rem; }

/* ── Inputs / Selects ──────────────────────────────────────── */
.input, .select {
  width: 100%;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: .88rem;
  transition: border var(--transition), box-shadow var(--transition);
  outline: none;
}
.input:focus, .select:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-glow);
}
.select { cursor: pointer; appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg fill='%238b8fa3' viewBox='0 0 20 20' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M5.293 7.293a1 1 0 011.414 0L10 10.586l3.293-3.293a1 1 0 111.414 1.414l-4 4a1 1 0 01-1.414 0l-4-4a1 1 0 010-1.414z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  background-size: 16px;
  padding-right: 36px;
}

label {
  display: block;
  margin-bottom: 6px;
  font-size: .82rem;
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: .06em;
}

/* ── Cards ─────────────────────────────────────────────────── */
.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 24px;
  box-shadow: var(--shadow);
}

/* ── Status Badges ─────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 12px;
  border-radius: 999px;
  font-size: .75rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .05em;
}
.badge::before {
  content: '';
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.badge-pending      { background: var(--orange-glow); color: var(--orange); }
.badge-processing   { background: rgba(99,102,241,.15); color: var(--accent); }
.badge-intransit    { background: rgba(59,130,246,.15); color: var(--blue); }
.badge-arrived      { background: rgba(34,197,94,.15); color: var(--green); }
.badge-outfordelivery { background: rgba(236,72,153,.15); color: #ec4899; }
.badge-delivered    { background: var(--green-glow); color: var(--green); }

/* ── Map Container ─────────────────────────────────────────── */
.map-wrap {
  position: relative;
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
  background: var(--bg);
}
.map-wrap .leaflet-container { background: #1a1d27; }

/* ── Loader Spinner ────────────────────────────────────────── */
.spinner {
  width: 28px; height: 28px;
  border: 3px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.loading-overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(15,17,23,.7);
  z-index: 1000;
  backdrop-filter: blur(4px);
  border-radius: var(--radius);
}

/* ── Empty State ───────────────────────────────────────────── */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 48px 24px;
  color: var(--text-muted);
  text-align: center;
}
.empty-state svg { opacity: .35; }
.empty-state p { font-size: .92rem; }

/* ── Leaflet Overrides ─────────────────────────────────────── */
.leaflet-popup-content-wrapper {
  background: var(--bg-card) !important;
  color: var(--text) !important;
  border-radius: var(--radius-sm) !important;
  box-shadow: var(--shadow) !important;
  border: 1px solid var(--border) !important;
}
.leaflet-popup-tip { background: var(--bg-card) !important; }
.leaflet-popup-content { font-family: var(--font) !important; font-size: .85rem !important; }

/* ── Scrollbar ─────────────────────────────────────────────── */
::-webkit-scrollbar { width: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 8px; }
::-webkit-scrollbar-thumb:hover { background: var(--text-muted); }

/* ── Responsive helpers ────────────────────────────────────── */
@media (max-width: 768px) {
  html { font-size: 14px; }
}

/* ============================================================
   LIVE CHAT WIDGET STYLES
   ============================================================ */

/* ── Chat Toggle Button ────────────────────────────────────── */
.chat-toggle {
  position: fixed;
  bottom: 24px;
  right: 24px;
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(99,102,241,.4);
  z-index: 9000;
  transition: transform var(--transition), box-shadow var(--transition);
}
.chat-toggle:hover {
  transform: scale(1.08);
  box-shadow: 0 6px 28px rgba(99,102,241,.5);
}
.chat-toggle:active { transform: scale(.96); }
.chat-toggle svg { color: #fff; }
.chat-toggle .badge-count {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--red);
  color: #fff;
  font-size: .72rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--bg);
}

/* ── Chat Widget Container ─────────────────────────────────── */
.chat-widget {
  position: fixed;
  bottom: 100px;
  right: 24px;
  width: 380px;
  max-width: calc(100vw - 48px);
  height: 520px;
  max-height: calc(100vh - 140px);
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 8px 40px rgba(0,0,0,.4);
  z-index: 9000;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: chatSlideUp .3s ease;
}
@keyframes chatSlideUp {
  from { opacity: 0; transform: translateY(20px); }
  to { opacity: 1; transform: translateY(0); }
}

/* ── Chat Header ───────────────────────────────────────────── */
.chat-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 18px;
  background: linear-gradient(135deg, var(--accent), #818cf8);
  color: #fff;
}
.chat-header-info {
  display: flex;
  align-items: center;
  gap: 10px;
}
.chat-header-info h3 {
  font-size: .95rem;
  font-weight: 700;
}
.chat-header-info .online-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--green);
  box-shadow: 0 0 0 2px rgba(34,197,94,.3);
}
.chat-header-actions {
  display: flex;
  gap: 6px;
}
.chat-header-btn {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(255,255,255,.15);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition);
}
.chat-header-btn:hover { background: rgba(255,255,255,.25); }
.chat-header-btn svg { color: #fff; width: 16px; height: 16px; }

/* ── Chat Messages ─────────────────────────────────────────── */
.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  background: var(--bg);
}

.chat-message {
  max-width: 85%;
  padding: 10px 14px;
  border-radius: 16px;
  font-size: .88rem;
  line-height: 1.5;
  animation: msgFade .25s ease;
}
@keyframes msgFade {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.chat-message.customer {
  align-self: flex-end;
  background: var(--accent);
  color: #fff;
  border-bottom-right-radius: 4px;
}
.chat-message.admin {
  align-self: flex-start;
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  border-bottom-left-radius: 4px;
}
.chat-message .msg-time {
  display: block;
  font-size: .68rem;
  margin-top: 4px;
  opacity: .6;
}
.chat-message.customer .msg-time { text-align: right; }

.chat-system-msg {
  text-align: center;
  font-size: .78rem;
  color: var(--text-muted);
  padding: 8px;
}

/* ── Chat Input ────────────────────────────────────────────── */
.chat-input-area {
  display: flex;
  gap: 8px;
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  background: var(--bg-card);
}
.chat-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: 20px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: .88rem;
  outline: none;
  transition: border-color var(--transition);
}
.chat-input:focus { border-color: var(--accent); }
.chat-input::placeholder { color: var(--text-muted); }

.chat-send-btn {
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--accent);
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background var(--transition), transform var(--transition);
}
.chat-send-btn:hover { background: #818cf8; }
.chat-send-btn:active { transform: scale(.92); }
.chat-send-btn svg { color: #fff; }
.chat-send-btn:disabled {
  background: var(--border);
  cursor: not-allowed;
}

/* ── Chat Start Form ───────────────────────────────────────── */
.chat-start-form {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
  background: var(--bg);
}
.chat-start-form svg { color: var(--accent); margin-bottom: 16px; }
.chat-start-form h3 {
  font-size: 1.1rem;
  margin-bottom: 6px;
}
.chat-start-form p {
  font-size: .85rem;
  color: var(--text-muted);
  margin-bottom: 20px;
}
.chat-start-form .form-group {
  width: 100%;
  max-width: 260px;
  margin-bottom: 12px;
}
.chat-start-form .input {
  text-align: center;
}

/* ── Chat Closed State ─────────────────────────────────────── */
.chat-closed-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 32px 24px;
  text-align: center;
  background: var(--bg);
}
.chat-closed-state svg { color: var(--text-muted); margin-bottom: 16px; opacity: .5; }
.chat-closed-state h3 { font-size: 1rem; margin-bottom: 6px; }
.chat-closed-state p { font-size: .85rem; color: var(--text-muted); margin-bottom: 20px; }

/* ── Chat Typing Indicator ─────────────────────────────────── */
.typing-indicator {
  display: flex;
  gap: 4px;
  padding: 12px 16px;
  align-self: flex-start;
}
.typing-indicator span {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--text-muted);
  animation: typingBounce 1.4s infinite ease-in-out both;
}
.typing-indicator span:nth-child(1) { animation-delay: -0.32s; }
.typing-indicator span:nth-child(2) { animation-delay: -0.16s; }
@keyframes typingBounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: .4; }
  40% { transform: scale(1); opacity: 1; }
}

/* ── Mobile Responsive ─────────────────────────────────────── */
@media (max-width: 480px) {
  .chat-widget {
    bottom: 0;
    right: 0;
    left: 0;
    width: 100%;
    max-width: 100%;
    height: calc(100vh - 70px);
    max-height: none;
    border-radius: var(--radius) var(--radius) 0 0;
  }
  .chat-toggle {
    bottom: 16px;
    right: 16px;
    width: 54px;
    height: 54px;
  }
}
