/* ==========================================================================
   REUSABLE UI COMPONENTS (CARDS, TABLES, BUTTONS, MODALS, TOASTS, SKELETONS)
   ========================================================================== */

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.6rem 1.25rem;
  border-radius: var(--radius-md);
  font-weight: 600;
  font-size: 0.9rem;
  transition: all var(--transition-fast);
  cursor: pointer;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--primary-600);
  color: white;
  box-shadow: 0 2px 8px rgba(79, 70, 229, 0.3);
}
.btn-primary:hover {
  background: var(--primary-500);
  transform: translateY(-1px);
}

.btn-secondary {
  background: var(--bg-subtle);
  color: var(--text-main);
  border-color: var(--border-color);
}
.btn-secondary:hover {
  background: var(--bg-hover);
  border-color: var(--text-subtle);
}

.btn-success {
  background: var(--success-600);
  color: white;
}
.btn-danger {
  background: var(--danger-600);
  color: white;
}
.btn-outline-danger {
  border-color: var(--danger-500);
  color: var(--danger-500);
}
.btn-sm {
  padding: 0.35rem 0.75rem;
  font-size: 0.8rem;
  border-radius: var(--radius-sm);
}

/* Cards & Metric Cards */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  box-shadow: var(--shadow-sm);
  transition: all var(--transition-normal);
}

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

.card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 1.1rem;
  font-weight: 700;
  color: var(--text-main);
}

.metric-card {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
  padding: 1.25rem;
  border-radius: var(--radius-lg);
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  position: relative;
  overflow: hidden;
}

.metric-icon {
  width: 44px;
  height: 44px;
  border-radius: var(--radius-md);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.3rem;
  background: rgba(99, 102, 241, 0.12);
  color: var(--primary-400);
}

.metric-value {
  font-size: 1.75rem;
  font-weight: 800;
  color: var(--text-main);
  letter-spacing: -0.5px;
}

.metric-label {
  font-size: 0.85rem;
  color: var(--text-muted);
  font-weight: 600;
}

/* Badges */
.badge {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.25rem 0.65rem;
  border-radius: var(--radius-full);
  font-size: 0.75rem;
  font-weight: 700;
  white-space: nowrap;
}

.badge-active, .badge-completed, .badge-paid, .badge-success {
  background: var(--badge-bg-success);
  color: var(--badge-text-success);
  border: 1px solid var(--badge-border-success);
}

.badge-near-expiry, .badge-pending, .badge-partial, .badge-warning {
  background: var(--badge-bg-warning);
  color: var(--badge-text-warning);
  border: 1px solid var(--badge-border-warning);
}

.badge-expired, .badge-cancelled, .badge-failed, .badge-danger {
  background: var(--badge-bg-danger);
  color: var(--badge-text-danger);
  border: 1px solid var(--badge-border-danger);
}

.badge-paused {
  background: rgba(139, 92, 246, 0.15);
  color: #a78bfa;
  border: 1px solid rgba(139, 92, 246, 0.3);
}

[data-theme="light"] .badge-paused {
  background: #f5f3ff;
  color: #6d28d9;
  border-color: #ddd6fe;
}

.badge-secondary {
  background: var(--bg-subtle);
  color: var(--text-muted);
  border: 1px solid var(--border-color);
}

.badge-info {
  background: rgba(59, 130, 246, 0.15);
  color: #60a5fa;
  border: 1px solid rgba(59, 130, 246, 0.3);
}

[data-theme="light"] .badge-info {
  background: #eff6ff;
  color: #1d4ed8;
  border-color: #bfdbfe;
}

/* Data Tables */
.table-responsive {
  width: 100%;
  overflow-x: auto;
  border-radius: var(--radius-lg);
  border: 1px solid var(--border-color);
  background: var(--bg-surface);
}

.data-table {
  width: 100%;
  border-collapse: collapse;
  text-align: right;
}

.data-table th {
  background: var(--bg-subtle);
  padding: 0.85rem 1rem;
  font-weight: 700;
  font-size: 0.8rem;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border-color);
  white-space: nowrap;
}

.data-table td {
  padding: 0.95rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  font-size: 0.9rem;
  color: var(--text-main);
  vertical-align: middle;
}

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

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

/* Forms & Inputs */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  margin-bottom: 1rem;
}

.form-label {
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--text-main);
}

.form-input, .form-select, .form-textarea {
  background: var(--bg-subtle);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-md);
  padding: 0.65rem 0.9rem;
  color: var(--text-main);
  transition: all var(--transition-fast);
  width: 100%;
}

.form-input:focus, .form-select:focus, .form-textarea:focus {
  border-color: var(--primary-500);
  background: var(--bg-surface);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
  outline: none;
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.7);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  padding: 1rem;
}

.modal-backdrop.active {
  display: flex !important;
  opacity: 1;
  pointer-events: auto;
  animation: modal-fade-in 0.2s ease forwards;
}

@keyframes modal-fade-in {
  from { opacity: 0; }
  to { opacity: 1; }
}

.modal-card {
  background: var(--bg-surface);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  width: 100%;
  max-width: 580px;
  max-height: 90vh;
  overflow-y: auto;
  box-shadow: var(--shadow-xl);
  transform: translateY(0) scale(1);
  display: flex;
  flex-direction: column;
}

.modal-backdrop.active .modal-card {
  transform: translateY(0) scale(1);
}

.modal-header {
  padding: 1.25rem 1.5rem;
  border-bottom: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.modal-body {
  padding: 1.5rem;
  flex: 1;
}

.modal-footer {
  padding: 1rem 1.5rem;
  border-top: 1px solid var(--border-color);
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 0.75rem;
}

/* ==========================================================================
   LUXURY LOGIN MODAL & AUTHENTICATION COMPONENTS
   ========================================================================== */
.login-modal-container {
  width: 100%;
  max-width: 440px;
  margin: auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 1.25rem 0;
  z-index: 10;
}

.login-modal-card {
  max-width: 440px;
  width: 100%;
  background: var(--bg-surface-elevated, rgba(17, 24, 39, 0.94)) !important;
  border: 1px solid rgba(99, 102, 241, 0.32) !important;
  border-radius: var(--radius-2xl, 22px) !important;
  box-shadow: 0 25px 60px -15px rgba(0, 0, 0, 0.85), 0 0 45px rgba(14, 165, 233, 0.18) !important;
  overflow: hidden;
  position: relative;
  backdrop-filter: blur(24px);
  -webkit-backdrop-filter: blur(24px);
  animation: login-card-enter 0.35s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes login-card-enter {
  from { opacity: 0; transform: translateY(12px) scale(0.98); }
  to { opacity: 1; transform: translateY(0) scale(1); }
}

.login-modal-header {
  padding: 1.6rem 1.6rem 0.75rem;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  position: relative;
}

.login-logo-wrapper {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 0.65rem;
  position: relative;
  background: transparent !important;
  box-shadow: none !important;
  border: none !important;
}

.login-brand-img-full {
  width: 74px;
  height: auto;
  max-height: 78px;
  object-fit: contain;
  display: block;
  background: transparent !important;
  box-shadow: none !important;
  border: none !important;
  filter: none !important;
}

.login-title {
  margin: 0;
  font-size: 1.3rem;
  font-weight: 800;
  color: var(--text-main, #fff);
  letter-spacing: -0.3px;
}

.login-subtitle {
  font-size: 0.82rem;
  color: var(--text-muted, #94a3b8);
  margin-top: 4px;
}

.login-footer-copy {
  font-size: 0.76rem;
  color: var(--text-muted, #94a3b8);
  text-align: center;
  letter-spacing: 0.2px;
  opacity: 0.8;
  user-select: none;
}

.login-input-group {
  position: relative;
  display: flex;
  align-items: center;
}

.login-input-field {
  width: 100%;
  height: 44px;
  padding: 0.5rem 2.5rem 0.5rem 2.85rem;
  font-size: 0.92rem;
  border-radius: var(--radius-md, 10px);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.12));
  background: var(--bg-surface, rgba(15, 23, 42, 0.75));
  color: var(--text-main, #f8fafc);
  transition: all var(--transition-fast, 0.2s ease);
  direction: ltr;
  text-align: right;
}

.login-input-field:focus {
  outline: none;
  border-color: var(--primary-500, #6366f1);
  box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.25), 0 4px 12px rgba(99, 102, 241, 0.15);
  background: var(--bg-surface-elevated, rgba(15, 23, 42, 0.95));
}

.login-input-icon-right {
  position: absolute;
  right: 0.85rem;
  top: 50%;
  transform: translateY(-50%);
  font-size: 1.05rem;
  color: var(--text-muted, #94a3b8);
  pointer-events: none;
  user-select: none;
  display: flex;
  align-items: center;
}

.login-input-btn-left {
  position: absolute;
  left: 0.4rem;
  top: 50%;
  transform: translateY(-50%);
  border: none;
  background: transparent;
  padding: 0.35rem 0.5rem;
  cursor: pointer;
  color: var(--text-muted, #94a3b8);
  font-size: 1.15rem;
  border-radius: var(--radius-sm, 6px);
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition-fast, 0.2s ease);
}

.login-input-btn-left:hover {
  color: var(--text-main, #fff);
  background: rgba(255, 255, 255, 0.08);
}

/* Quick Role Selector Box */
.login-quick-roles-panel {
  background: var(--bg-surface, rgba(15, 23, 42, 0.65));
  padding: 0.75rem 0.85rem;
  border-radius: var(--radius-lg, 12px);
  border: 1px solid var(--border-color, rgba(255, 255, 255, 0.08));
  margin-top: 1.15rem;
}

.login-quick-roles-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 0.55rem;
}

.login-quick-roles-title {
  font-size: 0.76rem;
  font-weight: 700;
  color: var(--primary-400, #818cf8);
  display: flex;
  align-items: center;
  gap: 0.35rem;
}

.login-quick-roles-grid {
  display: grid !important;
  grid-template-columns: 1fr 1fr !important;
  gap: 0.45rem !important;
}

.login-role-chip {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.45rem 0.65rem;
  font-size: 0.78rem;
  font-weight: 600;
  border-radius: var(--radius-md, 8px);
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-main, #e2e8f0);
  cursor: pointer;
  transition: all var(--transition-fast, 0.2s ease);
  text-align: right;
  user-select: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.login-role-chip:hover {
  transform: translateY(-1px);
  border-color: rgba(99, 102, 241, 0.4);
  background: rgba(99, 102, 241, 0.12);
  color: #fff;
}

.login-role-chip.active {
  border-color: var(--primary-500, #6366f1);
  background: rgba(99, 102, 241, 0.2);
  color: #fff;
  box-shadow: 0 0 10px rgba(99, 102, 241, 0.3);
}

.login-role-chip.chip-admin {
  background: rgba(99, 102, 241, 0.08);
  border-color: rgba(99, 102, 241, 0.25);
}
.login-role-chip.chip-sales {
  background: rgba(16, 185, 129, 0.08);
  border-color: rgba(16, 185, 129, 0.25);
}
.login-role-chip.chip-finance {
  background: rgba(245, 158, 11, 0.08);
  border-color: rgba(245, 158, 11, 0.25);
}
.login-role-chip.chip-support {
  background: rgba(6, 182, 212, 0.08);
  border-color: rgba(6, 182, 212, 0.25);
}

/* Luxury Submit Button */
.login-submit-btn {
  width: 100%;
  padding: 0.75rem 1rem;
  font-size: 0.95rem;
  font-weight: 700;
  border-radius: var(--radius-md, 10px);
  border: none;
  background: linear-gradient(135deg, #4f46e5 0%, #0ea5e9 100%);
  color: #ffffff;
  cursor: pointer;
  box-shadow: 0 6px 20px -4px rgba(79, 70, 229, 0.5);
  transition: all var(--transition-fast, 0.2s ease);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
}

.login-submit-btn:hover {
  background: linear-gradient(135deg, #4338ca 0%, #0284c7 100%);
  box-shadow: 0 8px 24px -4px rgba(79, 70, 229, 0.65);
  transform: translateY(-1px);
}

.login-submit-btn:active {
  transform: translateY(0);
}

.login-submit-btn:disabled {
  opacity: 0.7;
  cursor: not-allowed;
  transform: none;
}

/* Toast Notifications */
.toast-container {
  position: fixed;
  top: 1.5rem;
  left: 1.5rem;
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  max-width: 380px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.9rem 1.15rem;
  border-radius: var(--radius-md);
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  box-shadow: var(--shadow-xl);
  color: var(--text-main);
  transform: translateX(-100%);
  opacity: 0;
  transition: all var(--transition-slow);
}

.toast.show {
  transform: translateX(0);
  opacity: 1;
}

.toast-success { border-right: 4px solid var(--success-500); }
.toast-error { border-right: 4px solid var(--danger-500); }
.toast-info { border-right: 4px solid var(--info-500); }
.toast-warning { border-right: 4px solid var(--warning-500); }

/* Skeleton Loading */
.skeleton {
  background: linear-gradient(90deg, var(--bg-subtle) 25%, var(--bg-hover) 50%, var(--bg-subtle) 75%);
  background-size: 200% 100%;
  animation: skeleton-shimmer 1.5s infinite;
  border-radius: var(--radius-sm);
}

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

/* Empty States */
.empty-state {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 3rem 1.5rem;
  text-align: center;
  gap: 0.75rem;
}

.empty-icon {
  font-size: 3rem;
  margin-bottom: 0.5rem;
  opacity: 0.6;
}

.empty-title {
  font-size: 1.15rem;
  font-weight: 700;
}

.empty-desc {
  font-size: 0.9rem;
  color: var(--text-muted);
  max-width: 320px;
}

/* PWA Floating Install Banner */
.pwa-install-banner {
  position: fixed;
  bottom: calc(var(--bottom-nav-height) + 1rem);
  left: 1rem;
  right: 1rem;
  max-width: 440px;
  margin: 0 auto;
  z-index: 999;
  background: var(--bg-surface-elevated);
  border: 1px solid var(--border-color);
  border-radius: var(--radius-xl);
  padding: 0.85rem 1.15rem;
  box-shadow: 0 12px 32px rgba(0, 0, 0, 0.5), 0 0 0 1px rgba(99, 102, 241, 0.2);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  backdrop-filter: blur(12px);
  animation: pwa-slide-up 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}

@media (min-width: 1025px) {
  .pwa-install-banner {
    left: 2rem;
    right: auto;
    bottom: 2rem;
  }
}

@keyframes pwa-slide-up {
  from {
    transform: translateY(100%) scale(0.9);
    opacity: 0;
  }
  to {
    transform: translateY(0) scale(1);
    opacity: 1;
  }
}

.pwa-banner-content {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  min-width: 0;
}

.pwa-banner-icon {
  width: 42px;
  height: 42px;
  border-radius: var(--radius-md);
  background: linear-gradient(135deg, var(--primary-600), var(--accent-purple));
  color: white;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.4rem;
  flex-shrink: 0;
  box-shadow: 0 4px 10px rgba(99, 102, 241, 0.4);
}

.pwa-banner-text {
  min-width: 0;
}

.pwa-banner-title {
  font-weight: 700;
  font-size: 0.9rem;
  color: var(--text-main);
  line-height: 1.2;
}

.pwa-banner-desc {
  font-size: 0.75rem;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  margin-top: 2px;
}

.pwa-banner-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  flex-shrink: 0;
}

/* Scrollable Horizontal Tabs Bar (Pills & Filter Bars) */
.scrollable-tabs-bar {
  display: flex !important;
  align-items: center !important;
  gap: 0.5rem !important;
  overflow-x: auto !important;
  -webkit-overflow-scrolling: touch !important;
  white-space: nowrap !important;
  padding: 0.25rem 0.25rem 0.65rem !important;
  margin-top: 1rem !important;
  width: 100% !important;
  scrollbar-width: none;
}
.scrollable-tabs-bar::-webkit-scrollbar {
  display: none;
}

.scrollable-tabs-bar .btn,
.ren-tab-btn,
.pause-tab-btn,
.fin-tab-btn,
.tab-pill-btn {
  flex-shrink: 0 !important;
  white-space: nowrap !important;
  display: inline-flex !important;
  align-items: center !important;
  justify-content: center !important;
  gap: 0.45rem !important;
  padding: 0.5rem 0.95rem !important;
  font-size: 0.82rem !important;
  font-weight: 600 !important;
  border-radius: var(--radius-full) !important;
  transition: all var(--transition-fast) !important;
}

.ren-tab-btn:hover,
.pause-tab-btn:hover,
.fin-tab-btn:hover {
  transform: translateY(-1px);
}

/* Search & Filter Rows */
.search-filter-row {
  width: 100%;
}

@media (max-width: 640px) {
  .search-filter-row {
    flex-direction: column !important;
    align-items: stretch !important;
    gap: 0.75rem !important;
  }
  .search-filter-row > div,
  .search-filter-row input,
  .search-filter-row select {
    width: 100% !important;
    min-width: 100% !important;
    max-width: 100% !important;
  }
}
