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

/* ─── Variables ──────────────────────────────────────────────────────────────── */
:root {
  --navy: #0f1e36;
  --orange: #E87722;
  --orange-hover: #d4661a;
  --white: #ffffff;
  --bg: #f8f9fa;
  --border: #e5e7eb;
  --text: #1a1a2e;
  --text-muted: #6b7280;
  --success: #10b981;
  --danger: #ef4444;
  --warning: #f59e0b;
  --sidebar-width: 220px;
  --radius: 8px;
}

/* ─── Base ───────────────────────────────────────────────────────────────────── */
html { scroll-behavior: smooth; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--orange); }

/* ─── Sidebar ────────────────────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  left: 0;
  top: 0;
  width: var(--sidebar-width);
  height: 100vh;
  background: var(--navy);
  display: flex;
  flex-direction: column;
  z-index: 100;
  overflow-y: auto;
  overflow-x: hidden;
}

.sidebar-logo {
  padding: 24px 20px;
  border-bottom: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.sidebar-logo span {
  color: white;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: -0.3px;
}

.sidebar-logo span::after {
  content: '.';
  color: var(--orange);
}

.sidebar-nav {
  flex: 1;
  padding: 12px 0;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 11px 20px;
  color: rgba(255, 255, 255, 0.65);
  text-decoration: none;
  font-size: 13.5px;
  font-weight: 500;
  transition: all 0.12s ease;
  border-left: 3px solid transparent;
  white-space: nowrap;
}

.nav-item:hover {
  color: white;
  background: rgba(255, 255, 255, 0.07);
  border-left-color: rgba(232, 119, 34, 0.5);
}

.nav-item.active {
  color: white;
  background: rgba(232, 119, 34, 0.12);
  border-left-color: var(--orange);
}

.nav-item svg {
  width: 18px;
  height: 18px;
  flex-shrink: 0;
  opacity: 0.8;
}

.nav-item.active svg,
.nav-item:hover svg { opacity: 1; }

.sidebar-user {
  padding: 16px 20px;
  border-top: 1px solid rgba(255, 255, 255, 0.1);
  flex-shrink: 0;
}

.sidebar-user span {
  color: rgba(255, 255, 255, 0.45);
  font-size: 11px;
  display: block;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  margin-bottom: 2px;
}

.sidebar-user strong {
  color: white;
  font-size: 13.5px;
  display: block;
}

/* ─── Main content ───────────────────────────────────────────────────────────── */
.main-content {
  margin-left: var(--sidebar-width);
  min-height: 100vh;
}

.page-header {
  background: white;
  border-bottom: 1px solid var(--border);
  padding: 16px 24px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 50;
}

.page-header h1 {
  font-size: 20px;
  font-weight: 700;
  color: var(--navy);
}

.page-body {
  padding: 24px;
}

/* ─── Cards ──────────────────────────────────────────────────────────────────── */
.card {
  background: white;
  border-radius: 12px;
  border: 1px solid var(--border);
  padding: 20px;
}

.card-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.07em;
  margin-bottom: 8px;
}

.card-value {
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -1px;
}

/* ─── KPI Grid ───────────────────────────────────────────────────────────────── */
.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 16px;
  margin-bottom: 24px;
}

/* ─── Buttons ────────────────────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 10px 18px;
  border-radius: var(--radius);
  border: none;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: all 0.12s ease;
  line-height: 1;
  white-space: nowrap;
}

.btn:focus { outline: 2px solid var(--orange); outline-offset: 2px; }

.btn-primary {
  background: var(--orange);
  color: white;
}

.btn-primary:hover { background: var(--orange-hover); color: white; }

.btn-secondary {
  background: white;
  color: var(--text);
  border: 1px solid var(--border);
}

.btn-secondary:hover { background: var(--bg); }

.btn-danger {
  background: var(--danger);
  color: white;
}

.btn-danger:hover { background: #dc2626; }

.btn-sm {
  padding: 6px 12px;
  font-size: 12.5px;
}

.btn-whatsapp {
  background: #25D366;
  color: white;
}

.btn-whatsapp:hover { background: #1ebe5a; color: white; }

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

/* ─── Forms ──────────────────────────────────────────────────────────────────── */
.form-group { margin-bottom: 16px; }

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

.form-control {
  width: 100%;
  padding: 10px 14px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  color: var(--text);
  background: white;
  transition: border-color 0.12s;
  font-family: inherit;
}

.form-control:focus {
  outline: none;
  border-color: var(--orange);
  box-shadow: 0 0 0 3px rgba(232, 119, 34, 0.1);
}

.form-control::placeholder { color: #9ca3af; }

select.form-control { cursor: pointer; }

textarea.form-control { resize: vertical; min-height: 80px; }

/* ─── Table ──────────────────────────────────────────────────────────────────── */
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }

table { width: 100%; border-collapse: collapse; font-size: 13.5px; }

th {
  text-align: left;
  padding: 10px 16px;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 2px solid var(--border);
  background: #f9fafb;
  white-space: nowrap;
}

td {
  padding: 13px 16px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

tr:last-child td { border-bottom: none; }
tr:hover td { background: #fafafa; }

/* ─── Badge ──────────────────────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
}

.badge-source-meta_ads { background: #dbeafe; color: #1d4ed8; }
.badge-source-manual { background: #f3f4f6; color: #374151; }
.badge-source-referral { background: #d1fae5; color: #065f46; }
.badge-source-other { background: #fef3c7; color: #92400e; }
.badge-source-whatsapp { background: #dcfce7; color: #166534; }

/* ─── Kanban ─────────────────────────────────────────────────────────────────── */
.kanban-board {
  display: flex;
  gap: 16px;
  overflow-x: auto;
  padding-bottom: 16px;
  align-items: flex-start;
  -webkit-overflow-scrolling: touch;
}

.kanban-column {
  min-width: 260px;
  max-width: 260px;
  background: #f4f5f7;
  border-radius: 12px;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.kanban-header {
  padding: 13px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: white;
  border-radius: 12px 12px 0 0;
}

.kanban-title {
  font-size: 13px;
  font-weight: 700;
  color: var(--text);
}

.kanban-count {
  background: var(--border);
  color: var(--text-muted);
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 700;
}

.kanban-cards {
  padding: 10px;
  min-height: 120px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.kanban-card {
  background: white;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  padding: 12px;
  cursor: grab;
  transition: box-shadow 0.15s, transform 0.1s;
  user-select: none;
}

.kanban-card:hover {
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
  transform: translateY(-1px);
}

.kanban-card.dragging {
  opacity: 0.5;
  cursor: grabbing;
}

.kanban-card .card-name {
  font-weight: 700;
  font-size: 13.5px;
  margin-bottom: 4px;
  color: var(--navy);
}

.kanban-card .card-phone {
  color: var(--text-muted);
  font-size: 12px;
}

.kanban-card .card-vendor {
  font-size: 11px;
  color: var(--orange);
  font-weight: 700;
  margin-top: 4px;
}

.kanban-drop-target {
  background: rgba(232, 119, 34, 0.06);
  border: 2px dashed var(--orange) !important;
  border-radius: var(--radius);
}

/* ─── Chat / WhatsApp ────────────────────────────────────────────────────────── */
.chat-contact-item {
  padding: 14px 16px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.chat-contact-item:hover { background: #fff8f4; }
.chat-contact-item.active { background: #fff3e8; border-left: 3px solid var(--orange); }

.chat-contact-name { font-weight: 700; font-size: 14px; }

.chat-contact-preview {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 3px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 220px;
}

.chat-messages {
  flex: 1;
  overflow-y: auto;
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.msg-bubble {
  max-width: 65%;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 14px;
  line-height: 1.5;
  word-break: break-word;
}

.msg-inbound {
  background: white;
  border-bottom-left-radius: 4px;
  box-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.msg-outbound {
  background: #dcf8c6;
  border-bottom-right-radius: 4px;
}

.msg-time {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 3px;
}

.chat-input {
  background: white;
  padding: 14px 16px;
  display: flex;
  gap: 10px;
  align-items: flex-end;
  border-top: 1px solid var(--border);
}

.chat-textarea {
  flex: 1;
  resize: none;
  min-height: 44px;
  max-height: 120px;
  overflow-y: auto;
}

/* ─── Calendar ───────────────────────────────────────────────────────────────── */
.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 1px;
  background: var(--border);
}

.calendar-day-header {
  background: #f9fafb;
  padding: 10px;
  text-align: center;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.calendar-day {
  background: white;
  min-height: 100px;
  padding: 8px;
  transition: background 0.12s;
}

.calendar-day:hover { background: #fafafa; }
.calendar-day.other-month { background: #fafafa; }

.calendar-day.today {
  border-top: 2.5px solid var(--orange);
  background: #fff8f4;
}

.calendar-day-num {
  font-size: 13px;
  font-weight: 700;
  color: var(--text-muted);
  margin-bottom: 6px;
}

.calendar-day.today .calendar-day-num {
  color: var(--orange);
  font-size: 14px;
}

.calendar-event {
  font-size: 11px;
  background: var(--orange);
  color: white;
  padding: 2px 6px;
  border-radius: 4px;
  margin-bottom: 3px;
  overflow: hidden;
  white-space: nowrap;
  text-overflow: ellipsis;
  cursor: pointer;
  transition: opacity 0.1s;
}

.calendar-event:hover { opacity: 0.85; }
.calendar-event.overdue { background: var(--danger); }
.calendar-event.done { background: var(--success); }

/* ─── Toast Notifications ────────────────────────────────────────────────────── */
.toast-container {
  position: fixed;
  top: 20px;
  right: 20px;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  padding: 13px 18px;
  border-radius: 10px;
  color: white;
  font-size: 14px;
  font-weight: 500;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.15);
  animation: slideIn 0.2s ease;
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 260px;
  max-width: 380px;
  pointer-events: all;
  cursor: pointer;
}

.toast-success { background: var(--success); }
.toast-error { background: var(--danger); }
.toast-info { background: #3b82f6; }
.toast-warning { background: var(--warning); }

@keyframes slideIn {
  from { opacity: 0; transform: translateX(24px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* ─── Tasks ──────────────────────────────────────────────────────────────────── */
.task-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: white;
  margin-bottom: 8px;
  transition: box-shadow 0.12s;
}

.task-item:hover { box-shadow: 0 2px 8px rgba(0, 0, 0, 0.06); }
.task-item.overdue { border-left: 3px solid var(--danger); }
.task-item.done { opacity: 0.55; }

.task-checkbox {
  width: 18px;
  height: 18px;
  accent-color: var(--orange);
  cursor: pointer;
  flex-shrink: 0;
}

.task-type-icon { font-size: 18px; flex-shrink: 0; }

.task-title {
  font-weight: 600;
  font-size: 14px;
  color: var(--navy);
}

.task-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── Empty state ────────────────────────────────────────────────────────────── */
.empty-state {
  text-align: center;
  padding: 64px 24px;
}

.empty-state-icon {
  font-size: 48px;
  margin-bottom: 16px;
  display: block;
}

.empty-state h3 {
  font-size: 18px;
  font-weight: 700;
  margin-bottom: 8px;
  color: var(--navy);
}

.empty-state p {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 20px;
  max-width: 320px;
  margin-left: auto;
  margin-right: auto;
}

/* ─── Spinner ────────────────────────────────────────────────────────────────── */
.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.35);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ─── Alerts ─────────────────────────────────────────────────────────────────── */
.alert {
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  margin-bottom: 16px;
}

.alert-error {
  background: #fef2f2;
  color: #991b1b;
  border: 1px solid #fecaca;
}

.alert-success {
  background: #f0fdf4;
  color: #166534;
  border: 1px solid #bbf7d0;
}

/* ─── Code / Pre ─────────────────────────────────────────────────────────────── */
code {
  background: #f3f4f6;
  padding: 2px 6px;
  border-radius: 4px;
  font-size: 12.5px;
  color: var(--navy);
  font-family: 'SFMono-Regular', Consolas, monospace;
}

/* ─── Mobile bottom navigation ───────────────────────────────────────────────── */
.bottom-nav {
  display: none;
  position: fixed;
  bottom: 0;
  left: 0;
  right: 0;
  background: var(--navy);
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  z-index: 100;
}

.bottom-nav-items {
  display: flex;
}

.bottom-nav-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 9px 4px;
  color: rgba(255, 255, 255, 0.55);
  text-decoration: none;
  font-size: 10px;
  gap: 3px;
  transition: color 0.12s;
}

.bottom-nav-item.active,
.bottom-nav-item:hover { color: var(--orange); }

.bottom-nav-item svg {
  width: 22px;
  height: 22px;
}

/* ─── Utility classes ────────────────────────────────────────────────────────── */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }
.text-center { text-align: center; }
.font-bold { font-weight: 700; }
.truncate { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }

/* ─── Responsive ─────────────────────────────────────────────────────────────── */
@media (max-width: 900px) {
  :root { --sidebar-width: 200px; }
  .kanban-column { min-width: 220px; max-width: 220px; }
}

@media (max-width: 768px) {
  .sidebar { display: none; }
  .bottom-nav { display: block; }
  .main-content { margin-left: 0; padding-bottom: 70px; }

  .kanban-board { flex-direction: column; }
  .kanban-column { min-width: 100%; max-width: 100%; }

  .kpi-grid { grid-template-columns: repeat(2, 1fr); }

  .page-body { padding: 12px; }
  .page-header { padding: 12px 16px; }

  .chat-layout { grid-template-columns: 1fr !important; }

  .msg-bubble { max-width: 85%; }

  .calendar-day { min-height: 60px; padding: 4px; }
  .calendar-event { font-size: 10px; }
}

@media (max-width: 480px) {
  .kpi-grid { grid-template-columns: 1fr 1fr; }
  .card-value { font-size: 26px; }
  .page-header h1 { font-size: 17px; }
}

/* ─── Print ──────────────────────────────────────────────────────────────────── */
@media print {
  .sidebar, .bottom-nav, .page-header .btn, .toast-container { display: none; }
  .main-content { margin-left: 0; }
  .card { box-shadow: none; border: 1px solid #ddd; }
}
