/* Quickly CRM — Design System */
:root {
  --primary:       #6366f1;
  --primary-dark:  #4f46e5;
  --primary-light: #eef2ff;
  --secondary:     #64748b;
  --success:       #16a34a;
  --warning:       #d97706;
  --danger:        #dc2626;
  --info:          #0891b2;
  --surface:       #ffffff;
  --bg:            #f1f5f9;
  --border:        #e2e8f0;
  --text:          #1e293b;
  --text-muted:    #64748b;
  --text-light:    #94a3b8;
  --sidebar-w:     240px;
  --radius-sm:     6px;
  --radius:        10px;
  --radius-lg:     14px;
  --shadow-sm:     0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.06);
  --shadow:        0 4px 6px -1px rgba(0,0,0,.08), 0 2px 4px -1px rgba(0,0,0,.06);
  --shadow-lg:     0 10px 15px -3px rgba(0,0,0,.08), 0 4px 6px -2px rgba(0,0,0,.05);
  --transition:    all .18s ease;
}

[data-theme="dark"] {
  --primary:       #818cf8;
  --primary-dark:  #6366f1;
  --primary-light: #1e1b4b;
  --surface:       #1e293b;
  --bg:            #0f172a;
  --border:        #334155;
  --text:          #e2e8f0;
  --text-muted:    #94a3b8;
  --text-light:    #64748b;
}

[data-theme="dark"] .table thead th { background: #1e293b; }
[data-theme="dark"] .table-hover tbody tr:hover td { background: #334155; }
[data-theme="dark"] .table tbody td { border-bottom-color: #334155; }
[data-theme="dark"] .input-group-text { background: #334155; border-color: #475569; color: #94a3b8; }
[data-theme="dark"] .btn-secondary { background: #334155; border-color: #475569; color: #e2e8f0; }
[data-theme="dark"] .btn-outline-secondary { border-color: #475569; color: #94a3b8; }
[data-theme="dark"] .btn-outline-secondary:hover { background: #334155; color: #e2e8f0; }
[data-theme="dark"] .modal-content { background: var(--surface); }
[data-theme="dark"] .modal-header, [data-theme="dark"] .modal-footer { border-color: var(--border); }
[data-theme="dark"] .btn-close { filter: invert(1); }
[data-theme="dark"] .alert-warning { background: #78350f; color: #fef3c7; }
[data-theme="dark"] .alert-danger { background: #7f1d1d; color: #fee2e2; }
[data-theme="dark"] .crm-sidebar { background: #0f172a; border-color: #334155; }
[data-theme="dark"] .kanban-column { background: #0f172a; }

*, *::before, *::after { box-sizing: border-box; }

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

.theme-toggle {
  background: none;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-muted);
  width: 36px;
  height: 36px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: var(--transition);
}
.theme-toggle:hover { color: var(--primary); border-color: var(--primary); }

/* ─── Login ─── */
.login-page {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px 16px;
  position: relative;
}
.login-page .login-theme-toggle { position: absolute; top: 16px; right: 16px; }
.login-card {
  width: 100%;
  max-width: 420px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  padding: 32px 28px;
}
.login-card .alert { margin: 0 0 16px; }
.login-brand { text-align: center; margin-bottom: 28px; }
.login-brand .brand-icon {
  width: 56px; height: 56px; margin: 0 auto 12px;
  border-radius: var(--radius-sm);
  background: var(--primary);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 24px;
}
.login-brand h1 { font-size: 1.35rem; font-weight: 700; margin: 0 0 6px; color: var(--primary); }
.login-brand p { margin: 0; color: var(--text-muted); font-size: 0.95rem; }

/* ─── App layout ─── */
.crm-app { display: flex; min-height: 100vh; }

.crm-sidebar {
  width: var(--sidebar-w);
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: fixed;
  top: 0; left: 0; bottom: 0;
  z-index: 200;
  transition: transform .25s ease;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 18px 16px;
  font-weight: 700;
  font-size: 15px;
  color: var(--primary);
  border-bottom: 1px solid var(--border);
}
.sidebar-brand .brand-icon {
  width: 34px; height: 34px;
  background: var(--primary);
  border-radius: var(--radius-sm);
  color: white;
  display: flex; align-items: center; justify-content: center;
  font-size: 15px;
}

.sidebar-nav { flex: 1; padding: 12px 10px; overflow-y: auto; }
.sidebar-nav .nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 10px 12px;
  margin-bottom: 4px;
  border: none;
  border-radius: var(--radius-sm);
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  text-align: left;
  cursor: pointer;
  transition: var(--transition);
}
.sidebar-nav .nav-item:hover { background: var(--primary-light); color: var(--primary); }
.sidebar-nav .nav-item.active {
  background: var(--primary-light);
  color: var(--primary);
  font-weight: 600;
}
.sidebar-nav .nav-item i { width: 18px; text-align: center; }

.sidebar-footer {
  padding: 14px 12px;
  border-top: 1px solid var(--border);
}
.sidebar-footer .user-name {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  margin-bottom: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.crm-main {
  flex: 1;
  margin-left: var(--sidebar-w);
  min-width: 0;
  display: flex;
  flex-direction: column;
}

.crm-topbar {
  height: 56px;
  padding: 0 20px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  gap: 12px;
  position: sticky;
  top: 0;
  z-index: 100;
}
.page-title { font-size: 1.1rem; font-weight: 600; margin: 0; flex: 1; }
.topbar-actions { display: flex; gap: 8px; }

.crm-content { padding: 20px; flex: 1; }

.view-panel { display: none; }
.view-panel.active { display: block; }

.view-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.search-input { max-width: 280px; }
.filter-select { max-width: 200px; }

/* ─── Cards & KPI ─── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.card-header {
  padding: 14px 18px;
  font-weight: 600;
  font-size: 13px;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
}
.card-header i { color: var(--primary); margin-right: 8px; }
.card-body { padding: 18px; }

.kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 14px;
  margin-bottom: 4px;
}
.kpi-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  box-shadow: var(--shadow-sm);
}
.kpi-card .kpi-label { font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; color: var(--text-muted); margin-bottom: 6px; }
.kpi-card .kpi-value { font-size: 1.5rem; font-weight: 700; color: var(--text); line-height: 1.2; }
.kpi-card .kpi-sub { font-size: 11px; color: var(--text-light); margin-top: 4px; }
.kpi-card.accent { border-left: 3px solid var(--primary); }
.kpi-card.success { border-left: 3px solid var(--success); }
.kpi-card.warning { border-left: 3px solid var(--warning); }

/* ─── Pipeline chart bars ─── */
.pipeline-bar-row {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
}
.pipeline-bar-label { width: 100px; font-size: 12px; font-weight: 500; flex-shrink: 0; }
.pipeline-bar-track { flex: 1; height: 28px; background: var(--bg); border-radius: var(--radius-sm); overflow: hidden; position: relative; }
.pipeline-bar-fill {
  height: 100%;
  border-radius: var(--radius-sm);
  display: flex;
  align-items: center;
  padding: 0 10px;
  font-size: 11px;
  font-weight: 600;
  color: white;
  min-width: 40px;
  transition: width .4s ease;
}
.pipeline-bar-meta { width: 80px; text-align: right; font-size: 11px; color: var(--text-muted); flex-shrink: 0; }

/* ─── Kanban ─── */
.kanban-board {
  display: flex;
  gap: 14px;
  overflow-x: auto;
  padding-bottom: 12px;
  min-height: 420px;
}
.kanban-column {
  flex: 0 0 280px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  max-height: calc(100vh - 180px);
}
.kanban-column-header {
  padding: 12px 14px;
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  font-weight: 600;
  font-size: 13px;
}
.kanban-column-header .stage-dot {
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 8px;
  display: inline-block;
}
.kanban-column-body {
  padding: 10px;
  overflow-y: auto;
  flex: 1;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.kanban-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px;
  cursor: grab;
  transition: var(--transition);
  box-shadow: var(--shadow-sm);
}
.kanban-card:hover { border-color: var(--primary); box-shadow: var(--shadow); }
.kanban-card.dragging { opacity: .5; }
.kanban-card-title { font-weight: 600; font-size: 13px; margin-bottom: 6px; }
.kanban-card-meta { font-size: 11px; color: var(--text-muted); }
.kanban-card-value { font-weight: 700; color: var(--primary); font-size: 13px; margin-top: 6px; }
.kanban-column.drag-over { background: var(--primary-light); border-color: var(--primary); }

/* ─── Tables ─── */
.table { font-size: 13px; color: var(--text); margin-bottom: 0; }
.table thead th {
  background: #f8fafc;
  border-bottom: 1px solid var(--border);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .4px;
  color: var(--text-muted);
  padding: 10px 12px;
  white-space: nowrap;
}
.table tbody td { padding: 11px 12px; vertical-align: middle; border-bottom: 1px solid #f1f5f9; }
.table-hover tbody tr:hover td { background: #f8fafc; }

/* ─── Forms & buttons ─── */
.form-control, .form-select {
  border: 1.5px solid var(--border);
  border-radius: var(--radius-sm);
  font-size: 13px;
  color: var(--text);
  background: var(--surface);
  transition: var(--transition);
}
.form-control:focus, .form-select:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px rgba(99,102,241,.12);
  outline: none;
}
.form-label { font-size: 12px; font-weight: 600; color: var(--text-muted); margin-bottom: 6px; }
.input-group-text { background: #f8fafc; border: 1.5px solid var(--border); color: var(--text-muted); }

.btn { font-size: 13px; font-weight: 500; border-radius: var(--radius-sm); display: inline-flex; align-items: center; gap: 6px; }
.btn-primary { background: var(--primary); border-color: var(--primary); color: white; }
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); color: white; }
.btn i { color: inherit !important; }

.badge-stage {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  color: white;
}
.badge-estado {
  display: inline-block;
  padding: 3px 8px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  background: var(--primary-light);
  color: var(--primary);
}

.alert { border: none; border-radius: var(--radius); font-size: 13px; padding: 12px 16px; }
.alert-danger { background: #fee2e2; color: #dc2626; }
.alert-warning { background: #fef3c7; color: #92400e; }

/* ─── Activity list ─── */
.activity-list { padding: 0; }
.activity-item {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px 18px;
  border-bottom: 1px solid var(--border);
}
.activity-item:last-child { border-bottom: none; }
.activity-icon {
  width: 36px; height: 36px;
  border-radius: var(--radius-sm);
  background: var(--primary-light);
  color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  flex-shrink: 0;
}
.activity-item.done { opacity: .55; }
.activity-item.done .activity-title { text-decoration: line-through; }
.activity-title { font-weight: 600; font-size: 13px; }
.activity-meta { font-size: 11px; color: var(--text-muted); margin-top: 2px; }

.list-empty {
  text-align: center;
  padding: 32px 16px;
  color: var(--text-light);
  font-size: 13px;
}

.apps-grid .activity-item { color: inherit; }
.apps-grid .activity-item:hover { background: var(--primary-light); }

#configTabs .nav-link { font-size: 13px; cursor: pointer; }

#mailWarning code {
  font-size: 11px;
  background: rgba(0,0,0,.06);
  padding: 1px 4px;
  border-radius: 4px;
}

.btn-icon {
  padding: 4px 8px;
  border: none;
  background: transparent;
  color: var(--text-muted);
  border-radius: var(--radius-sm);
  cursor: pointer;
}
.btn-icon:hover { color: var(--primary); background: var(--primary-light); }
.btn-icon.danger:hover { color: var(--danger); background: #fee2e2; }

@media (max-width: 767px) {
  .crm-sidebar {
    transform: translateX(-100%);
  }
  .crm-sidebar.open { transform: translateX(0); box-shadow: var(--shadow-lg); }
  .crm-main { margin-left: 0; }
  .kpi-grid { grid-template-columns: repeat(2, 1fr); }
  .kanban-column { flex: 0 0 260px; }
}
