/* ── Buttons ─────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 8px 16px;
  font-family: var(--font);
  font-size: var(--font-size-base);
  font-weight: 500;
  border: 1px solid transparent;
  border-radius: var(--r-md);
  cursor: pointer;
  transition: all var(--transition-fast);
  text-decoration: none;
  white-space: nowrap;
  flex-shrink: 0;
  line-height: 1;
}

.btn:disabled { opacity: 0.5; cursor: not-allowed; pointer-events: none; }
.btn:active { transform: scale(0.98); }

.btn svg { width: 16px; height: 16px; flex-shrink: 0; }

/* Primary - Red */
.btn-primary {
  background: var(--red);
  color: white;
  border-color: var(--red);
}
.btn-primary:hover { background: var(--red-dark); border-color: var(--red-dark); box-shadow: var(--shadow-red); }

/* Secondary - outlined */
.btn-secondary {
  background: white;
  color: var(--text-primary);
  border-color: var(--border-dark);
}
.btn-secondary:hover { background: var(--bg-hover); border-color: var(--border-dark); }

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}
.btn-ghost:hover { background: var(--bg-hover); color: var(--text-primary); }

/* Danger */
.btn-danger {
  background: white;
  color: var(--red);
  border-color: var(--red-100);
}
.btn-danger:hover { background: var(--red-50); }

/* Dark */
.btn-dark {
  background: var(--dark);
  color: white;
  border-color: var(--dark);
}
.btn-dark:hover { background: var(--dark-2); }

/* Sizes */
.btn-sm { padding: 5px 12px; font-size: var(--font-size-sm); }
.btn-sm svg { width: 14px; height: 14px; }
.btn-lg { padding: 11px 24px; font-size: var(--font-size-md); }
.btn-icon { padding: 8px; }
.btn-icon.btn-sm { padding: 5px; }

/* ── Cards ──────────────────────────────────────────────────────────── */

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
}

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-4);
  gap: var(--sp-3);
}

.card-title {
  font-size: var(--font-size-md);
  font-weight: 600;
  color: var(--text-primary);
}

.card-subtitle {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  margin-top: 2px;
}

/* ── KPI Cards ──────────────────────────────────────────────────────── */

.kpi-card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
  transition: box-shadow var(--transition), border-color var(--transition);
  cursor: default;
}

.kpi-card:hover { box-shadow: var(--shadow-md); border-color: var(--border-dark); }

.kpi-card-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: var(--sp-3);
}

.kpi-icon {
  width: 40px;
  height: 40px;
  border-radius: var(--r-md);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}

.kpi-icon.red   { background: var(--red-light); color: var(--red); }
.kpi-icon.green { background: var(--green-light); color: var(--green); }
.kpi-icon.blue  { background: var(--blue-light); color: var(--blue); }
.kpi-icon.yellow{ background: var(--yellow-light); color: var(--yellow); }
.kpi-icon.dark  { background: rgba(10,15,30,0.08); color: var(--dark); }

.kpi-icon svg { width: 20px; height: 20px; }

.kpi-trend {
  font-size: var(--font-size-xs);
  font-weight: 600;
  padding: 2px 6px;
  border-radius: var(--r-full);
}

.kpi-trend.up   { background: var(--green-light); color: var(--green); }
.kpi-trend.down { background: var(--red-light); color: var(--red); }
.kpi-trend.flat { background: var(--bg-secondary); color: var(--text-muted); }

.kpi-value {
  font-size: 32px;
  font-weight: 700;
  letter-spacing: -1px;
  color: var(--text-primary);
  line-height: 1;
  margin-bottom: var(--sp-1);
}

.kpi-label {
  font-size: var(--font-size-sm);
  color: var(--text-muted);
  font-weight: 400;
}

/* ── Forms ──────────────────────────────────────────────────────────── */

.form-group { margin-bottom: var(--sp-4); }

.form-label {
  display: block;
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-secondary);
  margin-bottom: var(--sp-2);
}

.form-label .required { color: var(--red); margin-left: 2px; }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 9px 12px;
  background: var(--bg-input);
  border: 1px solid var(--border-input);
  border-radius: var(--r-md);
  font-family: var(--font);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
  outline: none;
  -webkit-appearance: none;
  color-scheme: light;
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  border-color: var(--border-focus);
  box-shadow: 0 0 0 3px var(--red-light);
}

.form-input::placeholder,
.form-textarea::placeholder { color: var(--text-disabled); }

.form-select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' fill='none' viewBox='0 0 20 20'%3E%3Cpath stroke='%236B7280' stroke-linecap='round' stroke-linejoin='round' stroke-width='1.5' d='M6 8l4 4 4-4'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 8px center;
  background-size: 20px;
  padding-right: 36px;
  cursor: pointer;
}

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

.form-hint {
  font-size: var(--font-size-xs);
  color: var(--text-muted);
  margin-top: var(--sp-1);
}

.pw-eye-btn {
  position: absolute;
  right: 10px;
  top: 50%;
  transform: translateY(-50%);
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  padding: 2px;
  border-radius: var(--r-sm);
  transition: color var(--transition-fast);
}
.pw-eye-btn:hover { color: var(--text-primary); }

.form-error {
  font-size: var(--font-size-xs);
  color: var(--red);
  margin-top: var(--sp-1);
}

.form-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--sp-4);
}

@media (max-width: 640px) { .form-row { grid-template-columns: 1fr; } }

/* ── Badges / Tags ──────────────────────────────────────────────────── */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 600;
  border-radius: var(--r-full);
  white-space: nowrap;
}

.badge-dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  flex-shrink: 0;
}

/* Lead status badges */
.badge-new         { background: var(--blue-light); color: var(--blue); }
.badge-contacted   { background: var(--yellow-light); color: var(--yellow); }
.badge-qualified   { background: var(--purple-light); color: var(--purple); }
.badge-proposal    { background: var(--red-light); color: var(--red); }
.badge-negotiation { background: rgba(217,119,6,0.1); color: #92400E; }
.badge-won         { background: var(--green-light); color: var(--green); }
.badge-lost        { background: var(--bg-secondary); color: var(--text-muted); }

/* Priority badges */
.badge-critical  { background: #FFF0F0; color: #991B1B; }
.badge-high      { background: var(--red-light); color: var(--red); }
.badge-medium    { background: var(--yellow-light); color: var(--yellow); }
.badge-low       { background: var(--blue-light); color: var(--blue); }

/* Role badges */
.badge-superadmin { background: var(--dark); color: white; }
.badge-admin      { background: var(--red-light-strong); color: var(--red-dark); }
.badge-employee   { background: var(--bg-secondary); color: var(--text-secondary); }

/* ── Tables ─────────────────────────────────────────────────────────── */

.table-wrapper {
  overflow-x: auto;
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  background: var(--bg-card);
}

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--font-size-base);
}

.table th {
  padding: 10px 14px;
  text-align: left;
  font-size: var(--font-size-xs);
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-muted);
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
  cursor: pointer;
  user-select: none;
}

.table th:hover { color: var(--text-primary); }

.table td {
  padding: 12px 14px;
  border-bottom: 1px solid var(--bg-tertiary);
  color: var(--text-primary);
  vertical-align: middle;
}

.table tr:last-child td { border-bottom: none; }

.table tr:hover td { background: var(--bg-hover); }
.table tr.selected td { background: var(--bg-selected); }

.table-actions {
  display: flex;
  gap: var(--sp-1);
  opacity: 0;
  transition: opacity var(--transition-fast);
}

.table tr:hover .table-actions { opacity: 1; }

/* ── Modals ─────────────────────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(10, 15, 30, 0.45);
  backdrop-filter: blur(2px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  z-index: 500;
  animation: fadeIn 0.15s ease;
}

@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

.modal {
  background: var(--bg-card);
  border-radius: var(--r-xl);
  box-shadow: var(--shadow-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  animation: slideUp 0.2s ease;
}

@keyframes slideUp { from { transform: translateY(16px); opacity: 0; } to { transform: translateY(0); opacity: 1; } }

.modal-lg { max-width: 760px; }
.modal-xl { max-width: 1000px; }

.modal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: var(--sp-5) var(--sp-6);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.modal-title {
  font-size: var(--font-size-lg);
  font-weight: 700;
}

.modal-close {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-muted);
  padding: var(--sp-1);
  border-radius: var(--r-sm);
  display: flex;
  align-items: center;
  transition: color var(--transition-fast), background var(--transition-fast);
}

.modal-close:hover { color: var(--text-primary); background: var(--bg-hover); }

/* form inside modal must participate in flex layout */
.modal > form,
.modal form.modal-form {
  display: flex;
  flex-direction: column;
  flex: 1;
  min-height: 0;
  overflow: hidden;
}

.modal-body {
  padding: var(--sp-6);
  overflow-y: auto;
  flex: 1;
  min-height: 0;
}

.modal-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

/* ── Toast Notifications ────────────────────────────────────────────── */

#toast-container {
  position: fixed;
  top: var(--sp-5);
  right: var(--sp-5);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: 9000;
  pointer-events: none;
}

.toast {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 12px var(--sp-4);
  background: var(--dark);
  color: white;
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  font-size: var(--font-size-sm);
  font-weight: 500;
  max-width: 360px;
  pointer-events: auto;
  animation: toastIn 0.25s ease;
}

@keyframes toastIn { from { transform: translateY(-12px) scale(0.96); opacity: 0; } to { transform: translateY(0) scale(1); opacity: 1; } }

.toast.success { background: var(--green); }
.toast.error   { background: var(--red); }
.toast.warning { background: var(--yellow); color: var(--dark); }
.toast.info    { background: var(--blue); }

.toast svg { width: 16px; height: 16px; flex-shrink: 0; }

@keyframes toastProgress { from { transform: scaleX(1); } to { transform: scaleX(0); } }

/* ── Search & Filter Bar ────────────────────────────────────────────── */

.filter-bar {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  margin-bottom: var(--sp-4);
  flex-wrap: wrap;
}

.search-input-wrap {
  position: relative;
  flex: 1;
  min-width: 200px;
  max-width: 360px;
}

.search-input-wrap svg {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  width: 16px;
  height: 16px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-input-wrap input {
  padding-left: 34px;
  width: 100%;
}

/* ── Empty State ────────────────────────────────────────────────────── */

.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: var(--sp-12) var(--sp-8);
  text-align: center;
  color: var(--text-muted);
}

.empty-state-icon {
  width: 56px;
  height: 56px;
  background: var(--bg-secondary);
  border-radius: var(--r-full);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--sp-4);
}

.empty-state-icon svg { width: 24px; height: 24px; }
.empty-state h3 { font-size: var(--font-size-md); font-weight: 600; color: var(--text-secondary); margin-bottom: var(--sp-2); }
.empty-state p { font-size: var(--font-size-sm); max-width: 320px; }

/* ── Tabs ────────────────────────────────────────────────────────────── */

.tabs {
  display: flex;
  border-bottom: 1px solid var(--border);
  gap: 0;
  margin-bottom: var(--sp-5);
}

.tab {
  padding: 10px var(--sp-4);
  font-size: var(--font-size-sm);
  font-weight: 500;
  color: var(--text-muted);
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  transition: color var(--transition-fast), border-color var(--transition-fast);
  white-space: nowrap;
}

.tab:hover { color: var(--text-primary); }
.tab.active { color: var(--red); border-bottom-color: var(--red); font-weight: 600; }

/* ── Dropdown Menu ──────────────────────────────────────────────────── */

.dropdown {
  position: relative;
  display: inline-flex;
}

.dropdown-menu {
  position: absolute;
  top: calc(100% + 4px);
  right: 0;
  min-width: 180px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-lg);
  z-index: 300;
  overflow: hidden;
  animation: fadeIn 0.12s ease;
}

.dropdown-item {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: 9px var(--sp-4);
  font-size: var(--font-size-base);
  color: var(--text-primary);
  cursor: pointer;
  transition: background var(--transition-fast);
}

.dropdown-item:hover { background: var(--bg-hover); }
.dropdown-item.danger { color: var(--red); }
.dropdown-item svg { width: 16px; height: 16px; flex-shrink: 0; color: var(--text-muted); }
.dropdown-item.danger svg { color: var(--red); }
.dropdown-divider { height: 1px; background: var(--border); }

/* ── Confirm Dialog ─────────────────────────────────────────────────── */

.confirm-dialog {
  max-width: 400px;
}

.confirm-dialog .modal-body {
  padding: var(--sp-6);
}

.confirm-dialog-icon {
  width: 48px;
  height: 48px;
  border-radius: var(--r-full);
  background: var(--red-50);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: var(--sp-4);
}

.confirm-dialog-icon svg { width: 24px; height: 24px; color: var(--red); }

/* ── Progress / Skeleton ─────────────────────────────────────────────── */

.skeleton {
  background: linear-gradient(90deg, var(--bg-secondary) 0%, var(--bg-tertiary) 50%, var(--bg-secondary) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--r-sm);
}

@keyframes shimmer { to { background-position: -200% 0; } }

/* ── Grid Layouts ────────────────────────────────────────────────────── */

.grid-kpi {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: var(--sp-4);
  margin-bottom: var(--sp-6);
}

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--sp-4); }
.grid-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: var(--sp-4); }
.grid-4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: var(--sp-4); }

@media (max-width: 1024px) {
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-3 { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 640px) {
  .grid-2, .grid-3, .grid-4 { grid-template-columns: 1fr; }
}

/* ── Activity Feed ───────────────────────────────────────────────────── */

.activity-list { display: flex; flex-direction: column; gap: 0; }

.activity-item {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid var(--bg-tertiary);
}

.activity-item:last-child { border-bottom: none; }

.activity-dot {
  width: 28px;
  height: 28px;
  border-radius: var(--r-full);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  margin-top: 2px;
}

.activity-dot svg { width: 14px; height: 14px; }

.activity-dot.note       { background: var(--blue-light); color: var(--blue); }
.activity-dot.call       { background: var(--green-light); color: var(--green); }
.activity-dot.email      { background: var(--purple-light); color: var(--purple); }
.activity-dot.status     { background: var(--yellow-light); color: var(--yellow); }
.activity-dot.assignment { background: var(--red-light); color: var(--red); }
.activity-dot.approval   { background: var(--green-light); color: var(--green); }

.activity-content { flex: 1; min-width: 0; }
.activity-text { font-size: var(--font-size-sm); color: var(--text-primary); line-height: 1.5; }
.activity-time { font-size: var(--font-size-xs); color: var(--text-muted); margin-top: 2px; }

/* ── Notification Bell ─────────────────────────────────────────────────── */

.notif-bell {
  position: relative;
  display: inline-flex;
  align-items: center;
}

.notif-bell .notif-dropdown {
  position: absolute;
  right: 0;
  top: 44px;
  width: 360px;
  background: var(--bg-card, #ffffff);
  border: 1px solid var(--border, #e2e8f0);
  border-radius: 10px;
  box-shadow: 0 8px 32px rgba(0,0,0,0.14);
  z-index: 9999;
  max-height: 460px;
  overflow: hidden;
  flex-direction: column;
  display: none;
}

.notif-item {
  padding: 12px 16px;
  border-bottom: 1px solid var(--border, #f0f0f0);
  cursor: pointer;
  transition: background 0.15s;
  border-left: 3px solid transparent;
}

.notif-item:hover { background: var(--bg-hover, #f7f9fc); }
.notif-item.unread { background: var(--bg-secondary, #f7fbff); }

.notif-item.priority-urgent { border-left-color: var(--red, #e53e3e); }
.notif-item.priority-high   { border-left-color: var(--yellow, #dd6b20); }
.notif-item.priority-normal { border-left-color: var(--blue, #3182ce); }
.notif-item.priority-low    { border-left-color: #718096; }

.notif-title {
  font-weight: 600;
  font-size: 13px;
  margin-bottom: 2px;
  color: var(--text-primary, #1a202c);
}

.notif-message {
  font-size: 12px;
  color: var(--text-muted, #718096);
  margin-bottom: 4px;
  line-height: 1.4;
}

.notif-time {
  font-size: 11px;
  color: var(--text-muted, #a0aec0);
}

@keyframes bell-pulse {
  0%, 100% { transform: rotate(0deg); }
  20%       { transform: rotate(-15deg); }
  40%       { transform: rotate(15deg); }
  60%       { transform: rotate(-10deg); }
  80%       { transform: rotate(10deg); }
}

.bell-animate {
  animation: bell-pulse 0.6s ease-in-out;
}
