/* ============================================
   BANDAR AKI APP — Reusable Components
   Buttons, Cards, Forms, Tables, Modals, etc.
   ============================================ */

/* ══════════════════════════════════════════
   BUTTONS
   ══════════════════════════════════════════ */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  padding: 0.625rem 1.25rem;
  font-size: var(--fs-sm);
  font-weight: var(--fw-semibold);
  line-height: 1;
  border-radius: var(--radius-md);
  border: var(--border-subtle);
  transition: var(--transition-base);
  white-space: nowrap;
  user-select: none;
  position: relative;
  overflow: hidden;
}
.btn:active { transform: scale(0.97); }

/* Primary */
.btn-primary {
  background: var(--gradient-primary);
  color: #fff;
  border: none;
  box-shadow: var(--shadow-sm), var(--shadow-glow-sm);
}
.btn-primary:hover {
  box-shadow: var(--shadow-md), var(--shadow-glow);
  filter: brightness(1.1);
}

/* Secondary */
.btn-secondary {
  background: var(--clr-bg-elevated);
  color: var(--clr-text-primary);
}
.btn-secondary:hover { background: var(--clr-dark-600); }

/* Outline */
.btn-outline {
  background: transparent;
  color: var(--clr-primary-400);
  border: 1px solid var(--clr-primary-600);
}
.btn-outline:hover {
  background: rgba(220, 38, 38, 0.1);
  border-color: var(--clr-primary-400);
}

/* Ghost */
.btn-ghost {
  background: transparent;
  color: var(--clr-text-secondary);
  border: none;
}
.btn-ghost:hover { background: rgba(255,255,255,0.06); color: var(--clr-text-primary); }

/* Danger */
.btn-danger {
  background: var(--clr-error);
  color: #fff;
  border: none;
}
.btn-danger:hover { background: #DC2626; box-shadow: var(--shadow-md); }

/* Success */
.btn-success {
  background: var(--clr-success);
  color: #fff;
  border: none;
}
.btn-success:hover { filter: brightness(1.1); }

/* Sizes */
.btn-sm { padding: 0.4rem 0.85rem; font-size: var(--fs-xs); }
.btn-lg { padding: 0.85rem 1.75rem; font-size: var(--fs-md); }
.btn-xl { padding: 1rem 2.25rem; font-size: var(--fs-lg); border-radius: var(--radius-lg); }

/* Icon button */
.btn-icon {
  width: 40px; height: 40px;
  padding: 0; border-radius: var(--radius-md);
  display: inline-flex; align-items: center; justify-content: center;
}
.btn-icon.btn-sm { width: 32px; height: 32px; }
.btn-icon.btn-lg { width: 48px; height: 48px; }

/* Disabled */
.btn:disabled, .btn[disabled] {
  opacity: 0.5; cursor: not-allowed; pointer-events: none;
}

/* Loading state */
.btn.loading { color: transparent; pointer-events: none; }
.btn.loading::after {
  content: '';
  position: absolute;
  width: 18px; height: 18px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

/* ══════════════════════════════════════════
   CARDS
   ══════════════════════════════════════════ */
.card {
  background: var(--gradient-card);
  border: var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
  transition: var(--transition-base);
  position: relative;
  overflow: hidden;
}
.card::before {
  content: '';
  position: absolute; inset: 0;
  background: var(--gradient-glass);
  pointer-events: none;
}
.card:hover { border-color: rgba(255,255,255,0.12); }

/* Glass card */
.card-glass {
  background: var(--clr-bg-glass);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  border: var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--sp-6);
}

/* Stat card */
.stat-card {
  background: var(--gradient-card);
  border: var(--border-subtle);
  border-radius: var(--radius-lg);
  padding: var(--sp-5);
  position: relative; overflow: hidden;
  transition: var(--transition-base);
}
.stat-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-lg);
  border-color: rgba(255,255,255,0.1);
}
.stat-card__icon {
  width: 48px; height: 48px;
  border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  font-size: 1.5rem;
  margin-bottom: var(--sp-3);
}
.stat-card__icon--primary { background: rgba(220,38,38,0.15); color: var(--clr-primary-400); }
.stat-card__icon--success { background: var(--clr-success-bg); color: var(--clr-success); }
.stat-card__icon--warning { background: var(--clr-warning-bg); color: var(--clr-warning); }
.stat-card__icon--info    { background: var(--clr-info-bg); color: var(--clr-info); }
.stat-card__label { font-size: var(--fs-sm); color: var(--clr-text-muted); margin-bottom: var(--sp-1); }
.stat-card__value { font-size: var(--fs-2xl); font-weight: var(--fw-bold); font-family: var(--font-display); }
.stat-card__trend { font-size: var(--fs-xs); margin-top: var(--sp-2); display: flex; align-items: center; gap: var(--sp-1); }
.stat-card__trend--up   { color: var(--clr-success); }
.stat-card__trend--down { color: var(--clr-error); }

/* ══════════════════════════════════════════
   FORM ELEMENTS
   ══════════════════════════════════════════ */
.form-group { margin-bottom: var(--sp-5); }
.form-label {
  display: block;
  font-size: var(--fs-sm);
  font-weight: var(--fw-medium);
  color: var(--clr-text-secondary);
  margin-bottom: var(--sp-2);
}
.form-label .required { color: var(--clr-primary-400); margin-left: 2px; }

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.65rem 0.9rem;
  font-size: var(--fs-sm);
  background: var(--clr-bg-surface);
  border: var(--border-default);
  border-radius: var(--radius-md);
  color: var(--clr-text-primary);
  transition: var(--transition-fast);
}
.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--clr-primary-500);
  box-shadow: 0 0 0 3px rgba(220,38,38,0.15);
}
.form-input::placeholder { color: var(--clr-text-muted); }
.form-textarea { min-height: 100px; resize: vertical; }
.form-select { appearance: none; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%2394A3B8' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10z'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 12px center;
  padding-right: 2.2rem;
}
.form-hint { font-size: var(--fs-xs); color: var(--clr-text-muted); margin-top: var(--sp-1); }
.form-error { font-size: var(--fs-xs); color: var(--clr-error); margin-top: var(--sp-1); }
.form-input.error { border-color: var(--clr-error); }

/* Search input */
.search-input {
  position: relative;
}
.search-input input {
  padding-left: 2.5rem;
}
.search-input .search-icon {
  position: absolute;
  left: 0.85rem; top: 50%;
  transform: translateY(-50%);
  color: var(--clr-text-muted);
  pointer-events: none;
}

/* ══════════════════════════════════════════
   TABLES
   ══════════════════════════════════════════ */
.table-wrapper {
  overflow-x: auto;
  border: var(--border-subtle);
  border-radius: var(--radius-lg);
  background: var(--clr-bg-surface);
}
.data-table { width: 100%; }
.data-table thead {
  background: rgba(255,255,255,0.03);
  border-bottom: var(--border-default);
}
.data-table th {
  padding: 0.85rem 1rem;
  text-align: left;
  font-size: var(--fs-xs);
  font-weight: var(--fw-semibold);
  color: var(--clr-text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.data-table td {
  padding: 0.8rem 1rem;
  font-size: var(--fs-sm);
  color: var(--clr-text-secondary);
  border-bottom: var(--border-subtle);
}
.data-table tbody tr { transition: var(--transition-fast); }
.data-table tbody tr:hover { background: rgba(255,255,255,0.03); }
.data-table tbody tr:last-child td { border-bottom: none; }

/* ══════════════════════════════════════════
   BADGES
   ══════════════════════════════════════════ */
.badge {
  display: inline-flex; align-items: center; gap: 4px;
  padding: 0.2rem 0.65rem;
  font-size: var(--fs-xs); font-weight: var(--fw-medium);
  border-radius: var(--radius-full);
  white-space: nowrap;
}
.badge--primary { background: rgba(220,38,38,0.15); color: var(--clr-primary-400); }
.badge--success { background: var(--clr-success-bg); color: var(--clr-success); }
.badge--warning { background: var(--clr-warning-bg); color: var(--clr-warning); }
.badge--danger  { background: var(--clr-error-bg); color: var(--clr-error); }
.badge--info    { background: var(--clr-info-bg); color: var(--clr-info); }
.badge--neutral { background: rgba(255,255,255,0.08); color: var(--clr-text-secondary); }

/* Dot indicator */
.badge--dot::before {
  content: '';
  width: 6px; height: 6px;
  border-radius: 50%;
  background: currentColor;
}

/* ══════════════════════════════════════════
   MODAL / DIALOG
   ══════════════════════════════════════════ */
.modal-overlay {
  position: fixed; inset: 0;
  background: var(--clr-bg-overlay);
  backdrop-filter: blur(4px);
  z-index: var(--z-modal);
  display: flex; align-items: center; justify-content: center;
  padding: var(--sp-4);
  opacity: 0; visibility: hidden;
  transition: var(--transition-base);
}
.modal-overlay.active { opacity: 1; visibility: visible; }
.modal {
  background: var(--clr-bg-surface);
  border: var(--border-default);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 520px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  transform: scale(0.95) translateY(8px);
  transition: var(--transition-base);
}
.modal-overlay.active .modal { transform: scale(1) translateY(0); }
.modal__header {
  display: flex; align-items: center; justify-content: space-between;
  padding: var(--sp-5) var(--sp-6);
  border-bottom: var(--border-subtle);
}
.modal__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); }
.modal__close { width: 32px; height: 32px; border-radius: var(--radius-md);
  display: flex; align-items: center; justify-content: center;
  color: var(--clr-text-muted); transition: var(--transition-fast); cursor: pointer;
}
.modal__close:hover { background: rgba(255,255,255,0.08); color: var(--clr-text-primary); }
.modal__body { padding: var(--sp-6); }
.modal__footer {
  display: flex; justify-content: flex-end; gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-6);
  border-top: var(--border-subtle);
}

/* ══════════════════════════════════════════
   TOAST NOTIFICATIONS
   ══════════════════════════════════════════ */
.toast-container {
  position: fixed; top: var(--sp-6); right: var(--sp-6);
  z-index: var(--z-toast);
  display: flex; flex-direction: column; gap: var(--sp-3);
  pointer-events: none;
  max-width: 380px; width: 100%;
}
.toast {
  pointer-events: auto;
  background: var(--clr-bg-surface);
  border: var(--border-default);
  border-radius: var(--radius-lg);
  padding: var(--sp-4);
  box-shadow: var(--shadow-lg);
  display: flex; align-items: flex-start; gap: var(--sp-3);
  animation: slideInRight var(--duration-slow) var(--ease-spring) forwards;
  position: relative; overflow: hidden;
}
.toast.removing { animation: slideOutRight var(--duration-normal) var(--ease-smooth) forwards; }
.toast__icon { font-size: 1.25rem; flex-shrink: 0; margin-top: 1px; }
.toast__content { flex: 1; }
.toast__title { font-size: var(--fs-sm); font-weight: var(--fw-semibold); margin-bottom: 2px; }
.toast__message { font-size: var(--fs-xs); color: var(--clr-text-muted); }
.toast__close { cursor: pointer; color: var(--clr-text-muted); flex-shrink: 0; background: none; border: none; }
.toast__close:hover { color: var(--clr-text-primary); }
.toast__progress {
  position: absolute; bottom: 0; left: 0; height: 3px;
  border-radius: 0 0 var(--radius-lg) var(--radius-lg);
  animation: shrink linear forwards;
}
@keyframes shrink { from { width: 100%; } to { width: 0%; } }

.toast--success { border-left: 3px solid var(--clr-success); }
.toast--success .toast__icon { color: var(--clr-success); }
.toast--success .toast__progress { background: var(--clr-success); }
.toast--error { border-left: 3px solid var(--clr-error); }
.toast--error .toast__icon { color: var(--clr-error); }
.toast--error .toast__progress { background: var(--clr-error); }
.toast--warning { border-left: 3px solid var(--clr-warning); }
.toast--warning .toast__icon { color: var(--clr-warning); }
.toast--warning .toast__progress { background: var(--clr-warning); }
.toast--info { border-left: 3px solid var(--clr-info); }
.toast--info .toast__icon { color: var(--clr-info); }
.toast--info .toast__progress { background: var(--clr-info); }

/* ══════════════════════════════════════════
   LOADING / SKELETON
   ══════════════════════════════════════════ */
.spinner {
  width: 32px; height: 32px;
  border: 3px solid rgba(255,255,255,0.1);
  border-top-color: var(--clr-primary-500);
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
.spinner--sm { width: 20px; height: 20px; border-width: 2px; }
.spinner--lg { width: 48px; height: 48px; border-width: 4px; }

.skeleton {
  background: linear-gradient(90deg, var(--clr-bg-elevated) 25%, rgba(255,255,255,0.06) 50%, var(--clr-bg-elevated) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.5s ease-in-out infinite;
  border-radius: var(--radius-md);
}
.skeleton--text { height: 14px; margin-bottom: var(--sp-2); }
.skeleton--title { height: 24px; width: 60%; margin-bottom: var(--sp-3); }
.skeleton--avatar { width: 48px; height: 48px; border-radius: 50%; }
.skeleton--card { height: 140px; border-radius: var(--radius-lg); }

/* ══════════════════════════════════════════
   EMPTY STATE
   ══════════════════════════════════════════ */
.empty-state {
  text-align: center;
  padding: var(--sp-16) var(--sp-6);
  color: var(--clr-text-muted);
}
.empty-state__icon { font-size: 3rem; margin-bottom: var(--sp-4); opacity: 0.4; }
.empty-state__title { font-size: var(--fs-lg); font-weight: var(--fw-semibold); color: var(--clr-text-secondary); margin-bottom: var(--sp-2); }
.empty-state__text { font-size: var(--fs-sm); max-width: 360px; margin-inline: auto; }

/* ══════════════════════════════════════════
   AVATAR
   ══════════════════════════════════════════ */
.avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--gradient-primary);
  display: flex; align-items: center; justify-content: center;
  font-size: var(--fs-sm); font-weight: var(--fw-bold);
  color: #fff; flex-shrink: 0;
  text-transform: uppercase;
}
.avatar--sm { width: 32px; height: 32px; font-size: var(--fs-xs); }
.avatar--lg { width: 56px; height: 56px; font-size: var(--fs-lg); }

/* ══════════════════════════════════════════
   DIVIDER
   ══════════════════════════════════════════ */
.divider {
  height: 1px;
  background: rgba(255,255,255,0.06);
  margin: var(--sp-6) 0;
  border: none;
}

/* ══════════════════════════════════════════
   DROPDOWN
   ══════════════════════════════════════════ */
.dropdown { position: relative; }
.dropdown-menu {
  position: absolute; top: calc(100% + 4px); right: 0;
  min-width: 180px;
  background: var(--clr-bg-surface);
  border: var(--border-default);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xl);
  padding: var(--sp-2);
  z-index: var(--z-dropdown);
  opacity: 0; visibility: hidden;
  transform: translateY(-4px);
  transition: var(--transition-fast);
}
.dropdown-menu.show { opacity: 1; visibility: visible; transform: translateY(0); }
.dropdown-item {
  display: flex; align-items: center; gap: var(--sp-2);
  padding: 0.55rem 0.75rem;
  font-size: var(--fs-sm);
  color: var(--clr-text-secondary);
  border-radius: var(--radius-md);
  cursor: pointer;
  transition: var(--transition-fast);
}
.dropdown-item:hover { background: rgba(255,255,255,0.06); color: var(--clr-text-primary); }
.dropdown-item--danger:hover { background: var(--clr-error-bg); color: var(--clr-error); }
.dropdown-divider { height: 1px; background: rgba(255,255,255,0.06); margin: var(--sp-1) 0; }

/* ══════════════════════════════════════════
   TABS
   ══════════════════════════════════════════ */
.tabs {
  display: flex; gap: var(--sp-1);
  border-bottom: var(--border-subtle);
  margin-bottom: var(--sp-6);
}
.tab-item {
  padding: 0.7rem 1rem;
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
  color: var(--clr-text-muted);
  border-bottom: 2px solid transparent;
  cursor: pointer;
  transition: var(--transition-fast);
}
.tab-item:hover { color: var(--clr-text-secondary); }
.tab-item.active { color: var(--clr-primary-400); border-bottom-color: var(--clr-primary-500); }

/* ══════════════════════════════════════════
   PAGINATION
   ══════════════════════════════════════════ */
.pagination {
  display: flex; align-items: center; justify-content: center;
  gap: var(--sp-1); margin-top: var(--sp-6);
}
.page-btn {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-md);
  font-size: var(--fs-sm); font-weight: var(--fw-medium);
  color: var(--clr-text-secondary);
  cursor: pointer; transition: var(--transition-fast);
}
.page-btn:hover { background: rgba(255,255,255,0.06); }
.page-btn.active { background: var(--clr-primary-600); color: #fff; }
.page-btn:disabled { opacity: 0.3; cursor: not-allowed; }

/* ══════════════════════════════════════════
   MOBILE RESPONSIVE — All Components
   ══════════════════════════════════════════ */

/* Tablet */
@media (max-width: 768px) {
  /* Modal full-width on mobile */
  .modal {
    max-width: calc(100vw - 2rem);
    max-height: 85vh;
    margin: auto;
  }
  .modal__header { padding: var(--sp-4) var(--sp-5); }
  .modal__body { padding: var(--sp-5); }
  .modal__footer {
    padding: var(--sp-4) var(--sp-5);
    flex-wrap: wrap;
  }
  .modal__footer .btn { flex: 1; min-width: 120px; }

  /* Tabs scroll horizontal */
  .tabs {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    gap: 0;
  }
  .tabs::-webkit-scrollbar { display: none; }
  .tab-item { white-space: nowrap; flex-shrink: 0; }
}

/* Mobile */
@media (max-width: 640px) {
  /* Toast to bottom-center on mobile */
  .toast-container {
    top: auto;
    bottom: var(--sp-4);
    right: var(--sp-4);
    left: var(--sp-4);
    max-width: 100%;
  }

  /* Button full-width helpers */
  .btn-xl {
    padding: 0.85rem 1.5rem;
    font-size: var(--fs-base);
    width: 100%;
    justify-content: center;
  }

  /* Card padding compact */
  .card { padding: var(--sp-4); }
  .card-glass { padding: var(--sp-4); }

  /* Stat card compact */
  .stat-card { padding: var(--sp-4); }
  .stat-card__icon { width: 40px; height: 40px; font-size: 1.25rem; }
  .stat-card__value { font-size: var(--fs-xl); }

  /* Form improvements */
  .form-group { margin-bottom: var(--sp-4); }
  .form-input, .form-select, .form-textarea {
    padding: 0.75rem 1rem;
    font-size: var(--fs-base);
  }

  /* Empty state compact */
  .empty-state { padding: var(--sp-10) var(--sp-4); }
  .empty-state__icon { font-size: 2.5rem; }

  /* Search input full-width */
  .search-input { width: 100%; }
  .search-input input { width: 100%; }
}

/* Small mobile */
@media (max-width: 480px) {
  .modal {
    max-width: calc(100vw - 1.5rem);
    border-radius: var(--radius-lg);
  }
  .modal__header { padding: var(--sp-3) var(--sp-4); }
  .modal__body { padding: var(--sp-4); }
  .modal__footer {
    padding: var(--sp-3) var(--sp-4);
    gap: var(--sp-2);
  }
  .modal__footer .btn { width: 100%; }

  /* Badge compact */
  .badge { font-size: 0.65rem; padding: 0.15rem 0.5rem; }

  /* Pagination compact */
  .page-btn { width: 32px; height: 32px; font-size: var(--fs-xs); }
}
