/* ==========================================================================
   Kalqy — Reusable components
   ========================================================================== */

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  border: none;
  border-radius: var(--r-sm);
  padding: 0 22px;
  height: 48px;
  font-weight: 700;
  font-size: 14px;
  cursor: pointer;
  transition: var(--transition);
  white-space: nowrap;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); box-shadow: var(--shadow-md); }
.btn-secondary { background: var(--primary-light); color: var(--primary-dark); }
.btn-secondary:hover { background: #E0DCFF; }
.btn-outline { background: transparent; color: var(--text-primary); border: 1.5px solid var(--border); }
.btn-outline:hover { border-color: var(--primary); color: var(--primary-dark); }
.btn-ghost { background: transparent; color: var(--text-secondary); height: 40px; padding: 0 14px; }
.btn-ghost:hover { background: var(--background); color: var(--text-primary); }
.btn-danger { background: var(--danger-light); color: var(--danger); }
.btn-danger:hover { background: #FADADA; }
.btn-sm { height: 38px; padding: 0 16px; font-size: 13px; border-radius: var(--r-sm); }
.btn-block { width: 100%; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn {
  width: 44px; height: 44px; border-radius: var(--r-sm);
  display: inline-flex; align-items: center; justify-content: center;
  background: var(--surface); border: 1px solid var(--border);
  cursor: pointer; color: var(--text-secondary); transition: var(--transition);
  position: relative;
}
.icon-btn:hover { color: var(--primary); border-color: var(--primary); }
.icon-btn svg { width: 20px; height: 20px; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border-radius: var(--r-lg);
  border: 1px solid var(--border);
  padding: var(--sp-5);
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.card-hover:hover { box-shadow: var(--shadow-md); transform: translateY(-2px); }
.card-flush { padding: 0; overflow: hidden; }

/* ---------- Avatar ---------- */
.avatar {
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-family: var(--font-display);
  font-weight: 700;
  color: #fff;
  flex-shrink: 0;
  background: var(--primary);
}
.avatar-sm { width: 32px; height: 32px; font-size: 12px; }
.avatar-md { width: 44px; height: 44px; font-size: 15px; }
.avatar-lg { width: 64px; height: 64px; font-size: 22px; }
.avatar-xl { width: 96px; height: 96px; font-size: 32px; }
.avatar-wrap { position: relative; display: inline-flex; }
.online-dot {
  position: absolute; bottom: 1px; right: 1px;
  width: 11px; height: 11px; border-radius: 50%;
  background: var(--success); border: 2px solid var(--surface);
}

/* ---------- Badges ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px;
  font-size: 12px; font-weight: 700;
  padding: 4px 10px; border-radius: 999px;
  background: var(--background); color: var(--text-secondary);
}
.badge-primary { background: var(--primary-light); color: var(--primary-dark); }
.badge-success { background: var(--success-light); color: var(--success); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-info { background: var(--info-light); color: var(--info); }
.badge-secondary { background: var(--secondary-light); color: #B87400; }
.badge-verified { background: var(--success-light); color: var(--success); }

/* ---------- Chips / Filter pills ---------- */
.chip {
  padding: 9px 16px;
  border-radius: 999px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  font-weight: 600;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
  white-space: nowrap;
  transition: var(--transition);
}
.chip:hover { border-color: var(--primary); color: var(--primary-dark); }
.chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }
.chip-row { display: flex; gap: var(--sp-2); overflow-x: auto; padding-bottom: 4px; -ms-overflow-style: none; scrollbar-width: none; }
.chip-row::-webkit-scrollbar { display: none; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 6px; }
.field label { font-size: 13px; font-weight: 700; color: var(--text-primary); }
.field .hint { font-size: 12px; color: var(--text-muted); }
.input, .select, .textarea {
  border: 1.5px solid var(--border);
  border-radius: var(--r-sm);
  padding: 12px 14px;
  background: var(--surface);
  width: 100%;
  transition: var(--transition);
}
.input:focus, .select:focus, .textarea:focus { border-color: var(--primary); outline: none; }
.textarea { resize: vertical; min-height: 90px; font-family: inherit; }
.search-input-wrap { position: relative; }
.search-input-wrap svg { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); width: 18px; height: 18px; color: var(--text-muted); }
.search-input-wrap .input { padding-left: 42px; }
.radio-row, .checkbox-row { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border: 1.5px solid var(--border); border-radius: var(--r-sm); cursor: pointer; transition: var(--transition); }
.radio-row:hover, .checkbox-row:hover { border-color: var(--primary); }
.radio-row.selected, .checkbox-row.selected { border-color: var(--primary); background: var(--primary-light); }
.radio-row input, .checkbox-row input { accent-color: var(--primary); width: 18px; height: 18px; }

/* ---------- Tabs ---------- */
.tabs {
  display: flex;
  gap: var(--sp-1);
  border-bottom: 1px solid var(--border);
  overflow-x: auto;
  scrollbar-width: none;
}
.tabs::-webkit-scrollbar { display: none; }
.tab-btn {
  padding: 12px 16px;
  font-weight: 700;
  font-size: 14px;
  color: var(--text-secondary);
  background: none; border: none; cursor: pointer;
  border-bottom: 2.5px solid transparent;
  white-space: nowrap;
  transition: var(--transition);
}
.tab-btn:hover { color: var(--text-primary); }
.tab-btn.active { color: var(--primary-dark); border-color: var(--primary); }
.tab-panel { display: none; }
.tab-panel.active { display: block; animation: fadeIn 220ms ease; }

/* ---------- Modal ---------- */
.modal-backdrop {
  position: fixed; inset: 0; background: rgba(32, 35, 54, 0.5);
  display: none; align-items: center; justify-content: center;
  z-index: 200; padding: var(--sp-4);
  backdrop-filter: blur(2px);
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--r-lg);
  width: 100%; max-width: 460px;
  max-height: 88vh;
  overflow-y: auto;
  padding: var(--sp-6);
  animation: modalIn 220ms cubic-bezier(.2,.8,.2,1);
  box-shadow: var(--shadow-lg);
}
.modal-wide { max-width: 720px; }
.modal-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-4); }
.modal-close { background: none; border: none; cursor: pointer; color: var(--text-muted); width: 32px; height: 32px; border-radius: 50%; display: flex; align-items: center; justify-content: center; }
.modal-close:hover { background: var(--background); color: var(--text-primary); }
@keyframes modalIn { from { opacity: 0; transform: translateY(12px) scale(.98); } to { opacity: 1; transform: translateY(0) scale(1); } }
@media (max-width: 480px) {
  .modal-backdrop { align-items: flex-end; padding: 0; }
  .modal { max-width: 100%; border-radius: var(--r-lg) var(--r-lg) 0 0; max-height: 92vh; }
}

/* ---------- Bottom sheet (filters, mobile) ---------- */
.sheet-backdrop { position: fixed; inset: 0; background: rgba(32,35,54,0.5); display:none; z-index: 200; }
.sheet-backdrop.open { display: block; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; background: var(--surface);
  border-radius: var(--r-lg) var(--r-lg) 0 0; padding: var(--sp-6);
  max-height: 85vh; overflow-y: auto; z-index: 201;
  animation: modalIn 220ms cubic-bezier(.2,.8,.2,1);
}

/* ---------- Toast ---------- */
.toast-container {
  position: fixed; bottom: 96px; left: 50%; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: var(--sp-2);
  z-index: 300; width: min(92vw, 380px);
}
@media (min-width: 1024px) { .toast-container { bottom: var(--sp-6); } }
.toast {
  background: var(--text-primary); color: #fff;
  padding: 14px 18px; border-radius: var(--r-sm);
  font-weight: 600; font-size: 14px;
  box-shadow: var(--shadow-lg);
  display: flex; align-items: center; gap: var(--sp-3);
  animation: toastIn 220ms ease;
}
.toast.success { background: var(--success); }
.toast.error { background: var(--danger); }
@keyframes toastIn { from { opacity: 0; transform: translateY(10px); } to { opacity: 1; transform: translateY(0); } }

/* ---------- Progress bars ---------- */
.progress-bar { height: 8px; border-radius: 999px; background: var(--border); overflow: hidden; }
.progress-bar-fill { height: 100%; border-radius: 999px; background: var(--primary); transition: width 500ms ease; }
.progress-bar-fill.success { background: var(--success); }
.progress-bar-fill.secondary { background: var(--secondary); }

.ring {
  --ring-size: 64px; --ring-pct: 0;
  width: var(--ring-size); height: var(--ring-size); border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: conic-gradient(var(--primary) calc(var(--ring-pct) * 1%), var(--border) 0);
  position: relative; flex-shrink: 0;
}
.ring::before {
  content: ''; position: absolute; inset: 6px; border-radius: 50%; background: var(--surface);
}
.ring span { position: relative; font-weight: 800; font-size: 14px; font-family: var(--font-display); }

/* ---------- Simple bar chart ---------- */
.bar-chart { display: flex; align-items: flex-end; gap: 6px; height: 120px; }
.bar-chart .bar { flex: 1; background: var(--primary-light); border-radius: 6px 6px 2px 2px; position: relative; min-height: 4px; transition: height 500ms ease; }
.bar-chart .bar.today { background: var(--primary); }
.bar-chart-labels { display: flex; gap: 6px; margin-top: 6px; }
.bar-chart-labels span { flex: 1; text-align: center; font-size: 10px; color: var(--text-muted); }

/* ---------- Skeleton ---------- */
.skeleton {
  background: linear-gradient(90deg, #EEEFF6 25%, #F6F7FB 37%, #EEEFF6 63%);
  background-size: 400% 100%;
  animation: skeletonShine 1.4s ease infinite;
  border-radius: var(--r-sm);
}
@keyframes skeletonShine { 0% { background-position: 100% 50%; } 100% { background-position: 0 50%; } }

/* ---------- Empty / error states ---------- */
.state-block {
  text-align: center;
  padding: var(--sp-10) var(--sp-4);
  color: var(--text-secondary);
}
.state-block .state-icon {
  width: 64px; height: 64px; border-radius: 50%;
  background: var(--primary-light); color: var(--primary);
  display: flex; align-items: center; justify-content: center;
  margin: 0 auto var(--sp-4);
}
.state-block .state-icon svg { width: 30px; height: 30px; }
.state-block h3 { margin-bottom: var(--sp-2); }
.state-block.error .state-icon { background: var(--danger-light); color: var(--danger); }

/* ---------- Dropdown ---------- */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 8px); right: 0;
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--r-md); box-shadow: var(--shadow-lg);
  min-width: 260px; max-width: 92vw;
  padding: var(--sp-2); z-index: 100;
  display: none;
}
.dropdown-menu.open { display: block; animation: fadeIn 180ms ease; }
.dropdown-item {
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border-radius: var(--r-sm); cursor: pointer;
  transition: var(--transition);
}
.dropdown-item:hover { background: var(--background); }
.dropdown-header { display: flex; align-items: center; justify-content: space-between; padding: 8px 10px; font-weight: 700; font-size: 13px; color: var(--text-muted); }

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

/* ---------- Misc ---------- */
.divider { height: 1px; background: var(--border); }
.section-title { display: flex; align-items: center; justify-content: space-between; margin-bottom: var(--sp-4); }
.section-title h2 { font-size: 19px; }
.link-more { font-weight: 700; font-size: 13px; color: var(--primary); }
.pill-nav { display: flex; gap: var(--sp-2); background: var(--background); padding: 4px; border-radius: var(--r-sm); }
.pill-nav button { flex: 1; border: none; background: transparent; padding: 9px; border-radius: 10px; font-weight: 700; font-size: 13px; color: var(--text-secondary); cursor: pointer; transition: var(--transition); }
.pill-nav button.active { background: var(--surface); color: var(--primary-dark); box-shadow: var(--shadow-sm); }
