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

:root {
  --bg: #F3F4F6;
  --surface: #FFFFFF;
  --border: #E5E7EB;
  --text: #111827;
  --text-muted: #6B7280;
  --text-light: #9CA3AF;
  --primary: #1F93FF;
  --primary-dark: #1677cc;
  --success: #10B981;
  --warning: #F59E0B;
  --purple: #8B5CF6;
  --danger: #EF4444;
  --header-h: 60px;
  --filter-h: 48px;
  --shadow-sm: 0 1px 3px rgba(0,0,0,.08);
  --shadow-md: 0 4px 12px rgba(0,0,0,.12);
  --shadow-lg: 0 8px 24px rgba(0,0,0,.16);
  --radius: 10px;
  --radius-sm: 6px;
  --col-w: 300px;
}

html, body { height: 100%; font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif; font-size: 14px; color: var(--text); background: var(--bg); }
#app { display: flex; flex-direction: column; height: 100vh; overflow: hidden; }

/* ================================
   Header
================================ */
.header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 16px;
  flex-shrink: 0;
  box-shadow: var(--shadow-sm);
  z-index: 100;
}

.header-left { display: flex; align-items: center; min-width: 200px; }
.header-center { flex: 1; display: flex; justify-content: center; }
.header-right { display: flex; align-items: center; gap: 12px; min-width: 280px; justify-content: flex-end; }

.logo { display: flex; align-items: center; gap: 10px; }
.logo-text { font-size: 16px; font-weight: 700; color: var(--text); letter-spacing: -0.3px; }

.inbox-selector { display: flex; align-items: center; gap: 8px; }
.inbox-selector label { font-size: 13px; color: var(--text-muted); font-weight: 500; }
.inbox-selector select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 6px 28px 6px 10px;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%236B7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  cursor: pointer;
  min-width: 180px;
}
.inbox-selector select:focus { outline: none; border-color: var(--primary); }

.search-box {
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 20px;
  padding: 6px 12px;
  transition: border-color .2s;
}
.search-box:focus-within { border-color: var(--primary); background: white; }
.search-box input { border: none; background: none; font-size: 13px; color: var(--text); outline: none; width: 160px; }
.search-box input::placeholder { color: var(--text-light); }

.btn-refresh {
  background: none;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  width: 32px;
  height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all .2s;
}
.btn-refresh:hover { background: var(--bg); border-color: var(--primary); }
.btn-refresh.spinning svg { animation: spin .8s linear infinite; }

.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bg);
  border: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  white-space: nowrap;
}
.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--text-light); }
.status-badge.connected .status-dot { background: var(--success); box-shadow: 0 0 0 2px rgba(16,185,129,.2); }
.status-badge.connected .status-text { color: var(--success); }
.status-badge.error .status-dot { background: var(--danger); }
.status-badge.error .status-text { color: var(--danger); }

/* ================================
   Filters Bar
================================ */
.filters-bar {
  height: var(--filter-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 20px;
  gap: 20px;
  flex-shrink: 0;
}

.filter-group { display: flex; align-items: center; gap: 6px; }
.filter-label { font-size: 12px; color: var(--text-muted); font-weight: 500; }
.filter-group select {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 4px 24px 4px 8px;
  font-size: 12px;
  color: var(--text);
  background: var(--bg);
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='10' viewBox='0 0 12 12'%3E%3Cpath fill='%236B7280' d='M6 8L1 3h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 6px center;
  cursor: pointer;
}
.filter-group select:focus { outline: none; border-color: var(--primary); }

.filter-stats { margin-left: auto; font-size: 12px; color: var(--text-muted); }

/* ================================
   Board
================================ */
.board-container {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 16px 20px;
}

.board {
  display: flex;
  gap: 16px;
  height: 100%;
  min-width: max-content;
}

/* ================================
   Column
================================ */
.column {
  width: var(--col-w);
  background: var(--surface);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  border: 1px solid var(--border);
  box-shadow: var(--shadow-sm);
  flex-shrink: 0;
  height: 100%;
}

.column-header {
  padding: 14px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 2px solid var(--col-color, var(--primary));
  flex-shrink: 0;
}
.column-title { display: flex; align-items: center; gap: 8px; font-weight: 600; font-size: 14px; color: var(--text); }
.column-icon { font-size: 16px; }

.column-count {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 8px;
  border-radius: 20px;
  min-width: 24px;
  text-align: center;
}
.badge-blue { background: #DBEAFE; color: #1D4ED8; }
.badge-yellow { background: #FEF3C7; color: #92400E; }
.badge-purple { background: #EDE9FE; color: #6D28D9; }
.badge-green { background: #D1FAE5; color: #065F46; }

.column-body {
  flex: 1;
  overflow-y: auto;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
.column-body::-webkit-scrollbar { width: 4px; }
.column-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
.column-body.drag-over { background: rgba(31,147,255,.04); border: 2px dashed var(--primary); border-radius: 8px; }

/* ================================
   Card
================================ */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: pointer;
  transition: all .18s;
  box-shadow: var(--shadow-sm);
  user-select: none;
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute;
  left: 0; top: 0; bottom: 0;
  width: 3px;
  background: var(--card-accent, var(--primary));
}
.card:hover { box-shadow: var(--shadow-md); transform: translateY(-1px); border-color: #d1d5db; }
.card.dragging { opacity: .5; box-shadow: var(--shadow-lg); transform: rotate(1.5deg) scale(1.02); }

.card-header { display: flex; align-items: flex-start; justify-content: space-between; margin-bottom: 8px; gap: 8px; }
.card-id { font-size: 11px; font-weight: 600; color: var(--text-muted); }
.card-channel { font-size: 10px; padding: 2px 6px; border-radius: 4px; background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }

.card-contact { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.avatar {
  width: 32px; height: 32px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  font-size: 12px; font-weight: 700; color: white;
  flex-shrink: 0;
  background: linear-gradient(135deg, var(--primary), #7C3AED);
}
.avatar img { width: 32px; height: 32px; border-radius: 50%; object-fit: cover; }
.contact-info { flex: 1; min-width: 0; }
.contact-name { font-size: 13px; font-weight: 600; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.contact-phone { font-size: 11px; color: var(--text-muted); }

.card-preview { font-size: 12px; color: var(--text-muted); line-height: 1.4; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; margin-bottom: 10px; }

.card-footer { display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 4px; }
.card-time { font-size: 11px; color: var(--text-light); }
.card-labels { display: flex; gap: 4px; flex-wrap: wrap; }
.label-chip { font-size: 10px; padding: 1px 6px; border-radius: 10px; font-weight: 500; }
.card-agent { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--text-muted); }
.agent-avatar { width: 18px; height: 18px; border-radius: 50%; background: var(--border); display: flex; align-items: center; justify-content: center; font-size: 9px; font-weight: 700; color: var(--text-muted); }

/* ================================
   Skeleton Loading
================================ */
.loading-skeleton { display: flex; flex-direction: column; gap: 10px; }
.skeleton-card {
  background: linear-gradient(90deg, #f0f0f0 25%, #e8e8e8 50%, #f0f0f0 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
  height: 100px;
}
@keyframes shimmer { 0% { background-position: -200% 0; } 100% { background-position: 200% 0; } }

/* ================================
   Modal
================================ */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,.5);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 20px;
  backdrop-filter: blur(2px);
}
.modal-overlay.open { display: flex; }

.modal {
  background: var(--surface);
  border-radius: var(--radius);
  width: 100%;
  max-width: 600px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
  animation: modalIn .2s ease-out;
}
@keyframes modalIn { from { opacity: 0; transform: scale(.95) translateY(10px); } to { opacity: 1; transform: none; } }

.modal-header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 20px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.modal-title { font-size: 16px; font-weight: 700; color: var(--text); }
.modal-close {
  background: none; border: none; cursor: pointer;
  font-size: 22px; color: var(--text-muted);
  width: 32px; height: 32px; display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm); transition: all .15s;
}
.modal-close:hover { background: var(--bg); color: var(--text); }

.modal-body {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.modal-info-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  background: var(--bg);
  border-radius: var(--radius-sm);
  padding: 14px;
}
.info-item { display: flex; flex-direction: column; gap: 2px; }
.info-label { font-size: 11px; font-weight: 600; color: var(--text-muted); text-transform: uppercase; letter-spacing: .5px; }
.info-value { font-size: 13px; color: var(--text); font-weight: 500; }

.modal-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-action {
  padding: 7px 14px;
  border-radius: var(--radius-sm);
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: all .15s;
  display: flex; align-items: center; gap: 6px;
}
.btn-action:hover { background: var(--bg); }
.btn-action.btn-resolve { background: var(--success); color: white; border-color: var(--success); }
.btn-action.btn-resolve:hover { background: #059669; }
.btn-action.btn-reopen { background: var(--primary); color: white; border-color: var(--primary); }
.btn-action.btn-reopen:hover { background: var(--primary-dark); }
.btn-action.btn-open-cw { background: #F3F4F6; color: var(--text); }

.messages-section h3 { font-size: 13px; font-weight: 600; color: var(--text-muted); margin-bottom: 10px; text-transform: uppercase; letter-spacing: .5px; }
.messages-list { display: flex; flex-direction: column; gap: 8px; max-height: 200px; overflow-y: auto; }

.message-bubble {
  padding: 8px 12px;
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.5;
  max-width: 80%;
  word-break: break-word;
}
.message-bubble.incoming { background: var(--bg); border-bottom-left-radius: 2px; align-self: flex-start; }
.message-bubble.outgoing { background: #DBEAFE; border-bottom-right-radius: 2px; align-self: flex-end; text-align: right; }
.message-bubble.activity { background: #FEF3C7; text-align: center; font-style: italic; font-size: 12px; align-self: center; max-width: 100%; color: var(--text-muted); }
.message-time { font-size: 10px; color: var(--text-light); margin-top: 2px; }
.loading-text { font-size: 13px; color: var(--text-muted); text-align: center; padding: 16px; }

.quick-reply { display: flex; gap: 8px; align-items: flex-end; }
.quick-reply textarea {
  flex: 1;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 10px 12px;
  font-size: 13px;
  font-family: inherit;
  resize: none;
  transition: border-color .2s;
}
.quick-reply textarea:focus { outline: none; border-color: var(--primary); }
.btn-send {
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius-sm);
  padding: 10px 16px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex; align-items: center; gap: 6px;
  transition: background .15s;
  white-space: nowrap;
}
.btn-send:hover { background: var(--primary-dark); }

/* ================================
   Toast Notifications
================================ */
.toast-container {
  position: fixed;
  bottom: 20px; right: 20px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 2000;
}
.toast {
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  color: white;
  font-size: 13px;
  font-weight: 500;
  box-shadow: var(--shadow-md);
  animation: toastIn .3s ease-out;
  display: flex; align-items: center; gap: 8px;
  min-width: 200px;
  max-width: 320px;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
.toast.info { background: var(--primary); }
.toast.warning { background: var(--warning); color: #1f2937; }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: none; } }

/* ================================
   Empty State
================================ */
.empty-state {
  display: flex; flex-direction: column; align-items: center;
  padding: 32px 16px;
  color: var(--text-muted);
  gap: 8px;
  text-align: center;
}
.empty-state svg { opacity: .3; }
.empty-state p { font-size: 12px; }

/* ================================
   Animations
================================ */
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* ================================
   Scrollbar Global
================================ */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 4px; }
::-webkit-scrollbar-track { background: transparent; }

/* ================================
   Responsive
================================ */
@media (max-width: 768px) {
  .header-center { display: none; }
  .search-box input { width: 100px; }
  :root { --col-w: 260px; }
}
